Home | History | Annotate | Download | only in cintltst
      1 /*
      2  *******************************************************************************
      3  *
      4  *   Copyright (C) 2003-2010, International Business Machines
      5  *   Corporation and others.  All Rights Reserved.
      6  *
      7  *******************************************************************************
      8  *   file name:  idnatest.c
      9  *   encoding:   US-ASCII
     10  *   tab size:   8 (not used)
     11  *   indentation:4
     12  *
     13  *   created on: 2003jul11
     14  *   created by: Ram Viswanadha
     15  */
     16 #include <stdlib.h>
     17 #include <string.h>
     18 #include "unicode/utypes.h"
     19 
     20 #if !UCONFIG_NO_IDNA
     21 
     22 #include "unicode/ustring.h"
     23 #include "unicode/uidna.h"
     24 #include "cintltst.h"
     25 
     26 
     27 
     28 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
     29 #define MAX_DEST_SIZE 1000
     30 
     31 static void TestToUnicode(void);
     32 static void TestToASCII(void);
     33 static void TestIDNToUnicode(void);
     34 static void TestIDNToASCII(void);
     35 static void TestCompare(void);
     36 static void TestJB4490(void);
     37 static void TestJB4475(void);
     38 static void TestLength(void);
     39 static void TestJB5273(void);
     40 static void TestUTS46(void);
     41 
     42 void addIDNATest(TestNode** root);
     43 
     44 
     45 typedef int32_t
     46 (U_EXPORT2 *TestFunc) (   const UChar *src, int32_t srcLength,
     47                 UChar *dest, int32_t destCapacity,
     48                 int32_t options, UParseError *parseError,
     49                 UErrorCode *status);
     50 typedef int32_t
     51 (U_EXPORT2 *CompareFunc) (const UChar *s1, int32_t s1Len,
     52                 const UChar *s2, int32_t s2Len,
     53                 int32_t options,
     54                 UErrorCode *status);
     55 
     56 
     57 void
     58 addIDNATest(TestNode** root)
     59 {
     60    addTest(root, &TestToUnicode,    "idna/TestToUnicode");
     61    addTest(root, &TestToASCII,      "idna/TestToASCII");
     62    addTest(root, &TestIDNToUnicode, "idna/TestIDNToUnicode");
     63    addTest(root, &TestIDNToASCII,   "idna/TestIDNToASCII");
     64    addTest(root, &TestCompare,      "idna/TestCompare");
     65    addTest(root, &TestJB4490,       "idna/TestJB4490");
     66    addTest(root, &TestJB4475,       "idna/TestJB4475");
     67    addTest(root, &TestLength,       "idna/TestLength");
     68    addTest(root, &TestJB5273,       "idna/TestJB5273");
     69    addTest(root, &TestUTS46,        "idna/TestUTS46");
     70 }
     71 
     72 static void
     73 testAPI(const UChar* src, const UChar* expected, const char* testName,
     74             UBool useSTD3ASCIIRules,UErrorCode expectedStatus,
     75             UBool doCompare, UBool testUnassigned,  TestFunc func){
     76 
     77     UErrorCode status = U_ZERO_ERROR;
     78     UChar destStack[MAX_DEST_SIZE];
     79     int32_t destLen = 0;
     80     UChar* dest = NULL;
     81     int32_t expectedLen = (expected != NULL) ? u_strlen(expected) : 0;
     82     int32_t options = (useSTD3ASCIIRules == TRUE) ? UIDNA_USE_STD3_RULES : UIDNA_DEFAULT;
     83     UParseError parseError;
     84     int32_t tSrcLen = 0;
     85     UChar* tSrc = NULL;
     86 
     87     if(src != NULL){
     88         tSrcLen = u_strlen(src);
     89         tSrc  =(UChar*) malloc( U_SIZEOF_UCHAR * tSrcLen );
     90         memcpy(tSrc,src,tSrcLen * U_SIZEOF_UCHAR);
     91     }
     92 
     93     /* test null-terminated source and return value of number of UChars required */
     94 
     95     destLen = func(src,-1,NULL,0,options, &parseError , &status);
     96     if(status == U_BUFFER_OVERFLOW_ERROR){
     97         status = U_ZERO_ERROR; /* reset error code */
     98         if(destLen+1 < MAX_DEST_SIZE){
     99             dest = destStack;
    100             destLen = func(src,-1,dest,destLen+1,options, &parseError, &status);
    101             /* TODO : compare output with expected */
    102             if(U_SUCCESS(status) && expectedStatus != U_IDNA_STD3_ASCII_RULES_ERROR&& (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
    103                 log_err("Did not get the expected result for  null terminated source.\n" );
    104             }
    105         }else{
    106             log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName);
    107         }
    108     }
    109 
    110     if(status != expectedStatus){
    111         log_err_status(status,  "Did not get the expected error for %s null terminated source failed. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status));
    112         free(tSrc);
    113         return;
    114     }
    115     if(testUnassigned ){
    116         status = U_ZERO_ERROR;
    117         destLen = func(src,-1,NULL,0,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
    118         if(status == U_BUFFER_OVERFLOW_ERROR){
    119             status = U_ZERO_ERROR; /* reset error code */
    120             if(destLen+1 < MAX_DEST_SIZE){
    121                 dest = destStack;
    122                 destLen = func(src,-1,dest,destLen+1,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
    123                 /* TODO : compare output with expected */
    124                 if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
    125                     log_err("Did not get the expected result for %s null terminated source with both options set.\n",testName);
    126 
    127                 }
    128             }else{
    129                 log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName);
    130             }
    131         }
    132         /*testing query string*/
    133         if(status != expectedStatus && expectedStatus != U_IDNA_UNASSIGNED_ERROR){
    134             log_err( "Did not get the expected error for %s null terminated source with options set. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status));
    135         }
    136     }
    137 
    138     status = U_ZERO_ERROR;
    139 
    140     /* test source with lengthand return value of number of UChars required*/
    141     destLen = func(tSrc, tSrcLen, NULL,0,options, &parseError, &status);
    142     if(status == U_BUFFER_OVERFLOW_ERROR){
    143         status = U_ZERO_ERROR; /* reset error code */
    144         if(destLen+1 < MAX_DEST_SIZE){
    145             dest = destStack;
    146             destLen = func(src,u_strlen(src),dest,destLen+1,options, &parseError, &status);
    147             /* TODO : compare output with expected */
    148             if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
    149                 log_err("Did not get the expected result for %s with source length.\n",testName);
    150             }
    151         }else{
    152             log_err( "%s with source length  failed. Requires destCapacity > 300\n",testName);
    153         }
    154     }
    155 
    156     if(status != expectedStatus){
    157         log_err( "Did not get the expected error for %s with source length. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status));
    158     }
    159     if(testUnassigned){
    160         status = U_ZERO_ERROR;
    161 
    162         destLen = func(tSrc,tSrcLen,NULL,0,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
    163 
    164         if(status == U_BUFFER_OVERFLOW_ERROR){
    165             status = U_ZERO_ERROR; /* reset error code */
    166             if(destLen+1 < MAX_DEST_SIZE){
    167                 dest = destStack;
    168                 destLen = func(src,u_strlen(src),dest,destLen+1,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
    169                 /* TODO : compare output with expected */
    170                 if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
    171                     log_err("Did not get the expected result for %s with source length and both options set.\n",testName);
    172                 }
    173             }else{
    174                 log_err( "%s with source length  failed. Requires destCapacity > 300\n",testName);
    175             }
    176         }
    177         /*testing query string*/
    178         if(status != expectedStatus && expectedStatus != U_IDNA_UNASSIGNED_ERROR){
    179             log_err( "Did not get the expected error for %s with source length and options set. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status));
    180         }
    181     }
    182 
    183     status = U_ZERO_ERROR;
    184     destLen = func(src,-1,NULL,0,options | UIDNA_USE_STD3_RULES, &parseError, &status);
    185     if(status == U_BUFFER_OVERFLOW_ERROR){
    186         status = U_ZERO_ERROR; /* reset error code*/
    187         if(destLen+1 < MAX_DEST_SIZE){
    188             dest = destStack;
    189             destLen = func(src,-1,dest,destLen+1,options | UIDNA_USE_STD3_RULES, &parseError, &status);
    190             /* TODO : compare output with expected*/
    191             if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
    192                 log_err("Did not get the expected result for %s null terminated source with both options set.\n",testName);
    193 
    194             }
    195         }else{
    196             log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName);
    197         }
    198     }
    199     /*testing query string*/
    200     if(status != expectedStatus){
    201         log_err( "Did not get the expected error for %s null terminated source with options set. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status));
    202     }
    203 
    204     status = U_ZERO_ERROR;
    205 
    206     destLen = func(tSrc,tSrcLen,NULL,0,options | UIDNA_USE_STD3_RULES, &parseError, &status);
    207 
    208     if(status == U_BUFFER_OVERFLOW_ERROR){
    209         status = U_ZERO_ERROR; /* reset error code*/
    210         if(destLen+1 < MAX_DEST_SIZE){
    211             dest = destStack;
    212             destLen = func(src,u_strlen(src),dest,destLen+1,options | UIDNA_USE_STD3_RULES, &parseError, &status);
    213             /* TODO : compare output with expected*/
    214             if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
    215                 log_err("Did not get the expected result for %s with source length and both options set.\n",testName);
    216             }
    217         }else{
    218             log_err( "%s with source length  failed. Requires destCapacity > 300\n",testName);
    219         }
    220     }
    221     /*testing query string*/
    222     if(status != expectedStatus && expectedStatus != U_IDNA_UNASSIGNED_ERROR){
    223         log_err( "Did not get the expected error for %s with source length and options set. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status));
    224     }
    225     free(tSrc);
    226 }
    227 
    228 static const UChar unicodeIn[][41] ={
    229     {
    230         0x0644, 0x064A, 0x0647, 0x0645, 0x0627, 0x0628, 0x062A, 0x0643, 0x0644,
    231         0x0645, 0x0648, 0x0634, 0x0639, 0x0631, 0x0628, 0x064A, 0x061F, 0x0000
    232     },
    233     {
    234         0x4ED6, 0x4EEC, 0x4E3A, 0x4EC0, 0x4E48, 0x4E0D, 0x8BF4, 0x4E2D, 0x6587,
    235         0x0000
    236     },
    237     {
    238         0x0050, 0x0072, 0x006F, 0x010D, 0x0070, 0x0072, 0x006F, 0x0073, 0x0074,
    239         0x011B, 0x006E, 0x0065, 0x006D, 0x006C, 0x0075, 0x0076, 0x00ED, 0x010D,
    240         0x0065, 0x0073, 0x006B, 0x0079, 0x0000
    241     },
    242     {
    243         0x05DC, 0x05DE, 0x05D4, 0x05D4, 0x05DD, 0x05E4, 0x05E9, 0x05D5, 0x05D8,
    244         0x05DC, 0x05D0, 0x05DE, 0x05D3, 0x05D1, 0x05E8, 0x05D9, 0x05DD, 0x05E2,
    245         0x05D1, 0x05E8, 0x05D9, 0x05EA, 0x0000
    246     },
    247     {
    248         0x092F, 0x0939, 0x0932, 0x094B, 0x0917, 0x0939, 0x093F, 0x0928, 0x094D,
    249         0x0926, 0x0940, 0x0915, 0x094D, 0x092F, 0x094B, 0x0902, 0x0928, 0x0939,
    250         0x0940, 0x0902, 0x092C, 0x094B, 0x0932, 0x0938, 0x0915, 0x0924, 0x0947,
    251         0x0939, 0x0948, 0x0902, 0x0000
    252     },
    253     {
    254         0x306A, 0x305C, 0x307F, 0x3093, 0x306A, 0x65E5, 0x672C, 0x8A9E, 0x3092,
    255         0x8A71, 0x3057, 0x3066, 0x304F, 0x308C, 0x306A, 0x3044, 0x306E, 0x304B,
    256         0x0000
    257     },
    258 /*
    259     {
    260         0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
    261         0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
    262         0xC5BC, 0xB9C8, 0xB098, 0xC88B, 0xC744, 0xAE4C, 0x0000
    263     },
    264 */
    265     {
    266         0x043F, 0x043E, 0x0447, 0x0435, 0x043C, 0x0443, 0x0436, 0x0435, 0x043E,
    267         0x043D, 0x0438, 0x043D, 0x0435, 0x0433, 0x043E, 0x0432, 0x043E, 0x0440,
    268         0x044F, 0x0442, 0x043F, 0x043E, 0x0440, 0x0443, 0x0441, 0x0441, 0x043A,
    269         0x0438, 0x0000
    270     },
    271     {
    272         0x0050, 0x006F, 0x0072, 0x0071, 0x0075, 0x00E9, 0x006E, 0x006F, 0x0070,
    273         0x0075, 0x0065, 0x0064, 0x0065, 0x006E, 0x0073, 0x0069, 0x006D, 0x0070,
    274         0x006C, 0x0065, 0x006D, 0x0065, 0x006E, 0x0074, 0x0065, 0x0068, 0x0061,
    275         0x0062, 0x006C, 0x0061, 0x0072, 0x0065, 0x006E, 0x0045, 0x0073, 0x0070,
    276         0x0061, 0x00F1, 0x006F, 0x006C, 0x0000
    277     },
    278     {
    279         0x4ED6, 0x5011, 0x7232, 0x4EC0, 0x9EBD, 0x4E0D, 0x8AAA, 0x4E2D, 0x6587,
    280         0x0000
    281     },
    282     {
    283         0x0054, 0x1EA1, 0x0069, 0x0073, 0x0061, 0x006F, 0x0068, 0x1ECD, 0x006B,
    284         0x0068, 0x00F4, 0x006E, 0x0067, 0x0074, 0x0068, 0x1EC3, 0x0063, 0x0068,
    285         0x1EC9, 0x006E, 0x00F3, 0x0069, 0x0074, 0x0069, 0x1EBF, 0x006E, 0x0067,
    286         0x0056, 0x0069, 0x1EC7, 0x0074, 0x0000
    287     },
    288     {
    289         0x0033, 0x5E74, 0x0042, 0x7D44, 0x91D1, 0x516B, 0x5148, 0x751F, 0x0000
    290     },
    291     {
    292         0x5B89, 0x5BA4, 0x5948, 0x7F8E, 0x6075, 0x002D, 0x0077, 0x0069, 0x0074,
    293         0x0068, 0x002D, 0x0053, 0x0055, 0x0050, 0x0045, 0x0052, 0x002D, 0x004D,
    294         0x004F, 0x004E, 0x004B, 0x0045, 0x0059, 0x0053, 0x0000
    295     },
    296     {
    297         0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x002D, 0x0041, 0x006E, 0x006F,
    298         0x0074, 0x0068, 0x0065, 0x0072, 0x002D, 0x0057, 0x0061, 0x0079, 0x002D,
    299         0x305D, 0x308C, 0x305E, 0x308C, 0x306E, 0x5834, 0x6240, 0x0000
    300     },
    301     {
    302         0x3072, 0x3068, 0x3064, 0x5C4B, 0x6839, 0x306E, 0x4E0B, 0x0032, 0x0000
    303     },
    304     {
    305         0x004D, 0x0061, 0x006A, 0x0069, 0x3067, 0x004B, 0x006F, 0x0069, 0x3059,
    306         0x308B, 0x0035, 0x79D2, 0x524D, 0x0000
    307     },
    308     {
    309         0x30D1, 0x30D5, 0x30A3, 0x30FC, 0x0064, 0x0065, 0x30EB, 0x30F3, 0x30D0,
    310         0x0000
    311     },
    312     {
    313         0x305D, 0x306E, 0x30B9, 0x30D4, 0x30FC, 0x30C9, 0x3067, 0x0000
    314     },
    315     /* test non-BMP code points */
    316     {
    317         0xD800, 0xDF00, 0xD800, 0xDF01, 0xD800, 0xDF02, 0xD800, 0xDF03, 0xD800, 0xDF05,
    318         0xD800, 0xDF06, 0xD800, 0xDF07, 0xD800, 0xDF09, 0xD800, 0xDF0A, 0xD800, 0xDF0B,
    319         0x0000
    320     },
    321     {
    322         0xD800, 0xDF0D, 0xD800, 0xDF0C, 0xD800, 0xDF1E, 0xD800, 0xDF0F, 0xD800, 0xDF16,
    323         0xD800, 0xDF15, 0xD800, 0xDF14, 0xD800, 0xDF12, 0xD800, 0xDF10, 0xD800, 0xDF20,
    324         0xD800, 0xDF21,
    325         0x0000
    326     },
    327     /* Greek  */
    328     {
    329         0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac
    330     },
    331     /* Maltese */
    332     {
    333         0x0062, 0x006f, 0x006e, 0x0121, 0x0075, 0x0073, 0x0061, 0x0127,
    334         0x0127, 0x0061
    335     },
    336     /* Russian */
    337     {
    338         0x043f, 0x043e, 0x0447, 0x0435, 0x043c, 0x0443, 0x0436, 0x0435,
    339         0x043e, 0x043d, 0x0438, 0x043d, 0x0435, 0x0433, 0x043e, 0x0432,
    340         0x043e, 0x0440, 0x044f, 0x0442, 0x043f, 0x043e, 0x0440, 0x0443,
    341         0x0441, 0x0441, 0x043a, 0x0438
    342     },
    343     {
    344         0x0054,0x0045,0x0053,0x0054
    345     }
    346 };
    347 
    348 static const char * const asciiIn[] = {
    349     "xn--egbpdaj6bu4bxfgehfvwxn",
    350     "xn--ihqwcrb4cv8a8dqg056pqjye",
    351     "xn--Proprostnemluvesky-uyb24dma41a",
    352     "xn--4dbcagdahymbxekheh6e0a7fei0b",
    353     "xn--i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd",
    354     "xn--n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa",
    355 /*  "xn--989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c",*/
    356     "xn--b1abfaaepdrnnbgefbaDotcwatmq2g4l",
    357     "xn--PorqunopuedensimplementehablarenEspaol-fmd56a",
    358     "xn--ihqwctvzc91f659drss3x8bo0yb",
    359     "xn--TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g",
    360     "xn--3B-ww4c5e180e575a65lsy2b",
    361     "xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n",
    362     "xn--Hello-Another-Way--fc4qua05auwb3674vfr0b",
    363     "xn--2-u9tlzr9756bt3uc0v",
    364     "xn--MajiKoi5-783gue6qz075azm5e",
    365     "xn--de-jg4avhby1noc0d",
    366     "xn--d9juau41awczczp",
    367     "XN--097CCDEKGHQJK",
    368     "XN--db8CBHEJLGH4E0AL",
    369     "xn--hxargifdar",                       /* Greek */
    370     "xn--bonusaa-5bb1da",                   /* Maltese */
    371     "xn--b1abfaaepdrnnbgefbadotcwatmq2g4l",  /* Russian (Cyrillic)*/
    372     "TEST"
    373 
    374 };
    375 
    376 static const char * const domainNames[] = {
    377     "slip129-37-118-146.nc.us.ibm.net",
    378     "saratoga.pe.utexas.edu",
    379     "dial-120-45.ots.utexas.edu",
    380     "woo-085.dorms.waller.net",
    381     "hd30-049.hil.compuserve.com",
    382     "pem203-31.pe.ttu.edu",
    383     "56K-227.MaxTNT3.pdq.net",
    384     "dial-36-2.ots.utexas.edu",
    385     "slip129-37-23-152.ga.us.ibm.net",
    386     "ts45ip119.cadvision.com",
    387     "sdn-ts-004txaustP05.dialsprint.net",
    388     "bar-tnt1s66.erols.com",
    389     "101.st-louis-15.mo.dial-access.att.net",
    390     "h92-245.Arco.COM",
    391     "dial-13-2.ots.utexas.edu",
    392     "net-redynet29.datamarkets.com.ar",
    393     "ccs-shiva28.reacciun.net.ve",
    394     "7.houston-11.tx.dial-access.att.net",
    395     "ingw129-37-120-26.mo.us.ibm.net",
    396     "dialup6.austintx.com",
    397     "dns2.tpao.gov.tr",
    398     "slip129-37-119-194.nc.us.ibm.net",
    399     "cs7.dillons.co.uk.203.119.193.in-addr.arpa",
    400     "swprd1.innovplace.saskatoon.sk.ca",
    401     "bikini.bologna.maraut.it",
    402     "node91.subnet159-198-79.baxter.com",
    403     "cust19.max5.new-york.ny.ms.uu.net",
    404     "balexander.slip.andrew.cmu.edu",
    405     "pool029.max2.denver.co.dynip.alter.net",
    406     "cust49.max9.new-york.ny.ms.uu.net",
    407     "s61.abq-dialin2.hollyberry.com",
    408     "\\u0917\\u0928\\u0947\\u0936.sanjose.ibm.com", /*':'(0x003a) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
    409     "www.xn--vea.com",
    410     /* "www.\\u00E0\\u00B3\\u00AF.com",//' ' (0x0020) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
    411     "www.\\u00C2\\u00A4.com",
    412     "www.\\u00C2\\u00A3.com",
    413     /* "\\u0025", //'%' (0x0025) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
    414     /* "\\u005C\\u005C", //'\' (0x005C) produces U_IDNA_STD3_ASCII_RULES_ERROR*/
    415     /*"@",*/
    416     /*"\\u002F",*/
    417     /*"www.\\u0021.com",*/
    418     /*"www.\\u0024.com",*/
    419     /*"\\u003f",*/
    420     /* These yeild U_IDNA_PROHIBITED_ERROR*/
    421     /*"\\u00CF\\u0082.com",*/
    422     /*"\\u00CE\\u00B2\\u00C3\\u009Fss.com",*/
    423     /*"\\u00E2\\u0098\\u00BA.com",*/
    424     "\\u00C3\\u00BC.com"
    425 
    426 };
    427 
    428 static void
    429 TestToASCII(){
    430 
    431     int32_t i;
    432     UChar buf[MAX_DEST_SIZE];
    433     const char* testName = "uidna_toASCII";
    434     TestFunc func = uidna_toASCII;
    435     for(i=0;i< (int32_t)(sizeof(unicodeIn)/sizeof(unicodeIn[0])); i++){
    436         u_charsToUChars(asciiIn[i],buf, (int32_t)strlen(asciiIn[i])+1);
    437         testAPI(unicodeIn[i], buf,testName, FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
    438 
    439     }
    440 }
    441 
    442 static void
    443 TestToUnicode(){
    444 
    445     int32_t i;
    446     UChar buf[MAX_DEST_SIZE];
    447     const char* testName = "uidna_toUnicode";
    448     TestFunc func = uidna_toUnicode;
    449     for(i=0;i< (int32_t)(sizeof(asciiIn)/sizeof(asciiIn[0])); i++){
    450         u_charsToUChars(asciiIn[i],buf, (int32_t)strlen(asciiIn[i])+1);
    451         testAPI(buf,unicodeIn[i],testName,FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
    452     }
    453 }
    454 
    455 
    456 static void
    457 TestIDNToUnicode(){
    458     int32_t i;
    459     UChar buf[MAX_DEST_SIZE];
    460     UChar expected[MAX_DEST_SIZE];
    461     UErrorCode status = U_ZERO_ERROR;
    462     int32_t bufLen = 0;
    463     UParseError parseError;
    464     const char* testName="uidna_IDNToUnicode";
    465     TestFunc func = uidna_IDNToUnicode;
    466     for(i=0;i< (int32_t)(sizeof(domainNames)/sizeof(domainNames[0])); i++){
    467         bufLen = (int32_t)strlen(domainNames[i]);
    468         bufLen = u_unescape(domainNames[i],buf, bufLen+1);
    469         func(buf,bufLen,expected,MAX_DEST_SIZE, UIDNA_ALLOW_UNASSIGNED, &parseError,&status);
    470         if(U_FAILURE(status)){
    471             log_err_status(status,  "%s failed to convert domainNames[%i].Error: %s \n",testName, i, u_errorName(status));
    472             break;
    473         }
    474         testAPI(buf,expected,testName,FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
    475          /*test toUnicode with all labels in the string*/
    476         testAPI(buf,expected,testName, FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
    477         if(U_FAILURE(status)){
    478             log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName,i, u_errorName(status));
    479             break;
    480         }
    481     }
    482 
    483 }
    484 
    485 static void
    486 TestIDNToASCII(){
    487     int32_t i;
    488     UChar buf[MAX_DEST_SIZE];
    489     UChar expected[MAX_DEST_SIZE];
    490     UErrorCode status = U_ZERO_ERROR;
    491     int32_t bufLen = 0;
    492     UParseError parseError;
    493     const char* testName="udina_IDNToASCII";
    494     TestFunc func=uidna_IDNToASCII;
    495 
    496     for(i=0;i< (int32_t)(sizeof(domainNames)/sizeof(domainNames[0])); i++){
    497         bufLen = (int32_t)strlen(domainNames[i]);
    498         bufLen = u_unescape(domainNames[i],buf, bufLen+1);
    499         func(buf,bufLen,expected,MAX_DEST_SIZE, UIDNA_ALLOW_UNASSIGNED, &parseError,&status);
    500         if(U_FAILURE(status)){
    501             log_err_status(status,  "%s failed to convert domainNames[%i].Error: %s \n",testName,i, u_errorName(status));
    502             break;
    503         }
    504         testAPI(buf,expected,testName, FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
    505         /*test toASCII with all labels in the string*/
    506         testAPI(buf,expected,testName, FALSE,U_ZERO_ERROR, FALSE, TRUE, func);
    507         if(U_FAILURE(status)){
    508             log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName,i, u_errorName(status));
    509             break;
    510         }
    511     }
    512 
    513 
    514 }
    515 
    516 
    517 static void
    518 testCompareWithSrc(const UChar* s1, int32_t s1Len,
    519             const UChar* s2, int32_t s2Len,
    520             const char* testName, CompareFunc func,
    521             UBool isEqual){
    522 
    523     UErrorCode status = U_ZERO_ERROR;
    524     int32_t retVal = func(s1,-1,s2,-1,UIDNA_DEFAULT,&status);
    525 
    526     if(isEqual==TRUE &&  retVal !=0){
    527         log_err("Did not get the expected result for %s with null termniated strings.\n",testName);
    528     }
    529     if(U_FAILURE(status)){
    530         log_err_status(status, "%s null terminated source failed. Error: %s\n", testName,u_errorName(status));
    531     }
    532 
    533     status = U_ZERO_ERROR;
    534     retVal = func(s1,-1,s2,-1,UIDNA_ALLOW_UNASSIGNED,&status);
    535 
    536     if(isEqual==TRUE &&  retVal !=0){
    537         log_err("Did not get the expected result for %s with null termniated strings with options set.\n", testName);
    538     }
    539     if(U_FAILURE(status)){
    540         log_err_status(status, "%s null terminated source and options set failed. Error: %s\n",testName, u_errorName(status));
    541     }
    542 
    543     status = U_ZERO_ERROR;
    544     retVal = func(s1,s1Len,s2,s2Len,UIDNA_DEFAULT,&status);
    545 
    546     if(isEqual==TRUE &&  retVal !=0){
    547         log_err("Did not get the expected result for %s with string length.\n",testName);
    548     }
    549     if(U_FAILURE(status)){
    550         log_err_status(status,  "%s with string length. Error: %s\n",testName, u_errorName(status));
    551     }
    552 
    553     status = U_ZERO_ERROR;
    554     retVal = func(s1,s1Len,s2,s2Len,UIDNA_ALLOW_UNASSIGNED,&status);
    555 
    556     if(isEqual==TRUE &&  retVal !=0){
    557         log_err("Did not get the expected result for %s with string length and options set.\n",testName);
    558     }
    559     if(U_FAILURE(status)){
    560         log_err_status(status,  "%s with string length and options set. Error: %s\n", u_errorName(status), testName);
    561     }
    562 }
    563 
    564 
    565 static void
    566 TestCompare(){
    567     int32_t i;
    568 
    569     const char* testName ="uidna_compare";
    570     CompareFunc func = uidna_compare;
    571 
    572     UChar www[] = {0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
    573     UChar com[] = {0x002E, 0x0043, 0x004F, 0x004D, 0x0000};
    574     UChar buf[MAX_DEST_SIZE]={0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
    575     UChar source[MAX_DEST_SIZE]={0},
    576           uni0[MAX_DEST_SIZE]={0},
    577           uni1[MAX_DEST_SIZE]={0},
    578           ascii0[MAX_DEST_SIZE]={0},
    579           ascii1[MAX_DEST_SIZE]={0},
    580           temp[MAX_DEST_SIZE] ={0};
    581 
    582 
    583     u_strcat(uni0,unicodeIn[0]);
    584     u_strcat(uni0,com);
    585 
    586     u_strcat(uni1,unicodeIn[1]);
    587     u_strcat(uni1,com);
    588 
    589     u_charsToUChars(asciiIn[0], temp, (int32_t)strlen(asciiIn[0]));
    590     u_strcat(ascii0,temp);
    591     u_strcat(ascii0,com);
    592 
    593     memset(temp, 0, U_SIZEOF_UCHAR * MAX_DEST_SIZE);
    594 
    595     u_charsToUChars(asciiIn[1], temp, (int32_t)strlen(asciiIn[1]));
    596     u_strcat(ascii1,temp);
    597     u_strcat(ascii1,com);
    598 
    599     /* prepend www. */
    600     u_strcat(source, www);
    601 
    602     for(i=0;i< (int32_t)(sizeof(unicodeIn)/sizeof(unicodeIn[0])); i++){
    603         UChar* src;
    604         int32_t srcLen;
    605 
    606         memset(buf+4, 0, (MAX_DEST_SIZE-4) * U_SIZEOF_UCHAR);
    607 
    608         u_charsToUChars(asciiIn[i],buf+4, (int32_t)strlen(asciiIn[i]));
    609         u_strcat(buf,com);
    610 
    611 
    612         /* for every entry in unicodeIn array
    613            prepend www. and append .com*/
    614         source[4]=0;
    615         u_strncat(source,unicodeIn[i], u_strlen(unicodeIn[i]));
    616         u_strcat(source,com);
    617 
    618         /* a) compare it with itself*/
    619         src = source;
    620         srcLen = u_strlen(src);
    621 
    622         testCompareWithSrc(src,srcLen,src,srcLen,testName, func, TRUE);
    623 
    624         /* b) compare it with asciiIn equivalent */
    625         testCompareWithSrc(src,srcLen,buf,u_strlen(buf),testName, func,TRUE);
    626 
    627         /* c) compare it with unicodeIn not equivalent*/
    628         if(i==0){
    629             testCompareWithSrc(src,srcLen,uni1,u_strlen(uni1),testName, func,FALSE);
    630         }else{
    631             testCompareWithSrc(src,srcLen,uni0,u_strlen(uni0),testName, func,FALSE);
    632         }
    633         /* d) compare it with asciiIn not equivalent */
    634         if(i==0){
    635             testCompareWithSrc(src,srcLen,ascii1,u_strlen(ascii1),testName, func,FALSE);
    636         }else{
    637             testCompareWithSrc(src,srcLen,ascii0,u_strlen(ascii0),testName, func,FALSE);
    638         }
    639 
    640     }
    641 }
    642 
    643 static void TestJB4490(){
    644     static const UChar data[][50]= {
    645         {0x00F5,0x00dE,0x00dF,0x00dD, 0x0000},
    646         {0xFB00,0xFB01}
    647     };
    648     UChar output1[40] = {0};
    649     UChar output2[40] = {0};
    650     int32_t i;
    651     for(i=0; i< sizeof(data)/sizeof(data[0]); i++){
    652         const UChar* src1 = data[i];
    653         int32_t src1Len = u_strlen(src1);
    654         UChar* dest1 = output1;
    655         int32_t dest1Len = 40;
    656         UErrorCode status = U_ZERO_ERROR;
    657         UParseError ps;
    658         UChar* src2 = NULL;
    659         int32_t src2Len = 0;
    660         UChar* dest2 = output2;
    661         int32_t dest2Len = 40;
    662         dest1Len = uidna_toASCII(src1, src1Len, dest1, dest1Len,UIDNA_DEFAULT, &ps, &status);
    663         if(U_FAILURE(status)){
    664             log_err_status(status, "uidna_toUnicode failed with error %s.\n", u_errorName(status));
    665         }
    666         src2 = dest1;
    667         src2Len = dest1Len;
    668         dest2Len = uidna_toUnicode(src2, src2Len, dest2, dest2Len, UIDNA_DEFAULT, &ps, &status);
    669         if(U_FAILURE(status)){
    670             log_err_status(status, "uidna_toUnicode failed with error %s.\n", u_errorName(status));
    671         }
    672     }
    673 }
    674 
    675 static void TestJB4475(){
    676 
    677     static const UChar input[][10] = {
    678         {0x0054,0x0045,0x0053,0x0054,0x0000},/* TEST */
    679         {0x0074,0x0065,0x0073,0x0074,0x0000} /* test */
    680     };
    681     int i;
    682     UChar output[40] = {0};
    683     for(i=0; i< sizeof(input)/sizeof(input[0]); i++){
    684         const UChar* src = input[i];
    685         int32_t srcLen = u_strlen(src);
    686         UChar* dest = output;
    687         int32_t destLen = 40;
    688         UErrorCode status = U_ZERO_ERROR;
    689         UParseError ps;
    690 
    691         destLen = uidna_toASCII(src, srcLen, dest, destLen,UIDNA_DEFAULT, &ps, &status);
    692         if(U_FAILURE(status)){
    693             log_err_status(status, "uidna_toASCII failed with error %s.\n", u_errorName(status));
    694             continue;
    695         }
    696         if(u_strncmp(input[i], dest, srcLen)!=0){
    697             log_err("uidna_toASCII did not return the expected output.\n");
    698         }
    699     }
    700 }
    701 
    702 static void TestLength(){
    703     {
    704         static const char* cl = "my_very_very_very_very_very_very_very_very_very_very_very_very_very_long_and_incredibly_uncreative_domain_label";
    705         UChar ul[128] = {'\0'};
    706         UChar dest[256] = {'\0'};
    707         /* this unicode string is longer than MAX_LABEL_BUFFER_SIZE and produces an
    708            IDNA prepared string (including xn--)that is exactly 63 bytes long */
    709         UChar ul1[] = { 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
    710                         0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0x00AD, 0x034F, 0x1806, 0x180B,
    711                         0x180C, 0x180D, 0x200B, 0x200C, 0x200D, 0x2060, 0xFE00, 0xFE01, 0xFE02,
    712                         0xFE03, 0xFE04, 0xFE05, 0xFE06, 0xFE07, 0xFE08, 0xFE09, 0xFE0A, 0xFE0B,
    713                         0xFE0C, 0xFE0D, 0xFE0E, 0xFE0F, 0xFEFF, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
    714                         0xC138, 0x0041, 0x00AD, 0x034F, 0x1806, 0x180B, 0x180C, 0x180D, 0x200B,
    715                         0x200C, 0x200D, 0x2060, 0xFE00, 0xFE01, 0xFE02, 0xFE03, 0xFE04, 0xFE05,
    716                         0xFE06, 0xFE07, 0xFE08, 0xFE09, 0xFE0A, 0xFE0B, 0xFE0C, 0xFE0D, 0xFE0E,
    717                         0xFE0F, 0xFEFF, 0x00AD, 0x034F, 0x1806, 0x180B, 0x180C, 0x180D, 0x200B,
    718                         0x200C, 0x200D, 0x2060, 0xFE00, 0xFE01, 0xFE02, 0xFE03, 0xFE04, 0xFE05,
    719                         0xFE06, 0xFE07, 0xFE08, 0xFE09, 0xFE0A, 0xFE0B, 0xFE0C, 0xFE0D, 0xFE0E,
    720                         0xFE0F, 0xFEFF, 0x00AD, 0x034F, 0x1806, 0x180B, 0x180C, 0x180D, 0x200B,
    721                         0x200C, 0x200D, 0x2060, 0xFE00, 0xFE01, 0xFE02, 0xFE03, 0xFE04, 0xFE05,
    722                         0xFE06, 0xFE07, 0xFE08, 0xFE09, 0xFE0A, 0xFE0B, 0xFE0C, 0xFE0D, 0xFE0E,
    723                         0xFE0F, 0xFEFF, 0x0000
    724                       };
    725 
    726         int32_t len1 = LENGTHOF(ul1)-1/*remove the null termination*/;
    727         int32_t destLen = LENGTHOF(dest);
    728         UErrorCode status = U_ZERO_ERROR;
    729         UParseError ps;
    730         int32_t len = (int32_t)strlen(cl);
    731         u_charsToUChars(cl, ul, len+1);
    732         destLen = uidna_toUnicode(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
    733         if(status != U_ZERO_ERROR){
    734             log_err_status(status, "uidna_toUnicode failed with error %s.\n", u_errorName(status));
    735         }
    736 
    737         status = U_ZERO_ERROR;
    738         destLen = LENGTHOF(dest);
    739         len = -1;
    740         destLen = uidna_toUnicode(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
    741         if(status != U_ZERO_ERROR){
    742             log_err_status(status, "uidna_toUnicode failed with error %s.\n", u_errorName(status));
    743         }
    744         status = U_ZERO_ERROR;
    745         destLen = LENGTHOF(dest);
    746         len = (int32_t)strlen(cl);
    747         destLen = uidna_toASCII(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
    748         if(status != U_IDNA_LABEL_TOO_LONG_ERROR){
    749             log_err_status(status, "uidna_toASCII failed with error %s.\n", u_errorName(status));
    750         }
    751 
    752         status = U_ZERO_ERROR;
    753         destLen = LENGTHOF(dest);
    754         len = -1;
    755         destLen = uidna_toASCII(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
    756         if(status != U_IDNA_LABEL_TOO_LONG_ERROR){
    757             log_err_status(status, "uidna_toASCII failed with error %s.\n", u_errorName(status));
    758         }
    759 
    760         status = U_ZERO_ERROR;
    761         destLen = LENGTHOF(dest);
    762         destLen = uidna_toASCII(ul1, len1, dest, destLen, UIDNA_DEFAULT, &ps, &status);
    763         if(status != U_ZERO_ERROR){
    764             log_err_status(status, "uidna_toASCII failed with error %s.\n", u_errorName(status));
    765         }
    766 
    767         status = U_ZERO_ERROR;
    768         destLen = LENGTHOF(dest);
    769         len1 = -1;
    770         destLen = uidna_toASCII(ul1, len1, dest, destLen, UIDNA_DEFAULT, &ps, &status);
    771         if(status != U_ZERO_ERROR){
    772             log_err_status(status, "uidna_toASCII failed with error %s.\n", u_errorName(status));
    773         }
    774     }
    775     {
    776         static const char* cl = "my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.my_very_very_long_and_incredibly_uncreative_domain_label.ibm.com";
    777         UChar ul[400] = {'\0'};
    778         UChar dest[400] = {'\0'};
    779         int32_t destLen = LENGTHOF(dest);
    780         UErrorCode status = U_ZERO_ERROR;
    781         UParseError ps;
    782         int32_t len = (int32_t)strlen(cl);
    783         u_charsToUChars(cl, ul, len+1);
    784 
    785         destLen = uidna_IDNToUnicode(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
    786         if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
    787             log_err_status(status, "uidna_IDNToUnicode failed with error %s.\n", u_errorName(status));
    788         }
    789 
    790         status = U_ZERO_ERROR;
    791         destLen = LENGTHOF(dest);
    792         len = -1;
    793         destLen = uidna_IDNToUnicode(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
    794         if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
    795             log_err_status(status, "uidna_IDNToUnicode failed with error %s.\n", u_errorName(status));
    796         }
    797 
    798         status = U_ZERO_ERROR;
    799         destLen = LENGTHOF(dest);
    800         len = (int32_t)strlen(cl);
    801         destLen = uidna_IDNToASCII(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
    802         if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
    803             log_err_status(status, "uidna_IDNToASCII failed with error %s.\n", u_errorName(status));
    804         }
    805 
    806         status = U_ZERO_ERROR;
    807         destLen = LENGTHOF(dest);
    808         len = -1;
    809         destLen = uidna_IDNToASCII(ul, len, dest, destLen, UIDNA_DEFAULT, &ps, &status);
    810         if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
    811             log_err_status(status, "uidna_IDNToASCII failed with error %s.\n", u_errorName(status));
    812         }
    813 
    814         status = U_ZERO_ERROR;
    815         uidna_compare(ul, len, ul, len, UIDNA_DEFAULT, &status);
    816         if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
    817             log_err_status(status, "uidna_compare failed with error %s.\n", u_errorName(status));
    818         }
    819         uidna_compare(ul, -1, ul, -1, UIDNA_DEFAULT, &status);
    820         if(status != U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR){
    821             log_err_status(status, "uidna_compare failed with error %s.\n", u_errorName(status));
    822         }
    823     }
    824 }
    825 static void TestJB5273(){
    826     static const char INVALID_DOMAIN_NAME[] = "xn--m\\u00FCller.de";
    827     UChar invalid_idn[25] = {'\0'};
    828     int32_t len = u_unescape(INVALID_DOMAIN_NAME, invalid_idn, strlen(INVALID_DOMAIN_NAME));
    829     UChar output[50] = {'\0'};
    830     UErrorCode status = U_ZERO_ERROR;
    831     UParseError prsError;
    832     int32_t outLen = uidna_toUnicode(invalid_idn, len, output, 50, UIDNA_DEFAULT, &prsError, &status);
    833     if(U_FAILURE(status)){
    834         log_err_status(status, "uidna_toUnicode failed with error: %s\n", u_errorName(status));
    835     }
    836     status = U_ZERO_ERROR;
    837     outLen = uidna_toUnicode(invalid_idn, len, output, 50, UIDNA_USE_STD3_RULES, &prsError, &status);
    838     if(U_FAILURE(status)){
    839         log_err_status(status, "uidna_toUnicode failed with error: %s\n", u_errorName(status));
    840     }
    841 
    842     status = U_ZERO_ERROR;
    843     outLen = uidna_IDNToUnicode(invalid_idn, len, output, 50, UIDNA_DEFAULT, &prsError, &status);
    844     if(U_FAILURE(status)){
    845         log_err_status(status, "uidna_toUnicode failed with error: %s\n", u_errorName(status));
    846     }
    847     status = U_ZERO_ERROR;
    848     outLen = uidna_IDNToUnicode(invalid_idn, len, output, 50, UIDNA_USE_STD3_RULES, &prsError, &status);
    849     if(U_FAILURE(status)){
    850         log_err_status(status, "uidna_toUnicode failed with error: %s\n", u_errorName(status));
    851     }
    852 }
    853 
    854 /*
    855  * Test the new (ICU 4.6/2010) C API that was added for UTS #46.
    856  * Just an API test: Functionality is tested via C++ intltest.
    857  */
    858 static void TestUTS46() {
    859     static const UChar fA_sharps16[] = { 0x66, 0x41, 0xdf, 0 };
    860     static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
    861     static const UChar fa_sharps16[] = { 0x66, 0x61, 0xdf, 0 };
    862     static const char fa_sharps8[] = { 0x66, 0x61, (char)0xc3, (char)0x9f, 0 };
    863     static const UChar fass16[] = { 0x66, 0x61, 0x73, 0x73, 0 };
    864     static const char fass8[] = { 0x66, 0x61, 0x73, 0x73, 0 };
    865     static const UChar fA_BEL[] = { 0x66, 0x41, 7, 0 };
    866     static const UChar fa_FFFD[] = { 0x66, 0x61, 0xfffd, 0 };
    867 
    868     UChar dest16[10];
    869     char dest8[10];
    870     int32_t length;
    871 
    872     UIDNAInfo info = UIDNA_INFO_INITIALIZER;
    873     UErrorCode errorCode = U_ZERO_ERROR;
    874     UIDNA *uts46 = uidna_openUTS46(UIDNA_USE_STD3_RULES|UIDNA_NONTRANSITIONAL_TO_UNICODE,
    875                                    &errorCode);
    876     if(U_FAILURE(errorCode)) {
    877         log_err_status(errorCode, "uidna_openUTS46() failed: %s\n", u_errorName(errorCode));
    878         return;
    879     }
    880 
    881     /* These calls should succeed. */
    882     length = uidna_labelToASCII(uts46, fA_sharps16, -1,
    883                                 dest16, LENGTHOF(dest16), &info, &errorCode);
    884     if( U_FAILURE(errorCode) || length != 4 || 0 != u_memcmp(dest16, fass16, 5) ||
    885         !info.isTransitionalDifferent || info.errors != 0
    886     ) {
    887         log_err("uidna_labelToASCII() failed: %s\n", u_errorName(errorCode));
    888     }
    889     errorCode = U_ZERO_ERROR;
    890     length = uidna_labelToUnicode(uts46, fA_sharps16, u_strlen(fA_sharps16),
    891                                   dest16, LENGTHOF(dest16), &info, &errorCode);
    892     if( U_FAILURE(errorCode) || length != 3 || 0 != u_memcmp(dest16, fa_sharps16, 4) ||
    893         !info.isTransitionalDifferent || info.errors != 0
    894     ) {
    895         log_err("uidna_labelToUnicode() failed: %s\n", u_errorName(errorCode));
    896     }
    897     errorCode = U_ZERO_ERROR;
    898     length = uidna_nameToASCII(uts46, fA_sharps16, u_strlen(fA_sharps16),
    899                                dest16, 4, &info, &errorCode);
    900     if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
    901         length != 4 || 0 != u_memcmp(dest16, fass16, 4) ||
    902         !info.isTransitionalDifferent || info.errors != 0
    903     ) {
    904         log_err("uidna_nameToASCII() failed: %s\n", u_errorName(errorCode));
    905     }
    906     errorCode = U_ZERO_ERROR;
    907     length = uidna_nameToUnicode(uts46, fA_sharps16, -1,
    908                                  dest16, 3, &info, &errorCode);
    909     if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
    910         length != 3 || 0 != u_memcmp(dest16, fa_sharps16, 3) ||
    911         !info.isTransitionalDifferent || info.errors != 0
    912     ) {
    913         log_err("uidna_nameToUnicode() failed: %s\n", u_errorName(errorCode));
    914     }
    915 
    916     errorCode = U_ZERO_ERROR;
    917     length = uidna_labelToASCII_UTF8(uts46, fA_sharps8, -1,
    918                                      dest8, LENGTHOF(dest8), &info, &errorCode);
    919     if( U_FAILURE(errorCode) || length != 4 || 0 != memcmp(dest8, fass8, 5) ||
    920         !info.isTransitionalDifferent || info.errors != 0
    921     ) {
    922         log_err("uidna_labelToASCII_UTF8() failed: %s\n", u_errorName(errorCode));
    923     }
    924     errorCode = U_ZERO_ERROR;
    925     length = uidna_labelToUnicodeUTF8(uts46, fA_sharps8, strlen(fA_sharps8),
    926                                       dest8, LENGTHOF(dest8), &info, &errorCode);
    927     if( U_FAILURE(errorCode) || length != 4 || 0 != memcmp(dest8, fa_sharps8, 5) ||
    928         !info.isTransitionalDifferent || info.errors != 0
    929     ) {
    930         log_err("uidna_labelToUnicodeUTF8() failed: %s\n", u_errorName(errorCode));
    931     }
    932     errorCode = U_ZERO_ERROR;
    933     length = uidna_nameToASCII_UTF8(uts46, fA_sharps8, strlen(fA_sharps8),
    934                                     dest8, 4, &info, &errorCode);
    935     if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
    936         length != 4 || 0 != memcmp(dest8, fass8, 4) ||
    937         !info.isTransitionalDifferent || info.errors != 0
    938     ) {
    939         log_err("uidna_nameToASCII_UTF8() failed: %s\n", u_errorName(errorCode));
    940     }
    941     errorCode = U_ZERO_ERROR;
    942     length = uidna_nameToUnicodeUTF8(uts46, fA_sharps8, -1,
    943                                      dest8, 4, &info, &errorCode);
    944     if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
    945         length != 4 || 0 != memcmp(dest8, fa_sharps8, 4) ||
    946         !info.isTransitionalDifferent || info.errors != 0
    947     ) {
    948         log_err("uidna_nameToUnicodeUTF8() failed: %s\n", u_errorName(errorCode));
    949     }
    950 
    951     errorCode = U_ZERO_ERROR;
    952     length = uidna_nameToASCII(uts46, NULL, 0,
    953                                dest16, 0, &info, &errorCode);
    954     if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
    955         length != 0 ||
    956         info.isTransitionalDifferent || info.errors != UIDNA_ERROR_EMPTY_LABEL
    957     ) {
    958         log_err("uidna_nameToASCII(empty) failed: %s\n", u_errorName(errorCode));
    959     }
    960     errorCode = U_ZERO_ERROR;
    961     length = uidna_nameToUnicode(uts46, fA_BEL, -1,
    962                                  dest16, 3, &info, &errorCode);
    963     if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
    964         length != 3 || 0 != u_memcmp(dest16, fa_FFFD, 3) ||
    965         info.isTransitionalDifferent || info.errors == 0
    966     ) {
    967         log_err("uidna_nameToUnicode(fa<BEL>) failed: %s\n", u_errorName(errorCode));
    968     }
    969 
    970     /* These calls should fail. */
    971     errorCode = U_USELESS_COLLATOR_ERROR;
    972     length = uidna_labelToASCII(uts46, fA_sharps16, -1,
    973                                 dest16, LENGTHOF(dest16), &info, &errorCode);
    974     if(errorCode != U_USELESS_COLLATOR_ERROR) {
    975         log_err("uidna_labelToASCII(failure) failed: %s\n", u_errorName(errorCode));
    976     }
    977     errorCode = U_ZERO_ERROR;
    978     length = uidna_labelToUnicode(uts46, fA_sharps16, u_strlen(fA_sharps16),
    979                                   dest16, LENGTHOF(dest16), NULL, &errorCode);
    980     if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
    981         log_err("uidna_labelToUnicode(UIDNAInfo=NULL) failed: %s\n", u_errorName(errorCode));
    982     }
    983     errorCode = U_ZERO_ERROR;
    984     length = uidna_nameToASCII(uts46, NULL, u_strlen(fA_sharps16),
    985                                dest16, 4, &info, &errorCode);
    986     if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
    987         log_err("uidna_nameToASCII(src=NULL) failed: %s\n", u_errorName(errorCode));
    988     }
    989     errorCode = U_ZERO_ERROR;
    990     length = uidna_nameToUnicode(uts46, fA_sharps16, -2,
    991                                  dest16, 3, &info, &errorCode);
    992     if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
    993         log_err("uidna_nameToUnicode(length<-1) failed: %s\n", u_errorName(errorCode));
    994     }
    995 
    996     errorCode = U_ZERO_ERROR;
    997     length = uidna_labelToASCII_UTF8(uts46, fA_sharps8, -1,
    998                                      NULL, LENGTHOF(dest8), &info, &errorCode);
    999     if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
   1000         log_err("uidna_labelToASCII_UTF8(dest=NULL) failed: %s\n", u_errorName(errorCode));
   1001     }
   1002     errorCode = U_ZERO_ERROR;
   1003     length = uidna_labelToUnicodeUTF8(uts46, fA_sharps8, strlen(fA_sharps8),
   1004                                       dest8, -1, &info, &errorCode);
   1005     if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
   1006         log_err("uidna_labelToUnicodeUTF8(capacity<0) failed: %s\n", u_errorName(errorCode));
   1007     }
   1008     errorCode = U_ZERO_ERROR;
   1009     length = uidna_nameToASCII_UTF8(uts46, dest8, strlen(fA_sharps8),
   1010                                     dest8, 4, &info, &errorCode);
   1011     if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
   1012         log_err("uidna_nameToASCII_UTF8(src==dest!=NULL) failed: %s\n", u_errorName(errorCode));
   1013     }
   1014     errorCode = U_ZERO_ERROR;
   1015     length = uidna_nameToUnicodeUTF8(uts46, fA_sharps8, -1,
   1016                                      dest8, 3, &info, &errorCode);
   1017     if(errorCode != U_BUFFER_OVERFLOW_ERROR || length != 4) {
   1018         log_err("uidna_nameToUnicodeUTF8() overflow failed: %s\n", u_errorName(errorCode));
   1019     }
   1020 
   1021     uidna_close(uts46);
   1022 }
   1023 
   1024 #endif
   1025 
   1026 /*
   1027  * Hey, Emacs, please set the following:
   1028  *
   1029  * Local Variables:
   1030  * indent-tabs-mode: nil
   1031  * End:
   1032  *
   1033  */
   1034