2 *******************************************************************************
3 * Copyright (C) 2010-2014, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
6 * file name: uts46test.cpp
8 * tab size: 8 (not used)
11 * created on: 2010may05
12 * created by: Markus W. Scherer
15 #include "unicode/utypes.h"
20 #include "unicode/bytestream.h"
21 #include "unicode/idna.h"
22 #include "unicode/localpointer.h"
23 #include "unicode/std_string.h"
24 #include "unicode/stringpiece.h"
25 #include "unicode/uidna.h"
26 #include "unicode/unistr.h"
30 class UTS46Test
: public IntlTest
{
32 UTS46Test() : trans(NULL
), nontrans(NULL
) {}
35 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
=NULL
);
40 IDNA
*trans
, *nontrans
;
43 extern IntlTest
*createUTS46Test() {
44 return new UTS46Test();
47 UTS46Test::~UTS46Test() {
52 void UTS46Test::runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char * /*par*/) {
54 logln("TestSuite UTS46Test: ");
56 IcuTestErrorCode
errorCode(*this, "init/createUTS46Instance()");
57 uint32_t commonOptions
=
58 UIDNA_USE_STD3_RULES
|UIDNA_CHECK_BIDI
|
59 UIDNA_CHECK_CONTEXTJ
|UIDNA_CHECK_CONTEXTO
;
60 trans
=IDNA::createUTS46Instance(commonOptions
, errorCode
);
61 nontrans
=IDNA::createUTS46Instance(
63 UIDNA_NONTRANSITIONAL_TO_ASCII
|UIDNA_NONTRANSITIONAL_TO_UNICODE
,
65 if(errorCode
.logDataIfFailureAndReset("createUTS46Instance()")) {
72 TESTCASE_AUTO(TestAPI
);
73 TESTCASE_AUTO(TestNotSTD3
);
74 TESTCASE_AUTO(TestSomeCases
);
78 const uint32_t severeErrors
=
79 UIDNA_ERROR_LEADING_COMBINING_MARK
|
80 UIDNA_ERROR_DISALLOWED
|
82 UIDNA_ERROR_LABEL_HAS_DOT
|
83 UIDNA_ERROR_INVALID_ACE_LABEL
;
85 static UBool
isASCII(const UnicodeString
&str
) {
86 const UChar
*s
=str
.getBuffer();
87 int32_t length
=str
.length();
88 for(int32_t i
=0; i
<length
; ++i
) {
96 class TestCheckedArrayByteSink
: public CheckedArrayByteSink
{
98 TestCheckedArrayByteSink(char* outbuf
, int32_t capacity
)
99 : CheckedArrayByteSink(outbuf
, capacity
), calledFlush(FALSE
) {}
100 virtual CheckedArrayByteSink
& Reset() {
101 CheckedArrayByteSink::Reset();
105 virtual void Flush() { calledFlush
= TRUE
; }
109 void UTS46Test::TestAPI() {
110 UErrorCode errorCode
=U_ZERO_ERROR
;
111 UnicodeString result
;
113 UnicodeString input
=UNICODE_STRING_SIMPLE("www.eXample.cOm");
114 UnicodeString expected
=UNICODE_STRING_SIMPLE("www.example.com");
115 trans
->nameToASCII(input
, result
, info
, errorCode
);
116 if(U_FAILURE(errorCode
) || info
.hasErrors() || result
!=expected
) {
117 errln("T.nameToASCII(www.example.com) info.errors=%04lx result matches=%d %s",
118 (long)info
.getErrors(), result
==expected
, u_errorName(errorCode
));
120 errorCode
=U_USELESS_COLLATOR_ERROR
;
121 trans
->nameToUnicode(input
, result
, info
, errorCode
);
122 if(errorCode
!=U_USELESS_COLLATOR_ERROR
|| !result
.isBogus()) {
123 errln("T.nameToUnicode(U_FAILURE) did not preserve the errorCode "
124 "or not result.setToBogus() - %s",
125 u_errorName(errorCode
));
127 errorCode
=U_ZERO_ERROR
;
129 result
=UNICODE_STRING_SIMPLE("quatsch");
130 nontrans
->labelToASCII(input
, result
, info
, errorCode
);
131 if(errorCode
!=U_ILLEGAL_ARGUMENT_ERROR
|| !result
.isBogus()) {
132 errln("N.labelToASCII(bogus) did not set illegal-argument-error "
133 "or not result.setToBogus() - %s",
134 u_errorName(errorCode
));
136 errorCode
=U_ZERO_ERROR
;
137 input
=UNICODE_STRING_SIMPLE("xn--bcher.de-65a");
138 expected
=UNICODE_STRING_SIMPLE("xn--bcher\\uFFFDde-65a").unescape();
139 nontrans
->labelToASCII(input
, result
, info
, errorCode
);
140 if( U_FAILURE(errorCode
) ||
141 info
.getErrors()!=(UIDNA_ERROR_LABEL_HAS_DOT
|UIDNA_ERROR_INVALID_ACE_LABEL
) ||
144 errln("N.labelToASCII(label-with-dot) failed with errors %04lx - %s",
145 info
.getErrors(), u_errorName(errorCode
));
149 TestCheckedArrayByteSink
sink(buffer
, UPRV_LENGTHOF(buffer
));
150 errorCode
=U_ZERO_ERROR
;
151 nontrans
->labelToUnicodeUTF8(StringPiece(NULL
, 5), sink
, info
, errorCode
);
152 if(errorCode
!=U_ILLEGAL_ARGUMENT_ERROR
|| sink
.NumberOfBytesWritten()!=0) {
153 errln("N.labelToUnicodeUTF8(StringPiece(NULL, 5)) did not set illegal-argument-error ",
154 "or did output something - %s",
155 u_errorName(errorCode
));
159 errorCode
=U_ZERO_ERROR
;
160 nontrans
->nameToASCII_UTF8(StringPiece(), sink
, info
, errorCode
);
161 if(U_FAILURE(errorCode
) || sink
.NumberOfBytesWritten()!=0 || !sink
.calledFlush
) {
162 errln("N.nameToASCII_UTF8(empty) failed - %s",
163 u_errorName(errorCode
));
166 static const char s
[]={ 0x61, (char)0xc3, (char)0x9f };
168 errorCode
=U_USELESS_COLLATOR_ERROR
;
169 nontrans
->nameToUnicodeUTF8(StringPiece(s
, 3), sink
, info
, errorCode
);
170 if(errorCode
!=U_USELESS_COLLATOR_ERROR
|| sink
.NumberOfBytesWritten()!=0) {
171 errln("N.nameToUnicode_UTF8(U_FAILURE) did not preserve the errorCode "
172 "or did output something - %s",
173 u_errorName(errorCode
));
177 errorCode
=U_ZERO_ERROR
;
178 trans
->labelToUnicodeUTF8(StringPiece(s
, 3), sink
, info
, errorCode
);
179 if( U_FAILURE(errorCode
) || sink
.NumberOfBytesWritten()!=3 ||
180 buffer
[0]!=0x61 || buffer
[1]!=0x73 || buffer
[2]!=0x73 ||
183 errln("T.labelToUnicodeUTF8(a sharp-s) failed - %s",
184 u_errorName(errorCode
));
188 errorCode
=U_ZERO_ERROR
;
190 static const char eX
[]={ 0x65, 0x58, 0x61, 0x6d, 0x70, 0x4c, 0x65, 0x2e, 0x63, 0x4f, 0x6d, 0 };
192 static const char ex
[]={ 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d };
193 trans
->nameToUnicodeUTF8(eX
, sink
, info
, errorCode
);
194 if( U_FAILURE(errorCode
) || sink
.NumberOfBytesWritten()!=11 ||
195 0!=memcmp(ex
, buffer
, 11) || !sink
.calledFlush
197 errln("T.nameToUnicodeUTF8(eXampLe.cOm) failed - %s",
198 u_errorName(errorCode
));
202 void UTS46Test::TestNotSTD3() {
203 IcuTestErrorCode
errorCode(*this, "TestNotSTD3()");
205 LocalPointer
<IDNA
> not3(IDNA::createUTS46Instance(UIDNA_CHECK_BIDI
, errorCode
));
206 if(errorCode
.isFailure()) {
209 UnicodeString input
=UNICODE_STRING_SIMPLE("\\u0000A_2+2=4\\u000A.e\\u00DFen.net").unescape();
210 UnicodeString result
;
212 if( not3
->nameToUnicode(input
, result
, info
, errorCode
)!=
213 UNICODE_STRING_SIMPLE("\\u0000a_2+2=4\\u000A.essen.net").unescape() ||
216 prettify(result
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
217 errln("notSTD3.nameToUnicode(non-LDH ASCII) unexpected errors %04lx string %s",
218 (long)info
.getErrors(), buffer
);
220 // A space (BiDi class WS) is not allowed in a BiDi domain name.
221 input
=UNICODE_STRING_SIMPLE("a z.xn--4db.edu");
222 not3
->nameToASCII(input
, result
, info
, errorCode
);
223 if(result
!=input
|| info
.getErrors()!=UIDNA_ERROR_BIDI
) {
224 errln("notSTD3.nameToASCII(ASCII-with-space.alef.edu) failed");
226 // Characters that are canonically equivalent to sequences with non-LDH ASCII.
227 input
=UNICODE_STRING_SIMPLE("a\\u2260b\\u226Ec\\u226Fd").unescape();
228 not3
->nameToUnicode(input
, result
, info
, errorCode
);
229 if(result
!=input
|| info
.hasErrors()) {
230 prettify(result
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
231 errln("notSTD3.nameToUnicode(equiv to non-LDH ASCII) unexpected errors %04lx string %s",
232 (long)info
.getErrors(), buffer
);
237 // Input string and options string (Nontransitional/Transitional/Both).
239 // Expected Unicode result string.
244 static const TestCase testCases
[]={
245 { "www.eXample.cOm", "B", // all ASCII
246 "www.example.com", 0 },
247 { "B\\u00FCcher.de", "B", // u-umlaut
248 "b\\u00FCcher.de", 0 },
249 { "\\u00D6BB", "B", // O-umlaut
251 { "fa\\u00DF.de", "N", // sharp s
253 { "fa\\u00DF.de", "T", // sharp s
255 { "XN--fA-hia.dE", "B", // sharp s in Punycode
257 { "\\u03B2\\u03CC\\u03BB\\u03BF\\u03C2.com", "N", // Greek with final sigma
258 "\\u03B2\\u03CC\\u03BB\\u03BF\\u03C2.com", 0 },
259 { "\\u03B2\\u03CC\\u03BB\\u03BF\\u03C2.com", "T", // Greek with final sigma
260 "\\u03B2\\u03CC\\u03BB\\u03BF\\u03C3.com", 0 },
261 { "xn--nxasmm1c", "B", // Greek with final sigma in Punycode
262 "\\u03B2\\u03CC\\u03BB\\u03BF\\u03C2", 0 },
263 { "www.\\u0DC1\\u0DCA\\u200D\\u0DBB\\u0DD3.com", "N", // "Sri" in "Sri Lanka" has a ZWJ
264 "www.\\u0DC1\\u0DCA\\u200D\\u0DBB\\u0DD3.com", 0 },
265 { "www.\\u0DC1\\u0DCA\\u200D\\u0DBB\\u0DD3.com", "T", // "Sri" in "Sri Lanka" has a ZWJ
266 "www.\\u0DC1\\u0DCA\\u0DBB\\u0DD3.com", 0 },
267 { "www.xn--10cl1a0b660p.com", "B", // "Sri" in Punycode
268 "www.\\u0DC1\\u0DCA\\u200D\\u0DBB\\u0DD3.com", 0 },
269 { "\\u0646\\u0627\\u0645\\u0647\\u200C\\u0627\\u06CC", "N", // ZWNJ
270 "\\u0646\\u0627\\u0645\\u0647\\u200C\\u0627\\u06CC", 0 },
271 { "\\u0646\\u0627\\u0645\\u0647\\u200C\\u0627\\u06CC", "T", // ZWNJ
272 "\\u0646\\u0627\\u0645\\u0647\\u0627\\u06CC", 0 },
273 { "xn--mgba3gch31f060k.com", "B", // ZWNJ in Punycode
274 "\\u0646\\u0627\\u0645\\u0647\\u200C\\u0627\\u06CC.com", 0 },
275 { "a.b\\uFF0Ec\\u3002d\\uFF61", "B",
277 { "U\\u0308.xn--tda", "B", // U+umlaut.u-umlaut
278 "\\u00FC.\\u00FC", 0 },
279 { "xn--u-ccb", "B", // u+umlaut in Punycode
280 "xn--u-ccb\\uFFFD", UIDNA_ERROR_INVALID_ACE_LABEL
},
281 { "a\\u2488com", "B", // contains 1-dot
282 "a\\uFFFDcom", UIDNA_ERROR_DISALLOWED
},
283 { "xn--a-ecp.ru", "B", // contains 1-dot in Punycode
284 "xn--a-ecp\\uFFFD.ru", UIDNA_ERROR_INVALID_ACE_LABEL
},
285 { "xn--0.pt", "B", // invalid Punycode
286 "xn--0\\uFFFD.pt", UIDNA_ERROR_PUNYCODE
},
287 { "xn--a.pt", "B", // U+0080
288 "xn--a\\uFFFD.pt", UIDNA_ERROR_INVALID_ACE_LABEL
},
289 { "xn--a-\\u00C4.pt", "B", // invalid Punycode
290 "xn--a-\\u00E4.pt", UIDNA_ERROR_PUNYCODE
},
291 { "\\u65E5\\u672C\\u8A9E\\u3002\\uFF2A\\uFF30", "B", // Japanese with fullwidth ".jp"
292 "\\u65E5\\u672C\\u8A9E.jp", 0 },
293 { "\\u2615", "B", "\\u2615", 0 }, // Unicode 4.0 HOT BEVERAGE
294 // some characters are disallowed because they are canonically equivalent
295 // to sequences with non-LDH ASCII
296 { "a\\u2260b\\u226Ec\\u226Fd", "B",
297 "a\\uFFFDb\\uFFFDc\\uFFFDd", UIDNA_ERROR_DISALLOWED
},
298 // many deviation characters, test the special mapping code
299 { "1.a\\u00DF\\u200C\\u200Db\\u200C\\u200Dc\\u00DF\\u00DF\\u00DF\\u00DFd"
300 "\\u03C2\\u03C3\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFe"
301 "\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFx"
302 "\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFy"
303 "\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u0302\\u00DFz", "N",
304 "1.a\\u00DF\\u200C\\u200Db\\u200C\\u200Dc\\u00DF\\u00DF\\u00DF\\u00DFd"
305 "\\u03C2\\u03C3\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFe"
306 "\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFx"
307 "\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFy"
308 "\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u0302\\u00DFz",
309 UIDNA_ERROR_LABEL_TOO_LONG
|UIDNA_ERROR_CONTEXTJ
},
310 { "1.a\\u00DF\\u200C\\u200Db\\u200C\\u200Dc\\u00DF\\u00DF\\u00DF\\u00DFd"
311 "\\u03C2\\u03C3\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFe"
312 "\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFx"
313 "\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFy"
314 "\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u0302\\u00DFz", "T",
316 "\\u03C3\\u03C3sssssssssssssssse"
317 "ssssssssssssssssssssx"
318 "ssssssssssssssssssssy"
319 "sssssssssssssss\\u015Dssz", UIDNA_ERROR_LABEL_TOO_LONG
},
320 // "xn--bss" with deviation characters
321 { "\\u200Cx\\u200Dn\\u200C-\\u200D-b\\u00DF", "N",
322 "\\u200Cx\\u200Dn\\u200C-\\u200D-b\\u00DF", UIDNA_ERROR_CONTEXTJ
},
323 { "\\u200Cx\\u200Dn\\u200C-\\u200D-b\\u00DF", "T",
325 // "xn--bssffl" written as:
326 // 02E3 MODIFIER LETTER SMALL X
327 // 034F COMBINING GRAPHEME JOINER (ignored)
328 // 2115 DOUBLE-STRUCK CAPITAL N
329 // 200B ZERO WIDTH SPACE (ignored)
330 // FE63 SMALL HYPHEN-MINUS
331 // 00AD SOFT HYPHEN (ignored)
332 // FF0D FULLWIDTH HYPHEN-MINUS
333 // 180C MONGOLIAN FREE VARIATION SELECTOR TWO (ignored)
334 // 212C SCRIPT CAPITAL B
335 // FE00 VARIATION SELECTOR-1 (ignored)
336 // 017F LATIN SMALL LETTER LONG S
337 // 2064 INVISIBLE PLUS (ignored)
338 // 1D530 MATHEMATICAL FRAKTUR SMALL S
339 // E01EF VARIATION SELECTOR-256 (ignored)
340 // FB04 LATIN SMALL LIGATURE FFL
341 { "\\u02E3\\u034F\\u2115\\u200B\\uFE63\\u00AD\\uFF0D\\u180C"
342 "\\u212C\\uFE00\\u017F\\u2064\\U0001D530\\U000E01EF\\uFB04", "B",
343 "\\u5921\\u591E\\u591C\\u5919", 0 },
344 { "123456789012345678901234567890123456789012345678901234567890123."
345 "123456789012345678901234567890123456789012345678901234567890123."
346 "123456789012345678901234567890123456789012345678901234567890123."
347 "1234567890123456789012345678901234567890123456789012345678901", "B",
348 "123456789012345678901234567890123456789012345678901234567890123."
349 "123456789012345678901234567890123456789012345678901234567890123."
350 "123456789012345678901234567890123456789012345678901234567890123."
351 "1234567890123456789012345678901234567890123456789012345678901", 0 },
352 { "123456789012345678901234567890123456789012345678901234567890123."
353 "123456789012345678901234567890123456789012345678901234567890123."
354 "123456789012345678901234567890123456789012345678901234567890123."
355 "1234567890123456789012345678901234567890123456789012345678901.", "B",
356 "123456789012345678901234567890123456789012345678901234567890123."
357 "123456789012345678901234567890123456789012345678901234567890123."
358 "123456789012345678901234567890123456789012345678901234567890123."
359 "1234567890123456789012345678901234567890123456789012345678901.", 0 },
360 // Domain name >256 characters, forces slow path in UTF-8 processing.
361 { "123456789012345678901234567890123456789012345678901234567890123."
362 "123456789012345678901234567890123456789012345678901234567890123."
363 "123456789012345678901234567890123456789012345678901234567890123."
364 "123456789012345678901234567890123456789012345678901234567890123."
365 "12345678901234567890123456789012345678901234567890123456789012", "B",
366 "123456789012345678901234567890123456789012345678901234567890123."
367 "123456789012345678901234567890123456789012345678901234567890123."
368 "123456789012345678901234567890123456789012345678901234567890123."
369 "123456789012345678901234567890123456789012345678901234567890123."
370 "12345678901234567890123456789012345678901234567890123456789012",
371 UIDNA_ERROR_DOMAIN_NAME_TOO_LONG
},
372 { "123456789012345678901234567890123456789012345678901234567890123."
373 "123456789012345678901234567890123456789012345678901234567890123."
374 "123456789012345678901234567890123456789012345678901234567890123."
375 "123456789012345678901234567890123456789012345678901234567890123."
376 "1234567890123456789012345678901234567890123456789\\u05D0", "B",
377 "123456789012345678901234567890123456789012345678901234567890123."
378 "123456789012345678901234567890123456789012345678901234567890123."
379 "123456789012345678901234567890123456789012345678901234567890123."
380 "123456789012345678901234567890123456789012345678901234567890123."
381 "1234567890123456789012345678901234567890123456789\\u05D0",
382 UIDNA_ERROR_DOMAIN_NAME_TOO_LONG
|UIDNA_ERROR_BIDI
},
383 { "123456789012345678901234567890123456789012345678901234567890123."
384 "1234567890123456789012345678901234567890123456789012345678901234."
385 "123456789012345678901234567890123456789012345678901234567890123."
386 "123456789012345678901234567890123456789012345678901234567890", "B",
387 "123456789012345678901234567890123456789012345678901234567890123."
388 "1234567890123456789012345678901234567890123456789012345678901234."
389 "123456789012345678901234567890123456789012345678901234567890123."
390 "123456789012345678901234567890123456789012345678901234567890",
391 UIDNA_ERROR_LABEL_TOO_LONG
},
392 { "123456789012345678901234567890123456789012345678901234567890123."
393 "1234567890123456789012345678901234567890123456789012345678901234."
394 "123456789012345678901234567890123456789012345678901234567890123."
395 "123456789012345678901234567890123456789012345678901234567890.", "B",
396 "123456789012345678901234567890123456789012345678901234567890123."
397 "1234567890123456789012345678901234567890123456789012345678901234."
398 "123456789012345678901234567890123456789012345678901234567890123."
399 "123456789012345678901234567890123456789012345678901234567890.",
400 UIDNA_ERROR_LABEL_TOO_LONG
},
401 { "123456789012345678901234567890123456789012345678901234567890123."
402 "1234567890123456789012345678901234567890123456789012345678901234."
403 "123456789012345678901234567890123456789012345678901234567890123."
404 "1234567890123456789012345678901234567890123456789012345678901", "B",
405 "123456789012345678901234567890123456789012345678901234567890123."
406 "1234567890123456789012345678901234567890123456789012345678901234."
407 "123456789012345678901234567890123456789012345678901234567890123."
408 "1234567890123456789012345678901234567890123456789012345678901",
409 UIDNA_ERROR_LABEL_TOO_LONG
|UIDNA_ERROR_DOMAIN_NAME_TOO_LONG
},
410 // label length 63: xn--1234567890123456789012345678901234567890123456789012345-9te
411 { "\\u00E41234567890123456789012345678901234567890123456789012345", "B",
412 "\\u00E41234567890123456789012345678901234567890123456789012345", 0 },
413 { "1234567890\\u00E41234567890123456789012345678901234567890123456", "B",
414 "1234567890\\u00E41234567890123456789012345678901234567890123456", UIDNA_ERROR_LABEL_TOO_LONG
},
415 { "123456789012345678901234567890123456789012345678901234567890123."
416 "1234567890\\u00E4123456789012345678901234567890123456789012345."
417 "123456789012345678901234567890123456789012345678901234567890123."
418 "1234567890123456789012345678901234567890123456789012345678901", "B",
419 "123456789012345678901234567890123456789012345678901234567890123."
420 "1234567890\\u00E4123456789012345678901234567890123456789012345."
421 "123456789012345678901234567890123456789012345678901234567890123."
422 "1234567890123456789012345678901234567890123456789012345678901", 0 },
423 { "123456789012345678901234567890123456789012345678901234567890123."
424 "1234567890\\u00E4123456789012345678901234567890123456789012345."
425 "123456789012345678901234567890123456789012345678901234567890123."
426 "1234567890123456789012345678901234567890123456789012345678901.", "B",
427 "123456789012345678901234567890123456789012345678901234567890123."
428 "1234567890\\u00E4123456789012345678901234567890123456789012345."
429 "123456789012345678901234567890123456789012345678901234567890123."
430 "1234567890123456789012345678901234567890123456789012345678901.", 0 },
431 { "123456789012345678901234567890123456789012345678901234567890123."
432 "1234567890\\u00E4123456789012345678901234567890123456789012345."
433 "123456789012345678901234567890123456789012345678901234567890123."
434 "12345678901234567890123456789012345678901234567890123456789012", "B",
435 "123456789012345678901234567890123456789012345678901234567890123."
436 "1234567890\\u00E4123456789012345678901234567890123456789012345."
437 "123456789012345678901234567890123456789012345678901234567890123."
438 "12345678901234567890123456789012345678901234567890123456789012",
439 UIDNA_ERROR_DOMAIN_NAME_TOO_LONG
},
440 { "123456789012345678901234567890123456789012345678901234567890123."
441 "1234567890\\u00E41234567890123456789012345678901234567890123456."
442 "123456789012345678901234567890123456789012345678901234567890123."
443 "123456789012345678901234567890123456789012345678901234567890", "B",
444 "123456789012345678901234567890123456789012345678901234567890123."
445 "1234567890\\u00E41234567890123456789012345678901234567890123456."
446 "123456789012345678901234567890123456789012345678901234567890123."
447 "123456789012345678901234567890123456789012345678901234567890",
448 UIDNA_ERROR_LABEL_TOO_LONG
},
449 { "123456789012345678901234567890123456789012345678901234567890123."
450 "1234567890\\u00E41234567890123456789012345678901234567890123456."
451 "123456789012345678901234567890123456789012345678901234567890123."
452 "123456789012345678901234567890123456789012345678901234567890.", "B",
453 "123456789012345678901234567890123456789012345678901234567890123."
454 "1234567890\\u00E41234567890123456789012345678901234567890123456."
455 "123456789012345678901234567890123456789012345678901234567890123."
456 "123456789012345678901234567890123456789012345678901234567890.",
457 UIDNA_ERROR_LABEL_TOO_LONG
},
458 { "123456789012345678901234567890123456789012345678901234567890123."
459 "1234567890\\u00E41234567890123456789012345678901234567890123456."
460 "123456789012345678901234567890123456789012345678901234567890123."
461 "1234567890123456789012345678901234567890123456789012345678901", "B",
462 "123456789012345678901234567890123456789012345678901234567890123."
463 "1234567890\\u00E41234567890123456789012345678901234567890123456."
464 "123456789012345678901234567890123456789012345678901234567890123."
465 "1234567890123456789012345678901234567890123456789012345678901",
466 UIDNA_ERROR_LABEL_TOO_LONG
|UIDNA_ERROR_DOMAIN_NAME_TOO_LONG
},
467 // hyphen errors and empty-label errors
468 // Ticket #10883: ToUnicode also checks for empty labels.
469 { ".", "B", ".", UIDNA_ERROR_EMPTY_LABEL
},
470 { "\\uFF0E", "B", ".", UIDNA_ERROR_EMPTY_LABEL
},
471 // "xn---q----jra"=="-q--a-umlaut-"
472 { "a.b..-q--a-.e", "B", "a.b..-q--a-.e",
473 UIDNA_ERROR_EMPTY_LABEL
|UIDNA_ERROR_LEADING_HYPHEN
|UIDNA_ERROR_TRAILING_HYPHEN
|
474 UIDNA_ERROR_HYPHEN_3_4
},
475 { "a.b..-q--\\u00E4-.e", "B", "a.b..-q--\\u00E4-.e",
476 UIDNA_ERROR_EMPTY_LABEL
|UIDNA_ERROR_LEADING_HYPHEN
|UIDNA_ERROR_TRAILING_HYPHEN
|
477 UIDNA_ERROR_HYPHEN_3_4
},
478 { "a.b..xn---q----jra.e", "B", "a.b..-q--\\u00E4-.e",
479 UIDNA_ERROR_EMPTY_LABEL
|UIDNA_ERROR_LEADING_HYPHEN
|UIDNA_ERROR_TRAILING_HYPHEN
|
480 UIDNA_ERROR_HYPHEN_3_4
},
481 { "a..c", "B", "a..c", UIDNA_ERROR_EMPTY_LABEL
},
482 { "a.xn--.c", "B", "a..c", UIDNA_ERROR_EMPTY_LABEL
},
483 { "a.-b.", "B", "a.-b.", UIDNA_ERROR_LEADING_HYPHEN
},
484 { "a.b-.c", "B", "a.b-.c", UIDNA_ERROR_TRAILING_HYPHEN
},
485 { "a.-.c", "B", "a.-.c", UIDNA_ERROR_LEADING_HYPHEN
|UIDNA_ERROR_TRAILING_HYPHEN
},
486 { "a.bc--de.f", "B", "a.bc--de.f", UIDNA_ERROR_HYPHEN_3_4
},
487 { "\\u00E4.\\u00AD.c", "B", "\\u00E4..c", UIDNA_ERROR_EMPTY_LABEL
},
488 { "\\u00E4.xn--.c", "B", "\\u00E4..c", UIDNA_ERROR_EMPTY_LABEL
},
489 { "\\u00E4.-b.", "B", "\\u00E4.-b.", UIDNA_ERROR_LEADING_HYPHEN
},
490 { "\\u00E4.b-.c", "B", "\\u00E4.b-.c", UIDNA_ERROR_TRAILING_HYPHEN
},
491 { "\\u00E4.-.c", "B", "\\u00E4.-.c", UIDNA_ERROR_LEADING_HYPHEN
|UIDNA_ERROR_TRAILING_HYPHEN
},
492 { "\\u00E4.bc--de.f", "B", "\\u00E4.bc--de.f", UIDNA_ERROR_HYPHEN_3_4
},
493 { "a.b.\\u0308c.d", "B", "a.b.\\uFFFDc.d", UIDNA_ERROR_LEADING_COMBINING_MARK
},
494 { "a.b.xn--c-bcb.d", "B",
495 "a.b.xn--c-bcb\\uFFFD.d", UIDNA_ERROR_LEADING_COMBINING_MARK
|UIDNA_ERROR_INVALID_ACE_LABEL
},
497 { "A0", "B", "a0", 0 },
498 { "0A", "B", "0a", 0 }, // all-LTR is ok to start with a digit (EN)
499 { "0A.\\u05D0", "B", // ASCII label does not start with L/R/AL
500 "0a.\\u05D0", UIDNA_ERROR_BIDI
},
501 { "c.xn--0-eha.xn--4db", "B", // 2nd label does not start with L/R/AL
502 "c.0\\u00FC.\\u05D0", UIDNA_ERROR_BIDI
},
503 { "b-.\\u05D0", "B", // label does not end with L/EN
504 "b-.\\u05D0", UIDNA_ERROR_TRAILING_HYPHEN
|UIDNA_ERROR_BIDI
},
505 { "d.xn----dha.xn--4db", "B", // 2nd label does not end with L/EN
506 "d.\\u00FC-.\\u05D0", UIDNA_ERROR_TRAILING_HYPHEN
|UIDNA_ERROR_BIDI
},
507 { "a\\u05D0", "B", "a\\u05D0", UIDNA_ERROR_BIDI
}, // first dir != last dir
508 { "\\u05D0\\u05C7", "B", "\\u05D0\\u05C7", 0 },
509 { "\\u05D09\\u05C7", "B", "\\u05D09\\u05C7", 0 },
510 { "\\u05D0a\\u05C7", "B", "\\u05D0a\\u05C7", UIDNA_ERROR_BIDI
}, // first dir != last dir
511 { "\\u05D0\\u05EA", "B", "\\u05D0\\u05EA", 0 },
512 { "\\u05D0\\u05F3\\u05EA", "B", "\\u05D0\\u05F3\\u05EA", 0 },
513 { "a\\u05D0Tz", "B", "a\\u05D0tz", UIDNA_ERROR_BIDI
}, // mixed dir
514 { "\\u05D0T\\u05EA", "B", "\\u05D0t\\u05EA", UIDNA_ERROR_BIDI
}, // mixed dir
515 { "\\u05D07\\u05EA", "B", "\\u05D07\\u05EA", 0 },
516 { "\\u05D0\\u0667\\u05EA", "B", "\\u05D0\\u0667\\u05EA", 0 }, // Arabic 7 in the middle
517 { "a7\\u0667z", "B", "a7\\u0667z", UIDNA_ERROR_BIDI
}, // AN digit in LTR
518 { "\\u05D07\\u0667\\u05EA", "B", // mixed EN/AN digits in RTL
519 "\\u05D07\\u0667\\u05EA", UIDNA_ERROR_BIDI
},
521 { "\\u0BB9\\u0BCD\\u200D", "N", "\\u0BB9\\u0BCD\\u200D", 0 }, // Virama+ZWJ
522 { "\\u0BB9\\u200D", "N", "\\u0BB9\\u200D", UIDNA_ERROR_CONTEXTJ
}, // no Virama
523 { "\\u200D", "N", "\\u200D", UIDNA_ERROR_CONTEXTJ
}, // no Virama
525 { "\\u0BB9\\u0BCD\\u200C", "N", "\\u0BB9\\u0BCD\\u200C", 0 }, // Virama+ZWNJ
526 { "\\u0BB9\\u200C", "N", "\\u0BB9\\u200C", UIDNA_ERROR_CONTEXTJ
}, // no Virama
527 { "\\u200C", "N", "\\u200C", UIDNA_ERROR_CONTEXTJ
}, // no Virama
528 { "\\u0644\\u0670\\u200C\\u06ED\\u06EF", "N", // Joining types D T ZWNJ T R
529 "\\u0644\\u0670\\u200C\\u06ED\\u06EF", 0 },
530 { "\\u0644\\u0670\\u200C\\u06EF", "N", // D T ZWNJ R
531 "\\u0644\\u0670\\u200C\\u06EF", 0 },
532 { "\\u0644\\u200C\\u06ED\\u06EF", "N", // D ZWNJ T R
533 "\\u0644\\u200C\\u06ED\\u06EF", 0 },
534 { "\\u0644\\u200C\\u06EF", "N", // D ZWNJ R
535 "\\u0644\\u200C\\u06EF", 0 },
536 { "\\u0644\\u0670\\u200C\\u06ED", "N", // D T ZWNJ T
537 "\\u0644\\u0670\\u200C\\u06ED", UIDNA_ERROR_BIDI
|UIDNA_ERROR_CONTEXTJ
},
538 { "\\u06EF\\u200C\\u06EF", "N", // R ZWNJ R
539 "\\u06EF\\u200C\\u06EF", UIDNA_ERROR_CONTEXTJ
},
540 { "\\u0644\\u200C", "N", // D ZWNJ
541 "\\u0644\\u200C", UIDNA_ERROR_BIDI
|UIDNA_ERROR_CONTEXTJ
},
542 { "\\u0660\\u0661", "B", // Arabic-Indic Digits alone
543 "\\u0660\\u0661", UIDNA_ERROR_BIDI
},
544 { "\\u06F0\\u06F1", "B", // Extended Arabic-Indic Digits alone
545 "\\u06F0\\u06F1", 0 },
546 { "\\u0660\\u06F1", "B", // Mixed Arabic-Indic Digits
547 "\\u0660\\u06F1", UIDNA_ERROR_CONTEXTO_DIGITS
|UIDNA_ERROR_BIDI
},
548 // All of the CONTEXTO "Would otherwise have been DISALLOWED" characters
549 // in their correct contexts,
550 // then each in incorrect context.
551 { "l\\u00B7l\\u4E00\\u0375\\u03B1\\u05D0\\u05F3\\u05F4\\u30FB", "B",
552 "l\\u00B7l\\u4E00\\u0375\\u03B1\\u05D0\\u05F3\\u05F4\\u30FB", UIDNA_ERROR_BIDI
},
554 "l\\u00B7", UIDNA_ERROR_CONTEXTO_PUNCTUATION
},
556 "\\u00B7l", UIDNA_ERROR_CONTEXTO_PUNCTUATION
},
558 "\\u0375", UIDNA_ERROR_CONTEXTO_PUNCTUATION
},
559 { "\\u03B1\\u05F3", "B",
560 "\\u03B1\\u05F3", UIDNA_ERROR_CONTEXTO_PUNCTUATION
|UIDNA_ERROR_BIDI
},
562 "\\u05F4", UIDNA_ERROR_CONTEXTO_PUNCTUATION
},
564 "l\\u30FB", UIDNA_ERROR_CONTEXTO_PUNCTUATION
},
565 // Ticket #8137: UTS #46 toUnicode() fails with non-ASCII labels that turn
566 // into 15 characters (UChars).
567 // The bug was in u_strFromPunycode() which did not write the last character
568 // if it just so fit into the end of the destination buffer.
569 // The UTS #46 code gives a default-capacity UnicodeString as the destination buffer,
570 // and the internal UnicodeString capacity is currently 15 UChars on 64-bit machines
571 // but 13 on 32-bit machines.
572 // Label with 15 UChars, for 64-bit-machine testing:
573 { "aaaaaaaaaaaaa\\u00FCa.de", "B", "aaaaaaaaaaaaa\\u00FCa.de", 0 },
574 { "xn--aaaaaaaaaaaaaa-ssb.de", "B", "aaaaaaaaaaaaa\\u00FCa.de", 0 },
575 { "abschlu\\u00DFpr\\u00FCfung.de", "N", "abschlu\\u00DFpr\\u00FCfung.de", 0 },
576 { "xn--abschluprfung-hdb15b.de", "B", "abschlu\\u00DFpr\\u00FCfung.de", 0 },
577 // Label with 13 UChars, for 32-bit-machine testing:
578 { "xn--aaaaaaaaaaaa-nlb.de", "B", "aaaaaaaaaaa\\u00FCa.de", 0 },
579 { "xn--schluprfung-z6a39a.de", "B", "schlu\\u00DFpr\\u00FCfung.de", 0 },
584 void UTS46Test::TestSomeCases() {
585 IcuTestErrorCode
errorCode(*this, "TestSomeCases");
586 char buffer
[400], buffer2
[400];
588 for(i
=0; i
<UPRV_LENGTHOF(testCases
); ++i
) {
589 const TestCase
&testCase
=testCases
[i
];
590 UnicodeString
input(ctou(testCase
.s
));
591 UnicodeString
expected(ctou(testCase
.u
));
592 // ToASCII/ToUnicode, transitional/nontransitional
593 UnicodeString aT
, uT
, aN
, uN
;
594 IDNAInfo aTInfo
, uTInfo
, aNInfo
, uNInfo
;
595 trans
->nameToASCII(input
, aT
, aTInfo
, errorCode
);
596 trans
->nameToUnicode(input
, uT
, uTInfo
, errorCode
);
597 nontrans
->nameToASCII(input
, aN
, aNInfo
, errorCode
);
598 nontrans
->nameToUnicode(input
, uN
, uNInfo
, errorCode
);
599 if(errorCode
.logIfFailureAndReset("first-level processing [%d/%s] %s",
600 (int)i
, testCase
.o
, testCase
.s
)
604 // ToUnicode does not set length-overflow errors.
605 uint32_t uniErrors
=testCase
.errors
&~
606 (UIDNA_ERROR_LABEL_TOO_LONG
|
607 UIDNA_ERROR_DOMAIN_NAME_TOO_LONG
);
608 char mode
=testCase
.o
[0];
609 if(mode
=='B' || mode
=='N') {
610 if(uNInfo
.getErrors()!=uniErrors
) {
611 errln("N.nameToUnicode([%d] %s) unexpected errors %04lx",
612 (int)i
, testCase
.s
, (long)uNInfo
.getErrors());
616 prettify(uN
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
617 errln("N.nameToUnicode([%d] %s) unexpected string %s",
618 (int)i
, testCase
.s
, buffer
);
621 if(aNInfo
.getErrors()!=testCase
.errors
) {
622 errln("N.nameToASCII([%d] %s) unexpected errors %04lx",
623 (int)i
, testCase
.s
, (long)aNInfo
.getErrors());
627 if(mode
=='B' || mode
=='T') {
628 if(uTInfo
.getErrors()!=uniErrors
) {
629 errln("T.nameToUnicode([%d] %s) unexpected errors %04lx",
630 (int)i
, testCase
.s
, (long)uTInfo
.getErrors());
634 prettify(uT
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
635 errln("T.nameToUnicode([%d] %s) unexpected string %s",
636 (int)i
, testCase
.s
, buffer
);
639 if(aTInfo
.getErrors()!=testCase
.errors
) {
640 errln("T.nameToASCII([%d] %s) unexpected errors %04lx",
641 (int)i
, testCase
.s
, (long)aTInfo
.getErrors());
645 // ToASCII is all-ASCII if no severe errors
646 if((aNInfo
.getErrors()&severeErrors
)==0 && !isASCII(aN
)) {
647 prettify(aN
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
648 errln("N.nameToASCII([%d] %s) (errors %04lx) result is not ASCII %s",
649 (int)i
, testCase
.s
, aNInfo
.getErrors(), buffer
);
652 if((aTInfo
.getErrors()&severeErrors
)==0 && !isASCII(aT
)) {
653 prettify(aT
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
654 errln("T.nameToASCII([%d] %s) (errors %04lx) result is not ASCII %s",
655 (int)i
, testCase
.s
, aTInfo
.getErrors(), buffer
);
659 char m
= mode
=='B' ? mode
: 'N';
660 prettify(aN
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
661 logln("%c.nameToASCII([%d] %s) (errors %04lx) result string: %s",
662 m
, (int)i
, testCase
.s
, aNInfo
.getErrors(), buffer
);
664 prettify(aT
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
665 logln("T.nameToASCII([%d] %s) (errors %04lx) result string: %s",
666 (int)i
, testCase
.s
, aTInfo
.getErrors(), buffer
);
669 // second-level processing
670 UnicodeString aTuN
, uTaN
, aNuN
, uNaN
;
671 IDNAInfo aTuNInfo
, uTaNInfo
, aNuNInfo
, uNaNInfo
;
672 nontrans
->nameToUnicode(aT
, aTuN
, aTuNInfo
, errorCode
);
673 nontrans
->nameToASCII(uT
, uTaN
, uTaNInfo
, errorCode
);
674 nontrans
->nameToUnicode(aN
, aNuN
, aNuNInfo
, errorCode
);
675 nontrans
->nameToASCII(uN
, uNaN
, uNaNInfo
, errorCode
);
676 if(errorCode
.logIfFailureAndReset("second-level processing [%d/%s] %s",
677 (int)i
, testCase
.o
, testCase
.s
)
682 prettify(aN
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
683 prettify(uNaN
).extract(0, 0x7fffffff, buffer2
, UPRV_LENGTHOF(buffer2
));
684 errln("N.nameToASCII([%d] %s)!=N.nameToUnicode().N.nameToASCII() "
685 "(errors %04lx) %s vs. %s",
686 (int)i
, testCase
.s
, aNInfo
.getErrors(), buffer
, buffer2
);
690 prettify(aT
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
691 prettify(uTaN
).extract(0, 0x7fffffff, buffer2
, UPRV_LENGTHOF(buffer2
));
692 errln("T.nameToASCII([%d] %s)!=T.nameToUnicode().N.nameToASCII() "
693 "(errors %04lx) %s vs. %s",
694 (int)i
, testCase
.s
, aNInfo
.getErrors(), buffer
, buffer2
);
698 prettify(uN
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
699 prettify(aNuN
).extract(0, 0x7fffffff, buffer2
, UPRV_LENGTHOF(buffer2
));
700 errln("N.nameToUnicode([%d] %s)!=N.nameToASCII().N.nameToUnicode() "
701 "(errors %04lx) %s vs. %s",
702 (int)i
, testCase
.s
, uNInfo
.getErrors(), buffer
, buffer2
);
706 prettify(uT
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
707 prettify(aTuN
).extract(0, 0x7fffffff, buffer2
, UPRV_LENGTHOF(buffer2
));
708 errln("T.nameToUnicode([%d] %s)!=T.nameToASCII().N.nameToUnicode() "
709 "(errors %04lx) %s vs. %s",
710 (int)i
, testCase
.s
, uNInfo
.getErrors(), buffer
, buffer2
);
714 UnicodeString aTL
, uTL
, aNL
, uNL
;
715 IDNAInfo aTLInfo
, uTLInfo
, aNLInfo
, uNLInfo
;
716 trans
->labelToASCII(input
, aTL
, aTLInfo
, errorCode
);
717 trans
->labelToUnicode(input
, uTL
, uTLInfo
, errorCode
);
718 nontrans
->labelToASCII(input
, aNL
, aNLInfo
, errorCode
);
719 nontrans
->labelToUnicode(input
, uNL
, uNLInfo
, errorCode
);
720 if(errorCode
.logIfFailureAndReset("labelToXYZ processing [%d/%s] %s",
721 (int)i
, testCase
.o
, testCase
.s
)
725 if(aN
.indexOf((UChar
)0x2e)<0) {
726 if(aN
!=aNL
|| aNInfo
.getErrors()!=aNLInfo
.getErrors()) {
727 prettify(aN
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
728 prettify(aNL
).extract(0, 0x7fffffff, buffer2
, UPRV_LENGTHOF(buffer2
));
729 errln("N.nameToASCII([%d] %s)!=N.labelToASCII() "
730 "(errors %04lx vs %04lx) %s vs. %s",
731 (int)i
, testCase
.s
, aNInfo
.getErrors(), aNLInfo
.getErrors(), buffer
, buffer2
);
735 if((aNLInfo
.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT
)==0) {
736 errln("N.labelToASCII([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
737 (int)i
, testCase
.s
, (long)aNLInfo
.getErrors());
741 if(aT
.indexOf((UChar
)0x2e)<0) {
742 if(aT
!=aTL
|| aTInfo
.getErrors()!=aTLInfo
.getErrors()) {
743 prettify(aT
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
744 prettify(aTL
).extract(0, 0x7fffffff, buffer2
, UPRV_LENGTHOF(buffer2
));
745 errln("T.nameToASCII([%d] %s)!=T.labelToASCII() "
746 "(errors %04lx vs %04lx) %s vs. %s",
747 (int)i
, testCase
.s
, aTInfo
.getErrors(), aTLInfo
.getErrors(), buffer
, buffer2
);
751 if((aTLInfo
.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT
)==0) {
752 errln("T.labelToASCII([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
753 (int)i
, testCase
.s
, (long)aTLInfo
.getErrors());
757 if(uN
.indexOf((UChar
)0x2e)<0) {
758 if(uN
!=uNL
|| uNInfo
.getErrors()!=uNLInfo
.getErrors()) {
759 prettify(uN
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
760 prettify(uNL
).extract(0, 0x7fffffff, buffer2
, UPRV_LENGTHOF(buffer2
));
761 errln("N.nameToUnicode([%d] %s)!=N.labelToUnicode() "
762 "(errors %04lx vs %04lx) %s vs. %s",
763 (int)i
, testCase
.s
, uNInfo
.getErrors(), uNLInfo
.getErrors(), buffer
, buffer2
);
767 if((uNLInfo
.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT
)==0) {
768 errln("N.labelToUnicode([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
769 (int)i
, testCase
.s
, (long)uNLInfo
.getErrors());
773 if(uT
.indexOf((UChar
)0x2e)<0) {
774 if(uT
!=uTL
|| uTInfo
.getErrors()!=uTLInfo
.getErrors()) {
775 prettify(uT
).extract(0, 0x7fffffff, buffer
, UPRV_LENGTHOF(buffer
));
776 prettify(uTL
).extract(0, 0x7fffffff, buffer2
, UPRV_LENGTHOF(buffer2
));
777 errln("T.nameToUnicode([%d] %s)!=T.labelToUnicode() "
778 "(errors %04lx vs %04lx) %s vs. %s",
779 (int)i
, testCase
.s
, uTInfo
.getErrors(), uTLInfo
.getErrors(), buffer
, buffer2
);
783 if((uTLInfo
.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT
)==0) {
784 errln("T.labelToUnicode([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
785 (int)i
, testCase
.s
, (long)uTLInfo
.getErrors());
789 // Differences between transitional and nontransitional processing
791 if( aNInfo
.isTransitionalDifferent() ||
792 aTInfo
.isTransitionalDifferent() ||
793 uNInfo
.isTransitionalDifferent() ||
794 uTInfo
.isTransitionalDifferent() ||
795 aNLInfo
.isTransitionalDifferent() ||
796 aTLInfo
.isTransitionalDifferent() ||
797 uNLInfo
.isTransitionalDifferent() ||
798 uTLInfo
.isTransitionalDifferent()
800 errln("B.process([%d] %s) isTransitionalDifferent()", (int)i
, testCase
.s
);
803 if( aN
!=aT
|| uN
!=uT
|| aNL
!=aTL
|| uNL
!=uTL
||
804 aNInfo
.getErrors()!=aTInfo
.getErrors() || uNInfo
.getErrors()!=uTInfo
.getErrors() ||
805 aNLInfo
.getErrors()!=aTLInfo
.getErrors() || uNLInfo
.getErrors()!=uTLInfo
.getErrors()
807 errln("N.process([%d] %s) vs. T.process() different errors or result strings",
812 if( !aNInfo
.isTransitionalDifferent() ||
813 !aTInfo
.isTransitionalDifferent() ||
814 !uNInfo
.isTransitionalDifferent() ||
815 !uTInfo
.isTransitionalDifferent() ||
816 !aNLInfo
.isTransitionalDifferent() ||
817 !aTLInfo
.isTransitionalDifferent() ||
818 !uNLInfo
.isTransitionalDifferent() ||
819 !uTLInfo
.isTransitionalDifferent()
821 errln("%s.process([%d] %s) !isTransitionalDifferent()",
822 testCase
.o
, (int)i
, testCase
.s
);
825 if(aN
==aT
|| uN
==uT
|| aNL
==aTL
|| uNL
==uTL
) {
826 errln("N.process([%d] %s) vs. T.process() same result strings",
831 // UTF-8 if we have std::string
832 #if U_HAVE_STD_STRING
833 std::string input8
, aT8
, uT8
, aN8
, uN8
;
834 StringByteSink
<std::string
> aT8Sink(&aT8
), uT8Sink(&uT8
), aN8Sink(&aN8
), uN8Sink(&uN8
);
835 IDNAInfo aT8Info
, uT8Info
, aN8Info
, uN8Info
;
836 input
.toUTF8String(input8
);
837 trans
->nameToASCII_UTF8(input8
, aT8Sink
, aT8Info
, errorCode
);
838 trans
->nameToUnicodeUTF8(input8
, uT8Sink
, uT8Info
, errorCode
);
839 nontrans
->nameToASCII_UTF8(input8
, aN8Sink
, aN8Info
, errorCode
);
840 nontrans
->nameToUnicodeUTF8(input8
, uN8Sink
, uN8Info
, errorCode
);
841 if(errorCode
.logIfFailureAndReset("UTF-8 processing [%d/%s] %s",
842 (int)i
, testCase
.o
, testCase
.s
)
846 UnicodeString
aT16(UnicodeString::fromUTF8(aT8
));
847 UnicodeString
uT16(UnicodeString::fromUTF8(uT8
));
848 UnicodeString
aN16(UnicodeString::fromUTF8(aN8
));
849 UnicodeString
uN16(UnicodeString::fromUTF8(uN8
));
850 if( aN8Info
.getErrors()!=aNInfo
.getErrors() ||
851 uN8Info
.getErrors()!=uNInfo
.getErrors()
853 errln("N.xyzUTF8([%d] %s) vs. UTF-16 processing different errors %04lx vs. %04lx",
855 (long)aN8Info
.getErrors(), (long)aNInfo
.getErrors());
858 if( aT8Info
.getErrors()!=aTInfo
.getErrors() ||
859 uT8Info
.getErrors()!=uTInfo
.getErrors()
861 errln("T.xyzUTF8([%d] %s) vs. UTF-16 processing different errors %04lx vs. %04lx",
863 (long)aT8Info
.getErrors(), (long)aTInfo
.getErrors());
866 if(aT16
!=aT
|| uT16
!=uT
|| aN16
!=aN
|| uN16
!=uN
) {
867 errln("%s.xyzUTF8([%d] %s) vs. UTF-16 processing different string results",
868 testCase
.o
, (int)i
, testCase
.s
, (long)aTInfo
.getErrors());
871 if( aT8Info
.isTransitionalDifferent()!=aTInfo
.isTransitionalDifferent() ||
872 uT8Info
.isTransitionalDifferent()!=uTInfo
.isTransitionalDifferent() ||
873 aN8Info
.isTransitionalDifferent()!=aNInfo
.isTransitionalDifferent() ||
874 uN8Info
.isTransitionalDifferent()!=uNInfo
.isTransitionalDifferent()
876 errln("%s.xyzUTF8([%d] %s) vs. UTF-16 processing different isTransitionalDifferent()",
877 testCase
.o
, (int)i
, testCase
.s
);
884 #endif // UCONFIG_NO_IDNA