2 static char *rcsid = "Id: res.tsy,v 1.1 2003/06/04 00:26:59 marka Exp ";
6 * Copyright (c) 2002 Japan Network Information Center.
9 * By using this file, you agree to the terms and conditions set forth bellow.
11 * LICENSE TERMS AND CONDITIONS
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.
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.
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.
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."
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
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.
58 #ifndef EUCJP_ENCODING_NAME
59 #define EUCJP_ENCODING_NAME "eucJP"
63 * U+304B: hiragana letter KA
64 * U+3099: combining katakana-hiragana voiced sound mark
66 * map("U+304B U+3099") -> "U+304C"
68 * U+304C: hiragana letter GA
70 #define UTF8_NAME "A<U+304B><U+3099>"
71 #define UTF8_REVNAME "a<U+304C>"
74 * A4AC: hiragana letter GA (in EUC-JP)
76 #define EUCJP_NAME "\xa4\xac"
77 #define EUCJP_REVNAME "\xa4\xac"
80 * Conversion result of "U+304B U+3099 A"
82 #define PUNYCODE_NAME "xn--a-i8t"
85 * Conversion result of "A U+304B U+3099" (in EUC-JP).
87 #define AUX_EUCJP_NAME "xn--a-i\xa3\xb8t"
89 //--------------------------------------------------------------------
90 // Setups and Teardowns.
91 //--------------------------------------------------------------------
94 // group: generic-conversion
96 // Initialize the `resconf' context.
97 // Set local encoding to `UTF-8'.
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);
117 // group: generic-conversion
119 idn_resconf_destroy(ctx);
125 // Set log level to `fatal' to supress log messages.
129 saved_log_level = idn_log_getlevel();
130 idn_log_setlevel(idn_log_level_fatal);
136 // Restore log level.
138 idn_log_setlevel(saved_log_level);
141 //--------------------------------------------------------------------
143 //--------------------------------------------------------------------
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);
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);
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);
170 ASSERT_RESULT(r, idn_failure);
172 ASSERT_RESULT(r, idn_success);
173 ASSERT_STRING(to, UTF8_REVNAME);
178 // title: call decodename2() with auxencoding=NULL
179 // group: generic-conversion
184 r = idn_res_decodename2(ctx, IDN_DECODE_APP, PUNYCODE_NAME, to, sizeof(to),
186 ASSERT_RESULT(r, idn_success);
187 ASSERT_STRING(to, UTF8_REVNAME);
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);
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);
210 // title: call decodename2() with actions=0
211 // group: generic-conversion
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);
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);
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);
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);
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);
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);
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);
272 // title: call decodename2() with actions=localmap
273 // group: generic-conversion quiet
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);
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);
293 // title: call decodename2() with actions=lencheck
294 // group: generic-conversion quiet
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);
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);
314 // title: call decodename2() with actions=encode-query
315 // group: generic-conversion quiet
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);
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);
335 // title: call decodename2() with actions=encode-app
336 // group: generic-conversion quiet
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);
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);
356 // title: call decodename2() with actions=encode-stored
357 // group: generic-conversion quiet
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);
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);
377 // title: call decodename2() with actions=(1<<31)
378 // group: generic-conversion quiet
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);
390 // title: call encodename() with actions=localconv
391 // group: generic-conversion quiet
393 #ifndef WITHOUT_ICONV
396 r = idn_res_encodename(ctx, IDN_LOCALCONV, UTF8_NAME, to, sizeof(to));
397 ASSERT_RESULT(r, idn_invalid_action);
402 // title: call decodename() with actions=localconv
403 // group: generic-conversion quiet
405 #ifndef WITHOUT_ICONV
408 r = idn_res_decodename(ctx, IDN_LOCALCONV, PUNYCODE_NAME, to, sizeof(to));
409 ASSERT_RESULT(r, idn_invalid_action);
414 // title: call decodename2() with actions=localconv
415 // group: generic-conversion
417 #ifndef WITHOUT_ICONV
420 r = idn_res_decodename2(ctx, IDN_LOCALCONV, AUX_EUCJP_NAME, to, sizeof(to),
421 EUCJP_ENCODING_NAME);
422 ASSERT_RESULT(r, idn_failure);
427 // title: call enable(0) and then encodename()
428 // group: generic-conversion
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);
437 // title: call decodename() when IDN_DISABLE is defined
438 // group: generic-conversion
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);
447 // title: call decodename() when IDN_DISABLE is defined
448 // group: generic-conversion
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);
462 // title: call enable(0) and then encodename()
463 // group: generic-conversion
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);
472 // title: call enable(0) and then decodename()
473 // group: generic-conversion
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);
482 // title: call enable(0) and then decodename2()
483 // group: generic-conversion
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);
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);
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);
517 // title: set IDN_DISABLE and call decodename2()
518 // group: generic-conversion
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);
532 // title: set IDN_DISABLE, and then call enable(1) and encodename()
533 // group: generic-conversion
535 setenv("IDN_DISABLE", "1", 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);
543 // title: set IDN_DISABLE, and then call enable(1) and decodename()
544 // group: generic-conversion
546 setenv("IDN_DISABLE", "1", 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);
554 // title: set IDN_DISABLE, and then call enable(1) and decodename2()
555 // group: generic-conversion
560 setenv("IDN_DISABLE", "1", 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);
570 // title: overrun test for arg `to' of encodename()
571 // group: generic-conversion
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);
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,
592 ASSERT_RESULT(r, idn_buffer_overflow);
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);
605 // title: overrun test for arg `to' of decodename()
606 // group: generic-conversion
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 */
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);
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);
642 // title: overrun test for arg `to' of decodename2()
643 // group: generic-conversion
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 */
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);
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);
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);
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);
700 // title: call decodename2() with tolen=0
701 // group: generic-conversion
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);
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, "");
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, "");
731 // title: convert an empty string using decodename2()
732 // group: generic-conversion
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, "");
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);
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);
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>",
774 ASSERT_RESULT(r, idn_success);
776 r = idn_res_encodename(ctx, IDN_BIDICHECK, "<U+05D0><U+05D0>-a",
778 ASSERT_RESULT(r, idn_prohibited);
780 r = idn_res_encodename(ctx, IDN_BIDICHECK, "<U+05D0>-a-<U+05D0>",
782 ASSERT_RESULT(r, idn_prohibited);
784 r = idn_res_encodename(ctx, IDN_BIDICHECK, "a-<U+05D0><U+05D0>",
786 ASSERT_RESULT(r, idn_prohibited);
788 r = idn_res_encodename(ctx, IDN_BIDICHECK, "<U+05D0><U+05D0>-0",
790 ASSERT_RESULT(r, idn_prohibited);
792 r = idn_res_encodename(ctx, IDN_BIDICHECK, "<U+05D0>-0-<U+05D0>",
794 ASSERT_RESULT(r, idn_success);
796 r = idn_res_encodename(ctx, IDN_BIDICHECK, "0-<U+05D0><U+05D0>",
798 ASSERT_RESULT(r, idn_prohibited);
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);
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);
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");
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");
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");
872 // title: rtcheck non-lenchecked label by decodename()
873 // group: generic-conversion
875 /* `s1' has 63 characters */
877 "xn--l8jaa5522a8sj38bzugvvblo3y90fjzgvxlmxscifws3d43odzaq6aj340b";
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 */
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);
905 // title: rtcheck non-prohchecked label by decodename2()
906 // group: generic-conversion
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");
920 // title: rtcheck non-unaschecked label by decodename2()
921 // group: generic-conversion
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");
935 // title: rtcheck non-ascchecked label by decodename2()
936 // group: generic-conversion
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");
957 // title: rtcheck non-lenchecked label by decodename2()
958 // group: generic-conversion
963 /* `s1' has 63 characters */
965 "xn--l8jaa5522a8sj38bzugvvblo3y90fjzgvxlmxscifws3d43odzaq6aj340b";
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 */
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);
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);
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);
1014 // title: pass broken string as `from' to decodename2()
1015 // group: generic-conversion quiet
1017 #ifdef WITHOUT_ICONV
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);