• 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         currentLocale = ures_open(NULL, currLoc, &errorCode);
919         if(errorCode != U_ZERO_ERROR) {
920             if(U_SUCCESS(errorCode)) {
921                 /* It's installed, but there is no data.
922                    It's installed for the g18n white paper [grhoten] */
923                 log_err("ERROR: Locale %-5s not installed, and it should be!\n",
924                     uloc_getAvailable(locIndex));
925             } else {
926                 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
927                     u_errorName(errorCode),
928                     uloc_getAvailable(locIndex));
929             }
930             ures_close(currentLocale);
931             continue;
932         }
933         {
934             UErrorCode exemplarStatus = U_ZERO_ERROR;
935             ULocaleData * uld = ulocdata_open(currLoc, &exemplarStatus);
936             if (U_SUCCESS(exemplarStatus)) {
937                 USet * exemplarSet = ulocdata_getExemplarSet(uld, NULL, USET_ADD_CASE_MAPPINGS, ULOCDATA_ES_STANDARD, &exemplarStatus);
938                 if (U_SUCCESS(exemplarStatus)) {
939                     mergedExemplarSet = uset_cloneAsThawed(exemplarSet);
940                     uset_close(exemplarSet);
941                     exemplarSet = ulocdata_getExemplarSet(uld, NULL, USET_ADD_CASE_MAPPINGS, ULOCDATA_ES_AUXILIARY, &exemplarStatus);
942                     if (U_SUCCESS(exemplarStatus)) {
943                         uset_addAll(mergedExemplarSet, exemplarSet);
944                         uset_close(exemplarSet);
945                     }
946                     exemplarStatus = U_ZERO_ERROR;
947                     exemplarSet = ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_PUNCTUATION, &exemplarStatus);
948                     if (U_SUCCESS(exemplarStatus)) {
949                         uset_addAll(mergedExemplarSet, exemplarSet);
950                         uset_close(exemplarSet);
951                     }
952                 } else {
953                     log_err("error ulocdata_getExemplarSet (main) for locale %s returned %s\n", currLoc, u_errorName(errorCode));
954                 }
955                 ulocdata_close(uld);
956             } else {
957                 log_err("error ulocdata_open for locale %s returned %s\n", currLoc, u_errorName(errorCode));
958             }
959         }
960         if (mergedExemplarSet == NULL /*|| (getTestOption(QUICK_OPTION) && uset_size() > 2048)*/) {
961             log_verbose("skipping test for %s\n", currLoc);
962         }
963         //else if (uprv_strncmp(currLoc,"bem",3) == 0 || uprv_strncmp(currLoc,"mgo",3) == 0 || uprv_strncmp(currLoc,"nl",2) == 0) {
964         //    log_verbose("skipping test for %s, some month and country names known to use aux exemplars\n", currLoc);
965         //}
966         else {
967             UChar langBuffer[128];
968             int32_t langSize;
969             int32_t strIdx;
970             UChar32 badChar;
971             langSize = uloc_getDisplayLanguage(currLoc, currLoc, langBuffer, UPRV_LENGTHOF(langBuffer), &errorCode);
972             if (U_FAILURE(errorCode)) {
973                 log_err("error uloc_getDisplayLanguage returned %s\n", u_errorName(errorCode));
974             }
975             else {
976                 strIdx = findStringSetMismatch(currLoc, langBuffer, langSize, mergedExemplarSet, false, &badChar);
977                 if (strIdx >= 0) {
978                     log_err("getDisplayLanguage(%s) at index %d returned characters not in the exemplar characters: %04X.\n",
979                         currLoc, strIdx, badChar);
980                 }
981             }
982             langSize = uloc_getDisplayCountry(currLoc, currLoc, langBuffer, UPRV_LENGTHOF(langBuffer), &errorCode);
983             if (U_FAILURE(errorCode)) {
984                 log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode));
985             }
986             {
987                 UResourceBundle* cal = ures_getByKey(currentLocale, "calendar", NULL, &errorCode);
988                 UResourceBundle* greg = ures_getByKeyWithFallback(cal, "gregorian", NULL, &errorCode);
989                 UResourceBundle* names = ures_getByKeyWithFallback(greg,  "dayNames", NULL, &errorCode);
990                 UResourceBundle* format = ures_getByKeyWithFallback(names,  "format", NULL, &errorCode);
991                 resArray = ures_getByKeyWithFallback(format,  "wide", NULL, &errorCode);
992 
993                 if (U_FAILURE(errorCode)) {
994                     log_err("error ures_getByKey returned %s\n", u_errorName(errorCode));
995                 }
996                 if (getTestOption(QUICK_OPTION)) {
997                     end = 1;
998                 }
999                 else {
1000                     end = ures_getSize(resArray);
1001                 }
1002 
1003                 if ((uprv_strncmp(currLoc,"lrc",3) == 0 || uprv_strncmp(currLoc,"mzn",3) == 0) &&
1004                         log_knownIssue("cldrbug:8899", "lrc and mzn locales don't have translated day names")) {
1005                     end = 0;
1006                 }
1007                 if ((uprv_strncmp(currLoc,"mai",3) == 0 || uprv_strncmp(currLoc,"sd_Deva",7) == 0) &&
1008                         log_knownIssue("cldrbug:14995", "mai/sd_Deva day names use chars not in exemplars")) {
1009                     end = 0;
1010                 }
1011                 if (uprv_strncmp(currLoc,"ks_Deva",7) == 0 &&
1012                         log_knownIssue("cldrbug:15355", "ks_Deva day names use chars not in exemplars")) {
1013                     end = 0;
1014                 }
1015 
1016                 for (idx = 0; idx < end; idx++) {
1017                     const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode);
1018                     if (U_FAILURE(errorCode)) {
1019                         log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode));
1020                         continue;
1021                     }
1022                     strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, mergedExemplarSet, true, &badChar);
1023                     if ( strIdx >= 0 ) {
1024                         log_err("getDayNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1025                             currLoc, idx, strIdx, badChar);
1026                     }
1027                 }
1028                 ures_close(resArray);
1029                 ures_close(format);
1030                 ures_close(names);
1031 
1032                 names = ures_getByKeyWithFallback(greg, "monthNames", NULL, &errorCode);
1033                 format = ures_getByKeyWithFallback(names,"format", NULL, &errorCode);
1034                 resArray = ures_getByKeyWithFallback(format, "wide", NULL, &errorCode);
1035                 if (U_FAILURE(errorCode)) {
1036                     log_err("error ures_getByKey returned %s\n", u_errorName(errorCode));
1037                 }
1038                 if (getTestOption(QUICK_OPTION)) {
1039                     end = 1;
1040                 }
1041                 else {
1042                     end = ures_getSize(resArray);
1043                 }
1044                 if (uprv_strncmp(currLoc,"sd_Deva",7) == 0 &&
1045                         log_knownIssue("cldrbug:14995", "sd_Deva month names use chars not in exemplars")) {
1046                     end = 0;
1047                 }
1048                 if (uprv_strncmp(currLoc,"ks_Deva",7) == 0 &&
1049                         log_knownIssue("cldrbug:15355", "ks_Deva month names use chars not in exemplars")) {
1050                     end = 0;
1051                 }
1052 
1053                 for (idx = 0; idx < end; idx++) {
1054                     const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode);
1055                     if (U_FAILURE(errorCode)) {
1056                         log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode));
1057                         continue;
1058                     }
1059                     strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, mergedExemplarSet, true, &badChar);
1060                     if (strIdx >= 0) {
1061                         log_err("getMonthNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1062                             currLoc, idx, strIdx, badChar);
1063                     }
1064                 }
1065                 ures_close(resArray);
1066                 ures_close(format);
1067                 ures_close(names);
1068                 ures_close(greg);
1069                 ures_close(cal);
1070             }
1071             errorCode = U_ZERO_ERROR;
1072             numScripts = uscript_getCode(currLoc, scripts, UPRV_LENGTHOF(scripts), &errorCode);
1073             if (strcmp(currLoc, "yi") == 0 && numScripts > 0 && log_knownIssue("11217", "Fix result of uscript_getCode for yi: USCRIPT_YI -> USCRIPT_HEBREW")) {
1074                 scripts[0] = USCRIPT_HEBREW;
1075             }
1076             if (numScripts == 0) {
1077                 log_err("uscript_getCode(%s) doesn't work.\n", currLoc);
1078             }else if(scripts[0] == USCRIPT_COMMON){
1079                 log_err("uscript_getCode(%s) returned USCRIPT_COMMON.\n", currLoc);
1080             }
1081 
1082             /* test that the scripts are a superset of exemplar characters. */
1083            {
1084                 ULocaleData *uld = ulocdata_open(currLoc,&errorCode);
1085                 USet *exemplarSet =  ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_STANDARD, &errorCode);
1086                 /* test if exemplar characters are part of script code */
1087                 findSetMatch(scripts, numScripts, exemplarSet, currLoc);
1088                 uset_close(exemplarSet);
1089                 ulocdata_close(uld);
1090             }
1091 
1092            /* test that the paperSize API works */
1093            {
1094                int32_t height=0, width=0;
1095                ulocdata_getPaperSize(currLoc, &height, &width, &errorCode);
1096                if(U_FAILURE(errorCode)){
1097                    log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
1098                }
1099                if(strstr(currLoc, "_US")!=NULL && height != 279 && width != 216 ){
1100                    log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
1101                }
1102            }
1103             /* test that the MeasurementSystem API works */
1104            {
1105                char fullLoc[ULOC_FULLNAME_CAPACITY];
1106                UMeasurementSystem measurementSystem;
1107                int32_t height = 0, width = 0;
1108 
1109                uloc_addLikelySubtags(currLoc, fullLoc, ULOC_FULLNAME_CAPACITY, &errorCode);
1110 
1111                errorCode = U_ZERO_ERROR;
1112                measurementSystem = ulocdata_getMeasurementSystem(currLoc, &errorCode);
1113                if (U_FAILURE(errorCode)) {
1114                    log_err("ulocdata_getMeasurementSystem failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
1115                } else {
1116                    if ( strstr(fullLoc, "_US")!=NULL || strstr(fullLoc, "_LR")!=NULL ) {
1117                        if(measurementSystem != UMS_US){
1118                             log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
1119                        }
1120                    } else if ( strstr(fullLoc, "_GB")!=NULL || strstr(fullLoc, "_MM")!=NULL ) {
1121                        if(measurementSystem != UMS_UK){
1122                             log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
1123                        }
1124                    } else if (measurementSystem != UMS_SI) {
1125                        log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
1126                    }
1127                }
1128 
1129                errorCode = U_ZERO_ERROR;
1130                ulocdata_getPaperSize(currLoc, &height, &width, &errorCode);
1131                if (U_FAILURE(errorCode)) {
1132                    log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
1133                } else {
1134                    if ( strstr(fullLoc, "_US")!=NULL || strstr(fullLoc, "_BZ")!=NULL || strstr(fullLoc, "_CA")!=NULL || strstr(fullLoc, "_CL")!=NULL ||
1135                         strstr(fullLoc, "_CO")!=NULL || strstr(fullLoc, "_CR")!=NULL || strstr(fullLoc, "_GT")!=NULL || strstr(fullLoc, "_MX")!=NULL ||
1136                         strstr(fullLoc, "_NI")!=NULL || strstr(fullLoc, "_PA")!=NULL || strstr(fullLoc, "_PH")!=NULL || strstr(fullLoc, "_PR")!=NULL ||
1137                         strstr(fullLoc, "_SV")!=NULL || strstr(fullLoc, "_VE")!=NULL ) {
1138                        if (height != 279 || width != 216) {
1139                             log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
1140                        }
1141                    } else if (height != 297 || width != 210) {
1142                        log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
1143                    }
1144                }
1145            }
1146         }
1147         if (mergedExemplarSet != NULL) {
1148             uset_close(mergedExemplarSet);
1149         }
1150         ures_close(currentLocale);
1151     }
1152 
1153     ures_close(root);
1154 }
1155 
1156 /* adjust this limit as appropriate */
1157 #define MAX_SCRIPTS_PER_LOCALE 8
1158 
TestExemplarSet(void)1159 static void TestExemplarSet(void){
1160     int32_t i, j, k, m, n;
1161     int32_t equalCount = 0;
1162     UErrorCode ec = U_ZERO_ERROR;
1163     UEnumeration* avail;
1164     USet* exemplarSets[2];
1165     USet* unassignedSet;
1166     UScriptCode code[MAX_SCRIPTS_PER_LOCALE];
1167     USet* codeSets[MAX_SCRIPTS_PER_LOCALE];
1168     int32_t codeLen;
1169     char cbuf[32]; /* 9 should be enough */
1170     UChar ubuf[64]; /* adjust as needed */
1171     UBool existsInScript;
1172     int32_t itemCount;
1173     int32_t strLen;
1174     UChar32 start, end;
1175 
1176     unassignedSet = NULL;
1177     exemplarSets[0] = NULL;
1178     exemplarSets[1] = NULL;
1179     for (i=0; i<MAX_SCRIPTS_PER_LOCALE; ++i) {
1180         codeSets[i] = NULL;
1181     }
1182 
1183     avail = ures_openAvailableLocales(NULL, &ec);
1184     if (!assertSuccess("ures_openAvailableLocales", &ec)) goto END;
1185     n = uenum_count(avail, &ec);
1186     if (!assertSuccess("uenum_count", &ec)) goto END;
1187 
1188     u_uastrcpy(ubuf, "[:unassigned:]");
1189     unassignedSet = uset_openPattern(ubuf, -1, &ec);
1190     if (!assertSuccess("uset_openPattern", &ec)) goto END;
1191 
1192     for(i=0; i<n; i++){
1193         const char* locale = uenum_next(avail, NULL, &ec);
1194         if (!assertSuccess("uenum_next", &ec)) goto END;
1195         log_verbose("%s\n", locale);
1196         for (k=0; k<2; ++k) {
1197             uint32_t option = (k==0) ? 0 : USET_CASE_INSENSITIVE;
1198             ULocaleData *uld = ulocdata_open(locale,&ec);
1199             USet* exemplarSet = ulocdata_getExemplarSet(uld,NULL, option, ULOCDATA_ES_STANDARD, &ec);
1200             uset_close(exemplarSets[k]);
1201             ulocdata_close(uld);
1202             exemplarSets[k] = exemplarSet;
1203             if (!assertSuccess("ulocaledata_getExemplarSet", &ec)) goto END;
1204 
1205             if (uset_containsSome(exemplarSet, unassignedSet)) {
1206                 log_err("ExemplarSet contains unassigned characters for locale : %s\n", locale);
1207             }
1208             codeLen = uscript_getCode(locale, code, 8, &ec);
1209             if (strcmp(locale, "yi") == 0 && codeLen > 0 && log_knownIssue("11217", "Fix result of uscript_getCode for yi: USCRIPT_YI -> USCRIPT_HEBREW")) {
1210                 code[0] = USCRIPT_HEBREW;
1211             }
1212             if (!assertSuccess("uscript_getCode", &ec)) goto END;
1213 
1214             for (j=0; j<MAX_SCRIPTS_PER_LOCALE; ++j) {
1215                 uset_close(codeSets[j]);
1216                 codeSets[j] = NULL;
1217             }
1218             for (j=0; j<codeLen; ++j) {
1219                 uprv_strcpy(cbuf, "[:");
1220                 if(code[j]==-1){
1221                     log_err("USCRIPT_INVALID_CODE returned for locale: %s\n", locale);
1222                     continue;
1223                 }
1224                 uprv_strcat(cbuf, uscript_getShortName(code[j]));
1225                 uprv_strcat(cbuf, ":]");
1226                 u_uastrcpy(ubuf, cbuf);
1227                 codeSets[j] = uset_openPattern(ubuf, -1, &ec);
1228             }
1229             if (!assertSuccess("uset_openPattern", &ec)) goto END;
1230 
1231             existsInScript = false;
1232             itemCount = uset_getItemCount(exemplarSet);
1233             for (m=0; m<itemCount && !existsInScript; ++m) {
1234                 strLen = uset_getItem(exemplarSet, m, &start, &end, ubuf,
1235                                       UPRV_LENGTHOF(ubuf), &ec);
1236                 /* failure here might mean str[] needs to be larger */
1237                 if (!assertSuccess("uset_getItem", &ec)) goto END;
1238                 if (strLen == 0) {
1239                     for (j=0; j<codeLen; ++j) {
1240                         if (codeSets[j]!=NULL && uset_containsRange(codeSets[j], start, end)) {
1241                             existsInScript = true;
1242                             break;
1243                         }
1244                     }
1245                 } else {
1246                     for (j=0; j<codeLen; ++j) {
1247                         if (codeSets[j]!=NULL && uset_containsString(codeSets[j], ubuf, strLen)) {
1248                             existsInScript = true;
1249                             break;
1250                         }
1251                     }
1252                 }
1253             }
1254 
1255             if (existsInScript == false){
1256                 log_err("ExemplarSet containment failed for locale : %s\n", locale);
1257             }
1258         }
1259         assertTrue("case-folded is a superset",
1260                    uset_containsAll(exemplarSets[1], exemplarSets[0]));
1261         if (uset_equals(exemplarSets[1], exemplarSets[0])) {
1262             ++equalCount;
1263         }
1264     }
1265     /* Note: The case-folded set should sometimes be a strict superset
1266        and sometimes be equal. */
1267     assertTrue("case-folded is sometimes a strict superset, and sometimes equal",
1268                equalCount > 0 && equalCount < n);
1269 
1270  END:
1271     uenum_close(avail);
1272     uset_close(exemplarSets[0]);
1273     uset_close(exemplarSets[1]);
1274     uset_close(unassignedSet);
1275     for (i=0; i<MAX_SCRIPTS_PER_LOCALE; ++i) {
1276         uset_close(codeSets[i]);
1277     }
1278 }
1279 
1280 enum { kUBufMax = 32 };
TestLocaleDisplayPattern(void)1281 static void TestLocaleDisplayPattern(void){
1282     UErrorCode status;
1283     UChar pattern[kUBufMax] = {0,};
1284     UChar separator[kUBufMax] = {0,};
1285     ULocaleData *uld;
1286     static const UChar enExpectPat[] = { 0x007B,0x0030,0x007D,0x0020,0x0028,0x007B,0x0031,0x007D,0x0029,0 }; /* "{0} ({1})" */
1287     static const UChar enExpectSep[] = { 0x002C,0x0020,0 }; /* ", " */
1288     static const UChar zhExpectPat[] = { 0x007B,0x0030,0x007D,0xFF08,0x007B,0x0031,0x007D,0xFF09,0 };
1289     static const UChar zhExpectSep[] = { 0xFF0C,0 };
1290 
1291     status = U_ZERO_ERROR;
1292     uld = ulocdata_open("en", &status);
1293     if(U_FAILURE(status)){
1294         log_data_err("ulocdata_open en error %s", u_errorName(status));
1295     } else {
1296         ulocdata_getLocaleDisplayPattern(uld, pattern, kUBufMax, &status);
1297         if (U_FAILURE(status)){
1298             log_err("ulocdata_getLocaleDisplayPattern en error %s", u_errorName(status));
1299         } else if (u_strcmp(pattern, enExpectPat) != 0) {
1300              log_err("ulocdata_getLocaleDisplayPattern en returns unexpected pattern");
1301         }
1302         status = U_ZERO_ERROR;
1303         ulocdata_getLocaleSeparator(uld, separator, kUBufMax, &status);
1304         if (U_FAILURE(status)){
1305             log_err("ulocdata_getLocaleSeparator en error %s", u_errorName(status));
1306         } else if (u_strcmp(separator, enExpectSep) != 0) {
1307              log_err("ulocdata_getLocaleSeparator en returns unexpected string ");
1308         }
1309         ulocdata_close(uld);
1310     }
1311 
1312     status = U_ZERO_ERROR;
1313     uld = ulocdata_open("zh", &status);
1314     if(U_FAILURE(status)){
1315         log_data_err("ulocdata_open zh error %s", u_errorName(status));
1316     } else {
1317         ulocdata_getLocaleDisplayPattern(uld, pattern, kUBufMax, &status);
1318         if (U_FAILURE(status)){
1319             log_err("ulocdata_getLocaleDisplayPattern zh error %s", u_errorName(status));
1320         } else if (u_strcmp(pattern, zhExpectPat) != 0) {
1321              log_err("ulocdata_getLocaleDisplayPattern zh returns unexpected pattern");
1322         }
1323         status = U_ZERO_ERROR;
1324         ulocdata_getLocaleSeparator(uld, separator, kUBufMax, &status);
1325         if (U_FAILURE(status)){
1326             log_err("ulocdata_getLocaleSeparator zh error %s", u_errorName(status));
1327         } else if (u_strcmp(separator, zhExpectSep) != 0) {
1328              log_err("ulocdata_getLocaleSeparator zh returns unexpected string ");
1329         }
1330         ulocdata_close(uld);
1331     }
1332 }
1333 
TestCoverage(void)1334 static void TestCoverage(void){
1335     ULocaleDataDelimiterType types[] = {
1336      ULOCDATA_QUOTATION_START,     /* Quotation start */
1337      ULOCDATA_QUOTATION_END,       /* Quotation end */
1338      ULOCDATA_ALT_QUOTATION_START, /* Alternate quotation start */
1339      ULOCDATA_ALT_QUOTATION_END,   /* Alternate quotation end */
1340      ULOCDATA_DELIMITER_COUNT
1341     };
1342     int i;
1343     UBool sub;
1344     UErrorCode status = U_ZERO_ERROR;
1345     ULocaleData *uld = ulocdata_open(uloc_getDefault(), &status);
1346 
1347     if(U_FAILURE(status)){
1348         log_data_err("ulocdata_open error");
1349         return;
1350     }
1351 
1352 
1353     for(i = 0; i < ULOCDATA_DELIMITER_COUNT; i++){
1354         UChar result[32] = {0,};
1355         status = U_ZERO_ERROR;
1356         ulocdata_getDelimiter(uld, types[i], result, 32, &status);
1357         if (U_FAILURE(status)){
1358             log_err("ulocdata_getDelimiter error with type %d", types[i]);
1359         }
1360     }
1361 
1362     sub = ulocdata_getNoSubstitute(uld);
1363     ulocdata_setNoSubstitute(uld,sub);
1364     ulocdata_close(uld);
1365 }
1366 
1367 typedef struct {
1368     const char*  locale;
1369     const UChar* quoteStart;
1370     const UChar* quoteEnd;
1371 } TestDelimitersItem;
1372 
1373 static const TestDelimitersItem testDelimsItems[] = {
1374     { "fr_CA", u"«", u"»" }, // inherited from fr
1375     { "de_CH", u"„", u"“" }, // inherited from de
1376     { "es_MX", u"“", u"”" }, // inherited from es_419
1377     { "ja",    u"「", u"」" },
1378     { NULL, NULL, NULL }
1379 };
1380 
1381 enum { kUDelimMax = 8, kBDelimMax = 16 };
TestDelimiters(void)1382 static void TestDelimiters(void){
1383     const TestDelimitersItem* itemPtr = testDelimsItems;
1384     for (; itemPtr->locale != NULL; itemPtr++) {
1385         UErrorCode status = U_ZERO_ERROR;
1386         ULocaleData  *uld = ulocdata_open(itemPtr->locale, &status);
1387         if (U_FAILURE(status)) {
1388             log_data_err("ulocdata_open for locale %s fails: %s\n", itemPtr->locale, u_errorName(status));
1389         } else {
1390             UChar quoteStart[kUDelimMax], quoteEnd[kUDelimMax];
1391             (void)ulocdata_getDelimiter(uld, ULOCDATA_QUOTATION_START, quoteStart, kUDelimMax, &status);
1392             (void)ulocdata_getDelimiter(uld, ULOCDATA_QUOTATION_END,   quoteEnd,   kUDelimMax, &status);
1393             if (U_FAILURE(status)) {
1394                 log_err("ulocdata_getDelimiter ULOCDATA_QUOTATION_START/END for locale %s fails: %s\n", itemPtr->locale, u_errorName(status));
1395             } else if (u_strcmp(quoteStart,itemPtr->quoteStart)!=0 || u_strcmp(quoteEnd,itemPtr->quoteEnd)!=0) {
1396                 char expStart[kBDelimMax], expEnd[kBDelimMax], getStart[kBDelimMax], getEnd[kBDelimMax];
1397                 u_austrcpy(expStart, itemPtr->quoteStart);
1398                 u_austrcpy(expEnd, itemPtr->quoteEnd);
1399                 u_austrcpy(getStart, quoteStart);
1400                 u_austrcpy(getEnd, quoteEnd);
1401                 log_err("ulocdata_getDelimiter ULOCDATA_QUOTATION_START/END for locale %s, expect %s..%s, get %s..%s\n",
1402                         itemPtr->locale, expStart, expEnd, getStart, getEnd);
1403             }
1404             ulocdata_close(uld);
1405         }
1406     }
1407 }
1408 
1409 
TestIndexChars(void)1410 static void TestIndexChars(void) {
1411     /* Very basic test of ULOCDATA_ES_INDEX.
1412      * No comprehensive test of data, just basic check that the code path is alive.
1413      */
1414     UErrorCode status = U_ZERO_ERROR;
1415     ULocaleData  *uld;
1416     USet *exemplarChars;
1417     USet *indexChars;
1418 
1419     uld = ulocdata_open("en", &status);
1420     exemplarChars = uset_openEmpty();
1421     indexChars = uset_openEmpty();
1422     ulocdata_getExemplarSet(uld, exemplarChars, 0, ULOCDATA_ES_STANDARD, &status);
1423     ulocdata_getExemplarSet(uld, indexChars, 0, ULOCDATA_ES_INDEX, &status);
1424     if (U_FAILURE(status)) {
1425         log_data_err("File %s, line %d, Failure opening exemplar chars: %s", __FILE__, __LINE__, u_errorName(status));
1426         goto close_sets;
1427     }
1428     /* en data, standard exemplars are [a-z], lower case. */
1429     /* en data, index characters are [A-Z], upper case. */
1430     if ((uset_contains(exemplarChars, (UChar32)0x41) || uset_contains(indexChars, (UChar32)0x61))) {
1431         log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__, __LINE__ );
1432         goto close_sets;
1433     }
1434     if (!(uset_contains(exemplarChars, (UChar32)0x61) && uset_contains(indexChars, (UChar32)0x41) )) {
1435         log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__, __LINE__ );
1436         goto close_sets;
1437     }
1438 
1439   close_sets:
1440     uset_close(exemplarChars);
1441     uset_close(indexChars);
1442     ulocdata_close(uld);
1443 }
1444 
1445 
1446 
1447 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
TestCurrencyList(void)1448 static void TestCurrencyList(void){
1449 #if !UCONFIG_NO_FORMATTING
1450     UErrorCode errorCode = U_ZERO_ERROR;
1451     int32_t structLocaleCount, currencyCount;
1452     UEnumeration *en = ucurr_openISOCurrencies(UCURR_ALL, &errorCode);
1453     const char *isoCode, *structISOCode;
1454     UResourceBundle *subBundle;
1455     UResourceBundle *currencies = ures_openDirect(loadTestData(&errorCode), "structLocale", &errorCode);
1456     if(U_FAILURE(errorCode)) {
1457         log_data_err("Can't open structLocale\n");
1458         return;
1459     }
1460     currencies = ures_getByKey(currencies, "Currencies", currencies, &errorCode);
1461     currencyCount = uenum_count(en, &errorCode);
1462     structLocaleCount = ures_getSize(currencies);
1463     if (currencyCount != structLocaleCount) {
1464         log_err("structLocale(%d) and ISO4217(%d) currency list are out of sync.\n", structLocaleCount, currencyCount);
1465 #if U_CHARSET_FAMILY == U_ASCII_FAMILY
1466         ures_resetIterator(currencies);
1467         while ((isoCode = uenum_next(en, NULL, &errorCode)) != NULL && ures_hasNext(currencies)) {
1468             subBundle = ures_getNextResource(currencies, NULL, &errorCode);
1469             structISOCode = ures_getKey(subBundle);
1470             ures_close(subBundle);
1471             if (strcmp(structISOCode, isoCode) != 0) {
1472                 log_err("First difference found at structLocale(%s) and ISO4217(%s).\n", structISOCode, isoCode);
1473                 break;
1474             }
1475         }
1476 #endif
1477     }
1478     ures_close(currencies);
1479     uenum_close(en);
1480 #endif
1481 }
1482 #endif
1483 
TestAvailableIsoCodes(void)1484 static void TestAvailableIsoCodes(void){
1485 #if !UCONFIG_NO_FORMATTING
1486     UErrorCode errorCode = U_ZERO_ERROR;
1487     const char* eurCode = "EUR";
1488     const char* usdCode = "USD";
1489     const char* lastCode = "RHD";
1490     const char* zzzCode = "ZZZ";
1491     UDate date1950 = (UDate)-630720000000.0;/* year 1950 */
1492     UDate date1970 = (UDate)0.0;            /* year 1970 */
1493     UDate date1975 = (UDate)173448000000.0; /* year 1975 */
1494     UDate date1978 = (UDate)260172000000.0; /* year 1978 */
1495     UDate date1981 = (UDate)346896000000.0; /* year 1981 */
1496     UDate date1992 = (UDate)693792000000.0; /* year 1992 */
1497     UChar* isoCode = (UChar*)malloc(sizeof(UChar) * (uprv_strlen(usdCode) + 1));
1498 
1499     /* testing available codes with no time ranges */
1500     u_charsToUChars(eurCode, isoCode, (int32_t)uprv_strlen(usdCode) + 1);
1501     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == false) {
1502        log_data_err("FAIL: ISO code (%s) is not found.\n", eurCode);
1503     }
1504 
1505     u_charsToUChars(usdCode, isoCode, (int32_t)uprv_strlen(zzzCode) + 1);
1506     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == false) {
1507        log_data_err("FAIL: ISO code (%s) is not found.\n", usdCode);
1508     }
1509 
1510     u_charsToUChars(zzzCode, isoCode, (int32_t)uprv_strlen(zzzCode) + 1);
1511     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == true) {
1512        log_err("FAIL: ISO code (%s) is reported as available, but it doesn't exist.\n", zzzCode);
1513     }
1514 
1515     u_charsToUChars(lastCode, isoCode, (int32_t)uprv_strlen(zzzCode) + 1);
1516     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == false) {
1517        log_data_err("FAIL: ISO code (%s) is not found.\n", lastCode);
1518     }
1519 
1520     /* RHD was used from 1970-02-17  to 1980-04-18*/
1521 
1522     /* to = null */
1523     if (ucurr_isAvailable(isoCode, date1970, U_DATE_MAX, &errorCode) == false) {
1524        log_data_err("FAIL: ISO code (%s) was available in time range >1970-01-01.\n", lastCode);
1525     }
1526 
1527     if (ucurr_isAvailable(isoCode, date1975, U_DATE_MAX, &errorCode) == false) {
1528        log_data_err("FAIL: ISO code (%s) was available in time range >1975.\n", lastCode);
1529     }
1530 
1531     if (ucurr_isAvailable(isoCode, date1981, U_DATE_MAX, &errorCode) == true) {
1532        log_err("FAIL: ISO code (%s) was not available in time range >1981.\n", lastCode);
1533     }
1534 
1535     /* from = null */
1536     if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1970, &errorCode) == true) {
1537        log_err("FAIL: ISO code (%s) was not available in time range <1970.\n", lastCode);
1538     }
1539 
1540     if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1975, &errorCode) == false) {
1541        log_data_err("FAIL: ISO code (%s) was available in time range <1975.\n", lastCode);
1542     }
1543 
1544     if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1981, &errorCode) == false) {
1545        log_data_err("FAIL: ISO code (%s) was available in time range <1981.\n", lastCode);
1546     }
1547 
1548     /* full ranges */
1549     if (ucurr_isAvailable(isoCode, date1975, date1978, &errorCode) == false) {
1550        log_data_err("FAIL: ISO code (%s) was available in time range 1975-1978.\n", lastCode);
1551     }
1552 
1553     if (ucurr_isAvailable(isoCode, date1970, date1975, &errorCode) == false) {
1554        log_data_err("FAIL: ISO code (%s) was available in time range 1970-1975.\n", lastCode);
1555     }
1556 
1557     if (ucurr_isAvailable(isoCode, date1975, date1981, &errorCode) == false) {
1558        log_data_err("FAIL: ISO code (%s) was available in time range 1975-1981.\n", lastCode);
1559     }
1560 
1561     if (ucurr_isAvailable(isoCode, date1970,  date1981, &errorCode) == false) {
1562        log_data_err("FAIL: ISO code (%s) was available in time range 1970-1981.\n", lastCode);
1563     }
1564 
1565     if (ucurr_isAvailable(isoCode, date1981,  date1992, &errorCode) == true) {
1566        log_err("FAIL: ISO code (%s) was not available in time range 1981-1992.\n", lastCode);
1567     }
1568 
1569     if (ucurr_isAvailable(isoCode, date1950,  date1970, &errorCode) == true) {
1570        log_err("FAIL: ISO code (%s) was not available in time range 1950-1970.\n", lastCode);
1571     }
1572 
1573     /* wrong range - from > to*/
1574     if (ucurr_isAvailable(isoCode, date1975,  date1970, &errorCode) == true) {
1575        log_err("FAIL: Wrong range 1975-1970 for ISO code (%s) was not reported.\n", lastCode);
1576     } else if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
1577        log_data_err("FAIL: Error code not reported for wrong range 1975-1970 for ISO code (%s).\n", lastCode);
1578     }
1579 
1580     free(isoCode);
1581 #endif
1582 }
1583 
1584 #define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name)
1585 
1586 void addCLDRTest(TestNode** root);
1587 
addCLDRTest(TestNode ** root)1588 void addCLDRTest(TestNode** root)
1589 {
1590 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1591     TESTCASE(TestLocaleStructure);
1592     TESTCASE(TestCurrencyList);
1593 #endif
1594     TESTCASE(TestConsistentCountryInfo);
1595     TESTCASE(VerifyTranslation);
1596     TESTCASE(TestExemplarSet);
1597     TESTCASE(TestLocaleDisplayPattern);
1598     TESTCASE(TestCoverage);
1599     TESTCASE(TestDelimiters);
1600     TESTCASE(TestIndexChars);
1601     TESTCASE(TestAvailableIsoCodes);
1602 }
1603 
1604