Home | History | Annotate | Download | only in cintltst
      1 /********************************************************************
      2  * COPYRIGHT:
      3  * Copyright (c) 1997-2012, 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 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
     72 static void
     73 TestKeyInRootRecursive(UResourceBundle *root, const char *rootName,
     74                        UResourceBundle *currentBundle, const char *locale) {
     75     UErrorCode errorCode = U_ZERO_ERROR;
     76     UResourceBundle *subRootBundle = NULL, *subBundle = NULL, *arr = NULL;
     77 
     78     ures_resetIterator(root);
     79     ures_resetIterator(currentBundle);
     80     while (ures_hasNext(currentBundle)) {
     81         const char *subBundleKey = NULL;
     82         const char *currentBundleKey = NULL;
     83 
     84         errorCode = U_ZERO_ERROR;
     85         currentBundleKey = ures_getKey(currentBundle);
     86         subBundle = ures_getNextResource(currentBundle, NULL, &errorCode);
     87         if (U_FAILURE(errorCode)) {
     88             log_err("Can't open a resource for lnocale %s. Error: %s\n", locale, u_errorName(errorCode));
     89             continue;
     90         }
     91         subBundleKey = ures_getKey(subBundle);
     92 
     93 
     94         subRootBundle = ures_getByKey(root, subBundleKey, NULL, &errorCode);
     95         if (U_FAILURE(errorCode)) {
     96             log_err("Can't open a resource with key \"%s\" in \"%s\" from %s for locale \"%s\"\n",
     97                     subBundleKey,
     98                     ures_getKey(currentBundle),
     99                     rootName,
    100                     locale);
    101             ures_close(subBundle);
    102             continue;
    103         }
    104         if (ures_getType(subRootBundle) != ures_getType(subBundle)) {
    105             log_err("key \"%s\" in \"%s\" has a different type from root for locale \"%s\"\n"
    106                     "\troot=%d, locale=%d\n",
    107                     subBundleKey,
    108                     ures_getKey(currentBundle),
    109                     locale,
    110                     ures_getType(subRootBundle),
    111                     ures_getType(subBundle));
    112             ures_close(subBundle);
    113             continue;
    114         }
    115         else if (ures_getType(subBundle) == URES_INT_VECTOR) {
    116             int32_t minSize;
    117             int32_t subBundleSize;
    118             int32_t idx;
    119             UBool sameArray = TRUE;
    120             const int32_t *subRootBundleArr = ures_getIntVector(subRootBundle, &minSize, &errorCode);
    121             const int32_t *subBundleArr = ures_getIntVector(subBundle, &subBundleSize, &errorCode);
    122 
    123             if (minSize > subBundleSize) {
    124                 minSize = subBundleSize;
    125                 log_err("Arrays are different size with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
    126                         subBundleKey,
    127                         ures_getKey(currentBundle),
    128                         locale);
    129             }
    130 
    131             for (idx = 0; idx < minSize && sameArray; idx++) {
    132                 if (subRootBundleArr[idx] != subBundleArr[idx]) {
    133                     sameArray = FALSE;
    134                 }
    135                 if (strcmp(subBundleKey, "DateTimeElements") == 0
    136                     && (subBundleArr[idx] < 1 || 7 < subBundleArr[idx]))
    137                 {
    138                     log_err("Value out of range with key \"%s\" at index %d in \"%s\" for locale \"%s\"\n",
    139                             subBundleKey,
    140                             idx,
    141                             ures_getKey(currentBundle),
    142                             locale);
    143                 }
    144             }
    145             /* Special exception es_US and DateTimeElements */
    146             if (sameArray
    147                 && !(strcmp(locale, "es_US") == 0 && strcmp(subBundleKey, "DateTimeElements") == 0))
    148             {
    149                 log_err("Integer vectors are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
    150                         subBundleKey,
    151                         ures_getKey(currentBundle),
    152                         locale);
    153             }
    154         }
    155         else if (ures_getType(subBundle) == URES_ARRAY) {
    156             UResourceBundle *subSubBundle = ures_getByIndex(subBundle, 0, NULL, &errorCode);
    157             UResourceBundle *subSubRootBundle = ures_getByIndex(subRootBundle, 0, NULL, &errorCode);
    158 
    159             if (U_SUCCESS(errorCode)
    160                 && (ures_getType(subSubBundle) == URES_ARRAY || ures_getType(subSubRootBundle) == URES_ARRAY))
    161             {
    162                 /* Here is one of the recursive parts */
    163                 TestKeyInRootRecursive(subRootBundle, rootName, subBundle, locale);
    164             }
    165             else {
    166                 int32_t minSize = ures_getSize(subRootBundle);
    167                 int32_t idx;
    168                 UBool sameArray = TRUE;
    169 
    170                 if (minSize > ures_getSize(subBundle)) {
    171                     minSize = ures_getSize(subBundle);
    172                 }
    173 
    174                 if ((subBundleKey == NULL
    175                     || (subBundleKey != NULL &&  strcmp(subBundleKey, "LocaleScript") != 0 && !isCurrencyPreEuro(subBundleKey)))
    176                     && ures_getSize(subRootBundle) != ures_getSize(subBundle))
    177                 {
    178                     log_err("Different size array with key \"%s\" in \"%s\" from root for locale \"%s\"\n"
    179                             "\troot array size=%d, locale array size=%d\n",
    180                             subBundleKey,
    181                             ures_getKey(currentBundle),
    182                             locale,
    183                             ures_getSize(subRootBundle),
    184                             ures_getSize(subBundle));
    185                 }
    186                 /*
    187                 if(isCurrencyPreEuro(subBundleKey) && ures_getSize(subBundle)!=3){
    188                     log_err("Different size array with key \"%s\" in \"%s\" for locale \"%s\" the expected size is 3 got size=%d\n",
    189                             subBundleKey,
    190                             ures_getKey(currentBundle),
    191                             locale,
    192                             ures_getSize(subBundle));
    193                 }
    194                 */
    195                 for (idx = 0; idx < minSize; idx++) {
    196                     int32_t rootStrLen, localeStrLen;
    197                     const UChar *rootStr = ures_getStringByIndex(subRootBundle,idx,&rootStrLen,&errorCode);
    198                     const UChar *localeStr = ures_getStringByIndex(subBundle,idx,&localeStrLen,&errorCode);
    199                     if (rootStr && localeStr && U_SUCCESS(errorCode)) {
    200                         if (u_strcmp(rootStr, localeStr) != 0) {
    201                             sameArray = FALSE;
    202                         }
    203                     }
    204                     else {
    205                         if ( rootStrLen > 1 && rootStr[0] == 0x41 && rootStr[1] >= 0x30 && rootStr[1] <= 0x39 ) {
    206                            /* A2 or A4 in the root string indicates that the resource can optionally be an array instead of a */
    207                            /* string.  Attempt to read it as an array. */
    208                           errorCode = U_ZERO_ERROR;
    209                           arr = ures_getByIndex(subBundle,idx,NULL,&errorCode);
    210                           if (U_FAILURE(errorCode)) {
    211                               log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
    212                                       subBundleKey,
    213                                       ures_getKey(currentBundle),
    214                                       idx,
    215                                       locale);
    216                               continue;
    217                           }
    218                           if (ures_getType(arr) != URES_ARRAY || ures_getSize(arr) != (int32_t)rootStr[1] - 0x30) {
    219                               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",
    220                                       rootStr[1] - 0x30,
    221                                       subBundleKey,
    222                                       ures_getKey(currentBundle),
    223                                       idx,
    224                                       locale);
    225                               ures_close(arr);
    226                               continue;
    227                           }
    228                           localeStr = ures_getStringByIndex(arr,0,&localeStrLen,&errorCode);
    229                           ures_close(arr);
    230                           if (U_FAILURE(errorCode)) {
    231                               log_err("Got something other than a string or array for key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
    232                                       subBundleKey,
    233                                       ures_getKey(currentBundle),
    234                                       idx,
    235                                       locale);
    236                               continue;
    237                           }
    238                         } else {
    239                             log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
    240                                 subBundleKey,
    241                                 ures_getKey(currentBundle),
    242                                 idx,
    243                                 locale);
    244                             continue;
    245                         }
    246                     }
    247                     if (localeStr[0] == (UChar)0x20) {
    248                         log_err("key \"%s\" at index %d in \"%s\" starts with a space in locale \"%s\"\n",
    249                                 subBundleKey,
    250                                 idx,
    251                                 ures_getKey(currentBundle),
    252                                 locale);
    253                     }
    254                     else if ((localeStr[localeStrLen - 1] == (UChar)0x20) && (strcmp(subBundleKey,"separator") != 0)) {
    255                         log_err("key \"%s\" at index %d in \"%s\" ends with a space in locale \"%s\"\n",
    256                                 subBundleKey,
    257                                 idx,
    258                                 ures_getKey(currentBundle),
    259                                 locale);
    260                     }
    261                     else if (subBundleKey != NULL
    262                         && strcmp(subBundleKey, "DateTimePatterns") == 0)
    263                     {
    264                         int32_t quoted = 0;
    265                         const UChar *localeStrItr = localeStr;
    266                         while (*localeStrItr) {
    267                             if (*localeStrItr == (UChar)0x27 /* ' */) {
    268                                 quoted++;
    269                             }
    270                             else if ((quoted % 2) == 0) {
    271                                 /* Search for unquoted characters */
    272                                 if (4 <= idx && idx <= 7
    273                                     && (*localeStrItr == (UChar)0x6B /* k */
    274                                     || *localeStrItr == (UChar)0x48 /* H */
    275                                     || *localeStrItr == (UChar)0x6D /* m */
    276                                     || *localeStrItr == (UChar)0x73 /* s */
    277                                     || *localeStrItr == (UChar)0x53 /* S */
    278                                     || *localeStrItr == (UChar)0x61 /* a */
    279                                     || *localeStrItr == (UChar)0x68 /* h */
    280                                     || *localeStrItr == (UChar)0x7A /* z */))
    281                                 {
    282                                     log_err("key \"%s\" at index %d has time pattern chars in date for locale \"%s\"\n",
    283                                             subBundleKey,
    284                                             idx,
    285                                             locale);
    286                                 }
    287                                 else if (0 <= idx && idx <= 3
    288                                     && (*localeStrItr == (UChar)0x47 /* G */
    289                                     || *localeStrItr == (UChar)0x79 /* y */
    290                                     || *localeStrItr == (UChar)0x4D /* M */
    291                                     || *localeStrItr == (UChar)0x64 /* d */
    292                                     || *localeStrItr == (UChar)0x45 /* E */
    293                                     || *localeStrItr == (UChar)0x44 /* D */
    294                                     || *localeStrItr == (UChar)0x46 /* F */
    295                                     || *localeStrItr == (UChar)0x77 /* w */
    296                                     || *localeStrItr == (UChar)0x57 /* W */))
    297                                 {
    298                                     log_err("key \"%s\" at index %d has date pattern chars in time for locale \"%s\"\n",
    299                                             subBundleKey,
    300                                             idx,
    301                                             locale);
    302                                 }
    303                             }
    304                             localeStrItr++;
    305                         }
    306                     }
    307                     else if (idx == 4 && subBundleKey != NULL
    308                         && strcmp(subBundleKey, "NumberElements") == 0
    309                         && u_charDigitValue(localeStr[0]) != 0)
    310                     {
    311                         log_err("key \"%s\" at index %d has a non-zero based number for locale \"%s\"\n",
    312                                 subBundleKey,
    313                                 idx,
    314                                 locale);
    315                     }
    316                 }
    317 /*                if (sameArray && strcmp(rootName, "root") == 0) {
    318                     log_err("Arrays are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
    319                             subBundleKey,
    320                             ures_getKey(currentBundle),
    321                             locale);
    322                 }*/
    323             }
    324             ures_close(subSubBundle);
    325             ures_close(subSubRootBundle);
    326         }
    327         else if (ures_getType(subBundle) == URES_STRING) {
    328             int32_t len = 0;
    329             const UChar *string = ures_getString(subBundle, &len, &errorCode);
    330             if (U_FAILURE(errorCode) || string == NULL) {
    331                 log_err("Can't open a string with key \"%s\" in \"%s\" for locale \"%s\"\n",
    332                         subBundleKey,
    333                         ures_getKey(currentBundle),
    334                         locale);
    335             } else if (string[0] == (UChar)0x20) {
    336                 log_err("key \"%s\" in \"%s\" starts with a space in locale \"%s\"\n",
    337                         subBundleKey,
    338                         ures_getKey(currentBundle),
    339                         locale);
    340             /* localeDisplayPattern/separator can end with a space */
    341             } else if (string[len - 1] == (UChar)0x20 && (strcmp(subBundleKey,"separator"))) {
    342                 log_err("key \"%s\" in \"%s\" ends with a space in locale \"%s\"\n",
    343                         subBundleKey,
    344                         ures_getKey(currentBundle),
    345                         locale);
    346             } else if (strcmp(subBundleKey, "localPatternChars") == 0) {
    347                 /* Note: We no longer import localPatternChars data starting
    348                  * ICU 3.8.  So it never comes into this else if block. (ticket#5597)
    349                  */
    350 
    351                 /* Check well-formedness of localPatternChars.  First, the
    352                  * length must match the number of fields defined by
    353                  * DateFormat.  Second, each character in the string must
    354                  * be in the set [A-Za-z].  Finally, each character must be
    355                  * unique.
    356                  */
    357                 int32_t i,j;
    358 #if !UCONFIG_NO_FORMATTING
    359                 if (len != UDAT_FIELD_COUNT) {
    360                     log_err("key \"%s\" has the wrong number of characters in locale \"%s\"\n",
    361                             subBundleKey,
    362                             locale);
    363                 }
    364 #endif
    365                 /* Check char validity. */
    366                 for (i=0; i<len; ++i) {
    367                     if (!((string[i] >= 65/*'A'*/ && string[i] <= 90/*'Z'*/) ||
    368                           (string[i] >= 97/*'a'*/ && string[i] <= 122/*'z'*/))) {
    369                         log_err("key \"%s\" has illegal character '%c' in locale \"%s\"\n",
    370                                 subBundleKey,
    371                                 (char) string[i],
    372                                 locale);
    373                     }
    374                     /* Do O(n^2) check for duplicate chars. */
    375                     for (j=0; j<i; ++j) {
    376                         if (string[j] == string[i]) {
    377                             log_err("key \"%s\" has duplicate character '%c' in locale \"%s\"\n",
    378                                     subBundleKey,
    379                                     (char) string[i],
    380                                     locale);
    381                         }
    382                     }
    383                 }
    384             }
    385             /* No fallback was done. Check for duplicate data */
    386             /* The ures_* API does not do fallback of sub-resource bundles,
    387                So we can't do this now. */
    388 #if 0
    389             else if (strcmp(locale, "root") != 0 && errorCode == U_ZERO_ERROR) {
    390 
    391                 const UChar *rootString = ures_getString(subRootBundle, &len, &errorCode);
    392                 if (U_FAILURE(errorCode) || rootString == NULL) {
    393                     log_err("Can't open a string with key \"%s\" in \"%s\" in root\n",
    394                             ures_getKey(subRootBundle),
    395                             ures_getKey(currentBundle));
    396                     continue;
    397                 } else if (u_strcmp(string, rootString) == 0) {
    398                     if (strcmp(locale, "de_CH") != 0 && strcmp(subBundleKey, "Countries") != 0 &&
    399                         strcmp(subBundleKey, "Version") != 0) {
    400                         log_err("Found duplicate data with key \"%s\" in \"%s\" in locale \"%s\"\n",
    401                                 ures_getKey(subRootBundle),
    402                                 ures_getKey(currentBundle),
    403                                 locale);
    404                     }
    405                     else {
    406                         /* Ignore for now. */
    407                         /* Can be fixed if fallback through de locale was done. */
    408                         log_verbose("Skipping key %s in %s\n", subBundleKey, locale);
    409                     }
    410                 }
    411             }
    412 #endif
    413         }
    414         else if (ures_getType(subBundle) == URES_TABLE) {
    415             if (strcmp(subBundleKey, "availableFormats")!=0) {
    416                 /* Here is one of the recursive parts */
    417                 TestKeyInRootRecursive(subRootBundle, rootName, subBundle, locale);
    418             }
    419             else {
    420                 log_verbose("Skipping key %s in %s\n", subBundleKey, locale);
    421             }
    422         }
    423         else if (ures_getType(subBundle) == URES_BINARY || ures_getType(subBundle) == URES_INT) {
    424             /* Can't do anything to check it */
    425             /* We'll assume it's all correct */
    426             if (strcmp(subBundleKey, "MeasurementSystem") != 0) {
    427                 log_verbose("Skipping key \"%s\" in \"%s\" for locale \"%s\"\n",
    428                         subBundleKey,
    429                         ures_getKey(currentBundle),
    430                         locale);
    431             }
    432             /* Testing for MeasurementSystem is done in VerifyTranslation */
    433         }
    434         else {
    435             log_err("Type %d for key \"%s\" in \"%s\" is unknown for locale \"%s\"\n",
    436                     ures_getType(subBundle),
    437                     subBundleKey,
    438                     ures_getKey(currentBundle),
    439                     locale);
    440         }
    441         ures_close(subRootBundle);
    442         ures_close(subBundle);
    443     }
    444 }
    445 #endif
    446 
    447 static void
    448 testLCID(UResourceBundle *currentBundle,
    449          const char *localeName)
    450 {
    451     UErrorCode status = U_ZERO_ERROR;
    452     uint32_t expectedLCID;
    453     char lcidStringC[64] = {0};
    454 
    455     expectedLCID = uloc_getLCID(localeName);
    456     if (expectedLCID == 0) {
    457         log_verbose("INFO:    %-5s does not have any LCID mapping\n",
    458             localeName);
    459         return;
    460     }
    461 
    462     status = U_ZERO_ERROR;
    463     uprv_strcpy(lcidStringC, uprv_convertToPosix(expectedLCID, &status));
    464     if (U_FAILURE(status)) {
    465         log_err("ERROR:   %.4x does not have a POSIX mapping due to %s\n",
    466             expectedLCID, u_errorName(status));
    467     }
    468 
    469     if(strcmp(localeName, lcidStringC) != 0) {
    470         char langName[1024];
    471         char langLCID[1024];
    472         uloc_getLanguage(localeName, langName, sizeof(langName), &status);
    473         uloc_getLanguage(lcidStringC, langLCID, sizeof(langLCID), &status);
    474 
    475         if (strcmp(langName, langLCID) == 0) {
    476             log_verbose("WARNING: %-5s resolves to %s (0x%.4x)\n",
    477                 localeName, lcidStringC, expectedLCID);
    478         }
    479         else {
    480             log_err("ERROR:   %-5s has 0x%.4x and the number resolves wrongfully to %s\n",
    481                 localeName, expectedLCID, lcidStringC);
    482         }
    483     }
    484 }
    485 
    486 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
    487 static void
    488 TestLocaleStructure(void) {
    489     UResourceBundle *root, *currentLocale;
    490     int32_t locCount = uloc_countAvailable();
    491     int32_t locIndex;
    492     UErrorCode errorCode = U_ZERO_ERROR;
    493     const char *currLoc, *resolvedLoc;
    494 
    495     /* TODO: Compare against parent's data too. This code can't handle fallbacks that some tools do already. */
    496 /*    char locName[ULOC_FULLNAME_CAPACITY];
    497     char *locNamePtr;
    498 
    499     for (locIndex = 0; locIndex < locCount; locIndex++) {
    500         errorCode=U_ZERO_ERROR;
    501         strcpy(locName, uloc_getAvailable(locIndex));
    502         locNamePtr = strrchr(locName, '_');
    503         if (locNamePtr) {
    504             *locNamePtr = 0;
    505         }
    506         else {
    507             strcpy(locName, "root");
    508         }
    509 
    510         root = ures_openDirect(NULL, locName, &errorCode);
    511         if(U_FAILURE(errorCode)) {
    512             log_err("Can't open %s\n", locName);
    513             continue;
    514         }
    515 */
    516     if (locCount <= 1) {
    517         log_data_err("At least root needs to be installed\n");
    518     }
    519 
    520     root = ures_openDirect(loadTestData(&errorCode), "structLocale", &errorCode);
    521     if(U_FAILURE(errorCode)) {
    522         log_data_err("Can't open structLocale\n");
    523         return;
    524     }
    525     for (locIndex = 0; locIndex < locCount; locIndex++) {
    526         errorCode=U_ZERO_ERROR;
    527         currLoc = uloc_getAvailable(locIndex);
    528         currentLocale = ures_open(NULL, currLoc, &errorCode);
    529         if(errorCode != U_ZERO_ERROR) {
    530             if(U_SUCCESS(errorCode)) {
    531                 /* It's installed, but there is no data.
    532                    It's installed for the g18n white paper [grhoten] */
    533                 log_err("ERROR: Locale %-5s not installed, and it should be, err %s\n",
    534                     uloc_getAvailable(locIndex), u_errorName(errorCode));
    535             } else {
    536                 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
    537                     u_errorName(errorCode),
    538                     uloc_getAvailable(locIndex));
    539             }
    540             ures_close(currentLocale);
    541             continue;
    542         }
    543         ures_getStringByKey(currentLocale, "Version", NULL, &errorCode);
    544         if(errorCode != U_ZERO_ERROR) {
    545             log_err("No version information is available for locale %s, and it should be!\n",
    546                 currLoc);
    547         }
    548         else if (ures_getStringByKey(currentLocale, "Version", NULL, &errorCode)[0] == (UChar)(0x78)) {
    549             log_verbose("WARNING: The locale %s is experimental! It shouldn't be listed as an installed locale.\n",
    550                 currLoc);
    551         }
    552         resolvedLoc = ures_getLocaleByType(currentLocale, ULOC_ACTUAL_LOCALE, &errorCode);
    553         if (strcmp(resolvedLoc, currLoc) != 0) {
    554             /* All locales have at least a Version resource.
    555                If it's absolutely empty, then the previous test will fail too.*/
    556             log_err("Locale resolves to different locale. Is %s an alias of %s?\n",
    557                 currLoc, resolvedLoc);
    558         }
    559         TestKeyInRootRecursive(root, "root", currentLocale, currLoc);
    560 
    561         testLCID(currentLocale, currLoc);
    562 
    563         ures_close(currentLocale);
    564     }
    565 
    566     ures_close(root);
    567 }
    568 #endif
    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] != 0x005B && string[strIdx] != 0x005D && 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     UResourceBundle *root, *currentLocale;
    871     int32_t locCount = uloc_countAvailable();
    872     int32_t locIndex;
    873     UErrorCode errorCode = U_ZERO_ERROR;
    874     int32_t exemplarLen;
    875     const UChar *exemplarCharacters;
    876     const char *currLoc;
    877     UScriptCode scripts[USCRIPT_CODE_LIMIT];
    878     int32_t numScripts;
    879     int32_t idx;
    880     int32_t end;
    881     UResourceBundle *resArray;
    882 
    883     if (locCount <= 1) {
    884         log_data_err("At least root needs to be installed\n");
    885     }
    886 
    887     root = ures_openDirect(NULL, "root", &errorCode);
    888     if(U_FAILURE(errorCode)) {
    889         log_data_err("Can't open root\n");
    890         return;
    891     }
    892     for (locIndex = 0; locIndex < locCount; locIndex++) {
    893         errorCode=U_ZERO_ERROR;
    894         currLoc = uloc_getAvailable(locIndex);
    895         currentLocale = ures_open(NULL, currLoc, &errorCode);
    896         if(errorCode != U_ZERO_ERROR) {
    897             if(U_SUCCESS(errorCode)) {
    898                 /* It's installed, but there is no data.
    899                    It's installed for the g18n white paper [grhoten] */
    900                 log_err("ERROR: Locale %-5s not installed, and it should be!\n",
    901                     uloc_getAvailable(locIndex));
    902             } else {
    903                 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
    904                     u_errorName(errorCode),
    905                     uloc_getAvailable(locIndex));
    906             }
    907             ures_close(currentLocale);
    908             continue;
    909         }
    910         exemplarCharacters = ures_getStringByKey(currentLocale, "ExemplarCharacters", &exemplarLen, &errorCode);
    911         if (U_FAILURE(errorCode)) {
    912             log_err("error ures_getStringByKey returned %s\n", u_errorName(errorCode));
    913         }
    914         else if (getTestOption(QUICK_OPTION) && exemplarLen > 2048) {
    915             log_verbose("skipping test for %s\n", currLoc);
    916         }
    917         else if (uprv_strncmp(currLoc,"bem",3) == 0 || uprv_strncmp(currLoc,"mgo",3) == 0 || uprv_strncmp(currLoc,"nl",2) == 0) {
    918             log_verbose("skipping test for %s, some month and country names known to use aux exemplars\n", currLoc);
    919         }
    920         else {
    921             UChar langBuffer[128];
    922             int32_t langSize;
    923             int32_t strIdx;
    924             UChar badChar;
    925             langSize = uloc_getDisplayLanguage(currLoc, currLoc, langBuffer, sizeof(langBuffer)/sizeof(langBuffer[0]), &errorCode);
    926             if (U_FAILURE(errorCode)) {
    927                 log_err("error uloc_getDisplayLanguage returned %s\n", u_errorName(errorCode));
    928             }
    929             else {
    930                 strIdx = findStringSetMismatch(currLoc, langBuffer, langSize, exemplarCharacters, exemplarLen, FALSE, &badChar);
    931                 if (strIdx >= 0) {
    932                     log_err("getDisplayLanguage(%s) at index %d returned characters not in the exemplar characters: %04X.\n",
    933                         currLoc, strIdx, badChar);
    934                 }
    935             }
    936             langSize = uloc_getDisplayCountry(currLoc, currLoc, langBuffer, sizeof(langBuffer)/sizeof(langBuffer[0]), &errorCode);
    937             if (U_FAILURE(errorCode)) {
    938                 log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode));
    939             }
    940             else if (uprv_strstr(currLoc, "ti_") != currLoc || isICUVersionAtLeast(51, 0, 0)) { /* TODO: restore DisplayCountry test for ti_* when cldrbug 3058 is fixed) */
    941               strIdx = findStringSetMismatch(currLoc, langBuffer, langSize, exemplarCharacters, exemplarLen, FALSE, &badChar);
    942                 if (strIdx >= 0) {
    943                     log_err("getDisplayCountry(%s) at index %d returned characters not in the exemplar characters: %04X.\n",
    944                         currLoc, strIdx, badChar);
    945                 }
    946             }
    947             {
    948                 UResourceBundle* cal = ures_getByKey(currentLocale, "calendar", NULL, &errorCode);
    949                 UResourceBundle* greg = ures_getByKeyWithFallback(cal, "gregorian", NULL, &errorCode);
    950                 UResourceBundle* names = ures_getByKeyWithFallback(greg,  "dayNames", NULL, &errorCode);
    951                 UResourceBundle* format = ures_getByKeyWithFallback(names,  "format", NULL, &errorCode);
    952                 resArray = ures_getByKeyWithFallback(format,  "wide", NULL, &errorCode);
    953 
    954                 if (U_FAILURE(errorCode)) {
    955                     log_err("error ures_getByKey returned %s\n", u_errorName(errorCode));
    956                 }
    957                 if (getTestOption(QUICK_OPTION)) {
    958                     end = 1;
    959                 }
    960                 else {
    961                     end = ures_getSize(resArray);
    962                 }
    963 
    964 
    965                 for (idx = 0; idx < end; idx++) {
    966                     const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode);
    967                     if (U_FAILURE(errorCode)) {
    968                         log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode));
    969                         continue;
    970                     }
    971                     strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, exemplarCharacters, exemplarLen, TRUE, &badChar);
    972                     if (strIdx >= 0) {
    973                         log_err("getDayNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
    974                             currLoc, idx, strIdx, badChar);
    975                     }
    976                 }
    977                 ures_close(resArray);
    978                 ures_close(format);
    979                 ures_close(names);
    980 
    981                 names = ures_getByKeyWithFallback(greg, "monthNames", NULL, &errorCode);
    982                 format = ures_getByKeyWithFallback(names,"format", NULL, &errorCode);
    983                 resArray = ures_getByKeyWithFallback(format, "wide", NULL, &errorCode);
    984                 if (U_FAILURE(errorCode)) {
    985                     log_err("error ures_getByKey returned %s\n", u_errorName(errorCode));
    986                 }
    987                 if (getTestOption(QUICK_OPTION)) {
    988                     end = 1;
    989                 }
    990                 else {
    991                     end = ures_getSize(resArray);
    992                 }
    993 
    994                 for (idx = 0; idx < end; idx++) {
    995                     const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode);
    996                     if (U_FAILURE(errorCode)) {
    997                         log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode));
    998                         continue;
    999                     }
   1000                     strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, exemplarCharacters, exemplarLen, TRUE, &badChar);
   1001                     if (strIdx >= 0) {
   1002                         log_err("getMonthNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
   1003                             currLoc, idx, strIdx, badChar);
   1004                     }
   1005                 }
   1006                 ures_close(resArray);
   1007                 ures_close(format);
   1008                 ures_close(names);
   1009                 ures_close(greg);
   1010                 ures_close(cal);
   1011             }
   1012             errorCode = U_ZERO_ERROR;
   1013             numScripts = uscript_getCode(currLoc, scripts, sizeof(scripts)/sizeof(scripts[0]), &errorCode);
   1014             if (numScripts == 0) {
   1015                 log_err("uscript_getCode(%s) doesn't work.\n", currLoc);
   1016             }else if(scripts[0] == USCRIPT_COMMON){
   1017                 log_err("uscript_getCode(%s) returned USCRIPT_COMMON.\n", currLoc);
   1018             }
   1019 
   1020             /* test that the scripts are a superset of exemplar characters. */
   1021            {
   1022                 ULocaleData *uld = ulocdata_open(currLoc,&errorCode);
   1023                 USet *exemplarSet =  ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_STANDARD, &errorCode);
   1024                 /* test if exemplar characters are part of script code */
   1025                 findSetMatch(scripts, numScripts, exemplarSet, currLoc);
   1026                 uset_close(exemplarSet);
   1027                 ulocdata_close(uld);
   1028             }
   1029 
   1030            /* test that the paperSize API works */
   1031            {
   1032                int32_t height=0, width=0;
   1033                ulocdata_getPaperSize(currLoc, &height, &width, &errorCode);
   1034                if(U_FAILURE(errorCode)){
   1035                    log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
   1036                }
   1037                if(strstr(currLoc, "_US")!=NULL && height != 279 && width != 216 ){
   1038                    log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
   1039                }
   1040            }
   1041             /* test that the MeasurementSystem works API works */
   1042            {
   1043                UMeasurementSystem measurementSystem = ulocdata_getMeasurementSystem(currLoc, &errorCode);
   1044                if(U_FAILURE(errorCode)){
   1045                    log_err("ulocdata_getMeasurementSystem failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
   1046                }
   1047                if(strstr(currLoc, "_US")!=NULL || strstr(currLoc, "_MM")!=NULL || strstr(currLoc, "_LR")!=NULL){
   1048                    if(measurementSystem != UMS_US){
   1049                         log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
   1050                    }
   1051                }else if(measurementSystem != UMS_SI){
   1052                    log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
   1053                }
   1054            }
   1055         }
   1056         ures_close(currentLocale);
   1057     }
   1058 
   1059     ures_close(root);
   1060 }
   1061 
   1062 /* adjust this limit as appropriate */
   1063 #define MAX_SCRIPTS_PER_LOCALE 8
   1064 
   1065 static void TestExemplarSet(void){
   1066     int32_t i, j, k, m, n;
   1067     int32_t equalCount = 0;
   1068     UErrorCode ec = U_ZERO_ERROR;
   1069     UEnumeration* avail;
   1070     USet* exemplarSets[2];
   1071     USet* unassignedSet;
   1072     UScriptCode code[MAX_SCRIPTS_PER_LOCALE];
   1073     USet* codeSets[MAX_SCRIPTS_PER_LOCALE];
   1074     int32_t codeLen;
   1075     char cbuf[32]; /* 9 should be enough */
   1076     UChar ubuf[64]; /* adjust as needed */
   1077     UBool existsInScript;
   1078     int32_t itemCount;
   1079     int32_t strLen;
   1080     UChar32 start, end;
   1081 
   1082     unassignedSet = NULL;
   1083     exemplarSets[0] = NULL;
   1084     exemplarSets[1] = NULL;
   1085     for (i=0; i<MAX_SCRIPTS_PER_LOCALE; ++i) {
   1086         codeSets[i] = NULL;
   1087     }
   1088 
   1089     avail = ures_openAvailableLocales(NULL, &ec);
   1090     if (!assertSuccess("ures_openAvailableLocales", &ec)) goto END;
   1091     n = uenum_count(avail, &ec);
   1092     if (!assertSuccess("uenum_count", &ec)) goto END;
   1093 
   1094     u_uastrcpy(ubuf, "[:unassigned:]");
   1095     unassignedSet = uset_openPattern(ubuf, -1, &ec);
   1096     if (!assertSuccess("uset_openPattern", &ec)) goto END;
   1097 
   1098     for(i=0; i<n; i++){
   1099         const char* locale = uenum_next(avail, NULL, &ec);
   1100         if (!assertSuccess("uenum_next", &ec)) goto END;
   1101         log_verbose("%s\n", locale);
   1102         for (k=0; k<2; ++k) {
   1103             uint32_t option = (k==0) ? 0 : USET_CASE_INSENSITIVE;
   1104             ULocaleData *uld = ulocdata_open(locale,&ec);
   1105             USet* exemplarSet = ulocdata_getExemplarSet(uld,NULL, option, ULOCDATA_ES_STANDARD, &ec);
   1106             uset_close(exemplarSets[k]);
   1107             ulocdata_close(uld);
   1108             exemplarSets[k] = exemplarSet;
   1109             if (!assertSuccess("ulocaledata_getExemplarSet", &ec)) goto END;
   1110 
   1111             if (uset_containsSome(exemplarSet, unassignedSet)) {
   1112                 log_err("ExemplarSet contains unassigned characters for locale : %s\n", locale);
   1113             }
   1114             codeLen = uscript_getCode(locale, code, 8, &ec);
   1115             if (!assertSuccess("uscript_getCode", &ec)) goto END;
   1116 
   1117             for (j=0; j<MAX_SCRIPTS_PER_LOCALE; ++j) {
   1118                 uset_close(codeSets[j]);
   1119                 codeSets[j] = NULL;
   1120             }
   1121             for (j=0; j<codeLen; ++j) {
   1122                 uprv_strcpy(cbuf, "[:");
   1123                 if(code[j]==-1){
   1124                     log_err("USCRIPT_INVALID_CODE returned for locale: %s\n", locale);
   1125                     continue;
   1126                 }
   1127                 uprv_strcat(cbuf, uscript_getShortName(code[j]));
   1128                 uprv_strcat(cbuf, ":]");
   1129                 u_uastrcpy(ubuf, cbuf);
   1130                 codeSets[j] = uset_openPattern(ubuf, -1, &ec);
   1131             }
   1132             if (!assertSuccess("uset_openPattern", &ec)) goto END;
   1133 
   1134             existsInScript = FALSE;
   1135             itemCount = uset_getItemCount(exemplarSet);
   1136             for (m=0; m<itemCount && !existsInScript; ++m) {
   1137                 strLen = uset_getItem(exemplarSet, m, &start, &end, ubuf,
   1138                                       sizeof(ubuf)/sizeof(ubuf[0]), &ec);
   1139                 /* failure here might mean str[] needs to be larger */
   1140                 if (!assertSuccess("uset_getItem", &ec)) goto END;
   1141                 if (strLen == 0) {
   1142                     for (j=0; j<codeLen; ++j) {
   1143                         if (codeSets[j]!=NULL && uset_containsRange(codeSets[j], start, end)) {
   1144                             existsInScript = TRUE;
   1145                             break;
   1146                         }
   1147                     }
   1148                 } else {
   1149                     for (j=0; j<codeLen; ++j) {
   1150                         if (codeSets[j]!=NULL && uset_containsString(codeSets[j], ubuf, strLen)) {
   1151                             existsInScript = TRUE;
   1152                             break;
   1153                         }
   1154                     }
   1155                 }
   1156             }
   1157 
   1158             if (existsInScript == FALSE){
   1159                 log_err("ExemplarSet containment failed for locale : %s\n", locale);
   1160             }
   1161         }
   1162         assertTrue("case-folded is a superset",
   1163                    uset_containsAll(exemplarSets[1], exemplarSets[0]));
   1164         if (uset_equals(exemplarSets[1], exemplarSets[0])) {
   1165             ++equalCount;
   1166         }
   1167     }
   1168     /* Note: The case-folded set should sometimes be a strict superset
   1169        and sometimes be equal. */
   1170     assertTrue("case-folded is sometimes a strict superset, and sometimes equal",
   1171                equalCount > 0 && equalCount < n);
   1172 
   1173  END:
   1174     uenum_close(avail);
   1175     uset_close(exemplarSets[0]);
   1176     uset_close(exemplarSets[1]);
   1177     uset_close(unassignedSet);
   1178     for (i=0; i<MAX_SCRIPTS_PER_LOCALE; ++i) {
   1179         uset_close(codeSets[i]);
   1180     }
   1181 }
   1182 
   1183 static void TestLocaleDisplayPattern(void){
   1184     UErrorCode status = U_ZERO_ERROR;
   1185     UChar pattern[32] = {0,};
   1186     UChar separator[32] = {0,};
   1187     ULocaleData *uld = ulocdata_open(uloc_getDefault(), &status);
   1188 
   1189     if(U_FAILURE(status)){
   1190         log_data_err("ulocdata_open error");
   1191         return;
   1192     }
   1193     ulocdata_getLocaleDisplayPattern(uld, pattern, 32, &status);
   1194     if (U_FAILURE(status)){
   1195         log_err("ulocdata_getLocaleDisplayPattern error!");
   1196     }
   1197     status = U_ZERO_ERROR;
   1198     ulocdata_getLocaleSeparator(uld, separator, 32, &status);
   1199     if (U_FAILURE(status)){
   1200         log_err("ulocdata_getLocaleSeparator error!");
   1201     }
   1202     ulocdata_close(uld);
   1203 }
   1204 
   1205 static void TestCoverage(void){
   1206     ULocaleDataDelimiterType types[] = {
   1207      ULOCDATA_QUOTATION_START,     /* Quotation start */
   1208      ULOCDATA_QUOTATION_END,       /* Quotation end */
   1209      ULOCDATA_ALT_QUOTATION_START, /* Alternate quotation start */
   1210      ULOCDATA_ALT_QUOTATION_END,   /* Alternate quotation end */
   1211      ULOCDATA_DELIMITER_COUNT
   1212     };
   1213     int i;
   1214     UBool sub;
   1215     UErrorCode status = U_ZERO_ERROR;
   1216     ULocaleData *uld = ulocdata_open(uloc_getDefault(), &status);
   1217 
   1218     if(U_FAILURE(status)){
   1219         log_data_err("ulocdata_open error");
   1220         return;
   1221     }
   1222 
   1223 
   1224     for(i = 0; i < ULOCDATA_DELIMITER_COUNT; i++){
   1225         UChar result[32] = {0,};
   1226         status = U_ZERO_ERROR;
   1227         ulocdata_getDelimiter(uld, types[i], result, 32, &status);
   1228         if (U_FAILURE(status)){
   1229             log_err("ulocdata_getgetDelimiter error with type %d", types[i]);
   1230         }
   1231     }
   1232 
   1233     sub = ulocdata_getNoSubstitute(uld);
   1234     ulocdata_setNoSubstitute(uld,sub);
   1235     ulocdata_close(uld);
   1236 }
   1237 
   1238 static void TestIndexChars(void) {
   1239     /* Very basic test of ULOCDATA_ES_INDEX.
   1240      * No comprehensive test of data, just basic check that the code path is alive.
   1241      */
   1242     UErrorCode status = U_ZERO_ERROR;
   1243     ULocaleData  *uld;
   1244     USet *exemplarChars;
   1245     USet *indexChars;
   1246 
   1247     uld = ulocdata_open("en", &status);
   1248     exemplarChars = uset_openEmpty();
   1249     indexChars = uset_openEmpty();
   1250     ulocdata_getExemplarSet(uld, exemplarChars, 0, ULOCDATA_ES_STANDARD, &status);
   1251     ulocdata_getExemplarSet(uld, indexChars, 0, ULOCDATA_ES_INDEX, &status);
   1252     if (U_FAILURE(status)) {
   1253         log_data_err("File %s, line %d, Failure opening exemplar chars: %s", __FILE__, __LINE__, u_errorName(status));
   1254         goto close_sets;
   1255     }
   1256     /* en data, standard exemplars are [a-z], lower case. */
   1257     /* en data, index characters are [A-Z], upper case. */
   1258     if ((uset_contains(exemplarChars, (UChar32)0x41) || uset_contains(indexChars, (UChar32)0x61))) {
   1259         log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__, __LINE__ );
   1260         goto close_sets;
   1261     }
   1262     if (!(uset_contains(exemplarChars, (UChar32)0x61) && uset_contains(indexChars, (UChar32)0x41) )) {
   1263         log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__, __LINE__ );
   1264         goto close_sets;
   1265     }
   1266 
   1267   close_sets:
   1268     uset_close(exemplarChars);
   1269     uset_close(indexChars);
   1270     ulocdata_close(uld);
   1271 }
   1272 
   1273 
   1274 
   1275 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
   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 #endif
   1311 
   1312 static void TestAvailableIsoCodes(void){
   1313 #if !UCONFIG_NO_FORMATTING
   1314     UErrorCode errorCode = U_ZERO_ERROR;
   1315     const char* eurCode = "EUR";
   1316     const char* usdCode = "USD";
   1317     const char* lastCode = "RHD";
   1318     const char* zzzCode = "ZZZ";
   1319     UDate date1950 = (UDate)-630720000000.0;/* year 1950 */
   1320     UDate date1970 = (UDate)0.0;            /* year 1970 */
   1321     UDate date1975 = (UDate)173448000000.0; /* year 1975 */
   1322     UDate date1978 = (UDate)260172000000.0; /* year 1978 */
   1323     UDate date1981 = (UDate)346896000000.0; /* year 1981 */
   1324     UDate date1992 = (UDate)693792000000.0; /* year 1992 */
   1325     UChar* isoCode = (UChar*)malloc(sizeof(UChar) * (uprv_strlen(usdCode) + 1));
   1326 
   1327     /* testing available codes with no time ranges */
   1328     u_charsToUChars(eurCode, isoCode, uprv_strlen(usdCode) + 1);
   1329     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
   1330        log_data_err("FAIL: ISO code (%s) is not found.\n", eurCode);
   1331     }
   1332 
   1333     u_charsToUChars(usdCode, isoCode, uprv_strlen(zzzCode) + 1);
   1334     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
   1335        log_data_err("FAIL: ISO code (%s) is not found.\n", usdCode);
   1336     }
   1337 
   1338     u_charsToUChars(zzzCode, isoCode, uprv_strlen(zzzCode) + 1);
   1339     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == TRUE) {
   1340        log_err("FAIL: ISO code (%s) is reported as available, but it doesn't exist.\n", zzzCode);
   1341     }
   1342 
   1343     u_charsToUChars(lastCode, isoCode, uprv_strlen(zzzCode) + 1);
   1344     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
   1345        log_data_err("FAIL: ISO code (%s) is not found.\n", lastCode);
   1346     }
   1347 
   1348     /* RHD was used from 1970-02-17  to 1980-04-18*/
   1349 
   1350     /* to = null */
   1351     if (ucurr_isAvailable(isoCode, date1970, U_DATE_MAX, &errorCode) == FALSE) {
   1352        log_data_err("FAIL: ISO code (%s) was available in time range >1970-01-01.\n", lastCode);
   1353     }
   1354 
   1355     if (ucurr_isAvailable(isoCode, date1975, U_DATE_MAX, &errorCode) == FALSE) {
   1356        log_data_err("FAIL: ISO code (%s) was available in time range >1975.\n", lastCode);
   1357     }
   1358 
   1359     if (ucurr_isAvailable(isoCode, date1981, U_DATE_MAX, &errorCode) == TRUE) {
   1360        log_err("FAIL: ISO code (%s) was not available in time range >1981.\n", lastCode);
   1361     }
   1362 
   1363     /* from = null */
   1364     if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1970, &errorCode) == TRUE) {
   1365        log_err("FAIL: ISO code (%s) was not available in time range <1970.\n", lastCode);
   1366     }
   1367 
   1368     if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1975, &errorCode) == FALSE) {
   1369        log_data_err("FAIL: ISO code (%s) was available in time range <1975.\n", lastCode);
   1370     }
   1371 
   1372     if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1981, &errorCode) == FALSE) {
   1373        log_data_err("FAIL: ISO code (%s) was available in time range <1981.\n", lastCode);
   1374     }
   1375 
   1376     /* full ranges */
   1377     if (ucurr_isAvailable(isoCode, date1975, date1978, &errorCode) == FALSE) {
   1378        log_data_err("FAIL: ISO code (%s) was available in time range 1975-1978.\n", lastCode);
   1379     }
   1380 
   1381     if (ucurr_isAvailable(isoCode, date1970, date1975, &errorCode) == FALSE) {
   1382        log_data_err("FAIL: ISO code (%s) was available in time range 1970-1975.\n", lastCode);
   1383     }
   1384 
   1385     if (ucurr_isAvailable(isoCode, date1975, date1981, &errorCode) == FALSE) {
   1386        log_data_err("FAIL: ISO code (%s) was available in time range 1975-1981.\n", lastCode);
   1387     }
   1388 
   1389     if (ucurr_isAvailable(isoCode, date1970,  date1981, &errorCode) == FALSE) {
   1390        log_data_err("FAIL: ISO code (%s) was available in time range 1970-1981.\n", lastCode);
   1391     }
   1392 
   1393     if (ucurr_isAvailable(isoCode, date1981,  date1992, &errorCode) == TRUE) {
   1394        log_err("FAIL: ISO code (%s) was not available in time range 1981-1992.\n", lastCode);
   1395     }
   1396 
   1397     if (ucurr_isAvailable(isoCode, date1950,  date1970, &errorCode) == TRUE) {
   1398        log_err("FAIL: ISO code (%s) was not available in time range 1950-1970.\n", lastCode);
   1399     }
   1400 
   1401     /* wrong range - from > to*/
   1402     if (ucurr_isAvailable(isoCode, date1975,  date1970, &errorCode) == TRUE) {
   1403        log_err("FAIL: Wrong range 1975-1970 for ISO code (%s) was not reported.\n", lastCode);
   1404     } else if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
   1405        log_data_err("FAIL: Error code not reported for wrong range 1975-1970 for ISO code (%s).\n", lastCode);
   1406     }
   1407 
   1408     free(isoCode);
   1409 #endif
   1410 }
   1411 
   1412 #define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name)
   1413 
   1414 void addCLDRTest(TestNode** root);
   1415 
   1416 void addCLDRTest(TestNode** root)
   1417 {
   1418 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
   1419     TESTCASE(TestLocaleStructure);
   1420     TESTCASE(TestCurrencyList);
   1421 #endif
   1422     TESTCASE(TestConsistentCountryInfo);
   1423     TESTCASE(VerifyTranslation);
   1424     TESTCASE(TestExemplarSet);
   1425     TESTCASE(TestLocaleDisplayPattern);
   1426     TESTCASE(TestCoverage);
   1427     TESTCASE(TestIndexChars);
   1428     TESTCASE(TestAvailableIsoCodes);
   1429 }
   1430 
   1431