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