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