2 *******************************************************************************
4 * Copyright (C) 2003-2004, 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"
33 static UChar unicodeIn
[][41] ={
35 0x0644, 0x064A, 0x0647, 0x0645, 0x0627, 0x0628, 0x062A, 0x0643, 0x0644,
36 0x0645, 0x0648, 0x0634, 0x0639, 0x0631, 0x0628, 0x064A, 0x061F, 0x0000
39 0x4ED6, 0x4EEC, 0x4E3A, 0x4EC0, 0x4E48, 0x4E0D, 0x8BF4, 0x4E2D, 0x6587,
43 0x0050, 0x0072, 0x006F, 0x010D, 0x0070, 0x0072, 0x006F, 0x0073, 0x0074,
44 0x011B, 0x006E, 0x0065, 0x006D, 0x006C, 0x0075, 0x0076, 0x00ED, 0x010D,
45 0x0065, 0x0073, 0x006B, 0x0079, 0x0000
48 0x05DC, 0x05DE, 0x05D4, 0x05D4, 0x05DD, 0x05E4, 0x05E9, 0x05D5, 0x05D8,
49 0x05DC, 0x05D0, 0x05DE, 0x05D3, 0x05D1, 0x05E8, 0x05D9, 0x05DD, 0x05E2,
50 0x05D1, 0x05E8, 0x05D9, 0x05EA, 0x0000
53 0x092F, 0x0939, 0x0932, 0x094B, 0x0917, 0x0939, 0x093F, 0x0928, 0x094D,
54 0x0926, 0x0940, 0x0915, 0x094D, 0x092F, 0x094B, 0x0902, 0x0928, 0x0939,
55 0x0940, 0x0902, 0x092C, 0x094B, 0x0932, 0x0938, 0x0915, 0x0924, 0x0947,
56 0x0939, 0x0948, 0x0902, 0x0000
59 0x306A, 0x305C, 0x307F, 0x3093, 0x306A, 0x65E5, 0x672C, 0x8A9E, 0x3092,
60 0x8A71, 0x3057, 0x3066, 0x304F, 0x308C, 0x306A, 0x3044, 0x306E, 0x304B,
65 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
66 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
67 0xC5BC, 0xB9C8, 0xB098, 0xC88B, 0xC744, 0xAE4C, 0x0000
71 0x043F, 0x043E, 0x0447, 0x0435, 0x043C, 0x0443, 0x0436, 0x0435, 0x043E,
72 0x043D, 0x0438, 0x043D, 0x0435, 0x0433, 0x043E, 0x0432, 0x043E, 0x0440,
73 0x044F, 0x0442, 0x043F, 0x043E, 0x0440, 0x0443, 0x0441, 0x0441, 0x043A,
77 0x0050, 0x006F, 0x0072, 0x0071, 0x0075, 0x00E9, 0x006E, 0x006F, 0x0070,
78 0x0075, 0x0065, 0x0064, 0x0065, 0x006E, 0x0073, 0x0069, 0x006D, 0x0070,
79 0x006C, 0x0065, 0x006D, 0x0065, 0x006E, 0x0074, 0x0065, 0x0068, 0x0061,
80 0x0062, 0x006C, 0x0061, 0x0072, 0x0065, 0x006E, 0x0045, 0x0073, 0x0070,
81 0x0061, 0x00F1, 0x006F, 0x006C, 0x0000
84 0x4ED6, 0x5011, 0x7232, 0x4EC0, 0x9EBD, 0x4E0D, 0x8AAA, 0x4E2D, 0x6587,
88 0x0054, 0x1EA1, 0x0069, 0x0073, 0x0061, 0x006F, 0x0068, 0x1ECD, 0x006B,
89 0x0068, 0x00F4, 0x006E, 0x0067, 0x0074, 0x0068, 0x1EC3, 0x0063, 0x0068,
90 0x1EC9, 0x006E, 0x00F3, 0x0069, 0x0074, 0x0069, 0x1EBF, 0x006E, 0x0067,
91 0x0056, 0x0069, 0x1EC7, 0x0074, 0x0000
94 0x0033, 0x5E74, 0x0042, 0x7D44, 0x91D1, 0x516B, 0x5148, 0x751F, 0x0000
97 0x5B89, 0x5BA4, 0x5948, 0x7F8E, 0x6075, 0x002D, 0x0077, 0x0069, 0x0074,
98 0x0068, 0x002D, 0x0053, 0x0055, 0x0050, 0x0045, 0x0052, 0x002D, 0x004D,
99 0x004F, 0x004E, 0x004B, 0x0045, 0x0059, 0x0053, 0x0000
102 0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x002D, 0x0041, 0x006E, 0x006F,
103 0x0074, 0x0068, 0x0065, 0x0072, 0x002D, 0x0057, 0x0061, 0x0079, 0x002D,
104 0x305D, 0x308C, 0x305E, 0x308C, 0x306E, 0x5834, 0x6240, 0x0000
107 0x3072, 0x3068, 0x3064, 0x5C4B, 0x6839, 0x306E, 0x4E0B, 0x0032, 0x0000
110 0x004D, 0x0061, 0x006A, 0x0069, 0x3067, 0x004B, 0x006F, 0x0069, 0x3059,
111 0x308B, 0x0035, 0x79D2, 0x524D, 0x0000
114 0x30D1, 0x30D5, 0x30A3, 0x30FC, 0x0064, 0x0065, 0x30EB, 0x30F3, 0x30D0,
118 0x305D, 0x306E, 0x30B9, 0x30D4, 0x30FC, 0x30C9, 0x3067, 0x0000
120 // test non-BMP code points
122 0xD800, 0xDF00, 0xD800, 0xDF01, 0xD800, 0xDF02, 0xD800, 0xDF03, 0xD800, 0xDF05,
123 0xD800, 0xDF06, 0xD800, 0xDF07, 0xD800, 0xDF09, 0xD800, 0xDF0A, 0xD800, 0xDF0B,
127 0xD800, 0xDF0D, 0xD800, 0xDF0C, 0xD800, 0xDF1E, 0xD800, 0xDF0F, 0xD800, 0xDF16,
128 0xD800, 0xDF15, 0xD800, 0xDF14, 0xD800, 0xDF12, 0xD800, 0xDF10, 0xD800, 0xDF20,
134 0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac
138 0x0062, 0x006f, 0x006e, 0x0121, 0x0075, 0x0073, 0x0061, 0x0127,
143 0x043f, 0x043e, 0x0447, 0x0435, 0x043c, 0x0443, 0x0436, 0x0435,
144 0x043e, 0x043d, 0x0438, 0x043d, 0x0435, 0x0433, 0x043e, 0x0432,
145 0x043e, 0x0440, 0x044f, 0x0442, 0x043f, 0x043e, 0x0440, 0x0443,
146 0x0441, 0x0441, 0x043a, 0x0438
151 static const char *asciiIn
[] = {
152 "xn--egbpdaj6bu4bxfgehfvwxn",
153 "xn--ihqwcrb4cv8a8dqg056pqjye",
154 "xn--Proprostnemluvesky-uyb24dma41a",
155 "xn--4dbcagdahymbxekheh6e0a7fei0b",
156 "xn--i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd",
157 "xn--n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa",
158 /* "xn--989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c",*/
159 "xn--b1abfaaepdrnnbgefbaDotcwatmq2g4l",
160 "xn--PorqunopuedensimplementehablarenEspaol-fmd56a",
161 "xn--ihqwctvzc91f659drss3x8bo0yb",
162 "xn--TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g",
163 "xn--3B-ww4c5e180e575a65lsy2b",
164 "xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n",
165 "xn--Hello-Another-Way--fc4qua05auwb3674vfr0b",
166 "xn--2-u9tlzr9756bt3uc0v",
167 "xn--MajiKoi5-783gue6qz075azm5e",
168 "xn--de-jg4avhby1noc0d",
169 "xn--d9juau41awczczp",
171 "XN--db8CBHEJLGH4E0AL",
172 "xn--hxargifdar", // Greek
173 "xn--bonusaa-5bb1da", // Maltese
174 "xn--b1abfaaepdrnnbgefbadotcwatmq2g4l", // Russian (Cyrillic)
177 static const char *domainNames
[] = {
178 "slip129-37-118-146.nc.us.ibm.net",
179 "saratoga.pe.utexas.edu",
180 "dial-120-45.ots.utexas.edu",
181 "woo-085.dorms.waller.net",
182 "hd30-049.hil.compuserve.com",
183 "pem203-31.pe.ttu.edu",
184 "56K-227.MaxTNT3.pdq.net",
185 "dial-36-2.ots.utexas.edu",
186 "slip129-37-23-152.ga.us.ibm.net",
187 "ts45ip119.cadvision.com",
188 "sdn-ts-004txaustP05.dialsprint.net",
189 "bar-tnt1s66.erols.com",
190 "101.st-louis-15.mo.dial-access.att.net",
192 "dial-13-2.ots.utexas.edu",
193 "net-redynet29.datamarkets.com.ar",
194 "ccs-shiva28.reacciun.net.ve",
195 "7.houston-11.tx.dial-access.att.net",
196 "ingw129-37-120-26.mo.us.ibm.net",
197 "dialup6.austintx.com",
199 "slip129-37-119-194.nc.us.ibm.net",
200 "cs7.dillons.co.uk.203.119.193.in-addr.arpa",
201 "swprd1.innovplace.saskatoon.sk.ca",
202 "bikini.bologna.maraut.it",
203 "node91.subnet159-198-79.baxter.com",
204 "cust19.max5.new-york.ny.ms.uu.net",
205 "balexander.slip.andrew.cmu.edu",
206 "pool029.max2.denver.co.dynip.alter.net",
207 "cust49.max9.new-york.ny.ms.uu.net",
208 "s61.abq-dialin2.hollyberry.com",
209 "\\u0917\\u0928\\u0947\\u0936.sanjose.ibm.com", //':'(0x003a) produces U_IDNA_STD3_ASCII_RULES_ERROR
211 // "www.\\u00E0\\u00B3\\u00AF.com",//' ' (0x0020) produces U_IDNA_STD3_ASCII_RULES_ERROR
212 "www.\\u00C2\\u00A4.com",
213 "www.\\u00C2\\u00A3.com",
214 // "\\u0025", //'%' (0x0025) produces U_IDNA_STD3_ASCII_RULES_ERROR
215 // "\\u005C\\u005C", //'\' (0x005C) produces U_IDNA_STD3_ASCII_RULES_ERROR
221 // These yeild U_IDNA_PROHIBITED_ERROR
222 //"\\u00CF\\u0082.com",
223 //"\\u00CE\\u00B2\\u00C3\\u009Fss.com",
224 //"\\u00E2\\u0098\\u00BA.com",
225 "\\u00C3\\u00BC.com",
229 typedef struct ErrorCases ErrorCases
;
231 static struct ErrorCases
{
236 UBool useSTD3ASCIIRules
;
243 0x0077, 0x0077, 0x0077, 0x002e, /* www. */
244 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
245 0x070F,/*prohibited*/
246 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
247 0x002e, 0x0063, 0x006f, 0x006d, /* com. */
250 "www.XN--8mb5595fsoa28orucya378bqre2tcwop06c5qbw82a1rffmae0361dea96b.com",
251 U_IDNA_PROHIBITED_ERROR
,
257 0x0077, 0x0077, 0x0077, 0x002e, /* www. */
258 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
259 0x0221, 0x0234/*Unassigned code points*/,
260 0x002e, 0x0063, 0x006f, 0x006d, /* com. */
263 "www.XN--6lA2Bz548Fj1GuA391Bf1Gb1N59Ab29A7iA.com",
265 U_IDNA_UNASSIGNED_ERROR
,
270 0x0077, 0x0077, 0x0077, 0x002e, /* www. */
271 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
272 0x0644, 0x064A, 0x0647,/*Arabic code points. Cannot mix RTL with LTR*/
273 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
274 0x002e, 0x0063, 0x006f, 0x006d, /* com. */
277 "www.xn--ghBGI4851OiyA33VqrD6Az86C4qF83CtRv93D5xBk15AzfG0nAgA0578DeA71C.com",
278 U_IDNA_CHECK_BIDI_ERROR
,
283 0x0077, 0x0077, 0x0077, 0x002e, /* www. */
284 /* labels cannot begin with an HYPHEN */
285 0x002D, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
287 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
288 0x002e, 0x0063, 0x006f, 0x006d, /* com. */
292 "www.xn----b95Ew8SqA315Ao5FbuMlnNmhA.com",
293 U_IDNA_STD3_ASCII_RULES_ERROR
,
298 /* correct ACE-prefix followed by unicode */
299 0x0077, 0x0077, 0x0077, 0x002e, /* www. */
300 0x0078, 0x006e, 0x002d,0x002d, /* ACE Prefix */
301 0x002D, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
303 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
304 0x002e, 0x0063, 0x006f, 0x006d, /* com. */
308 /* wrong ACE-prefix followed by valid ACE-encoded ASCII */
309 "www.XY-----b91I0V65S96C2A355Cw1E5yCeQr19CsnP1mFfmAE0361DeA96B.com",
310 U_IDNA_ACE_PREFIX_ERROR
,
313 /* cannot verify U_IDNA_VERIFICATION_ERROR */
317 0x0077, 0x0077, 0x0077, 0x002e, /* www. */
318 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
319 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
320 0xC5BC, 0xB9C8, 0xB098, 0xC88B, 0xC744, 0xAE4C,
321 0x002e, 0x0063, 0x006f, 0x006d, /* com. */
324 "www.xn--989AoMsVi5E83Db1D2A355Cv1E0vAk1DwRv93D5xBh15A0Dt30A5JpSD879Ccm6FeA98C.com",
325 U_IDNA_LABEL_TOO_LONG_ERROR
,
331 0x0077, 0x0077, 0x0077, 0x002e, /* www. */
332 0x0030, 0x0644, 0x064A, 0x0647, 0x0031, /* Arabic code points squashed between EN codepoints */
333 0x002e, 0x0063, 0x006f, 0x006d, /* com. */
336 "www.xn--01-tvdmo.com",
337 U_IDNA_CHECK_BIDI_ERROR
,
343 0x0077, 0x0077, 0x0077, 0x002e, // www.
344 0x206C, 0x0644, 0x064A, 0x0647, 0x206D, // Arabic code points squashed between BN codepoints
345 0x002e, 0x0063, 0x006f, 0x006d, // com.
348 "www.XN--ghbgi278xia.com",
349 U_IDNA_PROHIBITED_ERROR
,
354 0x0077, 0x0077, 0x0077, 0x002e, // www.
355 0x002D, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, // HYPHEN at the start of label
356 0x002e, 0x0063, 0x006f, 0x006d, // com.
360 U_IDNA_STD3_ASCII_RULES_ERROR
,
365 0x0077, 0x0077, 0x0077, 0x002e, // www.
366 0x0041, 0x0042, 0x0043, 0x0044, 0x0045,0x002D, // HYPHEN at the end of the label
367 0x002e, 0x0063, 0x006f, 0x006d, // com.
371 U_IDNA_STD3_ASCII_RULES_ERROR
,
376 0x0077, 0x0077, 0x0077, 0x002e, // www.
377 0x0041, 0x0042, 0x0043, 0x0044, 0x0045,0x0040, // Containing non LDH code point
378 0x002e, 0x0063, 0x006f, 0x006d, // com.
382 U_IDNA_STD3_ASCII_RULES_ERROR
,
388 U_ILLEGAL_ARGUMENT_ERROR
,
394 static struct ConformanceTestCases
401 UErrorCode expectedStatus
;
403 conformanceTestCases
[] =
407 "Case folding ASCII U+0043 U+0041 U+0046 U+0045",
408 "\x43\x41\x46\x45", "\x63\x61\x66\x65",
409 "Nameprep", UIDNA_DEFAULT
,
414 "Case folding 8bit U+00DF (german sharp s)",
415 "\xC3\x9F", "\x73\x73",
416 "Nameprep", UIDNA_DEFAULT
,
420 "Non-ASCII multibyte space character U+1680",
421 "\xE1\x9A\x80", NULL
,
422 "Nameprep", UIDNA_DEFAULT
,
423 U_IDNA_PROHIBITED_ERROR
426 "Non-ASCII 8bit control character U+0085",
428 "Nameprep", UIDNA_DEFAULT
,
429 U_IDNA_PROHIBITED_ERROR
432 "Non-ASCII multibyte control character U+180E",
433 "\xE1\xA0\x8E", NULL
,
434 "Nameprep", UIDNA_DEFAULT
,
435 U_IDNA_PROHIBITED_ERROR
438 "Non-ASCII control character U+1D175",
439 "\xF0\x9D\x85\xB5", NULL
,
440 "Nameprep", UIDNA_DEFAULT
,
441 U_IDNA_PROHIBITED_ERROR
444 "Plane 0 private use character U+F123",
445 "\xEF\x84\xA3", NULL
,
446 "Nameprep", UIDNA_DEFAULT
,
447 U_IDNA_PROHIBITED_ERROR
450 "Plane 15 private use character U+F1234",
451 "\xF3\xB1\x88\xB4", NULL
,
452 "Nameprep", UIDNA_DEFAULT
,
453 U_IDNA_PROHIBITED_ERROR
456 "Plane 16 private use character U+10F234",
457 "\xF4\x8F\x88\xB4", NULL
,
458 "Nameprep", UIDNA_DEFAULT
,
459 U_IDNA_PROHIBITED_ERROR
462 "Non-character code point U+8FFFE",
463 "\xF2\x8F\xBF\xBE", NULL
,
464 "Nameprep", UIDNA_DEFAULT
,
465 U_IDNA_PROHIBITED_ERROR
468 "Non-character code point U+10FFFF",
469 "\xF4\x8F\xBF\xBF", NULL
,
470 "Nameprep", UIDNA_DEFAULT
,
471 U_IDNA_PROHIBITED_ERROR
475 "Surrogate code U+DF42",
476 "\xED\xBD\x82", NULL, "Nameprep", UIDNA_DEFAULT,
477 U_IDNA_PROHIBITED_ERROR
481 "Non-plain text character U+FFFD",
482 "\xEF\xBF\xBD", NULL
,
483 "Nameprep", UIDNA_DEFAULT
,
484 U_IDNA_PROHIBITED_ERROR
487 "Ideographic description character U+2FF5",
488 "\xE2\xBF\xB5", NULL
,
489 "Nameprep", UIDNA_DEFAULT
,
490 U_IDNA_PROHIBITED_ERROR
493 "Display property character U+0341",
494 "\xCD\x81", "\xCC\x81",
495 "Nameprep", UIDNA_DEFAULT
, U_ZERO_ERROR
500 "Left-to-right mark U+200E",
501 "\xE2\x80\x8E", "\xCC\x81",
502 "Nameprep", UIDNA_DEFAULT
,
503 U_IDNA_PROHIBITED_ERROR
508 "\xE2\x80\xAA", "\xCC\x81",
509 "Nameprep", UIDNA_DEFAULT
,
510 U_IDNA_PROHIBITED_ERROR
513 "Language tagging character U+E0001",
514 "\xF3\xA0\x80\x81", "\xCC\x81",
515 "Nameprep", UIDNA_DEFAULT
,
516 U_IDNA_PROHIBITED_ERROR
519 "Language tagging character U+E0042",
520 "\xF3\xA0\x81\x82", NULL
,
521 "Nameprep", UIDNA_DEFAULT
,
522 U_IDNA_PROHIBITED_ERROR
525 "Bidi: RandALCat character U+05BE and LCat characters",
526 "\x66\x6F\x6F\xD6\xBE\x62\x61\x72", NULL
,
527 "Nameprep", UIDNA_DEFAULT
,
528 U_IDNA_CHECK_BIDI_ERROR
531 "Bidi: RandALCat character U+FD50 and LCat characters",
532 "\x66\x6F\x6F\xEF\xB5\x90\x62\x61\x72", NULL
,
533 "Nameprep",UIDNA_DEFAULT
,
534 U_IDNA_CHECK_BIDI_ERROR
537 "Bidi: RandALCat character U+FB38 and LCat characters",
538 "\x66\x6F\x6F\xEF\xB9\xB6\x62\x61\x72", "\x66\x6F\x6F\x20\xd9\x8e\x62\x61\x72",
539 "Nameprep", UIDNA_DEFAULT
,
542 { "Bidi: RandALCat without trailing RandALCat U+0627 U+0031",
543 "\xD8\xA7\x31", NULL
,
544 "Nameprep", UIDNA_DEFAULT
,
545 U_IDNA_CHECK_BIDI_ERROR
548 "Bidi: RandALCat character U+0627 U+0031 U+0628",
549 "\xD8\xA7\x31\xD8\xA8", "\xD8\xA7\x31\xD8\xA8",
550 "Nameprep", UIDNA_DEFAULT
,
554 "Unassigned code point U+E0002",
555 "\xF3\xA0\x80\x82", NULL
,
556 "Nameprep", UIDNA_DEFAULT
,
557 U_IDNA_UNASSIGNED_ERROR
562 "Larger test (shrinking)",
563 "X\xC2\xAD\xC3\xDF\xC4\xB0\xE2\x84\xA1\x6a\xcc\x8c\xc2\xa0\xc2"
564 "\xaa\xce\xb0\xe2\x80\x80", "xssi\xcc\x87""tel\xc7\xb0 a\xce\xb0 ",
566 UIDNA_DEFAULT, U_ZERO_ERROR
570 "Larger test (expanding)",
571 "X\xC3\xDF\xe3\x8c\x96\xC4\xB0\xE2\x84\xA1\xE2\x92\x9F\xE3\x8c\x80",
572 "xss\xe3\x82\xad\xe3\x83\xad\xe3\x83\xa1\xe3\x83\xbc\xe3\x83\x88"
573 "\xe3\x83\xab""i\xcc\x87""tel\x28""d\x29\xe3\x82\xa2\xe3\x83\x91"
574 "\xe3\x83\xbc\xe3\x83\x88"
576 UIDNA_DEFAULT, U_ZERO_ERROR
583 #define MAX_DEST_SIZE 300
585 void TestIDNA::debug(const UChar
* src
, int32_t srcLength
, int32_t options
){
586 UParseError parseError
;
587 UErrorCode transStatus
= U_ZERO_ERROR
;
588 UErrorCode prepStatus
= U_ZERO_ERROR
;
589 NamePrepTransform
* trans
= NamePrepTransform::createInstance(parseError
,transStatus
);
590 int32_t prepOptions
= (((options
& UIDNA_ALLOW_UNASSIGNED
) != 0) ? USPREP_ALLOW_UNASSIGNED
: 0);
591 UStringPrepProfile
* prep
= usprep_open(NULL
,"uidna",&prepStatus
);
592 UChar
*transOut
=NULL
, *prepOut
=NULL
;
593 int32_t transOutLength
=0, prepOutLength
=0;
596 transOutLength
= trans
->process(src
,srcLength
,transOut
, 0, prepOptions
>0, &parseError
, transStatus
);
597 if( transStatus
== U_BUFFER_OVERFLOW_ERROR
){
598 transStatus
= U_ZERO_ERROR
;
599 transOut
= (UChar
*) malloc(U_SIZEOF_UCHAR
* transOutLength
);
600 transOutLength
= trans
->process(src
,srcLength
,transOut
, transOutLength
, prepOptions
>0, &parseError
, transStatus
);
603 prepOutLength
= usprep_prepare(prep
, src
, srcLength
, prepOut
, 0, prepOptions
, &parseError
, &prepStatus
);
605 if( prepStatus
== U_BUFFER_OVERFLOW_ERROR
){
606 prepStatus
= U_ZERO_ERROR
;
607 prepOut
= (UChar
*) malloc(U_SIZEOF_UCHAR
* prepOutLength
);
608 prepOutLength
= usprep_prepare(prep
, src
, srcLength
, prepOut
, prepOutLength
, prepOptions
, &parseError
, &prepStatus
);
611 if(UnicodeString(transOut
,transOutLength
)!= UnicodeString(prepOut
, prepOutLength
)){
612 errln("Failed. Expected: " + prettify(UnicodeString(transOut
, transOutLength
))
613 + " Got: " + prettify(UnicodeString(prepOut
,prepOutLength
)));
621 void TestIDNA::testAPI(const UChar
* src
, const UChar
* expected
, const char* testName
,
622 UBool useSTD3ASCIIRules
,UErrorCode expectedStatus
,
623 UBool doCompare
, UBool testUnassigned
, TestFunc func
, UBool testSTD3ASCIIRules
){
625 UErrorCode status
= U_ZERO_ERROR
;
626 UChar destStack
[MAX_DEST_SIZE
];
629 int32_t expectedLen
= (expected
!= NULL
) ? u_strlen(expected
) : 0;
630 int32_t options
= (useSTD3ASCIIRules
== TRUE
) ? UIDNA_USE_STD3_RULES
: UIDNA_DEFAULT
;
631 UParseError parseError
;
636 tSrcLen
= u_strlen(src
);
637 tSrc
=(UChar
*) malloc( U_SIZEOF_UCHAR
* tSrcLen
);
638 memcpy(tSrc
,src
,tSrcLen
* U_SIZEOF_UCHAR
);
641 // test null-terminated source and return value of number of UChars required
642 destLen
= func(src
,-1,NULL
,0,options
, &parseError
, &status
);
643 if(status
== U_BUFFER_OVERFLOW_ERROR
){
644 status
= U_ZERO_ERROR
; // reset error code
645 if(destLen
+1 < MAX_DEST_SIZE
){
647 destLen
= func(src
,-1,dest
,destLen
+1,options
, &parseError
, &status
);
648 // TODO : compare output with expected
649 if(U_SUCCESS(status
) && expectedStatus
!= U_IDNA_STD3_ASCII_RULES_ERROR
&& (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
650 errln("Did not get the expected result for "+UnicodeString(testName
) +" null terminated source. Expected : "
651 + prettify(UnicodeString(expected
,expectedLen
))
652 + " Got: " + prettify(UnicodeString(dest
,destLen
))
656 errln( "%s null terminated source failed. Requires destCapacity > 300\n",testName
);
660 if(status
!= expectedStatus
){
661 errln( "Did not get the expected error for"+
662 UnicodeString(testName
)+
663 "null terminated source. Expected: " +UnicodeString(u_errorName(expectedStatus
))
664 + " Got: "+ UnicodeString(u_errorName(status
))
665 + " Source: " + prettify(UnicodeString(src
))
671 status
= U_ZERO_ERROR
;
672 destLen
= func(src
,-1,NULL
,0,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
673 if(status
== U_BUFFER_OVERFLOW_ERROR
){
674 status
= U_ZERO_ERROR
; // reset error code
675 if(destLen
+1 < MAX_DEST_SIZE
){
677 destLen
= func(src
,-1,dest
,destLen
+1,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
678 // TODO : compare output with expected
679 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
680 //errln("Did not get the expected result for %s null terminated source with both options set.\n",testName);
681 errln("Did not get the expected result for "+UnicodeString(testName
) +
682 " null terminated source "+ prettify(src
) +
683 " with both options set. Expected: "+ prettify(UnicodeString(expected
,expectedLen
))+
684 "Got: " + prettify(UnicodeString(dest
,destLen
)));
686 debug(src
,-1,options
| UIDNA_ALLOW_UNASSIGNED
);
690 errln( "%s null terminated source failed. Requires destCapacity > 300\n",testName
);
693 //testing query string
694 if(status
!= expectedStatus
&& expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
){
695 errln( "Did not get the expected error for"+
696 UnicodeString(testName
)+
697 "null terminated source with options set. Expected: " +UnicodeString(u_errorName(expectedStatus
))
698 + " Got: "+ UnicodeString(u_errorName(status
))
699 + " Source: " + prettify(UnicodeString(src
))
704 status
= U_ZERO_ERROR
;
706 // test source with lengthand return value of number of UChars required
707 destLen
= func(tSrc
, tSrcLen
, NULL
,0,options
, &parseError
, &status
);
708 if(status
== U_BUFFER_OVERFLOW_ERROR
){
709 status
= U_ZERO_ERROR
; // reset error code
710 if(destLen
+1 < MAX_DEST_SIZE
){
712 destLen
= func(src
,u_strlen(src
),dest
,destLen
+1,options
, &parseError
, &status
);
713 // TODO : compare output with expected
714 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
715 errln("Did not get the expected result for %s with source length.\n",testName
);
718 errln( "%s with source length failed. Requires destCapacity > 300\n",testName
);
722 if(status
!= expectedStatus
){
723 errln( "Did not get the expected error for"+
724 UnicodeString(testName
)+
725 "with source length. Expected: " +UnicodeString(u_errorName(expectedStatus
))
726 + " Got: "+ UnicodeString(u_errorName(status
))
727 + " Source: " + prettify(UnicodeString(src
))
731 status
= U_ZERO_ERROR
;
733 destLen
= func(tSrc
,tSrcLen
,NULL
,0,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
735 if(status
== U_BUFFER_OVERFLOW_ERROR
){
736 status
= U_ZERO_ERROR
; // reset error code
737 if(destLen
+1 < MAX_DEST_SIZE
){
739 destLen
= func(src
,u_strlen(src
),dest
,destLen
+1,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
740 // TODO : compare output with expected
741 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
742 errln("Did not get the expected result for %s with source length and both options set.\n",testName
);
745 errln( "%s with source length failed. Requires destCapacity > 300\n",testName
);
748 //testing query string
749 if(status
!= expectedStatus
&& expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
){
750 errln( "Did not get the expected error for"+
751 UnicodeString(testName
)+
752 "with source length and options set. Expected: " +UnicodeString(u_errorName(expectedStatus
))
753 + " Got: "+ UnicodeString(u_errorName(status
))
754 + " Source: " + prettify(UnicodeString(src
))
759 status
= U_ZERO_ERROR
;
760 if(testSTD3ASCIIRules
==TRUE
){
761 destLen
= func(src
,-1,NULL
,0,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
762 if(status
== U_BUFFER_OVERFLOW_ERROR
){
763 status
= U_ZERO_ERROR
; // reset error code
764 if(destLen
+1 < MAX_DEST_SIZE
){
766 destLen
= func(src
,-1,dest
,destLen
+1,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
767 // TODO : compare output with expected
768 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
769 //errln("Did not get the expected result for %s null terminated source with both options set.\n",testName);
770 errln("Did not get the expected result for "+UnicodeString(testName
) +" null terminated source with both options set. Expected: "+ prettify(UnicodeString(expected
,expectedLen
)));
774 errln( "%s null terminated source failed. Requires destCapacity > 300\n",testName
);
777 //testing query string
778 if(status
!= expectedStatus
){
779 errln( "Did not get the expected error for"+
780 UnicodeString(testName
)+
781 "null terminated source with options set. Expected: " +UnicodeString(u_errorName(expectedStatus
))
782 + " Got: "+ UnicodeString(u_errorName(status
))
783 + " Source: " + prettify(UnicodeString(src
))
787 status
= U_ZERO_ERROR
;
789 destLen
= func(tSrc
,tSrcLen
,NULL
,0,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
791 if(status
== U_BUFFER_OVERFLOW_ERROR
){
792 status
= U_ZERO_ERROR
; // reset error code
793 if(destLen
+1 < MAX_DEST_SIZE
){
795 destLen
= func(src
,u_strlen(src
),dest
,destLen
+1,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
796 // TODO : compare output with expected
797 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
798 errln("Did not get the expected result for %s with source length and both options set.\n",testName
);
801 errln( "%s with source length failed. Requires destCapacity > 300\n",testName
);
804 //testing query string
805 if(status
!= expectedStatus
&& expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
){
806 errln( "Did not get the expected error for"+
807 UnicodeString(testName
)+
808 "with source length and options set. Expected: " +UnicodeString(u_errorName(expectedStatus
))
809 + " Got: "+ UnicodeString(u_errorName(status
))
810 + " Source: " + prettify(UnicodeString(src
))
817 void TestIDNA::testCompare(const UChar
* s1
, int32_t s1Len
,
818 const UChar
* s2
, int32_t s2Len
,
819 const char* testName
, CompareFunc func
,
822 UErrorCode status
= U_ZERO_ERROR
;
823 int32_t retVal
= func(s1
,-1,s2
,-1,UIDNA_DEFAULT
,&status
);
825 if(isEqual
==TRUE
&& retVal
!=0){
826 errln("Did not get the expected result for %s with null termniated strings.\n",testName
);
828 if(U_FAILURE(status
)){
829 errln( "%s null terminated source failed. Error: %s\n", testName
,u_errorName(status
));
832 status
= U_ZERO_ERROR
;
833 retVal
= func(s1
,-1,s2
,-1,UIDNA_ALLOW_UNASSIGNED
,&status
);
835 if(isEqual
==TRUE
&& retVal
!=0){
836 errln("Did not get the expected result for %s with null termniated strings with options set.\n", testName
);
838 if(U_FAILURE(status
)){
839 errln( "%s null terminated source and options set failed. Error: %s\n",testName
, u_errorName(status
));
842 status
= U_ZERO_ERROR
;
843 retVal
= func(s1
,s1Len
,s2
,s2Len
,UIDNA_DEFAULT
,&status
);
845 if(isEqual
==TRUE
&& retVal
!=0){
846 errln("Did not get the expected result for %s with string length.\n",testName
);
848 if(U_FAILURE(status
)){
849 errln( "%s with string length. Error: %s\n",testName
, u_errorName(status
));
852 status
= U_ZERO_ERROR
;
853 retVal
= func(s1
,s1Len
,s2
,s2Len
,UIDNA_ALLOW_UNASSIGNED
,&status
);
855 if(isEqual
==TRUE
&& retVal
!=0){
856 errln("Did not get the expected result for %s with string length and options set.\n",testName
);
858 if(U_FAILURE(status
)){
859 errln( "%s with string length and options set. Error: %s\n", u_errorName(status
), testName
);
863 void TestIDNA::testToASCII(const char* testName
, TestFunc func
){
866 UChar buf
[MAX_DEST_SIZE
];
868 for(i
=0;i
< (int32_t)(sizeof(unicodeIn
)/sizeof(unicodeIn
[0])); i
++){
869 u_charsToUChars(asciiIn
[i
],buf
, (int32_t)(strlen(asciiIn
[i
])+1));
870 testAPI(unicodeIn
[i
], buf
,testName
, FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
875 void TestIDNA::testToUnicode(const char* testName
, TestFunc func
){
878 UChar buf
[MAX_DEST_SIZE
];
880 for(i
=0;i
< (int32_t)(sizeof(asciiIn
)/sizeof(asciiIn
[0])); i
++){
881 u_charsToUChars(asciiIn
[i
],buf
, (int32_t)(strlen(asciiIn
[i
])+1));
882 testAPI(buf
,unicodeIn
[i
],testName
,FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
887 void TestIDNA::testIDNToUnicode(const char* testName
, TestFunc func
){
889 UChar buf
[MAX_DEST_SIZE
];
890 UChar expected
[MAX_DEST_SIZE
];
891 UErrorCode status
= U_ZERO_ERROR
;
893 UParseError parseError
;
894 for(i
=0;i
< (int32_t)(sizeof(domainNames
)/sizeof(domainNames
[0])); i
++){
895 bufLen
= (int32_t)strlen(domainNames
[i
]);
896 bufLen
= u_unescape(domainNames
[i
],buf
, bufLen
+1);
897 func(buf
,bufLen
,expected
,MAX_DEST_SIZE
, UIDNA_ALLOW_UNASSIGNED
, &parseError
,&status
);
898 if(U_FAILURE(status
)){
899 errln( "%s failed to convert domainNames[%i].Error: %s \n",testName
, i
, u_errorName(status
));
902 testAPI(buf
,expected
,testName
,FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
903 //test toUnicode with all labels in the string
904 testAPI(buf
,expected
,testName
, FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
905 if(U_FAILURE(status
)){
906 errln( "%s failed to convert domainNames[%i].Error: %s \n",testName
,i
, u_errorName(status
));
913 void TestIDNA::testIDNToASCII(const char* testName
, TestFunc func
){
915 UChar buf
[MAX_DEST_SIZE
];
916 UChar expected
[MAX_DEST_SIZE
];
917 UErrorCode status
= U_ZERO_ERROR
;
919 UParseError parseError
;
920 for(i
=0;i
< (int32_t)(sizeof(domainNames
)/sizeof(domainNames
[0])); i
++){
921 bufLen
= (int32_t)strlen(domainNames
[i
]);
922 bufLen
= u_unescape(domainNames
[i
],buf
, bufLen
+1);
923 func(buf
,bufLen
,expected
,MAX_DEST_SIZE
, UIDNA_ALLOW_UNASSIGNED
, &parseError
,&status
);
924 if(U_FAILURE(status
)){
925 errln( "%s failed to convert domainNames[%i].Error: %s \n",testName
,i
, u_errorName(status
));
928 testAPI(buf
,expected
,testName
, FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
929 //test toASCII with all labels in the string
930 testAPI(buf
,expected
,testName
, FALSE
,U_ZERO_ERROR
, FALSE
, TRUE
, func
);
931 if(U_FAILURE(status
)){
932 errln( "%s failed to convert domainNames[%i].Error: %s \n",testName
,i
, u_errorName(status
));
939 void TestIDNA::testCompare(const char* testName
, CompareFunc func
){
943 UChar www
[] = {0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
944 UChar com
[] = {0x002E, 0x0043, 0x004F, 0x004D, 0x0000};
945 UChar buf
[MAX_DEST_SIZE
]={0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
947 UnicodeString
source(www
), uni0(www
),uni1(www
), ascii0(www
), ascii1(www
);
949 uni0
.append(unicodeIn
[0]);
951 uni0
.append((UChar
)0x0000);
953 uni1
.append(unicodeIn
[1]);
955 uni1
.append((UChar
)0x0000);
957 ascii0
.append(asciiIn
[0]);
959 ascii0
.append((UChar
)0x0000);
961 ascii1
.append(asciiIn
[1]);
963 ascii1
.append((UChar
)0x0000);
965 for(i
=0;i
< (int32_t)(sizeof(unicodeIn
)/sizeof(unicodeIn
[0])); i
++){
967 u_charsToUChars(asciiIn
[i
],buf
+4, (int32_t)(strlen(asciiIn
[i
])+1));
970 // for every entry in unicodeIn array
971 // prepend www. and append .com
973 source
.append(unicodeIn
[i
]);
975 source
.append((UChar
)0x0000);
976 // a) compare it with itself
977 const UChar
* src
= source
.getBuffer();
978 int32_t srcLen
= u_strlen(src
); //subtract null
980 testCompare(src
,srcLen
,src
,srcLen
,testName
, func
, TRUE
);
982 // b) compare it with asciiIn equivalent
983 testCompare(src
,srcLen
,buf
,u_strlen(buf
),testName
, func
,TRUE
);
985 // c) compare it with unicodeIn not equivalent
987 testCompare(src
,srcLen
,uni1
.getBuffer(),uni1
.length()-1,testName
, func
,FALSE
);
988 uni1
.releaseBuffer();
990 testCompare(src
,srcLen
,uni0
.getBuffer(),uni0
.length()-1,testName
, func
,FALSE
);
991 uni0
.releaseBuffer();
993 // d) compare it with asciiIn not equivalent
995 testCompare(src
,srcLen
,ascii1
.getBuffer(),ascii1
.length()-1,testName
, func
,FALSE
);
996 ascii1
.releaseBuffer();
998 testCompare(src
,srcLen
,ascii0
.getBuffer(),ascii0
.length()-1,testName
, func
,FALSE
);
999 ascii0
.releaseBuffer();
1008 getNextSeperator(UChar
*src
,int32_t srcLength
,
1010 if(srcLength
== -1){
1014 *limit
= src
+ i
; // point to null
1018 *limit
= src
+ (i
+1); // go past the delimiter
1022 // we have not found the delimiter
1024 *limit
= src
+srcLength
;
1029 for(i
=0;i
<srcLength
;i
++){
1031 *limit
= src
+ (i
+1); // go past the delimiter
1035 // we have not found the delimiter
1037 *limit
= src
+srcLength
;
1043 void printPunycodeOutput(){
1045 UChar dest
[MAX_DEST_SIZE
];
1046 int32_t destCapacity
=MAX_DEST_SIZE
;
1050 UBool caseFlags
[MAX_DEST_SIZE
];
1052 for(int32_t i
=0;i
< sizeof(errorCases
)/sizeof(errorCases
[0]);i
++){
1053 ErrorCases errorCase
= errorCases
[i
];
1054 UErrorCode status
= U_ZERO_ERROR
;
1055 start
= errorCase
.unicode
;
1056 int32_t srcLen
= u_strlen(start
);
1057 labelLen
= getNextSeperator(start
,srcLen
,&limit
);
1059 labelLen
=getNextSeperator(start
,srcLen
-labelLen
,&limit
);
1060 int32_t destLen
= u_strToPunycode(dest
,destCapacity
,start
,labelLen
,caseFlags
, &status
);
1061 if(U_FAILURE(status
)){
1062 printf("u_strToPunycode failed for index %i\n",i
);
1065 for(int32_t j
=0; j
<destLen
; j
++){
1066 printf("%c",(char)dest
[j
]);
1073 void TestIDNA::testErrorCases(const char* IDNToASCIIName
, TestFunc IDNToASCII
,
1074 const char* IDNToUnicodeName
, TestFunc IDNToUnicode
){
1075 UChar buf
[MAX_DEST_SIZE
];
1078 for(int32_t i
=0;i
< (int32_t)(sizeof(errorCases
)/sizeof(errorCases
[0]));i
++){
1079 ErrorCases errorCase
= errorCases
[i
];
1081 if(errorCase
.ascii
!= NULL
){
1082 bufLen
= (int32_t)strlen(errorCase
.ascii
);
1083 u_charsToUChars(errorCase
.ascii
,buf
, bufLen
+1);
1086 memset(buf
,0,U_SIZEOF_UCHAR
*MAX_DEST_SIZE
);
1089 if(errorCase
.unicode
[0]!=0){
1090 src
= errorCase
.unicode
;
1094 IDNToASCIIName
, errorCase
.useSTD3ASCIIRules
,
1095 errorCase
.expected
, TRUE
, TRUE
, IDNToASCII
);
1096 if(errorCase
.testLabel
==TRUE
){
1098 IDNToASCIIName
, errorCase
.useSTD3ASCIIRules
,
1099 errorCase
.expected
, FALSE
,TRUE
, IDNToASCII
);
1101 if(errorCase
.testToUnicode
==TRUE
){
1102 testAPI((src
==NULL
)? NULL
: buf
,src
,
1103 IDNToUnicodeName
, errorCase
.useSTD3ASCIIRules
,
1104 errorCase
.expected
, TRUE
, TRUE
, IDNToUnicode
);
1111 void TestIDNA::testConformance(const char* toASCIIName
, TestFunc toASCII
,
1112 const char* IDNToASCIIName
, TestFunc IDNToASCII
,
1113 const char* IDNToUnicodeName
, TestFunc IDNToUnicode
,
1114 const char* toUnicodeName
, TestFunc toUnicode
){
1115 UChar src
[MAX_DEST_SIZE
];
1117 UChar expected
[MAX_DEST_SIZE
];
1118 int32_t expectedLen
= 0;
1119 for(int32_t i
=0;i
< (int32_t)(sizeof(conformanceTestCases
)/sizeof(conformanceTestCases
[0]));i
++){
1120 const char* utf8Chars1
= conformanceTestCases
[i
].in
;
1121 int32_t utf8Chars1Len
= (int32_t)strlen(utf8Chars1
);
1122 const char* utf8Chars2
= conformanceTestCases
[i
].out
;
1123 int32_t utf8Chars2Len
= (utf8Chars2
== NULL
) ? 0 : (int32_t)strlen(utf8Chars2
);
1125 UErrorCode status
= U_ZERO_ERROR
;
1126 u_strFromUTF8(src
,MAX_DEST_SIZE
,&srcLen
,utf8Chars1
,utf8Chars1Len
,&status
);
1127 if(U_FAILURE(status
)){
1128 errln(UnicodeString("Conversion of UTF8 source in conformanceTestCases[") + i
+UnicodeString( "].in ( ")+prettify(utf8Chars1
) +UnicodeString(" ) failed. Error: ")+ UnicodeString(u_errorName(status
)));
1131 if(utf8Chars2
!= NULL
){
1132 u_strFromUTF8(expected
,MAX_DEST_SIZE
,&expectedLen
,utf8Chars2
,utf8Chars2Len
, &status
);
1133 if(U_FAILURE(status
)){
1134 errln(UnicodeString("Conversion of UTF8 source in conformanceTestCases[") + i
+UnicodeString( "].in ( ")+prettify(utf8Chars1
) +UnicodeString(" ) failed. Error: ")+ UnicodeString(u_errorName(status
)));
1139 if(conformanceTestCases
[i
].expectedStatus
!= U_ZERO_ERROR
){
1141 testAPI(src
,expected
,
1142 IDNToASCIIName
, FALSE
,
1143 conformanceTestCases
[i
].expectedStatus
,
1145 (conformanceTestCases
[i
].expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
),
1148 testAPI(src
,expected
,
1150 conformanceTestCases
[i
].expectedStatus
, TRUE
,
1151 (conformanceTestCases
[i
].expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
),
1156 IDNToUnicodeName
, FALSE
,
1157 conformanceTestCases
[i
].expectedStatus
, TRUE
, TRUE
, IDNToUnicode
);
1159 toUnicodeName
, FALSE
,
1160 conformanceTestCases
[i
].expectedStatus
, TRUE
, TRUE
, toUnicode
);
1166 // test and ascertain
1167 // func(func(func(src))) == func(src)
1168 void TestIDNA::testChaining(UChar
* src
,int32_t numIterations
,const char* testName
,
1169 UBool useSTD3ASCIIRules
, UBool caseInsensitive
, TestFunc func
){
1170 UChar even
[MAX_DEST_SIZE
];
1171 UChar odd
[MAX_DEST_SIZE
];
1172 UChar expected
[MAX_DEST_SIZE
];
1173 int32_t i
=0,evenLen
=0,oddLen
=0,expectedLen
=0;
1174 UErrorCode status
= U_ZERO_ERROR
;
1175 int32_t srcLen
= u_strlen(src
);
1176 int32_t options
= (useSTD3ASCIIRules
== TRUE
) ? UIDNA_USE_STD3_RULES
: UIDNA_DEFAULT
;
1177 UParseError parseError
;
1179 // test null-terminated source
1180 expectedLen
= func(src
,-1,expected
,MAX_DEST_SIZE
, options
, &parseError
, &status
);
1181 if(U_FAILURE(status
)){
1182 errln("%s null terminated source failed. Error: %s\n",testName
, u_errorName(status
));
1184 memcpy(odd
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1185 memcpy(even
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1186 for(;i
<=numIterations
; i
++){
1188 evenLen
= func(odd
,-1,even
,MAX_DEST_SIZE
,options
, &parseError
, &status
);
1189 if(U_FAILURE(status
)){
1190 errln("%s null terminated source failed\n",testName
);
1194 oddLen
= func(even
,-1,odd
,MAX_DEST_SIZE
,options
, &parseError
, &status
);
1195 if(U_FAILURE(status
)){
1196 errln("%s null terminated source failed\n",testName
);
1201 if(caseInsensitive
==TRUE
){
1202 if( u_strCaseCompare(even
,evenLen
, expected
,expectedLen
, 0, &status
) !=0 ||
1203 u_strCaseCompare(odd
,oddLen
, expected
,expectedLen
, 0, &status
) !=0 ){
1205 errln("Chaining for %s null terminated source failed\n",testName
);
1208 if( u_strncmp(even
,expected
,expectedLen
) != 0 ||
1209 u_strncmp(odd
,expected
,expectedLen
) !=0 ){
1211 errln("Chaining for %s null terminated source failed\n",testName
);
1215 // test null-terminated source
1216 status
= U_ZERO_ERROR
;
1217 expectedLen
= func(src
,-1,expected
,MAX_DEST_SIZE
,options
|UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
1218 if(U_FAILURE(status
)){
1219 errln("%s null terminated source with options set failed. Error: %s\n",testName
, u_errorName(status
));
1221 memcpy(odd
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1222 memcpy(even
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1223 for(;i
<=numIterations
; i
++){
1225 evenLen
= func(odd
,-1,even
,MAX_DEST_SIZE
,options
|UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
1226 if(U_FAILURE(status
)){
1227 errln("%s null terminated source with options set failed\n",testName
);
1231 oddLen
= func(even
,-1,odd
,MAX_DEST_SIZE
,options
|UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
1232 if(U_FAILURE(status
)){
1233 errln("%s null terminated source with options set failed\n",testName
);
1238 if(caseInsensitive
==TRUE
){
1239 if( u_strCaseCompare(even
,evenLen
, expected
,expectedLen
, 0, &status
) !=0 ||
1240 u_strCaseCompare(odd
,oddLen
, expected
,expectedLen
, 0, &status
) !=0 ){
1242 errln("Chaining for %s null terminated source with options set failed\n",testName
);
1245 if( u_strncmp(even
,expected
,expectedLen
) != 0 ||
1246 u_strncmp(odd
,expected
,expectedLen
) !=0 ){
1248 errln("Chaining for %s null terminated source with options set failed\n",testName
);
1253 // test source with length
1254 status
= U_ZERO_ERROR
;
1255 expectedLen
= func(src
,srcLen
,expected
,MAX_DEST_SIZE
,options
, &parseError
, &status
);
1256 if(U_FAILURE(status
)){
1257 errln("%s null terminated source failed. Error: %s\n",testName
, u_errorName(status
));
1259 memcpy(odd
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1260 memcpy(even
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1261 for(;i
<=numIterations
; i
++){
1263 evenLen
= func(odd
,oddLen
,even
,MAX_DEST_SIZE
,options
, &parseError
, &status
);
1264 if(U_FAILURE(status
)){
1265 errln("%s source with source length failed\n",testName
);
1269 oddLen
= func(even
,evenLen
,odd
,MAX_DEST_SIZE
,options
, &parseError
, &status
);
1270 if(U_FAILURE(status
)){
1271 errln("%s source with source length failed\n",testName
);
1276 if(caseInsensitive
==TRUE
){
1277 if( u_strCaseCompare(even
,evenLen
, expected
,expectedLen
, 0, &status
) !=0 ||
1278 u_strCaseCompare(odd
,oddLen
, expected
,expectedLen
, 0, &status
) !=0 ){
1280 errln("Chaining for %s source with source length failed\n",testName
);
1283 if( u_strncmp(even
,expected
,expectedLen
) != 0 ||
1284 u_strncmp(odd
,expected
,expectedLen
) !=0 ){
1286 errln("Chaining for %s source with source length failed\n",testName
);
1289 status
= U_ZERO_ERROR
;
1290 expectedLen
= func(src
,srcLen
,expected
,MAX_DEST_SIZE
,options
|UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
1291 if(U_FAILURE(status
)){
1292 errln("%s null terminated source with options set failed. Error: %s\n",testName
, u_errorName(status
));
1294 memcpy(odd
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1295 memcpy(even
,expected
,(expectedLen
+1) * U_SIZEOF_UCHAR
);
1296 for(;i
<=numIterations
; i
++){
1298 evenLen
= func(odd
,oddLen
,even
,MAX_DEST_SIZE
,options
|UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
1299 if(U_FAILURE(status
)){
1300 errln("%s source with source length and options set failed\n",testName
);
1304 oddLen
= func(even
,evenLen
,odd
,MAX_DEST_SIZE
,options
|UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
1305 if(U_FAILURE(status
)){
1306 errln("%s source with source length and options set failed\n",testName
);
1311 if(caseInsensitive
==TRUE
){
1312 if( u_strCaseCompare(even
,evenLen
, expected
,expectedLen
, 0, &status
) !=0 ||
1313 u_strCaseCompare(odd
,oddLen
, expected
,expectedLen
, 0, &status
) !=0 ){
1315 errln("Chaining for %s source with source length and options set failed\n",testName
);
1318 if( u_strncmp(even
,expected
,expectedLen
) != 0 ||
1319 u_strncmp(odd
,expected
,expectedLen
) !=0 ){
1321 errln("Chaining for %s source with source length and options set failed\n",testName
);
1325 void TestIDNA::testChaining(const char* toASCIIName
, TestFunc toASCII
,
1326 const char* toUnicodeName
, TestFunc toUnicode
){
1328 UChar buf
[MAX_DEST_SIZE
];
1330 for(i
=0;i
< (int32_t)(sizeof(asciiIn
)/sizeof(asciiIn
[0])); i
++){
1331 u_charsToUChars(asciiIn
[i
],buf
, (int32_t)(strlen(asciiIn
[i
])+1));
1332 testChaining(buf
,5,toUnicodeName
, FALSE
, FALSE
, toUnicode
);
1334 for(i
=0;i
< (int32_t)(sizeof(unicodeIn
)/sizeof(unicodeIn
[0])); i
++){
1335 testChaining(unicodeIn
[i
], 5,toASCIIName
, FALSE
, TRUE
, toASCII
);
1340 void TestIDNA::testRootLabelSeparator(const char* testName
, CompareFunc func
,
1341 const char* IDNToASCIIName
, TestFunc IDNToASCII
,
1342 const char* IDNToUnicodeName
, TestFunc IDNToUnicode
){
1346 UChar www
[] = {0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
1347 UChar com
[] = {0x002E, 0x0043, 0x004F, 0x004D, 0x002E, /* root label separator */0x0000};
1348 UChar buf
[MAX_DEST_SIZE
]={0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
1350 UnicodeString
source(www
), uni0(www
),uni1(www
), ascii0(www
), ascii1(www
);
1352 uni0
.append(unicodeIn
[0]);
1354 uni0
.append((UChar
)0x0000);
1356 uni1
.append(unicodeIn
[1]);
1358 uni1
.append((UChar
)0x0000);
1360 ascii0
.append(asciiIn
[0]);
1362 ascii0
.append((UChar
)0x0000);
1364 ascii1
.append(asciiIn
[1]);
1366 ascii1
.append((UChar
)0x0000);
1368 for(i
=0;i
< (int32_t)(sizeof(unicodeIn
)/sizeof(unicodeIn
[0])); i
++){
1370 u_charsToUChars(asciiIn
[i
],buf
+4, (int32_t)(strlen(asciiIn
[i
])+1));
1373 // for every entry in unicodeIn array
1374 // prepend www. and append .com
1376 source
.append(unicodeIn
[i
]);
1378 source
.append((UChar
)0x0000);
1380 const UChar
* src
= source
.getBuffer();
1381 int32_t srcLen
= u_strlen(src
); //subtract null
1383 // b) compare it with asciiIn equivalent
1384 testCompare(src
,srcLen
,buf
,u_strlen(buf
),testName
, func
,TRUE
);
1386 // a) compare it with itself
1387 testCompare(src
,srcLen
,src
,srcLen
,testName
, func
,TRUE
);
1390 // IDNToASCII comparison
1391 testAPI(src
,buf
,IDNToASCIIName
,FALSE
,U_ZERO_ERROR
,TRUE
, TRUE
, IDNToASCII
);
1392 // IDNToUnicode comparison
1393 testAPI(buf
,src
,IDNToUnicodeName
, FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, IDNToUnicode
);
1395 // c) compare it with unicodeIn not equivalent
1397 testCompare(src
,srcLen
,uni1
.getBuffer(),uni1
.length()-1,testName
, func
,FALSE
);
1398 uni1
.releaseBuffer();
1400 testCompare(src
,srcLen
,uni0
.getBuffer(),uni0
.length()-1,testName
, func
,FALSE
);
1401 uni0
.releaseBuffer();
1403 // d) compare it with asciiIn not equivalent
1405 testCompare(src
,srcLen
,ascii1
.getBuffer(),ascii1
.length()-1,testName
, func
,FALSE
);
1406 ascii1
.releaseBuffer();
1408 testCompare(src
,srcLen
,ascii0
.getBuffer(),ascii0
.length()-1,testName
, func
,FALSE
);
1409 ascii0
.releaseBuffer();
1414 //---------------------------------------------
1416 //---------------------------------------------
1418 void TestIDNA::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
1420 if (exec
) logln((UnicodeString
)"TestSuite IDNA API ");
1423 case 0: name
= "TestToASCII"; if (exec
) TestToASCII(); break;
1424 case 1: name
= "TestToUnicode"; if (exec
) TestToUnicode(); break;
1425 case 2: name
= "TestIDNToASCII"; if (exec
) TestIDNToASCII(); break;
1426 case 3: name
= "TestIDNToUnicode"; if (exec
) TestIDNToUnicode(); break;
1427 case 4: name
= "TestCompare"; if (exec
) TestCompare(); break;
1428 case 5: name
= "TestErrorCases"; if (exec
) TestErrorCases(); break;
1429 case 6: name
= "TestChaining"; if (exec
) TestChaining(); break;
1430 case 7: name
= "TestRootLabelSeparator"; if(exec
) TestRootLabelSeparator(); break;
1431 case 8: name
= "TestCompareReferenceImpl"; if(exec
) TestCompareReferenceImpl(); break;
1432 case 9: name
= "TestDataFile"; if(exec
) TestDataFile(); break;
1433 case 10: name
= "TestRefIDNA"; if(exec
) TestRefIDNA(); break;
1434 case 11: name
= "TestIDNAMonkeyTest"; if(exec
) TestIDNAMonkeyTest(); break;
1435 case 12: name
= "TestConformance"; if(exec
) TestConformance();break;
1436 default: name
= ""; break; /*needed to end loop*/
1439 void TestIDNA::TestToASCII(){
1440 testToASCII("uidna_toASCII", uidna_toASCII
);
1442 void TestIDNA::TestToUnicode(){
1443 testToUnicode("uidna_toUnicode", uidna_toUnicode
);
1445 void TestIDNA::TestIDNToASCII(){
1446 testIDNToASCII("uidna_IDNToASCII", uidna_IDNToASCII
);
1448 void TestIDNA::TestIDNToUnicode(){
1449 testIDNToUnicode("uidna_IDNToUnicode", uidna_IDNToUnicode
);
1451 void TestIDNA::TestCompare(){
1452 testCompare("uidna_compare",uidna_compare
);
1454 void TestIDNA::TestErrorCases(){
1455 testErrorCases( "uidna_IDNToASCII",uidna_IDNToASCII
,
1456 "uidna_IDNToUnicode",uidna_IDNToUnicode
);
1458 void TestIDNA::TestRootLabelSeparator(){
1459 testRootLabelSeparator( "uidna_compare",uidna_compare
,
1460 "uidna_IDNToASCII", uidna_IDNToASCII
,
1461 "uidna_IDNToUnicode",uidna_IDNToUnicode
1464 void TestIDNA::TestChaining(){
1465 testChaining("uidna_toASCII",uidna_toASCII
, "uidna_toUnicode", uidna_toUnicode
);
1467 void TestIDNA::TestConformance(){
1468 testConformance("uidna_toASCII",uidna_toASCII
,"uidna_IDNToASCII",uidna_IDNToASCII
,
1469 "uidna_IDNToUnicode",uidna_IDNToUnicode
, "uidna_toUnicode", uidna_toUnicode
);
1472 static const int loopCount
= 100;
1473 static const int maxCharCount
= 20;
1474 static const int maxCodePoint
= 0x10ffff;
1478 static UBool initialized
= FALSE
;
1481 srand((unsigned)time(NULL
));
1484 // Assume rand has at least 12 bits of precision
1486 for (uint32_t i
=0; i
<sizeof(l
); ++i
)
1487 ((char*)&l
)[i
] = (char)((rand() & 0x0FF0) >> 4);
1492 * Return a random integer i where 0 <= i < n.
1493 * A special function that gets random codepoints from planes 0,1,2 and 14
1495 static int32_t rand_uni()
1497 int32_t retVal
= (int32_t)(randul()& 0x3FFFF);
1498 if(retVal
>= 0x30000){
1504 static int32_t randi(int32_t n
){
1505 return (int32_t) (randul() % (n
+1));
1508 void getTestSource(UnicodeString
& fillIn
) {
1510 int32_t charCount
= (randi(maxCharCount
) + 1);
1511 while (i
<charCount
) {
1512 int32_t codepoint
= rand_uni();
1513 if(codepoint
== 0x0000){
1516 fillIn
.append((UChar32
)codepoint
);
1522 UnicodeString
TestIDNA::testCompareReferenceImpl(UnicodeString
& src
,
1523 TestFunc refIDNA
, const char* refIDNAName
,
1524 TestFunc uIDNA
, const char* uIDNAName
,
1527 const UChar
* srcUChars
= src
.getBuffer();
1528 UChar exp
[MAX_DEST_SIZE
]={0};
1529 int32_t expCap
= MAX_DEST_SIZE
, expLen
=0;
1530 UErrorCode expStatus
= U_ZERO_ERROR
;
1531 UParseError parseError
;
1533 logln("Comparing "+ UnicodeString(refIDNAName
)
1534 + " with "+ UnicodeString(uIDNAName
)
1535 +" for input: " + prettify(srcUChars
));
1537 expLen
= refIDNA(srcUChars
, src
.length()-1, exp
, expCap
,
1538 options
, &parseError
, &expStatus
);
1540 UChar got
[MAX_DEST_SIZE
]={0};
1541 int32_t gotCap
= MAX_DEST_SIZE
, gotLen
=0;
1542 UErrorCode gotStatus
= U_ZERO_ERROR
;
1544 gotLen
= uIDNA(srcUChars
, src
.length()-1, got
, gotCap
,
1545 options
, &parseError
, &gotStatus
);
1547 if(expStatus
!= gotStatus
){
1548 errln("Did not get the expected status while comparing " + UnicodeString(refIDNAName
)
1549 + " with " + UnicodeString(uIDNAName
)
1550 + " Expected: " + UnicodeString(u_errorName(expStatus
))
1551 + " Got: " + UnicodeString(u_errorName(gotStatus
))
1552 + " for Source: "+ prettify(srcUChars
)
1553 + " Options: " + options
);
1554 src
.releaseBuffer();
1555 return UnicodeString("");
1558 // now we know that both implementations yielded same error
1559 if(U_SUCCESS(expStatus
)){
1560 // compare the outputs if status == U_ZERO_ERROR
1561 if(u_strCompare(exp
, expLen
, got
, gotLen
, TRUE
) != 0){
1562 errln("Did not get the expected output while comparing " + UnicodeString(refIDNAName
)
1563 + " with " + UnicodeString(uIDNAName
)
1564 + " Expected: " + prettify(UnicodeString(exp
, expLen
))
1565 + " Got: " + prettify(UnicodeString(got
, gotLen
))
1566 + " for Source: "+ prettify(srcUChars
)
1567 + " Options: " + options
);
1569 src
.releaseBuffer();
1570 return UnicodeString(exp
, expLen
);
1573 logln("Got the same error while comparing "
1574 + UnicodeString(refIDNAName
)
1575 + " with "+ UnicodeString(uIDNAName
)
1576 +" for input: " + prettify(srcUChars
));
1578 src
.releaseBuffer();
1579 return UnicodeString("");
1582 void TestIDNA::testCompareReferenceImpl(const UChar
* src
, int32_t srcLen
){
1583 UnicodeString
label(src
,srcLen
);
1584 label
.append((UChar
)0x0000);
1586 //test idnaref_toASCII and idnare
1587 UnicodeString asciiLabel
= testCompareReferenceImpl(label
,
1588 idnaref_toASCII
, "idnaref_toASCII",
1589 uidna_toASCII
, "uidna_toASCII",
1590 UIDNA_ALLOW_UNASSIGNED
);
1591 testCompareReferenceImpl(label
,
1592 idnaref_toASCII
, "idnaref_toASCII",
1593 uidna_toASCII
, "uidna_toASCII",
1595 testCompareReferenceImpl(label
,
1596 idnaref_toASCII
, "idnaref_toASCII",
1597 uidna_toASCII
, "uidna_toASCII",
1598 UIDNA_USE_STD3_RULES
);
1599 testCompareReferenceImpl(label
,
1600 idnaref_toASCII
, "idnaref_toASCII",
1601 uidna_toASCII
, "uidna_toASCII",
1602 UIDNA_USE_STD3_RULES
| UIDNA_ALLOW_UNASSIGNED
);
1604 if(asciiLabel
.length()!=0){
1605 asciiLabel
.append((UChar
)0x0000);
1608 testCompareReferenceImpl(asciiLabel
,
1609 idnaref_toUnicode
, "idnaref_toUnicode",
1610 uidna_toUnicode
, "uidna_toUnicode",
1611 UIDNA_ALLOW_UNASSIGNED
);
1612 testCompareReferenceImpl(asciiLabel
,
1613 idnaref_toUnicode
, "idnaref_toUnicode",
1614 uidna_toUnicode
, "uidna_toUnicode",
1616 testCompareReferenceImpl(asciiLabel
,
1617 idnaref_toUnicode
, "idnaref_toUnicode",
1618 uidna_toUnicode
, "uidna_toUnicode",
1619 UIDNA_USE_STD3_RULES
);
1620 testCompareReferenceImpl(asciiLabel
,
1621 idnaref_toUnicode
, "idnaref_toUnicode",
1622 uidna_toUnicode
, "uidna_toUnicode",
1623 UIDNA_USE_STD3_RULES
| UIDNA_ALLOW_UNASSIGNED
);
1627 const char* failures
[] ={
1628 "\\uAA42\\U0001F8DD\\U00019D01\\U000149A3\\uD385\\U000EE0F5\\U00018B92\\U000179D1\\U00018624\\U0002227F\\U000E83C0\\U000E8DCD\\u5460\\U00017F34\\U0001570B\\u43D1\\U0002C9C9\\U000281EC\\u2105\\U000180AE\\uC5D4",
1629 "\\U0002F5A6\\uD638\\u0D0A\\u9E9C\\uFE5B\\U0001FCCB\\u66C4",
1632 void TestIDNA::TestIDNAMonkeyTest(){
1633 UnicodeString source
;
1634 UErrorCode status
= U_ZERO_ERROR
;
1637 getInstance(status
); // Init prep
1639 for(i
=0; i
<loopCount
; i
++){
1641 getTestSource(source
);
1642 source
.append((UChar
)0x0000);
1643 const UChar
* src
= source
.getBuffer();
1644 testCompareReferenceImpl(src
,source
.length()-1);
1645 testCompareReferenceImpl(src
,source
.length()-1);
1646 source
.releaseBuffer();
1650 for (i
=0; i
<(int)(sizeof(failures
)/sizeof(failures
[0])); i
++){
1652 source
.append( failures
[i
] );
1653 source
= source
.unescape();
1654 source
.append((UChar
)0x0000);
1655 const UChar
*src
= source
.getBuffer();
1656 testCompareReferenceImpl(src
,source
.length()-1);
1657 //debug(source.getBuffer(),source.length(),UIDNA_ALLOW_UNASSIGNED);
1658 source
.releaseBuffer();
1663 source
.append("\\uCF18\\U00021161\\U000EEF11\\U0002BB82\\U0001D63C");
1664 debug(source
.getBuffer(),source
.length(),UIDNA_ALLOW_UNASSIGNED
);
1665 source
.releaseBuffer();
1667 { // test deletion of code points
1668 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");
1669 source
= source
.unescape();
1670 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");
1671 expected
= expected
.unescape();
1672 UnicodeString
ascii("xn--b1abfaaepdrnnbgefbadotcwatmq2g4l");
1673 ascii
.append((UChar
)0x0000);
1674 testAPI(source
.getBuffer(),ascii
.getBuffer(), "uidna_toASCII", FALSE
, U_ZERO_ERROR
, TRUE
, TRUE
, uidna_toASCII
);
1675 source
.releaseBuffer();
1676 ascii
.releaseBuffer();
1678 testAPI(source
.getBuffer(),ascii
.getBuffer(), "idnaref_toASCII", FALSE
, U_ZERO_ERROR
, TRUE
, TRUE
, idnaref_toASCII
);
1679 source
.releaseBuffer();
1680 ascii
.releaseBuffer();
1683 testCompareReferenceImpl(source
.getBuffer(), source
.length()-1);
1684 source
.releaseBuffer();
1690 void TestIDNA::TestCompareReferenceImpl(){
1692 UChar src
[2] = {0,0};
1696 for(int32_t i
= 0x40000 ; i
< 0x10ffff; i
++){
1697 if(quick
==TRUE
&& i
> 0x1FFFF){
1700 if(i
>= 0x30000 && i
<= 0xF0000){
1704 src
[0] = U16_LEAD(i
);
1705 src
[1] = U16_TRAIL(i
);
1712 testCompareReferenceImpl(src
, srcLen
);
1716 void TestIDNA::TestRefIDNA(){
1717 testToASCII("idnaref_toASCII", idnaref_toASCII
);
1718 testToUnicode("idnaref_toUnicode", idnaref_toUnicode
);
1719 testIDNToASCII("idnaref_IDNToASCII", idnaref_IDNToASCII
);
1720 testIDNToUnicode("idnaref_IDNToUnicode", idnaref_IDNToUnicode
);
1721 testCompare("idnaref_compare",idnaref_compare
);
1722 testErrorCases( "idnaref_IDNToASCII",idnaref_IDNToASCII
,
1723 "idnaref_IDNToUnicode",idnaref_IDNToUnicode
);
1724 testChaining("idnaref_toASCII",idnaref_toASCII
, "idnaref_toUnicode", idnaref_toUnicode
);
1726 testRootLabelSeparator( "idnaref_compare",idnaref_compare
,
1727 "idnaref_IDNToASCII", idnaref_IDNToASCII
,
1728 "idnaref_IDNToUnicode",idnaref_IDNToUnicode
1730 testChaining("idnaref_toASCII",idnaref_toASCII
, "idnaref_toUnicode", idnaref_toUnicode
);
1733 void TestIDNA::TestDataFile(){
1736 TestIDNA::~TestIDNA(){
1743 NamePrepTransform
* TestIDNA::gPrep
= NULL
;
1745 NamePrepTransform
* TestIDNA::getInstance(UErrorCode
& status
){
1746 if(TestIDNA::gPrep
== NULL
){
1747 UParseError parseError
;
1748 TestIDNA::gPrep
= NamePrepTransform::createInstance(parseError
, status
);
1749 if(TestIDNA::gPrep
==NULL
){
1750 //status = U_MEMORY_ALLOCATION_ERROR;
1754 return TestIDNA::gPrep
;
1757 #endif /* #if !UCONFIG_NO_IDNA */