1 /********************************************************************
3 * Copyright (c) 1997-2016, 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"
21 returns a new UnicodeSet that is a flattened form of the original
25 createFlattenSet(USet
*origSet
, UErrorCode
*status
) {
29 int32_t origItemCount
= 0;
30 int32_t idx
, graphmeSize
;
33 if (U_FAILURE(*status
)) {
34 log_err("createFlattenSet called with %s\n", u_errorName(*status
));
37 newSet
= uset_open(1, 0);
38 origItemCount
= uset_getItemCount(origSet
);
39 for (idx
= 0; idx
< origItemCount
; idx
++) {
40 graphmeSize
= uset_getItem(origSet
, idx
,
42 graphme
, UPRV_LENGTHOF(graphme
),
44 if (U_FAILURE(*status
)) {
45 log_err("ERROR: uset_getItem returned %s\n", u_errorName(*status
));
46 *status
= U_ZERO_ERROR
;
49 uset_addAllCodePoints(newSet
, graphme
, graphmeSize
);
52 uset_addRange(newSet
, start
, end
);
55 uset_closeOver(newSet
,USET_CASE_INSENSITIVE
);
60 isCurrencyPreEuro(const char* currencyKey
){
61 if( strcmp(currencyKey
, "PTE") == 0 ||
62 strcmp(currencyKey
, "ESP") == 0 ||
63 strcmp(currencyKey
, "LUF") == 0 ||
64 strcmp(currencyKey
, "GRD") == 0 ||
65 strcmp(currencyKey
, "BEF") == 0 ||
66 strcmp(currencyKey
, "ITL") == 0 ||
67 strcmp(currencyKey
, "EEK") == 0){
72 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
74 TestKeyInRootRecursive(UResourceBundle
*root
, const char *rootName
,
75 UResourceBundle
*currentBundle
, const char *locale
) {
76 UErrorCode errorCode
= U_ZERO_ERROR
;
77 UResourceBundle
*subRootBundle
= NULL
, *subBundle
= NULL
, *arr
= NULL
;
79 ures_resetIterator(root
);
80 ures_resetIterator(currentBundle
);
81 while (ures_hasNext(currentBundle
)) {
82 const char *subBundleKey
= NULL
;
83 const char *currentBundleKey
= NULL
;
85 errorCode
= U_ZERO_ERROR
;
86 currentBundleKey
= ures_getKey(currentBundle
);
87 (void)currentBundleKey
; /* Suppress set but not used warning. */
88 subBundle
= ures_getNextResource(currentBundle
, NULL
, &errorCode
);
89 if (U_FAILURE(errorCode
)) {
90 log_err("Can't open a resource for lnocale %s. Error: %s\n", locale
, u_errorName(errorCode
));
93 subBundleKey
= ures_getKey(subBundle
);
96 subRootBundle
= ures_getByKey(root
, subBundleKey
, NULL
, &errorCode
);
97 if (U_FAILURE(errorCode
)) {
98 log_err("Can't open a resource with key \"%s\" in \"%s\" from %s for locale \"%s\"\n",
100 ures_getKey(currentBundle
),
103 ures_close(subBundle
);
106 if (ures_getType(subRootBundle
) != ures_getType(subBundle
)) {
107 log_err("key \"%s\" in \"%s\" has a different type from root for locale \"%s\"\n"
108 "\troot=%d, locale=%d\n",
110 ures_getKey(currentBundle
),
112 ures_getType(subRootBundle
),
113 ures_getType(subBundle
));
114 ures_close(subBundle
);
117 else if (ures_getType(subBundle
) == URES_INT_VECTOR
) {
119 int32_t subBundleSize
;
121 UBool sameArray
= TRUE
;
122 const int32_t *subRootBundleArr
= ures_getIntVector(subRootBundle
, &minSize
, &errorCode
);
123 const int32_t *subBundleArr
= ures_getIntVector(subBundle
, &subBundleSize
, &errorCode
);
125 if (minSize
> subBundleSize
) {
126 minSize
= subBundleSize
;
127 log_err("Arrays are different size with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
129 ures_getKey(currentBundle
),
133 for (idx
= 0; idx
< minSize
&& sameArray
; idx
++) {
134 if (subRootBundleArr
[idx
] != subBundleArr
[idx
]) {
137 if (strcmp(subBundleKey
, "DateTimeElements") == 0
138 && (subBundleArr
[idx
] < 1 || 7 < subBundleArr
[idx
]))
140 log_err("Value out of range with key \"%s\" at index %d in \"%s\" for locale \"%s\"\n",
143 ures_getKey(currentBundle
),
147 /* Special exception es_US and DateTimeElements */
149 && !(strcmp(locale
, "es_US") == 0 && strcmp(subBundleKey
, "DateTimeElements") == 0))
151 log_err("Integer vectors are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
153 ures_getKey(currentBundle
),
157 else if (ures_getType(subBundle
) == URES_ARRAY
) {
158 UResourceBundle
*subSubBundle
= ures_getByIndex(subBundle
, 0, NULL
, &errorCode
);
159 UResourceBundle
*subSubRootBundle
= ures_getByIndex(subRootBundle
, 0, NULL
, &errorCode
);
161 if (U_SUCCESS(errorCode
)
162 && (ures_getType(subSubBundle
) == URES_ARRAY
|| ures_getType(subSubRootBundle
) == URES_ARRAY
))
164 /* Here is one of the recursive parts */
165 TestKeyInRootRecursive(subRootBundle
, rootName
, subBundle
, locale
);
168 int32_t minSize
= ures_getSize(subRootBundle
);
170 UBool sameArray
= TRUE
;
172 if (minSize
> ures_getSize(subBundle
)) {
173 minSize
= ures_getSize(subBundle
);
176 if ((subBundleKey
== NULL
177 || (subBundleKey
!= NULL
&& strcmp(subBundleKey
, "LocaleScript") != 0 && !isCurrencyPreEuro(subBundleKey
)))
178 && ures_getSize(subRootBundle
) != ures_getSize(subBundle
))
180 log_err("Different size array with key \"%s\" in \"%s\" from root for locale \"%s\"\n"
181 "\troot array size=%d, locale array size=%d\n",
183 ures_getKey(currentBundle
),
185 ures_getSize(subRootBundle
),
186 ures_getSize(subBundle
));
189 if(isCurrencyPreEuro(subBundleKey) && ures_getSize(subBundle)!=3){
190 log_err("Different size array with key \"%s\" in \"%s\" for locale \"%s\" the expected size is 3 got size=%d\n",
192 ures_getKey(currentBundle),
194 ures_getSize(subBundle));
197 for (idx
= 0; idx
< minSize
; idx
++) {
198 int32_t rootStrLen
, localeStrLen
;
199 const UChar
*rootStr
= ures_getStringByIndex(subRootBundle
,idx
,&rootStrLen
,&errorCode
);
200 const UChar
*localeStr
= ures_getStringByIndex(subBundle
,idx
,&localeStrLen
,&errorCode
);
201 if (rootStr
&& localeStr
&& U_SUCCESS(errorCode
)) {
202 if (u_strcmp(rootStr
, localeStr
) != 0) {
207 if ( rootStrLen
> 1 && rootStr
[0] == 0x41 && rootStr
[1] >= 0x30 && rootStr
[1] <= 0x39 ) {
208 /* A2 or A4 in the root string indicates that the resource can optionally be an array instead of a */
209 /* string. Attempt to read it as an array. */
210 errorCode
= U_ZERO_ERROR
;
211 arr
= ures_getByIndex(subBundle
,idx
,NULL
,&errorCode
);
212 if (U_FAILURE(errorCode
)) {
213 log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
215 ures_getKey(currentBundle
),
220 if (ures_getType(arr
) != URES_ARRAY
|| ures_getSize(arr
) != (int32_t)rootStr
[1] - 0x30) {
221 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",
224 ures_getKey(currentBundle
),
230 localeStr
= ures_getStringByIndex(arr
,0,&localeStrLen
,&errorCode
);
232 if (U_FAILURE(errorCode
)) {
233 log_err("Got something other than a string or array for key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
235 ures_getKey(currentBundle
),
241 log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
243 ures_getKey(currentBundle
),
249 if (localeStr
[0] == (UChar
)0x20) {
250 log_err("key \"%s\" at index %d in \"%s\" starts with a space in locale \"%s\"\n",
253 ures_getKey(currentBundle
),
256 else if ((localeStr
[localeStrLen
- 1] == (UChar
)0x20) && (strcmp(subBundleKey
,"separator") != 0)) {
257 log_err("key \"%s\" at index %d in \"%s\" ends with a space in locale \"%s\"\n",
260 ures_getKey(currentBundle
),
263 else if (subBundleKey
!= NULL
264 && strcmp(subBundleKey
, "DateTimePatterns") == 0)
267 const UChar
*localeStrItr
= localeStr
;
268 while (*localeStrItr
) {
269 if (*localeStrItr
== (UChar
)0x27 /* ' */) {
272 else if ((quoted
% 2) == 0) {
273 /* Search for unquoted characters */
274 if (4 <= idx
&& idx
<= 7
275 && (*localeStrItr
== (UChar
)0x6B /* k */
276 || *localeStrItr
== (UChar
)0x48 /* H */
277 || *localeStrItr
== (UChar
)0x6D /* m */
278 || *localeStrItr
== (UChar
)0x73 /* s */
279 || *localeStrItr
== (UChar
)0x53 /* S */
280 || *localeStrItr
== (UChar
)0x61 /* a */
281 || *localeStrItr
== (UChar
)0x68 /* h */
282 || *localeStrItr
== (UChar
)0x7A /* z */))
284 log_err("key \"%s\" at index %d has time pattern chars in date for locale \"%s\"\n",
289 else if (0 <= idx
&& idx
<= 3
290 && (*localeStrItr
== (UChar
)0x47 /* G */
291 || *localeStrItr
== (UChar
)0x79 /* y */
292 || *localeStrItr
== (UChar
)0x4D /* M */
293 || *localeStrItr
== (UChar
)0x64 /* d */
294 || *localeStrItr
== (UChar
)0x45 /* E */
295 || *localeStrItr
== (UChar
)0x44 /* D */
296 || *localeStrItr
== (UChar
)0x46 /* F */
297 || *localeStrItr
== (UChar
)0x77 /* w */
298 || *localeStrItr
== (UChar
)0x57 /* W */))
300 log_err("key \"%s\" at index %d has date pattern chars in time for locale \"%s\"\n",
309 else if (idx
== 4 && subBundleKey
!= NULL
310 && strcmp(subBundleKey
, "NumberElements") == 0
311 && u_charDigitValue(localeStr
[0]) != 0)
313 log_err("key \"%s\" at index %d has a non-zero based number for locale \"%s\"\n",
319 (void)sameArray
; /* Suppress set but not used warning. */
320 /* if (sameArray && strcmp(rootName, "root") == 0) {
321 log_err("Arrays are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
323 ures_getKey(currentBundle),
327 ures_close(subSubBundle
);
328 ures_close(subSubRootBundle
);
330 else if (ures_getType(subBundle
) == URES_STRING
) {
332 const UChar
*string
= ures_getString(subBundle
, &len
, &errorCode
);
333 if (U_FAILURE(errorCode
) || string
== NULL
) {
334 log_err("Can't open a string with key \"%s\" in \"%s\" for locale \"%s\"\n",
336 ures_getKey(currentBundle
),
338 } else if (string
[0] == (UChar
)0x20) {
339 log_err("key \"%s\" in \"%s\" starts with a space in locale \"%s\"\n",
341 ures_getKey(currentBundle
),
343 /* localeDisplayPattern/separator can end with a space */
344 } else if (string
[len
- 1] == (UChar
)0x20 && (strcmp(subBundleKey
,"separator"))) {
345 log_err("key \"%s\" in \"%s\" ends with a space in locale \"%s\"\n",
347 ures_getKey(currentBundle
),
349 } else if (strcmp(subBundleKey
, "localPatternChars") == 0) {
350 /* Note: We no longer import localPatternChars data starting
351 * ICU 3.8. So it never comes into this else if block. (ticket#5597)
354 /* Check well-formedness of localPatternChars. First, the
355 * length must match the number of fields defined by
356 * DateFormat. Second, each character in the string must
357 * be in the set [A-Za-z]. Finally, each character must be
361 #if !UCONFIG_NO_FORMATTING
362 if (len
!= UDAT_FIELD_COUNT
) {
363 log_err("key \"%s\" has the wrong number of characters in locale \"%s\"\n",
368 /* Check char validity. */
369 for (i
=0; i
<len
; ++i
) {
370 if (!((string
[i
] >= 65/*'A'*/ && string
[i
] <= 90/*'Z'*/) ||
371 (string
[i
] >= 97/*'a'*/ && string
[i
] <= 122/*'z'*/))) {
372 log_err("key \"%s\" has illegal character '%c' in locale \"%s\"\n",
377 /* Do O(n^2) check for duplicate chars. */
378 for (j
=0; j
<i
; ++j
) {
379 if (string
[j
] == string
[i
]) {
380 log_err("key \"%s\" has duplicate character '%c' in locale \"%s\"\n",
388 /* No fallback was done. Check for duplicate data */
389 /* The ures_* API does not do fallback of sub-resource bundles,
390 So we can't do this now. */
392 else if (strcmp(locale
, "root") != 0 && errorCode
== U_ZERO_ERROR
) {
394 const UChar
*rootString
= ures_getString(subRootBundle
, &len
, &errorCode
);
395 if (U_FAILURE(errorCode
) || rootString
== NULL
) {
396 log_err("Can't open a string with key \"%s\" in \"%s\" in root\n",
397 ures_getKey(subRootBundle
),
398 ures_getKey(currentBundle
));
400 } else if (u_strcmp(string
, rootString
) == 0) {
401 if (strcmp(locale
, "de_CH") != 0 && strcmp(subBundleKey
, "Countries") != 0 &&
402 strcmp(subBundleKey
, "Version") != 0) {
403 log_err("Found duplicate data with key \"%s\" in \"%s\" in locale \"%s\"\n",
404 ures_getKey(subRootBundle
),
405 ures_getKey(currentBundle
),
409 /* Ignore for now. */
410 /* Can be fixed if fallback through de locale was done. */
411 log_verbose("Skipping key %s in %s\n", subBundleKey
, locale
);
417 else if (ures_getType(subBundle
) == URES_TABLE
) {
418 if (strcmp(subBundleKey
, "availableFormats")!=0) {
419 /* Here is one of the recursive parts */
420 TestKeyInRootRecursive(subRootBundle
, rootName
, subBundle
, locale
);
423 log_verbose("Skipping key %s in %s\n", subBundleKey
, locale
);
426 else if (ures_getType(subBundle
) == URES_BINARY
|| ures_getType(subBundle
) == URES_INT
) {
427 /* Can't do anything to check it */
428 /* We'll assume it's all correct */
429 if (strcmp(subBundleKey
, "MeasurementSystem") != 0) {
430 log_verbose("Skipping key \"%s\" in \"%s\" for locale \"%s\"\n",
432 ures_getKey(currentBundle
),
435 /* Testing for MeasurementSystem is done in VerifyTranslation */
438 log_err("Type %d for key \"%s\" in \"%s\" is unknown for locale \"%s\"\n",
439 ures_getType(subBundle
),
441 ures_getKey(currentBundle
),
444 ures_close(subRootBundle
);
445 ures_close(subBundle
);
451 testLCID(UResourceBundle
*currentBundle
,
452 const char *localeName
)
454 UErrorCode status
= U_ZERO_ERROR
;
455 uint32_t expectedLCID
;
456 char lcidStringC
[64] = {0};
459 expectedLCID
= uloc_getLCID(localeName
);
460 if (expectedLCID
== 0) {
461 log_verbose("INFO: %-5s does not have any LCID mapping\n",
466 status
= U_ZERO_ERROR
;
467 len
= uprv_convertToPosix(expectedLCID
, lcidStringC
, UPRV_LENGTHOF(lcidStringC
) - 1, &status
);
468 if (U_FAILURE(status
)) {
469 log_err("ERROR: %.4x does not have a POSIX mapping due to %s\n",
470 expectedLCID
, u_errorName(status
));
472 lcidStringC
[len
] = 0;
474 if(strcmp(localeName
, lcidStringC
) != 0) {
477 uloc_getLanguage(localeName
, langName
, sizeof(langName
), &status
);
478 uloc_getLanguage(lcidStringC
, langLCID
, sizeof(langLCID
), &status
);
480 if (strcmp(langName
, langLCID
) == 0) {
481 log_verbose("WARNING: %-5s resolves to %s (0x%.4x)\n",
482 localeName
, lcidStringC
, expectedLCID
);
485 log_err("ERROR: %-5s has 0x%.4x and the number resolves wrongfully to %s\n",
486 localeName
, expectedLCID
, lcidStringC
);
491 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
493 TestLocaleStructure(void) {
494 // This test checks the locale structure against a key file located
495 // at source/test/testdata/structLocale.txt. When adding new data to
496 // a locale file such as en.txt, the structLocale.txt file must be changed
497 // too to include the the template of the new data. Otherwise this test
500 UResourceBundle
*root
, *currentLocale
;
501 int32_t locCount
= uloc_countAvailable();
503 UErrorCode errorCode
= U_ZERO_ERROR
;
504 const char *currLoc
, *resolvedLoc
;
506 /* TODO: Compare against parent's data too. This code can't handle fallbacks that some tools do already. */
507 /* char locName[ULOC_FULLNAME_CAPACITY];
510 for (locIndex = 0; locIndex < locCount; locIndex++) {
511 errorCode=U_ZERO_ERROR;
512 strcpy(locName, uloc_getAvailable(locIndex));
513 locNamePtr = strrchr(locName, '_');
518 strcpy(locName, "root");
521 root = ures_openDirect(NULL, locName, &errorCode);
522 if(U_FAILURE(errorCode)) {
523 log_err("Can't open %s\n", locName);
528 log_data_err("At least root needs to be installed\n");
531 root
= ures_openDirect(loadTestData(&errorCode
), "structLocale", &errorCode
);
532 if(U_FAILURE(errorCode
)) {
533 log_data_err("Can't open structLocale\n");
536 for (locIndex
= 0; locIndex
< locCount
; locIndex
++) {
537 errorCode
=U_ZERO_ERROR
;
538 currLoc
= uloc_getAvailable(locIndex
);
539 currentLocale
= ures_open(NULL
, currLoc
, &errorCode
);
540 if(errorCode
!= U_ZERO_ERROR
) {
541 if(U_SUCCESS(errorCode
)) {
542 /* It's installed, but there is no data.
543 It's installed for the g18n white paper [grhoten] */
544 log_err("ERROR: Locale %-5s not installed, and it should be, err %s\n",
545 uloc_getAvailable(locIndex
), u_errorName(errorCode
));
547 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
548 u_errorName(errorCode
),
549 uloc_getAvailable(locIndex
));
551 ures_close(currentLocale
);
554 ures_getStringByKey(currentLocale
, "Version", NULL
, &errorCode
);
555 if(errorCode
!= U_ZERO_ERROR
) {
556 log_err("No version information is available for locale %s, and it should be!\n",
559 else if (ures_getStringByKey(currentLocale
, "Version", NULL
, &errorCode
)[0] == (UChar
)(0x78)) {
560 log_verbose("WARNING: The locale %s is experimental! It shouldn't be listed as an installed locale.\n",
563 resolvedLoc
= ures_getLocaleByType(currentLocale
, ULOC_ACTUAL_LOCALE
, &errorCode
);
564 if (strcmp(resolvedLoc
, currLoc
) != 0 && strcmp(currLoc
, "ars") != 0) { /* ars IS an aliased locale */
565 /* All locales have at least a Version resource.
566 If it's absolutely empty, then the previous test will fail too.*/
567 log_err("Locale resolves to different locale. Is %s an alias of %s?\n",
568 currLoc
, resolvedLoc
);
570 TestKeyInRootRecursive(root
, "root", currentLocale
, currLoc
);
572 testLCID(currentLocale
, currLoc
);
574 ures_close(currentLocale
);
582 compareArrays(const char *keyName
,
583 UResourceBundle
*fromArray
, const char *fromLocale
,
584 UResourceBundle
*toArray
, const char *toLocale
,
585 int32_t start
, int32_t end
)
587 int32_t fromSize
= ures_getSize(fromArray
);
588 int32_t toSize
= ures_getSize(fromArray
);
590 UErrorCode errorCode
= U_ZERO_ERROR
;
592 if (fromSize
> toSize
) {
594 log_err("Arrays are different size from \"%s\" to \"%s\"\n",
599 for (idx
= start
; idx
<= end
; idx
++) {
600 const UChar
*fromBundleStr
= ures_getStringByIndex(fromArray
, idx
, NULL
, &errorCode
);
601 const UChar
*toBundleStr
= ures_getStringByIndex(toArray
, idx
, NULL
, &errorCode
);
602 if (fromBundleStr
&& toBundleStr
&& u_strcmp(fromBundleStr
, toBundleStr
) != 0)
604 log_err("Difference for %s at index %d from %s= \"%s\" to %s= \"%s\"\n",
608 austrdup(fromBundleStr
),
610 austrdup(toBundleStr
));
616 compareConsistentCountryInfo(const char *fromLocale
, const char *toLocale
) {
617 UErrorCode errorCode
= U_ZERO_ERROR
;
618 UResourceBundle
*fromArray
, *toArray
;
619 UResourceBundle
*fromLocaleBund
= ures_open(NULL
, fromLocale
, &errorCode
);
620 UResourceBundle
*toLocaleBund
= ures_open(NULL
, toLocale
, &errorCode
);
621 UResourceBundle
*toCalendar
, *fromCalendar
, *toGregorian
, *fromGregorian
;
623 if(U_FAILURE(errorCode
)) {
624 log_err("Can't open resource bundle %s or %s - %s\n", fromLocale
, toLocale
, u_errorName(errorCode
));
627 fromCalendar
= ures_getByKey(fromLocaleBund
, "calendar", NULL
, &errorCode
);
628 fromGregorian
= ures_getByKeyWithFallback(fromCalendar
, "gregorian", NULL
, &errorCode
);
630 toCalendar
= ures_getByKey(toLocaleBund
, "calendar", NULL
, &errorCode
);
631 toGregorian
= ures_getByKeyWithFallback(toCalendar
, "gregorian", NULL
, &errorCode
);
633 fromArray
= ures_getByKey(fromLocaleBund
, "CurrencyElements", NULL
, &errorCode
);
634 toArray
= ures_getByKey(toLocaleBund
, "CurrencyElements", NULL
, &errorCode
);
635 if (strcmp(fromLocale
, "en_CA") != 0)
637 /* The first one is probably localized. */
638 compareArrays("CurrencyElements", fromArray
, fromLocale
, toArray
, toLocale
, 1, 2);
640 ures_close(fromArray
);
643 fromArray
= ures_getByKey(fromLocaleBund
, "NumberPatterns", NULL
, &errorCode
);
644 toArray
= ures_getByKey(toLocaleBund
, "NumberPatterns", NULL
, &errorCode
);
645 if (strcmp(fromLocale
, "en_CA") != 0)
647 compareArrays("NumberPatterns", fromArray
, fromLocale
, toArray
, toLocale
, 0, 3);
649 ures_close(fromArray
);
652 /* Difficult to test properly */
654 fromArray = ures_getByKey(fromLocaleBund, "DateTimePatterns", NULL, &errorCode);
655 toArray = ures_getByKey(toLocaleBund, "DateTimePatterns", NULL, &errorCode);
657 compareArrays("DateTimePatterns", fromArray, fromLocale, toArray, toLocale);
659 ures_close(fromArray);
660 ures_close(toArray);*/
662 fromArray
= ures_getByKey(fromLocaleBund
, "NumberElements", NULL
, &errorCode
);
663 toArray
= ures_getByKey(toLocaleBund
, "NumberElements", NULL
, &errorCode
);
664 if (strcmp(fromLocale
, "en_CA") != 0)
666 compareArrays("NumberElements", fromArray
, fromLocale
, toArray
, toLocale
, 0, 3);
667 /* Index 4 is a script based 0 */
668 compareArrays("NumberElements", fromArray
, fromLocale
, toArray
, toLocale
, 5, 10);
670 ures_close(fromArray
);
672 ures_close(fromCalendar
);
673 ures_close(toCalendar
);
674 ures_close(fromGregorian
);
675 ures_close(toGregorian
);
677 ures_close(fromLocaleBund
);
678 ures_close(toLocaleBund
);
682 TestConsistentCountryInfo(void) {
683 /* UResourceBundle *fromLocale, *toLocale;*/
684 int32_t locCount
= uloc_countAvailable();
685 int32_t fromLocIndex
, toLocIndex
;
687 int32_t fromCountryLen
, toCountryLen
;
688 char fromCountry
[ULOC_FULLNAME_CAPACITY
], toCountry
[ULOC_FULLNAME_CAPACITY
];
690 int32_t fromVariantLen
, toVariantLen
;
691 char fromVariant
[ULOC_FULLNAME_CAPACITY
], toVariant
[ULOC_FULLNAME_CAPACITY
];
693 UErrorCode errorCode
= U_ZERO_ERROR
;
695 for (fromLocIndex
= 0; fromLocIndex
< locCount
; fromLocIndex
++) {
696 const char *fromLocale
= uloc_getAvailable(fromLocIndex
);
698 errorCode
=U_ZERO_ERROR
;
699 fromCountryLen
= uloc_getCountry(fromLocale
, fromCountry
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
700 if (fromCountryLen
<= 0) {
701 /* Ignore countryless locales */
704 fromVariantLen
= uloc_getVariant(fromLocale
, fromVariant
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
705 if (fromVariantLen
> 0) {
706 /* Most variants are ignorable like PREEURO, or collation variants. */
709 /* Start comparing only after the current index.
710 Previous loop should have already compared fromLocIndex.
712 for (toLocIndex
= fromLocIndex
+ 1; toLocIndex
< locCount
; toLocIndex
++) {
713 const char *toLocale
= uloc_getAvailable(toLocIndex
);
715 toCountryLen
= uloc_getCountry(toLocale
, toCountry
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
716 if(U_FAILURE(errorCode
)) {
717 log_err("Unknown failure fromLocale=%s toLocale=%s errorCode=%s\n",
718 fromLocale
, toLocale
, u_errorName(errorCode
));
722 if (toCountryLen
<= 0) {
723 /* Ignore countryless locales */
726 toVariantLen
= uloc_getVariant(toLocale
, toVariant
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
727 if (toVariantLen
> 0) {
728 /* Most variants are ignorable like PREEURO, or collation variants. */
729 /* They're a variant for a reason. */
732 if (strcmp(fromCountry
, toCountry
) == 0) {
733 log_verbose("comparing fromLocale=%s toLocale=%s\n",
734 fromLocale
, toLocale
);
735 compareConsistentCountryInfo(fromLocale
, toLocale
);
742 findStringSetMismatch(const char *currLoc
, const UChar
*string
, int32_t langSize
,
743 USet
* mergedExemplarSet
,
744 UBool ignoreNumbers
, UChar
* badCharPtr
) {
745 UErrorCode errorCode
= U_ZERO_ERROR
;
748 if (mergedExemplarSet
== NULL
) {
751 exemplarSet
= createFlattenSet(mergedExemplarSet
, &errorCode
);
752 if (U_FAILURE(errorCode
)) {
753 log_err("%s: error createFlattenSet returned %s\n", currLoc
, u_errorName(errorCode
));
757 for (strIdx
= 0; strIdx
< langSize
; strIdx
++) {
758 if (!uset_contains(exemplarSet
, string
[strIdx
])
759 && string
[strIdx
] != 0x0020 && string
[strIdx
] != 0x00A0 && string
[strIdx
] != 0x002e && string
[strIdx
] != 0x002c && string
[strIdx
] != 0x002d && string
[strIdx
] != 0x0027 && string
[strIdx
] != 0x005B && string
[strIdx
] != 0x005D && string
[strIdx
] != 0x2019 && string
[strIdx
] != 0x0f0b
760 && string
[strIdx
] != 0x200C && string
[strIdx
] != 0x200D) {
761 if (!ignoreNumbers
|| (ignoreNumbers
&& (string
[strIdx
] < 0x30 || string
[strIdx
] > 0x39))) {
762 uset_close(exemplarSet
);
764 *badCharPtr
= string
[strIdx
];
770 uset_close(exemplarSet
);
776 /* include non-invariant chars */
778 myUCharsToChars(const UChar
* us
, char* cs
, int32_t len
){
790 findSetMatch( UScriptCode
*scriptCodes
, int32_t scriptsLen
,
793 USet
*scripts
[10]= {0};
794 char pattern
[256] = { '[', ':', 0x000 };
796 UChar uPattern
[256] = {0};
797 UErrorCode status
= U_ZERO_ERROR
;
800 /* create the sets with script codes */
801 for(i
= 0; i
<scriptsLen
; i
++){
802 strcat(pattern
, uscript_getShortName(scriptCodes
[i
]));
803 strcat(pattern
, ":]");
804 patternLen
= (int32_t)strlen(pattern
);
805 u_charsToUChars(pattern
, uPattern
, patternLen
);
806 scripts
[i
] = uset_openPattern(uPattern
, patternLen
, &status
);
807 if(U_FAILURE(status
)){
808 log_err("Could not create set for pattern %s. Error: %s\n", pattern
, u_errorName(status
));
813 if (strcmp(locale
, "uk") == 0 || strcmp(locale
, "uk_UA") == 0) {
814 /* Special addition. Add the modifying apostrophe, which isn't in Cyrillic. */
815 uset_add(scripts
[0], 0x2bc);
817 if(U_SUCCESS(status
)){
818 UBool existsInScript
= FALSE
;
819 /* iterate over the exemplarSet and ascertain if all
820 * UChars in exemplarSet belong to the scripts returned
823 int32_t count
= uset_getItemCount(exemplarSet
);
825 for( i
=0; i
< count
; i
++){
829 int32_t strCapacity
= 0;
831 strCapacity
= uset_getItem(exemplarSet
, i
, &start
, &end
, str
, strCapacity
, &status
);
832 if(U_SUCCESS(status
)){
834 if(strCapacity
== 0){
835 /* ok the item is a range */
836 for( j
= 0; j
< scriptsLen
; j
++){
837 if(uset_containsRange(scripts
[j
], start
, end
) == TRUE
){
838 existsInScript
= TRUE
;
841 if(existsInScript
== FALSE
){
842 for( j
= 0; j
< scriptsLen
; j
++){
843 UChar toPattern
[500]={'\0'};
844 char pat
[500]={'\0'};
845 int32_t len
= uset_toPattern(scripts
[j
], toPattern
, 500, TRUE
, &status
);
846 len
= myUCharsToChars(toPattern
, pat
, len
);
847 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
));
849 log_err("Pattern: %s\n",pat
);
852 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale
);
855 strCapacity
++; /* increment for NUL termination */
856 /* allocate the str and call the api again */
857 str
= (UChar
*) malloc(U_SIZEOF_UCHAR
* strCapacity
);
858 strCapacity
= uset_getItem(exemplarSet
, i
, &start
, &end
, str
, strCapacity
, &status
);
859 /* iterate over the scripts and figure out if the string contained is actually
862 for( j
= 0; j
< scriptsLen
; j
++){
863 if(uset_containsString(scripts
[j
],str
, strCapacity
) == TRUE
){
864 existsInScript
= TRUE
;
867 if(existsInScript
== FALSE
){
868 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale
);
877 for(i
= 0; i
<scriptsLen
; i
++){
878 uset_close(scripts
[i
]);
882 static void VerifyTranslation(void) {
883 UResourceBundle
*root
, *currentLocale
;
884 int32_t locCount
= uloc_countAvailable();
886 UErrorCode errorCode
= U_ZERO_ERROR
;
888 UScriptCode scripts
[USCRIPT_CODE_LIMIT
];
892 UResourceBundle
*resArray
;
895 log_data_err("At least root needs to be installed\n");
898 root
= ures_openDirect(NULL
, "root", &errorCode
);
899 if(U_FAILURE(errorCode
)) {
900 log_data_err("Can't open root\n");
903 for (locIndex
= 0; locIndex
< locCount
; locIndex
++) {
904 USet
* mergedExemplarSet
= NULL
;
905 errorCode
=U_ZERO_ERROR
;
906 currLoc
= uloc_getAvailable(locIndex
);
907 currentLocale
= ures_open(NULL
, currLoc
, &errorCode
);
908 if(errorCode
!= U_ZERO_ERROR
) {
909 if(U_SUCCESS(errorCode
)) {
910 /* It's installed, but there is no data.
911 It's installed for the g18n white paper [grhoten] */
912 log_err("ERROR: Locale %-5s not installed, and it should be!\n",
913 uloc_getAvailable(locIndex
));
915 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
916 u_errorName(errorCode
),
917 uloc_getAvailable(locIndex
));
919 ures_close(currentLocale
);
923 UErrorCode exemplarStatus
= U_ZERO_ERROR
;
924 ULocaleData
* uld
= ulocdata_open(currLoc
, &exemplarStatus
);
925 if (U_SUCCESS(exemplarStatus
)) {
926 USet
* exemplarSet
= ulocdata_getExemplarSet(uld
, NULL
, USET_ADD_CASE_MAPPINGS
, ULOCDATA_ES_STANDARD
, &exemplarStatus
);
927 if (U_SUCCESS(exemplarStatus
)) {
928 mergedExemplarSet
= uset_cloneAsThawed(exemplarSet
);
929 uset_close(exemplarSet
);
930 exemplarSet
= ulocdata_getExemplarSet(uld
, NULL
, USET_ADD_CASE_MAPPINGS
, ULOCDATA_ES_AUXILIARY
, &exemplarStatus
);
931 if (U_SUCCESS(exemplarStatus
)) {
932 uset_addAll(mergedExemplarSet
, exemplarSet
);
933 uset_close(exemplarSet
);
935 exemplarStatus
= U_ZERO_ERROR
;
936 exemplarSet
= ulocdata_getExemplarSet(uld
, NULL
, 0, ULOCDATA_ES_PUNCTUATION
, &exemplarStatus
);
937 if (U_SUCCESS(exemplarStatus
)) {
938 uset_addAll(mergedExemplarSet
, exemplarSet
);
939 uset_close(exemplarSet
);
942 log_err("error ulocdata_getExemplarSet (main) for locale %s returned %s\n", currLoc
, u_errorName(errorCode
));
946 log_err("error ulocdata_open for locale %s returned %s\n", currLoc
, u_errorName(errorCode
));
949 if (mergedExemplarSet
== NULL
/*|| (getTestOption(QUICK_OPTION) && uset_size() > 2048)*/) {
950 log_verbose("skipping test for %s\n", currLoc
);
952 //else if (uprv_strncmp(currLoc,"bem",3) == 0 || uprv_strncmp(currLoc,"mgo",3) == 0 || uprv_strncmp(currLoc,"nl",2) == 0) {
953 // log_verbose("skipping test for %s, some month and country names known to use aux exemplars\n", currLoc);
956 UChar langBuffer
[128];
960 langSize
= uloc_getDisplayLanguage(currLoc
, currLoc
, langBuffer
, UPRV_LENGTHOF(langBuffer
), &errorCode
);
961 if (U_FAILURE(errorCode
)) {
962 log_err("error uloc_getDisplayLanguage returned %s\n", u_errorName(errorCode
));
965 strIdx
= findStringSetMismatch(currLoc
, langBuffer
, langSize
, mergedExemplarSet
, FALSE
, &badChar
);
968 log_err("getDisplayLanguage(%s) at index %d returned characters not in the exemplar characters: %04X in \"%s\"\n",
969 currLoc
, strIdx
, badChar
, u_austrncpy(bbuf
,langBuffer
,langSize
));
972 langSize
= uloc_getDisplayCountry(currLoc
, currLoc
, langBuffer
, UPRV_LENGTHOF(langBuffer
), &errorCode
);
973 if (U_FAILURE(errorCode
)) {
974 log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode
));
977 UResourceBundle
* cal
= ures_getByKey(currentLocale
, "calendar", NULL
, &errorCode
);
978 UResourceBundle
* greg
= ures_getByKeyWithFallback(cal
, "gregorian", NULL
, &errorCode
);
979 UResourceBundle
* names
= ures_getByKeyWithFallback(greg
, "dayNames", NULL
, &errorCode
);
980 UResourceBundle
* format
= ures_getByKeyWithFallback(names
, "format", NULL
, &errorCode
);
981 resArray
= ures_getByKeyWithFallback(format
, "wide", NULL
, &errorCode
);
983 if (U_FAILURE(errorCode
)) {
984 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode
));
986 if (getTestOption(QUICK_OPTION
)) {
990 end
= ures_getSize(resArray
);
993 if ((uprv_strncmp(currLoc
,"lrc",3) == 0 || uprv_strncmp(currLoc
,"mzn",3) == 0) &&
994 log_knownIssue("cldrbug:8899", "lrc and mzn locales don't have translated day names")) {
998 for (idx
= 0; idx
< end
; idx
++) {
999 const UChar
*fromBundleStr
= ures_getStringByIndex(resArray
, idx
, &langSize
, &errorCode
);
1000 if (U_FAILURE(errorCode
)) {
1001 log_err("error ures_getStringByIndex(%d) returned %s\n", idx
, u_errorName(errorCode
));
1004 strIdx
= findStringSetMismatch(currLoc
, fromBundleStr
, langSize
, mergedExemplarSet
, TRUE
, &badChar
);
1005 if ( strIdx
>= 0 ) {
1006 log_err("getDayNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1007 currLoc
, idx
, strIdx
, badChar
);
1010 ures_close(resArray
);
1014 names
= ures_getByKeyWithFallback(greg
, "monthNames", NULL
, &errorCode
);
1015 format
= ures_getByKeyWithFallback(names
,"format", NULL
, &errorCode
);
1016 resArray
= ures_getByKeyWithFallback(format
, "wide", NULL
, &errorCode
);
1017 if (U_FAILURE(errorCode
)) {
1018 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode
));
1020 if (getTestOption(QUICK_OPTION
)) {
1024 end
= ures_getSize(resArray
);
1027 for (idx
= 0; idx
< end
; idx
++) {
1028 const UChar
*fromBundleStr
= ures_getStringByIndex(resArray
, idx
, &langSize
, &errorCode
);
1029 if (U_FAILURE(errorCode
)) {
1030 log_err("error ures_getStringByIndex(%d) returned %s\n", idx
, u_errorName(errorCode
));
1033 strIdx
= findStringSetMismatch(currLoc
, fromBundleStr
, langSize
, mergedExemplarSet
, TRUE
, &badChar
);
1035 log_err("getMonthNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1036 currLoc
, idx
, strIdx
, badChar
);
1039 ures_close(resArray
);
1045 errorCode
= U_ZERO_ERROR
;
1046 numScripts
= uscript_getCode(currLoc
, scripts
, UPRV_LENGTHOF(scripts
), &errorCode
);
1047 if (strcmp(currLoc
, "yi") == 0 && numScripts
> 0 && log_knownIssue("11217", "Fix result of uscript_getCode for yi: USCRIPT_YI -> USCRIPT_HEBREW")) {
1048 scripts
[0] = USCRIPT_HEBREW
;
1050 if (numScripts
== 0) {
1051 log_err("uscript_getCode(%s) doesn't work.\n", currLoc
);
1052 }else if(scripts
[0] == USCRIPT_COMMON
){
1053 log_err("uscript_getCode(%s) returned USCRIPT_COMMON.\n", currLoc
);
1056 /* test that the scripts are a superset of exemplar characters. */
1058 ULocaleData
*uld
= ulocdata_open(currLoc
,&errorCode
);
1059 USet
*exemplarSet
= ulocdata_getExemplarSet(uld
, NULL
, 0, ULOCDATA_ES_STANDARD
, &errorCode
);
1060 /* test if exemplar characters are part of script code */
1061 findSetMatch(scripts
, numScripts
, exemplarSet
, currLoc
);
1062 uset_close(exemplarSet
);
1063 ulocdata_close(uld
);
1066 /* test that the paperSize API works */
1068 int32_t height
=0, width
=0;
1069 ulocdata_getPaperSize(currLoc
, &height
, &width
, &errorCode
);
1070 if(U_FAILURE(errorCode
)){
1071 log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc
, u_errorName(errorCode
));
1073 if(strstr(currLoc
, "_US")!=NULL
&& height
!= 279 && width
!= 216 ){
1074 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc
);
1077 /* test that the MeasurementSystem API works */
1079 char fullLoc
[ULOC_FULLNAME_CAPACITY
];
1080 UMeasurementSystem measurementSystem
;
1081 int32_t height
= 0, width
= 0;
1083 uloc_addLikelySubtags(currLoc
, fullLoc
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
1085 errorCode
= U_ZERO_ERROR
;
1086 measurementSystem
= ulocdata_getMeasurementSystem(currLoc
, &errorCode
);
1087 if (U_FAILURE(errorCode
)) {
1088 log_err("ulocdata_getMeasurementSystem failed for locale %s with error: %s \n", currLoc
, u_errorName(errorCode
));
1090 if ( strstr(fullLoc
, "_US")!=NULL
|| strstr(fullLoc
, "_MM")!=NULL
|| strstr(fullLoc
, "_LR")!=NULL
) {
1091 if(measurementSystem
!= UMS_US
){
1092 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc
);
1094 } else if ( strstr(fullLoc
, "_GB")!=NULL
) {
1095 if(measurementSystem
!= UMS_UK
){
1096 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc
);
1098 } else if (measurementSystem
!= UMS_SI
) {
1099 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc
);
1103 errorCode
= U_ZERO_ERROR
;
1104 ulocdata_getPaperSize(currLoc
, &height
, &width
, &errorCode
);
1105 if (U_FAILURE(errorCode
)) {
1106 log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc
, u_errorName(errorCode
));
1108 if ( strstr(fullLoc
, "_US")!=NULL
|| strstr(fullLoc
, "_BZ")!=NULL
|| strstr(fullLoc
, "_CA")!=NULL
|| strstr(fullLoc
, "_CL")!=NULL
||
1109 strstr(fullLoc
, "_CO")!=NULL
|| strstr(fullLoc
, "_CR")!=NULL
|| strstr(fullLoc
, "_GT")!=NULL
|| strstr(fullLoc
, "_MX")!=NULL
||
1110 strstr(fullLoc
, "_NI")!=NULL
|| strstr(fullLoc
, "_PA")!=NULL
|| strstr(fullLoc
, "_PH")!=NULL
|| strstr(fullLoc
, "_PR")!=NULL
||
1111 strstr(fullLoc
, "_SV")!=NULL
|| strstr(fullLoc
, "_VE")!=NULL
) {
1112 if (height
!= 279 || width
!= 216) {
1113 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc
);
1115 } else if (height
!= 297 || width
!= 210) {
1116 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc
);
1121 if (mergedExemplarSet
!= NULL
) {
1122 uset_close(mergedExemplarSet
);
1124 ures_close(currentLocale
);
1130 /* adjust this limit as appropriate */
1131 #define MAX_SCRIPTS_PER_LOCALE 8
1133 static void TestExemplarSet(void){
1134 int32_t i
, j
, k
, m
, n
;
1135 int32_t equalCount
= 0;
1136 UErrorCode ec
= U_ZERO_ERROR
;
1137 UEnumeration
* avail
;
1138 USet
* exemplarSets
[2];
1139 USet
* unassignedSet
;
1140 UScriptCode code
[MAX_SCRIPTS_PER_LOCALE
];
1141 USet
* codeSets
[MAX_SCRIPTS_PER_LOCALE
];
1143 char cbuf
[32]; /* 9 should be enough */
1144 UChar ubuf
[64]; /* adjust as needed */
1145 UBool existsInScript
;
1150 unassignedSet
= NULL
;
1151 exemplarSets
[0] = NULL
;
1152 exemplarSets
[1] = NULL
;
1153 for (i
=0; i
<MAX_SCRIPTS_PER_LOCALE
; ++i
) {
1157 avail
= ures_openAvailableLocales(NULL
, &ec
);
1158 if (!assertSuccess("ures_openAvailableLocales", &ec
)) goto END
;
1159 n
= uenum_count(avail
, &ec
);
1160 if (!assertSuccess("uenum_count", &ec
)) goto END
;
1162 u_uastrcpy(ubuf
, "[:unassigned:]");
1163 unassignedSet
= uset_openPattern(ubuf
, -1, &ec
);
1164 if (!assertSuccess("uset_openPattern", &ec
)) goto END
;
1167 const char* locale
= uenum_next(avail
, NULL
, &ec
);
1168 if (!assertSuccess("uenum_next", &ec
)) goto END
;
1169 log_verbose("%s\n", locale
);
1170 for (k
=0; k
<2; ++k
) {
1171 uint32_t option
= (k
==0) ? 0 : USET_CASE_INSENSITIVE
;
1172 ULocaleData
*uld
= ulocdata_open(locale
,&ec
);
1173 USet
* exemplarSet
= ulocdata_getExemplarSet(uld
,NULL
, option
, ULOCDATA_ES_STANDARD
, &ec
);
1174 uset_close(exemplarSets
[k
]);
1175 ulocdata_close(uld
);
1176 exemplarSets
[k
] = exemplarSet
;
1177 if (!assertSuccess("ulocaledata_getExemplarSet", &ec
)) goto END
;
1179 if (uset_containsSome(exemplarSet
, unassignedSet
)) {
1180 log_err("ExemplarSet contains unassigned characters for locale : %s\n", locale
);
1182 codeLen
= uscript_getCode(locale
, code
, 8, &ec
);
1183 if (strcmp(locale
, "yi") == 0 && codeLen
> 0 && log_knownIssue("11217", "Fix result of uscript_getCode for yi: USCRIPT_YI -> USCRIPT_HEBREW")) {
1184 code
[0] = USCRIPT_HEBREW
;
1186 if (!assertSuccess("uscript_getCode", &ec
)) goto END
;
1188 for (j
=0; j
<MAX_SCRIPTS_PER_LOCALE
; ++j
) {
1189 uset_close(codeSets
[j
]);
1192 for (j
=0; j
<codeLen
; ++j
) {
1193 uprv_strcpy(cbuf
, "[:");
1195 log_err("USCRIPT_INVALID_CODE returned for locale: %s\n", locale
);
1198 uprv_strcat(cbuf
, uscript_getShortName(code
[j
]));
1199 uprv_strcat(cbuf
, ":]");
1200 u_uastrcpy(ubuf
, cbuf
);
1201 codeSets
[j
] = uset_openPattern(ubuf
, -1, &ec
);
1203 if (!assertSuccess("uset_openPattern", &ec
)) goto END
;
1205 existsInScript
= FALSE
;
1206 itemCount
= uset_getItemCount(exemplarSet
);
1207 for (m
=0; m
<itemCount
&& !existsInScript
; ++m
) {
1208 strLen
= uset_getItem(exemplarSet
, m
, &start
, &end
, ubuf
,
1209 UPRV_LENGTHOF(ubuf
), &ec
);
1210 /* failure here might mean str[] needs to be larger */
1211 if (!assertSuccess("uset_getItem", &ec
)) goto END
;
1213 for (j
=0; j
<codeLen
; ++j
) {
1214 if (codeSets
[j
]!=NULL
&& uset_containsRange(codeSets
[j
], start
, end
)) {
1215 existsInScript
= TRUE
;
1220 for (j
=0; j
<codeLen
; ++j
) {
1221 if (codeSets
[j
]!=NULL
&& uset_containsString(codeSets
[j
], ubuf
, strLen
)) {
1222 existsInScript
= TRUE
;
1229 if (existsInScript
== FALSE
){
1230 log_err("ExemplarSet containment failed for locale : %s\n", locale
);
1233 assertTrue("case-folded is a superset",
1234 uset_containsAll(exemplarSets
[1], exemplarSets
[0]));
1235 if (uset_equals(exemplarSets
[1], exemplarSets
[0])) {
1239 /* Note: The case-folded set should sometimes be a strict superset
1240 and sometimes be equal. */
1241 assertTrue("case-folded is sometimes a strict superset, and sometimes equal",
1242 equalCount
> 0 && equalCount
< n
);
1246 uset_close(exemplarSets
[0]);
1247 uset_close(exemplarSets
[1]);
1248 uset_close(unassignedSet
);
1249 for (i
=0; i
<MAX_SCRIPTS_PER_LOCALE
; ++i
) {
1250 uset_close(codeSets
[i
]);
1254 enum { kUBufMax
= 32 };
1255 static void TestLocaleDisplayPattern(void){
1257 UChar pattern
[kUBufMax
] = {0,};
1258 UChar separator
[kUBufMax
] = {0,};
1260 static const UChar enExpectPat
[] = { 0x007B,0x0030,0x007D,0x0020,0x0028,0x007B,0x0031,0x007D,0x0029,0 }; /* "{0} ({1})" */
1261 static const UChar enExpectSep
[] = { 0x002C,0x0020,0 }; /* ", " */
1262 static const UChar zhExpectPat
[] = { 0x007B,0x0030,0x007D,0xFF08,0x007B,0x0031,0x007D,0xFF09,0 };
1263 static const UChar zhExpectSep
[] = { 0x3001,0 };
1265 status
= U_ZERO_ERROR
;
1266 uld
= ulocdata_open("en", &status
);
1267 if(U_FAILURE(status
)){
1268 log_data_err("ulocdata_open en error %s", u_errorName(status
));
1270 ulocdata_getLocaleDisplayPattern(uld
, pattern
, kUBufMax
, &status
);
1271 if (U_FAILURE(status
)){
1272 log_err("ulocdata_getLocaleDisplayPattern en error %s", u_errorName(status
));
1273 } else if (u_strcmp(pattern
, enExpectPat
) != 0) {
1274 log_err("ulocdata_getLocaleDisplayPattern en returns unexpected pattern");
1276 status
= U_ZERO_ERROR
;
1277 ulocdata_getLocaleSeparator(uld
, separator
, kUBufMax
, &status
);
1278 if (U_FAILURE(status
)){
1279 log_err("ulocdata_getLocaleSeparator en error %s", u_errorName(status
));
1280 } else if (u_strcmp(separator
, enExpectSep
) != 0) {
1281 log_err("ulocdata_getLocaleSeparator en returns unexpected string ");
1283 ulocdata_close(uld
);
1286 status
= U_ZERO_ERROR
;
1287 uld
= ulocdata_open("zh", &status
);
1288 if(U_FAILURE(status
)){
1289 log_data_err("ulocdata_open zh error %s", u_errorName(status
));
1291 ulocdata_getLocaleDisplayPattern(uld
, pattern
, kUBufMax
, &status
);
1292 if (U_FAILURE(status
)){
1293 log_err("ulocdata_getLocaleDisplayPattern zh error %s", u_errorName(status
));
1294 } else if (u_strcmp(pattern
, zhExpectPat
) != 0) {
1295 log_err("ulocdata_getLocaleDisplayPattern zh returns unexpected pattern");
1297 status
= U_ZERO_ERROR
;
1298 ulocdata_getLocaleSeparator(uld
, separator
, kUBufMax
, &status
);
1299 if (U_FAILURE(status
)){
1300 log_err("ulocdata_getLocaleSeparator zh error %s", u_errorName(status
));
1301 } else if (u_strcmp(separator
, zhExpectSep
) != 0) {
1302 log_err("ulocdata_getLocaleSeparator zh returns unexpected string ");
1304 ulocdata_close(uld
);
1308 static void TestCoverage(void){
1309 ULocaleDataDelimiterType types
[] = {
1310 ULOCDATA_QUOTATION_START
, /* Quotation start */
1311 ULOCDATA_QUOTATION_END
, /* Quotation end */
1312 ULOCDATA_ALT_QUOTATION_START
, /* Alternate quotation start */
1313 ULOCDATA_ALT_QUOTATION_END
, /* Alternate quotation end */
1314 ULOCDATA_DELIMITER_COUNT
1318 UErrorCode status
= U_ZERO_ERROR
;
1319 ULocaleData
*uld
= ulocdata_open(uloc_getDefault(), &status
);
1321 if(U_FAILURE(status
)){
1322 log_data_err("ulocdata_open error");
1327 for(i
= 0; i
< ULOCDATA_DELIMITER_COUNT
; i
++){
1328 UChar result
[32] = {0,};
1329 status
= U_ZERO_ERROR
;
1330 ulocdata_getDelimiter(uld
, types
[i
], result
, 32, &status
);
1331 if (U_FAILURE(status
)){
1332 log_err("ulocdata_getgetDelimiter error with type %d", types
[i
]);
1336 sub
= ulocdata_getNoSubstitute(uld
);
1337 ulocdata_setNoSubstitute(uld
,sub
);
1338 ulocdata_close(uld
);
1341 static void TestIndexChars(void) {
1342 /* Very basic test of ULOCDATA_ES_INDEX.
1343 * No comprehensive test of data, just basic check that the code path is alive.
1345 UErrorCode status
= U_ZERO_ERROR
;
1347 USet
*exemplarChars
;
1350 uld
= ulocdata_open("en", &status
);
1351 exemplarChars
= uset_openEmpty();
1352 indexChars
= uset_openEmpty();
1353 ulocdata_getExemplarSet(uld
, exemplarChars
, 0, ULOCDATA_ES_STANDARD
, &status
);
1354 ulocdata_getExemplarSet(uld
, indexChars
, 0, ULOCDATA_ES_INDEX
, &status
);
1355 if (U_FAILURE(status
)) {
1356 log_data_err("File %s, line %d, Failure opening exemplar chars: %s", __FILE__
, __LINE__
, u_errorName(status
));
1359 /* en data, standard exemplars are [a-z], lower case. */
1360 /* en data, index characters are [A-Z], upper case. */
1361 if ((uset_contains(exemplarChars
, (UChar32
)0x41) || uset_contains(indexChars
, (UChar32
)0x61))) {
1362 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__
, __LINE__
);
1365 if (!(uset_contains(exemplarChars
, (UChar32
)0x61) && uset_contains(indexChars
, (UChar32
)0x41) )) {
1366 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__
, __LINE__
);
1371 uset_close(exemplarChars
);
1372 uset_close(indexChars
);
1373 ulocdata_close(uld
);
1378 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1379 static void TestCurrencyList(void){
1380 #if !UCONFIG_NO_FORMATTING
1381 UErrorCode errorCode
= U_ZERO_ERROR
;
1382 int32_t structLocaleCount
, currencyCount
;
1383 UEnumeration
*en
= ucurr_openISOCurrencies(UCURR_ALL
, &errorCode
);
1384 const char *isoCode
, *structISOCode
;
1385 UResourceBundle
*subBundle
;
1386 UResourceBundle
*currencies
= ures_openDirect(loadTestData(&errorCode
), "structLocale", &errorCode
);
1387 if(U_FAILURE(errorCode
)) {
1388 log_data_err("Can't open structLocale\n");
1391 currencies
= ures_getByKey(currencies
, "Currencies", currencies
, &errorCode
);
1392 currencyCount
= uenum_count(en
, &errorCode
);
1393 structLocaleCount
= ures_getSize(currencies
);
1394 if (currencyCount
!= structLocaleCount
) {
1395 log_err("structLocale(%d) and ISO4217(%d) currency list are out of sync.\n", structLocaleCount
, currencyCount
);
1396 #if U_CHARSET_FAMILY == U_ASCII_FAMILY
1397 ures_resetIterator(currencies
);
1398 while ((isoCode
= uenum_next(en
, NULL
, &errorCode
)) != NULL
&& ures_hasNext(currencies
)) {
1399 subBundle
= ures_getNextResource(currencies
, NULL
, &errorCode
);
1400 structISOCode
= ures_getKey(subBundle
);
1401 ures_close(subBundle
);
1402 if (strcmp(structISOCode
, isoCode
) != 0) {
1403 log_err("First difference found at structLocale(%s) and ISO4217(%s).\n", structISOCode
, isoCode
);
1409 ures_close(currencies
);
1415 static void TestAvailableIsoCodes(void){
1416 #if !UCONFIG_NO_FORMATTING
1417 UErrorCode errorCode
= U_ZERO_ERROR
;
1418 const char* eurCode
= "EUR";
1419 const char* usdCode
= "USD";
1420 const char* lastCode
= "RHD";
1421 const char* zzzCode
= "ZZZ";
1422 UDate date1950
= (UDate
)-630720000000.0;/* year 1950 */
1423 UDate date1970
= (UDate
)0.0; /* year 1970 */
1424 UDate date1975
= (UDate
)173448000000.0; /* year 1975 */
1425 UDate date1978
= (UDate
)260172000000.0; /* year 1978 */
1426 UDate date1981
= (UDate
)346896000000.0; /* year 1981 */
1427 UDate date1992
= (UDate
)693792000000.0; /* year 1992 */
1428 UChar
* isoCode
= (UChar
*)malloc(sizeof(UChar
) * (uprv_strlen(usdCode
) + 1));
1430 /* testing available codes with no time ranges */
1431 u_charsToUChars(eurCode
, isoCode
, uprv_strlen(usdCode
) + 1);
1432 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1433 log_data_err("FAIL: ISO code (%s) is not found.\n", eurCode
);
1436 u_charsToUChars(usdCode
, isoCode
, uprv_strlen(zzzCode
) + 1);
1437 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1438 log_data_err("FAIL: ISO code (%s) is not found.\n", usdCode
);
1441 u_charsToUChars(zzzCode
, isoCode
, uprv_strlen(zzzCode
) + 1);
1442 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == TRUE
) {
1443 log_err("FAIL: ISO code (%s) is reported as available, but it doesn't exist.\n", zzzCode
);
1446 u_charsToUChars(lastCode
, isoCode
, uprv_strlen(zzzCode
) + 1);
1447 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1448 log_data_err("FAIL: ISO code (%s) is not found.\n", lastCode
);
1451 /* RHD was used from 1970-02-17 to 1980-04-18*/
1454 if (ucurr_isAvailable(isoCode
, date1970
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1455 log_data_err("FAIL: ISO code (%s) was available in time range >1970-01-01.\n", lastCode
);
1458 if (ucurr_isAvailable(isoCode
, date1975
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1459 log_data_err("FAIL: ISO code (%s) was available in time range >1975.\n", lastCode
);
1462 if (ucurr_isAvailable(isoCode
, date1981
, U_DATE_MAX
, &errorCode
) == TRUE
) {
1463 log_err("FAIL: ISO code (%s) was not available in time range >1981.\n", lastCode
);
1467 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1970
, &errorCode
) == TRUE
) {
1468 log_err("FAIL: ISO code (%s) was not available in time range <1970.\n", lastCode
);
1471 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1975
, &errorCode
) == FALSE
) {
1472 log_data_err("FAIL: ISO code (%s) was available in time range <1975.\n", lastCode
);
1475 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1981
, &errorCode
) == FALSE
) {
1476 log_data_err("FAIL: ISO code (%s) was available in time range <1981.\n", lastCode
);
1480 if (ucurr_isAvailable(isoCode
, date1975
, date1978
, &errorCode
) == FALSE
) {
1481 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1978.\n", lastCode
);
1484 if (ucurr_isAvailable(isoCode
, date1970
, date1975
, &errorCode
) == FALSE
) {
1485 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1975.\n", lastCode
);
1488 if (ucurr_isAvailable(isoCode
, date1975
, date1981
, &errorCode
) == FALSE
) {
1489 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1981.\n", lastCode
);
1492 if (ucurr_isAvailable(isoCode
, date1970
, date1981
, &errorCode
) == FALSE
) {
1493 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1981.\n", lastCode
);
1496 if (ucurr_isAvailable(isoCode
, date1981
, date1992
, &errorCode
) == TRUE
) {
1497 log_err("FAIL: ISO code (%s) was not available in time range 1981-1992.\n", lastCode
);
1500 if (ucurr_isAvailable(isoCode
, date1950
, date1970
, &errorCode
) == TRUE
) {
1501 log_err("FAIL: ISO code (%s) was not available in time range 1950-1970.\n", lastCode
);
1504 /* wrong range - from > to*/
1505 if (ucurr_isAvailable(isoCode
, date1975
, date1970
, &errorCode
) == TRUE
) {
1506 log_err("FAIL: Wrong range 1975-1970 for ISO code (%s) was not reported.\n", lastCode
);
1507 } else if (errorCode
!= U_ILLEGAL_ARGUMENT_ERROR
) {
1508 log_data_err("FAIL: Error code not reported for wrong range 1975-1970 for ISO code (%s).\n", lastCode
);
1515 #define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name)
1517 void addCLDRTest(TestNode
** root
);
1519 void addCLDRTest(TestNode
** root
)
1521 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1522 TESTCASE(TestLocaleStructure
);
1523 TESTCASE(TestCurrencyList
);
1525 TESTCASE(TestConsistentCountryInfo
);
1526 TESTCASE(VerifyTranslation
);
1527 TESTCASE(TestExemplarSet
);
1528 TESTCASE(TestLocaleDisplayPattern
);
1529 TESTCASE(TestCoverage
);
1530 TESTCASE(TestIndexChars
);
1531 TESTCASE(TestAvailableIsoCodes
);