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