etc/services - sync with NetBSD-8
[minix.git] / external / bsd / bind / dist / contrib / idn / idnkit-1.0-src / lib / tests / api.tsy
blob8cfb5d895e12a283992974273d351f63776fe635
1 #ifndef lint
2 static char *rcsid = "Id: api.tsy,v 1.1 2003/06/04 00:26:50 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/api.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"
90 //--------------------------------------------------------------------
91 // Setups and Teardowns.
92 //--------------------------------------------------------------------
94 //# SETUP
95 //      group: generic-conversion
96 //--
97 //      Initialize the `api' module.
98 //      Set local encoding to `UTF-8'.
100         char to[256];
101         idn_result_t r;
103         setenv("IDN_LOCAL_CODESET", "UTF-8", 1);
104         unsetenv("IDN_DISABLE");
105         idn_nameinit(0);
108 //# SETUP
109 //      group: quiet
110 //--
111 //      Set log level to `fatal' to supress log messages.
113         int saved_log_level;
115         saved_log_level = idn_log_getlevel();
116         idn_log_setlevel(idn_log_level_fatal);
119 //# TEARDOWN
120 //      group: quiet
121 //--
122 //      Restore log level.
124         idn_log_setlevel(saved_log_level);
127 //--------------------------------------------------------------------
128 // Testcases.
129 //--------------------------------------------------------------------
131 //# TESTCASE
132 //      title: basic conversion by encodename()
133 //      group: generic-conversion
135         r = idn_encodename(IDN_ENCODE_APP, UTF8_NAME, to, sizeof(to));
136         ASSERT_RESULT(r, idn_success);
137         ASSERT_STRING(to, PUNYCODE_NAME);
140 //# TESTCASE
141 //      title: basic conversion by decodename()
142 //      group: generic-conversion
144         r = idn_decodename(IDN_DECODE_APP, PUNYCODE_NAME, to, sizeof(to));
145         ASSERT_RESULT(r, idn_success);
146         ASSERT_STRING(to, UTF8_REVNAME);
149 //# TESTCASE
150 //      title: basic conversion by decodename2()
151 //      group: generic-conversion
153         r = idn_decodename2(IDN_DECODE_APP, AUX_EUCJP_NAME, to, sizeof(to),
154                             EUCJP_ENCODING_NAME);
155 #ifdef WITHOUT_ICONV
156         ASSERT_RESULT(r, idn_failure);
157 #else
158         ASSERT_RESULT(r, idn_success);
159         ASSERT_STRING(to, UTF8_REVNAME);
160 #endif
163 //# TESTCASE
164 //      title: call decodename2() with auxencoding=NULL
165 //      group: generic-conversion
167 #ifdef WITHOUT_ICONV
168         SKIP_TESTCASE;
169 #else
170         r = idn_decodename2(IDN_DECODE_APP, PUNYCODE_NAME, to, sizeof(to),
171                             NULL);
172         ASSERT_RESULT(r, idn_success);
173         ASSERT_STRING(to, UTF8_REVNAME);
174 #endif
177 //# TESTCASE
178 //      title: call encodename() with actions=0
179 //      group: generic-conversion
181         r = idn_encodename(0, UTF8_NAME, to, sizeof(to));
182         ASSERT_RESULT(r, idn_success);
183         ASSERT_STRING(to, UTF8_NAME);
186 //# TESTCASE
187 //      title: call decodename() with actions=0
188 //      group: generic-conversion
190         r = idn_decodename(0, PUNYCODE_NAME, to, sizeof(to));
191         ASSERT_RESULT(r, idn_success);
192         ASSERT_STRING(to, PUNYCODE_NAME);
195 //# TESTCASE
196 //      title: call decodename2() with actions=0
197 //      group: generic-conversion
199 #ifdef WITHOUT_ICONV
200         SKIP_TESTCASE;
201 #else
202         r = idn_decodename2(0, AUX_EUCJP_NAME, to, sizeof(to),
203                             EUCJP_ENCODING_NAME);
204         ASSERT_RESULT(r, idn_success);
205         ASSERT_STRING(to, AUX_EUCJP_NAME);
206 #endif
209 //# TESTCASE
210 //      title: call encodename() with actions=rtcheck
211 //      group: generic-conversion quiet
213         r = idn_encodename(IDN_RTCHECK, EUCJP_NAME, to, sizeof(to));
214         ASSERT_RESULT(r, idn_invalid_action);
217 //# TESTCASE
218 //      title: call encodename() with actions=decode-query
219 //      group: generic-conversion quiet
221         r = idn_encodename(IDN_DECODE_QUERY, EUCJP_NAME, to, sizeof(to));
222         ASSERT_RESULT(r, idn_invalid_action);
225 //# TESTCASE
226 //      title: call encodename() with actions=decode-app
227 //      group: generic-conversion quiet
229         r = idn_encodename(IDN_DECODE_APP, EUCJP_NAME, to, sizeof(to));
230         ASSERT_RESULT(r, idn_invalid_action);
233 //# TESTCASE
234 //      title: call encodename() with actions=decode-stored
235 //      group: generic-conversion quiet
237         r = idn_encodename(IDN_DECODE_STORED, EUCJP_NAME, to, sizeof(to));
238         ASSERT_RESULT(r, idn_invalid_action);
241 //# TESTCASE
242 //      title: call encodename() with actions=(1<<31)
243 //      group: generic-conversion quiet
245         r = idn_encodename(1 << 31, EUCJP_NAME, to, sizeof(to));
246         ASSERT_RESULT(r, idn_invalid_action);
249 //# TESTCASE
250 //      title: call decodename() with actions=localmap
251 //      group: generic-conversion quiet
253         r = idn_decodename(IDN_LOCALMAP, PUNYCODE_NAME, to, sizeof(to));
254         ASSERT_RESULT(r, idn_invalid_action);
257 //# TESTCASE
258 //      title: call decodename2() with actions=localmap
259 //      group: generic-conversion quiet
261 #ifdef WITHOUT_ICONV
262         SKIP_TESTCASE;
263 #else
264         r = idn_decodename2(IDN_LOCALMAP, AUX_EUCJP_NAME, to, sizeof(to),
265                             EUCJP_ENCODING_NAME);
266         ASSERT_RESULT(r, idn_invalid_action);
267 #endif
270 //# TESTCASE
271 //      title: call decodename() with actions=lencheck
272 //      group: generic-conversion quiet
274         r = idn_decodename(IDN_LENCHECK, PUNYCODE_NAME, to, sizeof(to));
275         ASSERT_RESULT(r, idn_invalid_action);
278 //# TESTCASE
279 //      title: call decodename2() with actions=lencheck
280 //      group: generic-conversion quiet
282 #ifdef WITHOUT_ICONV
283         SKIP_TESTCASE;
284 #else
285         r = idn_decodename2(IDN_LENCHECK, AUX_EUCJP_NAME, to, sizeof(to),
286                             EUCJP_ENCODING_NAME);
287         ASSERT_RESULT(r, idn_invalid_action);
288 #endif
291 //# TESTCASE
292 //      title: call decodename() with actions=encode-query
293 //      group: generic-conversion quiet
295         r = idn_decodename(IDN_ENCODE_QUERY, PUNYCODE_NAME, to, sizeof(to));
296         ASSERT_RESULT(r, idn_invalid_action);
299 //# TESTCASE
300 //      title: call decodename2() with actions=encode-query
301 //      group: generic-conversion quiet
303 #ifdef WITHOUT_ICONV
304         SKIP_TESTCASE;
305 #else
306         r = idn_decodename2(IDN_ENCODE_QUERY, AUX_EUCJP_NAME, to, sizeof(to),
307                             EUCJP_ENCODING_NAME);
308         ASSERT_RESULT(r, idn_invalid_action);
309 #endif
312 //# TESTCASE
313 //      title: call decodename() with actions=encode-app
314 //      group: generic-conversion quiet
316         r = idn_decodename(IDN_ENCODE_APP, PUNYCODE_NAME, to, sizeof(to));
317         ASSERT_RESULT(r, idn_invalid_action);
320 //# TESTCASE
321 //      title: call decodename2() with actions=encode-app
322 //      group: generic-conversion quiet
324 #ifdef WITHOUT_ICONV
325         SKIP_TESTCASE;
326 #else
327         r = idn_decodename2(IDN_ENCODE_APP, AUX_EUCJP_NAME, to, sizeof(to),
328                             EUCJP_ENCODING_NAME);
329         ASSERT_RESULT(r, idn_invalid_action);
330 #endif
333 //# TESTCASE
334 //      title: call decodename() with actions=encode-stored
335 //      group: generic-conversion quiet
337         r = idn_decodename(IDN_ENCODE_STORED, PUNYCODE_NAME, to, sizeof(to));
338         ASSERT_RESULT(r, idn_invalid_action);
341 //# TESTCASE
342 //      title: call decodename2() with actions=encode-stored
343 //      group: generic-conversion quiet
345 #ifdef WITHOUT_ICONV
346         SKIP_TESTCASE;
347 #else
348         r = idn_decodename2(IDN_ENCODE_STORED, AUX_EUCJP_NAME, to, sizeof(to),
349                             EUCJP_ENCODING_NAME);
350         ASSERT_RESULT(r, idn_invalid_action);
351 #endif
354 //# TESTCASE
355 //      title: call decodename() with actions=(1<<31)
356 //      group: generic-conversion quiet
358         r = idn_decodename(1 << 31, PUNYCODE_NAME, to, sizeof(to));
359         ASSERT_RESULT(r, idn_invalid_action);
362 //# TESTCASE
363 //      title: call decodename2() with actions=(1<<31)
364 //      group: generic-conversion quiet
366 #ifdef WITHOUT_ICONV
367         SKIP_TESTCASE;
368 #else
369         r = idn_decodename2(1 << 31, AUX_EUCJP_NAME, to, sizeof(to),
370                             EUCJP_ENCODING_NAME);
371         ASSERT_RESULT(r, idn_invalid_action);
372 #endif
375 //# TESTCASE
376 //      title: call encodename() with actions=localconv
377 //      group: generic-conversion quiet
379 #ifndef WITHOUT_ICONV
380         SKIP_TESTCASE;
381 #else
382         r = idn_encodename(IDN_LOCALCONV, UTF8_NAME, to, sizeof(to));
383         ASSERT_RESULT(r, idn_invalid_action);
384 #endif
387 //# TESTCASE
388 //      title: call decodename() with actions=localconv
389 //      group: generic-conversion quiet
391 #ifndef WITHOUT_ICONV
392         SKIP_TESTCASE;
393 #else
394         r = idn_decodename(IDN_LOCALCONV, PUNYCODE_NAME, to, sizeof(to));
395         ASSERT_RESULT(r, idn_invalid_action);
396 #endif
399 //# TESTCASE
400 //      title: call decodename2() with actions=localconv
401 //      group: generic-conversion
403 #ifndef WITHOUT_ICONV
404         SKIP_TESTCASE;
405 #else
406         r = idn_decodename2(IDN_LOCALCONV, AUX_EUCJP_NAME, to, sizeof(to),
407                             EUCJP_ENCODING_NAME);
408         ASSERT_RESULT(r, idn_failure);
409 #endif
412 //# TESTCASE
413 //      title: call enable(0) and then encodename()
414 //      group: generic-conversion
416         idn_enable(0);
417         r = idn_encodename(IDN_ENCODE_APP, UTF8_NAME, to, sizeof(to));
418         ASSERT_RESULT(r, idn_success);
419         ASSERT_STRING(to, UTF8_NAME);
422 //# TESTCASE
423 //      title: call decodename() when IDN_DISABLE is defined
424 //      group: generic-conversion
426         idn_enable(0);
427         r = idn_decodename(IDN_DECODE_APP, PUNYCODE_NAME, to, sizeof(to));
428         ASSERT_RESULT(r, idn_success);
429         ASSERT_STRING(to, PUNYCODE_NAME);
432 //# TESTCASE
433 //      title: call decodename() when IDN_DISABLE is defined
434 //      group: generic-conversion
436 #ifdef WITHOUT_ICONV
437         SKIP_TESTCASE;
438 #else
439         idn_enable(0);
440         r = idn_decodename2(IDN_DECODE_APP, AUX_EUCJP_NAME, to, sizeof(to),
441                             EUCJP_ENCODING_NAME);
442         ASSERT_RESULT(r, idn_success);
443         ASSERT_STRING(to, AUX_EUCJP_NAME);
444 #endif
447 //# TESTCASE
448 //      title: call enable(0) and then encodename()
449 //      group: generic-conversion
451         idn_enable(0);
452         r = idn_encodename(IDN_ENCODE_APP, UTF8_NAME, to, sizeof(to));
453         ASSERT_RESULT(r, idn_success);
454         ASSERT_STRING(to, UTF8_NAME);
457 //# TESTCASE
458 //      title: call enable(0) and then decodename()
459 //      group: generic-conversion
461         idn_enable(0);
462         r = idn_decodename(IDN_DECODE_APP, PUNYCODE_NAME, to, sizeof(to));
463         ASSERT_RESULT(r, idn_success);
464         ASSERT_STRING(to, PUNYCODE_NAME);
467 //# TESTCASE
468 //      title: call enable(0) and then decodename2()
469 //      group: generic-conversion
471 #ifdef WITHOUT_ICONV
472         SKIP_TESTCASE;
473 #else
474         idn_enable(0);
475         r = idn_decodename2(IDN_DECODE_APP, AUX_EUCJP_NAME, to, sizeof(to),
476                             EUCJP_ENCODING_NAME);
477         ASSERT_RESULT(r, idn_success);
478         ASSERT_STRING(to, AUX_EUCJP_NAME);
479 #endif
482 //# TESTCASE
483 //      title: set IDN_DISABLE and call encodename()
484 //      group: generic-conversion
486         setenv("IDN_DISABLE", "1", 1);
487         r = idn_encodename(IDN_ENCODE_APP, UTF8_NAME, to, sizeof(to));
488         ASSERT_RESULT(r, idn_success);
489         ASSERT_STRING(to, UTF8_NAME);
492 //# TESTCASE
493 //      title: set IDN_DISABLE and call decodename()
494 //      group: generic-conversion
496         setenv("IDN_DISABLE", "1", 1);
497         r = idn_decodename(IDN_DECODE_APP, PUNYCODE_NAME, to, sizeof(to));
498         ASSERT_RESULT(r, idn_success);
499         ASSERT_STRING(to, PUNYCODE_NAME);
502 //# TESTCASE
503 //      title: set IDN_DISABLE and call decodename2()
504 //      group: generic-conversion
506 #ifdef WITHOUT_ICONV
507         SKIP_TESTCASE;
508 #else
509         setenv("IDN_DISABLE", "1", 1);
510         r = idn_decodename2(IDN_DECODE_APP, AUX_EUCJP_NAME, to, sizeof(to),
511                             EUCJP_ENCODING_NAME);
512         ASSERT_RESULT(r, idn_success);
513         ASSERT_STRING(to, AUX_EUCJP_NAME);
514 #endif
517 //# TESTCASE
518 //      title: set IDN_DISABLE, and then call enable(1) and encodename()
519 //      group: generic-conversion
521         setenv("IDN_DISABLE", "1", 1);
522         idn_enable(1);
523         r = idn_encodename(IDN_ENCODE_APP, UTF8_NAME, to, sizeof(to));
524         ASSERT_RESULT(r, idn_success);
525         ASSERT_STRING(to, PUNYCODE_NAME);
528 //# TESTCASE
529 //      title: set IDN_DISABLE, and then call enable(1) and decodename()
530 //      group: generic-conversion
532         setenv("IDN_DISABLE", "1", 1);
533         idn_enable(1);
534         r = idn_decodename(IDN_DECODE_APP, PUNYCODE_NAME, to, sizeof(to));
535         ASSERT_RESULT(r, idn_success);
536         ASSERT_STRING(to, UTF8_REVNAME);
539 //# TESTCASE
540 //      title: set IDN_DISABLE, and then call enable(1) and decodename2()
541 //      group: generic-conversion
543 #ifdef WITHOUT_ICONV
544         SKIP_TESTCASE;
545 #else
546         setenv("IDN_DISABLE", "1", 1);
547         idn_enable(1);
548         r = idn_decodename2(IDN_DECODE_APP, AUX_EUCJP_NAME, to, sizeof(to),
549                             EUCJP_ENCODING_NAME);
550         ASSERT_RESULT(r, idn_success);
551         ASSERT_STRING(to, UTF8_REVNAME);
552 #endif
555 //# TESTCASE
556 //      title: overrun test for arg `to' of encodename()
557 //      group: generic-conversion
559         /* Normal case */
560         r = idn_encodename(IDN_ENCODE_APP, UTF8_NAME, to,
561                            strlen(PUNYCODE_NAME) + 1);
562         ASSERT_RESULT(r, idn_success);
563         ASSERT_STRING(to, PUNYCODE_NAME);
565         r = idn_encodename(IDN_ENCODE_APP, UTF8_NAME, to,
566                            strlen(PUNYCODE_NAME));
567         ASSERT_RESULT(r, idn_buffer_overflow);
569         /* enable(0) case */
570         idn_enable(0);
571         r = idn_encodename(IDN_ENCODE_APP, UTF8_NAME, to,
572                            strlen(UTF8_NAME) + 1);
573         ASSERT_RESULT(r, idn_success);
574         ASSERT_STRING(to, UTF8_NAME);
576         r = idn_encodename(IDN_ENCODE_APP, UTF8_NAME, to,
577                            strlen(UTF8_NAME));
578         ASSERT_RESULT(r, idn_buffer_overflow);
580         /* actions=0 case */
581         idn_enable(1);
582         r = idn_encodename(0, UTF8_NAME, to, strlen(UTF8_NAME) + 1);
583         ASSERT_RESULT(r, idn_success);
584         ASSERT_STRING(to, UTF8_NAME);
586         r = idn_encodename(0, UTF8_NAME, to, strlen(UTF8_NAME));
587         ASSERT_RESULT(r, idn_buffer_overflow);
590 //# TESTCASE
591 //      title: overrun test for arg `to' of decodename()
592 //      group: generic-conversion
594         /* Normal case */
595         r = idn_decodename(IDN_DECODE_APP, PUNYCODE_NAME, to,
596                            strlen(UTF8_REVNAME) + 1);
597         ASSERT_RESULT(r, idn_success);
598         ASSERT_STRING(to, UTF8_REVNAME);
600         r = idn_decodename(IDN_DECODE_APP, PUNYCODE_NAME, to,
601                            strlen(UTF8_REVNAME));
602         ASSERT_RESULT(r, idn_buffer_overflow);
604         /* idn_enable(0) case */
605         idn_enable(0);
606         r = idn_decodename(IDN_DECODE_APP, PUNYCODE_NAME, to,
607                            strlen(PUNYCODE_NAME) + 1);
608         ASSERT_RESULT(r, idn_success);
609         ASSERT_STRING(to, PUNYCODE_NAME);
611         r = idn_decodename(IDN_DECODE_APP, PUNYCODE_NAME, to,
612                            strlen(PUNYCODE_NAME));
613         ASSERT_RESULT(r, idn_buffer_overflow);
615         /* actions=0 case */
616         idn_enable(1);
617         r = idn_decodename(0, PUNYCODE_NAME, to, strlen(PUNYCODE_NAME) + 1);
618         ASSERT_RESULT(r, idn_success);
619         ASSERT_STRING(to, PUNYCODE_NAME);
621         r = idn_decodename(0, PUNYCODE_NAME, to, strlen(PUNYCODE_NAME));
622         ASSERT_RESULT(r, idn_buffer_overflow);
625 //# TESTCASE
626 //      title: overrun test for arg `to' of decodename2()
627 //      group: generic-conversion
629 #ifdef WITHOUT_ICONV
630         SKIP_TESTCASE;
631 #else
632         /* Normal case */
633         r = idn_decodename2(IDN_DECODE_APP, AUX_EUCJP_NAME, to,
634                             strlen(UTF8_REVNAME) + 1, EUCJP_ENCODING_NAME);
635         ASSERT_RESULT(r, idn_success);
636         ASSERT_STRING(to, UTF8_REVNAME);
638         r = idn_decodename2(IDN_DECODE_APP, AUX_EUCJP_NAME, to,
639                             strlen(UTF8_REVNAME), EUCJP_ENCODING_NAME);
640         ASSERT_RESULT(r, idn_buffer_overflow);
642         /* idn_enable(0) case */
643         idn_enable(0);
644         r = idn_decodename2(IDN_DECODE_APP, AUX_EUCJP_NAME, to,
645                             strlen(AUX_EUCJP_NAME) + 1, EUCJP_ENCODING_NAME);
646         ASSERT_RESULT(r, idn_success);
647         ASSERT_STRING(to, AUX_EUCJP_NAME);
649         r = idn_decodename2(IDN_DECODE_APP, AUX_EUCJP_NAME, to,
650                             strlen(AUX_EUCJP_NAME), EUCJP_ENCODING_NAME);
651         ASSERT_RESULT(r, idn_buffer_overflow);
653         /* actions=0 case */
654         idn_enable(1);
655         r = idn_decodename2(0, AUX_EUCJP_NAME, to, strlen(AUX_EUCJP_NAME) + 1,
656                             EUCJP_ENCODING_NAME);
657         ASSERT_RESULT(r, idn_success);
658         ASSERT_STRING(to, AUX_EUCJP_NAME);
660         r = idn_decodename2(0, AUX_EUCJP_NAME, to, strlen(AUX_EUCJP_NAME),
661                             EUCJP_ENCODING_NAME);
662         ASSERT_RESULT(r, idn_buffer_overflow);
664 #endif
667 //# TESTCASE
668 //      title: call encodename() with tolen=0
669 //      group: generic-conversion
671         r = idn_encodename(IDN_ENCODE_APP, UTF8_NAME, to, 0);
672         ASSERT_RESULT(r, idn_buffer_overflow);
675 //# TESTCASE
676 //      title: call decodename() with tolen=0
677 //      group: generic-conversion
679         r = idn_decodename(IDN_DECODE_APP, PUNYCODE_NAME, to, 0);
680         ASSERT_RESULT(r, idn_buffer_overflow);
683 //# TESTCASE
684 //      title: call decodename2() with tolen=0
685 //      group: generic-conversion
687 #ifdef WITHOUT_ICONV
688         SKIP_TESTCASE;
689 #else
690         r = idn_decodename2(IDN_DECODE_APP, AUX_EUCJP_NAME, to, 0,
691                             EUCJP_ENCODING_NAME);
692         ASSERT_RESULT(r, idn_buffer_overflow);
693 #endif
696 //# TESTCASE
697 //      title: convert an empty string using encodename()
698 //      group: generic-conversion
700         r = idn_encodename(IDN_ENCODE_APP, "", to, sizeof(to));
701         ASSERT_RESULT(r, idn_success);
702         ASSERT_STRING(to, "");
705 //# TESTCASE
706 //      title: convert an empty string using decodename()
707 //      group: generic-conversion
709         r = idn_decodename(IDN_DECODE_APP, "", to, sizeof(to));
710         ASSERT_RESULT(r, idn_success);
711         ASSERT_STRING(to, "");
714 //# TESTCASE
715 //      title: convert an empty string using decodename2()
716 //      group: generic-conversion
718 #ifdef WITHOUT_ICONV
719         SKIP_TESTCASE;
720 #else
721         r = idn_decodename2(IDN_DECODE_APP, "", to, sizeof(to),
722                             EUCJP_ENCODING_NAME);
723         ASSERT_RESULT(r, idn_success);
724         ASSERT_STRING(to, "");
725 #endif
728 //# TESTCASE
729 //      title: prohcheck by encodename()
730 //      group: generic-conversion
732         /* U+1680: prohibited character */
733         r = idn_encodename(IDN_PROHCHECK, "<U+1680>", to, sizeof(to));
734         ASSERT_RESULT(r, idn_prohibited);
737 //# TESTCASE
738 //      title: unascheck by encodename()
739 //      group: generic-conversion
741         /* U+0221: unassigned codepoint */
742         r = idn_encodename(IDN_UNASCHECK, "<U+0221>", to, sizeof(to));
743         ASSERT_RESULT(r, idn_prohibited);
746 //# TESTCASE
747 //      title: bidicheck by encodename()
748 //      group: generic-conversion
750         /* U+05D0:   bidirectional property is "R" */
751         /* `a':      bidirectional property is "L" */
752         /* `0', `-': bidirectional property is "N" */
753         r = idn_encodename(IDN_BIDICHECK, "<U+05D0>", to, sizeof(to));
754         ASSERT_RESULT(r, idn_success);
756         r = idn_encodename(IDN_BIDICHECK, "<U+05D0><U+05D0>",
757                            to, sizeof(to));
758         ASSERT_RESULT(r, idn_success);
760         r = idn_encodename(IDN_BIDICHECK, "<U+05D0><U+05D0>-a",
761                            to, sizeof(to));
762         ASSERT_RESULT(r, idn_prohibited);
764         r = idn_encodename(IDN_BIDICHECK, "<U+05D0>-a-<U+05D0>",
765                            to, sizeof(to));
766         ASSERT_RESULT(r, idn_prohibited);
768         r = idn_encodename(IDN_BIDICHECK, "a-<U+05D0><U+05D0>",
769                            to, sizeof(to));
770         ASSERT_RESULT(r, idn_prohibited);
772         r = idn_encodename(IDN_BIDICHECK, "<U+05D0><U+05D0>-0",
773                            to, sizeof(to));
774         ASSERT_RESULT(r, idn_prohibited);
776         r = idn_encodename(IDN_BIDICHECK, "<U+05D0>-0-<U+05D0>",
777                            to, sizeof(to));
778         ASSERT_RESULT(r, idn_success);
780         r = idn_encodename(IDN_BIDICHECK, "0-<U+05D0><U+05D0>",
781                            to, sizeof(to));
782         ASSERT_RESULT(r, idn_prohibited);
785 //# TESTCASE
786 //      title: asccheck by encodename()
787 //      group: generic-conversion
789         r = idn_encodename(IDN_ASCCHECK, "-name", to, sizeof(to));
790         ASSERT_RESULT(r, idn_prohibited);
792         r = idn_encodename(IDN_ASCCHECK, "name-", to, sizeof(to));
793         ASSERT_RESULT(r, idn_prohibited);
795         r = idn_encodename(IDN_ASCCHECK, "n ame", to, sizeof(to));
796         ASSERT_RESULT(r, idn_prohibited);
799 //# TESTCASE
800 //      title: lencheck by encodename()
801 //      group: generic-conversion
803         r = idn_encodename(IDN_LENCHECK,
804                            "123456789-123456789-123456789-123456789-"
805                            "123456789-123456789-123", to, sizeof(to));
806         ASSERT_RESULT(r, idn_success);
808         r = idn_encodename(IDN_LENCHECK,
809                            "123456789-123456789-123456789-123456789-"
810                            "123456789-123456789-1234", to, sizeof(to));
811         ASSERT_RESULT(r, idn_invalid_length);
813         r = idn_encodename(IDN_LENCHECK, "a..b", to, sizeof(to));
814         ASSERT_RESULT(r, idn_invalid_length);
817 //# TESTCASE
818 //      title: rtcheck non-prohchecked label by decodename()
819 //      group: generic-conversion
821         /* "xn--6ue" -> "U+1680" (prohibited character) */
822         r = idn_decodename(IDN_RTCHECK, "xn--6ue", to, sizeof(to));
823         ASSERT_RESULT(r, idn_success);
824         ASSERT_STRING(to, "xn--6ue");
827 //# TESTCASE
828 //      title: rtcheck non-unaschecked label by decodename()
829 //      group: generic-conversion
831         /* "xn--6la" -> "U+0221" (unassigned codepoint) */
832         r = idn_decodename(IDN_IDNCONV | IDN_RTCHECK | IDN_UNASCHECK,
833                            "xn--6la", to, sizeof(to));
834         ASSERT_RESULT(r, idn_success);
835         ASSERT_STRING(to, "xn--6la");
838 //# TESTCASE
839 //      title: rtcheck non-ascchecked label by decodename()
840 //      group: generic-conversion
842         /* "xn----x7t" -> "- U+3042" */
843         r = idn_decodename(IDN_IDNCONV | IDN_RTCHECK | IDN_ASCCHECK,
844                            "xn----x7t", to, sizeof(to));
845         ASSERT_RESULT(r, idn_success);
846         ASSERT_STRING(to, "xn----x7t");
848         /* "xn----w7t" -> "U+3042 -" */
849         r = idn_decodename(IDN_IDNCONV | IDN_RTCHECK | IDN_ASCCHECK,
850                            "xn----w7t", to, sizeof(to));
851         ASSERT_RESULT(r, idn_success);
852         ASSERT_STRING(to, "xn----w7t");
855 //# TESTCASE
856 //      title: rtcheck non-lenchecked label by decodename()
857 //      group: generic-conversion
859         /* `s1' has 63 characters */
860         const char *s1 =
861             "xn--l8jaa5522a8sj38bzugvvblo3y90fjzgvxlmxscifws3d43odzaq6aj340b";
863         const char *s1rev =
864             "<U+9752><U+68EE><U+5CA9><U+624B><U+5BAE><U+57CE><U+79CB><U+7530>"
865             "<U+5C71><U+5F62><U+798F><U+5CF6><U+6771><U+4EAC><U+795E><U+5948>"
866             "<U+5DDD><U+3042><U+3042><U+3042>";
868         /* `s2' has 64 characters */
869         const char *s2 =
870             "xn--a-w7ta6522a8sj38bzugvvblo3y90fjzgvxlmxscifws3d43odzaq6aj340b";
872         /* `s3' has an empty label */
873         const char *s3 = "a..b";
875         r = idn_decodename(IDN_IDNCONV | IDN_RTCHECK, s1, to, sizeof(to));
876         ASSERT_RESULT(r, idn_success);
877         ASSERT_STRING(to, s1rev);
879         r = idn_decodename(IDN_IDNCONV | IDN_RTCHECK, s2, to, sizeof(to));
880         ASSERT_RESULT(r, idn_success);
881         ASSERT_STRING(to, s2);
883         r = idn_decodename(IDN_IDNCONV | IDN_RTCHECK, s3, to, sizeof(to));
884         ASSERT_RESULT(r, idn_success);
885         ASSERT_STRING(to, s3);
888 //# TESTCASE
889 //      title: rtcheck non-prohchecked label by decodename2()
890 //      group: generic-conversion
892 #ifdef WITHOUT_ICONV
893         SKIP_TESTCASE;
894 #else
895         /* "xn--6ue" -> "U+1680" (prohibited character) */
896         r = idn_decodename2(IDN_RTCHECK, "xn--6ue", to, sizeof(to),
897                             EUCJP_ENCODING_NAME);
898         ASSERT_RESULT(r, idn_success);
899         ASSERT_STRING(to, "xn--6ue");
900 #endif
903 //# TESTCASE
904 //      title: rtcheck non-unaschecked label by decodename2()
905 //      group: generic-conversion
907 #ifdef WITHOUT_ICONV
908         SKIP_TESTCASE;
909 #else
910         /* "xn--6la" -> "U+0221" (unassigned codepoint) */
911         r = idn_decodename2(IDN_IDNCONV | IDN_RTCHECK | IDN_UNASCHECK,
912                             "xn--6la", to, sizeof(to), EUCJP_ENCODING_NAME);
913         ASSERT_RESULT(r, idn_success);
914         ASSERT_STRING(to, "xn--6la");
915 #endif
918 //# TESTCASE
919 //      title: rtcheck non-ascchecked label by decodename2()
920 //      group: generic-conversion
922 #ifdef WITHOUT_ICONV
923         SKIP_TESTCASE;
924 #else
925         /* "xn----x7t" -> "- U+3042" */
926         r = idn_decodename2(IDN_IDNCONV | IDN_RTCHECK | IDN_ASCCHECK,
927                             "xn----x7t", to, sizeof(to), EUCJP_ENCODING_NAME);
929         ASSERT_RESULT(r, idn_success);
930         ASSERT_STRING(to, "xn----x7t");
932         /* "xn----w7t" -> "U+3042 -" */
933         r = idn_decodename2(IDN_IDNCONV | IDN_RTCHECK | IDN_ASCCHECK,
934                             "xn----w7t", to, sizeof(to), EUCJP_ENCODING_NAME);
935         ASSERT_RESULT(r, idn_success);
936         ASSERT_STRING(to, "xn----w7t");
937 #endif
940 //# TESTCASE
941 //      title: rtcheck non-lenchecked label by decodename2()
942 //      group: generic-conversion
944 #ifdef WITHOUT_ICONV
945         SKIP_TESTCASE;
946 #else
947         /* `s1' has 63 characters */
948         const char *s1 =
949             "xn--l8jaa5522a8sj38bzugvvblo3y90fjzgvxlmxscifws3d43odzaq6aj340b";
951         const char *s1rev =
952             "<U+9752><U+68EE><U+5CA9><U+624B><U+5BAE><U+57CE><U+79CB><U+7530>"
953             "<U+5C71><U+5F62><U+798F><U+5CF6><U+6771><U+4EAC><U+795E><U+5948>"
954             "<U+5DDD><U+3042><U+3042><U+3042>";
956         /* `s2' has 64 characters */
957         const char *s2 =
958             "xn--a-w7ta6522a8sj38bzugvvblo3y90fjzgvxlmxscifws3d43odzaq6aj340b";
960         /* `s3' has an empty label */
961         const char *s3 = "a..b";
963         r = idn_decodename2(IDN_IDNCONV | IDN_RTCHECK, s1, to, sizeof(to),
964                             EUCJP_ENCODING_NAME);
965         ASSERT_RESULT(r, idn_success);
966         ASSERT_STRING(to, s1rev);
968         r = idn_decodename2(IDN_IDNCONV | IDN_RTCHECK, s2, to, sizeof(to),
969                             EUCJP_ENCODING_NAME);
970         ASSERT_RESULT(r, idn_success);
971         ASSERT_STRING(to, s2);
973         r = idn_decodename(IDN_IDNCONV | IDN_RTCHECK, s3, to, sizeof(to));
974         ASSERT_RESULT(r, idn_success);
975         ASSERT_STRING(to, s3);
976 #endif
979 //# TESTCASE
980 //      title: pass broken string as `from' to encodename()
981 //      group: generic-conversion quiet
983         /* "\xe3\x21" is not valid UTF-8 string */
984         r = idn_encodename(IDN_ENCODE_APP, "\xe3\x21", to, sizeof(to));
985         ASSERT_RESULT(r, idn_invalid_encoding);
988 //# TESTCASE
989 //      title: pass broken string as `from' to decodename()
990 //      group: generic-conversion quiet
992         /* "\xe3\x21" is not valid UTF-8 string */
993         r = idn_decodename(IDN_DECODE_APP, "\xe3\x21", to, sizeof(to));
994         ASSERT_RESULT(r, idn_invalid_encoding);
997 //# TESTCASE
998 //      title: pass broken string as `from' to decodename2()
999 //      group: generic-conversion quiet
1001 #ifdef WITHOUT_ICONV
1002         SKIP_TESTCASE;
1003 #else
1004         /* "\xa4\x21" is not valid EUC-JP string */
1005         r = idn_decodename2(IDN_DECODE_APP, "\xa4\x21", to, sizeof(to),
1006                             EUCJP_ENCODING_NAME);
1007         ASSERT_RESULT(r, idn_invalid_encoding);
1008 #endif