2 *******************************************************************************
4 * Copyright (C) 2003-2007, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: idnatest.c
10 * tab size: 8 (not used)
13 * created on: 2003jul11
14 * created by: Ram Viswanadha
18 #include "unicode/utypes.h"
22 #include "unicode/ustring.h"
23 #include "unicode/uidna.h"
28 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
29 #define MAX_DEST_SIZE 1000
31 static void TestToUnicode(void);
32 static void TestToASCII(void);
33 static void TestIDNToUnicode(void);
34 static void TestIDNToASCII(void);
35 static void TestCompare(void);
36 static void TestUnicode32Norm(void);
37 static void TestJB4490(void);
38 static void TestJB4475(void);
39 static void TestLength(void);
40 static void TestJB5273(void);
41 void addIDNATest(TestNode
** root
);
45 (U_EXPORT2
*TestFunc
) ( const UChar
*src
, int32_t srcLength
,
46 UChar
*dest
, int32_t destCapacity
,
47 int32_t options
, UParseError
*parseError
,
50 (U_EXPORT2
*CompareFunc
) (const UChar
*s1
, int32_t s1Len
,
51 const UChar
*s2
, int32_t s2Len
,
57 addIDNATest(TestNode
** root
)
59 addTest(root
, &TestToUnicode
, "idna/TestToUnicode");
60 addTest(root
, &TestToASCII
, "idna/TestToASCII");
61 addTest(root
, &TestIDNToUnicode
, "idna/TestIDNToUnicode");
62 addTest(root
, &TestIDNToASCII
, "idna/TestIDNToASCII");
63 addTest(root
, &TestCompare
, "idna/TestCompare");
64 addTest(root
, &TestUnicode32Norm
,"idna/TestUnicode32Norm");
65 addTest(root
, &TestJB4490
, "idna/TestJB4490");
66 addTest(root
, &TestJB4475
, "idna/TestJB4475");
67 addTest(root
, &TestLength
, "idna/TestLength");
68 addTest(root
, &TestJB5273
, "idna/TestJB5273");
72 testAPI(const UChar
* src
, const UChar
* expected
, const char* testName
,
73 UBool useSTD3ASCIIRules
,UErrorCode expectedStatus
,
74 UBool doCompare
, UBool testUnassigned
, TestFunc func
){
76 UErrorCode status
= U_ZERO_ERROR
;
77 UChar destStack
[MAX_DEST_SIZE
];
80 int32_t expectedLen
= (expected
!= NULL
) ? u_strlen(expected
) : 0;
81 int32_t options
= (useSTD3ASCIIRules
== TRUE
) ? UIDNA_USE_STD3_RULES
: UIDNA_DEFAULT
;
82 UParseError parseError
;
87 tSrcLen
= u_strlen(src
);
88 tSrc
=(UChar
*) malloc( U_SIZEOF_UCHAR
* tSrcLen
);
89 memcpy(tSrc
,src
,tSrcLen
* U_SIZEOF_UCHAR
);
92 /* test null-terminated source and return value of number of UChars required */
94 destLen
= func(src
,-1,NULL
,0,options
, &parseError
, &status
);
95 if(status
== U_BUFFER_OVERFLOW_ERROR
){
96 status
= U_ZERO_ERROR
; /* reset error code */
97 if(destLen
+1 < MAX_DEST_SIZE
){
99 destLen
= func(src
,-1,dest
,destLen
+1,options
, &parseError
, &status
);
100 /* TODO : compare output with expected */
101 if(U_SUCCESS(status
) && expectedStatus
!= U_IDNA_STD3_ASCII_RULES_ERROR
&& (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
102 log_err("Did not get the expected result for null terminated source.\n" );
105 log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName
);
109 if(status
!= expectedStatus
){
110 log_err( "Did not get the expected error for %s null terminated source failed. Expected: %s Got: %s\n",testName
, u_errorName(expectedStatus
), u_errorName(status
));
115 status
= U_ZERO_ERROR
;
116 destLen
= func(src
,-1,NULL
,0,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
117 if(status
== U_BUFFER_OVERFLOW_ERROR
){
118 status
= U_ZERO_ERROR
; /* reset error code */
119 if(destLen
+1 < MAX_DEST_SIZE
){
121 destLen
= func(src
,-1,dest
,destLen
+1,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
122 /* TODO : compare output with expected */
123 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
124 log_err("Did not get the expected result for %s null terminated source with both options set.\n",testName
);
128 log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName
);
131 /*testing query string*/
132 if(status
!= expectedStatus
&& expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
){
133 log_err( "Did not get the expected error for %s null terminated source with options set. Expected: %s Got: %s\n",testName
, u_errorName(expectedStatus
), u_errorName(status
));
137 status
= U_ZERO_ERROR
;
139 /* test source with lengthand return value of number of UChars required*/
140 destLen
= func(tSrc
, tSrcLen
, NULL
,0,options
, &parseError
, &status
);
141 if(status
== U_BUFFER_OVERFLOW_ERROR
){
142 status
= U_ZERO_ERROR
; /* reset error code */
143 if(destLen
+1 < MAX_DEST_SIZE
){
145 destLen
= func(src
,u_strlen(src
),dest
,destLen
+1,options
, &parseError
, &status
);
146 /* TODO : compare output with expected */
147 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
148 log_err("Did not get the expected result for %s with source length.\n",testName
);
151 log_err( "%s with source length failed. Requires destCapacity > 300\n",testName
);
155 if(status
!= expectedStatus
){
156 log_err( "Did not get the expected error for %s with source length. Expected: %s Got: %s\n",testName
, u_errorName(expectedStatus
), u_errorName(status
));
159 status
= U_ZERO_ERROR
;
161 destLen
= func(tSrc
,tSrcLen
,NULL
,0,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
163 if(status
== U_BUFFER_OVERFLOW_ERROR
){
164 status
= U_ZERO_ERROR
; /* reset error code */
165 if(destLen
+1 < MAX_DEST_SIZE
){
167 destLen
= func(src
,u_strlen(src
),dest
,destLen
+1,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
168 /* TODO : compare output with expected */
169 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
170 log_err("Did not get the expected result for %s with source length and both options set.\n",testName
);
173 log_err( "%s with source length failed. Requires destCapacity > 300\n",testName
);
176 /*testing query string*/
177 if(status
!= expectedStatus
&& expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
){
178 log_err( "Did not get the expected error for %s with source length and options set. Expected: %s Got: %s\n",testName
, u_errorName(expectedStatus
), u_errorName(status
));
182 status
= U_ZERO_ERROR
;
183 destLen
= func(src
,-1,NULL
,0,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
184 if(status
== U_BUFFER_OVERFLOW_ERROR
){
185 status
= U_ZERO_ERROR
; /* reset error code*/
186 if(destLen
+1 < MAX_DEST_SIZE
){
188 destLen
= func(src
,-1,dest
,destLen
+1,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
189 /* TODO : compare output with expected*/
190 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
191 log_err("Did not get the expected result for %s null terminated source with both options set.\n",testName
);
195 log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName
);
198 /*testing query string*/
199 if(status
!= expectedStatus
){
200 log_err( "Did not get the expected error for %s null terminated source with options set. Expected: %s Got: %s\n",testName
, u_errorName(expectedStatus
), u_errorName(status
));
203 status
= U_ZERO_ERROR
;
205 destLen
= func(tSrc
,tSrcLen
,NULL
,0,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
207 if(status
== U_BUFFER_OVERFLOW_ERROR
){
208 status
= U_ZERO_ERROR
; /* reset error code*/
209 if(destLen
+1 < MAX_DEST_SIZE
){
211 destLen
= func(src
,u_strlen(src
),dest
,destLen
+1,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
212 /* TODO : compare output with expected*/
213 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
214 log_err("Did not get the expected result for %s with source length and both options set.\n",testName
);
217 log_err( "%s with source length failed. Requires destCapacity > 300\n",testName
);
220 /*testing query string*/
221 if(status
!= expectedStatus
&& expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
){
222 log_err( "Did not get the expected error for %s with source length and options set. Expected: %s Got: %s\n",testName
, u_errorName(expectedStatus
), u_errorName(status
));
227 static const UChar unicodeIn
[][41] ={
229 0x0644, 0x064A, 0x0647, 0x0645, 0x0627, 0x0628, 0x062A, 0x0643, 0x0644,
230 0x0645, 0x0648, 0x0634, 0x0639, 0x0631, 0x0628, 0x064A, 0x061F, 0x0000
233 0x4ED6, 0x4EEC, 0x4E3A, 0x4EC0, 0x4E48, 0x4E0D, 0x8BF4, 0x4E2D, 0x6587,
237 0x0050, 0x0072, 0x006F, 0x010D, 0x0070, 0x0072, 0x006F, 0x0073, 0x0074,
238 0x011B, 0x006E, 0x0065, 0x006D, 0x006C, 0x0075, 0x0076, 0x00ED, 0x010D,
239 0x0065, 0x0073, 0x006B, 0x0079, 0x0000
242 0x05DC, 0x05DE, 0x05D4, 0x05D4, 0x05DD, 0x05E4, 0x05E9, 0x05D5, 0x05D8,
243 0x05DC, 0x05D0, 0x05DE, 0x05D3, 0x05D1, 0x05E8, 0x05D9, 0x05DD, 0x05E2,
244 0x05D1, 0x05E8, 0x05D9, 0x05EA, 0x0000
247 0x092F, 0x0939, 0x0932, 0x094B, 0x0917, 0x0939, 0x093F, 0x0928, 0x094D,
248 0x0926, 0x0940, 0x0915, 0x094D, 0x092F, 0x094B, 0x0902, 0x0928, 0x0939,
249 0x0940, 0x0902, 0x092C, 0x094B, 0x0932, 0x0938, 0x0915, 0x0924, 0x0947,
250 0x0939, 0x0948, 0x0902, 0x0000
253 0x306A, 0x305C, 0x307F, 0x3093, 0x306A, 0x65E5, 0x672C, 0x8A9E, 0x3092,
254 0x8A71, 0x3057, 0x3066, 0x304F, 0x308C, 0x306A, 0x3044, 0x306E, 0x304B,
259 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
260 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
261 0xC5BC, 0xB9C8, 0xB098, 0xC88B, 0xC744, 0xAE4C, 0x0000
265 0x043F, 0x043E, 0x0447, 0x0435, 0x043C, 0x0443, 0x0436, 0x0435, 0x043E,
266 0x043D, 0x0438, 0x043D, 0x0435, 0x0433, 0x043E, 0x0432, 0x043E, 0x0440,
267 0x044F, 0x0442, 0x043F, 0x043E, 0x0440, 0x0443, 0x0441, 0x0441, 0x043A,
271 0x0050, 0x006F, 0x0072, 0x0071, 0x0075, 0x00E9, 0x006E, 0x006F, 0x0070,
272 0x0075, 0x0065, 0x0064, 0x0065, 0x006E, 0x0073, 0x0069, 0x006D, 0x0070,
273 0x006C, 0x0065, 0x006D, 0x0065, 0x006E, 0x0074, 0x0065, 0x0068, 0x0061,
274 0x0062, 0x006C, 0x0061, 0x0072, 0x0065, 0x006E, 0x0045, 0x0073, 0x0070,
275 0x0061, 0x00F1, 0x006F, 0x006C, 0x0000
278 0x4ED6, 0x5011, 0x7232, 0x4EC0, 0x9EBD, 0x4E0D, 0x8AAA, 0x4E2D, 0x6587,
282 0x0054, 0x1EA1, 0x0069, 0x0073, 0x0061, 0x006F, 0x0068, 0x1ECD, 0x006B,
283 0x0068, 0x00F4, 0x006E, 0x0067, 0x0074, 0x0068, 0x1EC3, 0x0063, 0x0068,
284 0x1EC9, 0x006E, 0x00F3, 0x0069, 0x0074, 0x0069, 0x1EBF, 0x006E, 0x0067,
285 0x0056, 0x0069, 0x1EC7, 0x0074, 0x0000
288 0x0033, 0x5E74, 0x0042, 0x7D44, 0x91D1, 0x516B, 0x5148, 0x751F, 0x0000
291 0x5B89, 0x5BA4, 0x5948, 0x7F8E, 0x6075, 0x002D, 0x0077, 0x0069, 0x0074,
292 0x0068, 0x002D, 0x0053, 0x0055, 0x0050, 0x0045, 0x0052, 0x002D, 0x004D,
293 0x004F, 0x004E, 0x004B, 0x0045, 0x0059, 0x0053, 0x0000
296 0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x002D, 0x0041, 0x006E, 0x006F,
297 0x0074, 0x0068, 0x0065, 0x0072, 0x002D, 0x0057, 0x0061, 0x0079, 0x002D,
298 0x305D, 0x308C, 0x305E, 0x308C, 0x306E, 0x5834, 0x6240, 0x0000
301 0x3072, 0x3068, 0x3064, 0x5C4B, 0x6839, 0x306E, 0x4E0B, 0x0032, 0x0000
304 0x004D, 0x0061, 0x006A, 0x0069, 0x3067, 0x004B, 0x006F, 0x0069, 0x3059,
305 0x308B, 0x0035, 0x79D2, 0x524D, 0x0000
308 0x30D1, 0x30D5, 0x30A3, 0x30FC, 0x0064, 0x0065, 0x30EB, 0x30F3, 0x30D0,
312 0x305D, 0x306E, 0x30B9, 0x30D4, 0x30FC, 0x30C9, 0x3067, 0x0000
314 /* test non-BMP code points */
316 0xD800, 0xDF00, 0xD800, 0xDF01, 0xD800, 0xDF02, 0xD800, 0xDF03, 0xD800, 0xDF05,
317 0xD800, 0xDF06, 0xD800, 0xDF07, 0xD800, 0xDF09, 0xD800, 0xDF0A, 0xD800, 0xDF0B,
321 0xD800, 0xDF0D, 0xD800, 0xDF0C, 0xD800, 0xDF1E, 0xD800, 0xDF0F, 0xD800, 0xDF16,
322 0xD800, 0xDF15, 0xD800, 0xDF14, 0xD800, 0xDF12, 0xD800, 0xDF10, 0xD800, 0xDF20,
328 0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac
332 0x0062, 0x006f, 0x006e, 0x0121, 0x0075, 0x0073, 0x0061, 0x0127,
337 0x043f, 0x043e, 0x0447, 0x0435, 0x043c, 0x0443, 0x0436, 0x0435,
338 0x043e, 0x043d, 0x0438, 0x043d, 0x0435, 0x0433, 0x043e, 0x0432,
339 0x043e, 0x0440, 0x044f, 0x0442, 0x043f, 0x043e, 0x0440, 0x0443,
340 0x0441, 0x0441, 0x043a, 0x0438
343 0x0054,0x0045,0x0053,0x0054
347 static const char * const asciiIn
[] = {
348 "xn--egbpdaj6bu4bxfgehfvwxn",
349 "xn--ihqwcrb4cv8a8dqg056pqjye",
350 "xn--Proprostnemluvesky-uyb24dma41a",
351 "xn--4dbcagdahymbxekheh6e0a7fei0b",
352 "xn--i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd",
353 "xn--n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa",
354 /* "xn--989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c",*/
355 "xn--b1abfaaepdrnnbgefbaDotcwatmq2g4l",
356 "xn--PorqunopuedensimplementehablarenEspaol-fmd56a",
357 "xn--ihqwctvzc91f659drss3x8bo0yb",
358 "xn--TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g",
359 "xn--3B-ww4c5e180e575a65lsy2b",
360 "xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n",
361 "xn--Hello-Another-Way--fc4qua05auwb3674vfr0b",
362 "xn--2-u9tlzr9756bt3uc0v",
363 "xn--MajiKoi5-783gue6qz075azm5e",
364 "xn--de-jg4avhby1noc0d",
365 "xn--d9juau41awczczp",
367 "XN--db8CBHEJLGH4E0AL",
368 "xn--hxargifdar", /* Greek */
369 "xn--bonusaa-5bb1da", /* Maltese */
370 "xn--b1abfaaepdrnnbgefbadotcwatmq2g4l", /* Russian (Cyrillic)*/
375 static const char * const domainNames
[] = {
376 "slip129-37-118-146.nc.us.ibm.net",
377 "saratoga.pe.utexas.edu",
378 "dial-120-45.ots.utexas.edu",
379 "woo-085.dorms.waller.net",
380 "hd30-049.hil.compuserve.com",
381 "pem203-31.pe.ttu.edu",
382 "56K-227.MaxTNT3.pdq.net",
383 "dial-36-2.ots.utexas.edu",
384 "slip129-37-23-152.ga.us.ibm.net",
385 "ts45ip119.cadvision.com",
386 "sdn-ts-004txaustP05.dialsprint.net",
387 "bar-tnt1s66.erols.com",
388 "101.st-louis-15.mo.dial-access.att.net",
390 "dial-13-2.ots.utexas.edu",
391 "net-redynet29.datamarkets.com.ar",
392 "ccs-shiva28.reacciun.net.ve",
393 "7.houston-11.tx.dial-access.att.net",
394 "ingw129-37-120-26.mo.us.ibm.net",
395 "dialup6.austintx.com",
397 "slip129-37-119-194.nc.us.ibm.net",
398 "cs7.dillons.co.uk.203.119.193.in-addr.arpa",
399 "swprd1.innovplace.saskatoon.sk.ca",
400 "bikini.bologna.maraut.it",
401 "node91.subnet159-198-79.baxter.com",
402 "cust19.max5.new-york.ny.ms.uu.net",
403 "balexander.slip.andrew.cmu.edu",
404 "pool029.max2.denver.co.dynip.alter.net",
405 "cust49.max9.new-york.ny.ms.uu.net",
406 "s61.abq-dialin2.hollyberry.com",
407 "\\u0917\\u0928\\u0947\\u0936.sanjose.ibm.com", /*':'(0x003a) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
409 /* "www.\\u00E0\\u00B3\\u00AF.com",//' ' (0x0020) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
410 "www.\\u00C2\\u00A4.com",
411 "www.\\u00C2\\u00A3.com",
412 /* "\\u0025", //'%' (0x0025) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
413 /* "\\u005C\\u005C", //'\' (0x005C) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
416 /*"www.\\u0021.com",*/
417 /*"www.\\u0024.com",*/
419 /* These yeild U_IDNA_PROHIBITED_ERROR*/
420 /*"\\u00CF\\u0082.com",*/
421 /*"\\u00CE\\u00B2\\u00C3\\u009Fss.com",*/
422 /*"\\u00E2\\u0098\\u00BA.com",*/
431 UChar buf
[MAX_DEST_SIZE
];
432 const char* testName
= "uidna_toASCII";
433 TestFunc func
= uidna_toASCII
;
434 for(i
=0;i
< (int32_t)(sizeof(unicodeIn
)/sizeof(unicodeIn
[0])); i
++){
435 u_charsToUChars(asciiIn
[i
],buf
, (int32_t)strlen(asciiIn
[i
])+1);
436 testAPI(unicodeIn
[i
], buf
,testName
, FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
445 UChar buf
[MAX_DEST_SIZE
];
446 const char* testName
= "uidna_toUnicode";
447 TestFunc func
= uidna_toUnicode
;
448 for(i
=0;i
< (int32_t)(sizeof(asciiIn
)/sizeof(asciiIn
[0])); i
++){
449 u_charsToUChars(asciiIn
[i
],buf
, (int32_t)strlen(asciiIn
[i
])+1);
450 testAPI(buf
,unicodeIn
[i
],testName
,FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
458 UChar buf
[MAX_DEST_SIZE
];
459 UChar expected
[MAX_DEST_SIZE
];
460 UErrorCode status
= U_ZERO_ERROR
;
462 UParseError parseError
;
463 const char* testName
="uidna_IDNToUnicode";
464 TestFunc func
= uidna_IDNToUnicode
;
465 for(i
=0;i
< (int32_t)(sizeof(domainNames
)/sizeof(domainNames
[0])); i
++){
466 bufLen
= (int32_t)strlen(domainNames
[i
]);
467 bufLen
= u_unescape(domainNames
[i
],buf
, bufLen
+1);
468 func(buf
,bufLen
,expected
,MAX_DEST_SIZE
, UIDNA_ALLOW_UNASSIGNED
, &parseError
,&status
);
469 if(U_FAILURE(status
)){
470 log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName
, i
, u_errorName(status
));
473 testAPI(buf
,expected
,testName
,FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
474 /*test toUnicode with all labels in the string*/
475 testAPI(buf
,expected
,testName
, FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
476 if(U_FAILURE(status
)){
477 log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName
,i
, u_errorName(status
));
487 UChar buf
[MAX_DEST_SIZE
];
488 UChar expected
[MAX_DEST_SIZE
];
489 UErrorCode status
= U_ZERO_ERROR
;
491 UParseError parseError
;
492 const char* testName
="udina_IDNToASCII";
493 TestFunc func
=uidna_IDNToASCII
;
495 for(i
=0;i
< (int32_t)(sizeof(domainNames
)/sizeof(domainNames
[0])); i
++){
496 bufLen
= (int32_t)strlen(domainNames
[i
]);
497 bufLen
= u_unescape(domainNames
[i
],buf
, bufLen
+1);
498 func(buf
,bufLen
,expected
,MAX_DEST_SIZE
, UIDNA_ALLOW_UNASSIGNED
, &parseError
,&status
);
499 if(U_FAILURE(status
)){
500 log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName
,i
, u_errorName(status
));
503 testAPI(buf
,expected
,testName
, FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
504 /*test toASCII with all labels in the string*/
505 testAPI(buf
,expected
,testName
, FALSE
,U_ZERO_ERROR
, FALSE
, TRUE
, func
);
506 if(U_FAILURE(status
)){
507 log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName
,i
, u_errorName(status
));
517 testCompareWithSrc(const UChar
* s1
, int32_t s1Len
,
518 const UChar
* s2
, int32_t s2Len
,
519 const char* testName
, CompareFunc func
,
522 UErrorCode status
= U_ZERO_ERROR
;
523 int32_t retVal
= func(s1
,-1,s2
,-1,UIDNA_DEFAULT
,&status
);
525 if(isEqual
==TRUE
&& retVal
!=0){
526 log_err("Did not get the expected result for %s with null termniated strings.\n",testName
);
528 if(U_FAILURE(status
)){
529 log_err( "%s null terminated source failed. Error: %s\n", testName
,u_errorName(status
));
532 status
= U_ZERO_ERROR
;
533 retVal
= func(s1
,-1,s2
,-1,UIDNA_ALLOW_UNASSIGNED
,&status
);
535 if(isEqual
==TRUE
&& retVal
!=0){
536 log_err("Did not get the expected result for %s with null termniated strings with options set.\n", testName
);
538 if(U_FAILURE(status
)){
539 log_err( "%s null terminated source and options set failed. Error: %s\n",testName
, u_errorName(status
));
542 status
= U_ZERO_ERROR
;
543 retVal
= func(s1
,s1Len
,s2
,s2Len
,UIDNA_DEFAULT
,&status
);
545 if(isEqual
==TRUE
&& retVal
!=0){
546 log_err("Did not get the expected result for %s with string length.\n",testName
);
548 if(U_FAILURE(status
)){
549 log_err( "%s with string length. Error: %s\n",testName
, u_errorName(status
));
552 status
= U_ZERO_ERROR
;
553 retVal
= func(s1
,s1Len
,s2
,s2Len
,UIDNA_ALLOW_UNASSIGNED
,&status
);
555 if(isEqual
==TRUE
&& retVal
!=0){
556 log_err("Did not get the expected result for %s with string length and options set.\n",testName
);
558 if(U_FAILURE(status
)){
559 log_err( "%s with string length and options set. Error: %s\n", u_errorName(status
), testName
);
568 const char* testName
="uidna_compare";
569 CompareFunc func
= uidna_compare
;
571 UChar www
[] = {0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
572 UChar com
[] = {0x002E, 0x0043, 0x004F, 0x004D, 0x0000};
573 UChar buf
[MAX_DEST_SIZE
]={0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
574 UChar source
[MAX_DEST_SIZE
]={0},
575 uni0
[MAX_DEST_SIZE
]={0},
576 uni1
[MAX_DEST_SIZE
]={0},
577 ascii0
[MAX_DEST_SIZE
]={0},
578 ascii1
[MAX_DEST_SIZE
]={0},
579 temp
[MAX_DEST_SIZE
] ={0};
582 u_strcat(uni0
,unicodeIn
[0]);
585 u_strcat(uni1
,unicodeIn
[1]);
588 u_charsToUChars(asciiIn
[0], temp
, (int32_t)strlen(asciiIn
[0]));
589 u_strcat(ascii0
,temp
);
590 u_strcat(ascii0
,com
);
592 memset(temp
, 0, U_SIZEOF_UCHAR
* MAX_DEST_SIZE
);
594 u_charsToUChars(asciiIn
[1], temp
, (int32_t)strlen(asciiIn
[1]));
595 u_strcat(ascii1
,temp
);
596 u_strcat(ascii1
,com
);
599 u_strcat(source
, www
);
601 for(i
=0;i
< (int32_t)(sizeof(unicodeIn
)/sizeof(unicodeIn
[0])); i
++){
605 memset(buf
+4, 0, (MAX_DEST_SIZE
-4) * U_SIZEOF_UCHAR
);
607 u_charsToUChars(asciiIn
[i
],buf
+4, (int32_t)strlen(asciiIn
[i
]));
611 /* for every entry in unicodeIn array
612 prepend www. and append .com*/
614 u_strncat(source
,unicodeIn
[i
], u_strlen(unicodeIn
[i
]));
615 u_strcat(source
,com
);
617 /* a) compare it with itself*/
619 srcLen
= u_strlen(src
);
621 testCompareWithSrc(src
,srcLen
,src
,srcLen
,testName
, func
, TRUE
);
623 /* b) compare it with asciiIn equivalent */
624 testCompareWithSrc(src
,srcLen
,buf
,u_strlen(buf
),testName
, func
,TRUE
);
626 /* c) compare it with unicodeIn not equivalent*/
628 testCompareWithSrc(src
,srcLen
,uni1
,u_strlen(uni1
),testName
, func
,FALSE
);
630 testCompareWithSrc(src
,srcLen
,uni0
,u_strlen(uni0
),testName
, func
,FALSE
);
632 /* d) compare it with asciiIn not equivalent */
634 testCompareWithSrc(src
,srcLen
,ascii1
,u_strlen(ascii1
),testName
, func
,FALSE
);
636 testCompareWithSrc(src
,srcLen
,ascii0
,u_strlen(ascii0
),testName
, func
,FALSE
);
642 static void TestUnicode32Norm() {
644 * test Unicode 3.2 normalization, before Public Review Issue #29
645 * see cnormtst.c TestComposition()
647 static const UChar strings
[][8]={
648 { 0x1100, 0x0300, 0x1161, 0x0327 },
649 { 0x0b47, 0x0300, 0x0b3e, 0x0327 }
652 UChar ascii
[20], unicode
[20];
654 UErrorCode errorCode
;
656 for(i
=0; i
<LENGTHOF(strings
); ++i
) {
657 errorCode
=U_ZERO_ERROR
;
658 length
=uidna_toASCII(strings
[i
], -1, ascii
, LENGTHOF(ascii
), 0, NULL
, &errorCode
);
659 length
=uidna_toUnicode(ascii
, length
, unicode
, LENGTHOF(unicode
), 0, NULL
, &errorCode
);
660 if(u_strncmp(ascii
, unicode
, length
)!=0) {
661 log_err("Did not get the correct output\n");
666 static void TestJB4490(){
667 static const UChar data
[][50]= {
668 {0x00F5,0x00dE,0x00dF,0x00dD, 0x0000},
671 UChar output1
[40] = {0};
672 UChar output2
[40] = {0};
674 for(i
=0; i
< sizeof(data
)/sizeof(data
[0]); i
++){
675 const UChar
* src1
= data
[i
];
676 int32_t src1Len
= u_strlen(src1
);
677 UChar
* dest1
= output1
;
678 int32_t dest1Len
= 40;
679 UErrorCode status
= U_ZERO_ERROR
;
683 UChar
* dest2
= output2
;
684 int32_t dest2Len
= 40;
685 dest1Len
= uidna_toASCII(src1
, src1Len
, dest1
, dest1Len
,UIDNA_DEFAULT
, &ps
, &status
);
686 if(U_FAILURE(status
)){
687 log_err("uidna_toUnicode failed with error %s.\n", u_errorName(status
));
691 dest2Len
= uidna_toUnicode(src2
, src2Len
, dest2
, dest2Len
, UIDNA_DEFAULT
, &ps
, &status
);
692 if(U_FAILURE(status
)){
693 log_err("uidna_toUnicode failed with error %s.\n", u_errorName(status
));
698 static void TestJB4475(){
700 static const UChar input
[][10] = {
701 {0x0054,0x0045,0x0053,0x0054,0x0000},/* TEST */
702 {0x0074,0x0065,0x0073,0x0074,0x0000} /* test */
705 UChar output
[40] = {0};
706 for(i
=0; i
< sizeof(input
)/sizeof(input
[0]); i
++){
707 const UChar
* src
= input
[i
];
708 int32_t srcLen
= u_strlen(src
);
709 UChar
* dest
= output
;
710 int32_t destLen
= 40;
711 UErrorCode status
= U_ZERO_ERROR
;
714 destLen
= uidna_toASCII(src
, srcLen
, dest
, destLen
,UIDNA_DEFAULT
, &ps
, &status
);
715 if(U_FAILURE(status
)){
716 log_err("uidna_toASCII failed with error %s.\n", u_errorName(status
));
718 if(u_strncmp(input
[i
], dest
, srcLen
)!=0){
719 log_err("uidna_toASCII did not return the expected output.\n");
724 static void TestLength(){
726 static const char* cl
= "my_very_very_very_very_very_very_very_very_very_very_very_very_very_long_and_incredibly_uncreative_domain_label";
727 UChar ul
[128] = {'\0'};
728 UChar dest
[256] = {'\0'};
729 /* this unicode string is longer than MAX_LABEL_BUFFER_SIZE and produces an
730 IDNA prepared string (including xn--)that is exactly 63 bytes long */
731 UChar ul1
[] = { 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
732 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0x00AD, 0x034F, 0x1806, 0x180B,
733 0x180C, 0x180D, 0x200B, 0x200C, 0x200D, 0x2060, 0xFE00, 0xFE01, 0xFE02,
734 0xFE03, 0xFE04, 0xFE05, 0xFE06, 0xFE07, 0xFE08, 0xFE09, 0xFE0A, 0xFE0B,
735 0xFE0C, 0xFE0D, 0xFE0E, 0xFE0F, 0xFEFF, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
736 0xC138, 0x0041, 0x00AD, 0x034F, 0x1806, 0x180B, 0x180C, 0x180D, 0x200B,
737 0x200C, 0x200D, 0x2060, 0xFE00, 0xFE01, 0xFE02, 0xFE03, 0xFE04, 0xFE05,
738 0xFE06, 0xFE07, 0xFE08, 0xFE09, 0xFE0A, 0xFE0B, 0xFE0C, 0xFE0D, 0xFE0E,
739 0xFE0F, 0xFEFF, 0x00AD, 0x034F, 0x1806, 0x180B, 0x180C, 0x180D, 0x200B,
740 0x200C, 0x200D, 0x2060, 0xFE00, 0xFE01, 0xFE02, 0xFE03, 0xFE04, 0xFE05,
741 0xFE06, 0xFE07, 0xFE08, 0xFE09, 0xFE0A, 0xFE0B, 0xFE0C, 0xFE0D, 0xFE0E,
742 0xFE0F, 0xFEFF, 0x00AD, 0x034F, 0x1806, 0x180B, 0x180C, 0x180D, 0x200B,
743 0x200C, 0x200D, 0x2060, 0xFE00, 0xFE01, 0xFE02, 0xFE03, 0xFE04, 0xFE05,
744 0xFE06, 0xFE07, 0xFE08, 0xFE09, 0xFE0A, 0xFE0B, 0xFE0C, 0xFE0D, 0xFE0E,
745 0xFE0F, 0xFEFF, 0x0000
748 int32_t len1
= LENGTHOF(ul1
)-1/*remove the null termination*/;
749 int32_t destLen
= LENGTHOF(dest
);
750 UErrorCode status
= U_ZERO_ERROR
;
752 int32_t len
= (int32_t)strlen(cl
);
753 u_charsToUChars(cl
, ul
, len
+1);
754 destLen
= uidna_toUnicode(ul
, len
, dest
, destLen
, UIDNA_DEFAULT
, &ps
, &status
);
755 if(status
!= U_ZERO_ERROR
){
756 log_err("uidna_toUnicode failed with error %s.\n", u_errorName(status
));
759 status
= U_ZERO_ERROR
;
760 destLen
= LENGTHOF(dest
);
762 destLen
= uidna_toUnicode(ul
, len
, dest
, destLen
, UIDNA_DEFAULT
, &ps
, &status
);
763 if(status
!= U_ZERO_ERROR
){
764 log_err("uidna_toUnicode failed with error %s.\n", u_errorName(status
));
766 status
= U_ZERO_ERROR
;
767 destLen
= LENGTHOF(dest
);
768 len
= (int32_t)strlen(cl
);
769 destLen
= uidna_toASCII(ul
, len
, dest
, destLen
, UIDNA_DEFAULT
, &ps
, &status
);
770 if(status
!= U_IDNA_LABEL_TOO_LONG_ERROR
){
771 log_err("uidna_toASCII failed with error %s.\n", u_errorName(status
));
774 status
= U_ZERO_ERROR
;
775 destLen
= LENGTHOF(dest
);
777 destLen
= uidna_toASCII(ul
, len
, dest
, destLen
, UIDNA_DEFAULT
, &ps
, &status
);
778 if(status
!= U_IDNA_LABEL_TOO_LONG_ERROR
){
779 log_err("uidna_toASCII failed with error %s.\n", u_errorName(status
));
782 status
= U_ZERO_ERROR
;
783 destLen
= LENGTHOF(dest
);
784 destLen
= uidna_toASCII(ul1
, len1
, dest
, destLen
, UIDNA_DEFAULT
, &ps
, &status
);
785 if(status
!= U_ZERO_ERROR
){
786 log_err("uidna_toASCII failed with error %s.\n", u_errorName(status
));
789 status
= U_ZERO_ERROR
;
790 destLen
= LENGTHOF(dest
);
792 destLen
= uidna_toASCII(ul1
, len1
, dest
, destLen
, UIDNA_DEFAULT
, &ps
, &status
);
793 if(status
!= U_ZERO_ERROR
){
794 log_err("uidna_toASCII failed with error %s.\n", u_errorName(status
));
798 static const char* cl
= "my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.ibm.com";
799 UChar ul
[400] = {'\0'};
800 UChar dest
[400] = {'\0'};
801 int32_t destLen
= LENGTHOF(dest
);
802 UErrorCode status
= U_ZERO_ERROR
;
804 int32_t len
= (int32_t)strlen(cl
);
805 u_charsToUChars(cl
, ul
, len
+1);
807 destLen
= uidna_IDNToUnicode(ul
, len
, dest
, destLen
, UIDNA_DEFAULT
, &ps
, &status
);
808 if(status
!= U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR
){
809 log_err("uidna_IDNToUnicode failed with error %s.\n", u_errorName(status
));
812 status
= U_ZERO_ERROR
;
813 destLen
= LENGTHOF(dest
);
815 destLen
= uidna_IDNToUnicode(ul
, len
, dest
, destLen
, UIDNA_DEFAULT
, &ps
, &status
);
816 if(status
!= U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR
){
817 log_err("uidna_IDNToUnicode failed with error %s.\n", u_errorName(status
));
820 status
= U_ZERO_ERROR
;
821 destLen
= LENGTHOF(dest
);
822 len
= (int32_t)strlen(cl
);
823 destLen
= uidna_IDNToASCII(ul
, len
, dest
, destLen
, UIDNA_DEFAULT
, &ps
, &status
);
824 if(status
!= U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR
){
825 log_err("uidna_IDNToASCII failed with error %s.\n", u_errorName(status
));
828 status
= U_ZERO_ERROR
;
829 destLen
= LENGTHOF(dest
);
831 destLen
= uidna_IDNToASCII(ul
, len
, dest
, destLen
, UIDNA_DEFAULT
, &ps
, &status
);
832 if(status
!= U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR
){
833 log_err("uidna_IDNToASCII failed with error %s.\n", u_errorName(status
));
836 status
= U_ZERO_ERROR
;
837 uidna_compare(ul
, len
, ul
, len
, UIDNA_DEFAULT
, &status
);
838 if(status
!= U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR
){
839 log_err("uidna_compare failed with error %s.\n", u_errorName(status
));
841 uidna_compare(ul
, -1, ul
, -1, UIDNA_DEFAULT
, &status
);
842 if(status
!= U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR
){
843 log_err("uidna_compare failed with error %s.\n", u_errorName(status
));
847 static void TestJB5273(){
848 static const char INVALID_DOMAIN_NAME
[] = "xn--m\\u00FCller.de";
849 UChar invalid_idn
[25] = {'\0'};
850 int32_t len
= u_unescape(INVALID_DOMAIN_NAME
, invalid_idn
, strlen(INVALID_DOMAIN_NAME
));
851 UChar output
[50] = {'\0'};
852 UErrorCode status
= U_ZERO_ERROR
;
853 UParseError prsError
;
854 int32_t outLen
= uidna_toUnicode(invalid_idn
, len
, output
, 50, UIDNA_DEFAULT
, &prsError
, &status
);
855 if(U_FAILURE(status
)){
856 log_err("uidna_toUnicode failed with error: %s\n", u_errorName(status
));
858 status
= U_ZERO_ERROR
;
859 outLen
= uidna_toUnicode(invalid_idn
, len
, output
, 50, UIDNA_USE_STD3_RULES
, &prsError
, &status
);
860 if(U_FAILURE(status
)){
861 log_err("uidna_toUnicode failed with error: %s\n", u_errorName(status
));
864 status
= U_ZERO_ERROR
;
865 outLen
= uidna_IDNToUnicode(invalid_idn
, len
, output
, 50, UIDNA_DEFAULT
, &prsError
, &status
);
866 if(U_FAILURE(status
)){
867 log_err("uidna_toUnicode failed with error: %s\n", u_errorName(status
));
869 status
= U_ZERO_ERROR
;
870 outLen
= uidna_IDNToUnicode(invalid_idn
, len
, output
, 50, UIDNA_USE_STD3_RULES
, &prsError
, &status
);
871 if(U_FAILURE(status
)){
872 log_err("uidna_toUnicode failed with error: %s\n", u_errorName(status
));
878 * Hey, Emacs, please set the following:
881 * indent-tabs-mode: nil