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