2 *******************************************************************************
4 * Copyright (C) 2003-2004, 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);
38 void addIDNATest(TestNode
** root
);
42 (U_EXPORT2
*TestFunc
) ( const UChar
*src
, int32_t srcLength
,
43 UChar
*dest
, int32_t destCapacity
,
44 int32_t options
, UParseError
*parseError
,
47 (U_EXPORT2
*CompareFunc
) (const UChar
*s1
, int32_t s1Len
,
48 const UChar
*s2
, int32_t s2Len
,
54 addIDNATest(TestNode
** root
)
56 addTest(root
, &TestToUnicode
, "idna/TestToUnicode");
57 addTest(root
, &TestToASCII
, "idna/TestToASCII");
58 addTest(root
, &TestIDNToUnicode
, "idna/TestIDNToUnicode");
59 addTest(root
, &TestIDNToASCII
, "idna/TestIDNToASCII");
60 addTest(root
, &TestCompare
, "idna/TestCompare");
61 addTest(root
, &TestUnicode32Norm
,"idna/TestUnicode32Norm");
65 testAPI(const UChar
* src
, const UChar
* expected
, const char* testName
,
66 UBool useSTD3ASCIIRules
,UErrorCode expectedStatus
,
67 UBool doCompare
, UBool testUnassigned
, TestFunc func
){
69 UErrorCode status
= U_ZERO_ERROR
;
70 UChar destStack
[MAX_DEST_SIZE
];
73 int32_t expectedLen
= (expected
!= NULL
) ? u_strlen(expected
) : 0;
74 int32_t options
= (useSTD3ASCIIRules
== TRUE
) ? UIDNA_USE_STD3_RULES
: UIDNA_DEFAULT
;
75 UParseError parseError
;
80 tSrcLen
= u_strlen(src
);
81 tSrc
=(UChar
*) malloc( U_SIZEOF_UCHAR
* tSrcLen
);
82 memcpy(tSrc
,src
,tSrcLen
* U_SIZEOF_UCHAR
);
85 /* test null-terminated source and return value of number of UChars required */
87 destLen
= func(src
,-1,NULL
,0,options
, &parseError
, &status
);
88 if(status
== U_BUFFER_OVERFLOW_ERROR
){
89 status
= U_ZERO_ERROR
; /* reset error code */
90 if(destLen
+1 < MAX_DEST_SIZE
){
92 destLen
= func(src
,-1,dest
,destLen
+1,options
, &parseError
, &status
);
93 /* TODO : compare output with expected */
94 if(U_SUCCESS(status
) && expectedStatus
!= U_IDNA_STD3_ASCII_RULES_ERROR
&& (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
95 log_err("Did not get the expected result for null terminated source.\n" );
98 log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName
);
102 if(status
!= expectedStatus
){
103 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
));
108 status
= U_ZERO_ERROR
;
109 destLen
= func(src
,-1,NULL
,0,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
110 if(status
== U_BUFFER_OVERFLOW_ERROR
){
111 status
= U_ZERO_ERROR
; /* reset error code */
112 if(destLen
+1 < MAX_DEST_SIZE
){
114 destLen
= func(src
,-1,dest
,destLen
+1,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
115 /* TODO : compare output with expected */
116 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
117 log_err("Did not get the expected result for %s null terminated source with both options set.\n",testName
);
121 log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName
);
124 /*testing query string*/
125 if(status
!= expectedStatus
&& expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
){
126 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
));
130 status
= U_ZERO_ERROR
;
132 /* test source with lengthand return value of number of UChars required*/
133 destLen
= func(tSrc
, tSrcLen
, NULL
,0,options
, &parseError
, &status
);
134 if(status
== U_BUFFER_OVERFLOW_ERROR
){
135 status
= U_ZERO_ERROR
; /* reset error code */
136 if(destLen
+1 < MAX_DEST_SIZE
){
138 destLen
= func(src
,u_strlen(src
),dest
,destLen
+1,options
, &parseError
, &status
);
139 /* TODO : compare output with expected */
140 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
141 log_err("Did not get the expected result for %s with source length.\n",testName
);
144 log_err( "%s with source length failed. Requires destCapacity > 300\n",testName
);
148 if(status
!= expectedStatus
){
149 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
));
152 status
= U_ZERO_ERROR
;
154 destLen
= func(tSrc
,tSrcLen
,NULL
,0,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
156 if(status
== U_BUFFER_OVERFLOW_ERROR
){
157 status
= U_ZERO_ERROR
; /* reset error code */
158 if(destLen
+1 < MAX_DEST_SIZE
){
160 destLen
= func(src
,u_strlen(src
),dest
,destLen
+1,options
| UIDNA_ALLOW_UNASSIGNED
, &parseError
, &status
);
161 /* TODO : compare output with expected */
162 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
163 log_err("Did not get the expected result for %s with source length and both options set.\n",testName
);
166 log_err( "%s with source length failed. Requires destCapacity > 300\n",testName
);
169 /*testing query string*/
170 if(status
!= expectedStatus
&& expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
){
171 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
));
175 status
= U_ZERO_ERROR
;
176 destLen
= func(src
,-1,NULL
,0,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
177 if(status
== U_BUFFER_OVERFLOW_ERROR
){
178 status
= U_ZERO_ERROR
; /* reset error code*/
179 if(destLen
+1 < MAX_DEST_SIZE
){
181 destLen
= func(src
,-1,dest
,destLen
+1,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
182 /* TODO : compare output with expected*/
183 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
184 log_err("Did not get the expected result for %s null terminated source with both options set.\n",testName
);
188 log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName
);
191 /*testing query string*/
192 if(status
!= expectedStatus
){
193 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
));
196 status
= U_ZERO_ERROR
;
198 destLen
= func(tSrc
,tSrcLen
,NULL
,0,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
200 if(status
== U_BUFFER_OVERFLOW_ERROR
){
201 status
= U_ZERO_ERROR
; /* reset error code*/
202 if(destLen
+1 < MAX_DEST_SIZE
){
204 destLen
= func(src
,u_strlen(src
),dest
,destLen
+1,options
| UIDNA_USE_STD3_RULES
, &parseError
, &status
);
205 /* TODO : compare output with expected*/
206 if(U_SUCCESS(status
) && (doCompare
==TRUE
) && u_strCaseCompare(dest
,destLen
, expected
,expectedLen
,0,&status
)!=0){
207 log_err("Did not get the expected result for %s with source length and both options set.\n",testName
);
210 log_err( "%s with source length failed. Requires destCapacity > 300\n",testName
);
213 /*testing query string*/
214 if(status
!= expectedStatus
&& expectedStatus
!= U_IDNA_UNASSIGNED_ERROR
){
215 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
));
220 static UChar unicodeIn
[][41] ={
222 0x0644, 0x064A, 0x0647, 0x0645, 0x0627, 0x0628, 0x062A, 0x0643, 0x0644,
223 0x0645, 0x0648, 0x0634, 0x0639, 0x0631, 0x0628, 0x064A, 0x061F, 0x0000
226 0x4ED6, 0x4EEC, 0x4E3A, 0x4EC0, 0x4E48, 0x4E0D, 0x8BF4, 0x4E2D, 0x6587,
230 0x0050, 0x0072, 0x006F, 0x010D, 0x0070, 0x0072, 0x006F, 0x0073, 0x0074,
231 0x011B, 0x006E, 0x0065, 0x006D, 0x006C, 0x0075, 0x0076, 0x00ED, 0x010D,
232 0x0065, 0x0073, 0x006B, 0x0079, 0x0000
235 0x05DC, 0x05DE, 0x05D4, 0x05D4, 0x05DD, 0x05E4, 0x05E9, 0x05D5, 0x05D8,
236 0x05DC, 0x05D0, 0x05DE, 0x05D3, 0x05D1, 0x05E8, 0x05D9, 0x05DD, 0x05E2,
237 0x05D1, 0x05E8, 0x05D9, 0x05EA, 0x0000
240 0x092F, 0x0939, 0x0932, 0x094B, 0x0917, 0x0939, 0x093F, 0x0928, 0x094D,
241 0x0926, 0x0940, 0x0915, 0x094D, 0x092F, 0x094B, 0x0902, 0x0928, 0x0939,
242 0x0940, 0x0902, 0x092C, 0x094B, 0x0932, 0x0938, 0x0915, 0x0924, 0x0947,
243 0x0939, 0x0948, 0x0902, 0x0000
246 0x306A, 0x305C, 0x307F, 0x3093, 0x306A, 0x65E5, 0x672C, 0x8A9E, 0x3092,
247 0x8A71, 0x3057, 0x3066, 0x304F, 0x308C, 0x306A, 0x3044, 0x306E, 0x304B,
252 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
253 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
254 0xC5BC, 0xB9C8, 0xB098, 0xC88B, 0xC744, 0xAE4C, 0x0000
258 0x043F, 0x043E, 0x0447, 0x0435, 0x043C, 0x0443, 0x0436, 0x0435, 0x043E,
259 0x043D, 0x0438, 0x043D, 0x0435, 0x0433, 0x043E, 0x0432, 0x043E, 0x0440,
260 0x044F, 0x0442, 0x043F, 0x043E, 0x0440, 0x0443, 0x0441, 0x0441, 0x043A,
264 0x0050, 0x006F, 0x0072, 0x0071, 0x0075, 0x00E9, 0x006E, 0x006F, 0x0070,
265 0x0075, 0x0065, 0x0064, 0x0065, 0x006E, 0x0073, 0x0069, 0x006D, 0x0070,
266 0x006C, 0x0065, 0x006D, 0x0065, 0x006E, 0x0074, 0x0065, 0x0068, 0x0061,
267 0x0062, 0x006C, 0x0061, 0x0072, 0x0065, 0x006E, 0x0045, 0x0073, 0x0070,
268 0x0061, 0x00F1, 0x006F, 0x006C, 0x0000
271 0x4ED6, 0x5011, 0x7232, 0x4EC0, 0x9EBD, 0x4E0D, 0x8AAA, 0x4E2D, 0x6587,
275 0x0054, 0x1EA1, 0x0069, 0x0073, 0x0061, 0x006F, 0x0068, 0x1ECD, 0x006B,
276 0x0068, 0x00F4, 0x006E, 0x0067, 0x0074, 0x0068, 0x1EC3, 0x0063, 0x0068,
277 0x1EC9, 0x006E, 0x00F3, 0x0069, 0x0074, 0x0069, 0x1EBF, 0x006E, 0x0067,
278 0x0056, 0x0069, 0x1EC7, 0x0074, 0x0000
281 0x0033, 0x5E74, 0x0042, 0x7D44, 0x91D1, 0x516B, 0x5148, 0x751F, 0x0000
284 0x5B89, 0x5BA4, 0x5948, 0x7F8E, 0x6075, 0x002D, 0x0077, 0x0069, 0x0074,
285 0x0068, 0x002D, 0x0053, 0x0055, 0x0050, 0x0045, 0x0052, 0x002D, 0x004D,
286 0x004F, 0x004E, 0x004B, 0x0045, 0x0059, 0x0053, 0x0000
289 0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x002D, 0x0041, 0x006E, 0x006F,
290 0x0074, 0x0068, 0x0065, 0x0072, 0x002D, 0x0057, 0x0061, 0x0079, 0x002D,
291 0x305D, 0x308C, 0x305E, 0x308C, 0x306E, 0x5834, 0x6240, 0x0000
294 0x3072, 0x3068, 0x3064, 0x5C4B, 0x6839, 0x306E, 0x4E0B, 0x0032, 0x0000
297 0x004D, 0x0061, 0x006A, 0x0069, 0x3067, 0x004B, 0x006F, 0x0069, 0x3059,
298 0x308B, 0x0035, 0x79D2, 0x524D, 0x0000
301 0x30D1, 0x30D5, 0x30A3, 0x30FC, 0x0064, 0x0065, 0x30EB, 0x30F3, 0x30D0,
305 0x305D, 0x306E, 0x30B9, 0x30D4, 0x30FC, 0x30C9, 0x3067, 0x0000
307 /* test non-BMP code points */
309 0xD800, 0xDF00, 0xD800, 0xDF01, 0xD800, 0xDF02, 0xD800, 0xDF03, 0xD800, 0xDF05,
310 0xD800, 0xDF06, 0xD800, 0xDF07, 0xD800, 0xDF09, 0xD800, 0xDF0A, 0xD800, 0xDF0B,
314 0xD800, 0xDF0D, 0xD800, 0xDF0C, 0xD800, 0xDF1E, 0xD800, 0xDF0F, 0xD800, 0xDF16,
315 0xD800, 0xDF15, 0xD800, 0xDF14, 0xD800, 0xDF12, 0xD800, 0xDF10, 0xD800, 0xDF20,
321 0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac
325 0x0062, 0x006f, 0x006e, 0x0121, 0x0075, 0x0073, 0x0061, 0x0127,
330 0x043f, 0x043e, 0x0447, 0x0435, 0x043c, 0x0443, 0x0436, 0x0435,
331 0x043e, 0x043d, 0x0438, 0x043d, 0x0435, 0x0433, 0x043e, 0x0432,
332 0x043e, 0x0440, 0x044f, 0x0442, 0x043f, 0x043e, 0x0440, 0x0443,
333 0x0441, 0x0441, 0x043a, 0x0438
338 static const char *asciiIn
[] = {
339 "xn--egbpdaj6bu4bxfgehfvwxn",
340 "xn--ihqwcrb4cv8a8dqg056pqjye",
341 "xn--Proprostnemluvesky-uyb24dma41a",
342 "xn--4dbcagdahymbxekheh6e0a7fei0b",
343 "xn--i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd",
344 "xn--n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa",
345 /* "xn--989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c",*/
346 "xn--b1abfaaepdrnnbgefbaDotcwatmq2g4l",
347 "xn--PorqunopuedensimplementehablarenEspaol-fmd56a",
348 "xn--ihqwctvzc91f659drss3x8bo0yb",
349 "xn--TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g",
350 "xn--3B-ww4c5e180e575a65lsy2b",
351 "xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n",
352 "xn--Hello-Another-Way--fc4qua05auwb3674vfr0b",
353 "xn--2-u9tlzr9756bt3uc0v",
354 "xn--MajiKoi5-783gue6qz075azm5e",
355 "xn--de-jg4avhby1noc0d",
356 "xn--d9juau41awczczp",
358 "XN--db8CBHEJLGH4E0AL",
359 "xn--hxargifdar", /* Greek */
360 "xn--bonusaa-5bb1da", /* Maltese */
361 "xn--b1abfaaepdrnnbgefbadotcwatmq2g4l", /* Russian (Cyrillic)*/
365 static const char *domainNames
[] = {
366 "slip129-37-118-146.nc.us.ibm.net",
367 "saratoga.pe.utexas.edu",
368 "dial-120-45.ots.utexas.edu",
369 "woo-085.dorms.waller.net",
370 "hd30-049.hil.compuserve.com",
371 "pem203-31.pe.ttu.edu",
372 "56K-227.MaxTNT3.pdq.net",
373 "dial-36-2.ots.utexas.edu",
374 "slip129-37-23-152.ga.us.ibm.net",
375 "ts45ip119.cadvision.com",
376 "sdn-ts-004txaustP05.dialsprint.net",
377 "bar-tnt1s66.erols.com",
378 "101.st-louis-15.mo.dial-access.att.net",
380 "dial-13-2.ots.utexas.edu",
381 "net-redynet29.datamarkets.com.ar",
382 "ccs-shiva28.reacciun.net.ve",
383 "7.houston-11.tx.dial-access.att.net",
384 "ingw129-37-120-26.mo.us.ibm.net",
385 "dialup6.austintx.com",
387 "slip129-37-119-194.nc.us.ibm.net",
388 "cs7.dillons.co.uk.203.119.193.in-addr.arpa",
389 "swprd1.innovplace.saskatoon.sk.ca",
390 "bikini.bologna.maraut.it",
391 "node91.subnet159-198-79.baxter.com",
392 "cust19.max5.new-york.ny.ms.uu.net",
393 "balexander.slip.andrew.cmu.edu",
394 "pool029.max2.denver.co.dynip.alter.net",
395 "cust49.max9.new-york.ny.ms.uu.net",
396 "s61.abq-dialin2.hollyberry.com",
397 "\\u0917\\u0928\\u0947\\u0936.sanjose.ibm.com", /*':'(0x003a) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
399 /* "www.\\u00E0\\u00B3\\u00AF.com",//' ' (0x0020) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
400 "www.\\u00C2\\u00A4.com",
401 "www.\\u00C2\\u00A3.com",
402 /* "\\u0025", //'%' (0x0025) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
403 /* "\\u005C\\u005C", //'\' (0x005C) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
406 /*"www.\\u0021.com",*/
407 /*"www.\\u0024.com",*/
409 /* These yeild U_IDNA_PROHIBITED_ERROR*/
410 /*"\\u00CF\\u0082.com",*/
411 /*"\\u00CE\\u00B2\\u00C3\\u009Fss.com",*/
412 /*"\\u00E2\\u0098\\u00BA.com",*/
413 "\\u00C3\\u00BC.com",
421 UChar buf
[MAX_DEST_SIZE
];
422 const char* testName
= "uidna_toASCII";
423 TestFunc func
= uidna_toASCII
;
424 for(i
=0;i
< (int32_t)(sizeof(unicodeIn
)/sizeof(unicodeIn
[0])); i
++){
425 u_charsToUChars(asciiIn
[i
],buf
, (int32_t)strlen(asciiIn
[i
])+1);
426 testAPI(unicodeIn
[i
], buf
,testName
, FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
435 UChar buf
[MAX_DEST_SIZE
];
436 const char* testName
= "uidna_toUnicode";
437 TestFunc func
= uidna_toUnicode
;
438 for(i
=0;i
< (int32_t)(sizeof(asciiIn
)/sizeof(asciiIn
[0])); i
++){
439 u_charsToUChars(asciiIn
[i
],buf
, (int32_t)strlen(asciiIn
[i
])+1);
440 testAPI(buf
,unicodeIn
[i
],testName
,FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
448 UChar buf
[MAX_DEST_SIZE
];
449 UChar expected
[MAX_DEST_SIZE
];
450 UErrorCode status
= U_ZERO_ERROR
;
452 UParseError parseError
;
453 const char* testName
="uidna_IDNToUnicode";
454 TestFunc func
= uidna_IDNToUnicode
;
455 for(i
=0;i
< (int32_t)(sizeof(domainNames
)/sizeof(domainNames
[0])); i
++){
456 bufLen
= (int32_t)strlen(domainNames
[i
]);
457 bufLen
= u_unescape(domainNames
[i
],buf
, bufLen
+1);
458 func(buf
,bufLen
,expected
,MAX_DEST_SIZE
, UIDNA_ALLOW_UNASSIGNED
, &parseError
,&status
);
459 if(U_FAILURE(status
)){
460 log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName
, i
, u_errorName(status
));
463 testAPI(buf
,expected
,testName
,FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
464 /*test toUnicode with all labels in the string*/
465 testAPI(buf
,expected
,testName
, FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
466 if(U_FAILURE(status
)){
467 log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName
,i
, u_errorName(status
));
477 UChar buf
[MAX_DEST_SIZE
];
478 UChar expected
[MAX_DEST_SIZE
];
479 UErrorCode status
= U_ZERO_ERROR
;
481 UParseError parseError
;
482 const char* testName
="udina_IDNToASCII";
483 TestFunc func
=uidna_IDNToASCII
;
485 for(i
=0;i
< (int32_t)(sizeof(domainNames
)/sizeof(domainNames
[0])); i
++){
486 bufLen
= (int32_t)strlen(domainNames
[i
]);
487 bufLen
= u_unescape(domainNames
[i
],buf
, bufLen
+1);
488 func(buf
,bufLen
,expected
,MAX_DEST_SIZE
, UIDNA_ALLOW_UNASSIGNED
, &parseError
,&status
);
489 if(U_FAILURE(status
)){
490 log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName
,i
, u_errorName(status
));
493 testAPI(buf
,expected
,testName
, FALSE
,U_ZERO_ERROR
, TRUE
, TRUE
, func
);
494 /*test toASCII with all labels in the string*/
495 testAPI(buf
,expected
,testName
, FALSE
,U_ZERO_ERROR
, FALSE
, TRUE
, func
);
496 if(U_FAILURE(status
)){
497 log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName
,i
, u_errorName(status
));
507 testCompareWithSrc(const UChar
* s1
, int32_t s1Len
,
508 const UChar
* s2
, int32_t s2Len
,
509 const char* testName
, CompareFunc func
,
512 UErrorCode status
= U_ZERO_ERROR
;
513 int32_t retVal
= func(s1
,-1,s2
,-1,UIDNA_DEFAULT
,&status
);
515 if(isEqual
==TRUE
&& retVal
!=0){
516 log_err("Did not get the expected result for %s with null termniated strings.\n",testName
);
518 if(U_FAILURE(status
)){
519 log_err( "%s null terminated source failed. Error: %s\n", testName
,u_errorName(status
));
522 status
= U_ZERO_ERROR
;
523 retVal
= func(s1
,-1,s2
,-1,UIDNA_ALLOW_UNASSIGNED
,&status
);
525 if(isEqual
==TRUE
&& retVal
!=0){
526 log_err("Did not get the expected result for %s with null termniated strings with options set.\n", testName
);
528 if(U_FAILURE(status
)){
529 log_err( "%s null terminated source and options set failed. Error: %s\n",testName
, u_errorName(status
));
532 status
= U_ZERO_ERROR
;
533 retVal
= func(s1
,s1Len
,s2
,s2Len
,UIDNA_DEFAULT
,&status
);
535 if(isEqual
==TRUE
&& retVal
!=0){
536 log_err("Did not get the expected result for %s with string length.\n",testName
);
538 if(U_FAILURE(status
)){
539 log_err( "%s with string length. Error: %s\n",testName
, u_errorName(status
));
542 status
= U_ZERO_ERROR
;
543 retVal
= func(s1
,s1Len
,s2
,s2Len
,UIDNA_ALLOW_UNASSIGNED
,&status
);
545 if(isEqual
==TRUE
&& retVal
!=0){
546 log_err("Did not get the expected result for %s with string length and options set.\n",testName
);
548 if(U_FAILURE(status
)){
549 log_err( "%s with string length and options set. Error: %s\n", u_errorName(status
), testName
);
558 const char* testName
="uidna_compare";
559 CompareFunc func
= uidna_compare
;
561 UChar www
[] = {0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
562 UChar com
[] = {0x002E, 0x0043, 0x004F, 0x004D, 0x0000};
563 UChar buf
[MAX_DEST_SIZE
]={0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
564 UChar source
[MAX_DEST_SIZE
]={0},
565 uni0
[MAX_DEST_SIZE
]={0},
566 uni1
[MAX_DEST_SIZE
]={0},
567 ascii0
[MAX_DEST_SIZE
]={0},
568 ascii1
[MAX_DEST_SIZE
]={0},
569 temp
[MAX_DEST_SIZE
] ={0};
572 u_strcat(uni0
,unicodeIn
[0]);
575 u_strcat(uni1
,unicodeIn
[1]);
578 u_charsToUChars(asciiIn
[0], temp
, (int32_t)strlen(asciiIn
[0]));
579 u_strcat(ascii0
,temp
);
580 u_strcat(ascii0
,com
);
582 memset(temp
, 0, U_SIZEOF_UCHAR
* MAX_DEST_SIZE
);
584 u_charsToUChars(asciiIn
[1], temp
, (int32_t)strlen(asciiIn
[1]));
585 u_strcat(ascii1
,temp
);
586 u_strcat(ascii1
,com
);
589 u_strcat(source
, www
);
591 for(i
=0;i
< (int32_t)(sizeof(unicodeIn
)/sizeof(unicodeIn
[0])); i
++){
595 memset(buf
+4, 0, (MAX_DEST_SIZE
-4) * U_SIZEOF_UCHAR
);
597 u_charsToUChars(asciiIn
[i
],buf
+4, (int32_t)strlen(asciiIn
[i
]));
601 /* for every entry in unicodeIn array
602 prepend www. and append .com*/
604 u_strncat(source
,unicodeIn
[i
], u_strlen(unicodeIn
[i
]));
605 u_strcat(source
,com
);
607 /* a) compare it with itself*/
609 srcLen
= u_strlen(src
);
611 testCompareWithSrc(src
,srcLen
,src
,srcLen
,testName
, func
, TRUE
);
613 /* b) compare it with asciiIn equivalent */
614 testCompareWithSrc(src
,srcLen
,buf
,u_strlen(buf
),testName
, func
,TRUE
);
616 /* c) compare it with unicodeIn not equivalent*/
618 testCompareWithSrc(src
,srcLen
,uni1
,u_strlen(uni1
),testName
, func
,FALSE
);
620 testCompareWithSrc(src
,srcLen
,uni0
,u_strlen(uni0
),testName
, func
,FALSE
);
622 /* d) compare it with asciiIn not equivalent */
624 testCompareWithSrc(src
,srcLen
,ascii1
,u_strlen(ascii1
),testName
, func
,FALSE
);
626 testCompareWithSrc(src
,srcLen
,ascii0
,u_strlen(ascii0
),testName
, func
,FALSE
);
632 static void TestUnicode32Norm() {
634 * test Unicode 3.2 normalization, before Public Review Issue #29
635 * see cnormtst.c TestComposition()
637 static const UChar strings
[][8]={
638 { 0x1100, 0x0300, 0x1161, 0x0327 },
639 { 0x0b47, 0x0300, 0x0b3e, 0x0327 }
642 UChar ascii
[20], unicode
[20];
644 UErrorCode errorCode
;
646 for(i
=0; i
<LENGTHOF(strings
); ++i
) {
647 errorCode
=U_ZERO_ERROR
;
648 length
=uidna_toASCII(strings
[i
], -1, ascii
, LENGTHOF(ascii
), 0, NULL
, &errorCode
);
649 length
=uidna_toUnicode(ascii
, length
, unicode
, LENGTHOF(unicode
), 0, NULL
, &errorCode
);
650 if(errorCode
!=U_IDNA_VERIFICATION_ERROR
) {
651 log_err("string %d yields %s instead of U_IDNA_VERIFICATION_ERROR\n",
652 i
, u_errorName(errorCode
));
660 * Hey, Emacs, please set the following:
663 * indent-tabs-mode: nil