etc/services - sync with NetBSD-8
[minix.git] / external / bsd / bind / dist / contrib / idn / idnkit-1.0-src / lib / tests / res.tsy
blob0a29a537ab855b18399e32a786e154c592da8cce
1 #ifndef lint
2 static char *rcsid = "Id: res.tsy,v 1.1 2003/06/04 00:26:59 marka Exp ";
3 #endif
5 /*
6  * Copyright (c) 2002 Japan Network Information Center.
7  * All rights reserved.
8  *  
9  * By using this file, you agree to the terms and conditions set forth bellow.
10  * 
11  *                      LICENSE TERMS AND CONDITIONS 
12  * 
13  * The following License Terms and Conditions apply, unless a different
14  * license is obtained from Japan Network Information Center ("JPNIC"),
15  * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
16  * Chiyoda-ku, Tokyo 101-0047, Japan.
17  * 
18  * 1. Use, Modification and Redistribution (including distribution of any
19  *    modified or derived work) in source and/or binary forms is permitted
20  *    under this License Terms and Conditions.
21  * 
22  * 2. Redistribution of source code must retain the copyright notices as they
23  *    appear in each source code file, this License Terms and Conditions.
24  * 
25  * 3. Redistribution in binary form must reproduce the Copyright Notice,
26  *    this License Terms and Conditions, in the documentation and/or other
27  *    materials provided with the distribution.  For the purposes of binary
28  *    distribution the "Copyright Notice" refers to the following language:
29  *    "Copyright (c) 2000-2002 Japan Network Information Center.  All rights reserved."
30  * 
31  * 4. The name of JPNIC may not be used to endorse or promote products
32  *    derived from this Software without specific prior written approval of
33  *    JPNIC.
34  * 
35  * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
36  *    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37  *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
38  *    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL JPNIC BE LIABLE
39  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
40  *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
41  *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42  *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
43  *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
44  *    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
45  *    ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
46  */
48 #include <stddef.h>
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <string.h>
52 #include <idn/res.h>
53 #include <idn/log.h>
55 #include "codeset.h"
56 #include "setenv.h"
58 #ifndef EUCJP_ENCODING_NAME
59 #define EUCJP_ENCODING_NAME     "eucJP"
60 #endif
63  * U+304B: hiragana letter KA
64  * U+3099: combining katakana-hiragana voiced sound mark
65  *
66  *      map("U+304B U+3099") -> "U+304C"
67  *
68  * U+304C: hiragana letter GA
69  */
70 #define UTF8_NAME               "A<U+304B><U+3099>"
71 #define UTF8_REVNAME            "a<U+304C>"
74  * A4AC: hiragana letter GA (in EUC-JP)
75  */
76 #define EUCJP_NAME      "\xa4\xac"
77 #define EUCJP_REVNAME   "\xa4\xac"
80  * Conversion result of "U+304B U+3099 A"
81  */
82 #define PUNYCODE_NAME   "xn--a-i8t"
85  * Conversion result of "A U+304B U+3099" (in EUC-JP).
86  */
87 #define AUX_EUCJP_NAME  "xn--a-i\xa3\xb8t"
89 //--------------------------------------------------------------------
90 // Setups and Teardowns.
91 //--------------------------------------------------------------------
93 //# SETUP
94 //      group: generic-conversion
95 //--
96 //      Initialize the `resconf' context.
97 //      Set local encoding to `UTF-8'.
99         char to[256];
100         idn_result_t r;
101         idn_resconf_t ctx;
103         setenv("IDN_LOCAL_CODESET", "UTF-8", 1);
104         unsetenv("IDN_DISABLE");
106         r = idn_resconf_initialize();
107         ASSERT_RESULT(r, idn_success);
109         r = idn_resconf_create(&ctx);
110         ASSERT_RESULT(r, idn_success);
112         r = idn_resconf_setdefaults(ctx);
113         ASSERT_RESULT(r, idn_success);
116 //# TEARDOWN
117 //      group: generic-conversion
119         idn_resconf_destroy(ctx);
122 //# SETUP
123 //      group: quiet
124 //--
125 //      Set log level to `fatal' to supress log messages.
127         int saved_log_level;
129         saved_log_level = idn_log_getlevel();
130         idn_log_setlevel(idn_log_level_fatal);
133 //# TEARDOWN
134 //      group: quiet
135 //--
136 //      Restore log level.
138         idn_log_setlevel(saved_log_level);
141 //--------------------------------------------------------------------
142 // Testcases.
143 //--------------------------------------------------------------------
145 //# TESTCASE
146 //      title: basic conversion by encodename()
147 //      group: generic-conversion
149         r = idn_res_encodename(ctx, IDN_ENCODE_APP, UTF8_NAME, to, sizeof(to));
150         ASSERT_RESULT(r, idn_success);
151         ASSERT_STRING(to, PUNYCODE_NAME);
154 //# TESTCASE
155 //      title: basic conversion by decodename()
156 //      group: generic-conversion
158         r = idn_res_decodename(ctx, IDN_DECODE_APP, PUNYCODE_NAME, to, sizeof(to));
159         ASSERT_RESULT(r, idn_success);
160         ASSERT_STRING(to, UTF8_REVNAME);
163 //# TESTCASE
164 //      title: basic conversion by decodename2()
165 //      group: generic-conversion
167         r = idn_res_decodename2(ctx, IDN_DECODE_APP, AUX_EUCJP_NAME, to, sizeof(to),
168                             EUCJP_ENCODING_NAME);
169 #ifdef WITHOUT_ICONV
170         ASSERT_RESULT(r, idn_failure);
171 #else
172         ASSERT_RESULT(r, idn_success);
173         ASSERT_STRING(to, UTF8_REVNAME);
174 #endif
177 //# TESTCASE
178 //      title: call decodename2() with auxencoding=NULL
179 //      group: generic-conversion
181 #ifdef WITHOUT_ICONV
182         SKIP_TESTCASE;
183 #else
184         r = idn_res_decodename2(ctx, IDN_DECODE_APP, PUNYCODE_NAME, to, sizeof(to),
185                             NULL);
186         ASSERT_RESULT(r, idn_success);
187         ASSERT_STRING(to, UTF8_REVNAME);
188 #endif
191 //# TESTCASE
192 //      title: call encodename() with actions=0
193 //      group: generic-conversion
195         r = idn_res_encodename(ctx, 0, UTF8_NAME, to, sizeof(to));
196         ASSERT_RESULT(r, idn_success);
197         ASSERT_STRING(to, UTF8_NAME);
200 //# TESTCASE
201 //      title: call decodename() with actions=0
202 //      group: generic-conversion
204         r = idn_res_decodename(ctx, 0, PUNYCODE_NAME, to, sizeof(to));
205         ASSERT_RESULT(r, idn_success);
206         ASSERT_STRING(to, PUNYCODE_NAME);
209 //# TESTCASE
210 //      title: call decodename2() with actions=0
211 //      group: generic-conversion
213 #ifdef WITHOUT_ICONV
214         SKIP_TESTCASE;
215 #else
216         r = idn_res_decodename2(ctx, 0, AUX_EUCJP_NAME, to, sizeof(to),
217                             EUCJP_ENCODING_NAME);
218         ASSERT_RESULT(r, idn_success);
219         ASSERT_STRING(to, AUX_EUCJP_NAME);
220 #endif
223 //# TESTCASE
224 //      title: call encodename() with actions=rtcheck
225 //      group: generic-conversion quiet
227         r = idn_res_encodename(ctx, IDN_RTCHECK, EUCJP_NAME, to, sizeof(to));
228         ASSERT_RESULT(r, idn_invalid_action);
231 //# TESTCASE
232 //      title: call encodename() with actions=decode-query
233 //      group: generic-conversion quiet
235         r = idn_res_encodename(ctx, IDN_DECODE_QUERY, EUCJP_NAME, to, sizeof(to));
236         ASSERT_RESULT(r, idn_invalid_action);
239 //# TESTCASE
240 //      title: call encodename() with actions=decode-app
241 //      group: generic-conversion quiet
243         r = idn_res_encodename(ctx, IDN_DECODE_APP, EUCJP_NAME, to, sizeof(to));
244         ASSERT_RESULT(r, idn_invalid_action);
247 //# TESTCASE
248 //      title: call encodename() with actions=decode-stored
249 //      group: generic-conversion quiet
251         r = idn_res_encodename(ctx, IDN_DECODE_STORED, EUCJP_NAME, to, sizeof(to));
252         ASSERT_RESULT(r, idn_invalid_action);
255 //# TESTCASE
256 //      title: call encodename() with actions=(1<<31)
257 //      group: generic-conversion quiet
259         r = idn_res_encodename(ctx, 1 << 31, EUCJP_NAME, to, sizeof(to));
260         ASSERT_RESULT(r, idn_invalid_action);
263 //# TESTCASE
264 //      title: call decodename() with actions=localmap
265 //      group: generic-conversion quiet
267         r = idn_res_decodename(ctx, IDN_LOCALMAP, PUNYCODE_NAME, to, sizeof(to));
268         ASSERT_RESULT(r, idn_invalid_action);
271 //# TESTCASE
272 //      title: call decodename2() with actions=localmap
273 //      group: generic-conversion quiet
275 #ifdef WITHOUT_ICONV
276         SKIP_TESTCASE;
277 #else
278         r = idn_res_decodename2(ctx, IDN_LOCALMAP, AUX_EUCJP_NAME, to, sizeof(to),
279                             EUCJP_ENCODING_NAME);
280         ASSERT_RESULT(r, idn_invalid_action);
281 #endif
284 //# TESTCASE
285 //      title: call decodename() with actions=lencheck
286 //      group: generic-conversion quiet
288         r = idn_res_decodename(ctx, IDN_LENCHECK, PUNYCODE_NAME, to, sizeof(to));
289         ASSERT_RESULT(r, idn_invalid_action);
292 //# TESTCASE
293 //      title: call decodename2() with actions=lencheck
294 //      group: generic-conversion quiet
296 #ifdef WITHOUT_ICONV
297         SKIP_TESTCASE;
298 #else
299         r = idn_res_decodename2(ctx, IDN_LENCHECK, AUX_EUCJP_NAME, to, sizeof(to),
300                             EUCJP_ENCODING_NAME);
301         ASSERT_RESULT(r, idn_invalid_action);
302 #endif
305 //# TESTCASE
306 //      title: call decodename() with actions=encode-query
307 //      group: generic-conversion quiet
309         r = idn_res_decodename(ctx, IDN_ENCODE_QUERY, PUNYCODE_NAME, to, sizeof(to));
310         ASSERT_RESULT(r, idn_invalid_action);
313 //# TESTCASE
314 //      title: call decodename2() with actions=encode-query
315 //      group: generic-conversion quiet
317 #ifdef WITHOUT_ICONV
318         SKIP_TESTCASE;
319 #else
320         r = idn_res_decodename2(ctx, IDN_ENCODE_QUERY, AUX_EUCJP_NAME, to, sizeof(to),
321                             EUCJP_ENCODING_NAME);
322         ASSERT_RESULT(r, idn_invalid_action);
323 #endif
326 //# TESTCASE
327 //      title: call decodename() with actions=encode-app
328 //      group: generic-conversion quiet
330         r = idn_res_decodename(ctx, IDN_ENCODE_APP, PUNYCODE_NAME, to, sizeof(to));
331         ASSERT_RESULT(r, idn_invalid_action);
334 //# TESTCASE
335 //      title: call decodename2() with actions=encode-app
336 //      group: generic-conversion quiet
338 #ifdef WITHOUT_ICONV
339         SKIP_TESTCASE;
340 #else
341         r = idn_res_decodename2(ctx, IDN_ENCODE_APP, AUX_EUCJP_NAME, to, sizeof(to),
342                             EUCJP_ENCODING_NAME);
343         ASSERT_RESULT(r, idn_invalid_action);
344 #endif
347 //# TESTCASE
348 //      title: call decodename() with actions=encode-stored
349 //      group: generic-conversion quiet
351         r = idn_res_decodename(ctx, IDN_ENCODE_STORED, PUNYCODE_NAME, to, sizeof(to));
352         ASSERT_RESULT(r, idn_invalid_action);
355 //# TESTCASE
356 //      title: call decodename2() with actions=encode-stored
357 //      group: generic-conversion quiet
359 #ifdef WITHOUT_ICONV
360         SKIP_TESTCASE;
361 #else
362         r = idn_res_decodename2(ctx, IDN_ENCODE_STORED, AUX_EUCJP_NAME, to, sizeof(to),
363                             EUCJP_ENCODING_NAME);
364         ASSERT_RESULT(r, idn_invalid_action);
365 #endif
368 //# TESTCASE
369 //      title: call decodename() with actions=(1<<31)
370 //      group: generic-conversion quiet
372         r = idn_res_decodename(ctx, 1 << 31, PUNYCODE_NAME, to, sizeof(to));
373         ASSERT_RESULT(r, idn_invalid_action);
376 //# TESTCASE
377 //      title: call decodename2() with actions=(1<<31)
378 //      group: generic-conversion quiet
380 #ifdef WITHOUT_ICONV
381         SKIP_TESTCASE;
382 #else
383         r = idn_res_decodename2(ctx, 1 << 31, AUX_EUCJP_NAME, to, sizeof(to),
384                             EUCJP_ENCODING_NAME);
385         ASSERT_RESULT(r, idn_invalid_action);
386 #endif
389 //# TESTCASE
390 //      title: call encodename() with actions=localconv
391 //      group: generic-conversion quiet
393 #ifndef WITHOUT_ICONV
394         SKIP_TESTCASE;
395 #else
396         r = idn_res_encodename(ctx, IDN_LOCALCONV, UTF8_NAME, to, sizeof(to));
397         ASSERT_RESULT(r, idn_invalid_action);
398 #endif
401 //# TESTCASE
402 //      title: call decodename() with actions=localconv
403 //      group: generic-conversion quiet
405 #ifndef WITHOUT_ICONV
406         SKIP_TESTCASE;
407 #else
408         r = idn_res_decodename(ctx, IDN_LOCALCONV, PUNYCODE_NAME, to, sizeof(to));
409         ASSERT_RESULT(r, idn_invalid_action);
410 #endif
413 //# TESTCASE
414 //      title: call decodename2() with actions=localconv
415 //      group: generic-conversion
417 #ifndef WITHOUT_ICONV
418         SKIP_TESTCASE;
419 #else
420         r = idn_res_decodename2(ctx, IDN_LOCALCONV, AUX_EUCJP_NAME, to, sizeof(to),
421                             EUCJP_ENCODING_NAME);
422         ASSERT_RESULT(r, idn_failure);
423 #endif
426 //# TESTCASE
427 //      title: call enable(0) and then encodename()
428 //      group: generic-conversion
430         idn_res_enable(0);
431         r = idn_res_encodename(ctx, IDN_ENCODE_APP, UTF8_NAME, to, sizeof(to));
432         ASSERT_RESULT(r, idn_success);
433         ASSERT_STRING(to, UTF8_NAME);
436 //# TESTCASE
437 //      title: call decodename() when IDN_DISABLE is defined
438 //      group: generic-conversion
440         idn_res_enable(0);
441         r = idn_res_decodename(ctx, IDN_DECODE_APP, PUNYCODE_NAME, to, sizeof(to));
442         ASSERT_RESULT(r, idn_success);
443         ASSERT_STRING(to, PUNYCODE_NAME);
446 //# TESTCASE
447 //      title: call decodename() when IDN_DISABLE is defined
448 //      group: generic-conversion
450 #ifdef WITHOUT_ICONV
451         SKIP_TESTCASE;
452 #else
453         idn_res_enable(0);
454         r = idn_res_decodename2(ctx, IDN_DECODE_APP, AUX_EUCJP_NAME, to, sizeof(to),
455                             EUCJP_ENCODING_NAME);
456         ASSERT_RESULT(r, idn_success);
457         ASSERT_STRING(to, AUX_EUCJP_NAME);
458 #endif
461 //# TESTCASE
462 //      title: call enable(0) and then encodename()
463 //      group: generic-conversion
465         idn_res_enable(0);
466         r = idn_res_encodename(ctx, IDN_ENCODE_APP, UTF8_NAME, to, sizeof(to));
467         ASSERT_RESULT(r, idn_success);
468         ASSERT_STRING(to, UTF8_NAME);
471 //# TESTCASE
472 //      title: call enable(0) and then decodename()
473 //      group: generic-conversion
475         idn_res_enable(0);
476         r = idn_res_decodename(ctx, IDN_DECODE_APP, PUNYCODE_NAME, to, sizeof(to));
477         ASSERT_RESULT(r, idn_success);
478         ASSERT_STRING(to, PUNYCODE_NAME);
481 //# TESTCASE
482 //      title: call enable(0) and then decodename2()
483 //      group: generic-conversion
485 #ifdef WITHOUT_ICONV
486         SKIP_TESTCASE;
487 #else
488         idn_res_enable(0);
489         r = idn_res_decodename2(ctx, IDN_DECODE_APP, AUX_EUCJP_NAME, to, sizeof(to),
490                             EUCJP_ENCODING_NAME);
491         ASSERT_RESULT(r, idn_success);
492         ASSERT_STRING(to, AUX_EUCJP_NAME);
493 #endif
496 //# TESTCASE
497 //      title: set IDN_DISABLE and call encodename()
498 //      group: generic-conversion
500         setenv("IDN_DISABLE", "1", 1);
501         r = idn_res_encodename(ctx, IDN_ENCODE_APP, UTF8_NAME, to, sizeof(to));
502         ASSERT_RESULT(r, idn_success);
503         ASSERT_STRING(to, UTF8_NAME);
506 //# TESTCASE
507 //      title: set IDN_DISABLE and call decodename()
508 //      group: generic-conversion
510         setenv("IDN_DISABLE", "1", 1);
511         r = idn_res_decodename(ctx, IDN_DECODE_APP, PUNYCODE_NAME, to, sizeof(to));
512         ASSERT_RESULT(r, idn_success);
513         ASSERT_STRING(to, PUNYCODE_NAME);
516 //# TESTCASE
517 //      title: set IDN_DISABLE and call decodename2()
518 //      group: generic-conversion
520 #ifdef WITHOUT_ICONV
521         SKIP_TESTCASE;
522 #else
523         setenv("IDN_DISABLE", "1", 1);
524         r = idn_res_decodename2(ctx, IDN_DECODE_APP, AUX_EUCJP_NAME, to, sizeof(to),
525                             EUCJP_ENCODING_NAME);
526         ASSERT_RESULT(r, idn_success);
527         ASSERT_STRING(to, AUX_EUCJP_NAME);
528 #endif
531 //# TESTCASE
532 //      title: set IDN_DISABLE, and then call enable(1) and encodename()
533 //      group: generic-conversion
535         setenv("IDN_DISABLE", "1", 1);
536         idn_res_enable(1);
537         r = idn_res_encodename(ctx, IDN_ENCODE_APP, UTF8_NAME, to, sizeof(to));
538         ASSERT_RESULT(r, idn_success);
539         ASSERT_STRING(to, PUNYCODE_NAME);
542 //# TESTCASE
543 //      title: set IDN_DISABLE, and then call enable(1) and decodename()
544 //      group: generic-conversion
546         setenv("IDN_DISABLE", "1", 1);
547         idn_res_enable(1);
548         r = idn_res_decodename(ctx, IDN_DECODE_APP, PUNYCODE_NAME, to, sizeof(to));
549         ASSERT_RESULT(r, idn_success);
550         ASSERT_STRING(to, UTF8_REVNAME);
553 //# TESTCASE
554 //      title: set IDN_DISABLE, and then call enable(1) and decodename2()
555 //      group: generic-conversion
557 #ifdef WITHOUT_ICONV
558         SKIP_TESTCASE;
559 #else
560         setenv("IDN_DISABLE", "1", 1);
561         idn_res_enable(1);
562         r = idn_res_decodename2(ctx, IDN_DECODE_APP, AUX_EUCJP_NAME, to, sizeof(to),
563                             EUCJP_ENCODING_NAME);
564         ASSERT_RESULT(r, idn_success);
565         ASSERT_STRING(to, UTF8_REVNAME);
566 #endif
569 //# TESTCASE
570 //      title: overrun test for arg `to' of encodename()
571 //      group: generic-conversion
573         /* Normal case */
574         r = idn_res_encodename(ctx, IDN_ENCODE_APP, UTF8_NAME, to,
575                            strlen(PUNYCODE_NAME) + 1);
576         ASSERT_RESULT(r, idn_success);
577         ASSERT_STRING(to, PUNYCODE_NAME);
579         r = idn_res_encodename(ctx, IDN_ENCODE_APP, UTF8_NAME, to,
580                            strlen(PUNYCODE_NAME));
581         ASSERT_RESULT(r, idn_buffer_overflow);
583         /* enable(0) case */
584         idn_res_enable(0);
585         r = idn_res_encodename(ctx, IDN_ENCODE_APP, UTF8_NAME, to,
586                            strlen(UTF8_NAME) + 1);
587         ASSERT_RESULT(r, idn_success);
588         ASSERT_STRING(to, UTF8_NAME);
590         r = idn_res_encodename(ctx, IDN_ENCODE_APP, UTF8_NAME, to,
591                            strlen(UTF8_NAME));
592         ASSERT_RESULT(r, idn_buffer_overflow);
594         /* actions=0 case */
595         idn_res_enable(1);
596         r = idn_res_encodename(ctx, 0, UTF8_NAME, to, strlen(UTF8_NAME) + 1);
597         ASSERT_RESULT(r, idn_success);
598         ASSERT_STRING(to, UTF8_NAME);
600         r = idn_res_encodename(ctx, 0, UTF8_NAME, to, strlen(UTF8_NAME));
601         ASSERT_RESULT(r, idn_buffer_overflow);
604 //# TESTCASE
605 //      title: overrun test for arg `to' of decodename()
606 //      group: generic-conversion
608         /* Normal case */
609         r = idn_res_decodename(ctx, IDN_DECODE_APP, PUNYCODE_NAME, to,
610                            strlen(UTF8_REVNAME) + 1);
611         ASSERT_RESULT(r, idn_success);
612         ASSERT_STRING(to, UTF8_REVNAME);
614         r = idn_res_decodename(ctx, IDN_DECODE_APP, PUNYCODE_NAME, to,
615                            strlen(UTF8_REVNAME));
616         ASSERT_RESULT(r, idn_buffer_overflow);
618         /* idn_res_enable(0) case */
619         idn_res_enable(0);
620         r = idn_res_decodename(ctx, IDN_DECODE_APP, PUNYCODE_NAME, to,
621                            strlen(PUNYCODE_NAME) + 1);
622         ASSERT_RESULT(r, idn_success);
623         ASSERT_STRING(to, PUNYCODE_NAME);
625         r = idn_res_decodename(ctx, IDN_DECODE_APP, PUNYCODE_NAME, to,
626                            strlen(PUNYCODE_NAME));
627         ASSERT_RESULT(r, idn_buffer_overflow);
629         /* actions=0 case */
630         idn_res_enable(1);
631         r = idn_res_decodename(ctx, 0, PUNYCODE_NAME, to,
632                                strlen(PUNYCODE_NAME) + 1);
633         ASSERT_RESULT(r, idn_success);
634         ASSERT_STRING(to, PUNYCODE_NAME);
636         r = idn_res_decodename(ctx, 0, PUNYCODE_NAME, to,
637                                strlen(PUNYCODE_NAME));
638         ASSERT_RESULT(r, idn_buffer_overflow);
641 //# TESTCASE
642 //      title: overrun test for arg `to' of decodename2()
643 //      group: generic-conversion
645 #ifdef WITHOUT_ICONV
646         SKIP_TESTCASE;
647 #else
648         /* Normal case */
649         r = idn_res_decodename2(ctx, IDN_DECODE_APP, AUX_EUCJP_NAME, to,
650                             strlen(UTF8_REVNAME) + 1, EUCJP_ENCODING_NAME);
651         ASSERT_RESULT(r, idn_success);
652         ASSERT_STRING(to, UTF8_REVNAME);
654         r = idn_res_decodename2(ctx, IDN_DECODE_APP, AUX_EUCJP_NAME, to,
655                             strlen(UTF8_REVNAME), EUCJP_ENCODING_NAME);
656         ASSERT_RESULT(r, idn_buffer_overflow);
658         /* idn_res_enable(0) case */
659         idn_res_enable(0);
660         r = idn_res_decodename2(ctx, IDN_DECODE_APP, AUX_EUCJP_NAME, to,
661                             strlen(AUX_EUCJP_NAME) + 1, EUCJP_ENCODING_NAME);
662         ASSERT_RESULT(r, idn_success);
663         ASSERT_STRING(to, AUX_EUCJP_NAME);
665         r = idn_res_decodename2(ctx, IDN_DECODE_APP, AUX_EUCJP_NAME, to,
666                             strlen(AUX_EUCJP_NAME), EUCJP_ENCODING_NAME);
667         ASSERT_RESULT(r, idn_buffer_overflow);
669         /* actions=0 case */
670         idn_res_enable(1);
671         r = idn_res_decodename2(ctx, 0, AUX_EUCJP_NAME, to,
672                             strlen(AUX_EUCJP_NAME) + 1, EUCJP_ENCODING_NAME);
673         ASSERT_RESULT(r, idn_success);
674         ASSERT_STRING(to, AUX_EUCJP_NAME);
676         r = idn_res_decodename2(ctx, 0, AUX_EUCJP_NAME, to,
677                                 strlen(AUX_EUCJP_NAME), EUCJP_ENCODING_NAME);
678         ASSERT_RESULT(r, idn_buffer_overflow);
680 #endif
683 //# TESTCASE
684 //      title: call encodename() with tolen=0
685 //      group: generic-conversion
687         r = idn_res_encodename(ctx, IDN_ENCODE_APP, UTF8_NAME, to, 0);
688         ASSERT_RESULT(r, idn_buffer_overflow);
691 //# TESTCASE
692 //      title: call decodename() with tolen=0
693 //      group: generic-conversion
695         r = idn_res_decodename(ctx, IDN_DECODE_APP, PUNYCODE_NAME, to, 0);
696         ASSERT_RESULT(r, idn_buffer_overflow);
699 //# TESTCASE
700 //      title: call decodename2() with tolen=0
701 //      group: generic-conversion
703 #ifdef WITHOUT_ICONV
704         SKIP_TESTCASE;
705 #else
706         r = idn_res_decodename2(ctx, IDN_DECODE_APP, AUX_EUCJP_NAME, to, 0,
707                             EUCJP_ENCODING_NAME);
708         ASSERT_RESULT(r, idn_buffer_overflow);
709 #endif
712 //# TESTCASE
713 //      title: convert an empty string using encodename()
714 //      group: generic-conversion
716         r = idn_res_encodename(ctx, IDN_ENCODE_APP, "", to, sizeof(to));
717         ASSERT_RESULT(r, idn_success);
718         ASSERT_STRING(to, "");
721 //# TESTCASE
722 //      title: convert an empty string using decodename()
723 //      group: generic-conversion
725         r = idn_res_decodename(ctx, IDN_DECODE_APP, "", to, sizeof(to));
726         ASSERT_RESULT(r, idn_success);
727         ASSERT_STRING(to, "");
730 //# TESTCASE
731 //      title: convert an empty string using decodename2()
732 //      group: generic-conversion
734 #ifdef WITHOUT_ICONV
735         SKIP_TESTCASE;
736 #else
737         r = idn_res_decodename2(ctx, IDN_DECODE_APP, "", to, sizeof(to),
738                             EUCJP_ENCODING_NAME);
739         ASSERT_RESULT(r, idn_success);
740         ASSERT_STRING(to, "");
741 #endif
744 //# TESTCASE
745 //      title: prohcheck by encodename()
746 //      group: generic-conversion
748         /* U+1680: prohibited character */
749         r = idn_res_encodename(ctx, IDN_PROHCHECK, "<U+1680>", to, sizeof(to));
750         ASSERT_RESULT(r, idn_prohibited);
753 //# TESTCASE
754 //      title: unascheck by encodename()
755 //      group: generic-conversion
757         /* U+0221: unassigned codepoint */
758         r = idn_res_encodename(ctx, IDN_UNASCHECK, "<U+0221>", to, sizeof(to));
759         ASSERT_RESULT(r, idn_prohibited);
762 //# TESTCASE
763 //      title: bidicheck by encodename()
764 //      group: generic-conversion
766         /* U+05D0:   bidirectional property is "R" */
767         /* `a':      bidirectional property is "L" */
768         /* `0', `-': bidirectional property is "N" */
769         r = idn_res_encodename(ctx, IDN_BIDICHECK, "<U+05D0>", to, sizeof(to));
770         ASSERT_RESULT(r, idn_success);
772         r = idn_res_encodename(ctx, IDN_BIDICHECK, "<U+05D0><U+05D0>",
773                            to, sizeof(to));
774         ASSERT_RESULT(r, idn_success);
776         r = idn_res_encodename(ctx, IDN_BIDICHECK, "<U+05D0><U+05D0>-a",
777                            to, sizeof(to));
778         ASSERT_RESULT(r, idn_prohibited);
780         r = idn_res_encodename(ctx, IDN_BIDICHECK, "<U+05D0>-a-<U+05D0>",
781                            to, sizeof(to));
782         ASSERT_RESULT(r, idn_prohibited);
784         r = idn_res_encodename(ctx, IDN_BIDICHECK, "a-<U+05D0><U+05D0>",
785                            to, sizeof(to));
786         ASSERT_RESULT(r, idn_prohibited);
788         r = idn_res_encodename(ctx, IDN_BIDICHECK, "<U+05D0><U+05D0>-0",
789                            to, sizeof(to));
790         ASSERT_RESULT(r, idn_prohibited);
792         r = idn_res_encodename(ctx, IDN_BIDICHECK, "<U+05D0>-0-<U+05D0>",
793                            to, sizeof(to));
794         ASSERT_RESULT(r, idn_success);
796         r = idn_res_encodename(ctx, IDN_BIDICHECK, "0-<U+05D0><U+05D0>",
797                            to, sizeof(to));
798         ASSERT_RESULT(r, idn_prohibited);
801 //# TESTCASE
802 //      title: asccheck by encodename()
803 //      group: generic-conversion
805         r = idn_res_encodename(ctx, IDN_ASCCHECK, "-name", to, sizeof(to));
806         ASSERT_RESULT(r, idn_prohibited);
808         r = idn_res_encodename(ctx, IDN_ASCCHECK, "name-", to, sizeof(to));
809         ASSERT_RESULT(r, idn_prohibited);
811         r = idn_res_encodename(ctx, IDN_ASCCHECK, "n ame", to, sizeof(to));
812         ASSERT_RESULT(r, idn_prohibited);
815 //# TESTCASE
816 //      title: lencheck by encodename()
817 //      group: generic-conversion
819         r = idn_res_encodename(ctx, IDN_LENCHECK,
820                            "123456789-123456789-123456789-123456789-"
821                            "123456789-123456789-123", to, sizeof(to));
822         ASSERT_RESULT(r, idn_success);
824         r = idn_res_encodename(ctx, IDN_LENCHECK,
825                            "123456789-123456789-123456789-123456789-"
826                            "123456789-123456789-1234", to, sizeof(to));
827         ASSERT_RESULT(r, idn_invalid_length);
829         r = idn_res_encodename(ctx, IDN_LENCHECK, "a..b", to, sizeof(to));
830         ASSERT_RESULT(r, idn_invalid_length);
833 //# TESTCASE
834 //      title: rtcheck non-prohchecked label by decodename()
835 //      group: generic-conversion
837         /* "xn--6ue" -> "U+1680" (prohibited character) */
838         r = idn_res_decodename(ctx, IDN_RTCHECK, "xn--6ue", to, sizeof(to));
839         ASSERT_RESULT(r, idn_success);
840         ASSERT_STRING(to, "xn--6ue");
843 //# TESTCASE
844 //      title: rtcheck non-unaschecked label by decodename()
845 //      group: generic-conversion
847         /* "xn--6la" -> "U+0221" (unassigned codepoint) */
848         r = idn_res_decodename(ctx, IDN_IDNCONV | IDN_RTCHECK | IDN_UNASCHECK,
849                            "xn--6la", to, sizeof(to));
850         ASSERT_RESULT(r, idn_success);
851         ASSERT_STRING(to, "xn--6la");
854 //# TESTCASE
855 //      title: rtcheck non-ascchecked label by decodename()
856 //      group: generic-conversion
858         /* "xn----x7t" -> "- U+3042" */
859         r = idn_res_decodename(ctx, IDN_IDNCONV | IDN_RTCHECK | IDN_ASCCHECK,
860                            "xn----x7t", to, sizeof(to));
861         ASSERT_RESULT(r, idn_success);
862         ASSERT_STRING(to, "xn----x7t");
864         /* "xn----w7t" -> "U+3042 -" */
865         r = idn_res_decodename(ctx, IDN_IDNCONV | IDN_RTCHECK | IDN_ASCCHECK,
866                            "xn----w7t", to, sizeof(to));
867         ASSERT_RESULT(r, idn_success);
868         ASSERT_STRING(to, "xn----w7t");
871 //# TESTCASE
872 //      title: rtcheck non-lenchecked label by decodename()
873 //      group: generic-conversion
875         /* `s1' has 63 characters */
876         const char *s1 =
877             "xn--l8jaa5522a8sj38bzugvvblo3y90fjzgvxlmxscifws3d43odzaq6aj340b";
879         const char *s1rev =
880             "<U+9752><U+68EE><U+5CA9><U+624B><U+5BAE><U+57CE><U+79CB><U+7530>"
881             "<U+5C71><U+5F62><U+798F><U+5CF6><U+6771><U+4EAC><U+795E><U+5948>"
882             "<U+5DDD><U+3042><U+3042><U+3042>";
884         /* `s2' has 64 characters */
885         const char *s2 =
886             "xn--a-w7ta6522a8sj38bzugvvblo3y90fjzgvxlmxscifws3d43odzaq6aj340b";
888         /* `s3' has an empty label */
889         const char *s3 = "a..b";
891         r = idn_res_decodename(ctx, IDN_IDNCONV | IDN_RTCHECK, s1, to, sizeof(to));
892         ASSERT_RESULT(r, idn_success);
893         ASSERT_STRING(to, s1rev);
895         r = idn_res_decodename(ctx, IDN_IDNCONV | IDN_RTCHECK, s2, to, sizeof(to));
896         ASSERT_RESULT(r, idn_success);
897         ASSERT_STRING(to, s2);
899         r = idn_res_decodename(ctx, IDN_IDNCONV | IDN_RTCHECK, s3, to, sizeof(to));
900         ASSERT_RESULT(r, idn_success);
901         ASSERT_STRING(to, s3);
904 //# TESTCASE
905 //      title: rtcheck non-prohchecked label by decodename2()
906 //      group: generic-conversion
908 #ifdef WITHOUT_ICONV
909         SKIP_TESTCASE;
910 #else
911         /* "xn--6ue" -> "U+1680" (prohibited character) */
912         r = idn_res_decodename2(ctx, IDN_RTCHECK, "xn--6ue", to, sizeof(to),
913                             EUCJP_ENCODING_NAME);
914         ASSERT_RESULT(r, idn_success);
915         ASSERT_STRING(to, "xn--6ue");
916 #endif
919 //# TESTCASE
920 //      title: rtcheck non-unaschecked label by decodename2()
921 //      group: generic-conversion
923 #ifdef WITHOUT_ICONV
924         SKIP_TESTCASE;
925 #else
926         /* "xn--6la" -> "U+0221" (unassigned codepoint) */
927         r = idn_res_decodename2(ctx, IDN_IDNCONV | IDN_RTCHECK | IDN_UNASCHECK,
928                             "xn--6la", to, sizeof(to), EUCJP_ENCODING_NAME);
929         ASSERT_RESULT(r, idn_success);
930         ASSERT_STRING(to, "xn--6la");
931 #endif
934 //# TESTCASE
935 //      title: rtcheck non-ascchecked label by decodename2()
936 //      group: generic-conversion
938 #ifdef WITHOUT_ICONV
939         SKIP_TESTCASE;
940 #else
941         /* "xn----x7t" -> "- U+3042" */
942         r = idn_res_decodename2(ctx, IDN_IDNCONV | IDN_RTCHECK | IDN_ASCCHECK,
943                             "xn----x7t", to, sizeof(to), EUCJP_ENCODING_NAME);
945         ASSERT_RESULT(r, idn_success);
946         ASSERT_STRING(to, "xn----x7t");
948         /* "xn----w7t" -> "U+3042 -" */
949         r = idn_res_decodename2(ctx, IDN_IDNCONV | IDN_RTCHECK | IDN_ASCCHECK,
950                             "xn----w7t", to, sizeof(to), EUCJP_ENCODING_NAME);
951         ASSERT_RESULT(r, idn_success);
952         ASSERT_STRING(to, "xn----w7t");
953 #endif
956 //# TESTCASE
957 //      title: rtcheck non-lenchecked label by decodename2()
958 //      group: generic-conversion
960 #ifdef WITHOUT_ICONV
961         SKIP_TESTCASE;
962 #else
963         /* `s1' has 63 characters */
964         const char *s1 =
965             "xn--l8jaa5522a8sj38bzugvvblo3y90fjzgvxlmxscifws3d43odzaq6aj340b";
967         const char *s1rev =
968             "<U+9752><U+68EE><U+5CA9><U+624B><U+5BAE><U+57CE><U+79CB><U+7530>"
969             "<U+5C71><U+5F62><U+798F><U+5CF6><U+6771><U+4EAC><U+795E><U+5948>"
970             "<U+5DDD><U+3042><U+3042><U+3042>";
972         /* `s2' has 64 characters */
973         const char *s2 =
974             "xn--a-w7ta6522a8sj38bzugvvblo3y90fjzgvxlmxscifws3d43odzaq6aj340b";
976         /* `s3' has an empty label */
977         const char *s3 = "a..b";
979         r = idn_res_decodename2(ctx, IDN_IDNCONV | IDN_RTCHECK, s1, to, sizeof(to),
980                             EUCJP_ENCODING_NAME);
981         ASSERT_RESULT(r, idn_success);
982         ASSERT_STRING(to, s1rev);
984         r = idn_res_decodename2(ctx, IDN_IDNCONV | IDN_RTCHECK, s2, to, sizeof(to),
985                             EUCJP_ENCODING_NAME);
986         ASSERT_RESULT(r, idn_success);
987         ASSERT_STRING(to, s2);
989         r = idn_res_decodename(ctx, IDN_IDNCONV | IDN_RTCHECK, s3, to, sizeof(to));
990         ASSERT_RESULT(r, idn_success);
991         ASSERT_STRING(to, s3);
992 #endif
995 //# TESTCASE
996 //      title: pass broken string as `from' to encodename()
997 //      group: generic-conversion quiet
999         /* "\xe3\x21" is not valid UTF-8 string */
1000         r = idn_res_encodename(ctx, IDN_ENCODE_APP, "\xe3\x21", to, sizeof(to));
1001         ASSERT_RESULT(r, idn_invalid_encoding);
1004 //# TESTCASE
1005 //      title: pass broken string as `from' to decodename()
1006 //      group: generic-conversion quiet
1008         /* "\xe3\x21" is not valid UTF-8 string */
1009         r = idn_res_decodename(ctx, IDN_DECODE_APP, "\xe3\x21", to, sizeof(to));
1010         ASSERT_RESULT(r, idn_invalid_encoding);
1013 //# TESTCASE
1014 //      title: pass broken string as `from' to decodename2()
1015 //      group: generic-conversion quiet
1017 #ifdef WITHOUT_ICONV
1018         SKIP_TESTCASE;
1019 #else
1020         /* "\xa4\x21" is not valid EUC-JP string */
1021         r = idn_res_decodename2(ctx, IDN_DECODE_APP, "\xa4\x21", to, sizeof(to),
1022                             EUCJP_ENCODING_NAME);
1023         ASSERT_RESULT(r, idn_invalid_encoding);
1024 #endif