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