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