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