1/*
2*******************************************************************************
3*   Copyright (C) 2010-2014, International Business Machines
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()");
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);
62            nontrans=IDNA::createUTS46Instance(
63                commonOptions|
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    { ".", "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.-b.", "B", "a.-b.", UIDNA_ERROR_LEADING_HYPHEN },
483    { "a.b-.c", "B", "a.b-.c", UIDNA_ERROR_TRAILING_HYPHEN },
484    { "a.-.c", "B", "a.-.c", UIDNA_ERROR_LEADING_HYPHEN|UIDNA_ERROR_TRAILING_HYPHEN },
485    { "a.bc--de.f", "B", "a.bc--de.f", UIDNA_ERROR_HYPHEN_3_4 },
486    { "\\u00E4.\\u00AD.c", "B", "\\u00E4..c", UIDNA_ERROR_EMPTY_LABEL },
487    { "\\u00E4.-b.", "B", "\\u00E4.-b.", UIDNA_ERROR_LEADING_HYPHEN },
488    { "\\u00E4.b-.c", "B", "\\u00E4.b-.c", UIDNA_ERROR_TRAILING_HYPHEN },
489    { "\\u00E4.-.c", "B", "\\u00E4.-.c", UIDNA_ERROR_LEADING_HYPHEN|UIDNA_ERROR_TRAILING_HYPHEN },
490    { "\\u00E4.bc--de.f", "B", "\\u00E4.bc--de.f", UIDNA_ERROR_HYPHEN_3_4 },
491    { "a.b.\\u0308c.d", "B", "a.b.\\uFFFDc.d", UIDNA_ERROR_LEADING_COMBINING_MARK },
492    { "a.b.xn--c-bcb.d", "B",
493      "a.b.xn--c-bcb\\uFFFD.d", UIDNA_ERROR_LEADING_COMBINING_MARK|UIDNA_ERROR_INVALID_ACE_LABEL },
494    // BiDi
495    { "A0", "B", "a0", 0 },
496    { "0A", "B", "0a", 0 },  // all-LTR is ok to start with a digit (EN)
497    { "0A.\\u05D0", "B",  // ASCII label does not start with L/R/AL
498      "0a.\\u05D0", UIDNA_ERROR_BIDI },
499    { "c.xn--0-eha.xn--4db", "B",  // 2nd label does not start with L/R/AL
500      "c.0\\u00FC.\\u05D0", UIDNA_ERROR_BIDI },
501    { "b-.\\u05D0", "B",  // label does not end with L/EN
502      "b-.\\u05D0", UIDNA_ERROR_TRAILING_HYPHEN|UIDNA_ERROR_BIDI },
503    { "d.xn----dha.xn--4db", "B",  // 2nd label does not end with L/EN
504      "d.\\u00FC-.\\u05D0", UIDNA_ERROR_TRAILING_HYPHEN|UIDNA_ERROR_BIDI },
505    { "a\\u05D0", "B", "a\\u05D0", UIDNA_ERROR_BIDI },  // first dir != last dir
506    { "\\u05D0\\u05C7", "B", "\\u05D0\\u05C7", 0 },
507    { "\\u05D09\\u05C7", "B", "\\u05D09\\u05C7", 0 },
508    { "\\u05D0a\\u05C7", "B", "\\u05D0a\\u05C7", UIDNA_ERROR_BIDI },  // first dir != last dir
509    { "\\u05D0\\u05EA", "B", "\\u05D0\\u05EA", 0 },
510    { "\\u05D0\\u05F3\\u05EA", "B", "\\u05D0\\u05F3\\u05EA", 0 },
511    { "a\\u05D0Tz", "B", "a\\u05D0tz", UIDNA_ERROR_BIDI },  // mixed dir
512    { "\\u05D0T\\u05EA", "B", "\\u05D0t\\u05EA", UIDNA_ERROR_BIDI },  // mixed dir
513    { "\\u05D07\\u05EA", "B", "\\u05D07\\u05EA", 0 },
514    { "\\u05D0\\u0667\\u05EA", "B", "\\u05D0\\u0667\\u05EA", 0 },  // Arabic 7 in the middle
515    { "a7\\u0667z", "B", "a7\\u0667z", UIDNA_ERROR_BIDI },  // AN digit in LTR
516    { "\\u05D07\\u0667\\u05EA", "B",  // mixed EN/AN digits in RTL
517      "\\u05D07\\u0667\\u05EA", UIDNA_ERROR_BIDI },
518    // ZWJ
519    { "\\u0BB9\\u0BCD\\u200D", "N", "\\u0BB9\\u0BCD\\u200D", 0 },  // Virama+ZWJ
520    { "\\u0BB9\\u200D", "N", "\\u0BB9\\u200D", UIDNA_ERROR_CONTEXTJ },  // no Virama
521    { "\\u200D", "N", "\\u200D", UIDNA_ERROR_CONTEXTJ },  // no Virama
522    // ZWNJ
523    { "\\u0BB9\\u0BCD\\u200C", "N", "\\u0BB9\\u0BCD\\u200C", 0 },  // Virama+ZWNJ
524    { "\\u0BB9\\u200C", "N", "\\u0BB9\\u200C", UIDNA_ERROR_CONTEXTJ },  // no Virama
525    { "\\u200C", "N", "\\u200C", UIDNA_ERROR_CONTEXTJ },  // no Virama
526    { "\\u0644\\u0670\\u200C\\u06ED\\u06EF", "N",  // Joining types D T ZWNJ T R
527      "\\u0644\\u0670\\u200C\\u06ED\\u06EF", 0 },
528    { "\\u0644\\u0670\\u200C\\u06EF", "N",  // D T ZWNJ R
529      "\\u0644\\u0670\\u200C\\u06EF", 0 },
530    { "\\u0644\\u200C\\u06ED\\u06EF", "N",  // D ZWNJ T R
531      "\\u0644\\u200C\\u06ED\\u06EF", 0 },
532    { "\\u0644\\u200C\\u06EF", "N",  // D ZWNJ R
533      "\\u0644\\u200C\\u06EF", 0 },
534    { "\\u0644\\u0670\\u200C\\u06ED", "N",  // D T ZWNJ T
535      "\\u0644\\u0670\\u200C\\u06ED", UIDNA_ERROR_BIDI|UIDNA_ERROR_CONTEXTJ },
536    { "\\u06EF\\u200C\\u06EF", "N",  // R ZWNJ R
537      "\\u06EF\\u200C\\u06EF", UIDNA_ERROR_CONTEXTJ },
538    { "\\u0644\\u200C", "N",  // D ZWNJ
539      "\\u0644\\u200C", UIDNA_ERROR_BIDI|UIDNA_ERROR_CONTEXTJ },
540    { "\\u0660\\u0661", "B",  // Arabic-Indic Digits alone
541      "\\u0660\\u0661", UIDNA_ERROR_BIDI },
542    { "\\u06F0\\u06F1", "B",  // Extended Arabic-Indic Digits alone
543      "\\u06F0\\u06F1", 0 },
544    { "\\u0660\\u06F1", "B",  // Mixed Arabic-Indic Digits
545      "\\u0660\\u06F1", UIDNA_ERROR_CONTEXTO_DIGITS|UIDNA_ERROR_BIDI },
546    // All of the CONTEXTO "Would otherwise have been DISALLOWED" characters
547    // in their correct contexts,
548    // then each in incorrect context.
549    { "l\\u00B7l\\u4E00\\u0375\\u03B1\\u05D0\\u05F3\\u05F4\\u30FB", "B",
550      "l\\u00B7l\\u4E00\\u0375\\u03B1\\u05D0\\u05F3\\u05F4\\u30FB", UIDNA_ERROR_BIDI },
551    { "l\\u00B7", "B",
552      "l\\u00B7", UIDNA_ERROR_CONTEXTO_PUNCTUATION },
553    { "\\u00B7l", "B",
554      "\\u00B7l", UIDNA_ERROR_CONTEXTO_PUNCTUATION },
555    { "\\u0375", "B",
556      "\\u0375", UIDNA_ERROR_CONTEXTO_PUNCTUATION },
557    { "\\u03B1\\u05F3", "B",
558      "\\u03B1\\u05F3", UIDNA_ERROR_CONTEXTO_PUNCTUATION|UIDNA_ERROR_BIDI },
559    { "\\u05F4", "B",
560      "\\u05F4", UIDNA_ERROR_CONTEXTO_PUNCTUATION },
561    { "l\\u30FB", "B",
562      "l\\u30FB", UIDNA_ERROR_CONTEXTO_PUNCTUATION },
563    // Ticket #8137: UTS #46 toUnicode() fails with non-ASCII labels that turn
564    // into 15 characters (UChars).
565    // The bug was in u_strFromPunycode() which did not write the last character
566    // if it just so fit into the end of the destination buffer.
567    // The UTS #46 code gives a default-capacity UnicodeString as the destination buffer,
568    // and the internal UnicodeString capacity is currently 15 UChars on 64-bit machines
569    // but 13 on 32-bit machines.
570    // Label with 15 UChars, for 64-bit-machine testing:
571    { "aaaaaaaaaaaaa\\u00FCa.de", "B", "aaaaaaaaaaaaa\\u00FCa.de", 0 },
572    { "xn--aaaaaaaaaaaaaa-ssb.de", "B", "aaaaaaaaaaaaa\\u00FCa.de", 0 },
573    { "abschlu\\u00DFpr\\u00FCfung.de", "N", "abschlu\\u00DFpr\\u00FCfung.de", 0 },
574    { "xn--abschluprfung-hdb15b.de", "B", "abschlu\\u00DFpr\\u00FCfung.de", 0 },
575    // Label with 13 UChars, for 32-bit-machine testing:
576    { "xn--aaaaaaaaaaaa-nlb.de", "B", "aaaaaaaaaaa\\u00FCa.de", 0 },
577    { "xn--schluprfung-z6a39a.de", "B", "schlu\\u00DFpr\\u00FCfung.de", 0 },
578    // { "", "B",
579    //   "", 0 },
580};
581
582void UTS46Test::TestSomeCases() {
583    IcuTestErrorCode errorCode(*this, "TestSomeCases");
584    char buffer[400], buffer2[400];
585    int32_t i;
586    for(i=0; i<LENGTHOF(testCases); ++i) {
587        const TestCase &testCase=testCases[i];
588        UnicodeString input(ctou(testCase.s));
589        UnicodeString expected(ctou(testCase.u));
590        // ToASCII/ToUnicode, transitional/nontransitional
591        UnicodeString aT, uT, aN, uN;
592        IDNAInfo aTInfo, uTInfo, aNInfo, uNInfo;
593        trans->nameToASCII(input, aT, aTInfo, errorCode);
594        trans->nameToUnicode(input, uT, uTInfo, errorCode);
595        nontrans->nameToASCII(input, aN, aNInfo, errorCode);
596        nontrans->nameToUnicode(input, uN, uNInfo, errorCode);
597        if(errorCode.logIfFailureAndReset("first-level processing [%d/%s] %s",
598                                          (int)i, testCase.o, testCase.s)
599        ) {
600            continue;
601        }
602        // ToUnicode does not set length errors.
603        uint32_t uniErrors=testCase.errors&~
604            (UIDNA_ERROR_EMPTY_LABEL|
605             UIDNA_ERROR_LABEL_TOO_LONG|
606             UIDNA_ERROR_DOMAIN_NAME_TOO_LONG);
607        char mode=testCase.o[0];
608        if(mode=='B' || mode=='N') {
609            if(uNInfo.getErrors()!=uniErrors) {
610                errln("N.nameToUnicode([%d] %s) unexpected errors %04lx",
611                      (int)i, testCase.s, (long)uNInfo.getErrors());
612                continue;
613            }
614            if(uN!=expected) {
615                prettify(uN).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
616                errln("N.nameToUnicode([%d] %s) unexpected string %s",
617                      (int)i, testCase.s, buffer);
618                continue;
619            }
620            if(aNInfo.getErrors()!=testCase.errors) {
621                errln("N.nameToASCII([%d] %s) unexpected errors %04lx",
622                      (int)i, testCase.s, (long)aNInfo.getErrors());
623                continue;
624            }
625        }
626        if(mode=='B' || mode=='T') {
627            if(uTInfo.getErrors()!=uniErrors) {
628                errln("T.nameToUnicode([%d] %s) unexpected errors %04lx",
629                      (int)i, testCase.s, (long)uTInfo.getErrors());
630                continue;
631            }
632            if(uT!=expected) {
633                prettify(uT).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
634                errln("T.nameToUnicode([%d] %s) unexpected string %s",
635                      (int)i, testCase.s, buffer);
636                continue;
637            }
638            if(aTInfo.getErrors()!=testCase.errors) {
639                errln("T.nameToASCII([%d] %s) unexpected errors %04lx",
640                      (int)i, testCase.s, (long)aTInfo.getErrors());
641                continue;
642            }
643        }
644        // ToASCII is all-ASCII if no severe errors
645        if((aNInfo.getErrors()&severeErrors)==0 && !isASCII(aN)) {
646            prettify(aN).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
647            errln("N.nameToASCII([%d] %s) (errors %04lx) result is not ASCII %s",
648                  (int)i, testCase.s, aNInfo.getErrors(), buffer);
649            continue;
650        }
651        if((aTInfo.getErrors()&severeErrors)==0 && !isASCII(aT)) {
652            prettify(aT).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
653            errln("T.nameToASCII([%d] %s) (errors %04lx) result is not ASCII %s",
654                  (int)i, testCase.s, aTInfo.getErrors(), buffer);
655            continue;
656        }
657        if(verbose) {
658            char m= mode=='B' ? mode : 'N';
659            prettify(aN).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
660            logln("%c.nameToASCII([%d] %s) (errors %04lx) result string: %s",
661                  m, (int)i, testCase.s, aNInfo.getErrors(), buffer);
662            if(mode!='B') {
663                prettify(aT).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
664                logln("T.nameToASCII([%d] %s) (errors %04lx) result string: %s",
665                      (int)i, testCase.s, aTInfo.getErrors(), buffer);
666            }
667        }
668        // second-level processing
669        UnicodeString aTuN, uTaN, aNuN, uNaN;
670        IDNAInfo aTuNInfo, uTaNInfo, aNuNInfo, uNaNInfo;
671        nontrans->nameToUnicode(aT, aTuN, aTuNInfo, errorCode);
672        nontrans->nameToASCII(uT, uTaN, uTaNInfo, errorCode);
673        nontrans->nameToUnicode(aN, aNuN, aNuNInfo, errorCode);
674        nontrans->nameToASCII(uN, uNaN, uNaNInfo, errorCode);
675        if(errorCode.logIfFailureAndReset("second-level processing [%d/%s] %s",
676                                          (int)i, testCase.o, testCase.s)
677        ) {
678            continue;
679        }
680        if(aN!=uNaN) {
681            prettify(aN).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
682            prettify(uNaN).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
683            errln("N.nameToASCII([%d] %s)!=N.nameToUnicode().N.nameToASCII() "
684                  "(errors %04lx) %s vs. %s",
685                  (int)i, testCase.s, aNInfo.getErrors(), buffer, buffer2);
686            continue;
687        }
688        if(aT!=uTaN) {
689            prettify(aT).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
690            prettify(uTaN).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
691            errln("T.nameToASCII([%d] %s)!=T.nameToUnicode().N.nameToASCII() "
692                  "(errors %04lx) %s vs. %s",
693                  (int)i, testCase.s, aNInfo.getErrors(), buffer, buffer2);
694            continue;
695        }
696        if(uN!=aNuN) {
697            prettify(uN).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
698            prettify(aNuN).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
699            errln("N.nameToUnicode([%d] %s)!=N.nameToASCII().N.nameToUnicode() "
700                  "(errors %04lx) %s vs. %s",
701                  (int)i, testCase.s, uNInfo.getErrors(), buffer, buffer2);
702            continue;
703        }
704        if(uT!=aTuN) {
705            prettify(uT).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
706            prettify(aTuN).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
707            errln("T.nameToUnicode([%d] %s)!=T.nameToASCII().N.nameToUnicode() "
708                  "(errors %04lx) %s vs. %s",
709                  (int)i, testCase.s, uNInfo.getErrors(), buffer, buffer2);
710            continue;
711        }
712        // labelToUnicode
713        UnicodeString aTL, uTL, aNL, uNL;
714        IDNAInfo aTLInfo, uTLInfo, aNLInfo, uNLInfo;
715        trans->labelToASCII(input, aTL, aTLInfo, errorCode);
716        trans->labelToUnicode(input, uTL, uTLInfo, errorCode);
717        nontrans->labelToASCII(input, aNL, aNLInfo, errorCode);
718        nontrans->labelToUnicode(input, uNL, uNLInfo, errorCode);
719        if(errorCode.logIfFailureAndReset("labelToXYZ processing [%d/%s] %s",
720                                          (int)i, testCase.o, testCase.s)
721        ) {
722            continue;
723        }
724        if(aN.indexOf((UChar)0x2e)<0) {
725            if(aN!=aNL || aNInfo.getErrors()!=aNLInfo.getErrors()) {
726                prettify(aN).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
727                prettify(aNL).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
728                errln("N.nameToASCII([%d] %s)!=N.labelToASCII() "
729                      "(errors %04lx vs %04lx) %s vs. %s",
730                      (int)i, testCase.s, aNInfo.getErrors(), aNLInfo.getErrors(), buffer, buffer2);
731                continue;
732            }
733        } else {
734            if((aNLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) {
735                errln("N.labelToASCII([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
736                      (int)i, testCase.s, (long)aNLInfo.getErrors());
737                continue;
738            }
739        }
740        if(aT.indexOf((UChar)0x2e)<0) {
741            if(aT!=aTL || aTInfo.getErrors()!=aTLInfo.getErrors()) {
742                prettify(aT).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
743                prettify(aTL).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
744                errln("T.nameToASCII([%d] %s)!=T.labelToASCII() "
745                      "(errors %04lx vs %04lx) %s vs. %s",
746                      (int)i, testCase.s, aTInfo.getErrors(), aTLInfo.getErrors(), buffer, buffer2);
747                continue;
748            }
749        } else {
750            if((aTLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) {
751                errln("T.labelToASCII([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
752                      (int)i, testCase.s, (long)aTLInfo.getErrors());
753                continue;
754            }
755        }
756        if(uN.indexOf((UChar)0x2e)<0) {
757            if(uN!=uNL || uNInfo.getErrors()!=uNLInfo.getErrors()) {
758                prettify(uN).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
759                prettify(uNL).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
760                errln("N.nameToUnicode([%d] %s)!=N.labelToUnicode() "
761                      "(errors %04lx vs %04lx) %s vs. %s",
762                      (int)i, testCase.s, uNInfo.getErrors(), uNLInfo.getErrors(), buffer, buffer2);
763                continue;
764            }
765        } else {
766            if((uNLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) {
767                errln("N.labelToUnicode([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
768                      (int)i, testCase.s, (long)uNLInfo.getErrors());
769                continue;
770            }
771        }
772        if(uT.indexOf((UChar)0x2e)<0) {
773            if(uT!=uTL || uTInfo.getErrors()!=uTLInfo.getErrors()) {
774                prettify(uT).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
775                prettify(uTL).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
776                errln("T.nameToUnicode([%d] %s)!=T.labelToUnicode() "
777                      "(errors %04lx vs %04lx) %s vs. %s",
778                      (int)i, testCase.s, uTInfo.getErrors(), uTLInfo.getErrors(), buffer, buffer2);
779                continue;
780            }
781        } else {
782            if((uTLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) {
783                errln("T.labelToUnicode([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
784                      (int)i, testCase.s, (long)uTLInfo.getErrors());
785                continue;
786            }
787        }
788        // Differences between transitional and nontransitional processing
789        if(mode=='B') {
790            if( aNInfo.isTransitionalDifferent() ||
791                aTInfo.isTransitionalDifferent() ||
792                uNInfo.isTransitionalDifferent() ||
793                uTInfo.isTransitionalDifferent() ||
794                aNLInfo.isTransitionalDifferent() ||
795                aTLInfo.isTransitionalDifferent() ||
796                uNLInfo.isTransitionalDifferent() ||
797                uTLInfo.isTransitionalDifferent()
798            ) {
799                errln("B.process([%d] %s) isTransitionalDifferent()", (int)i, testCase.s);
800                continue;
801            }
802            if( aN!=aT || uN!=uT || aNL!=aTL || uNL!=uTL ||
803                aNInfo.getErrors()!=aTInfo.getErrors() || uNInfo.getErrors()!=uTInfo.getErrors() ||
804                aNLInfo.getErrors()!=aTLInfo.getErrors() || uNLInfo.getErrors()!=uTLInfo.getErrors()
805            ) {
806                errln("N.process([%d] %s) vs. T.process() different errors or result strings",
807                      (int)i, testCase.s);
808                continue;
809            }
810        } else {
811            if( !aNInfo.isTransitionalDifferent() ||
812                !aTInfo.isTransitionalDifferent() ||
813                !uNInfo.isTransitionalDifferent() ||
814                !uTInfo.isTransitionalDifferent() ||
815                !aNLInfo.isTransitionalDifferent() ||
816                !aTLInfo.isTransitionalDifferent() ||
817                !uNLInfo.isTransitionalDifferent() ||
818                !uTLInfo.isTransitionalDifferent()
819            ) {
820                errln("%s.process([%d] %s) !isTransitionalDifferent()",
821                      testCase.o, (int)i, testCase.s);
822                continue;
823            }
824            if(aN==aT || uN==uT || aNL==aTL || uNL==uTL) {
825                errln("N.process([%d] %s) vs. T.process() same result strings",
826                      (int)i, testCase.s);
827                continue;
828            }
829        }
830        // UTF-8 if we have std::string
831#if U_HAVE_STD_STRING
832        std::string input8, aT8, uT8, aN8, uN8;
833        StringByteSink<std::string> aT8Sink(&aT8), uT8Sink(&uT8), aN8Sink(&aN8), uN8Sink(&uN8);
834        IDNAInfo aT8Info, uT8Info, aN8Info, uN8Info;
835        input.toUTF8String(input8);
836        trans->nameToASCII_UTF8(input8, aT8Sink, aT8Info, errorCode);
837        trans->nameToUnicodeUTF8(input8, uT8Sink, uT8Info, errorCode);
838        nontrans->nameToASCII_UTF8(input8, aN8Sink, aN8Info, errorCode);
839        nontrans->nameToUnicodeUTF8(input8, uN8Sink, uN8Info, errorCode);
840        if(errorCode.logIfFailureAndReset("UTF-8 processing [%d/%s] %s",
841                                          (int)i, testCase.o, testCase.s)
842        ) {
843            continue;
844        }
845        UnicodeString aT16(UnicodeString::fromUTF8(aT8));
846        UnicodeString uT16(UnicodeString::fromUTF8(uT8));
847        UnicodeString aN16(UnicodeString::fromUTF8(aN8));
848        UnicodeString uN16(UnicodeString::fromUTF8(uN8));
849        if( aN8Info.getErrors()!=aNInfo.getErrors() ||
850            uN8Info.getErrors()!=uNInfo.getErrors()
851        ) {
852            errln("N.xyzUTF8([%d] %s) vs. UTF-16 processing different errors %04lx vs. %04lx",
853                  (int)i, testCase.s,
854                  (long)aN8Info.getErrors(), (long)aNInfo.getErrors());
855            continue;
856        }
857        if( aT8Info.getErrors()!=aTInfo.getErrors() ||
858            uT8Info.getErrors()!=uTInfo.getErrors()
859        ) {
860            errln("T.xyzUTF8([%d] %s) vs. UTF-16 processing different errors %04lx vs. %04lx",
861                  (int)i, testCase.s,
862                  (long)aT8Info.getErrors(), (long)aTInfo.getErrors());
863            continue;
864        }
865        if(aT16!=aT || uT16!=uT || aN16!=aN || uN16!=uN) {
866            errln("%s.xyzUTF8([%d] %s) vs. UTF-16 processing different string results",
867                  testCase.o, (int)i, testCase.s, (long)aTInfo.getErrors());
868            continue;
869        }
870        if( aT8Info.isTransitionalDifferent()!=aTInfo.isTransitionalDifferent() ||
871            uT8Info.isTransitionalDifferent()!=uTInfo.isTransitionalDifferent() ||
872            aN8Info.isTransitionalDifferent()!=aNInfo.isTransitionalDifferent() ||
873            uN8Info.isTransitionalDifferent()!=uNInfo.isTransitionalDifferent()
874        ) {
875            errln("%s.xyzUTF8([%d] %s) vs. UTF-16 processing different isTransitionalDifferent()",
876                  testCase.o, (int)i, testCase.s);
877            continue;
878        }
879#endif
880    }
881}
882
883#endif  // UCONFIG_NO_IDNA
884