2 *******************************************************************************
4 * Copyright (C) 2003-2006, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: testidna.cpp
10 * tab size: 8 (not used)
13 * created on: 2003feb1
14 * created by: Ram Viswanadha
17 #include "unicode/utypes.h"
19 #if !UCONFIG_NO_IDNA && !UCONFIG_NO_TRANSLITERATION
25 #include "unicode/ustring.h"
26 #include "unicode/usprep.h"
27 #include "unicode/uniset.h"
31 #include "unicode/putil.h"
34 static UChar unicodeIn
[][41] ={
36 0x0644, 0x064A, 0x0647, 0x0645, 0x0627, 0x0628, 0x062A, 0x0643, 0x0644,
37 0x0645, 0x0648, 0x0634, 0x0639, 0x0631, 0x0628, 0x064A, 0x061F, 0x0000
40 0x4ED6, 0x4EEC, 0x4E3A, 0x4EC0, 0x4E48, 0x4E0D, 0x8BF4, 0x4E2D, 0x6587,
44 0x0050, 0x0072, 0x006F, 0x010D, 0x0070, 0x0072, 0x006F, 0x0073, 0x0074,
45 0x011B, 0x006E, 0x0065, 0x006D, 0x006C, 0x0075, 0x0076, 0x00ED, 0x010D,
46 0x0065, 0x0073, 0x006B, 0x0079, 0x0000
49 0x05DC, 0x05DE, 0x05D4, 0x05D4, 0x05DD, 0x05E4, 0x05E9, 0x05D5, 0x05D8,
50 0x05DC, 0x05D0, 0x05DE, 0x05D3, 0x05D1, 0x05E8, 0x05D9, 0x05DD, 0x05E2,
51 0x05D1, 0x05E8, 0x05D9, 0x05EA, 0x0000
54 0x092F, 0x0939, 0x0932, 0x094B, 0x0917, 0x0939, 0x093F, 0x0928, 0x094D,
55 0x0926, 0x0940, 0x0915, 0x094D, 0x092F, 0x094B, 0x0902, 0x0928, 0x0939,
56 0x0940, 0x0902, 0x092C, 0x094B, 0x0932, 0x0938, 0x0915, 0x0924, 0x0947,
57 0x0939, 0x0948, 0x0902, 0x0000
60 0x306A, 0x305C, 0x307F, 0x3093, 0x306A, 0x65E5, 0x672C, 0x8A9E, 0x3092,
61 0x8A71, 0x3057, 0x3066, 0x304F, 0x308C, 0x306A, 0x3044, 0x306E, 0x304B,
66 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
67 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
68 0xC5BC, 0xB9C8, 0xB098, 0xC88B, 0xC744, 0xAE4C, 0x0000
72 0x043F, 0x043E, 0x0447, 0x0435, 0x043C, 0x0443, 0x0436, 0x0435, 0x043E,
73 0x043D, 0x0438, 0x043D, 0x0435, 0x0433, 0x043E, 0x0432, 0x043E, 0x0440,
74 0x044F, 0x0442, 0x043F, 0x043E, 0x0440, 0x0443, 0x0441, 0x0441, 0x043A,
78 0x0050, 0x006F, 0x0072, 0x0071, 0x0075, 0x00E9, 0x006E, 0x006F, 0x0070,
79 0x0075, 0x0065, 0x0064, 0x0065, 0x006E, 0x0073, 0x0069, 0x006D, 0x0070,
80 0x006C, 0x0065, 0x006D, 0x0065, 0x006E, 0x0074, 0x0065, 0x0068, 0x0061,
81 0x0062, 0x006C, 0x0061, 0x0072, 0x0065, 0x006E, 0x0045, 0x0073, 0x0070,
82 0x0061, 0x00F1, 0x006F, 0x006C, 0x0000
85 0x4ED6, 0x5011, 0x7232, 0x4EC0, 0x9EBD, 0x4E0D, 0x8AAA, 0x4E2D, 0x6587,
89 0x0054, 0x1EA1, 0x0069, 0x0073, 0x0061, 0x006F, 0x0068, 0x1ECD, 0x006B,
90 0x0068, 0x00F4, 0x006E, 0x0067, 0x0074, 0x0068, 0x1EC3, 0x0063, 0x0068,
91 0x1EC9, 0x006E, 0x00F3, 0x0069, 0x0074, 0x0069, 0x1EBF, 0x006E, 0x0067,
92 0x0056, 0x0069, 0x1EC7, 0x0074, 0x0000
95 0x0033, 0x5E74, 0x0042, 0x7D44, 0x91D1, 0x516B, 0x5148, 0x751F, 0x0000
98 0x5B89, 0x5BA4, 0x5948, 0x7F8E, 0x6075, 0x002D, 0x0077, 0x0069, 0x0074,
99 0x0068, 0x002D, 0x0053, 0x0055, 0x0050, 0x0045, 0x0052, 0x002D, 0x004D,
100 0x004F, 0x004E, 0x004B, 0x0045, 0x0059, 0x0053, 0x0000
103 0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x002D, 0x0041, 0x006E, 0x006F,
104 0x0074, 0x0068, 0x0065, 0x0072, 0x002D, 0x0057, 0x0061, 0x0079, 0x002D,
105 0x305D, 0x308C, 0x305E, 0x308C, 0x306E, 0x5834, 0x6240, 0x0000
108 0x3072, 0x3068, 0x3064, 0x5C4B, 0x6839, 0x306E, 0x4E0B, 0x0032, 0x0000
111 0x004D, 0x0061, 0x006A, 0x0069, 0x3067, 0x004B, 0x006F, 0x0069, 0x3059,
112 0x308B, 0x0035, 0x79D2, 0x524D, 0x0000
115 0x30D1, 0x30D5, 0x30A3, 0x30FC, 0x0064, 0x0065, 0x30EB, 0x30F3, 0x30D0,
119 0x305D, 0x306E, 0x30B9, 0x30D4, 0x30FC, 0x30C9, 0x3067, 0x0000
121 // test non-BMP code points
123 0xD800, 0xDF00, 0xD800, 0xDF01, 0xD800, 0xDF02, 0xD800, 0xDF03, 0xD800, 0xDF05,
124 0xD800, 0xDF06, 0xD800, 0xDF07, 0xD800, 0xDF09, 0xD800, 0xDF0A, 0xD800, 0xDF0B,
128 0xD800, 0xDF0D, 0xD800, 0xDF0C, 0xD800, 0xDF1E, 0xD800, 0xDF0F, 0xD800, 0xDF16,
129 0xD800, 0xDF15, 0xD800, 0xDF14, 0xD800, 0xDF12, 0xD800, 0xDF10, 0xD800, 0xDF20,
135 0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac
139 0x0062, 0x006f, 0x006e, 0x0121, 0x0075, 0x0073, 0x0061, 0x0127,
144 0x043f, 0x043e, 0x0447, 0x0435, 0x043c, 0x0443, 0x0436, 0x0435,
145 0x043e, 0x043d, 0x0438, 0x043d, 0x0435, 0x0433, 0x043e, 0x0432,
146 0x043e, 0x0440, 0x044f, 0x0442, 0x043f, 0x043e, 0x0440, 0x0443,
147 0x0441, 0x0441, 0x043a, 0x0438
155 static const char *asciiIn
[] = {
156 "xn--egbpdaj6bu4bxfgehfvwxn",
157 "xn--ihqwcrb4cv8a8dqg056pqjye",
158 "xn--Proprostnemluvesky-uyb24dma41a",
159 "xn--4dbcagdahymbxekheh6e0a7fei0b",
160 "xn--i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd",
161 "xn--n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa",
162 /* "xn--989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c",*/
163 "xn--b1abfaaepdrnnbgefbaDotcwatmq2g4l",
164 "xn--PorqunopuedensimplementehablarenEspaol-fmd56a",
165 "xn--ihqwctvzc91f659drss3x8bo0yb",
166 "xn--TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g",
167 "xn--3B-ww4c5e180e575a65lsy2b",
168 "xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n",
169 "xn--Hello-Another-Way--fc4qua05auwb3674vfr0b",
170 "xn--2-u9tlzr9756bt3uc0v",
171 "xn--MajiKoi5-783gue6qz075azm5e",
172 "xn--de-jg4avhby1noc0d",
173 "xn--d9juau41awczczp",
175 "XN--db8CBHEJLGH4E0AL",
176 "xn--hxargifdar", // Greek
177 "xn--bonusaa-5bb1da", // Maltese
178 "xn--b1abfaaepdrnnbgefbadotcwatmq2g4l", // Russian (Cyrillic)
182 static const char *domainNames
[] = {
183 "slip129-37-118-146.nc.us.ibm.net",
184 "saratoga.pe.utexas.edu",
185 "dial-120-45.ots.utexas.edu",
186 "woo-085.dorms.waller.net",
187 "hd30-049.hil.compuserve.com",
188 "pem203-31.pe.ttu.edu",
189 "56K-227.MaxTNT3.pdq.net",
190 "dial-36-2.ots.utexas.edu",
191 "slip129-37-23-152.ga.us.ibm.net",
192 "ts45ip119.cadvision.com",
193 "sdn-ts-004txaustP05.dialsprint.net",
194 "bar-tnt1s66.erols.com",
195 "101.st-louis-15.mo.dial-access.att.net",
197 "dial-13-2.ots.utexas.edu",
198 "net-redynet29.datamarkets.com.ar",
199 "ccs-shiva28.reacciun.net.ve",
200 "7.houston-11.tx.dial-access.att.net",
201 "ingw129-37-120-26.mo.us.ibm.net",
202 "dialup6.austintx.com",
204 "slip129-37-119-194.nc.us.ibm.net",
205 "cs7.dillons.co.uk.203.119.193.in-addr.arpa",
206 "swprd1.innovplace.saskatoon.sk.ca",
207 "bikini.bologna.maraut.it",
208 "node91.subnet159-198-79.baxter.com",
209 "cust19.max5.new-york.ny.ms.uu.net",
210 "balexander.slip.andrew.cmu.edu",
211 "pool029.max2.denver.co.dynip.alter.net",
212 "cust49.max9.new-york.ny.ms.uu.net",
213 "s61.abq-dialin2.hollyberry.com",
214 "\\u0917\\u0928\\u0947\\u0936.sanjose.ibm.com", //':'(0x003a) produces U_IDNA_STD3_ASCII_RULES_ERROR
216 // "www.\\u00E0\\u00B3\\u00AF.com",//' ' (0x0020) produces U_IDNA_STD3_ASCII_RULES_ERROR
217 "www.\\u00C2\\u00A4.com",
218 "www.\\u00C2\\u00A3.com",
219 // "\\u0025", //'%' (0x0025) produces U_IDNA_STD3_ASCII_RULES_ERROR
220 // "\\u005C\\u005C", //'\' (0x005C) produces U_IDNA_STD3_ASCII_RULES_ERROR
226 // These yeild U_IDNA_PROHIBITED_ERROR
227 //"\\u00CF\\u0082.com",
228 //"\\u00CE\\u00B2\\u00C3\\u009Fss.com",
229 //"\\u00E2\\u0098\\u00BA.com",
230 "\\u00C3\\u00BC.com",
234 typedef struct ErrorCases ErrorCases
;
236 static struct ErrorCases
{
241 UBool useSTD3ASCIIRules
;
248 0x0077, 0x0077, 0x0077, 0x002e, /* www. */
249 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
250 0x070F,/*prohibited*/
251 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
252 0x002e, 0x0063, 0x006f, 0x006d, /* com. */
255 "www.XN--8mb5595fsoa28orucya378bqre2tcwop06c5qbw82a1rffmae0361dea96b.com",
256 U_IDNA_PROHIBITED_ERROR
,
262 0x0077, 0x0077, 0x0077, 0x002e, /* www. */
263 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
264 0x0221, 0x0234/*Unassigned code points*/,
265 0x002e, 0x0063, 0x006f, 0x006d, /* com. */
268 "www.XN--6lA2Bz548Fj1GuA391Bf1Gb1N59Ab29A7iA.com",
270 U_IDNA_UNASSIGNED_ERROR
,
275 0x0077, 0x0077, 0x0077, 0x002e, /* www. */
276 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
277 0x0644, 0x064A, 0x0647,/*Arabic code points. Cannot mix RTL with LTR*/
278 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
279 0x002e, 0x0063, 0x006f, 0x006d, /* com. */
282 "www.xn--ghBGI4851OiyA33VqrD6Az86C4qF83CtRv93D5xBk15AzfG0nAgA0578DeA71C.com",
283 U_IDNA_CHECK_BIDI_ERROR
,
288 0x0077, 0x0077, 0x0077, 0x002e, /* www. */
289 /* labels cannot begin with an HYPHEN */
290 0x002D, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
292 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
293 0x002e, 0x0063, 0x006f, 0x006d, /* com. */
297 "www.xn----b95Ew8SqA315Ao5FbuMlnNmhA.com",
298 U_IDNA_STD3_ASCII_RULES_ERROR
,
303 /* correct ACE-prefix followed by unicode */
304 0x0077, 0x0077, 0x0077, 0x002e, /* www. */
305 0x0078, 0x006e, 0x002d,0x002d, /* ACE Prefix */
306 0x002D, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
308 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
309 0x002e, 0x0063, 0x006f, 0x006d, /* com. */
313 /* wrong ACE-prefix followed by valid ACE-encoded ASCII */
314 "www.XY-----b91I0V65S96C2A355Cw1E5yCeQr19CsnP1mFfmAE0361DeA96B.com",
315 U_IDNA_ACE_PREFIX_ERROR
,
318 /* cannot verify U_IDNA_VERIFICATION_ERROR */
322 0x0077, 0x0077, 0x0077, 0x002e, /* www. */
323 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
324 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
325 0xC5BC, 0xB9C8, 0xB098, 0xC88B, 0xC744, 0xAE4C,
326 0x002e, 0x0063, 0x006f, 0x006d, /* com. */
329 "www.xn--989AoMsVi5E83Db1D2A355Cv1E0vAk1DwRv93D5xBh15A0Dt30A5JpSD879Ccm6FeA98C.com",
330 U_IDNA_LABEL_TOO_LONG_ERROR
,
336 0x0077, 0x0077, 0x0077, 0x002e, /* www. */
337 0x0030, 0x0644, 0x064A, 0x0647, 0x0031, /* Arabic code points squashed between EN codepoints */
338 0x002e, 0x0063, 0x006f, 0x006d, /* com. */
341 "www.xn--01-tvdmo.com",
342 U_IDNA_CHECK_BIDI_ERROR
,
348 0x0077, 0x0077, 0x0077, 0x002e, // www.
349 0x206C, 0x0644, 0x064A, 0x0647, 0x206D, // Arabic code points squashed between BN codepoints
350 0x002e, 0x0063, 0x006f, 0x006d, // com.
353 "www.XN--ghbgi278xia.com",
354 U_IDNA_PROHIBITED_ERROR
,
359 0x0077, 0x0077, 0x0077, 0x002e, // www.
360 0x002D, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, // HYPHEN at the start of label
361 0x002e, 0x0063, 0x006f, 0x006d, // com.
365 U_IDNA_STD3_ASCII_RULES_ERROR
,
370 0x0077, 0x0077, 0x0077, 0x002e, // www.
371 0x0041, 0x0042, 0x0043, 0x0044, 0x0045,0x002D, // HYPHEN at the end of the label
372 0x002e, 0x0063, 0x006f, 0x006d, // com.
376 U_IDNA_STD3_ASCII_RULES_ERROR
,
381 0x0077, 0x0077, 0x0077, 0x002e, // www.
382 0x0041, 0x0042, 0x0043, 0x0044, 0x0045,0x0040, // Containing non LDH code point
383 0x002e, 0x0063, 0x006f, 0x006d, // com.
387 U_IDNA_STD3_ASCII_RULES_ERROR
,
392 0x0077, 0x0077, 0x0077, 0x002e, // www.
394 0x002e, 0x0063, 0x006f, 0x006d, // com.
398 U_IDNA_ZERO_LENGTH_LABEL_ERROR
,
404 U_ILLEGAL_ARGUMENT_ERROR
,
410 static struct ConformanceTestCases
417 UErrorCode expectedStatus
;
419 conformanceTestCases
[] =
423 "Case folding ASCII U+0043 U+0041 U+0046 U+0045",
424 "\x43\x41\x46\x45", "\x63\x61\x66\x65",
425 "Nameprep", UIDNA_DEFAULT
,
430 "Case folding 8bit U+00DF (german sharp s)",
431 "\xC3\x9F", "\x73\x73",
432 "Nameprep", UIDNA_DEFAULT
,
436 "Non-ASCII multibyte space character U+1680",
437 "\xE1\x9A\x80", NULL
,
438 "Nameprep", UIDNA_DEFAULT
,
439 U_IDNA_PROHIBITED_ERROR
442 "Non-ASCII 8bit control character U+0085",
444 "Nameprep", UIDNA_DEFAULT
,
445 U_IDNA_PROHIBITED_ERROR
448 "Non-ASCII multibyte control character U+180E",
449 "\xE1\xA0\x8E", NULL
,
450 "Nameprep", UIDNA_DEFAULT
,
451 U_IDNA_PROHIBITED_ERROR
454 "Non-ASCII control character U+1D175",
455 "\xF0\x9D\x85\xB5", NULL
,
456 "Nameprep", UIDNA_DEFAULT
,
457 U_IDNA_PROHIBITED_ERROR
460 "Plane 0 private use character U+F123",
461 "\xEF\x84\xA3", NULL
,
462 "Nameprep", UIDNA_DEFAULT
,
463 U_IDNA_PROHIBITED_ERROR
466 "Plane 15 private use character U+F1234",
467 "\xF3\xB1\x88\xB4", NULL
,
468 "Nameprep", UIDNA_DEFAULT
,
469 U_IDNA_PROHIBITED_ERROR
472 "Plane 16 private use character U+10F234",
473 "\xF4\x8F\x88\xB4", NULL
,
474 "Nameprep", UIDNA_DEFAULT
,
475 U_IDNA_PROHIBITED_ERROR
478 "Non-character code point U+8FFFE",
479 "\xF2\x8F\xBF\xBE", NULL
,
480 "Nameprep", UIDNA_DEFAULT
,
481 U_IDNA_PROHIBITED_ERROR
484 "Non-character code point U+10FFFF",
485 "\xF4\x8F\xBF\xBF", NULL
,
486 "Nameprep", UIDNA_DEFAULT
,
487 U_IDNA_PROHIBITED_ERROR
491 "Surrogate code U+DF42",
492 "\xED\xBD\x82", NULL, "Nameprep", UIDNA_DEFAULT,
493 U_IDNA_PROHIBITED_ERROR
497 "Non-plain text character U+FFFD",
498 "\xEF\xBF\xBD", NULL
,
499 "Nameprep", UIDNA_DEFAULT
,
500 U_IDNA_PROHIBITED_ERROR
503 "Ideographic description character U+2FF5",
504 "\xE2\xBF\xB5", NULL
,
505 "Nameprep", UIDNA_DEFAULT
,
506 U_IDNA_PROHIBITED_ERROR
509 "Display property character U+0341",
510 "\xCD\x81", "\xCC\x81",
511 "Nameprep", UIDNA_DEFAULT
, U_ZERO_ERROR
516 "Left-to-right mark U+200E",
517 "\xE2\x80\x8E", "\xCC\x81",
518 "Nameprep", UIDNA_DEFAULT
,
519 U_IDNA_PROHIBITED_ERROR
524 "\xE2\x80\xAA", "\xCC\x81",
525 "Nameprep", UIDNA_DEFAULT
,
526 U_IDNA_PROHIBITED_ERROR
529 "Language tagging character U+E0001",
530 "\xF3\xA0\x80\x81", "\xCC\x81",
531 "Nameprep", UIDNA_DEFAULT
,
532 U_IDNA_PROHIBITED_ERROR
535 "Language tagging character U+E0042",
536 "\xF3\xA0\x81\x82", NULL
,
537 "Nameprep", UIDNA_DEFAULT
,
538 U_IDNA_PROHIBITED_ERROR
541 "Bidi: RandALCat character U+05BE and LCat characters",
542 "\x66\x6F\x6F\xD6\xBE\x62\x61\x72", NULL
,
543 "Nameprep", UIDNA_DEFAULT
,
544 U_IDNA_CHECK_BIDI_ERROR
547 "Bidi: RandALCat character U+FD50 and LCat characters",
548 "\x66\x6F\x6F\xEF\xB5\x90\x62\x61\x72", NULL
,
549 "Nameprep",UIDNA_DEFAULT
,
550 U_IDNA_CHECK_BIDI_ERROR
553 "Bidi: RandALCat character U+FB38 and LCat characters",
554 "\x66\x6F\x6F\xEF\xB9\xB6\x62\x61\x72", "\x66\x6F\x6F\x20\xd9\x8e\x62\x61\x72",
555 "Nameprep", UIDNA_DEFAULT
,
558 { "Bidi: RandALCat without trailing RandALCat U+0627 U+0031",
559 "\xD8\xA7\x31", NULL
,
560 "Nameprep", UIDNA_DEFAULT
,
561 U_IDNA_CHECK_BIDI_ERROR
564 "Bidi: RandALCat character U+0627 U+0031 U+0628",
565 "\xD8\xA7\x31\xD8\xA8", "\xD8\xA7\x31\xD8\xA8",
566 "Nameprep", UIDNA_DEFAULT
,
570 "Unassigned code point U+E0002",
571 "\xF3\xA0\x80\x82", NULL
,
572 "Nameprep", UIDNA_DEFAULT
,
573 U_IDNA_UNASSIGNED_ERROR
578 "Larger test (shrinking)",
579 "X\xC2\xAD\xC3\xDF\xC4\xB0\xE2\x84\xA1\x6a\xcc\x8c\xc2\xa0\xc2"
580 "\xaa\xce\xb0\xe2\x80\x80", "xssi\xcc\x87""tel\xc7\xb0 a\xce\xb0 ",
582 UIDNA_DEFAULT, U_ZERO_ERROR
586 "Larger test (expanding)",
587 "X\xC3\xDF\xe3\x8c\x96\xC4\xB0\xE2\x84\xA1\xE2\x92\x9F\xE3\x8c\x80",
588 "xss\xe3\x82\xad\xe3\x83\xad\xe3\x83\xa1\xe3\x83\xbc\xe3\x83\x88"
589 "\xe3\x83\xab""i\xcc\x87""tel\x28""d\x29\xe3\x82\xa2\xe3\x83\x91"
590 "\xe3\x83\xbc\xe3\x83\x88"
592 UIDNA_DEFAULT, U_ZERO_ERROR
599 #define MAX_DEST_SIZE 300
601 void TestIDNA::debug(const UChar
* src
, int32_t srcLength
, int32_t options
){
602 UParseError parseError
;
603 UErrorCode transStatus
= U_ZERO_ERROR
;
604 UErrorCode prepStatus
= U_ZERO_ERROR
;
605 NamePrepTransform
* trans
= NamePrepTransform::createInstance(parseError
,transStatus
);
606 int32_t prepOptions
= (((options
& UIDNA_ALLOW_UNASSIGNED
) != 0) ? USPREP_ALLOW_UNASSIGNED
: 0);
607 UStringPrepProfile
* prep
= usprep_open(NULL
,"uidna",&prepStatus
);
608 UChar
*transOut
=NULL
, *prepOut
=NULL
;
609 int32_t transOutLength
=0, prepOutLength
=0;
612 transOutLength
= trans
->process(src
,srcLength
,transOut
, 0, prepOptions
>0, &parseError
, transStatus
);
613 if( transStatus
== U_BUFFER_OVERFLOW_ERROR
){
614 transStatus
= U_ZERO_ERROR
;
615 transOut
= (UChar
*) malloc(U_SIZEOF_UCHAR
* transOutLength
);
616 transOutLength
= trans
->process(src
,srcLength
,transOut
, transOutLength
, prepOptions
>0, &parseError
, transStatus
);
619 prepOutLength
= usprep_prepare(prep
, src
, srcLength
, prepOut
, 0, prepOptions
, &parseError
, &prepStatus
);
621 if( prepStatus
== U_BUFFER_OVERFLOW_ERROR
){
622 prepStatus
= U_ZERO_ERROR
;
623 prepOut
= (UChar
*) malloc(U_SIZEOF_UCHAR
* prepOutLength
);
624 prepOutLength
= usprep_prepare(prep
, src
, srcLength
, prepOut
, prepOutLength
, prepOptions
, &parseError
, &prepStatus
);
627 if(UnicodeString(transOut
,transOutLength
)!= UnicodeString(prepOut
, prepOutLength
)){
628 errln("Failed. Expected: " + prettify(UnicodeString(transOut
, transOutLength
))
629 + " Got: " + prettify(UnicodeString(prepOut
,prepOutLength
)));
637 void TestIDNA::testAPI(const UChar
* src
, const UChar
* expected
, const char* testName
,
638 UBool useSTD3ASCIIRules
,UErrorCode expectedStatus
,
639 UBool doCompare
, UBool testUnassigned
, TestFunc func
, UBool testSTD3ASCIIRules
){
641 UErrorCode status
= U_ZERO_ERROR
;
642 UChar destStack
[MAX_DEST_SIZE
];
645 int32_t expectedLen
= (expected
!= NULL
) ? u_strlen(expected
) : 0;
646 int32_t options
= (useSTD3ASCIIRules
== TRUE
) ? UIDNA_USE_STD3_RULES
: UIDNA_DEFAULT
;
647 UParseError parseError
;
652 tSrcLen
= u_strlen(src
);
653 tSrc
=(UChar
*) malloc( U_SIZEOF_UCHAR
* tSrcLen
);
654 memcpy(tSrc
,src
,tSrcLen
* U_SIZEOF_UCHAR
);
657 // test null-terminated source and return value of number of UChars required
658 destLen
= func(src
,-1,NULL
,0,options
, &parseError
, &status
);
659 if(status
== U_BUFFER_OVERFLOW_ERROR
){
660 status
= U_ZERO_ERROR
; // reset error code
661 if(destLen
+1 < MAX_DEST_SIZE
){
663 destLen
= func(src
,-1,dest
,destLen
+1,options
, &parseError
, &status
);
664 // TODO : compare output with expected
665 if(U_SUCCESS(status
) && expectedStatus
!= U_IDNA_STD3_ASCII_RULES_ERROR
&& (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
666 errln("Did not get the expected result for "+UnicodeString(testName
) +" null terminated source. Expected : "
667 + prettify(UnicodeString(expected
,expectedLen
))
668 + " Got: " + prettify(UnicodeString(dest
,destLen
))
672 errln( "%s null terminated source failed. Requires destCapacity > 300\n",testName
);
676 if(status
!= expectedStatus
){
677 errln( "Did not get the expected error for "+
678 UnicodeString(testName
)+
679 " null terminated source. Expected: " +UnicodeString(u_errorName(expectedStatus
))
680 + " Got: "+ UnicodeString(u_errorName(status
))
681 + " Source: " + prettify(UnicodeString(src
))
687 status
= U_ZERO_ERROR
;
688 destLen
= func(src
,-1,NULL
,0,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
689 if(status
== U_BUFFER_OVERFLOW_ERROR
){
690 status
= U_ZERO_ERROR
; // reset error code
691 if(destLen
+1 < MAX_DEST_SIZE
){
693 destLen
= func(src
,-1,dest
,destLen
+1,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
694 // TODO : compare output with expected
695 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
696 //errln("Did not get the expected result for %s null terminated source with both options set.\n",testName);
697 errln("Did not get the expected result for "+UnicodeString(testName
) +
698 " null terminated source "+ prettify(src
) +
699 " with both options set. Expected: "+ prettify(UnicodeString(expected
,expectedLen
))+
700 "Got: " + prettify(UnicodeString(dest
,destLen
)));
702 debug(src
,-1,options
| UIDNA_ALLOW_UNASSIGNED
);
706 errln( "%s null terminated source failed. Requires destCapacity > 300\n",testName
);
709 //testing query string
710 if(status
!= expectedStatus
&& expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
){
711 errln( "Did not get the expected error for "+
712 UnicodeString(testName
)+
713 " null terminated source with options set. Expected: " +UnicodeString(u_errorName(expectedStatus
))
714 + " Got: "+ UnicodeString(u_errorName(status
))
715 + " Source: " + prettify(UnicodeString(src
))
720 status
= U_ZERO_ERROR
;
722 // test source with lengthand return value of number of UChars required
723 destLen
= func(tSrc
, tSrcLen
, NULL
,0,options
, &parseError
, &status
);
724 if(status
== U_BUFFER_OVERFLOW_ERROR
){
725 status
= U_ZERO_ERROR
; // reset error code
726 if(destLen
+1 < MAX_DEST_SIZE
){
728 destLen
= func(src
,u_strlen(src
),dest
,destLen
+1,options
, &parseError
, &status
);
729 // TODO : compare output with expected
730 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
731 errln("Did not get the expected result for %s with source length.\n",testName
);
734 errln( "%s with source length failed. Requires destCapacity > 300\n",testName
);
738 if(status
!= expectedStatus
){
739 errln( "Did not get the expected error for "+
740 UnicodeString(testName
)+
741 " with source length. Expected: " +UnicodeString(u_errorName(expectedStatus
))
742 + " Got: "+ UnicodeString(u_errorName(status
))
743 + " Source: " + prettify(UnicodeString(src
))
747 status
= U_ZERO_ERROR
;
749 destLen
= func(tSrc
,tSrcLen
,NULL
,0,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
751 if(status
== U_BUFFER_OVERFLOW_ERROR
){
752 status
= U_ZERO_ERROR
; // reset error code
753 if(destLen
+1 < MAX_DEST_SIZE
){
755 destLen
= func(src
,u_strlen(src
),dest
,destLen
+1,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
756 // TODO : compare output with expected
757 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
758 errln("Did not get the expected result for %s with source length and both options set.\n",testName
);
761 errln( "%s with source length failed. Requires destCapacity > 300\n",testName
);
764 //testing query string
765 if(status
!= expectedStatus
&& expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
){
766 errln( "Did not get the expected error for "+
767 UnicodeString(testName
)+
768 " with source length and options set. Expected: " +UnicodeString(u_errorName(expectedStatus
))
769 + " Got: "+ UnicodeString(u_errorName(status
))
770 + " Source: " + prettify(UnicodeString(src
))
775 status
= U_ZERO_ERROR
;
776 if(testSTD3ASCIIRules
==TRUE
){
777 destLen
= func(src
,-1,NULL
,0,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
778 if(status
== U_BUFFER_OVERFLOW_ERROR
){
779 status
= U_ZERO_ERROR
; // reset error code
780 if(destLen
+1 < MAX_DEST_SIZE
){
782 destLen
= func(src
,-1,dest
,destLen
+1,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
783 // TODO : compare output with expected
784 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
785 //errln("Did not get the expected result for %s null terminated source with both options set.\n",testName);
786 errln("Did not get the expected result for "+UnicodeString(testName
) +" null terminated source with both options set. Expected: "+ prettify(UnicodeString(expected
,expectedLen
)));
790 errln( "%s null terminated source failed. Requires destCapacity > 300\n",testName
);
793 //testing query string
794 if(status
!= expectedStatus
){
795 errln( "Did not get the expected error for "+
796 UnicodeString(testName
)+
797 " null terminated source with options set. Expected: " +UnicodeString(u_errorName(expectedStatus
))
798 + " Got: "+ UnicodeString(u_errorName(status
))
799 + " Source: " + prettify(UnicodeString(src
))
803 status
= U_ZERO_ERROR
;
805 destLen
= func(tSrc
,tSrcLen
,NULL
,0,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
807 if(status
== U_BUFFER_OVERFLOW_ERROR
){
808 status
= U_ZERO_ERROR
; // reset error code
809 if(destLen
+1 < MAX_DEST_SIZE
){
811 destLen
= func(src
,u_strlen(src
),dest
,destLen
+1,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
812 // TODO : compare output with expected
813 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
814 errln("Did not get the expected result for %s with source length and both options set.\n",testName
);
817 errln( "%s with source length failed. Requires destCapacity > 300\n",testName
);
820 //testing query string
821 if(status
!= expectedStatus
&& expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
){
822 errln( "Did not get the expected error for "+
823 UnicodeString(testName
)+
824 " with source length and options set. Expected: " +UnicodeString(u_errorName(expectedStatus
))
825 + " Got: "+ UnicodeString(u_errorName(status
))
826 + " Source: " + prettify(UnicodeString(src
))
833 void TestIDNA::testCompare(const UChar
* s1
, int32_t s1Len
,
834 const UChar
* s2
, int32_t s2Len
,
835 const char* testName
, CompareFunc func
,
838 UErrorCode status
= U_ZERO_ERROR
;
839 int32_t retVal
= func(s1
,-1,s2
,-1,UIDNA_DEFAULT
,&status
);
841 if(isEqual
==TRUE
&& retVal
!=0){
842 errln("Did not get the expected result for %s with null termniated strings.\n",testName
);
844 if(U_FAILURE(status
)){
845 errln( "%s null terminated source failed. Error: %s\n", testName
,u_errorName(status
));
848 status
= U_ZERO_ERROR
;
849 retVal
= func(s1
,-1,s2
,-1,UIDNA_ALLOW_UNASSIGNED
,&status
);
851 if(isEqual
==TRUE
&& retVal
!=0){
852 errln("Did not get the expected result for %s with null termniated strings with options set.\n", testName
);
854 if(U_FAILURE(status
)){
855 errln( "%s null terminated source and options set failed. Error: %s\n",testName
, u_errorName(status
));
858 status
= U_ZERO_ERROR
;
859 retVal
= func(s1
,s1Len
,s2
,s2Len
,UIDNA_DEFAULT
,&status
);
861 if(isEqual
==TRUE
&& retVal
!=0){
862 errln("Did not get the expected result for %s with string length.\n",testName
);
864 if(U_FAILURE(status
)){
865 errln( "%s with string length. Error: %s\n",testName
, u_errorName(status
));
868 status
= U_ZERO_ERROR
;
869 retVal
= func(s1
,s1Len
,s2
,s2Len
,UIDNA_ALLOW_UNASSIGNED
,&status
);
871 if(isEqual
==TRUE
&& retVal
!=0){
872 errln("Did not get the expected result for %s with string length and options set.\n",testName
);
874 if(U_FAILURE(status
)){
875 errln( "%s with string length and options set. Error: %s\n", u_errorName(status
), testName
);
879 void TestIDNA::testToASCII(const char* testName
, TestFunc func
){
882 UChar buf
[MAX_DEST_SIZE
];
884 for(i
=0;i
< (int32_t)(sizeof(unicodeIn
)/sizeof(unicodeIn
[0])); i
++){
885 u_charsToUChars(asciiIn
[i
],buf
, (int32_t)(strlen(asciiIn
[i
])+1));
886 testAPI(unicodeIn
[i
], buf
,testName
, FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
891 void TestIDNA::testToUnicode(const char* testName
, TestFunc func
){
894 UChar buf
[MAX_DEST_SIZE
];
896 for(i
=0;i
< (int32_t)(sizeof(asciiIn
)/sizeof(asciiIn
[0])); i
++){
897 u_charsToUChars(asciiIn
[i
],buf
, (int32_t)(strlen(asciiIn
[i
])+1));
898 testAPI(buf
,unicodeIn
[i
],testName
,FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
903 void TestIDNA::testIDNToUnicode(const char* testName
, TestFunc func
){
905 UChar buf
[MAX_DEST_SIZE
];
906 UChar expected
[MAX_DEST_SIZE
];
907 UErrorCode status
= U_ZERO_ERROR
;
909 UParseError parseError
;
910 for(i
=0;i
< (int32_t)(sizeof(domainNames
)/sizeof(domainNames
[0])); i
++){
911 bufLen
= (int32_t)strlen(domainNames
[i
]);
912 bufLen
= u_unescape(domainNames
[i
],buf
, bufLen
+1);
913 func(buf
,bufLen
,expected
,MAX_DEST_SIZE
, UIDNA_ALLOW_UNASSIGNED
, &parseError
,&status
);
914 if(U_FAILURE(status
)){
915 errln( "%s failed to convert domainNames[%i].Error: %s \n",testName
, i
, u_errorName(status
));
918 testAPI(buf
,expected
,testName
,FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
919 //test toUnicode with all labels in the string
920 testAPI(buf
,expected
,testName
, FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
921 if(U_FAILURE(status
)){
922 errln( "%s failed to convert domainNames[%i].Error: %s \n",testName
,i
, u_errorName(status
));
929 void TestIDNA::testIDNToASCII(const char* testName
, TestFunc func
){
931 UChar buf
[MAX_DEST_SIZE
];
932 UChar expected
[MAX_DEST_SIZE
];
933 UErrorCode status
= U_ZERO_ERROR
;
935 UParseError parseError
;
936 for(i
=0;i
< (int32_t)(sizeof(domainNames
)/sizeof(domainNames
[0])); i
++){
937 bufLen
= (int32_t)strlen(domainNames
[i
]);
938 bufLen
= u_unescape(domainNames
[i
],buf
, bufLen
+1);
939 func(buf
,bufLen
,expected
,MAX_DEST_SIZE
, UIDNA_ALLOW_UNASSIGNED
, &parseError
,&status
);
940 if(U_FAILURE(status
)){
941 errln( "%s failed to convert domainNames[%i].Error: %s \n",testName
,i
, u_errorName(status
));
944 testAPI(buf
,expected
,testName
, FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
945 //test toASCII with all labels in the string
946 testAPI(buf
,expected
,testName
, FALSE
,U_ZERO_ERROR
, FALSE
, TRUE
, func
);
947 if(U_FAILURE(status
)){
948 errln( "%s failed to convert domainNames[%i].Error: %s \n",testName
,i
, u_errorName(status
));
955 void TestIDNA::testCompare(const char* testName
, CompareFunc func
){
959 UChar www
[] = {0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
960 UChar com
[] = {0x002E, 0x0043, 0x004F, 0x004D, 0x0000};
961 UChar buf
[MAX_DEST_SIZE
]={0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
963 UnicodeString
source(www
), uni0(www
),uni1(www
), ascii0(www
), ascii1(www
);
965 uni0
.append(unicodeIn
[0]);
967 uni0
.append((UChar
)0x0000);
969 uni1
.append(unicodeIn
[1]);
971 uni1
.append((UChar
)0x0000);
973 ascii0
.append(asciiIn
[0]);
975 ascii0
.append((UChar
)0x0000);
977 ascii1
.append(asciiIn
[1]);
979 ascii1
.append((UChar
)0x0000);
981 for(i
=0;i
< (int32_t)(sizeof(unicodeIn
)/sizeof(unicodeIn
[0])); i
++){
983 u_charsToUChars(asciiIn
[i
],buf
+4, (int32_t)(strlen(asciiIn
[i
])+1));
986 // for every entry in unicodeIn array
987 // prepend www. and append .com
989 source
.append(unicodeIn
[i
]);
991 source
.append((UChar
)0x0000);
992 // a) compare it with itself
993 const UChar
* src
= source
.getBuffer();
994 int32_t srcLen
= u_strlen(src
); //subtract null
996 testCompare(src
,srcLen
,src
,srcLen
,testName
, func
, TRUE
);
998 // b) compare it with asciiIn equivalent
999 testCompare(src
,srcLen
,buf
,u_strlen(buf
),testName
, func
,TRUE
);
1001 // c) compare it with unicodeIn not equivalent
1003 testCompare(src
,srcLen
,uni1
.getBuffer(),uni1
.length()-1,testName
, func
,FALSE
);
1005 testCompare(src
,srcLen
,uni0
.getBuffer(),uni0
.length()-1,testName
, func
,FALSE
);
1007 // d) compare it with asciiIn not equivalent
1009 testCompare(src
,srcLen
,ascii1
.getBuffer(),ascii1
.length()-1,testName
, func
,FALSE
);
1011 testCompare(src
,srcLen
,ascii0
.getBuffer(),ascii0
.length()-1,testName
, func
,FALSE
);
1020 getNextSeperator(UChar
*src
,int32_t srcLength
,
1022 if(srcLength
== -1){
1026 *limit
= src
+ i
; // point to null
1030 *limit
= src
+ (i
+1); // go past the delimiter
1034 // we have not found the delimiter
1036 *limit
= src
+srcLength
;
1041 for(i
=0;i
<srcLength
;i
++){
1043 *limit
= src
+ (i
+1); // go past the delimiter
1047 // we have not found the delimiter
1049 *limit
= src
+srcLength
;
1055 void printPunycodeOutput(){
1057 UChar dest
[MAX_DEST_SIZE
];
1058 int32_t destCapacity
=MAX_DEST_SIZE
;
1062 UBool caseFlags
[MAX_DEST_SIZE
];
1064 for(int32_t i
=0;i
< sizeof(errorCases
)/sizeof(errorCases
[0]);i
++){
1065 ErrorCases errorCase
= errorCases
[i
];
1066 UErrorCode status
= U_ZERO_ERROR
;
1067 start
= errorCase
.unicode
;
1068 int32_t srcLen
= u_strlen(start
);
1069 labelLen
= getNextSeperator(start
,srcLen
,&limit
);
1071 labelLen
=getNextSeperator(start
,srcLen
-labelLen
,&limit
);
1072 int32_t destLen
= u_strToPunycode(dest
,destCapacity
,start
,labelLen
,caseFlags
, &status
);
1073 if(U_FAILURE(status
)){
1074 printf("u_strToPunycode failed for index %i\n",i
);
1077 for(int32_t j
=0; j
<destLen
; j
++){
1078 printf("%c",(char)dest
[j
]);
1085 void TestIDNA::testErrorCases(const char* IDNToASCIIName
, TestFunc IDNToASCII
,
1086 const char* IDNToUnicodeName
, TestFunc IDNToUnicode
){
1087 UChar buf
[MAX_DEST_SIZE
];
1090 for(int32_t i
=0;i
< (int32_t)(sizeof(errorCases
)/sizeof(errorCases
[0]));i
++){
1091 ErrorCases errorCase
= errorCases
[i
];
1093 if(errorCase
.ascii
!= NULL
){
1094 bufLen
= (int32_t)strlen(errorCase
.ascii
);
1095 u_charsToUChars(errorCase
.ascii
,buf
, bufLen
+1);
1098 memset(buf
,0,U_SIZEOF_UCHAR
*MAX_DEST_SIZE
);
1101 if(errorCase
.unicode
[0]!=0){
1102 src
= errorCase
.unicode
;
1106 IDNToASCIIName
, errorCase
.useSTD3ASCIIRules
,
1107 errorCase
.expected
, TRUE
, TRUE
, IDNToASCII
);
1108 if(errorCase
.testLabel
==TRUE
){
1110 IDNToASCIIName
, errorCase
.useSTD3ASCIIRules
,
1111 errorCase
.expected
, FALSE
,TRUE
, IDNToASCII
);
1113 if(errorCase
.testToUnicode
==TRUE
){
1114 testAPI((src
==NULL
)? NULL
: buf
,src
,
1115 IDNToUnicodeName
, errorCase
.useSTD3ASCIIRules
,
1116 errorCase
.expected
, TRUE
, TRUE
, IDNToUnicode
);
1123 void TestIDNA::testConformance(const char* toASCIIName
, TestFunc toASCII
,
1124 const char* IDNToASCIIName
, TestFunc IDNToASCII
,
1125 const char* IDNToUnicodeName
, TestFunc IDNToUnicode
,
1126 const char* toUnicodeName
, TestFunc toUnicode
){
1127 UChar src
[MAX_DEST_SIZE
];
1129 UChar expected
[MAX_DEST_SIZE
];
1130 int32_t expectedLen
= 0;
1131 for(int32_t i
=0;i
< (int32_t)(sizeof(conformanceTestCases
)/sizeof(conformanceTestCases
[0]));i
++){
1132 const char* utf8Chars1
= conformanceTestCases
[i
].in
;
1133 int32_t utf8Chars1Len
= (int32_t)strlen(utf8Chars1
);
1134 const char* utf8Chars2
= conformanceTestCases
[i
].out
;
1135 int32_t utf8Chars2Len
= (utf8Chars2
== NULL
) ? 0 : (int32_t)strlen(utf8Chars2
);
1137 UErrorCode status
= U_ZERO_ERROR
;
1138 u_strFromUTF8(src
,MAX_DEST_SIZE
,&srcLen
,utf8Chars1
,utf8Chars1Len
,&status
);
1139 if(U_FAILURE(status
)){
1140 errln(UnicodeString("Conversion of UTF8 source in conformanceTestCases[") + i
+UnicodeString( "].in ( ")+prettify(utf8Chars1
) +UnicodeString(" ) failed. Error: ")+ UnicodeString(u_errorName(status
)));
1143 if(utf8Chars2
!= NULL
){
1144 u_strFromUTF8(expected
,MAX_DEST_SIZE
,&expectedLen
,utf8Chars2
,utf8Chars2Len
, &status
);
1145 if(U_FAILURE(status
)){
1146 errln(UnicodeString("Conversion of UTF8 source in conformanceTestCases[") + i
+UnicodeString( "].in ( ")+prettify(utf8Chars1
) +UnicodeString(" ) failed. Error: ")+ UnicodeString(u_errorName(status
)));
1151 if(conformanceTestCases
[i
].expectedStatus
!= U_ZERO_ERROR
){
1153 testAPI(src
,expected
,
1154 IDNToASCIIName
, FALSE
,
1155 conformanceTestCases
[i
].expectedStatus
,
1157 (conformanceTestCases
[i
].expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
),
1160 testAPI(src
,expected
,
1162 conformanceTestCases
[i
].expectedStatus
, TRUE
,
1163 (conformanceTestCases
[i
].expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
),
1168 IDNToUnicodeName
, FALSE
,
1169 conformanceTestCases
[i
].expectedStatus
, TRUE
, TRUE
, IDNToUnicode
);
1171 toUnicodeName
, FALSE
,
1172 conformanceTestCases
[i
].expectedStatus
, TRUE
, TRUE
, toUnicode
);
1178 // test and ascertain
1179 // func(func(func(src))) == func(src)
1180 void TestIDNA::testChaining(UChar
* src
,int32_t numIterations
,const char* testName
,
1181 UBool useSTD3ASCIIRules
, UBool caseInsensitive
, TestFunc func
){
1182 UChar even
[MAX_DEST_SIZE
];
1183 UChar odd
[MAX_DEST_SIZE
];
1184 UChar expected
[MAX_DEST_SIZE
];
1185 int32_t i
=0,evenLen
=0,oddLen
=0,expectedLen
=0;
1186 UErrorCode status
= U_ZERO_ERROR
;
1187 int32_t srcLen
= u_strlen(src
);
1188 int32_t options
= (useSTD3ASCIIRules
== TRUE
) ? UIDNA_USE_STD3_RULES
: UIDNA_DEFAULT
;
1189 UParseError parseError
;
1191 // test null-terminated source
1192 expectedLen
= func(src
,-1,expected
,MAX_DEST_SIZE
, options
, &parseError
, &status
);
1193 if(U_FAILURE(status
)){
1194 errln("%s null terminated source failed. Error: %s\n",testName
, u_errorName(status
));
1196 memcpy(odd
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1197 memcpy(even
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1198 for(;i
<=numIterations
; i
++){
1200 evenLen
= func(odd
,-1,even
,MAX_DEST_SIZE
,options
, &parseError
, &status
);
1201 if(U_FAILURE(status
)){
1202 errln("%s null terminated source failed\n",testName
);
1206 oddLen
= func(even
,-1,odd
,MAX_DEST_SIZE
,options
, &parseError
, &status
);
1207 if(U_FAILURE(status
)){
1208 errln("%s null terminated source failed\n",testName
);
1213 if(caseInsensitive
==TRUE
){
1214 if( u_strCaseCompare(even
,evenLen
, expected
,expectedLen
, 0, &status
) !=0 ||
1215 u_strCaseCompare(odd
,oddLen
, expected
,expectedLen
, 0, &status
) !=0 ){
1217 errln("Chaining for %s null terminated source failed\n",testName
);
1220 if( u_strncmp(even
,expected
,expectedLen
) != 0 ||
1221 u_strncmp(odd
,expected
,expectedLen
) !=0 ){
1223 errln("Chaining for %s null terminated source failed\n",testName
);
1227 // test null-terminated source
1228 status
= U_ZERO_ERROR
;
1229 expectedLen
= func(src
,-1,expected
,MAX_DEST_SIZE
,options
|UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
1230 if(U_FAILURE(status
)){
1231 errln("%s null terminated source with options set failed. Error: %s\n",testName
, u_errorName(status
));
1233 memcpy(odd
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1234 memcpy(even
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1235 for(;i
<=numIterations
; i
++){
1237 evenLen
= func(odd
,-1,even
,MAX_DEST_SIZE
,options
|UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
1238 if(U_FAILURE(status
)){
1239 errln("%s null terminated source with options set failed\n",testName
);
1243 oddLen
= func(even
,-1,odd
,MAX_DEST_SIZE
,options
|UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
1244 if(U_FAILURE(status
)){
1245 errln("%s null terminated source with options set failed\n",testName
);
1250 if(caseInsensitive
==TRUE
){
1251 if( u_strCaseCompare(even
,evenLen
, expected
,expectedLen
, 0, &status
) !=0 ||
1252 u_strCaseCompare(odd
,oddLen
, expected
,expectedLen
, 0, &status
) !=0 ){
1254 errln("Chaining for %s null terminated source with options set failed\n",testName
);
1257 if( u_strncmp(even
,expected
,expectedLen
) != 0 ||
1258 u_strncmp(odd
,expected
,expectedLen
) !=0 ){
1260 errln("Chaining for %s null terminated source with options set failed\n",testName
);
1265 // test source with length
1266 status
= U_ZERO_ERROR
;
1267 expectedLen
= func(src
,srcLen
,expected
,MAX_DEST_SIZE
,options
, &parseError
, &status
);
1268 if(U_FAILURE(status
)){
1269 errln("%s null terminated source failed. Error: %s\n",testName
, u_errorName(status
));
1271 memcpy(odd
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1272 memcpy(even
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1273 for(;i
<=numIterations
; i
++){
1275 evenLen
= func(odd
,oddLen
,even
,MAX_DEST_SIZE
,options
, &parseError
, &status
);
1276 if(U_FAILURE(status
)){
1277 errln("%s source with source length failed\n",testName
);
1281 oddLen
= func(even
,evenLen
,odd
,MAX_DEST_SIZE
,options
, &parseError
, &status
);
1282 if(U_FAILURE(status
)){
1283 errln("%s source with source length failed\n",testName
);
1288 if(caseInsensitive
==TRUE
){
1289 if( u_strCaseCompare(even
,evenLen
, expected
,expectedLen
, 0, &status
) !=0 ||
1290 u_strCaseCompare(odd
,oddLen
, expected
,expectedLen
, 0, &status
) !=0 ){
1292 errln("Chaining for %s source with source length failed\n",testName
);
1295 if( u_strncmp(even
,expected
,expectedLen
) != 0 ||
1296 u_strncmp(odd
,expected
,expectedLen
) !=0 ){
1298 errln("Chaining for %s source with source length failed\n",testName
);
1301 status
= U_ZERO_ERROR
;
1302 expectedLen
= func(src
,srcLen
,expected
,MAX_DEST_SIZE
,options
|UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
1303 if(U_FAILURE(status
)){
1304 errln("%s null terminated source with options set failed. Error: %s\n",testName
, u_errorName(status
));
1306 memcpy(odd
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1307 memcpy(even
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1308 for(;i
<=numIterations
; i
++){
1310 evenLen
= func(odd
,oddLen
,even
,MAX_DEST_SIZE
,options
|UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
1311 if(U_FAILURE(status
)){
1312 errln("%s source with source length and options set failed\n",testName
);
1316 oddLen
= func(even
,evenLen
,odd
,MAX_DEST_SIZE
,options
|UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
1317 if(U_FAILURE(status
)){
1318 errln("%s source with source length and options set failed\n",testName
);
1323 if(caseInsensitive
==TRUE
){
1324 if( u_strCaseCompare(even
,evenLen
, expected
,expectedLen
, 0, &status
) !=0 ||
1325 u_strCaseCompare(odd
,oddLen
, expected
,expectedLen
, 0, &status
) !=0 ){
1327 errln("Chaining for %s source with source length and options set failed\n",testName
);
1330 if( u_strncmp(even
,expected
,expectedLen
) != 0 ||
1331 u_strncmp(odd
,expected
,expectedLen
) !=0 ){
1333 errln("Chaining for %s source with source length and options set failed\n",testName
);
1337 void TestIDNA::testChaining(const char* toASCIIName
, TestFunc toASCII
,
1338 const char* toUnicodeName
, TestFunc toUnicode
){
1340 UChar buf
[MAX_DEST_SIZE
];
1342 for(i
=0;i
< (int32_t)(sizeof(asciiIn
)/sizeof(asciiIn
[0])); i
++){
1343 u_charsToUChars(asciiIn
[i
],buf
, (int32_t)(strlen(asciiIn
[i
])+1));
1344 testChaining(buf
,5,toUnicodeName
, FALSE
, FALSE
, toUnicode
);
1346 for(i
=0;i
< (int32_t)(sizeof(unicodeIn
)/sizeof(unicodeIn
[0])); i
++){
1347 testChaining(unicodeIn
[i
], 5,toASCIIName
, FALSE
, TRUE
, toASCII
);
1352 void TestIDNA::testRootLabelSeparator(const char* testName
, CompareFunc func
,
1353 const char* IDNToASCIIName
, TestFunc IDNToASCII
,
1354 const char* IDNToUnicodeName
, TestFunc IDNToUnicode
){
1358 UChar www
[] = {0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
1359 UChar com
[] = {0x002E, 0x0043, 0x004F, 0x004D, 0x002E, /* root label separator */0x0000};
1360 UChar buf
[MAX_DEST_SIZE
]={0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
1362 UnicodeString
source(www
), uni0(www
),uni1(www
), ascii0(www
), ascii1(www
);
1364 uni0
.append(unicodeIn
[0]);
1366 uni0
.append((UChar
)0x0000);
1368 uni1
.append(unicodeIn
[1]);
1370 uni1
.append((UChar
)0x0000);
1372 ascii0
.append(asciiIn
[0]);
1374 ascii0
.append((UChar
)0x0000);
1376 ascii1
.append(asciiIn
[1]);
1378 ascii1
.append((UChar
)0x0000);
1380 for(i
=0;i
< (int32_t)(sizeof(unicodeIn
)/sizeof(unicodeIn
[0])); i
++){
1382 u_charsToUChars(asciiIn
[i
],buf
+4, (int32_t)(strlen(asciiIn
[i
])+1));
1385 // for every entry in unicodeIn array
1386 // prepend www. and append .com
1388 source
.append(unicodeIn
[i
]);
1390 source
.append((UChar
)0x0000);
1392 const UChar
* src
= source
.getBuffer();
1393 int32_t srcLen
= u_strlen(src
); //subtract null
1395 // b) compare it with asciiIn equivalent
1396 testCompare(src
,srcLen
,buf
,u_strlen(buf
),testName
, func
,TRUE
);
1398 // a) compare it with itself
1399 testCompare(src
,srcLen
,src
,srcLen
,testName
, func
,TRUE
);
1402 // IDNToASCII comparison
1403 testAPI(src
,buf
,IDNToASCIIName
,FALSE
,U_ZERO_ERROR
,TRUE
, TRUE
, IDNToASCII
);
1404 // IDNToUnicode comparison
1405 testAPI(buf
,src
,IDNToUnicodeName
, FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, IDNToUnicode
);
1407 // c) compare it with unicodeIn not equivalent
1409 testCompare(src
,srcLen
,uni1
.getBuffer(),uni1
.length()-1,testName
, func
,FALSE
);
1411 testCompare(src
,srcLen
,uni0
.getBuffer(),uni0
.length()-1,testName
, func
,FALSE
);
1413 // d) compare it with asciiIn not equivalent
1415 testCompare(src
,srcLen
,ascii1
.getBuffer(),ascii1
.length()-1,testName
, func
,FALSE
);
1417 testCompare(src
,srcLen
,ascii0
.getBuffer(),ascii0
.length()-1,testName
, func
,FALSE
);
1422 //---------------------------------------------
1424 //---------------------------------------------
1426 void TestIDNA::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* par
)
1428 if (exec
) logln((UnicodeString
)"TestSuite IDNA API ");
1431 case 0: name
= "TestToASCII"; if (exec
) TestToASCII(); break;
1432 case 1: name
= "TestToUnicode"; if (exec
) TestToUnicode(); break;
1433 case 2: name
= "TestIDNToASCII"; if (exec
) TestIDNToASCII(); break;
1434 case 3: name
= "TestIDNToUnicode"; if (exec
) TestIDNToUnicode(); break;
1435 case 4: name
= "TestCompare"; if (exec
) TestCompare(); break;
1436 case 5: name
= "TestErrorCases"; if (exec
) TestErrorCases(); break;
1437 case 6: name
= "TestChaining"; if (exec
) TestChaining(); break;
1438 case 7: name
= "TestRootLabelSeparator"; if(exec
) TestRootLabelSeparator(); break;
1439 case 8: name
= "TestCompareReferenceImpl"; if(exec
) TestCompareReferenceImpl(); break;
1440 case 9: name
= "TestDataFile"; if(exec
) TestDataFile(); break;
1441 case 10: name
= "TestRefIDNA"; if(exec
) TestRefIDNA(); break;
1442 case 11: name
= "TestIDNAMonkeyTest"; if(exec
) TestIDNAMonkeyTest(); break;
1443 case 12: name
= "TestConformance"; if(exec
) TestConformance();break;
1446 name
= "TestConformanceTestVectors";
1448 logln("TestSuite IDNA conf----"); logln();
1450 callTest(test
, par
);
1454 default: name
= ""; break; /*needed to end loop*/
1457 void TestIDNA::TestToASCII(){
1458 testToASCII("uidna_toASCII", uidna_toASCII
);
1460 void TestIDNA::TestToUnicode(){
1461 testToUnicode("uidna_toUnicode", uidna_toUnicode
);
1463 void TestIDNA::TestIDNToASCII(){
1464 testIDNToASCII("uidna_IDNToASCII", uidna_IDNToASCII
);
1466 void TestIDNA::TestIDNToUnicode(){
1467 testIDNToUnicode("uidna_IDNToUnicode", uidna_IDNToUnicode
);
1469 void TestIDNA::TestCompare(){
1470 testCompare("uidna_compare",uidna_compare
);
1472 void TestIDNA::TestErrorCases(){
1473 testErrorCases( "uidna_IDNToASCII",uidna_IDNToASCII
,
1474 "uidna_IDNToUnicode",uidna_IDNToUnicode
);
1476 void TestIDNA::TestRootLabelSeparator(){
1477 testRootLabelSeparator( "uidna_compare",uidna_compare
,
1478 "uidna_IDNToASCII", uidna_IDNToASCII
,
1479 "uidna_IDNToUnicode",uidna_IDNToUnicode
1482 void TestIDNA::TestChaining(){
1483 testChaining("uidna_toASCII",uidna_toASCII
, "uidna_toUnicode", uidna_toUnicode
);
1485 void TestIDNA::TestConformance(){
1486 testConformance("uidna_toASCII",uidna_toASCII
,"uidna_IDNToASCII",uidna_IDNToASCII
,
1487 "uidna_IDNToUnicode",uidna_IDNToUnicode
, "uidna_toUnicode", uidna_toUnicode
);
1490 static const int loopCount
= 100;
1491 static const int maxCharCount
= 20;
1492 static const int maxCodePoint
= 0x10ffff;
1496 static UBool initialized
= FALSE
;
1499 srand((unsigned)time(NULL
));
1502 // Assume rand has at least 12 bits of precision
1504 for (uint32_t i
=0; i
<sizeof(l
); ++i
)
1505 ((char*)&l
)[i
] = (char)((rand() & 0x0FF0) >> 4);
1510 * Return a random integer i where 0 <= i < n.
1511 * A special function that gets random codepoints from planes 0,1,2 and 14
1513 static int32_t rand_uni()
1515 int32_t retVal
= (int32_t)(randul()& 0x3FFFF);
1516 if(retVal
>= 0x30000){
1522 static int32_t randi(int32_t n
){
1523 return (int32_t) (randul() % (n
+1));
1526 void getTestSource(UnicodeString
& fillIn
) {
1528 int32_t charCount
= (randi(maxCharCount
) + 1);
1529 while (i
<charCount
) {
1530 int32_t codepoint
= rand_uni();
1531 if(codepoint
== 0x0000){
1534 fillIn
.append((UChar32
)codepoint
);
1540 UnicodeString
TestIDNA::testCompareReferenceImpl(UnicodeString
& src
,
1541 TestFunc refIDNA
, const char* refIDNAName
,
1542 TestFunc uIDNA
, const char* uIDNAName
,
1545 const UChar
* srcUChars
= src
.getBuffer();
1546 UChar exp
[MAX_DEST_SIZE
]={0};
1547 int32_t expCap
= MAX_DEST_SIZE
, expLen
=0;
1548 UErrorCode expStatus
= U_ZERO_ERROR
;
1549 UParseError parseError
;
1551 logln("Comparing "+ UnicodeString(refIDNAName
)
1552 + " with "+ UnicodeString(uIDNAName
)
1553 +" for input: " + prettify(srcUChars
));
1555 expLen
= refIDNA(srcUChars
, src
.length()-1, exp
, expCap
,
1556 options
, &parseError
, &expStatus
);
1558 UChar got
[MAX_DEST_SIZE
]={0};
1559 int32_t gotCap
= MAX_DEST_SIZE
, gotLen
=0;
1560 UErrorCode gotStatus
= U_ZERO_ERROR
;
1562 gotLen
= uIDNA(srcUChars
, src
.length()-1, got
, gotCap
,
1563 options
, &parseError
, &gotStatus
);
1565 if(expStatus
!= gotStatus
){
1566 errln("Did not get the expected status while comparing " + UnicodeString(refIDNAName
)
1567 + " with " + UnicodeString(uIDNAName
)
1568 + " Expected: " + UnicodeString(u_errorName(expStatus
))
1569 + " Got: " + UnicodeString(u_errorName(gotStatus
))
1570 + " for Source: "+ prettify(srcUChars
)
1571 + " Options: " + options
);
1572 return UnicodeString("");
1575 // now we know that both implementations yielded same error
1576 if(U_SUCCESS(expStatus
)){
1577 // compare the outputs if status == U_ZERO_ERROR
1578 if(u_strCompare(exp
, expLen
, got
, gotLen
, TRUE
) != 0){
1579 errln("Did not get the expected output while comparing " + UnicodeString(refIDNAName
)
1580 + " with " + UnicodeString(uIDNAName
)
1581 + " Expected: " + prettify(UnicodeString(exp
, expLen
))
1582 + " Got: " + prettify(UnicodeString(got
, gotLen
))
1583 + " for Source: "+ prettify(srcUChars
)
1584 + " Options: " + options
);
1586 return UnicodeString(exp
, expLen
);
1589 logln("Got the same error while comparing "
1590 + UnicodeString(refIDNAName
)
1591 + " with "+ UnicodeString(uIDNAName
)
1592 +" for input: " + prettify(srcUChars
));
1594 return UnicodeString("");
1597 void TestIDNA::testCompareReferenceImpl(const UChar
* src
, int32_t srcLen
){
1598 UnicodeString
label(src
,srcLen
);
1599 label
.append((UChar
)0x0000);
1601 //test idnaref_toASCII and idnare
1602 UnicodeString asciiLabel
= testCompareReferenceImpl(label
,
1603 idnaref_toASCII
, "idnaref_toASCII",
1604 uidna_toASCII
, "uidna_toASCII",
1605 UIDNA_ALLOW_UNASSIGNED
);
1606 testCompareReferenceImpl(label
,
1607 idnaref_toASCII
, "idnaref_toASCII",
1608 uidna_toASCII
, "uidna_toASCII",
1610 testCompareReferenceImpl(label
,
1611 idnaref_toASCII
, "idnaref_toASCII",
1612 uidna_toASCII
, "uidna_toASCII",
1613 UIDNA_USE_STD3_RULES
);
1614 testCompareReferenceImpl(label
,
1615 idnaref_toASCII
, "idnaref_toASCII",
1616 uidna_toASCII
, "uidna_toASCII",
1617 UIDNA_USE_STD3_RULES
| UIDNA_ALLOW_UNASSIGNED
);
1619 if(asciiLabel
.length()!=0){
1620 asciiLabel
.append((UChar
)0x0000);
1623 testCompareReferenceImpl(asciiLabel
,
1624 idnaref_toUnicode
, "idnaref_toUnicode",
1625 uidna_toUnicode
, "uidna_toUnicode",
1626 UIDNA_ALLOW_UNASSIGNED
);
1627 testCompareReferenceImpl(asciiLabel
,
1628 idnaref_toUnicode
, "idnaref_toUnicode",
1629 uidna_toUnicode
, "uidna_toUnicode",
1631 testCompareReferenceImpl(asciiLabel
,
1632 idnaref_toUnicode
, "idnaref_toUnicode",
1633 uidna_toUnicode
, "uidna_toUnicode",
1634 UIDNA_USE_STD3_RULES
);
1635 testCompareReferenceImpl(asciiLabel
,
1636 idnaref_toUnicode
, "idnaref_toUnicode",
1637 uidna_toUnicode
, "uidna_toUnicode",
1638 UIDNA_USE_STD3_RULES
| UIDNA_ALLOW_UNASSIGNED
);
1642 const char* failures
[] ={
1643 "\\uAA42\\U0001F8DD\\U00019D01\\U000149A3\\uD385\\U000EE0F5\\U00018B92\\U000179D1\\U00018624\\U0002227F\\U000E83C0\\U000E8DCD\\u5460\\U00017F34\\U0001570B\\u43D1\\U0002C9C9\\U000281EC\\u2105\\U000180AE\\uC5D4",
1644 "\\U0002F5A6\\uD638\\u0D0A\\u9E9C\\uFE5B\\U0001FCCB\\u66C4",
1647 void TestIDNA::TestIDNAMonkeyTest(){
1648 UnicodeString source
;
1649 UErrorCode status
= U_ZERO_ERROR
;
1652 getInstance(status
); // Init prep
1653 if (U_FAILURE(status
)) {
1654 errln("Test could not initialize. Got %s", u_errorName(status
));
1658 for(i
=0; i
<loopCount
; i
++){
1660 getTestSource(source
);
1661 source
.append((UChar
)0x0000);
1662 const UChar
* src
= source
.getBuffer();
1663 testCompareReferenceImpl(src
,source
.length()-1);
1664 testCompareReferenceImpl(src
,source
.length()-1);
1668 for (i
=0; i
<(int)(sizeof(failures
)/sizeof(failures
[0])); i
++){
1670 source
.append( failures
[i
] );
1671 source
= source
.unescape();
1672 source
.append((UChar
)0x0000);
1673 const UChar
*src
= source
.getBuffer();
1674 testCompareReferenceImpl(src
,source
.length()-1);
1675 //debug(source.getBuffer(),source.length(),UIDNA_ALLOW_UNASSIGNED);
1680 source
.append("\\uCF18\\U00021161\\U000EEF11\\U0002BB82\\U0001D63C");
1681 debug(source
.getBuffer(),source
.length(),UIDNA_ALLOW_UNASSIGNED
);
1683 { // test deletion of code points
1684 UnicodeString
source("\\u043f\\u00AD\\u034f\\u043e\\u0447\\u0435\\u043c\\u0443\\u0436\\u0435\\u043e\\u043d\\u0438\\u043d\\u0435\\u0433\\u043e\\u0432\\u043e\\u0440\\u044f\\u0442\\u043f\\u043e\\u0440\\u0443\\u0441\\u0441\\u043a\\u0438\\u0000");
1685 source
= source
.unescape();
1686 UnicodeString
expected("\\u043f\\u043e\\u0447\\u0435\\u043c\\u0443\\u0436\\u0435\\u043e\\u043d\\u0438\\u043d\\u0435\\u0433\\u043e\\u0432\\u043e\\u0440\\u044f\\u0442\\u043f\\u043e\\u0440\\u0443\\u0441\\u0441\\u043a\\u0438\\u0000");
1687 expected
= expected
.unescape();
1688 UnicodeString
ascii("xn--b1abfaaepdrnnbgefbadotcwatmq2g4l");
1689 ascii
.append((UChar
)0x0000);
1690 testAPI(source
.getBuffer(),ascii
.getBuffer(), "uidna_toASCII", FALSE
, U_ZERO_ERROR
, TRUE
, TRUE
, uidna_toASCII
);
1692 testAPI(source
.getBuffer(),ascii
.getBuffer(), "idnaref_toASCII", FALSE
, U_ZERO_ERROR
, TRUE
, TRUE
, idnaref_toASCII
);
1694 testCompareReferenceImpl(source
.getBuffer(), source
.length()-1);
1699 void TestIDNA::TestCompareReferenceImpl(){
1701 UChar src
[2] = {0,0};
1705 for(int32_t i
= 0x40000 ; i
< 0x10ffff; i
++){
1706 if(quick
==TRUE
&& i
> 0x1FFFF){
1709 if(i
>= 0x30000 && i
<= 0xF0000){
1713 src
[0] = U16_LEAD(i
);
1714 src
[1] = U16_TRAIL(i
);
1721 testCompareReferenceImpl(src
, srcLen
);
1725 void TestIDNA::TestRefIDNA(){
1726 UErrorCode status
= U_ZERO_ERROR
;
1727 getInstance(status
); // Init prep
1728 if (U_FAILURE(status
)) {
1729 errln("Test could not initialize. Got %s", u_errorName(status
));
1733 testToASCII("idnaref_toASCII", idnaref_toASCII
);
1734 testToUnicode("idnaref_toUnicode", idnaref_toUnicode
);
1735 testIDNToASCII("idnaref_IDNToASCII", idnaref_IDNToASCII
);
1736 testIDNToUnicode("idnaref_IDNToUnicode", idnaref_IDNToUnicode
);
1737 testCompare("idnaref_compare",idnaref_compare
);
1738 testErrorCases( "idnaref_IDNToASCII",idnaref_IDNToASCII
,
1739 "idnaref_IDNToUnicode",idnaref_IDNToUnicode
);
1740 testChaining("idnaref_toASCII",idnaref_toASCII
, "idnaref_toUnicode", idnaref_toUnicode
);
1742 testRootLabelSeparator( "idnaref_compare",idnaref_compare
,
1743 "idnaref_IDNToASCII", idnaref_IDNToASCII
,
1744 "idnaref_IDNToUnicode",idnaref_IDNToUnicode
1746 testChaining("idnaref_toASCII",idnaref_toASCII
, "idnaref_toUnicode", idnaref_toUnicode
);
1750 void TestIDNA::TestDataFile(){
1753 TestIDNA::~TestIDNA(){
1760 NamePrepTransform
* TestIDNA::gPrep
= NULL
;
1762 NamePrepTransform
* TestIDNA::getInstance(UErrorCode
& status
){
1763 if(TestIDNA::gPrep
== NULL
){
1764 UParseError parseError
;
1765 TestIDNA::gPrep
= NamePrepTransform::createInstance(parseError
, status
);
1766 if(TestIDNA::gPrep
==NULL
){
1767 //status = U_MEMORY_ALLOCATION_ERROR;
1771 return TestIDNA::gPrep
;
1774 #endif /* #if !UCONFIG_NO_IDNA */