Home | History | Annotate | Download | only in cintltst
      1 /********************************************************************
      2  * COPYRIGHT:
      3  * Copyright (c) 1997-2011, International Business Machines Corporation and
      4  * others. All Rights Reserved.
      5  ********************************************************************/
      6 
      7 #include "cintltst.h"
      8 #include "unicode/ures.h"
      9 #include "unicode/ucurr.h"
     10 #include "unicode/ustring.h"
     11 #include "unicode/uset.h"
     12 #include "unicode/udat.h"
     13 #include "unicode/uscript.h"
     14 #include "unicode/ulocdata.h"
     15 #include "cstring.h"
     16 #include "locmap.h"
     17 #include "uresimp.h"
     18 
     19 /*
     20 returns a new UnicodeSet that is a flattened form of the original
     21 UnicodeSet.
     22 */
     23 static USet*
     24 createFlattenSet(USet *origSet, UErrorCode *status) {
     25 
     26 
     27     USet *newSet = NULL;
     28     int32_t origItemCount = 0;
     29     int32_t idx, graphmeSize;
     30     UChar32 start, end;
     31     UChar graphme[64];
     32     if (U_FAILURE(*status)) {
     33         log_err("createFlattenSet called with %s\n", u_errorName(*status));
     34         return NULL;
     35     }
     36     newSet = uset_open(1, 0);
     37     origItemCount = uset_getItemCount(origSet);
     38     for (idx = 0; idx < origItemCount; idx++) {
     39         graphmeSize = uset_getItem(origSet, idx,
     40             &start, &end,
     41             graphme, (int32_t)(sizeof(graphme)/sizeof(graphme[0])),
     42             status);
     43         if (U_FAILURE(*status)) {
     44             log_err("ERROR: uset_getItem returned %s\n", u_errorName(*status));
     45             *status = U_ZERO_ERROR;
     46         }
     47         if (graphmeSize) {
     48             uset_addAllCodePoints(newSet, graphme, graphmeSize);
     49         }
     50         else {
     51             uset_addRange(newSet, start, end);
     52         }
     53     }
     54     uset_closeOver(newSet,USET_CASE_INSENSITIVE);
     55     return newSet;
     56 }
     57 
     58 static UBool
     59 isCurrencyPreEuro(const char* currencyKey){
     60     if( strcmp(currencyKey, "PTE") == 0 ||
     61         strcmp(currencyKey, "ESP") == 0 ||
     62         strcmp(currencyKey, "LUF") == 0 ||
     63         strcmp(currencyKey, "GRD") == 0 ||
     64         strcmp(currencyKey, "BEF") == 0 ||
     65         strcmp(currencyKey, "ITL") == 0 ||
     66         strcmp(currencyKey, "EEK") == 0){
     67             return TRUE;
     68     }
     69     return FALSE;
     70 }
     71 static void
     72 TestKeyInRootRecursive(UResourceBundle *root, const char *rootName,
     73                        UResourceBundle *currentBundle, const char *locale) {
     74     UErrorCode errorCode = U_ZERO_ERROR;
     75     UResourceBundle *subRootBundle = NULL, *subBundle = NULL, *arr = NULL;
     76 
     77     ures_resetIterator(root);
     78     ures_resetIterator(currentBundle);
     79     while (ures_hasNext(currentBundle)) {
     80         const char *subBundleKey = NULL;
     81         const char *currentBundleKey = NULL;
     82 
     83         errorCode = U_ZERO_ERROR;
     84         currentBundleKey = ures_getKey(currentBundle);
     85         subBundle = ures_getNextResource(currentBundle, NULL, &errorCode);
     86         if (U_FAILURE(errorCode)) {
     87             log_err("Can't open a resource for lnocale %s. Error: %s\n", locale, u_errorName(errorCode));
     88             continue;
     89         }
     90         subBundleKey = ures_getKey(subBundle);
     91 
     92 
     93         subRootBundle = ures_getByKey(root, subBundleKey, NULL, &errorCode);
     94         if (U_FAILURE(errorCode)) {
     95             log_err("Can't open a resource with key \"%s\" in \"%s\" from %s for locale \"%s\"\n",
     96                     subBundleKey,
     97                     ures_getKey(currentBundle),
     98                     rootName,
     99                     locale);
    100             ures_close(subBundle);
    101             continue;
    102         }
    103         if (ures_getType(subRootBundle) != ures_getType(subBundle)) {
    104             log_err("key \"%s\" in \"%s\" has a different type from root for locale \"%s\"\n"
    105                     "\troot=%d, locale=%d\n",
    106                     subBundleKey,
    107                     ures_getKey(currentBundle),
    108                     locale,
    109                     ures_getType(subRootBundle),
    110                     ures_getType(subBundle));
    111             ures_close(subBundle);
    112             continue;
    113         }
    114         else if (ures_getType(subBundle) == URES_INT_VECTOR) {
    115             int32_t minSize;
    116             int32_t subBundleSize;
    117             int32_t idx;
    118             UBool sameArray = TRUE;
    119             const int32_t *subRootBundleArr = ures_getIntVector(subRootBundle, &minSize, &errorCode);
    120             const int32_t *subBundleArr = ures_getIntVector(subBundle, &subBundleSize, &errorCode);
    121 
    122             if (minSize > subBundleSize) {
    123                 minSize = subBundleSize;
    124                 log_err("Arrays are different size with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
    125                         subBundleKey,
    126                         ures_getKey(currentBundle),
    127                         locale);
    128             }
    129 
    130             for (idx = 0; idx < minSize && sameArray; idx++) {
    131                 if (subRootBundleArr[idx] != subBundleArr[idx]) {
    132                     sameArray = FALSE;
    133                 }
    134                 if (strcmp(subBundleKey, "DateTimeElements") == 0
    135                     && (subBundleArr[idx] < 1 || 7 < subBundleArr[idx]))
    136                 {
    137                     log_err("Value out of range with key \"%s\" at index %d in \"%s\" for locale \"%s\"\n",
    138                             subBundleKey,
    139                             idx,
    140                             ures_getKey(currentBundle),
    141                             locale);
    142                 }
    143             }
    144             /* Special exception es_US and DateTimeElements */
    145             if (sameArray
    146                 && !(strcmp(locale, "es_US") == 0 && strcmp(subBundleKey, "DateTimeElements") == 0))
    147             {
    148                 log_err("Integer vectors are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
    149                         subBundleKey,
    150                         ures_getKey(currentBundle),
    151                         locale);
    152             }
    153         }
    154         else if (ures_getType(subBundle) == URES_ARRAY) {
    155             UResourceBundle *subSubBundle = ures_getByIndex(subBundle, 0, NULL, &errorCode);
    156             UResourceBundle *subSubRootBundle = ures_getByIndex(subRootBundle, 0, NULL, &errorCode);
    157 
    158             if (U_SUCCESS(errorCode)
    159                 && (ures_getType(subSubBundle) == URES_ARRAY || ures_getType(subSubRootBundle) == URES_ARRAY))
    160             {
    161                 /* Here is one of the recursive parts */
    162                 TestKeyInRootRecursive(subRootBundle, rootName, subBundle, locale);
    163             }
    164             else {
    165                 int32_t minSize = ures_getSize(subRootBundle);
    166                 int32_t idx;
    167                 UBool sameArray = TRUE;
    168 
    169                 if (minSize > ures_getSize(subBundle)) {
    170                     minSize = ures_getSize(subBundle);
    171                 }
    172 
    173                 if ((subBundleKey == NULL
    174                     || (subBundleKey != NULL &&  strcmp(subBundleKey, "LocaleScript") != 0 && !isCurrencyPreEuro(subBundleKey)))
    175                     && ures_getSize(subRootBundle) != ures_getSize(subBundle))
    176                 {
    177                     log_err("Different size array with key \"%s\" in \"%s\" from root for locale \"%s\"\n"
    178                             "\troot array size=%d, locale array size=%d\n",
    179                             subBundleKey,
    180                             ures_getKey(currentBundle),
    181                             locale,
    182                             ures_getSize(subRootBundle),
    183                             ures_getSize(subBundle));
    184                 }
    185                 /*
    186                 if(isCurrencyPreEuro(subBundleKey) && ures_getSize(subBundle)!=3){
    187                     log_err("Different size array with key \"%s\" in \"%s\" for locale \"%s\" the expected size is 3 got size=%d\n",
    188                             subBundleKey,
    189                             ures_getKey(currentBundle),
    190                             locale,
    191                             ures_getSize(subBundle));
    192                 }
    193                 */
    194                 for (idx = 0; idx < minSize; idx++) {
    195                     int32_t rootStrLen, localeStrLen;
    196                     const UChar *rootStr = ures_getStringByIndex(subRootBundle,idx,&rootStrLen,&errorCode);
    197                     const UChar *localeStr = ures_getStringByIndex(subBundle,idx,&localeStrLen,&errorCode);
    198                     if (rootStr && localeStr && U_SUCCESS(errorCode)) {
    199                         if (u_strcmp(rootStr, localeStr) != 0) {
    200                             sameArray = FALSE;
    201                         }
    202                     }
    203                     else {
    204                         if ( rootStrLen > 1 && rootStr[0] == 0x41 && rootStr[1] >= 0x30 && rootStr[1] <= 0x39 ) {
    205                            /* A2 or A4 in the root string indicates that the resource can optionally be an array instead of a */
    206                            /* string.  Attempt to read it as an array. */
    207                           errorCode = U_ZERO_ERROR;
    208                           arr = ures_getByIndex(subBundle,idx,NULL,&errorCode);
    209                           if (U_FAILURE(errorCode)) {
    210                               log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
    211                                       subBundleKey,
    212                                       ures_getKey(currentBundle),
    213                                       idx,
    214                                       locale);
    215                               continue;
    216                           }
    217                           if (ures_getType(arr) != URES_ARRAY || ures_getSize(arr) != (int32_t)rootStr[1] - 0x30) {
    218                               log_err("Got something other than a string or array of size %d for key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
    219                                       rootStr[1] - 0x30,
    220                                       subBundleKey,
    221                                       ures_getKey(currentBundle),
    222                                       idx,
    223                                       locale);
    224                               ures_close(arr);
    225                               continue;
    226                           }
    227                           localeStr = ures_getStringByIndex(arr,0,&localeStrLen,&errorCode);
    228                           ures_close(arr);
    229                           if (U_FAILURE(errorCode)) {
    230                               log_err("Got something other than a string or array for key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
    231                                       subBundleKey,
    232                                       ures_getKey(currentBundle),
    233                                       idx,
    234                                       locale);
    235                               continue;
    236                           }
    237                         } else {
    238                             log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
    239                                 subBundleKey,
    240                                 ures_getKey(currentBundle),
    241                                 idx,
    242                                 locale);
    243                             continue;
    244                         }
    245                     }
    246                     if (localeStr[0] == (UChar)0x20) {
    247                         log_err("key \"%s\" at index %d in \"%s\" starts with a space in locale \"%s\"\n",
    248                                 subBundleKey,
    249                                 idx,
    250                                 ures_getKey(currentBundle),
    251                                 locale);
    252                     }
    253                     else if ((localeStr[localeStrLen - 1] == (UChar)0x20) && (strcmp(subBundleKey,"separator") != 0)) {
    254                         log_err("key \"%s\" at index %d in \"%s\" ends with a space in locale \"%s\"\n",
    255                                 subBundleKey,
    256                                 idx,
    257                                 ures_getKey(currentBundle),
    258                                 locale);
    259                     }
    260                     else if (subBundleKey != NULL
    261                         && strcmp(subBundleKey, "DateTimePatterns") == 0)
    262                     {
    263                         int32_t quoted = 0;
    264                         const UChar *localeStrItr = localeStr;
    265                         while (*localeStrItr) {
    266                             if (*localeStrItr == (UChar)0x27 /* ' */) {
    267                                 quoted++;
    268                             }
    269                             else if ((quoted % 2) == 0) {
    270                                 /* Search for unquoted characters */
    271                                 if (4 <= idx && idx <= 7
    272                                     && (*localeStrItr == (UChar)0x6B /* k */
    273                                     || *localeStrItr == (UChar)0x48 /* H */
    274                                     || *localeStrItr == (UChar)0x6D /* m */
    275                                     || *localeStrItr == (UChar)0x73 /* s */
    276                                     || *localeStrItr == (UChar)0x53 /* S */
    277                                     || *localeStrItr == (UChar)0x61 /* a */
    278                                     || *localeStrItr == (UChar)0x68 /* h */
    279                                     || *localeStrItr == (UChar)0x7A /* z */))
    280                                 {
    281                                     log_err("key \"%s\" at index %d has time pattern chars in date for locale \"%s\"\n",
    282                                             subBundleKey,
    283                                             idx,
    284                                             locale);
    285                                 }
    286                                 else if (0 <= idx && idx <= 3
    287                                     && (*localeStrItr == (UChar)0x47 /* G */
    288                                     || *localeStrItr == (UChar)0x79 /* y */
    289                                     || *localeStrItr == (UChar)0x4D /* M */
    290                                     || *localeStrItr == (UChar)0x64 /* d */
    291                                     || *localeStrItr == (UChar)0x45 /* E */
    292                                     || *localeStrItr == (UChar)0x44 /* D */
    293                                     || *localeStrItr == (UChar)0x46 /* F */
    294                                     || *localeStrItr == (UChar)0x77 /* w */
    295                                     || *localeStrItr == (UChar)0x57 /* W */))
    296                                 {
    297                                     log_err("key \"%s\" at index %d has date pattern chars in time for locale \"%s\"\n",
    298                                             subBundleKey,
    299                                             idx,
    300                                             locale);
    301                                 }
    302                             }
    303                             localeStrItr++;
    304                         }
    305                     }
    306                     else if (idx == 4 && subBundleKey != NULL
    307                         && strcmp(subBundleKey, "NumberElements") == 0
    308                         && u_charDigitValue(localeStr[0]) != 0)
    309                     {
    310                         log_err("key \"%s\" at index %d has a non-zero based number for locale \"%s\"\n",
    311                                 subBundleKey,
    312                                 idx,
    313                                 locale);
    314                     }
    315                 }
    316 /*                if (sameArray && strcmp(rootName, "root") == 0) {
    317                     log_err("Arrays are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
    318                             subBundleKey,
    319                             ures_getKey(currentBundle),
    320                             locale);
    321                 }*/
    322             }
    323             ures_close(subSubBundle);
    324             ures_close(subSubRootBundle);
    325         }
    326         else if (ures_getType(subBundle) == URES_STRING) {
    327             int32_t len = 0;
    328             const UChar *string = ures_getString(subBundle, &len, &errorCode);
    329             if (U_FAILURE(errorCode) || string == NULL) {
    330                 log_err("Can't open a string with key \"%s\" in \"%s\" for locale \"%s\"\n",
    331                         subBundleKey,
    332                         ures_getKey(currentBundle),
    333                         locale);
    334             } else if (string[0] == (UChar)0x20) {
    335                 log_err("key \"%s\" in \"%s\" starts with a space in locale \"%s\"\n",
    336                         subBundleKey,
    337                         ures_getKey(currentBundle),
    338                         locale);
    339             /* localeDisplayPattern/separator can end with a space */
    340             } else if (string[len - 1] == (UChar)0x20 && (strcmp(subBundleKey,"separator"))) {
    341                 log_err("key \"%s\" in \"%s\" ends with a space in locale \"%s\"\n",
    342                         subBundleKey,
    343                         ures_getKey(currentBundle),
    344                         locale);
    345             } else if (strcmp(subBundleKey, "localPatternChars") == 0) {
    346                 /* Note: We no longer import localPatternChars data starting
    347                  * ICU 3.8.  So it never comes into this else if block. (ticket#5597)
    348                  */
    349 
    350                 /* Check well-formedness of localPatternChars.  First, the
    351                  * length must match the number of fields defined by
    352                  * DateFormat.  Second, each character in the string must
    353                  * be in the set [A-Za-z].  Finally, each character must be
    354                  * unique.
    355                  */
    356                 int32_t i,j;
    357 #if !UCONFIG_NO_FORMATTING
    358                 if (len != UDAT_FIELD_COUNT) {
    359                     log_err("key \"%s\" has the wrong number of characters in locale \"%s\"\n",
    360                             subBundleKey,
    361                             locale);
    362                 }
    363 #endif
    364                 /* Check char validity. */
    365                 for (i=0; i<len; ++i) {
    366                     if (!((string[i] >= 65/*'A'*/ && string[i] <= 90/*'Z'*/) ||
    367                           (string[i] >= 97/*'a'*/ && string[i] <= 122/*'z'*/))) {
    368                         log_err("key \"%s\" has illegal character '%c' in locale \"%s\"\n",
    369                                 subBundleKey,
    370                                 (char) string[i],
    371                                 locale);
    372                     }
    373                     /* Do O(n^2) check for duplicate chars. */
    374                     for (j=0; j<i; ++j) {
    375                         if (string[j] == string[i]) {
    376                             log_err("key \"%s\" has duplicate character '%c' in locale \"%s\"\n",
    377                                     subBundleKey,
    378                                     (char) string[i],
    379                                     locale);
    380                         }
    381                     }
    382                 }
    383             }
    384             /* No fallback was done. Check for duplicate data */
    385             /* The ures_* API does not do fallback of sub-resource bundles,
    386                So we can't do this now. */
    387 #if 0
    388             else if (strcmp(locale, "root") != 0 && errorCode == U_ZERO_ERROR) {
    389 
    390                 const UChar *rootString = ures_getString(subRootBundle, &len, &errorCode);
    391                 if (U_FAILURE(errorCode) || rootString == NULL) {
    392                     log_err("Can't open a string with key \"%s\" in \"%s\" in root\n",
    393                             ures_getKey(subRootBundle),
    394                             ures_getKey(currentBundle));
    395                     continue;
    396                 } else if (u_strcmp(string, rootString) == 0) {
    397                     if (strcmp(locale, "de_CH") != 0 && strcmp(subBundleKey, "Countries") != 0 &&
    398                         strcmp(subBundleKey, "Version") != 0) {
    399                         log_err("Found duplicate data with key \"%s\" in \"%s\" in locale \"%s\"\n",
    400                                 ures_getKey(subRootBundle),
    401                                 ures_getKey(currentBundle),
    402                                 locale);
    403                     }
    404                     else {
    405                         /* Ignore for now. */
    406                         /* Can be fixed if fallback through de locale was done. */
    407                         log_verbose("Skipping key %s in %s\n", subBundleKey, locale);
    408                     }
    409                 }
    410             }
    411 #endif
    412         }
    413         else if (ures_getType(subBundle) == URES_TABLE) {
    414             if (strcmp(subBundleKey, "availableFormats")!=0) {
    415                 /* Here is one of the recursive parts */
    416                 TestKeyInRootRecursive(subRootBundle, rootName, subBundle, locale);
    417             }
    418             else {
    419                 log_verbose("Skipping key %s in %s\n", subBundleKey, locale);
    420             }
    421         }
    422         else if (ures_getType(subBundle) == URES_BINARY || ures_getType(subBundle) == URES_INT) {
    423             /* Can't do anything to check it */
    424             /* We'll assume it's all correct */
    425             if (strcmp(subBundleKey, "MeasurementSystem") != 0) {
    426                 log_verbose("Skipping key \"%s\" in \"%s\" for locale \"%s\"\n",
    427                         subBundleKey,
    428                         ures_getKey(currentBundle),
    429                         locale);
    430             }
    431             /* Testing for MeasurementSystem is done in VerifyTranslation */
    432         }
    433         else {
    434             log_err("Type %d for key \"%s\" in \"%s\" is unknown for locale \"%s\"\n",
    435                     ures_getType(subBundle),
    436                     subBundleKey,
    437                     ures_getKey(currentBundle),
    438                     locale);
    439         }
    440         ures_close(subRootBundle);
    441         ures_close(subBundle);
    442     }
    443 }
    444 
    445 
    446 static void
    447 testLCID(UResourceBundle *currentBundle,
    448          const char *localeName)
    449 {
    450     UErrorCode status = U_ZERO_ERROR;
    451     uint32_t expectedLCID;
    452     char lcidStringC[64] = {0};
    453 
    454     expectedLCID = uloc_getLCID(localeName);
    455     if (expectedLCID == 0) {
    456         log_verbose("INFO:    %-5s does not have any LCID mapping\n",
    457             localeName);
    458         return;
    459     }
    460 
    461     status = U_ZERO_ERROR;
    462     uprv_strcpy(lcidStringC, uprv_convertToPosix(expectedLCID, &status));
    463     if (U_FAILURE(status)) {
    464         log_err("ERROR:   %.4x does not have a POSIX mapping due to %s\n",
    465             expectedLCID, u_errorName(status));
    466     }
    467 
    468     if(strcmp(localeName, lcidStringC) != 0) {
    469         char langName[1024];
    470         char langLCID[1024];
    471         uloc_getLanguage(localeName, langName, sizeof(langName), &status);
    472         uloc_getLanguage(lcidStringC, langLCID, sizeof(langLCID), &status);
    473 
    474         if (strcmp(langName, langLCID) == 0) {
    475             log_verbose("WARNING: %-5s resolves to %s (0x%.4x)\n",
    476                 localeName, lcidStringC, expectedLCID);
    477         }
    478         else {
    479             log_err("ERROR:   %-5s has 0x%.4x and the number resolves wrongfully to %s\n",
    480                 localeName, expectedLCID, lcidStringC);
    481         }
    482     }
    483 }
    484 
    485 static void
    486 TestLocaleStructure(void) {
    487     UResourceBundle *root, *currentLocale;
    488     int32_t locCount = uloc_countAvailable();
    489     int32_t locIndex;
    490     UErrorCode errorCode = U_ZERO_ERROR;
    491     const char *currLoc, *resolvedLoc;
    492     static const UVersionInfo icu48 = { 4, 8, 0, 0 };
    493 
    494     /* TODO: Compare against parent's data too. This code can't handle fallbacks that some tools do already. */
    495 /*    char locName[ULOC_FULLNAME_CAPACITY];
    496     char *locNamePtr;
    497 
    498     for (locIndex = 0; locIndex < locCount; locIndex++) {
    499         errorCode=U_ZERO_ERROR;
    500         strcpy(locName, uloc_getAvailable(locIndex));
    501         locNamePtr = strrchr(locName, '_');
    502         if (locNamePtr) {
    503             *locNamePtr = 0;
    504         }
    505         else {
    506             strcpy(locName, "root");
    507         }
    508 
    509         root = ures_openDirect(NULL, locName, &errorCode);
    510         if(U_FAILURE(errorCode)) {
    511             log_err("Can't open %s\n", locName);
    512             continue;
    513         }
    514 */
    515     if (locCount <= 1) {
    516         log_data_err("At least root needs to be installed\n");
    517     }
    518 
    519     root = ures_openDirect(loadTestData(&errorCode), "structLocale", &errorCode);
    520     if(U_FAILURE(errorCode)) {
    521         log_data_err("Can't open structLocale\n");
    522         return;
    523     }
    524     for (locIndex = 0; locIndex < locCount; locIndex++) {
    525         errorCode=U_ZERO_ERROR;
    526         currLoc = uloc_getAvailable(locIndex);
    527         currentLocale = ures_open(NULL, currLoc, &errorCode);
    528         if(errorCode != U_ZERO_ERROR) {
    529             if(U_SUCCESS(errorCode)) {
    530                 /* It's installed, but there is no data.
    531                    It's installed for the g18n white paper [grhoten] */
    532                 log_err("ERROR: Locale %-5s not installed, and it should be, err %s\n",
    533                     uloc_getAvailable(locIndex), u_errorName(errorCode));
    534             } else {
    535                 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
    536                     u_errorName(errorCode),
    537                     uloc_getAvailable(locIndex));
    538             }
    539             ures_close(currentLocale);
    540             continue;
    541         }
    542         ures_getStringByKey(currentLocale, "Version", NULL, &errorCode);
    543         if(errorCode != U_ZERO_ERROR) {
    544             log_err("No version information is available for locale %s, and it should be!\n",
    545                 currLoc);
    546         }
    547         else if (ures_getStringByKey(currentLocale, "Version", NULL, &errorCode)[0] == (UChar)(0x78)) {
    548             log_verbose("WARNING: The locale %s is experimental! It shouldn't be listed as an installed locale.\n",
    549                 currLoc);
    550         }
    551         resolvedLoc = ures_getLocaleByType(currentLocale, ULOC_ACTUAL_LOCALE, &errorCode);
    552         if ( strcmp(resolvedLoc, currLoc) != 0 &&
    553             ( strcmp(currLoc,"vai_LR") != 0 || isICUVersionAtLeast(icu48))) {
    554             /* Time bomb for weird case with vai_LR - needs investigation */
    555             /* All locales have at least a Version resource.
    556                If it's absolutely empty, then the previous test will fail too.*/
    557             log_err("Locale resolves to different locale. Is %s an alias of %s?\n",
    558                 currLoc, resolvedLoc);
    559         }
    560         TestKeyInRootRecursive(root, "root", currentLocale, currLoc);
    561 
    562         testLCID(currentLocale, currLoc);
    563 
    564         ures_close(currentLocale);
    565     }
    566 
    567     ures_close(root);
    568 }
    569 
    570 static void
    571 compareArrays(const char *keyName,
    572               UResourceBundle *fromArray, const char *fromLocale,
    573               UResourceBundle *toArray, const char *toLocale,
    574               int32_t start, int32_t end)
    575 {
    576     int32_t fromSize = ures_getSize(fromArray);
    577     int32_t toSize = ures_getSize(fromArray);
    578     int32_t idx;
    579     UErrorCode errorCode = U_ZERO_ERROR;
    580 
    581     if (fromSize > toSize) {
    582         fromSize = toSize;
    583         log_err("Arrays are different size from \"%s\" to \"%s\"\n",
    584                 fromLocale,
    585                 toLocale);
    586     }
    587 
    588     for (idx = start; idx <= end; idx++) {
    589         const UChar *fromBundleStr = ures_getStringByIndex(fromArray, idx, NULL, &errorCode);
    590         const UChar *toBundleStr = ures_getStringByIndex(toArray, idx, NULL, &errorCode);
    591         if (fromBundleStr && toBundleStr && u_strcmp(fromBundleStr, toBundleStr) != 0)
    592         {
    593             log_err("Difference for %s at index %d from %s= \"%s\" to %s= \"%s\"\n",
    594                     keyName,
    595                     idx,
    596                     fromLocale,
    597                     austrdup(fromBundleStr),
    598                     toLocale,
    599                     austrdup(toBundleStr));
    600         }
    601     }
    602 }
    603 
    604 static void
    605 compareConsistentCountryInfo(const char *fromLocale, const char *toLocale) {
    606     UErrorCode errorCode = U_ZERO_ERROR;
    607     UResourceBundle *fromArray, *toArray;
    608     UResourceBundle *fromLocaleBund = ures_open(NULL, fromLocale, &errorCode);
    609     UResourceBundle *toLocaleBund = ures_open(NULL, toLocale, &errorCode);
    610     UResourceBundle *toCalendar, *fromCalendar, *toGregorian, *fromGregorian;
    611 
    612     if(U_FAILURE(errorCode)) {
    613         log_err("Can't open resource bundle %s or %s - %s\n", fromLocale, toLocale, u_errorName(errorCode));
    614         return;
    615     }
    616     fromCalendar = ures_getByKey(fromLocaleBund, "calendar", NULL, &errorCode);
    617     fromGregorian = ures_getByKeyWithFallback(fromCalendar, "gregorian", NULL, &errorCode);
    618 
    619     toCalendar = ures_getByKey(toLocaleBund, "calendar", NULL, &errorCode);
    620     toGregorian = ures_getByKeyWithFallback(toCalendar, "gregorian", NULL, &errorCode);
    621 
    622     fromArray = ures_getByKey(fromLocaleBund, "CurrencyElements", NULL, &errorCode);
    623     toArray = ures_getByKey(toLocaleBund, "CurrencyElements", NULL, &errorCode);
    624     if (strcmp(fromLocale, "en_CA") != 0)
    625     {
    626         /* The first one is probably localized. */
    627         compareArrays("CurrencyElements", fromArray, fromLocale, toArray, toLocale, 1, 2);
    628     }
    629     ures_close(fromArray);
    630     ures_close(toArray);
    631 
    632     fromArray = ures_getByKey(fromLocaleBund, "NumberPatterns", NULL, &errorCode);
    633     toArray = ures_getByKey(toLocaleBund, "NumberPatterns", NULL, &errorCode);
    634     if (strcmp(fromLocale, "en_CA") != 0)
    635     {
    636         compareArrays("NumberPatterns", fromArray, fromLocale, toArray, toLocale, 0, 3);
    637     }
    638     ures_close(fromArray);
    639     ures_close(toArray);
    640 
    641     /* Difficult to test properly */
    642 /*
    643     fromArray = ures_getByKey(fromLocaleBund, "DateTimePatterns", NULL, &errorCode);
    644     toArray = ures_getByKey(toLocaleBund, "DateTimePatterns", NULL, &errorCode);
    645     {
    646         compareArrays("DateTimePatterns", fromArray, fromLocale, toArray, toLocale);
    647     }
    648     ures_close(fromArray);
    649     ures_close(toArray);*/
    650 
    651     fromArray = ures_getByKey(fromLocaleBund, "NumberElements", NULL, &errorCode);
    652     toArray = ures_getByKey(toLocaleBund, "NumberElements", NULL, &errorCode);
    653     if (strcmp(fromLocale, "en_CA") != 0)
    654     {
    655         compareArrays("NumberElements", fromArray, fromLocale, toArray, toLocale, 0, 3);
    656         /* Index 4 is a script based 0 */
    657         compareArrays("NumberElements", fromArray, fromLocale, toArray, toLocale, 5, 10);
    658     }
    659     ures_close(fromArray);
    660     ures_close(toArray);
    661     ures_close(fromCalendar);
    662     ures_close(toCalendar);
    663     ures_close(fromGregorian);
    664     ures_close(toGregorian);
    665 
    666     ures_close(fromLocaleBund);
    667     ures_close(toLocaleBund);
    668 }
    669 
    670 static void
    671 TestConsistentCountryInfo(void) {
    672 /*    UResourceBundle *fromLocale, *toLocale;*/
    673     int32_t locCount = uloc_countAvailable();
    674     int32_t fromLocIndex, toLocIndex;
    675 
    676     int32_t fromCountryLen, toCountryLen;
    677     char fromCountry[ULOC_FULLNAME_CAPACITY], toCountry[ULOC_FULLNAME_CAPACITY];
    678 
    679     int32_t fromVariantLen, toVariantLen;
    680     char fromVariant[ULOC_FULLNAME_CAPACITY], toVariant[ULOC_FULLNAME_CAPACITY];
    681 
    682     UErrorCode errorCode = U_ZERO_ERROR;
    683 
    684     for (fromLocIndex = 0; fromLocIndex < locCount; fromLocIndex++) {
    685         const char *fromLocale = uloc_getAvailable(fromLocIndex);
    686 
    687         errorCode=U_ZERO_ERROR;
    688         fromCountryLen = uloc_getCountry(fromLocale, fromCountry, ULOC_FULLNAME_CAPACITY, &errorCode);
    689         if (fromCountryLen <= 0) {
    690             /* Ignore countryless locales */
    691             continue;
    692         }
    693         fromVariantLen = uloc_getVariant(fromLocale, fromVariant, ULOC_FULLNAME_CAPACITY, &errorCode);
    694         if (fromVariantLen > 0) {
    695             /* Most variants are ignorable like PREEURO, or collation variants. */
    696             continue;
    697         }
    698         /* Start comparing only after the current index.
    699            Previous loop should have already compared fromLocIndex.
    700         */
    701         for (toLocIndex = fromLocIndex + 1; toLocIndex < locCount; toLocIndex++) {
    702             const char *toLocale = uloc_getAvailable(toLocIndex);
    703 
    704             toCountryLen = uloc_getCountry(toLocale, toCountry, ULOC_FULLNAME_CAPACITY, &errorCode);
    705             if(U_FAILURE(errorCode)) {
    706                 log_err("Unknown failure fromLocale=%s toLocale=%s errorCode=%s\n",
    707                     fromLocale, toLocale, u_errorName(errorCode));
    708                 continue;
    709             }
    710 
    711             if (toCountryLen <= 0) {
    712                 /* Ignore countryless locales */
    713                 continue;
    714             }
    715             toVariantLen = uloc_getVariant(toLocale, toVariant, ULOC_FULLNAME_CAPACITY, &errorCode);
    716             if (toVariantLen > 0) {
    717                 /* Most variants are ignorable like PREEURO, or collation variants. */
    718                 /* They're a variant for a reason. */
    719                 continue;
    720             }
    721             if (strcmp(fromCountry, toCountry) == 0) {
    722                 log_verbose("comparing fromLocale=%s toLocale=%s\n",
    723                     fromLocale, toLocale);
    724                 compareConsistentCountryInfo(fromLocale, toLocale);
    725             }
    726         }
    727     }
    728 }
    729 
    730 static int32_t
    731 findStringSetMismatch(const char *currLoc, const UChar *string, int32_t langSize,
    732                       const UChar *exemplarCharacters, int32_t exemplarLen,
    733                       UBool ignoreNumbers, UChar* badCharPtr) {
    734     UErrorCode errorCode = U_ZERO_ERROR;
    735     USet *origSet = uset_openPatternOptions(exemplarCharacters, exemplarLen, USET_CASE_INSENSITIVE, &errorCode);
    736     USet *exemplarSet = createFlattenSet(origSet, &errorCode);
    737     int32_t strIdx;
    738     uset_close(origSet);
    739     if (U_FAILURE(errorCode)) {
    740         log_err("%s: error uset_openPattern returned %s\n", currLoc, u_errorName(errorCode));
    741         return -1;
    742     }
    743 
    744     for (strIdx = 0; strIdx < langSize; strIdx++) {
    745         if (!uset_contains(exemplarSet, string[strIdx])
    746             && string[strIdx] != 0x0020 && string[strIdx] != 0x00A0 && string[strIdx] != 0x002e && string[strIdx] != 0x002c && string[strIdx] != 0x002d && string[strIdx] != 0x0027 && string[strIdx] != 0x2019 && string[strIdx] != 0x0f0b
    747             && string[strIdx] != 0x200C && string[strIdx] != 0x200D) {
    748             if (!ignoreNumbers || (ignoreNumbers && (string[strIdx] < 0x30 || string[strIdx] > 0x39))) {
    749                 uset_close(exemplarSet);
    750                 if (badCharPtr) {
    751                     *badCharPtr = string[strIdx];
    752                 }
    753                 return strIdx;
    754             }
    755         }
    756     }
    757     uset_close(exemplarSet);
    758     if (badCharPtr) {
    759         *badCharPtr = 0;
    760     }
    761     return -1;
    762 }
    763 /* include non-invariant chars */
    764 static int32_t
    765 myUCharsToChars(const UChar* us, char* cs, int32_t len){
    766     int32_t i=0;
    767     for(; i< len; i++){
    768         if(us[i] < 0x7f){
    769             cs[i] = (char)us[i];
    770         }else{
    771             return -1;
    772         }
    773     }
    774     return i;
    775 }
    776 static void
    777 findSetMatch( UScriptCode *scriptCodes, int32_t scriptsLen,
    778               USet *exemplarSet,
    779               const char  *locale){
    780     USet *scripts[10]= {0};
    781     char pattern[256] = { '[', ':', 0x000 };
    782     int32_t patternLen;
    783     UChar uPattern[256] = {0};
    784     UErrorCode status = U_ZERO_ERROR;
    785     int32_t i;
    786 
    787     /* create the sets with script codes */
    788     for(i = 0; i<scriptsLen; i++){
    789         strcat(pattern, uscript_getShortName(scriptCodes[i]));
    790         strcat(pattern, ":]");
    791         patternLen = (int32_t)strlen(pattern);
    792         u_charsToUChars(pattern, uPattern, patternLen);
    793         scripts[i] = uset_openPattern(uPattern, patternLen, &status);
    794         if(U_FAILURE(status)){
    795             log_err("Could not create set for pattern %s. Error: %s\n", pattern, u_errorName(status));
    796             return;
    797         }
    798         pattern[2] = 0;
    799     }
    800     if (strcmp(locale, "uk") == 0 || strcmp(locale, "uk_UA") == 0) {
    801         /* Special addition. Add the modifying apostrophe, which isn't in Cyrillic. */
    802         uset_add(scripts[0], 0x2bc);
    803     }
    804     if(U_SUCCESS(status)){
    805         UBool existsInScript = FALSE;
    806         /* iterate over the exemplarSet and ascertain if all
    807          * UChars in exemplarSet belong to the scripts returned
    808          * by getScript
    809          */
    810         int32_t count = uset_getItemCount(exemplarSet);
    811 
    812         for( i=0; i < count; i++){
    813             UChar32 start = 0;
    814             UChar32 end = 0;
    815             UChar *str = NULL;
    816             int32_t strCapacity = 0;
    817 
    818             strCapacity = uset_getItem(exemplarSet, i, &start, &end, str, strCapacity, &status);
    819             if(U_SUCCESS(status)){
    820                 int32_t j;
    821                 if(strCapacity == 0){
    822                     /* ok the item is a range */
    823                      for( j = 0; j < scriptsLen; j++){
    824                         if(uset_containsRange(scripts[j], start, end) == TRUE){
    825                             existsInScript = TRUE;
    826                         }
    827                     }
    828                     if(existsInScript == FALSE){
    829                         for( j = 0; j < scriptsLen; j++){
    830                             UChar toPattern[500]={'\0'};
    831                             char pat[500]={'\0'};
    832                             int32_t len = uset_toPattern(scripts[j], toPattern, 500, TRUE, &status);
    833                             len = myUCharsToChars(toPattern, pat, len);
    834                             log_err("uset_indexOf(\\u%04X)=%i uset_indexOf(\\u%04X)=%i\n", start, uset_indexOf(scripts[0], start), end, uset_indexOf(scripts[0], end));
    835                             if(len!=-1){
    836                                 log_err("Pattern: %s\n",pat);
    837                             }
    838                         }
    839                         log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale);
    840                     }
    841                 }else{
    842                     strCapacity++; /* increment for NUL termination */
    843                     /* allocate the str and call the api again */
    844                     str = (UChar*) malloc(U_SIZEOF_UCHAR * strCapacity);
    845                     strCapacity =  uset_getItem(exemplarSet, i, &start, &end, str, strCapacity, &status);
    846                     /* iterate over the scripts and figure out if the string contained is actually
    847                      * in the script set
    848                      */
    849                     for( j = 0; j < scriptsLen; j++){
    850                         if(uset_containsString(scripts[j],str, strCapacity) == TRUE){
    851                             existsInScript = TRUE;
    852                         }
    853                     }
    854                     if(existsInScript == FALSE){
    855                         log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale);
    856                     }
    857                 }
    858             }
    859         }
    860 
    861     }
    862 
    863     /* close the sets */
    864     for(i = 0; i<scriptsLen; i++){
    865         uset_close(scripts[i]);
    866     }
    867 }
    868 
    869 static void VerifyTranslation(void) {
    870     static const UVersionInfo icu49 = { 4, 9, 0, 0 };
    871     UResourceBundle *root, *currentLocale;
    872     int32_t locCount = uloc_countAvailable();
    873     int32_t locIndex;
    874     UErrorCode errorCode = U_ZERO_ERROR;
    875     int32_t exemplarLen;
    876     const UChar *exemplarCharacters;
    877     const char *currLoc;
    878     UScriptCode scripts[USCRIPT_CODE_LIMIT];
    879     int32_t numScripts;
    880     int32_t idx;
    881     int32_t end;
    882     UResourceBundle *resArray;
    883 
    884     if (locCount <= 1) {
    885         log_data_err("At least root needs to be installed\n");
    886     }
    887 
    888     root = ures_openDirect(NULL, "root", &errorCode);
    889     if(U_FAILURE(errorCode)) {
    890         log_data_err("Can't open root\n");
    891         return;
    892     }
    893     for (locIndex = 0; locIndex < locCount; locIndex++) {
    894         errorCode=U_ZERO_ERROR;
    895         currLoc = uloc_getAvailable(locIndex);
    896         currentLocale = ures_open(NULL, currLoc, &errorCode);
    897         if(errorCode != U_ZERO_ERROR) {
    898             if(U_SUCCESS(errorCode)) {
    899                 /* It's installed, but there is no data.
    900                    It's installed for the g18n white paper [grhoten] */
    901                 log_err("ERROR: Locale %-5s not installed, and it should be!\n",
    902                     uloc_getAvailable(locIndex));
    903             } else {
    904                 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
    905                     u_errorName(errorCode),
    906                     uloc_getAvailable(locIndex));
    907             }
    908             ures_close(currentLocale);
    909             continue;
    910         }
    911         exemplarCharacters = ures_getStringByKey(currentLocale, "ExemplarCharacters", &exemplarLen, &errorCode);
    912         if (U_FAILURE(errorCode)) {
    913             log_err("error ures_getStringByKey returned %s\n", u_errorName(errorCode));
    914         }
    915         else if (getTestOption(QUICK_OPTION) && exemplarLen > 2048) {
    916             log_verbose("skipping test for %s\n", currLoc);
    917         }
    918         else if (uprv_strncmp(currLoc,"bem",3) == 0) {
    919             log_verbose("skipping test for %s, some month and country names known to use aux exemplars\n", currLoc);
    920         }
    921         else {
    922             UChar langBuffer[128];
    923             int32_t langSize;
    924             int32_t strIdx;
    925             UChar badChar;
    926             langSize = uloc_getDisplayLanguage(currLoc, currLoc, langBuffer, sizeof(langBuffer)/sizeof(langBuffer[0]), &errorCode);
    927             if (U_FAILURE(errorCode)) {
    928                 log_err("error uloc_getDisplayLanguage returned %s\n", u_errorName(errorCode));
    929             }
    930             else {
    931                 strIdx = findStringSetMismatch(currLoc, langBuffer, langSize, exemplarCharacters, exemplarLen, FALSE, &badChar);
    932                 if (strIdx >= 0) {
    933                     log_err("getDisplayLanguage(%s) at index %d returned characters not in the exemplar characters: %04X.\n",
    934                         currLoc, strIdx, badChar);
    935                 }
    936             }
    937             langSize = uloc_getDisplayCountry(currLoc, currLoc, langBuffer, sizeof(langBuffer)/sizeof(langBuffer[0]), &errorCode);
    938             if (U_FAILURE(errorCode)) {
    939                 log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode));
    940             }
    941             else if (uprv_strstr(currLoc, "ti_") != currLoc || isICUVersionAtLeast(icu49)) { /* TODO: restore DisplayCountry test for ti_* when cldrbug 3058 is fixed) */
    942               strIdx = findStringSetMismatch(currLoc, langBuffer, langSize, exemplarCharacters, exemplarLen, FALSE, &badChar);
    943                 if (strIdx >= 0) {
    944                     log_err("getDisplayCountry(%s) at index %d returned characters not in the exemplar characters: %04X.\n",
    945                         currLoc, strIdx, badChar);
    946                 }
    947             }
    948             {
    949                 UResourceBundle* cal = ures_getByKey(currentLocale, "calendar", NULL, &errorCode);
    950                 UResourceBundle* greg = ures_getByKeyWithFallback(cal, "gregorian", NULL, &errorCode);
    951                 UResourceBundle* names = ures_getByKeyWithFallback(greg,  "dayNames", NULL, &errorCode);
    952                 UResourceBundle* format = ures_getByKeyWithFallback(names,  "format", NULL, &errorCode);
    953                 resArray = ures_getByKeyWithFallback(format,  "wide", NULL, &errorCode);
    954 
    955                 if (U_FAILURE(errorCode)) {
    956                     log_err("error ures_getByKey returned %s\n", u_errorName(errorCode));
    957                 }
    958                 if (getTestOption(QUICK_OPTION)) {
    959                     end = 1;
    960                 }
    961                 else {
    962                     end = ures_getSize(resArray);
    963                 }
    964 
    965 
    966                 for (idx = 0; idx < end; idx++) {
    967                     const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode);
    968                     if (U_FAILURE(errorCode)) {
    969                         log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode));
    970                         continue;
    971                     }
    972                     strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, exemplarCharacters, exemplarLen, TRUE, &badChar);
    973                     if (strIdx >= 0) {
    974                         log_err("getDayNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
    975                             currLoc, idx, strIdx, badChar);
    976                     }
    977                 }
    978                 ures_close(resArray);
    979                 ures_close(format);
    980                 ures_close(names);
    981 
    982                 names = ures_getByKeyWithFallback(greg, "monthNames", NULL, &errorCode);
    983                 format = ures_getByKeyWithFallback(names,"format", NULL, &errorCode);
    984                 resArray = ures_getByKeyWithFallback(format, "wide", NULL, &errorCode);
    985                 if (U_FAILURE(errorCode)) {
    986                     log_err("error ures_getByKey returned %s\n", u_errorName(errorCode));
    987                 }
    988                 if (getTestOption(QUICK_OPTION)) {
    989                     end = 1;
    990                 }
    991                 else {
    992                     end = ures_getSize(resArray);
    993                 }
    994 
    995                 for (idx = 0; idx < end; idx++) {
    996                     const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode);
    997                     if (U_FAILURE(errorCode)) {
    998                         log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode));
    999                         continue;
   1000                     }
   1001                     strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, exemplarCharacters, exemplarLen, TRUE, &badChar);
   1002                     if (strIdx >= 0) {
   1003                         log_err("getMonthNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
   1004                             currLoc, idx, strIdx, badChar);
   1005                     }
   1006                 }
   1007                 ures_close(resArray);
   1008                 ures_close(format);
   1009                 ures_close(names);
   1010                 ures_close(greg);
   1011                 ures_close(cal);
   1012             }
   1013             errorCode = U_ZERO_ERROR;
   1014             numScripts = uscript_getCode(currLoc, scripts, sizeof(scripts)/sizeof(scripts[0]), &errorCode);
   1015             if (numScripts == 0) {
   1016                 log_err("uscript_getCode(%s) doesn't work.\n", currLoc);
   1017             }else if(scripts[0] == USCRIPT_COMMON){
   1018                 log_err("uscript_getCode(%s) returned USCRIPT_COMMON.\n", currLoc);
   1019             }
   1020 
   1021             /* test that the scripts are a superset of exemplar characters. */
   1022            {
   1023                 ULocaleData *uld = ulocdata_open(currLoc,&errorCode);
   1024                 USet *exemplarSet =  ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_STANDARD, &errorCode);
   1025                 /* test if exemplar characters are part of script code */
   1026                 findSetMatch(scripts, numScripts, exemplarSet, currLoc);
   1027                 uset_close(exemplarSet);
   1028                 ulocdata_close(uld);
   1029             }
   1030 
   1031            /* test that the paperSize API works */
   1032            {
   1033                int32_t height=0, width=0;
   1034                ulocdata_getPaperSize(currLoc, &height, &width, &errorCode);
   1035                if(U_FAILURE(errorCode)){
   1036                    log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
   1037                }
   1038                if(strstr(currLoc, "_US")!=NULL && height != 279 && width != 216 ){
   1039                    log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
   1040                }
   1041            }
   1042             /* test that the MeasurementSystem works API works */
   1043            {
   1044                UMeasurementSystem measurementSystem = ulocdata_getMeasurementSystem(currLoc, &errorCode);
   1045                if(U_FAILURE(errorCode)){
   1046                    log_err("ulocdata_getMeasurementSystem failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
   1047                }
   1048                if(strstr(currLoc, "_US")!=NULL || strstr(currLoc, "_MM")!=NULL || strstr(currLoc, "_LR")!=NULL){
   1049                    if(measurementSystem != UMS_US){
   1050                         log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
   1051                    }
   1052                }else if(measurementSystem != UMS_SI){
   1053                    log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
   1054                }
   1055            }
   1056         }
   1057         ures_close(currentLocale);
   1058     }
   1059 
   1060     ures_close(root);
   1061 }
   1062 
   1063 /* adjust this limit as appropriate */
   1064 #define MAX_SCRIPTS_PER_LOCALE 8
   1065 
   1066 static void TestExemplarSet(void){
   1067     int32_t i, j, k, m, n;
   1068     int32_t equalCount = 0;
   1069     UErrorCode ec = U_ZERO_ERROR;
   1070     UEnumeration* avail;
   1071     USet* exemplarSets[2];
   1072     USet* unassignedSet;
   1073     UScriptCode code[MAX_SCRIPTS_PER_LOCALE];
   1074     USet* codeSets[MAX_SCRIPTS_PER_LOCALE];
   1075     int32_t codeLen;
   1076     char cbuf[32]; /* 9 should be enough */
   1077     UChar ubuf[64]; /* adjust as needed */
   1078     UBool existsInScript;
   1079     int32_t itemCount;
   1080     int32_t strLen;
   1081     UChar32 start, end;
   1082 
   1083     unassignedSet = NULL;
   1084     exemplarSets[0] = NULL;
   1085     exemplarSets[1] = NULL;
   1086     for (i=0; i<MAX_SCRIPTS_PER_LOCALE; ++i) {
   1087         codeSets[i] = NULL;
   1088     }
   1089 
   1090     avail = ures_openAvailableLocales(NULL, &ec);
   1091     if (!assertSuccess("ures_openAvailableLocales", &ec)) goto END;
   1092     n = uenum_count(avail, &ec);
   1093     if (!assertSuccess("uenum_count", &ec)) goto END;
   1094 
   1095     u_uastrcpy(ubuf, "[:unassigned:]");
   1096     unassignedSet = uset_openPattern(ubuf, -1, &ec);
   1097     if (!assertSuccess("uset_openPattern", &ec)) goto END;
   1098 
   1099     for(i=0; i<n; i++){
   1100         const char* locale = uenum_next(avail, NULL, &ec);
   1101         if (!assertSuccess("uenum_next", &ec)) goto END;
   1102         log_verbose("%s\n", locale);
   1103         for (k=0; k<2; ++k) {
   1104             uint32_t option = (k==0) ? 0 : USET_CASE_INSENSITIVE;
   1105             ULocaleData *uld = ulocdata_open(locale,&ec);
   1106             USet* exemplarSet = ulocdata_getExemplarSet(uld,NULL, option, ULOCDATA_ES_STANDARD, &ec);
   1107             uset_close(exemplarSets[k]);
   1108             ulocdata_close(uld);
   1109             exemplarSets[k] = exemplarSet;
   1110             if (!assertSuccess("ulocaledata_getExemplarSet", &ec)) goto END;
   1111 
   1112             if (uset_containsSome(exemplarSet, unassignedSet)) {
   1113                 log_err("ExemplarSet contains unassigned characters for locale : %s\n", locale);
   1114             }
   1115             codeLen = uscript_getCode(locale, code, 8, &ec);
   1116             if (!assertSuccess("uscript_getCode", &ec)) goto END;
   1117 
   1118             for (j=0; j<MAX_SCRIPTS_PER_LOCALE; ++j) {
   1119                 uset_close(codeSets[j]);
   1120                 codeSets[j] = NULL;
   1121             }
   1122             for (j=0; j<codeLen; ++j) {
   1123                 uprv_strcpy(cbuf, "[:");
   1124                 if(code[j]==-1){
   1125                     log_err("USCRIPT_INVALID_CODE returned for locale: %s\n", locale);
   1126                     continue;
   1127                 }
   1128                 uprv_strcat(cbuf, uscript_getShortName(code[j]));
   1129                 uprv_strcat(cbuf, ":]");
   1130                 u_uastrcpy(ubuf, cbuf);
   1131                 codeSets[j] = uset_openPattern(ubuf, -1, &ec);
   1132             }
   1133             if (!assertSuccess("uset_openPattern", &ec)) goto END;
   1134 
   1135             existsInScript = FALSE;
   1136             itemCount = uset_getItemCount(exemplarSet);
   1137             for (m=0; m<itemCount && !existsInScript; ++m) {
   1138                 strLen = uset_getItem(exemplarSet, m, &start, &end, ubuf,
   1139                                       sizeof(ubuf)/sizeof(ubuf[0]), &ec);
   1140                 /* failure here might mean str[] needs to be larger */
   1141                 if (!assertSuccess("uset_getItem", &ec)) goto END;
   1142                 if (strLen == 0) {
   1143                     for (j=0; j<codeLen; ++j) {
   1144                         if (codeSets[j]!=NULL && uset_containsRange(codeSets[j], start, end)) {
   1145                             existsInScript = TRUE;
   1146                             break;
   1147                         }
   1148                     }
   1149                 } else {
   1150                     for (j=0; j<codeLen; ++j) {
   1151                         if (codeSets[j]!=NULL && uset_containsString(codeSets[j], ubuf, strLen)) {
   1152                             existsInScript = TRUE;
   1153                             break;
   1154                         }
   1155                     }
   1156                 }
   1157             }
   1158 
   1159             if (existsInScript == FALSE){
   1160                 log_err("ExemplarSet containment failed for locale : %s\n", locale);
   1161             }
   1162         }
   1163         assertTrue("case-folded is a superset",
   1164                    uset_containsAll(exemplarSets[1], exemplarSets[0]));
   1165         if (uset_equals(exemplarSets[1], exemplarSets[0])) {
   1166             ++equalCount;
   1167         }
   1168     }
   1169     /* Note: The case-folded set should sometimes be a strict superset
   1170        and sometimes be equal. */
   1171     assertTrue("case-folded is sometimes a strict superset, and sometimes equal",
   1172                equalCount > 0 && equalCount < n);
   1173 
   1174  END:
   1175     uenum_close(avail);
   1176     uset_close(exemplarSets[0]);
   1177     uset_close(exemplarSets[1]);
   1178     uset_close(unassignedSet);
   1179     for (i=0; i<MAX_SCRIPTS_PER_LOCALE; ++i) {
   1180         uset_close(codeSets[i]);
   1181     }
   1182 }
   1183 
   1184 static void TestLocaleDisplayPattern(void){
   1185     UErrorCode status = U_ZERO_ERROR;
   1186     UChar pattern[32] = {0,};
   1187     UChar separator[32] = {0,};
   1188     ULocaleData *uld = ulocdata_open(uloc_getDefault(), &status);
   1189 
   1190     if(U_FAILURE(status)){
   1191         log_data_err("ulocdata_open error");
   1192         return;
   1193     }
   1194     ulocdata_getLocaleDisplayPattern(uld, pattern, 32, &status);
   1195     if (U_FAILURE(status)){
   1196         log_err("ulocdata_getLocaleDisplayPattern error!");
   1197     }
   1198     status = U_ZERO_ERROR;
   1199     ulocdata_getLocaleSeparator(uld, separator, 32, &status);
   1200     if (U_FAILURE(status)){
   1201         log_err("ulocdata_getLocaleSeparator error!");
   1202     }
   1203     ulocdata_close(uld);
   1204 }
   1205 
   1206 static void TestCoverage(void){
   1207     ULocaleDataDelimiterType types[] = {
   1208      ULOCDATA_QUOTATION_START,     /* Quotation start */
   1209      ULOCDATA_QUOTATION_END,       /* Quotation end */
   1210      ULOCDATA_ALT_QUOTATION_START, /* Alternate quotation start */
   1211      ULOCDATA_ALT_QUOTATION_END,   /* Alternate quotation end */
   1212      ULOCDATA_DELIMITER_COUNT
   1213     };
   1214     int i;
   1215     UBool sub;
   1216     UErrorCode status = U_ZERO_ERROR;
   1217     ULocaleData *uld = ulocdata_open(uloc_getDefault(), &status);
   1218 
   1219     if(U_FAILURE(status)){
   1220         log_data_err("ulocdata_open error");
   1221         return;
   1222     }
   1223 
   1224 
   1225     for(i = 0; i < ULOCDATA_DELIMITER_COUNT; i++){
   1226         UChar result[32] = {0,};
   1227         status = U_ZERO_ERROR;
   1228         ulocdata_getDelimiter(uld, types[i], result, 32, &status);
   1229         if (U_FAILURE(status)){
   1230             log_err("ulocdata_getgetDelimiter error with type %d", types[i]);
   1231         }
   1232     }
   1233 
   1234     sub = ulocdata_getNoSubstitute(uld);
   1235     ulocdata_setNoSubstitute(uld,sub);
   1236     ulocdata_close(uld);
   1237 }
   1238 
   1239 static void TestIndexChars(void) {
   1240     /* Very basic test of ULOCDATA_ES_INDEX.
   1241      * No comprehensive test of data, just basic check that the code path is alive.
   1242      */
   1243     UErrorCode status = U_ZERO_ERROR;
   1244     ULocaleData  *uld;
   1245     USet *exemplarChars;
   1246     USet *indexChars;
   1247 
   1248     uld = ulocdata_open("en", &status);
   1249     exemplarChars = uset_openEmpty();
   1250     indexChars = uset_openEmpty();
   1251     ulocdata_getExemplarSet(uld, exemplarChars, 0, ULOCDATA_ES_STANDARD, &status);
   1252     ulocdata_getExemplarSet(uld, indexChars, 0, ULOCDATA_ES_INDEX, &status);
   1253     if (U_FAILURE(status)) {
   1254         log_data_err("File %s, line %d, Failure opening exemplar chars: %s", __FILE__, __LINE__, u_errorName(status));
   1255         goto close_sets;
   1256     }
   1257     /* en data, standard exemplars are [a-z], lower case. */
   1258     /* en data, index characters are [A-Z], upper case. */
   1259     if ((uset_contains(exemplarChars, (UChar32)0x41) || uset_contains(indexChars, (UChar32)0x61))) {
   1260         log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__, __LINE__ );
   1261         goto close_sets;
   1262     }
   1263     if (!(uset_contains(exemplarChars, (UChar32)0x61) && uset_contains(indexChars, (UChar32)0x41) )) {
   1264         log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__, __LINE__ );
   1265         goto close_sets;
   1266     }
   1267 
   1268   close_sets:
   1269     uset_close(exemplarChars);
   1270     uset_close(indexChars);
   1271     ulocdata_close(uld);
   1272 }
   1273 
   1274 
   1275 
   1276 static void TestCurrencyList(void){
   1277 #if !UCONFIG_NO_FORMATTING
   1278     UErrorCode errorCode = U_ZERO_ERROR;
   1279     int32_t structLocaleCount, currencyCount;
   1280     UEnumeration *en = ucurr_openISOCurrencies(UCURR_ALL, &errorCode);
   1281     const char *isoCode, *structISOCode;
   1282     UResourceBundle *subBundle;
   1283     UResourceBundle *currencies = ures_openDirect(loadTestData(&errorCode), "structLocale", &errorCode);
   1284     if(U_FAILURE(errorCode)) {
   1285         log_data_err("Can't open structLocale\n");
   1286         return;
   1287     }
   1288     currencies = ures_getByKey(currencies, "Currencies", currencies, &errorCode);
   1289     currencyCount = uenum_count(en, &errorCode);
   1290     structLocaleCount = ures_getSize(currencies);
   1291     if (currencyCount != structLocaleCount) {
   1292         log_err("structLocale(%d) and ISO4217(%d) currency list are out of sync.\n", structLocaleCount, currencyCount);
   1293 #if U_CHARSET_FAMILY == U_ASCII_FAMILY
   1294         ures_resetIterator(currencies);
   1295         while ((isoCode = uenum_next(en, NULL, &errorCode)) != NULL && ures_hasNext(currencies)) {
   1296             subBundle = ures_getNextResource(currencies, NULL, &errorCode);
   1297             structISOCode = ures_getKey(subBundle);
   1298             ures_close(subBundle);
   1299             if (strcmp(structISOCode, isoCode) != 0) {
   1300                 log_err("First difference found at structLocale(%s) and ISO4217(%s).\n", structISOCode, isoCode);
   1301                 break;
   1302             }
   1303         }
   1304 #endif
   1305     }
   1306     ures_close(currencies);
   1307     uenum_close(en);
   1308 #endif
   1309 }
   1310 
   1311 static void TestAvailableIsoCodes(void){
   1312     UErrorCode errorCode = U_ZERO_ERROR;
   1313     const char* eurCode = "EUR";
   1314     const char* usdCode = "USD";
   1315     const char* lastCode = "RHD";
   1316     const char* zzzCode = "ZZZ";
   1317     UDate date1950 = (UDate)-630720000000.0;/* year 1950 */
   1318     UDate date1970 = (UDate)0.0;            /* year 1970 */
   1319     UDate date1975 = (UDate)173448000000.0; /* year 1975 */
   1320     UDate date1978 = (UDate)260172000000.0; /* year 1978 */
   1321     UDate date1981 = (UDate)346896000000.0; /* year 1981 */
   1322     UDate date1992 = (UDate)693792000000.0; /* year 1992 */
   1323     UChar* isoCode = (UChar*)malloc(sizeof(UChar) * (uprv_strlen(usdCode) + 1));
   1324 
   1325     /* testing available codes with no time ranges */
   1326     u_charsToUChars(eurCode, isoCode, uprv_strlen(usdCode) + 1);
   1327     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
   1328        log_data_err("FAIL: ISO code (%s) is not found.\n", eurCode);
   1329     }
   1330 
   1331     u_charsToUChars(usdCode, isoCode, uprv_strlen(zzzCode) + 1);
   1332     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
   1333        log_data_err("FAIL: ISO code (%s) is not found.\n", usdCode);
   1334     }
   1335 
   1336     u_charsToUChars(zzzCode, isoCode, uprv_strlen(zzzCode) + 1);
   1337     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == TRUE) {
   1338        log_err("FAIL: ISO code (%s) is reported as available, but it doesn't exist.\n", zzzCode);
   1339     }
   1340 
   1341     u_charsToUChars(lastCode, isoCode, uprv_strlen(zzzCode) + 1);
   1342     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
   1343        log_data_err("FAIL: ISO code (%s) is not found.\n", lastCode);
   1344     }
   1345 
   1346     /* RHD was used from 1970-02-17  to 1980-04-18*/
   1347 
   1348     /* to = null */
   1349     if (ucurr_isAvailable(isoCode, date1970, U_DATE_MAX, &errorCode) == FALSE) {
   1350        log_data_err("FAIL: ISO code (%s) was available in time range >1970-01-01.\n", lastCode);
   1351     }
   1352 
   1353     if (ucurr_isAvailable(isoCode, date1975, U_DATE_MAX, &errorCode) == FALSE) {
   1354        log_data_err("FAIL: ISO code (%s) was available in time range >1975.\n", lastCode);
   1355     }
   1356 
   1357     if (ucurr_isAvailable(isoCode, date1981, U_DATE_MAX, &errorCode) == TRUE) {
   1358        log_err("FAIL: ISO code (%s) was not available in time range >1981.\n", lastCode);
   1359     }
   1360 
   1361     /* from = null */
   1362     if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1970, &errorCode) == TRUE) {
   1363        log_err("FAIL: ISO code (%s) was not available in time range <1970.\n", lastCode);
   1364     }
   1365 
   1366     if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1975, &errorCode) == FALSE) {
   1367        log_data_err("FAIL: ISO code (%s) was available in time range <1975.\n", lastCode);
   1368     }
   1369 
   1370     if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1981, &errorCode) == FALSE) {
   1371        log_data_err("FAIL: ISO code (%s) was available in time range <1981.\n", lastCode);
   1372     }
   1373 
   1374     /* full ranges */
   1375     if (ucurr_isAvailable(isoCode, date1975, date1978, &errorCode) == FALSE) {
   1376        log_data_err("FAIL: ISO code (%s) was available in time range 1975-1978.\n", lastCode);
   1377     }
   1378 
   1379     if (ucurr_isAvailable(isoCode, date1970, date1975, &errorCode) == FALSE) {
   1380        log_data_err("FAIL: ISO code (%s) was available in time range 1970-1975.\n", lastCode);
   1381     }
   1382 
   1383     if (ucurr_isAvailable(isoCode, date1975, date1981, &errorCode) == FALSE) {
   1384        log_data_err("FAIL: ISO code (%s) was available in time range 1975-1981.\n", lastCode);
   1385     }
   1386 
   1387     if (ucurr_isAvailable(isoCode, date1970,  date1981, &errorCode) == FALSE) {
   1388        log_data_err("FAIL: ISO code (%s) was available in time range 1970-1981.\n", lastCode);
   1389     }
   1390 
   1391     if (ucurr_isAvailable(isoCode, date1981,  date1992, &errorCode) == TRUE) {
   1392        log_err("FAIL: ISO code (%s) was not available in time range 1981-1992.\n", lastCode);
   1393     }
   1394 
   1395     if (ucurr_isAvailable(isoCode, date1950,  date1970, &errorCode) == TRUE) {
   1396        log_err("FAIL: ISO code (%s) was not available in time range 1950-1970.\n", lastCode);
   1397     }
   1398 
   1399     /* wrong range - from > to*/
   1400     if (ucurr_isAvailable(isoCode, date1975,  date1970, &errorCode) == TRUE) {
   1401        log_err("FAIL: Wrong range 1975-1970 for ISO code (%s) was not reported.\n", lastCode);
   1402     } else if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
   1403        log_data_err("FAIL: Error code not reported for wrong range 1975-1970 for ISO code (%s).\n", lastCode);
   1404     }
   1405 
   1406     free(isoCode);
   1407 }
   1408 
   1409 #define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name)
   1410 
   1411 void addCLDRTest(TestNode** root);
   1412 
   1413 void addCLDRTest(TestNode** root)
   1414 {
   1415 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
   1416     TESTCASE(TestLocaleStructure);
   1417     TESTCASE(TestCurrencyList);
   1418 #endif
   1419     TESTCASE(TestConsistentCountryInfo);
   1420     TESTCASE(VerifyTranslation);
   1421     TESTCASE(TestExemplarSet);
   1422     TESTCASE(TestLocaleDisplayPattern);
   1423     TESTCASE(TestCoverage);
   1424     TESTCASE(TestIndexChars);
   1425     TESTCASE(TestAvailableIsoCodes);
   1426 }
   1427 
   1428