1 /********************************************************************
3 * Copyright (c) 1997-2012, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
8 #include "unicode/ures.h"
9 #include "unicode/ucurr.h"
10 #include "unicode/ustring.h"
11 #include "unicode/uset.h"
12 #include "unicode/udat.h"
13 #include "unicode/uscript.h"
14 #include "unicode/ulocdata.h"
20 returns a new UnicodeSet that is a flattened form of the original
24 createFlattenSet(USet
*origSet
, UErrorCode
*status
) {
28 int32_t origItemCount
= 0;
29 int32_t idx
, graphmeSize
;
32 if (U_FAILURE(*status
)) {
33 log_err("createFlattenSet called with %s\n", u_errorName(*status
));
36 newSet
= uset_open(1, 0);
37 origItemCount
= uset_getItemCount(origSet
);
38 for (idx
= 0; idx
< origItemCount
; idx
++) {
39 graphmeSize
= uset_getItem(origSet
, idx
,
41 graphme
, (int32_t)(sizeof(graphme
)/sizeof(graphme
[0])),
43 if (U_FAILURE(*status
)) {
44 log_err("ERROR: uset_getItem returned %s\n", u_errorName(*status
));
45 *status
= U_ZERO_ERROR
;
48 uset_addAllCodePoints(newSet
, graphme
, graphmeSize
);
51 uset_addRange(newSet
, start
, end
);
54 uset_closeOver(newSet
,USET_CASE_INSENSITIVE
);
59 isCurrencyPreEuro(const char* currencyKey
){
60 if( strcmp(currencyKey
, "PTE") == 0 ||
61 strcmp(currencyKey
, "ESP") == 0 ||
62 strcmp(currencyKey
, "LUF") == 0 ||
63 strcmp(currencyKey
, "GRD") == 0 ||
64 strcmp(currencyKey
, "BEF") == 0 ||
65 strcmp(currencyKey
, "ITL") == 0 ||
66 strcmp(currencyKey
, "EEK") == 0){
72 TestKeyInRootRecursive(UResourceBundle
*root
, const char *rootName
,
73 UResourceBundle
*currentBundle
, const char *locale
) {
74 UErrorCode errorCode
= U_ZERO_ERROR
;
75 UResourceBundle
*subRootBundle
= NULL
, *subBundle
= NULL
, *arr
= NULL
;
77 ures_resetIterator(root
);
78 ures_resetIterator(currentBundle
);
79 while (ures_hasNext(currentBundle
)) {
80 const char *subBundleKey
= NULL
;
81 const char *currentBundleKey
= NULL
;
83 errorCode
= U_ZERO_ERROR
;
84 currentBundleKey
= ures_getKey(currentBundle
);
85 subBundle
= ures_getNextResource(currentBundle
, NULL
, &errorCode
);
86 if (U_FAILURE(errorCode
)) {
87 log_err("Can't open a resource for lnocale %s. Error: %s\n", locale
, u_errorName(errorCode
));
90 subBundleKey
= ures_getKey(subBundle
);
93 subRootBundle
= ures_getByKey(root
, subBundleKey
, NULL
, &errorCode
);
94 if (U_FAILURE(errorCode
)) {
95 log_err("Can't open a resource with key \"%s\" in \"%s\" from %s for locale \"%s\"\n",
97 ures_getKey(currentBundle
),
100 ures_close(subBundle
);
103 if (ures_getType(subRootBundle
) != ures_getType(subBundle
)) {
104 log_err("key \"%s\" in \"%s\" has a different type from root for locale \"%s\"\n"
105 "\troot=%d, locale=%d\n",
107 ures_getKey(currentBundle
),
109 ures_getType(subRootBundle
),
110 ures_getType(subBundle
));
111 ures_close(subBundle
);
114 else if (ures_getType(subBundle
) == URES_INT_VECTOR
) {
116 int32_t subBundleSize
;
118 UBool sameArray
= TRUE
;
119 const int32_t *subRootBundleArr
= ures_getIntVector(subRootBundle
, &minSize
, &errorCode
);
120 const int32_t *subBundleArr
= ures_getIntVector(subBundle
, &subBundleSize
, &errorCode
);
122 if (minSize
> subBundleSize
) {
123 minSize
= subBundleSize
;
124 log_err("Arrays are different size with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
126 ures_getKey(currentBundle
),
130 for (idx
= 0; idx
< minSize
&& sameArray
; idx
++) {
131 if (subRootBundleArr
[idx
] != subBundleArr
[idx
]) {
134 if (strcmp(subBundleKey
, "DateTimeElements") == 0
135 && (subBundleArr
[idx
] < 1 || 7 < subBundleArr
[idx
]))
137 log_err("Value out of range with key \"%s\" at index %d in \"%s\" for locale \"%s\"\n",
140 ures_getKey(currentBundle
),
144 /* Special exception es_US and DateTimeElements */
146 && !(strcmp(locale
, "es_US") == 0 && strcmp(subBundleKey
, "DateTimeElements") == 0))
148 log_err("Integer vectors are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
150 ures_getKey(currentBundle
),
154 else if (ures_getType(subBundle
) == URES_ARRAY
) {
155 UResourceBundle
*subSubBundle
= ures_getByIndex(subBundle
, 0, NULL
, &errorCode
);
156 UResourceBundle
*subSubRootBundle
= ures_getByIndex(subRootBundle
, 0, NULL
, &errorCode
);
158 if (U_SUCCESS(errorCode
)
159 && (ures_getType(subSubBundle
) == URES_ARRAY
|| ures_getType(subSubRootBundle
) == URES_ARRAY
))
161 /* Here is one of the recursive parts */
162 TestKeyInRootRecursive(subRootBundle
, rootName
, subBundle
, locale
);
165 int32_t minSize
= ures_getSize(subRootBundle
);
167 UBool sameArray
= TRUE
;
169 if (minSize
> ures_getSize(subBundle
)) {
170 minSize
= ures_getSize(subBundle
);
173 if ((subBundleKey
== NULL
174 || (subBundleKey
!= NULL
&& strcmp(subBundleKey
, "LocaleScript") != 0 && !isCurrencyPreEuro(subBundleKey
)))
175 && ures_getSize(subRootBundle
) != ures_getSize(subBundle
))
177 log_err("Different size array with key \"%s\" in \"%s\" from root for locale \"%s\"\n"
178 "\troot array size=%d, locale array size=%d\n",
180 ures_getKey(currentBundle
),
182 ures_getSize(subRootBundle
),
183 ures_getSize(subBundle
));
186 if(isCurrencyPreEuro(subBundleKey) && ures_getSize(subBundle)!=3){
187 log_err("Different size array with key \"%s\" in \"%s\" for locale \"%s\" the expected size is 3 got size=%d\n",
189 ures_getKey(currentBundle),
191 ures_getSize(subBundle));
194 for (idx
= 0; idx
< minSize
; idx
++) {
195 int32_t rootStrLen
, localeStrLen
;
196 const UChar
*rootStr
= ures_getStringByIndex(subRootBundle
,idx
,&rootStrLen
,&errorCode
);
197 const UChar
*localeStr
= ures_getStringByIndex(subBundle
,idx
,&localeStrLen
,&errorCode
);
198 if (rootStr
&& localeStr
&& U_SUCCESS(errorCode
)) {
199 if (u_strcmp(rootStr
, localeStr
) != 0) {
204 if ( rootStrLen
> 1 && rootStr
[0] == 0x41 && rootStr
[1] >= 0x30 && rootStr
[1] <= 0x39 ) {
205 /* A2 or A4 in the root string indicates that the resource can optionally be an array instead of a */
206 /* string. Attempt to read it as an array. */
207 errorCode
= U_ZERO_ERROR
;
208 arr
= ures_getByIndex(subBundle
,idx
,NULL
,&errorCode
);
209 if (U_FAILURE(errorCode
)) {
210 log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
212 ures_getKey(currentBundle
),
217 if (ures_getType(arr
) != URES_ARRAY
|| ures_getSize(arr
) != (int32_t)rootStr
[1] - 0x30) {
218 log_err("Got something other than a string or array of size %d for key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
221 ures_getKey(currentBundle
),
227 localeStr
= ures_getStringByIndex(arr
,0,&localeStrLen
,&errorCode
);
229 if (U_FAILURE(errorCode
)) {
230 log_err("Got something other than a string or array for key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
232 ures_getKey(currentBundle
),
238 log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
240 ures_getKey(currentBundle
),
246 if (localeStr
[0] == (UChar
)0x20) {
247 log_err("key \"%s\" at index %d in \"%s\" starts with a space in locale \"%s\"\n",
250 ures_getKey(currentBundle
),
253 else if ((localeStr
[localeStrLen
- 1] == (UChar
)0x20) && (strcmp(subBundleKey
,"separator") != 0)) {
254 log_err("key \"%s\" at index %d in \"%s\" ends with a space in locale \"%s\"\n",
257 ures_getKey(currentBundle
),
260 else if (subBundleKey
!= NULL
261 && strcmp(subBundleKey
, "DateTimePatterns") == 0)
264 const UChar
*localeStrItr
= localeStr
;
265 while (*localeStrItr
) {
266 if (*localeStrItr
== (UChar
)0x27 /* ' */) {
269 else if ((quoted
% 2) == 0) {
270 /* Search for unquoted characters */
271 if (4 <= idx
&& idx
<= 7
272 && (*localeStrItr
== (UChar
)0x6B /* k */
273 || *localeStrItr
== (UChar
)0x48 /* H */
274 || *localeStrItr
== (UChar
)0x6D /* m */
275 || *localeStrItr
== (UChar
)0x73 /* s */
276 || *localeStrItr
== (UChar
)0x53 /* S */
277 || *localeStrItr
== (UChar
)0x61 /* a */
278 || *localeStrItr
== (UChar
)0x68 /* h */
279 || *localeStrItr
== (UChar
)0x7A /* z */))
281 log_err("key \"%s\" at index %d has time pattern chars in date for locale \"%s\"\n",
286 else if (0 <= idx
&& idx
<= 3
287 && (*localeStrItr
== (UChar
)0x47 /* G */
288 || *localeStrItr
== (UChar
)0x79 /* y */
289 || *localeStrItr
== (UChar
)0x4D /* M */
290 || *localeStrItr
== (UChar
)0x64 /* d */
291 || *localeStrItr
== (UChar
)0x45 /* E */
292 || *localeStrItr
== (UChar
)0x44 /* D */
293 || *localeStrItr
== (UChar
)0x46 /* F */
294 || *localeStrItr
== (UChar
)0x77 /* w */
295 || *localeStrItr
== (UChar
)0x57 /* W */))
297 log_err("key \"%s\" at index %d has date pattern chars in time for locale \"%s\"\n",
306 else if (idx
== 4 && subBundleKey
!= NULL
307 && strcmp(subBundleKey
, "NumberElements") == 0
308 && u_charDigitValue(localeStr
[0]) != 0)
310 log_err("key \"%s\" at index %d has a non-zero based number for locale \"%s\"\n",
316 /* if (sameArray && strcmp(rootName, "root") == 0) {
317 log_err("Arrays are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
319 ures_getKey(currentBundle),
323 ures_close(subSubBundle
);
324 ures_close(subSubRootBundle
);
326 else if (ures_getType(subBundle
) == URES_STRING
) {
328 const UChar
*string
= ures_getString(subBundle
, &len
, &errorCode
);
329 if (U_FAILURE(errorCode
) || string
== NULL
) {
330 log_err("Can't open a string with key \"%s\" in \"%s\" for locale \"%s\"\n",
332 ures_getKey(currentBundle
),
334 } else if (string
[0] == (UChar
)0x20) {
335 log_err("key \"%s\" in \"%s\" starts with a space in locale \"%s\"\n",
337 ures_getKey(currentBundle
),
339 /* localeDisplayPattern/separator can end with a space */
340 } else if (string
[len
- 1] == (UChar
)0x20 && (strcmp(subBundleKey
,"separator"))) {
341 log_err("key \"%s\" in \"%s\" ends with a space in locale \"%s\"\n",
343 ures_getKey(currentBundle
),
345 } else if (strcmp(subBundleKey
, "localPatternChars") == 0) {
346 /* Note: We no longer import localPatternChars data starting
347 * ICU 3.8. So it never comes into this else if block. (ticket#5597)
350 /* Check well-formedness of localPatternChars. First, the
351 * length must match the number of fields defined by
352 * DateFormat. Second, each character in the string must
353 * be in the set [A-Za-z]. Finally, each character must be
357 #if !UCONFIG_NO_FORMATTING
358 if (len
!= UDAT_FIELD_COUNT
) {
359 log_err("key \"%s\" has the wrong number of characters in locale \"%s\"\n",
364 /* Check char validity. */
365 for (i
=0; i
<len
; ++i
) {
366 if (!((string
[i
] >= 65/*'A'*/ && string
[i
] <= 90/*'Z'*/) ||
367 (string
[i
] >= 97/*'a'*/ && string
[i
] <= 122/*'z'*/))) {
368 log_err("key \"%s\" has illegal character '%c' in locale \"%s\"\n",
373 /* Do O(n^2) check for duplicate chars. */
374 for (j
=0; j
<i
; ++j
) {
375 if (string
[j
] == string
[i
]) {
376 log_err("key \"%s\" has duplicate character '%c' in locale \"%s\"\n",
384 /* No fallback was done. Check for duplicate data */
385 /* The ures_* API does not do fallback of sub-resource bundles,
386 So we can't do this now. */
388 else if (strcmp(locale
, "root") != 0 && errorCode
== U_ZERO_ERROR
) {
390 const UChar
*rootString
= ures_getString(subRootBundle
, &len
, &errorCode
);
391 if (U_FAILURE(errorCode
) || rootString
== NULL
) {
392 log_err("Can't open a string with key \"%s\" in \"%s\" in root\n",
393 ures_getKey(subRootBundle
),
394 ures_getKey(currentBundle
));
396 } else if (u_strcmp(string
, rootString
) == 0) {
397 if (strcmp(locale
, "de_CH") != 0 && strcmp(subBundleKey
, "Countries") != 0 &&
398 strcmp(subBundleKey
, "Version") != 0) {
399 log_err("Found duplicate data with key \"%s\" in \"%s\" in locale \"%s\"\n",
400 ures_getKey(subRootBundle
),
401 ures_getKey(currentBundle
),
405 /* Ignore for now. */
406 /* Can be fixed if fallback through de locale was done. */
407 log_verbose("Skipping key %s in %s\n", subBundleKey
, locale
);
413 else if (ures_getType(subBundle
) == URES_TABLE
) {
414 if (strcmp(subBundleKey
, "availableFormats")!=0) {
415 /* Here is one of the recursive parts */
416 TestKeyInRootRecursive(subRootBundle
, rootName
, subBundle
, locale
);
419 log_verbose("Skipping key %s in %s\n", subBundleKey
, locale
);
422 else if (ures_getType(subBundle
) == URES_BINARY
|| ures_getType(subBundle
) == URES_INT
) {
423 /* Can't do anything to check it */
424 /* We'll assume it's all correct */
425 if (strcmp(subBundleKey
, "MeasurementSystem") != 0) {
426 log_verbose("Skipping key \"%s\" in \"%s\" for locale \"%s\"\n",
428 ures_getKey(currentBundle
),
431 /* Testing for MeasurementSystem is done in VerifyTranslation */
434 log_err("Type %d for key \"%s\" in \"%s\" is unknown for locale \"%s\"\n",
435 ures_getType(subBundle
),
437 ures_getKey(currentBundle
),
440 ures_close(subRootBundle
);
441 ures_close(subBundle
);
447 testLCID(UResourceBundle
*currentBundle
,
448 const char *localeName
)
450 UErrorCode status
= U_ZERO_ERROR
;
451 uint32_t expectedLCID
;
452 char lcidStringC
[64] = {0};
454 expectedLCID
= uloc_getLCID(localeName
);
455 if (expectedLCID
== 0) {
456 log_verbose("INFO: %-5s does not have any LCID mapping\n",
461 status
= U_ZERO_ERROR
;
462 uprv_strcpy(lcidStringC
, uprv_convertToPosix(expectedLCID
, &status
));
463 if (U_FAILURE(status
)) {
464 log_err("ERROR: %.4x does not have a POSIX mapping due to %s\n",
465 expectedLCID
, u_errorName(status
));
468 if(strcmp(localeName
, lcidStringC
) != 0) {
471 uloc_getLanguage(localeName
, langName
, sizeof(langName
), &status
);
472 uloc_getLanguage(lcidStringC
, langLCID
, sizeof(langLCID
), &status
);
474 if (strcmp(langName
, langLCID
) == 0) {
475 log_verbose("WARNING: %-5s resolves to %s (0x%.4x)\n",
476 localeName
, lcidStringC
, expectedLCID
);
479 log_err("ERROR: %-5s has 0x%.4x and the number resolves wrongfully to %s\n",
480 localeName
, expectedLCID
, lcidStringC
);
486 TestLocaleStructure(void) {
487 UResourceBundle
*root
, *currentLocale
;
488 int32_t locCount
= uloc_countAvailable();
490 UErrorCode errorCode
= U_ZERO_ERROR
;
491 const char *currLoc
, *resolvedLoc
;
493 /* TODO: Compare against parent's data too. This code can't handle fallbacks that some tools do already. */
494 /* char locName[ULOC_FULLNAME_CAPACITY];
497 for (locIndex = 0; locIndex < locCount; locIndex++) {
498 errorCode=U_ZERO_ERROR;
499 strcpy(locName, uloc_getAvailable(locIndex));
500 locNamePtr = strrchr(locName, '_');
505 strcpy(locName, "root");
508 root = ures_openDirect(NULL, locName, &errorCode);
509 if(U_FAILURE(errorCode)) {
510 log_err("Can't open %s\n", locName);
515 log_data_err("At least root needs to be installed\n");
518 root
= ures_openDirect(loadTestData(&errorCode
), "structLocale", &errorCode
);
519 if(U_FAILURE(errorCode
)) {
520 log_data_err("Can't open structLocale\n");
523 for (locIndex
= 0; locIndex
< locCount
; locIndex
++) {
524 errorCode
=U_ZERO_ERROR
;
525 currLoc
= uloc_getAvailable(locIndex
);
526 currentLocale
= ures_open(NULL
, currLoc
, &errorCode
);
527 if(errorCode
!= U_ZERO_ERROR
) {
528 if(U_SUCCESS(errorCode
)) {
529 /* It's installed, but there is no data.
530 It's installed for the g18n white paper [grhoten] */
531 log_err("ERROR: Locale %-5s not installed, and it should be, err %s\n",
532 uloc_getAvailable(locIndex
), u_errorName(errorCode
));
534 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
535 u_errorName(errorCode
),
536 uloc_getAvailable(locIndex
));
538 ures_close(currentLocale
);
541 ures_getStringByKey(currentLocale
, "Version", NULL
, &errorCode
);
542 if(errorCode
!= U_ZERO_ERROR
) {
543 log_err("No version information is available for locale %s, and it should be!\n",
546 else if (ures_getStringByKey(currentLocale
, "Version", NULL
, &errorCode
)[0] == (UChar
)(0x78)) {
547 log_verbose("WARNING: The locale %s is experimental! It shouldn't be listed as an installed locale.\n",
550 resolvedLoc
= ures_getLocaleByType(currentLocale
, ULOC_ACTUAL_LOCALE
, &errorCode
);
551 if (strcmp(resolvedLoc
, currLoc
) != 0) {
552 /* All locales have at least a Version resource.
553 If it's absolutely empty, then the previous test will fail too.*/
554 log_err("Locale resolves to different locale. Is %s an alias of %s?\n",
555 currLoc
, resolvedLoc
);
557 TestKeyInRootRecursive(root
, "root", currentLocale
, currLoc
);
559 testLCID(currentLocale
, currLoc
);
561 ures_close(currentLocale
);
568 compareArrays(const char *keyName
,
569 UResourceBundle
*fromArray
, const char *fromLocale
,
570 UResourceBundle
*toArray
, const char *toLocale
,
571 int32_t start
, int32_t end
)
573 int32_t fromSize
= ures_getSize(fromArray
);
574 int32_t toSize
= ures_getSize(fromArray
);
576 UErrorCode errorCode
= U_ZERO_ERROR
;
578 if (fromSize
> toSize
) {
580 log_err("Arrays are different size from \"%s\" to \"%s\"\n",
585 for (idx
= start
; idx
<= end
; idx
++) {
586 const UChar
*fromBundleStr
= ures_getStringByIndex(fromArray
, idx
, NULL
, &errorCode
);
587 const UChar
*toBundleStr
= ures_getStringByIndex(toArray
, idx
, NULL
, &errorCode
);
588 if (fromBundleStr
&& toBundleStr
&& u_strcmp(fromBundleStr
, toBundleStr
) != 0)
590 log_err("Difference for %s at index %d from %s= \"%s\" to %s= \"%s\"\n",
594 austrdup(fromBundleStr
),
596 austrdup(toBundleStr
));
602 compareConsistentCountryInfo(const char *fromLocale
, const char *toLocale
) {
603 UErrorCode errorCode
= U_ZERO_ERROR
;
604 UResourceBundle
*fromArray
, *toArray
;
605 UResourceBundle
*fromLocaleBund
= ures_open(NULL
, fromLocale
, &errorCode
);
606 UResourceBundle
*toLocaleBund
= ures_open(NULL
, toLocale
, &errorCode
);
607 UResourceBundle
*toCalendar
, *fromCalendar
, *toGregorian
, *fromGregorian
;
609 if(U_FAILURE(errorCode
)) {
610 log_err("Can't open resource bundle %s or %s - %s\n", fromLocale
, toLocale
, u_errorName(errorCode
));
613 fromCalendar
= ures_getByKey(fromLocaleBund
, "calendar", NULL
, &errorCode
);
614 fromGregorian
= ures_getByKeyWithFallback(fromCalendar
, "gregorian", NULL
, &errorCode
);
616 toCalendar
= ures_getByKey(toLocaleBund
, "calendar", NULL
, &errorCode
);
617 toGregorian
= ures_getByKeyWithFallback(toCalendar
, "gregorian", NULL
, &errorCode
);
619 fromArray
= ures_getByKey(fromLocaleBund
, "CurrencyElements", NULL
, &errorCode
);
620 toArray
= ures_getByKey(toLocaleBund
, "CurrencyElements", NULL
, &errorCode
);
621 if (strcmp(fromLocale
, "en_CA") != 0)
623 /* The first one is probably localized. */
624 compareArrays("CurrencyElements", fromArray
, fromLocale
, toArray
, toLocale
, 1, 2);
626 ures_close(fromArray
);
629 fromArray
= ures_getByKey(fromLocaleBund
, "NumberPatterns", NULL
, &errorCode
);
630 toArray
= ures_getByKey(toLocaleBund
, "NumberPatterns", NULL
, &errorCode
);
631 if (strcmp(fromLocale
, "en_CA") != 0)
633 compareArrays("NumberPatterns", fromArray
, fromLocale
, toArray
, toLocale
, 0, 3);
635 ures_close(fromArray
);
638 /* Difficult to test properly */
640 fromArray = ures_getByKey(fromLocaleBund, "DateTimePatterns", NULL, &errorCode);
641 toArray = ures_getByKey(toLocaleBund, "DateTimePatterns", NULL, &errorCode);
643 compareArrays("DateTimePatterns", fromArray, fromLocale, toArray, toLocale);
645 ures_close(fromArray);
646 ures_close(toArray);*/
648 fromArray
= ures_getByKey(fromLocaleBund
, "NumberElements", NULL
, &errorCode
);
649 toArray
= ures_getByKey(toLocaleBund
, "NumberElements", NULL
, &errorCode
);
650 if (strcmp(fromLocale
, "en_CA") != 0)
652 compareArrays("NumberElements", fromArray
, fromLocale
, toArray
, toLocale
, 0, 3);
653 /* Index 4 is a script based 0 */
654 compareArrays("NumberElements", fromArray
, fromLocale
, toArray
, toLocale
, 5, 10);
656 ures_close(fromArray
);
658 ures_close(fromCalendar
);
659 ures_close(toCalendar
);
660 ures_close(fromGregorian
);
661 ures_close(toGregorian
);
663 ures_close(fromLocaleBund
);
664 ures_close(toLocaleBund
);
668 TestConsistentCountryInfo(void) {
669 /* UResourceBundle *fromLocale, *toLocale;*/
670 int32_t locCount
= uloc_countAvailable();
671 int32_t fromLocIndex
, toLocIndex
;
673 int32_t fromCountryLen
, toCountryLen
;
674 char fromCountry
[ULOC_FULLNAME_CAPACITY
], toCountry
[ULOC_FULLNAME_CAPACITY
];
676 int32_t fromVariantLen
, toVariantLen
;
677 char fromVariant
[ULOC_FULLNAME_CAPACITY
], toVariant
[ULOC_FULLNAME_CAPACITY
];
679 UErrorCode errorCode
= U_ZERO_ERROR
;
681 for (fromLocIndex
= 0; fromLocIndex
< locCount
; fromLocIndex
++) {
682 const char *fromLocale
= uloc_getAvailable(fromLocIndex
);
684 errorCode
=U_ZERO_ERROR
;
685 fromCountryLen
= uloc_getCountry(fromLocale
, fromCountry
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
686 if (fromCountryLen
<= 0) {
687 /* Ignore countryless locales */
690 fromVariantLen
= uloc_getVariant(fromLocale
, fromVariant
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
691 if (fromVariantLen
> 0) {
692 /* Most variants are ignorable like PREEURO, or collation variants. */
695 /* Start comparing only after the current index.
696 Previous loop should have already compared fromLocIndex.
698 for (toLocIndex
= fromLocIndex
+ 1; toLocIndex
< locCount
; toLocIndex
++) {
699 const char *toLocale
= uloc_getAvailable(toLocIndex
);
701 toCountryLen
= uloc_getCountry(toLocale
, toCountry
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
702 if(U_FAILURE(errorCode
)) {
703 log_err("Unknown failure fromLocale=%s toLocale=%s errorCode=%s\n",
704 fromLocale
, toLocale
, u_errorName(errorCode
));
708 if (toCountryLen
<= 0) {
709 /* Ignore countryless locales */
712 toVariantLen
= uloc_getVariant(toLocale
, toVariant
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
713 if (toVariantLen
> 0) {
714 /* Most variants are ignorable like PREEURO, or collation variants. */
715 /* They're a variant for a reason. */
718 if (strcmp(fromCountry
, toCountry
) == 0) {
719 log_verbose("comparing fromLocale=%s toLocale=%s\n",
720 fromLocale
, toLocale
);
721 compareConsistentCountryInfo(fromLocale
, toLocale
);
728 findStringSetMismatch(const char *currLoc
, const UChar
*string
, int32_t langSize
,
729 const UChar
*exemplarCharacters
, int32_t exemplarLen
,
730 UBool ignoreNumbers
, UChar
* badCharPtr
) {
731 UErrorCode errorCode
= U_ZERO_ERROR
;
732 USet
*origSet
= uset_openPatternOptions(exemplarCharacters
, exemplarLen
, USET_CASE_INSENSITIVE
, &errorCode
);
733 USet
*exemplarSet
= createFlattenSet(origSet
, &errorCode
);
736 if (U_FAILURE(errorCode
)) {
737 log_err("%s: error uset_openPattern returned %s\n", currLoc
, u_errorName(errorCode
));
741 for (strIdx
= 0; strIdx
< langSize
; strIdx
++) {
742 if (!uset_contains(exemplarSet
, string
[strIdx
])
743 && string
[strIdx
] != 0x0020 && string
[strIdx
] != 0x00A0 && string
[strIdx
] != 0x002e && string
[strIdx
] != 0x002c && string
[strIdx
] != 0x002d && string
[strIdx
] != 0x0027 && string
[strIdx
] != 0x2019 && string
[strIdx
] != 0x0f0b
744 && string
[strIdx
] != 0x200C && string
[strIdx
] != 0x200D) {
745 if (!ignoreNumbers
|| (ignoreNumbers
&& (string
[strIdx
] < 0x30 || string
[strIdx
] > 0x39))) {
746 uset_close(exemplarSet
);
748 *badCharPtr
= string
[strIdx
];
754 uset_close(exemplarSet
);
760 /* include non-invariant chars */
762 myUCharsToChars(const UChar
* us
, char* cs
, int32_t len
){
774 findSetMatch( UScriptCode
*scriptCodes
, int32_t scriptsLen
,
777 USet
*scripts
[10]= {0};
778 char pattern
[256] = { '[', ':', 0x000 };
780 UChar uPattern
[256] = {0};
781 UErrorCode status
= U_ZERO_ERROR
;
784 /* create the sets with script codes */
785 for(i
= 0; i
<scriptsLen
; i
++){
786 strcat(pattern
, uscript_getShortName(scriptCodes
[i
]));
787 strcat(pattern
, ":]");
788 patternLen
= (int32_t)strlen(pattern
);
789 u_charsToUChars(pattern
, uPattern
, patternLen
);
790 scripts
[i
] = uset_openPattern(uPattern
, patternLen
, &status
);
791 if(U_FAILURE(status
)){
792 log_err("Could not create set for pattern %s. Error: %s\n", pattern
, u_errorName(status
));
797 if (strcmp(locale
, "uk") == 0 || strcmp(locale
, "uk_UA") == 0) {
798 /* Special addition. Add the modifying apostrophe, which isn't in Cyrillic. */
799 uset_add(scripts
[0], 0x2bc);
801 if(U_SUCCESS(status
)){
802 UBool existsInScript
= FALSE
;
803 /* iterate over the exemplarSet and ascertain if all
804 * UChars in exemplarSet belong to the scripts returned
807 int32_t count
= uset_getItemCount(exemplarSet
);
809 for( i
=0; i
< count
; i
++){
813 int32_t strCapacity
= 0;
815 strCapacity
= uset_getItem(exemplarSet
, i
, &start
, &end
, str
, strCapacity
, &status
);
816 if(U_SUCCESS(status
)){
818 if(strCapacity
== 0){
819 /* ok the item is a range */
820 for( j
= 0; j
< scriptsLen
; j
++){
821 if(uset_containsRange(scripts
[j
], start
, end
) == TRUE
){
822 existsInScript
= TRUE
;
825 if(existsInScript
== FALSE
){
826 for( j
= 0; j
< scriptsLen
; j
++){
827 UChar toPattern
[500]={'\0'};
828 char pat
[500]={'\0'};
829 int32_t len
= uset_toPattern(scripts
[j
], toPattern
, 500, TRUE
, &status
);
830 len
= myUCharsToChars(toPattern
, pat
, len
);
831 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
));
833 log_err("Pattern: %s\n",pat
);
836 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale
);
839 strCapacity
++; /* increment for NUL termination */
840 /* allocate the str and call the api again */
841 str
= (UChar
*) malloc(U_SIZEOF_UCHAR
* strCapacity
);
842 strCapacity
= uset_getItem(exemplarSet
, i
, &start
, &end
, str
, strCapacity
, &status
);
843 /* iterate over the scripts and figure out if the string contained is actually
846 for( j
= 0; j
< scriptsLen
; j
++){
847 if(uset_containsString(scripts
[j
],str
, strCapacity
) == TRUE
){
848 existsInScript
= TRUE
;
851 if(existsInScript
== FALSE
){
852 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale
);
861 for(i
= 0; i
<scriptsLen
; i
++){
862 uset_close(scripts
[i
]);
866 static void VerifyTranslation(void) {
867 UResourceBundle
*root
, *currentLocale
;
868 int32_t locCount
= uloc_countAvailable();
870 UErrorCode errorCode
= U_ZERO_ERROR
;
872 const UChar
*exemplarCharacters
;
874 UScriptCode scripts
[USCRIPT_CODE_LIMIT
];
878 UResourceBundle
*resArray
;
881 log_data_err("At least root needs to be installed\n");
884 root
= ures_openDirect(NULL
, "root", &errorCode
);
885 if(U_FAILURE(errorCode
)) {
886 log_data_err("Can't open root\n");
889 for (locIndex
= 0; locIndex
< locCount
; locIndex
++) {
890 errorCode
=U_ZERO_ERROR
;
891 currLoc
= uloc_getAvailable(locIndex
);
892 currentLocale
= ures_open(NULL
, currLoc
, &errorCode
);
893 if(errorCode
!= U_ZERO_ERROR
) {
894 if(U_SUCCESS(errorCode
)) {
895 /* It's installed, but there is no data.
896 It's installed for the g18n white paper [grhoten] */
897 log_err("ERROR: Locale %-5s not installed, and it should be!\n",
898 uloc_getAvailable(locIndex
));
900 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
901 u_errorName(errorCode
),
902 uloc_getAvailable(locIndex
));
904 ures_close(currentLocale
);
907 exemplarCharacters
= ures_getStringByKey(currentLocale
, "ExemplarCharacters", &exemplarLen
, &errorCode
);
908 if (U_FAILURE(errorCode
)) {
909 log_err("error ures_getStringByKey returned %s\n", u_errorName(errorCode
));
911 else if (getTestOption(QUICK_OPTION
) && exemplarLen
> 2048) {
912 log_verbose("skipping test for %s\n", currLoc
);
914 else if (uprv_strncmp(currLoc
,"bem",3) == 0 || uprv_strncmp(currLoc
,"nl",2) == 0) {
915 log_verbose("skipping test for %s, some month and country names known to use aux exemplars\n", currLoc
);
918 UChar langBuffer
[128];
922 langSize
= uloc_getDisplayLanguage(currLoc
, currLoc
, langBuffer
, sizeof(langBuffer
)/sizeof(langBuffer
[0]), &errorCode
);
923 if (U_FAILURE(errorCode
)) {
924 log_err("error uloc_getDisplayLanguage returned %s\n", u_errorName(errorCode
));
927 strIdx
= findStringSetMismatch(currLoc
, langBuffer
, langSize
, exemplarCharacters
, exemplarLen
, FALSE
, &badChar
);
929 log_err("getDisplayLanguage(%s) at index %d returned characters not in the exemplar characters: %04X.\n",
930 currLoc
, strIdx
, badChar
);
933 langSize
= uloc_getDisplayCountry(currLoc
, currLoc
, langBuffer
, sizeof(langBuffer
)/sizeof(langBuffer
[0]), &errorCode
);
934 if (U_FAILURE(errorCode
)) {
935 log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode
));
937 else if (uprv_strstr(currLoc
, "ti_") != currLoc
|| isICUVersionAtLeast(50, 0, 0)) { /* TODO: restore DisplayCountry test for ti_* when cldrbug 3058 is fixed) */
938 strIdx
= findStringSetMismatch(currLoc
, langBuffer
, langSize
, exemplarCharacters
, exemplarLen
, FALSE
, &badChar
);
940 log_err("getDisplayCountry(%s) at index %d returned characters not in the exemplar characters: %04X.\n",
941 currLoc
, strIdx
, badChar
);
945 UResourceBundle
* cal
= ures_getByKey(currentLocale
, "calendar", NULL
, &errorCode
);
946 UResourceBundle
* greg
= ures_getByKeyWithFallback(cal
, "gregorian", NULL
, &errorCode
);
947 UResourceBundle
* names
= ures_getByKeyWithFallback(greg
, "dayNames", NULL
, &errorCode
);
948 UResourceBundle
* format
= ures_getByKeyWithFallback(names
, "format", NULL
, &errorCode
);
949 resArray
= ures_getByKeyWithFallback(format
, "wide", NULL
, &errorCode
);
951 if (U_FAILURE(errorCode
)) {
952 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode
));
954 if (getTestOption(QUICK_OPTION
)) {
958 end
= ures_getSize(resArray
);
962 for (idx
= 0; idx
< end
; idx
++) {
963 const UChar
*fromBundleStr
= ures_getStringByIndex(resArray
, idx
, &langSize
, &errorCode
);
964 if (U_FAILURE(errorCode
)) {
965 log_err("error ures_getStringByIndex(%d) returned %s\n", idx
, u_errorName(errorCode
));
968 strIdx
= findStringSetMismatch(currLoc
, fromBundleStr
, langSize
, exemplarCharacters
, exemplarLen
, TRUE
, &badChar
);
970 log_err("getDayNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
971 currLoc
, idx
, strIdx
, badChar
);
974 ures_close(resArray
);
978 names
= ures_getByKeyWithFallback(greg
, "monthNames", NULL
, &errorCode
);
979 format
= ures_getByKeyWithFallback(names
,"format", NULL
, &errorCode
);
980 resArray
= ures_getByKeyWithFallback(format
, "wide", NULL
, &errorCode
);
981 if (U_FAILURE(errorCode
)) {
982 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode
));
984 if (getTestOption(QUICK_OPTION
)) {
988 end
= ures_getSize(resArray
);
991 for (idx
= 0; idx
< end
; idx
++) {
992 const UChar
*fromBundleStr
= ures_getStringByIndex(resArray
, idx
, &langSize
, &errorCode
);
993 if (U_FAILURE(errorCode
)) {
994 log_err("error ures_getStringByIndex(%d) returned %s\n", idx
, u_errorName(errorCode
));
997 strIdx
= findStringSetMismatch(currLoc
, fromBundleStr
, langSize
, exemplarCharacters
, exemplarLen
, TRUE
, &badChar
);
999 log_err("getMonthNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1000 currLoc
, idx
, strIdx
, badChar
);
1003 ures_close(resArray
);
1009 errorCode
= U_ZERO_ERROR
;
1010 numScripts
= uscript_getCode(currLoc
, scripts
, sizeof(scripts
)/sizeof(scripts
[0]), &errorCode
);
1011 if (numScripts
== 0) {
1012 log_err("uscript_getCode(%s) doesn't work.\n", currLoc
);
1013 }else if(scripts
[0] == USCRIPT_COMMON
){
1014 log_err("uscript_getCode(%s) returned USCRIPT_COMMON.\n", currLoc
);
1017 /* test that the scripts are a superset of exemplar characters. */
1019 ULocaleData
*uld
= ulocdata_open(currLoc
,&errorCode
);
1020 USet
*exemplarSet
= ulocdata_getExemplarSet(uld
, NULL
, 0, ULOCDATA_ES_STANDARD
, &errorCode
);
1021 /* test if exemplar characters are part of script code */
1022 findSetMatch(scripts
, numScripts
, exemplarSet
, currLoc
);
1023 uset_close(exemplarSet
);
1024 ulocdata_close(uld
);
1027 /* test that the paperSize API works */
1029 int32_t height
=0, width
=0;
1030 ulocdata_getPaperSize(currLoc
, &height
, &width
, &errorCode
);
1031 if(U_FAILURE(errorCode
)){
1032 log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc
, u_errorName(errorCode
));
1034 if(strstr(currLoc
, "_US")!=NULL
&& height
!= 279 && width
!= 216 ){
1035 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc
);
1038 /* test that the MeasurementSystem works API works */
1040 UMeasurementSystem measurementSystem
= ulocdata_getMeasurementSystem(currLoc
, &errorCode
);
1041 if(U_FAILURE(errorCode
)){
1042 log_err("ulocdata_getMeasurementSystem failed for locale %s with error: %s \n", currLoc
, u_errorName(errorCode
));
1044 if(strstr(currLoc
, "_US")!=NULL
|| strstr(currLoc
, "_MM")!=NULL
|| strstr(currLoc
, "_LR")!=NULL
){
1045 if(measurementSystem
!= UMS_US
){
1046 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc
);
1048 }else if(measurementSystem
!= UMS_SI
){
1049 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc
);
1053 ures_close(currentLocale
);
1059 /* adjust this limit as appropriate */
1060 #define MAX_SCRIPTS_PER_LOCALE 8
1062 static void TestExemplarSet(void){
1063 int32_t i
, j
, k
, m
, n
;
1064 int32_t equalCount
= 0;
1065 UErrorCode ec
= U_ZERO_ERROR
;
1066 UEnumeration
* avail
;
1067 USet
* exemplarSets
[2];
1068 USet
* unassignedSet
;
1069 UScriptCode code
[MAX_SCRIPTS_PER_LOCALE
];
1070 USet
* codeSets
[MAX_SCRIPTS_PER_LOCALE
];
1072 char cbuf
[32]; /* 9 should be enough */
1073 UChar ubuf
[64]; /* adjust as needed */
1074 UBool existsInScript
;
1079 unassignedSet
= NULL
;
1080 exemplarSets
[0] = NULL
;
1081 exemplarSets
[1] = NULL
;
1082 for (i
=0; i
<MAX_SCRIPTS_PER_LOCALE
; ++i
) {
1086 avail
= ures_openAvailableLocales(NULL
, &ec
);
1087 if (!assertSuccess("ures_openAvailableLocales", &ec
)) goto END
;
1088 n
= uenum_count(avail
, &ec
);
1089 if (!assertSuccess("uenum_count", &ec
)) goto END
;
1091 u_uastrcpy(ubuf
, "[:unassigned:]");
1092 unassignedSet
= uset_openPattern(ubuf
, -1, &ec
);
1093 if (!assertSuccess("uset_openPattern", &ec
)) goto END
;
1096 const char* locale
= uenum_next(avail
, NULL
, &ec
);
1097 if (!assertSuccess("uenum_next", &ec
)) goto END
;
1098 log_verbose("%s\n", locale
);
1099 for (k
=0; k
<2; ++k
) {
1100 uint32_t option
= (k
==0) ? 0 : USET_CASE_INSENSITIVE
;
1101 ULocaleData
*uld
= ulocdata_open(locale
,&ec
);
1102 USet
* exemplarSet
= ulocdata_getExemplarSet(uld
,NULL
, option
, ULOCDATA_ES_STANDARD
, &ec
);
1103 uset_close(exemplarSets
[k
]);
1104 ulocdata_close(uld
);
1105 exemplarSets
[k
] = exemplarSet
;
1106 if (!assertSuccess("ulocaledata_getExemplarSet", &ec
)) goto END
;
1108 if (uset_containsSome(exemplarSet
, unassignedSet
)) {
1109 log_err("ExemplarSet contains unassigned characters for locale : %s\n", locale
);
1111 codeLen
= uscript_getCode(locale
, code
, 8, &ec
);
1112 if (!assertSuccess("uscript_getCode", &ec
)) goto END
;
1114 for (j
=0; j
<MAX_SCRIPTS_PER_LOCALE
; ++j
) {
1115 uset_close(codeSets
[j
]);
1118 for (j
=0; j
<codeLen
; ++j
) {
1119 uprv_strcpy(cbuf
, "[:");
1121 log_err("USCRIPT_INVALID_CODE returned for locale: %s\n", locale
);
1124 uprv_strcat(cbuf
, uscript_getShortName(code
[j
]));
1125 uprv_strcat(cbuf
, ":]");
1126 u_uastrcpy(ubuf
, cbuf
);
1127 codeSets
[j
] = uset_openPattern(ubuf
, -1, &ec
);
1129 if (!assertSuccess("uset_openPattern", &ec
)) goto END
;
1131 existsInScript
= FALSE
;
1132 itemCount
= uset_getItemCount(exemplarSet
);
1133 for (m
=0; m
<itemCount
&& !existsInScript
; ++m
) {
1134 strLen
= uset_getItem(exemplarSet
, m
, &start
, &end
, ubuf
,
1135 sizeof(ubuf
)/sizeof(ubuf
[0]), &ec
);
1136 /* failure here might mean str[] needs to be larger */
1137 if (!assertSuccess("uset_getItem", &ec
)) goto END
;
1139 for (j
=0; j
<codeLen
; ++j
) {
1140 if (codeSets
[j
]!=NULL
&& uset_containsRange(codeSets
[j
], start
, end
)) {
1141 existsInScript
= TRUE
;
1146 for (j
=0; j
<codeLen
; ++j
) {
1147 if (codeSets
[j
]!=NULL
&& uset_containsString(codeSets
[j
], ubuf
, strLen
)) {
1148 existsInScript
= TRUE
;
1155 if (existsInScript
== FALSE
){
1156 log_err("ExemplarSet containment failed for locale : %s\n", locale
);
1159 assertTrue("case-folded is a superset",
1160 uset_containsAll(exemplarSets
[1], exemplarSets
[0]));
1161 if (uset_equals(exemplarSets
[1], exemplarSets
[0])) {
1165 /* Note: The case-folded set should sometimes be a strict superset
1166 and sometimes be equal. */
1167 assertTrue("case-folded is sometimes a strict superset, and sometimes equal",
1168 equalCount
> 0 && equalCount
< n
);
1172 uset_close(exemplarSets
[0]);
1173 uset_close(exemplarSets
[1]);
1174 uset_close(unassignedSet
);
1175 for (i
=0; i
<MAX_SCRIPTS_PER_LOCALE
; ++i
) {
1176 uset_close(codeSets
[i
]);
1180 static void TestLocaleDisplayPattern(void){
1181 UErrorCode status
= U_ZERO_ERROR
;
1182 UChar pattern
[32] = {0,};
1183 UChar separator
[32] = {0,};
1184 ULocaleData
*uld
= ulocdata_open(uloc_getDefault(), &status
);
1186 if(U_FAILURE(status
)){
1187 log_data_err("ulocdata_open error");
1190 ulocdata_getLocaleDisplayPattern(uld
, pattern
, 32, &status
);
1191 if (U_FAILURE(status
)){
1192 log_err("ulocdata_getLocaleDisplayPattern error!");
1194 status
= U_ZERO_ERROR
;
1195 ulocdata_getLocaleSeparator(uld
, separator
, 32, &status
);
1196 if (U_FAILURE(status
)){
1197 log_err("ulocdata_getLocaleSeparator error!");
1199 ulocdata_close(uld
);
1202 static void TestCoverage(void){
1203 ULocaleDataDelimiterType types
[] = {
1204 ULOCDATA_QUOTATION_START
, /* Quotation start */
1205 ULOCDATA_QUOTATION_END
, /* Quotation end */
1206 ULOCDATA_ALT_QUOTATION_START
, /* Alternate quotation start */
1207 ULOCDATA_ALT_QUOTATION_END
, /* Alternate quotation end */
1208 ULOCDATA_DELIMITER_COUNT
1212 UErrorCode status
= U_ZERO_ERROR
;
1213 ULocaleData
*uld
= ulocdata_open(uloc_getDefault(), &status
);
1215 if(U_FAILURE(status
)){
1216 log_data_err("ulocdata_open error");
1221 for(i
= 0; i
< ULOCDATA_DELIMITER_COUNT
; i
++){
1222 UChar result
[32] = {0,};
1223 status
= U_ZERO_ERROR
;
1224 ulocdata_getDelimiter(uld
, types
[i
], result
, 32, &status
);
1225 if (U_FAILURE(status
)){
1226 log_err("ulocdata_getgetDelimiter error with type %d", types
[i
]);
1230 sub
= ulocdata_getNoSubstitute(uld
);
1231 ulocdata_setNoSubstitute(uld
,sub
);
1232 ulocdata_close(uld
);
1235 static void TestIndexChars(void) {
1236 /* Very basic test of ULOCDATA_ES_INDEX.
1237 * No comprehensive test of data, just basic check that the code path is alive.
1239 UErrorCode status
= U_ZERO_ERROR
;
1241 USet
*exemplarChars
;
1244 uld
= ulocdata_open("en", &status
);
1245 exemplarChars
= uset_openEmpty();
1246 indexChars
= uset_openEmpty();
1247 ulocdata_getExemplarSet(uld
, exemplarChars
, 0, ULOCDATA_ES_STANDARD
, &status
);
1248 ulocdata_getExemplarSet(uld
, indexChars
, 0, ULOCDATA_ES_INDEX
, &status
);
1249 if (U_FAILURE(status
)) {
1250 log_data_err("File %s, line %d, Failure opening exemplar chars: %s", __FILE__
, __LINE__
, u_errorName(status
));
1253 /* en data, standard exemplars are [a-z], lower case. */
1254 /* en data, index characters are [A-Z], upper case. */
1255 if ((uset_contains(exemplarChars
, (UChar32
)0x41) || uset_contains(indexChars
, (UChar32
)0x61))) {
1256 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__
, __LINE__
);
1259 if (!(uset_contains(exemplarChars
, (UChar32
)0x61) && uset_contains(indexChars
, (UChar32
)0x41) )) {
1260 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__
, __LINE__
);
1265 uset_close(exemplarChars
);
1266 uset_close(indexChars
);
1267 ulocdata_close(uld
);
1272 static void TestCurrencyList(void){
1273 #if !UCONFIG_NO_FORMATTING
1274 UErrorCode errorCode
= U_ZERO_ERROR
;
1275 int32_t structLocaleCount
, currencyCount
;
1276 UEnumeration
*en
= ucurr_openISOCurrencies(UCURR_ALL
, &errorCode
);
1277 const char *isoCode
, *structISOCode
;
1278 UResourceBundle
*subBundle
;
1279 UResourceBundle
*currencies
= ures_openDirect(loadTestData(&errorCode
), "structLocale", &errorCode
);
1280 if(U_FAILURE(errorCode
)) {
1281 log_data_err("Can't open structLocale\n");
1284 currencies
= ures_getByKey(currencies
, "Currencies", currencies
, &errorCode
);
1285 currencyCount
= uenum_count(en
, &errorCode
);
1286 structLocaleCount
= ures_getSize(currencies
);
1287 if (currencyCount
!= structLocaleCount
) {
1288 log_err("structLocale(%d) and ISO4217(%d) currency list are out of sync.\n", structLocaleCount
, currencyCount
);
1289 #if U_CHARSET_FAMILY == U_ASCII_FAMILY
1290 ures_resetIterator(currencies
);
1291 while ((isoCode
= uenum_next(en
, NULL
, &errorCode
)) != NULL
&& ures_hasNext(currencies
)) {
1292 subBundle
= ures_getNextResource(currencies
, NULL
, &errorCode
);
1293 structISOCode
= ures_getKey(subBundle
);
1294 ures_close(subBundle
);
1295 if (strcmp(structISOCode
, isoCode
) != 0) {
1296 log_err("First difference found at structLocale(%s) and ISO4217(%s).\n", structISOCode
, isoCode
);
1302 ures_close(currencies
);
1307 static void TestAvailableIsoCodes(void){
1308 #if !UCONFIG_NO_FORMATTING
1309 UErrorCode errorCode
= U_ZERO_ERROR
;
1310 const char* eurCode
= "EUR";
1311 const char* usdCode
= "USD";
1312 const char* lastCode
= "RHD";
1313 const char* zzzCode
= "ZZZ";
1314 UDate date1950
= (UDate
)-630720000000.0;/* year 1950 */
1315 UDate date1970
= (UDate
)0.0; /* year 1970 */
1316 UDate date1975
= (UDate
)173448000000.0; /* year 1975 */
1317 UDate date1978
= (UDate
)260172000000.0; /* year 1978 */
1318 UDate date1981
= (UDate
)346896000000.0; /* year 1981 */
1319 UDate date1992
= (UDate
)693792000000.0; /* year 1992 */
1320 UChar
* isoCode
= (UChar
*)malloc(sizeof(UChar
) * (uprv_strlen(usdCode
) + 1));
1322 /* testing available codes with no time ranges */
1323 u_charsToUChars(eurCode
, isoCode
, uprv_strlen(usdCode
) + 1);
1324 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1325 log_data_err("FAIL: ISO code (%s) is not found.\n", eurCode
);
1328 u_charsToUChars(usdCode
, isoCode
, uprv_strlen(zzzCode
) + 1);
1329 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1330 log_data_err("FAIL: ISO code (%s) is not found.\n", usdCode
);
1333 u_charsToUChars(zzzCode
, isoCode
, uprv_strlen(zzzCode
) + 1);
1334 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == TRUE
) {
1335 log_err("FAIL: ISO code (%s) is reported as available, but it doesn't exist.\n", zzzCode
);
1338 u_charsToUChars(lastCode
, isoCode
, uprv_strlen(zzzCode
) + 1);
1339 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1340 log_data_err("FAIL: ISO code (%s) is not found.\n", lastCode
);
1343 /* RHD was used from 1970-02-17 to 1980-04-18*/
1346 if (ucurr_isAvailable(isoCode
, date1970
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1347 log_data_err("FAIL: ISO code (%s) was available in time range >1970-01-01.\n", lastCode
);
1350 if (ucurr_isAvailable(isoCode
, date1975
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1351 log_data_err("FAIL: ISO code (%s) was available in time range >1975.\n", lastCode
);
1354 if (ucurr_isAvailable(isoCode
, date1981
, U_DATE_MAX
, &errorCode
) == TRUE
) {
1355 log_err("FAIL: ISO code (%s) was not available in time range >1981.\n", lastCode
);
1359 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1970
, &errorCode
) == TRUE
) {
1360 log_err("FAIL: ISO code (%s) was not available in time range <1970.\n", lastCode
);
1363 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1975
, &errorCode
) == FALSE
) {
1364 log_data_err("FAIL: ISO code (%s) was available in time range <1975.\n", lastCode
);
1367 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1981
, &errorCode
) == FALSE
) {
1368 log_data_err("FAIL: ISO code (%s) was available in time range <1981.\n", lastCode
);
1372 if (ucurr_isAvailable(isoCode
, date1975
, date1978
, &errorCode
) == FALSE
) {
1373 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1978.\n", lastCode
);
1376 if (ucurr_isAvailable(isoCode
, date1970
, date1975
, &errorCode
) == FALSE
) {
1377 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1975.\n", lastCode
);
1380 if (ucurr_isAvailable(isoCode
, date1975
, date1981
, &errorCode
) == FALSE
) {
1381 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1981.\n", lastCode
);
1384 if (ucurr_isAvailable(isoCode
, date1970
, date1981
, &errorCode
) == FALSE
) {
1385 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1981.\n", lastCode
);
1388 if (ucurr_isAvailable(isoCode
, date1981
, date1992
, &errorCode
) == TRUE
) {
1389 log_err("FAIL: ISO code (%s) was not available in time range 1981-1992.\n", lastCode
);
1392 if (ucurr_isAvailable(isoCode
, date1950
, date1970
, &errorCode
) == TRUE
) {
1393 log_err("FAIL: ISO code (%s) was not available in time range 1950-1970.\n", lastCode
);
1396 /* wrong range - from > to*/
1397 if (ucurr_isAvailable(isoCode
, date1975
, date1970
, &errorCode
) == TRUE
) {
1398 log_err("FAIL: Wrong range 1975-1970 for ISO code (%s) was not reported.\n", lastCode
);
1399 } else if (errorCode
!= U_ILLEGAL_ARGUMENT_ERROR
) {
1400 log_data_err("FAIL: Error code not reported for wrong range 1975-1970 for ISO code (%s).\n", lastCode
);
1407 #define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name)
1409 void addCLDRTest(TestNode
** root
);
1411 void addCLDRTest(TestNode
** root
)
1413 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1414 TESTCASE(TestLocaleStructure
);
1415 TESTCASE(TestCurrencyList
);
1417 TESTCASE(TestConsistentCountryInfo
);
1418 TESTCASE(VerifyTranslation
);
1419 TESTCASE(TestExemplarSet
);
1420 TESTCASE(TestLocaleDisplayPattern
);
1421 TESTCASE(TestCoverage
);
1422 TESTCASE(TestIndexChars
);
1423 TESTCASE(TestAvailableIsoCodes
);