1 /*
2 *******************************************************************************
3 *
4 * Copyright (C) 2003-2014, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 *******************************************************************************
8 * file name: idnatest.c
9 * encoding: US-ASCII
10 * tab size: 8 (not used)
11 * indentation:4
12 *
13 * created on: 2003jul11
14 * created by: Ram Viswanadha
15 */
16 #include <stdlib.h>
17 #include <string.h>
18 #include "unicode/utypes.h"
19
20 #if !UCONFIG_NO_IDNA
21
22 #include "unicode/ustring.h"
23 #include "unicode/uidna.h"
24 #include "cintltst.h"
25 #include "cmemory.h"
26
27 #define MAX_DEST_SIZE 1000
28
29 static void TestToUnicode(void);
30 static void TestToASCII(void);
31 static void TestIDNToUnicode(void);
32 static void TestIDNToASCII(void);
33 static void TestCompare(void);
34 static void TestJB4490(void);
35 static void TestJB4475(void);
36 static void TestLength(void);
37 static void TestJB5273(void);
38 static void TestUTS46(void);
39
40 void addIDNATest(TestNode** root);
41
42
43 typedef int32_t
44 (U_EXPORT2 *TestFunc) ( const UChar *src, int32_t srcLength,
45 UChar *dest, int32_t destCapacity,
46 int32_t options, UParseError *parseError,
47 UErrorCode *status);
48 typedef int32_t
49 (U_EXPORT2 *CompareFunc) (const UChar *s1, int32_t s1Len,
50 const UChar *s2, int32_t s2Len,
51 int32_t options,
52 UErrorCode *status);
53
54
55 void
addIDNATest(TestNode ** root)56 addIDNATest(TestNode** root)
57 {
58 addTest(root, &TestToUnicode, "idna/TestToUnicode");
59 addTest(root, &TestToASCII, "idna/TestToASCII");
60 addTest(root, &TestIDNToUnicode, "idna/TestIDNToUnicode");
61 addTest(root, &TestIDNToASCII, "idna/TestIDNToASCII");
62 addTest(root, &TestCompare, "idna/TestCompare");
63 addTest(root, &TestJB4490, "idna/TestJB4490");
64 addTest(root, &TestJB4475, "idna/TestJB4475");
65 addTest(root, &TestLength, "idna/TestLength");
66 addTest(root, &TestJB5273, "idna/TestJB5273");
67 addTest(root, &TestUTS46, "idna/TestUTS46");
68 }
69
70 static void
testAPI(const UChar * src,const UChar * expected,const char * testName,UBool useSTD3ASCIIRules,UErrorCode expectedStatus,UBool doCompare,UBool testUnassigned,TestFunc func)71 testAPI(const UChar* src, const UChar* expected, const char* testName,
72 UBool useSTD3ASCIIRules,UErrorCode expectedStatus,
73 UBool doCompare, UBool testUnassigned, TestFunc func){
74
75 UErrorCode status = U_ZERO_ERROR;
76 UChar destStack[MAX_DEST_SIZE];
77 int32_t destLen = 0;
78 UChar* dest = NULL;
79 int32_t expectedLen = (expected != NULL) ? u_strlen(expected) : 0;
80 int32_t options = (useSTD3ASCIIRules == TRUE) ? UIDNA_USE_STD3_RULES : UIDNA_DEFAULT;
81 UParseError parseError;
82 int32_t tSrcLen = 0;
83 UChar* tSrc = NULL;
84
85 if(src != NULL){
86 tSrcLen = u_strlen(src);
87 tSrc =(UChar*) malloc( U_SIZEOF_UCHAR * tSrcLen );
88 memcpy(tSrc,src,tSrcLen * U_SIZEOF_UCHAR);
89 }
90
91 /* test null-terminated source and return value of number of UChars required */
92
93 destLen = func(src,-1,NULL,0,options, &parseError , &status);
94 if(status == U_BUFFER_OVERFLOW_ERROR){
95 status = U_ZERO_ERROR; /* reset error code */
96 if(destLen+1 < MAX_DEST_SIZE){
97 dest = destStack;
98 destLen = func(src,-1,dest,destLen+1,options, &parseError, &status);
99 /* TODO : compare output with expected */
100 if(U_SUCCESS(status) && expectedStatus != U_IDNA_STD3_ASCII_RULES_ERROR&& (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
101 log_err("Did not get the expected result for null terminated source.\n" );
102 }
103 }else{
104 log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName);
105 }
106 }
107
108 if(status != expectedStatus){
109 log_err_status(status, "Did not get the expected error for %s null terminated source failed. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status));
110 free(tSrc);
111 return;
112 }
113 if(testUnassigned ){
114 status = U_ZERO_ERROR;
115 destLen = func(src,-1,NULL,0,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
116 if(status == U_BUFFER_OVERFLOW_ERROR){
117 status = U_ZERO_ERROR; /* reset error code */
118 if(destLen+1 < MAX_DEST_SIZE){
119 dest = destStack;
120 destLen = func(src,-1,dest,destLen+1,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
121 /* TODO : compare output with expected */
122 if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
123 log_err("Did not get the expected result for %s null terminated source with both options set.\n",testName);
124
125 }
126 }else{
127 log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName);
128 }
129 }
130 /*testing query string*/
131 if(status != expectedStatus && expectedStatus != U_IDNA_UNASSIGNED_ERROR){
132 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));
133 }
134 }
135
136 status = U_ZERO_ERROR;
137
138 /* test source with lengthand return value of number of UChars required*/
139 destLen = func(tSrc, tSrcLen, NULL,0,options, &parseError, &status);
140 if(status == U_BUFFER_OVERFLOW_ERROR){
141 status = U_ZERO_ERROR; /* reset error code */
142 if(destLen+1 < MAX_DEST_SIZE){
143 dest = destStack;
144 destLen = func(src,u_strlen(src),dest,destLen+1,options, &parseError, &status);
145 /* TODO : compare output with expected */
146 if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
147 log_err("Did not get the expected result for %s with source length.\n",testName);
148 }
149 }else{
150 log_err( "%s with source length failed. Requires destCapacity > 300\n",testName);
151 }
152 }
153
154 if(status != expectedStatus){
155 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));
156 }
157 if(testUnassigned){
158 status = U_ZERO_ERROR;
159
160 destLen = func(tSrc,tSrcLen,NULL,0,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
161
162 if(status == U_BUFFER_OVERFLOW_ERROR){
163 status = U_ZERO_ERROR; /* reset error code */
164 if(destLen+1 < MAX_DEST_SIZE){
165 dest = destStack;
166 destLen = func(src,u_strlen(src),dest,destLen+1,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
167 /* TODO : compare output with expected */
168 if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
169 log_err("Did not get the expected result for %s with source length and both options set.\n",testName);
170 }
171 }else{
172 log_err( "%s with source length failed. Requires destCapacity > 300\n",testName);
173 }
174 }
175 /*testing query string*/
176 if(status != expectedStatus && expectedStatus != U_IDNA_UNASSIGNED_ERROR){
177 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));
178 }
179 }
180
181 status = U_ZERO_ERROR;
182 destLen = func(src,-1,NULL,0,options | UIDNA_USE_STD3_RULES, &parseError, &status);
183 if(status == U_BUFFER_OVERFLOW_ERROR){
184 status = U_ZERO_ERROR; /* reset error code*/
185 if(destLen+1 < MAX_DEST_SIZE){
186 dest = destStack;
187 destLen = func(src,-1,dest,destLen+1,options | UIDNA_USE_STD3_RULES, &parseError, &status);
188 /* TODO : compare output with expected*/
189 if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
190 log_err("Did not get the expected result for %s null terminated source with both options set.\n",testName);
191
192 }
193 }else{
194 log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName);
195 }
196 }
197 /*testing query string*/
198 if(status != expectedStatus){
199 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));
200 }
201
202 status = U_ZERO_ERROR;
203
204 destLen = func(tSrc,tSrcLen,NULL,0,options | UIDNA_USE_STD3_RULES, &parseError, &status);
205
206 if(status == U_BUFFER_OVERFLOW_ERROR){
207 status = U_ZERO_ERROR; /* reset error code*/
208 if(destLen+1 < MAX_DEST_SIZE){
209 dest = destStack;
210 destLen = func(src,u_strlen(src),dest,destLen+1,options | UIDNA_USE_STD3_RULES, &parseError, &status);
211 /* TODO : compare output with expected*/
212 if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
213 log_err("Did not get the expected result for %s with source length and both options set.\n",testName);
214 }
215 }else{
216 log_err( "%s with source length failed. Requires destCapacity > 300\n",testName);
217 }
218 }
219 /*testing query string*/
220 if(status != expectedStatus && expectedStatus != U_IDNA_UNASSIGNED_ERROR){
221 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));
222 }
223 free(tSrc);
224 }
225
226 static const UChar unicodeIn[][41] ={
227 {
228 0x0644, 0x064A, 0x0647, 0x0645, 0x0627, 0x0628, 0x062A, 0x0643, 0x0644,
229 0x0645, 0x0648, 0x0634, 0x0639, 0x0631, 0x0628, 0x064A, 0x061F, 0x0000
230 },
231 {
232 0x4ED6, 0x4EEC, 0x4E3A, 0x4EC0, 0x4E48, 0x4E0D, 0x8BF4, 0x4E2D, 0x6587,
233 0x0000
234 },
235 {
236 0x0050, 0x0072, 0x006F, 0x010D, 0x0070, 0x0072, 0x006F, 0x0073, 0x0074,
237 0x011B, 0x006E, 0x0065, 0x006D, 0x006C, 0x0075, 0x0076, 0x00ED, 0x010D,
238 0x0065, 0x0073, 0x006B, 0x0079, 0x0000
239 },
240 {
241 0x05DC, 0x05DE, 0x05D4, 0x05D4, 0x05DD, 0x05E4, 0x05E9, 0x05D5, 0x05D8,
242 0x05DC, 0x05D0, 0x05DE, 0x05D3, 0x05D1, 0x05E8, 0x05D9, 0x05DD, 0x05E2,
243 0x05D1, 0x05E8, 0x05D9, 0x05EA, 0x0000
244 },
245 {
246 0x092F, 0x0939, 0x0932, 0x094B, 0x0917, 0x0939, 0x093F, 0x0928, 0x094D,
247 0x0926, 0x0940, 0x0915, 0x094D, 0x092F, 0x094B, 0x0902, 0x0928, 0x0939,
248 0x0940, 0x0902, 0x092C, 0x094B, 0x0932, 0x0938, 0x0915, 0x0924, 0x0947,
249 0x0939, 0x0948, 0x0902, 0x0000
250 },
251 {
252 0x306A, 0x305C, 0x307F, 0x3093, 0x306A, 0x65E5, 0x672C, 0x8A9E, 0x3092,
253 0x8A71, 0x3057, 0x3066, 0x304F, 0x308C, 0x306A, 0x3044, 0x306E, 0x304B,
254 0x0000
255 },
256 /*
257 {
258 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
259 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
260 0xC5BC, 0xB9C8, 0xB098, 0xC88B, 0xC744, 0xAE4C, 0x0000
261 },
262 */
263 {
264 0x043F, 0x043E, 0x0447, 0x0435, 0x043C, 0x0443, 0x0436, 0x0435, 0x043E,
265 0x043D, 0x0438, 0x043D, 0x0435, 0x0433, 0x043E, 0x0432, 0x043E, 0x0440,
266 0x044F, 0x0442, 0x043F, 0x043E, 0x0440, 0x0443, 0x0441, 0x0441, 0x043A,
267 0x0438, 0x0000
268 },
269 {
270 0x0050, 0x006F, 0x0072, 0x0071, 0x0075, 0x00E9, 0x006E, 0x006F, 0x0070,
271 0x0075, 0x0065, 0x0064, 0x0065, 0x006E, 0x0073, 0x0069, 0x006D, 0x0070,
272 0x006C, 0x0065, 0x006D, 0x0065, 0x006E, 0x0074, 0x0065, 0x0068, 0x0061,
273 0x0062, 0x006C, 0x0061, 0x0072, 0x0065, 0x006E, 0x0045, 0x0073, 0x0070,
274 0x0061, 0x00F1, 0x006F, 0x006C, 0x0000
275 },
276 {
277 0x4ED6, 0x5011, 0x7232, 0x4EC0, 0x9EBD, 0x4E0D, 0x8AAA, 0x4E2D, 0x6587,
278 0x0000
279 },
280 {
281 0x0054, 0x1EA1, 0x0069, 0x0073, 0x0061, 0x006F, 0x0068, 0x1ECD, 0x006B,
282 0x0068, 0x00F4, 0x006E, 0x0067, 0x0074, 0x0068, 0x1EC3, 0x0063, 0x0068,
283 0x1EC9, 0x006E, 0x00F3, 0x0069, 0x0074, 0x0069, 0x1EBF, 0x006E, 0x0067,
284 0x0056, 0x0069, 0x1EC7, 0x0074, 0x0000
285 },
286 {
287 0x0033, 0x5E74, 0x0042, 0x7D44, 0x91D1, 0x516B, 0x5148, 0x751F, 0x0000
288 },
289 {
290 0x5B89, 0x5BA4, 0x5948, 0x7F8E, 0x6075, 0x002D, 0x0077, 0x0069, 0x0074,
291 0x0068, 0x002D, 0x0053, 0x0055, 0x0050, 0x0045, 0x0052, 0x002D, 0x004D,
292 0x004F, 0x004E, 0x004B, 0x0045, 0x0059, 0x0053, 0x0000
293 },
294 {
295 0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x002D, 0x0041, 0x006E, 0x006F,
296 0x0074, 0x0068, 0x0065, 0x0072, 0x002D, 0x0057, 0x0061, 0x0079, 0x002D,
297 0x305D, 0x308C, 0x305E, 0x308C, 0x306E, 0x5834, 0x6240, 0x0000
298 },
299 {
300 0x3072, 0x3068, 0x3064, 0x5C4B, 0x6839, 0x306E, 0x4E0B, 0x0032, 0x0000
301 },
302 {
303 0x004D, 0x0061, 0x006A, 0x0069, 0x3067, 0x004B, 0x006F, 0x0069, 0x3059,
304 0x308B, 0x0035, 0x79D2, 0x524D, 0x0000
305 },
306 {
307 0x30D1, 0x30D5, 0x30A3, 0x30FC, 0x0064, 0x0065, 0x30EB, 0x30F3, 0x30D0,
308 0x0000
309 },
310 {
311 0x305D, 0x306E, 0x30B9, 0x30D4, 0x30FC, 0x30C9, 0x3067, 0x0000
312 },
313 /* test non-BMP code points */
314 {
315 0xD800, 0xDF00, 0xD800, 0xDF01, 0xD800, 0xDF02, 0xD800, 0xDF03, 0xD800, 0xDF05,
316 0xD800, 0xDF06, 0xD800, 0xDF07, 0xD800, 0xDF09, 0xD800, 0xDF0A, 0xD800, 0xDF0B,
317 0x0000
318 },
319 {
320 0xD800, 0xDF0D, 0xD800, 0xDF0C, 0xD800, 0xDF1E, 0xD800, 0xDF0F, 0xD800, 0xDF16,
321 0xD800, 0xDF15, 0xD800, 0xDF14, 0xD800, 0xDF12, 0xD800, 0xDF10, 0xD800, 0xDF20,
322 0xD800, 0xDF21,
323 0x0000
324 },
325 /* Greek */
326 {
327 0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac
328 },
329 /* Maltese */
330 {
331 0x0062, 0x006f, 0x006e, 0x0121, 0x0075, 0x0073, 0x0061, 0x0127,
332 0x0127, 0x0061
333 },
334 /* Russian */
335 {
336 0x043f, 0x043e, 0x0447, 0x0435, 0x043c, 0x0443, 0x0436, 0x0435,
337 0x043e, 0x043d, 0x0438, 0x043d, 0x0435, 0x0433, 0x043e, 0x0432,
338 0x043e, 0x0440, 0x044f, 0x0442, 0x043f, 0x043e, 0x0440, 0x0443,
339 0x0441, 0x0441, 0x043a, 0x0438
340 },
341 {
342 0x0054,0x0045,0x0053,0x0054
343 }
344 };
345
346 static const char * const asciiIn[] = {
347 "xn--egbpdaj6bu4bxfgehfvwxn",
348 "xn--ihqwcrb4cv8a8dqg056pqjye",
349 "xn--Proprostnemluvesky-uyb24dma41a",
350 "xn--4dbcagdahymbxekheh6e0a7fei0b",
351 "xn--i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd",
352 "xn--n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa",
353 /* "xn--989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c",*/
354 "xn--b1abfaaepdrnnbgefbaDotcwatmq2g4l",
355 "xn--PorqunopuedensimplementehablarenEspaol-fmd56a",
356 "xn--ihqwctvzc91f659drss3x8bo0yb",
357 "xn--TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g",
358 "xn--3B-ww4c5e180e575a65lsy2b",
359 "xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n",
360 "xn--Hello-Another-Way--fc4qua05auwb3674vfr0b",
361 "xn--2-u9tlzr9756bt3uc0v",
362 "xn--MajiKoi5-783gue6qz075azm5e",
363 "xn--de-jg4avhby1noc0d",
364 "xn--d9juau41awczczp",
365 "XN--097CCDEKGHQJK",
366 "XN--db8CBHEJLGH4E0AL",
367 "xn--hxargifdar", /* Greek */
368 "xn--bonusaa-5bb1da", /* Maltese */
369 "xn--b1abfaaepdrnnbgefbadotcwatmq2g4l", /* Russian (Cyrillic)*/
370 "TEST"
371
372 };
373
374 static const char * const domainNames[] = {
375 "slip129-37-118-146.nc.us.ibm.net",
376 "saratoga.pe.utexas.edu",
377 "dial-120-45.ots.utexas.edu",
378 "woo-085.dorms.waller.net",
379 "hd30-049.hil.compuserve.com",
380 "pem203-31.pe.ttu.edu",
381 "56K-227.MaxTNT3.pdq.net",
382 "dial-36-2.ots.utexas.edu",
383 "slip129-37-23-152.ga.us.ibm.net",
384 "ts45ip119.cadvision.com",
385 "sdn-ts-004txaustP05.dialsprint.net",
386 "bar-tnt1s66.erols.com",
387 "101.st-louis-15.mo.dial-access.att.net",
388 "h92-245.Arco.COM",
389 "dial-13-2.ots.utexas.edu",
390 "net-redynet29.datamarkets.com.ar",
391 "ccs-shiva28.reacciun.net.ve",
392 "7.houston-11.tx.dial-access.att.net",
393 "ingw129-37-120-26.mo.us.ibm.net",
394 "dialup6.austintx.com",
395 "dns2.tpao.gov.tr",
396 "slip129-37-119-194.nc.us.ibm.net",
397 "cs7.dillons.co.uk.203.119.193.in-addr.arpa",
398 "swprd1.innovplace.saskatoon.sk.ca",
399 "bikini.bologna.maraut.it",
400 "node91.subnet159-198-79.baxter.com",
401 "cust19.max5.new-york.ny.ms.uu.net",
402 "balexander.slip.andrew.cmu.edu",
403 "pool029.max2.denver.co.dynip.alter.net",
404 "cust49.max9.new-york.ny.ms.uu.net",
405 "s61.abq-dialin2.hollyberry.com",
406 "\\u0917\\u0928\\u0947\\u0936.sanjose.ibm.com", /*':'(0x003a) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
407 "www.xn--vea.com",
408 /* "www.\\u00E0\\u00B3\\u00AF.com",//' ' (0x0020) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
409 "www.\\u00C2\\u00A4.com",
410 "www.\\u00C2\\u00A3.com",
411 /* "\\u0025", //'%' (0x0025) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
412 /* "\\u005C\\u005C", //'\' (0x005C) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
413 /*"@",*/
414 /*"\\u002F",*/
415 /*"www.\\u0021.com",*/
416 /*"www.\\u0024.com",*/
417 /*"\\u003f",*/
418 /* These yeild U_IDNA_PROHIBITED_ERROR*/
419 /*"\\u00CF\\u0082.com",*/
420 /*"\\u00CE\\u00B2\\u00C3\\u009Fss.com",*/
421 /*"\\u00E2\\u0098\\u00BA.com",*/
422 "\\u00C3\\u00BC.com"
423
424 };
425
426 static void
TestToASCII()427 TestToASCII(){
428
429 int32_t i;
430 UChar buf[MAX_DEST_SIZE];
431 const char* testName = "uidna_toASCII";
432 TestFunc func = uidna_toASCII;
433 for(i=0;i< (int32_t)(sizeof(unicodeIn)/sizeof(unicodeIn[0])); i++){
434 u_charsToUChars(asciiIn[i],buf, (int32_t)strlen(asciiIn[i])+1);
435 testAPI(unicodeIn[i], buf,testName, FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
436
437 }
438 }
439
440 static void
TestToUnicode()441 TestToUnicode(){
442
443 int32_t i;
444 UChar buf[MAX_DEST_SIZE];
445 const char* testName = "uidna_toUnicode";
446 TestFunc func = uidna_toUnicode;
447 for(i=0;i< (int32_t)(sizeof(asciiIn)/sizeof(asciiIn[0])); i++){
448 u_charsToUChars(asciiIn[i],buf, (int32_t)strlen(asciiIn[i])+1);
449 testAPI(buf,unicodeIn[i],testName,FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
450 }
451 }
452
453
454 static void
TestIDNToUnicode()455 TestIDNToUnicode(){
456 int32_t i;
457 UChar buf[MAX_DEST_SIZE];
458 UChar expected[MAX_DEST_SIZE];
459 UErrorCode status = U_ZERO_ERROR;
460 int32_t bufLen = 0;
461 UParseError parseError;
462 const char* testName="uidna_IDNToUnicode";
463 TestFunc func = uidna_IDNToUnicode;
464 for(i=0;i< (int32_t)(sizeof(domainNames)/sizeof(domainNames[0])); i++){
465 bufLen = (int32_t)strlen(domainNames[i]);
466 bufLen = u_unescape(domainNames[i],buf, bufLen+1);
467 func(buf,bufLen,expected,MAX_DEST_SIZE, UIDNA_ALLOW_UNASSIGNED, &parseError,&status);
468 if(U_FAILURE(status)){
469 log_err_status(status, "%s failed to convert domainNames[%i].Error: %s \n",testName, i, u_errorName(status));
470 break;
471 }
472 testAPI(buf,expected,testName,FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
473 /*test toUnicode with all labels in the string*/
474 testAPI(buf,expected,testName, FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
475 if(U_FAILURE(status)){
476 log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName,i, u_errorName(status));
477 break;
478 }
479 }
480
481 }
482
483 static void
TestIDNToASCII()484 TestIDNToASCII(){
485 int32_t i;
486 UChar buf[MAX_DEST_SIZE];
487 UChar expected[MAX_DEST_SIZE];
488 UErrorCode status = U_ZERO_ERROR;
489 int32_t bufLen = 0;
490 UParseError parseError;
491 const char* testName="udina_IDNToASCII";
492 TestFunc func=uidna_IDNToASCII;
493
494 for(i=0;i< (int32_t)(sizeof(domainNames)/sizeof(domainNames[0])); i++){
495 bufLen = (int32_t)strlen(domainNames[i]);
496 bufLen = u_unescape(domainNames[i],buf, bufLen+1);
497 func(buf,bufLen,expected,MAX_DEST_SIZE, UIDNA_ALLOW_UNASSIGNED, &parseError,&status);
498 if(U_FAILURE(status)){
499 log_err_status(status, "%s failed to convert domainNames[%i].Error: %s \n",testName,i, u_errorName(status));
500 break;
501 }
502 testAPI(buf,expected,testName, FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
503 /*test toASCII with all labels in the string*/
504 testAPI(buf,expected,testName, FALSE,U_ZERO_ERROR, FALSE, TRUE, func);
505 if(U_FAILURE(status)){
506 log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName,i, u_errorName(status));
507 break;
508 }
509 }
510
511
512 }
513
514
515 static void
testCompareWithSrc(const UChar * s1,int32_t s1Len,const UChar * s2,int32_t s2Len,const char * testName,CompareFunc func,UBool isEqual)516 testCompareWithSrc(const UChar* s1, int32_t s1Len,
517 const UChar* s2, int32_t s2Len,
518 const char* testName, CompareFunc func,
519 UBool isEqual){
520
521 UErrorCode status = U_ZERO_ERROR;
522 int32_t retVal = func(s1,-1,s2,-1,UIDNA_DEFAULT,&status);
523
524 if(isEqual==TRUE && retVal !=0){
525 log_err("Did not get the expected result for %s with null termniated strings.\n",testName);
526 }
527 if(U_FAILURE(status)){
528 log_err_status(status, "%s null terminated source failed. Error: %s\n", testName,u_errorName(status));
529 }
530
531 status = U_ZERO_ERROR;
532 retVal = func(s1,-1,s2,-1,UIDNA_ALLOW_UNASSIGNED,&status);
533
534 if(isEqual==TRUE && retVal !=0){
535 log_err("Did not get the expected result for %s with null termniated strings with options set.\n", testName);
536 }
537 if(U_FAILURE(status)){
538 log_err_status(status, "%s null terminated source and options set failed. Error: %s\n",testName, u_errorName(status));
539 }
540
541 status = U_ZERO_ERROR;
542 retVal = func(s1,s1Len,s2,s2Len,UIDNA_DEFAULT,&status);
543
544 if(isEqual==TRUE && retVal !=0){
545 log_err("Did not get the expected result for %s with string length.\n",testName);
546 }
547 if(U_FAILURE(status)){
548 log_err_status(status, "%s with string length. Error: %s\n",testName, u_errorName(status));
549 }
550
551 status = U_ZERO_ERROR;
552 retVal = func(s1,s1Len,s2,s2Len,UIDNA_ALLOW_UNASSIGNED,&status);
553
554 if(isEqual==TRUE && retVal !=0){
555 log_err("Did not get the expected result for %s with string length and options set.\n",testName);
556 }
557 if(U_FAILURE(status)){
558 log_err_status(status, "%s with string length and options set. Error: %s\n", u_errorName(status), testName);
559 }
560 }
561
562
563 static void
TestCompare()564 TestCompare(){
565 int32_t i;
566
567 const char* testName ="uidna_compare";
568 CompareFunc func = uidna_compare;
569
570 UChar www[] = {0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
571 UChar com[] = {0x002E, 0x0043, 0x004F, 0x004D, 0x0000};
572 UChar buf[MAX_DEST_SIZE]={0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
573 UChar source[MAX_DEST_SIZE]={0},
574 uni0[MAX_DEST_SIZE]={0},
575 uni1[MAX_DEST_SIZE]={0},
576 ascii0[MAX_DEST_SIZE]={0},
577 ascii1[MAX_DEST_SIZE]={0},
578 temp[MAX_DEST_SIZE] ={0};
579
580
581 u_strcat(uni0,unicodeIn[0]);
582 u_strcat(uni0,com);
583
584 u_strcat(uni1,unicodeIn[1]);
585 u_strcat(uni1,com);
586
587 u_charsToUChars(asciiIn[0], temp, (int32_t)strlen(asciiIn[0]));
588 u_strcat(ascii0,temp);
589 u_strcat(ascii0,com);
590
591 memset(temp, 0, U_SIZEOF_UCHAR * MAX_DEST_SIZE);
592
593 u_charsToUChars(asciiIn[1], temp, (int32_t)strlen(asciiIn[1]));
594 u_strcat(ascii1,temp);
595 u_strcat(ascii1,com);
596
597 /* prepend www. */
598 u_strcat(source, www);
599
600 for(i=0;i< (int32_t)(sizeof(unicodeIn)/sizeof(unicodeIn[0])); i++){
601 UChar* src;
602 int32_t srcLen;
603
604 memset(buf+4, 0, (MAX_DEST_SIZE-4) * U_SIZEOF_UCHAR);
605
606 u_charsToUChars(asciiIn[i],buf+4, (int32_t)strlen(asciiIn[i]));
607 u_strcat(buf,com);
608
609
610 /* for every entry in unicodeIn array
611 prepend www. and append .com*/
612 source[4]=0;
613 u_strncat(source,unicodeIn[i], u_strlen(unicodeIn[i]));
614 u_strcat(source,com);
615
616 /* a) compare it with itself*/
617 src = source;
618 srcLen = u_strlen(src);
619
620 testCompareWithSrc(src,srcLen,src,srcLen,testName, func, TRUE);
621
622 /* b) compare it with asciiIn equivalent */
623 testCompareWithSrc(src,srcLen,buf,u_strlen(buf),testName, func,TRUE);
624
625 /* c) compare it with unicodeIn not equivalent*/
626 if(i==0){
627 testCompareWithSrc(src,srcLen,uni1,u_strlen(uni1),testName, func,FALSE);
628 }else{
629 testCompareWithSrc(src,srcLen,uni0,u_strlen(uni0),testName, func,FALSE);
630 }
631 /* d) compare it with asciiIn not equivalent */
632 if(i==0){
633 testCompareWithSrc(src,srcLen,ascii1,u_strlen(ascii1),testName, func,FALSE);
634 }else{
635 testCompareWithSrc(src,srcLen,ascii0,u_strlen(ascii0),testName, func,FALSE);
636 }
637
638 }
639 }
640
TestJB4490()641 static void TestJB4490(){
642 static const UChar data[][50]= {
643 {0x00F5,0x00dE,0x00dF,0x00dD, 0x0000},
644 {0xFB00,0xFB01}
645 };
646 UChar output1[40] = {0};
647 UChar output2[40] = {0};
648 int32_t i;
649 for(i=0; i< sizeof(data)/sizeof(data[0]); i++){
650 const UChar* src1 = data[i];
651 int32_t src1Len = u_strlen(src1);
652 UChar* dest1 = output1;
653 int32_t dest1Len = 40;
654 UErrorCode status = U_ZERO_ERROR;
655 UParseError ps;
656 UChar* src2 = NULL;
657 int32_t src2Len = 0;
658 UChar* dest2 = output2;
659 int32_t dest2Len = 40;
660 dest1Len = uidna_toASCII(src1, src1Len, dest1, dest1Len,UIDNA_DEFAULT, &ps, &status);
661 if(U_FAILURE(status)){
662 log_err_status(status, "uidna_toUnicode failed with error %s.\n", u_errorName(status));
663 }
664 src2 = dest1;
665 src2Len = dest1Len;
666 dest2Len = uidna_toUnicode(src2, src2Len, dest2, dest2Len, UIDNA_DEFAULT, &ps, &status);
667 if(U_FAILURE(status)){
668 log_err_status(status, "uidna_toUnicode failed with error %s.\n", u_errorName(status));
669 }
670 }
671 }
672
TestJB4475()673 static void TestJB4475(){
674
675 static const UChar input[][10] = {
676 {0x0054,0x0045,0x0053,0x0054,0x0000},/* TEST */
677 {0x0074,0x0065,0x0073,0x0074,0x0000} /* test */
678 };
679 int i;
680 UChar output[40] = {0};
681 for(i=0; i< sizeof(input)/sizeof(input[0]); i++){
682 const UChar* src = input[i];
683 int32_t srcLen = u_strlen(src);
684 UChar* dest = output;
685 int32_t destLen = 40;
686 UErrorCode status = U_ZERO_ERROR;
687 UParseError ps;
688
689 destLen = uidna_toASCII(src, srcLen, dest, destLen,UIDNA_DEFAULT, &ps, &status);
690 if(U_FAILURE(status)){
691 log_err_status(status, "uidna_toASCII failed with error %s.\n", u_errorName(status));
692 continue;
693 }
694 if(u_strncmp(input[i], dest, srcLen)!=0){
695 log_err("uidna_toASCII did not return the expected output.\n");
696 }
697 }
698 }
699
TestLength()700 static void TestLength(){
701 {
702 static const char* cl = "my_very_very_very_very_very_very_very_very_very_very_very_very_very_long_and_incredibly_uncreative_domain_label";
703 UChar ul[128] = {'\0'};
704 UChar dest[256] = {'\0'};
705 /* this unicode string is longer than MAX_LABEL_BUFFER_SIZE and produces an
706 IDNA prepared string (including xn--)that is exactly 63 bytes long */
707 UChar ul1[] = { 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
708 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0x00AD, 0x034F, 0x1806, 0x180B,
709 0x180C, 0x180D, 0x200B, 0x200C, 0x200D, 0x2060, 0xFE00, 0xFE01, 0xFE02,
710 0xFE03, 0xFE04, 0xFE05, 0xFE06, 0xFE07, 0xFE08, 0xFE09, 0xFE0A, 0xFE0B,
711 0xFE0C, 0xFE0D, 0xFE0E, 0xFE0F, 0xFEFF, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
712 0xC138, 0x0041, 0x00AD, 0x034F, 0x1806, 0x180B, 0x180C, 0x180D, 0x200B,
713 0x200C, 0x200D, 0x2060, 0xFE00, 0xFE01, 0xFE02, 0xFE03, 0xFE04, 0xFE05,
714 0xFE06, 0xFE07, 0xFE08, 0xFE09, 0xFE0A, 0xFE0B, 0xFE0C, 0xFE0D, 0xFE0E,
715 0xFE0F, 0xFEFF, 0x00AD, 0x034F, 0x1806, 0x180B, 0x180C, 0x180D, 0x200B,
716 0x200C, 0x200D, 0x2060, 0xFE00, 0xFE01, 0xFE02, 0xFE03, 0xFE04, 0xFE05,
717 0xFE06, 0xFE07, 0xFE08, 0xFE09, 0xFE0A, 0xFE0B, 0xFE0C, 0xFE0D, 0xFE0E,
718 0xFE0F, 0xFEFF, 0x00AD, 0x034F, 0x1806, 0x180B, 0x180C, 0x180D, 0x200B,
719 0x200C, 0x200D, 0x2060, 0xFE00, 0xFE01, 0xFE02, 0xFE03, 0xFE04, 0xFE05,
720 0xFE06, 0xFE07, 0xFE08, 0xFE09, 0xFE0A, 0xFE0B, 0xFE0C, 0xFE0D, 0xFE0E,
721 0xFE0F, 0xFEFF, 0x0000
722 };
723
724 int32_t len1 = UPRV_LENGTHOF(ul1)-1/*remove the null termination*/;
725 int32_t destLen = UPRV_LENGTHOF(dest);
726 UErrorCode status = U_ZERO_ERROR;
727 UParseError ps;
728 int32_t len = (int32_t)strlen(cl);
729 u_charsToUChars(cl, ul, len+1);
730 destLen = uidna_toUnicode(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
731 if(status != U_ZERO_ERROR){
732 log_err_status(status, "uidna_toUnicode failed with error %s.\n", u_errorName(status));
733 }
734
735 status = U_ZERO_ERROR;
736 destLen = UPRV_LENGTHOF(dest);
737 len = -1;
738 destLen = uidna_toUnicode(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
739 if(status != U_ZERO_ERROR){
740 log_err_status(status, "uidna_toUnicode failed with error %s.\n", u_errorName(status));
741 }
742 status = U_ZERO_ERROR;
743 destLen = UPRV_LENGTHOF(dest);
744 len = (int32_t)strlen(cl);
745 destLen = uidna_toASCII(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
746 if(status != U_IDNA_LABEL_TOO_LONG_ERROR){
747 log_err_status(status, "uidna_toASCII failed with error %s.\n", u_errorName(status));
748 }
749
750 status = U_ZERO_ERROR;
751 destLen = UPRV_LENGTHOF(dest);
752 len = -1;
753 destLen = uidna_toASCII(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
754 if(status != U_IDNA_LABEL_TOO_LONG_ERROR){
755 log_err_status(status, "uidna_toASCII failed with error %s.\n", u_errorName(status));
756 }
757
758 status = U_ZERO_ERROR;
759 destLen = UPRV_LENGTHOF(dest);
760 destLen = uidna_toASCII(ul1, len1, dest, destLen, UIDNA_DEFAULT, &ps, &status);
761 if(status != U_ZERO_ERROR){
762 log_err_status(status, "uidna_toASCII failed with error %s.\n", u_errorName(status));
763 }
764
765 status = U_ZERO_ERROR;
766 destLen = UPRV_LENGTHOF(dest);
767 len1 = -1;
768 destLen = uidna_toASCII(ul1, len1, dest, destLen, UIDNA_DEFAULT, &ps, &status);
769 if(status != U_ZERO_ERROR){
770 log_err_status(status, "uidna_toASCII failed with error %s.\n", u_errorName(status));
771 }
772 }
773 {
774 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";
775 UChar ul[400] = {'\0'};
776 UChar dest[400] = {'\0'};
777 int32_t destLen = UPRV_LENGTHOF(dest);
778 UErrorCode status = U_ZERO_ERROR;
779 UParseError ps;
780 int32_t len = (int32_t)strlen(cl);
781 u_charsToUChars(cl, ul, len+1);
782
783 destLen = uidna_IDNToUnicode(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
784 if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
785 log_err_status(status, "uidna_IDNToUnicode failed with error %s.\n", u_errorName(status));
786 }
787
788 status = U_ZERO_ERROR;
789 destLen = UPRV_LENGTHOF(dest);
790 len = -1;
791 destLen = uidna_IDNToUnicode(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
792 if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
793 log_err_status(status, "uidna_IDNToUnicode failed with error %s.\n", u_errorName(status));
794 }
795
796 status = U_ZERO_ERROR;
797 destLen = UPRV_LENGTHOF(dest);
798 len = (int32_t)strlen(cl);
799 destLen = uidna_IDNToASCII(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
800 if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
801 log_err_status(status, "uidna_IDNToASCII failed with error %s.\n", u_errorName(status));
802 }
803
804 status = U_ZERO_ERROR;
805 destLen = UPRV_LENGTHOF(dest);
806 len = -1;
807 destLen = uidna_IDNToASCII(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
808 if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
809 log_err_status(status, "uidna_IDNToASCII failed with error %s.\n", u_errorName(status));
810 }
811
812 status = U_ZERO_ERROR;
813 uidna_compare(ul, len, ul, len, UIDNA_DEFAULT, &status);
814 if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
815 log_err_status(status, "uidna_compare failed with error %s.\n", u_errorName(status));
816 }
817 uidna_compare(ul, -1, ul, -1, UIDNA_DEFAULT, &status);
818 if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
819 log_err_status(status, "uidna_compare failed with error %s.\n", u_errorName(status));
820 }
821 }
822 }
TestJB5273()823 static void TestJB5273(){
824 static const char INVALID_DOMAIN_NAME[] = "xn--m\\u00FCller.de";
825 UChar invalid_idn[25] = {'\0'};
826 int32_t len = u_unescape(INVALID_DOMAIN_NAME, invalid_idn, strlen(INVALID_DOMAIN_NAME));
827 UChar output[50] = {'\0'};
828 UErrorCode status = U_ZERO_ERROR;
829 UParseError prsError;
830 int32_t outLen = uidna_toUnicode(invalid_idn, len, output, 50, UIDNA_DEFAULT, &prsError, &status);
831 (void)outLen; /* Suppress set but not used warning. */
832 if(U_FAILURE(status)){
833 log_err_status(status, "uidna_toUnicode failed with error: %s\n", u_errorName(status));
834 }
835 status = U_ZERO_ERROR;
836 outLen = uidna_toUnicode(invalid_idn, len, output, 50, UIDNA_USE_STD3_RULES, &prsError, &status);
837 if(U_FAILURE(status)){
838 log_err_status(status, "uidna_toUnicode failed with error: %s\n", u_errorName(status));
839 }
840
841 status = U_ZERO_ERROR;
842 outLen = uidna_IDNToUnicode(invalid_idn, len, output, 50, UIDNA_DEFAULT, &prsError, &status);
843 if(U_FAILURE(status)){
844 log_err_status(status, "uidna_toUnicode failed with error: %s\n", u_errorName(status));
845 }
846 status = U_ZERO_ERROR;
847 outLen = uidna_IDNToUnicode(invalid_idn, len, output, 50, UIDNA_USE_STD3_RULES, &prsError, &status);
848 if(U_FAILURE(status)){
849 log_err_status(status, "uidna_toUnicode failed with error: %s\n", u_errorName(status));
850 }
851 }
852
853 /*
854 * Test the new (ICU 4.6/2010) C API that was added for UTS #46.
855 * Just an API test: Functionality is tested via C++ intltest.
856 */
TestUTS46()857 static void TestUTS46() {
858 static const UChar fA_sharps16[] = { 0x66, 0x41, 0xdf, 0 };
859 static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
860 static const UChar fa_sharps16[] = { 0x66, 0x61, 0xdf, 0 };
861 static const char fa_sharps8[] = { 0x66, 0x61, (char)0xc3, (char)0x9f, 0 };
862 static const UChar fass16[] = { 0x66, 0x61, 0x73, 0x73, 0 };
863 static const char fass8[] = { 0x66, 0x61, 0x73, 0x73, 0 };
864 static const UChar fA_BEL[] = { 0x66, 0x41, 7, 0 };
865 static const UChar fa_FFFD[] = { 0x66, 0x61, 0xfffd, 0 };
866
867 UChar dest16[10];
868 char dest8[10];
869 int32_t length;
870
871 UIDNAInfo info = UIDNA_INFO_INITIALIZER;
872 UErrorCode errorCode = U_ZERO_ERROR;
873 UIDNA *uts46 = uidna_openUTS46(UIDNA_USE_STD3_RULES|UIDNA_NONTRANSITIONAL_TO_UNICODE,
874 &errorCode);
875 if(U_FAILURE(errorCode)) {
876 log_err_status(errorCode, "uidna_openUTS46() failed: %s\n", u_errorName(errorCode));
877 return;
878 }
879
880 /* These calls should succeed. */
881 length = uidna_labelToASCII(uts46, fA_sharps16, -1,
882 dest16, UPRV_LENGTHOF(dest16), &info, &errorCode);
883 if( U_FAILURE(errorCode) || length != 4 || 0 != u_memcmp(dest16, fass16, 5) ||
884 !info.isTransitionalDifferent || info.errors != 0
885 ) {
886 log_err("uidna_labelToASCII() failed: %s\n", u_errorName(errorCode));
887 }
888 errorCode = U_ZERO_ERROR;
889 length = uidna_labelToUnicode(uts46, fA_sharps16, u_strlen(fA_sharps16),
890 dest16, UPRV_LENGTHOF(dest16), &info, &errorCode);
891 if( U_FAILURE(errorCode) || length != 3 || 0 != u_memcmp(dest16, fa_sharps16, 4) ||
892 !info.isTransitionalDifferent || info.errors != 0
893 ) {
894 log_err("uidna_labelToUnicode() failed: %s\n", u_errorName(errorCode));
895 }
896 errorCode = U_ZERO_ERROR;
897 length = uidna_nameToASCII(uts46, fA_sharps16, u_strlen(fA_sharps16),
898 dest16, 4, &info, &errorCode);
899 if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
900 length != 4 || 0 != u_memcmp(dest16, fass16, 4) ||
901 !info.isTransitionalDifferent || info.errors != 0
902 ) {
903 log_err("uidna_nameToASCII() failed: %s\n", u_errorName(errorCode));
904 }
905 errorCode = U_ZERO_ERROR;
906 length = uidna_nameToUnicode(uts46, fA_sharps16, -1,
907 dest16, 3, &info, &errorCode);
908 if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
909 length != 3 || 0 != u_memcmp(dest16, fa_sharps16, 3) ||
910 !info.isTransitionalDifferent || info.errors != 0
911 ) {
912 log_err("uidna_nameToUnicode() failed: %s\n", u_errorName(errorCode));
913 }
914
915 errorCode = U_ZERO_ERROR;
916 length = uidna_labelToASCII_UTF8(uts46, fA_sharps8, -1,
917 dest8, UPRV_LENGTHOF(dest8), &info, &errorCode);
918 if( U_FAILURE(errorCode) || length != 4 || 0 != memcmp(dest8, fass8, 5) ||
919 !info.isTransitionalDifferent || info.errors != 0
920 ) {
921 log_err("uidna_labelToASCII_UTF8() failed: %s\n", u_errorName(errorCode));
922 }
923 errorCode = U_ZERO_ERROR;
924 length = uidna_labelToUnicodeUTF8(uts46, fA_sharps8, strlen(fA_sharps8),
925 dest8, UPRV_LENGTHOF(dest8), &info, &errorCode);
926 if( U_FAILURE(errorCode) || length != 4 || 0 != memcmp(dest8, fa_sharps8, 5) ||
927 !info.isTransitionalDifferent || info.errors != 0
928 ) {
929 log_err("uidna_labelToUnicodeUTF8() failed: %s\n", u_errorName(errorCode));
930 }
931 errorCode = U_ZERO_ERROR;
932 length = uidna_nameToASCII_UTF8(uts46, fA_sharps8, strlen(fA_sharps8),
933 dest8, 4, &info, &errorCode);
934 if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
935 length != 4 || 0 != memcmp(dest8, fass8, 4) ||
936 !info.isTransitionalDifferent || info.errors != 0
937 ) {
938 log_err("uidna_nameToASCII_UTF8() failed: %s\n", u_errorName(errorCode));
939 }
940 errorCode = U_ZERO_ERROR;
941 length = uidna_nameToUnicodeUTF8(uts46, fA_sharps8, -1,
942 dest8, 4, &info, &errorCode);
943 if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
944 length != 4 || 0 != memcmp(dest8, fa_sharps8, 4) ||
945 !info.isTransitionalDifferent || info.errors != 0
946 ) {
947 log_err("uidna_nameToUnicodeUTF8() failed: %s\n", u_errorName(errorCode));
948 }
949
950 errorCode = U_ZERO_ERROR;
951 length = uidna_nameToASCII(uts46, NULL, 0,
952 dest16, 0, &info, &errorCode);
953 if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
954 length != 0 ||
955 info.isTransitionalDifferent || info.errors != UIDNA_ERROR_EMPTY_LABEL
956 ) {
957 log_err("uidna_nameToASCII(empty) failed: %s\n", u_errorName(errorCode));
958 }
959 errorCode = U_ZERO_ERROR;
960 length = uidna_nameToUnicode(uts46, fA_BEL, -1,
961 dest16, 3, &info, &errorCode);
962 if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
963 length != 3 || 0 != u_memcmp(dest16, fa_FFFD, 3) ||
964 info.isTransitionalDifferent || info.errors == 0
965 ) {
966 log_err("uidna_nameToUnicode(fa<BEL>) failed: %s\n", u_errorName(errorCode));
967 }
968
969 /* These calls should fail. */
970 errorCode = U_USELESS_COLLATOR_ERROR;
971 length = uidna_labelToASCII(uts46, fA_sharps16, -1,
972 dest16, UPRV_LENGTHOF(dest16), &info, &errorCode);
973 if(errorCode != U_USELESS_COLLATOR_ERROR) {
974 log_err("uidna_labelToASCII(failure) failed: %s\n", u_errorName(errorCode));
975 }
976 errorCode = U_ZERO_ERROR;
977 length = uidna_labelToUnicode(uts46, fA_sharps16, u_strlen(fA_sharps16),
978 dest16, UPRV_LENGTHOF(dest16), NULL, &errorCode);
979 if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
980 log_err("uidna_labelToUnicode(UIDNAInfo=NULL) failed: %s\n", u_errorName(errorCode));
981 }
982 errorCode = U_ZERO_ERROR;
983 length = uidna_nameToASCII(uts46, NULL, u_strlen(fA_sharps16),
984 dest16, 4, &info, &errorCode);
985 if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
986 log_err("uidna_nameToASCII(src=NULL) failed: %s\n", u_errorName(errorCode));
987 }
988 errorCode = U_ZERO_ERROR;
989 length = uidna_nameToUnicode(uts46, fA_sharps16, -2,
990 dest16, 3, &info, &errorCode);
991 if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
992 log_err("uidna_nameToUnicode(length<-1) failed: %s\n", u_errorName(errorCode));
993 }
994
995 errorCode = U_ZERO_ERROR;
996 length = uidna_labelToASCII_UTF8(uts46, fA_sharps8, -1,
997 NULL, UPRV_LENGTHOF(dest8), &info, &errorCode);
998 if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
999 log_err("uidna_labelToASCII_UTF8(dest=NULL) failed: %s\n", u_errorName(errorCode));
1000 }
1001 errorCode = U_ZERO_ERROR;
1002 length = uidna_labelToUnicodeUTF8(uts46, fA_sharps8, strlen(fA_sharps8),
1003 dest8, -1, &info, &errorCode);
1004 if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
1005 log_err("uidna_labelToUnicodeUTF8(capacity<0) failed: %s\n", u_errorName(errorCode));
1006 }
1007 errorCode = U_ZERO_ERROR;
1008 length = uidna_nameToASCII_UTF8(uts46, dest8, strlen(fA_sharps8),
1009 dest8, 4, &info, &errorCode);
1010 if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
1011 log_err("uidna_nameToASCII_UTF8(src==dest!=NULL) failed: %s\n", u_errorName(errorCode));
1012 }
1013 errorCode = U_ZERO_ERROR;
1014 length = uidna_nameToUnicodeUTF8(uts46, fA_sharps8, -1,
1015 dest8, 3, &info, &errorCode);
1016 if(errorCode != U_BUFFER_OVERFLOW_ERROR || length != 4) {
1017 log_err("uidna_nameToUnicodeUTF8() overflow failed: %s\n", u_errorName(errorCode));
1018 }
1019
1020 uidna_close(uts46);
1021 }
1022
1023 #endif
1024
1025 /*
1026 * Hey, Emacs, please set the following:
1027 *
1028 * Local Variables:
1029 * indent-tabs-mode: nil
1030 * End:
1031 *
1032 */
1033