1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 1997-2016, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
10 #include "unicode/ures.h"
11 #include "unicode/ucurr.h"
12 #include "unicode/ustring.h"
13 #include "unicode/uset.h"
14 #include "unicode/udat.h"
15 #include "unicode/uscript.h"
16 #include "unicode/ulocdata.h"
23 returns a new UnicodeSet that is a flattened form of the original
27 createFlattenSet(USet
*origSet
, UErrorCode
*status
) {
31 int32_t origItemCount
= 0;
32 int32_t idx
, graphmeSize
;
35 if (U_FAILURE(*status
)) {
36 log_err("createFlattenSet called with %s\n", u_errorName(*status
));
39 newSet
= uset_open(1, 0);
40 origItemCount
= uset_getItemCount(origSet
);
41 for (idx
= 0; idx
< origItemCount
; idx
++) {
42 graphmeSize
= uset_getItem(origSet
, idx
,
44 graphme
, UPRV_LENGTHOF(graphme
),
46 if (U_FAILURE(*status
)) {
47 log_err("ERROR: uset_getItem returned %s\n", u_errorName(*status
));
48 *status
= U_ZERO_ERROR
;
51 uset_addAllCodePoints(newSet
, graphme
, graphmeSize
);
54 uset_addRange(newSet
, start
, end
);
57 uset_closeOver(newSet
,USET_CASE_INSENSITIVE
);
62 isCurrencyPreEuro(const char* currencyKey
){
63 if( strcmp(currencyKey
, "PTE") == 0 ||
64 strcmp(currencyKey
, "ESP") == 0 ||
65 strcmp(currencyKey
, "LUF") == 0 ||
66 strcmp(currencyKey
, "GRD") == 0 ||
67 strcmp(currencyKey
, "BEF") == 0 ||
68 strcmp(currencyKey
, "ITL") == 0 ||
69 strcmp(currencyKey
, "EEK") == 0){
74 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
76 TestKeyInRootRecursive(UResourceBundle
*root
, const char *rootName
,
77 UResourceBundle
*currentBundle
, const char *locale
) {
78 UErrorCode errorCode
= U_ZERO_ERROR
;
79 UResourceBundle
*subRootBundle
= NULL
, *subBundle
= NULL
, *arr
= NULL
;
81 ures_resetIterator(root
);
82 ures_resetIterator(currentBundle
);
83 while (ures_hasNext(currentBundle
)) {
84 const char *subBundleKey
= NULL
;
85 const char *currentBundleKey
= NULL
;
87 errorCode
= U_ZERO_ERROR
;
88 currentBundleKey
= ures_getKey(currentBundle
);
89 (void)currentBundleKey
; /* Suppress set but not used warning. */
90 subBundle
= ures_getNextResource(currentBundle
, NULL
, &errorCode
);
91 if (U_FAILURE(errorCode
)) {
92 log_err("Can't open a resource for lnocale %s. Error: %s\n", locale
, u_errorName(errorCode
));
95 subBundleKey
= ures_getKey(subBundle
);
98 subRootBundle
= ures_getByKey(root
, subBundleKey
, NULL
, &errorCode
);
99 if (U_FAILURE(errorCode
)) {
100 log_err("Can't open a resource with key \"%s\" in \"%s\" from %s for locale \"%s\"\n",
102 ures_getKey(currentBundle
),
105 ures_close(subBundle
);
108 if (ures_getType(subRootBundle
) != ures_getType(subBundle
)) {
109 log_err("key \"%s\" in \"%s\" has a different type from root for locale \"%s\"\n"
110 "\troot=%d, locale=%d\n",
112 ures_getKey(currentBundle
),
114 ures_getType(subRootBundle
),
115 ures_getType(subBundle
));
116 ures_close(subBundle
);
119 else if (ures_getType(subBundle
) == URES_INT_VECTOR
) {
121 int32_t subBundleSize
;
123 UBool sameArray
= TRUE
;
124 const int32_t *subRootBundleArr
= ures_getIntVector(subRootBundle
, &minSize
, &errorCode
);
125 const int32_t *subBundleArr
= ures_getIntVector(subBundle
, &subBundleSize
, &errorCode
);
127 if (minSize
> subBundleSize
) {
128 minSize
= subBundleSize
;
129 log_err("Arrays are different size with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
131 ures_getKey(currentBundle
),
135 for (idx
= 0; idx
< minSize
&& sameArray
; idx
++) {
136 if (subRootBundleArr
[idx
] != subBundleArr
[idx
]) {
139 if (strcmp(subBundleKey
, "DateTimeElements") == 0
140 && (subBundleArr
[idx
] < 1 || 7 < subBundleArr
[idx
]))
142 log_err("Value out of range with key \"%s\" at index %d in \"%s\" for locale \"%s\"\n",
145 ures_getKey(currentBundle
),
149 /* Special exception es_US and DateTimeElements */
151 && !(strcmp(locale
, "es_US") == 0 && strcmp(subBundleKey
, "DateTimeElements") == 0))
153 log_err("Integer vectors are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
155 ures_getKey(currentBundle
),
159 else if (ures_getType(subBundle
) == URES_ARRAY
) {
160 UResourceBundle
*subSubBundle
= ures_getByIndex(subBundle
, 0, NULL
, &errorCode
);
161 UResourceBundle
*subSubRootBundle
= ures_getByIndex(subRootBundle
, 0, NULL
, &errorCode
);
163 if (U_SUCCESS(errorCode
)
164 && (ures_getType(subSubBundle
) == URES_ARRAY
|| ures_getType(subSubRootBundle
) == URES_ARRAY
))
166 /* Here is one of the recursive parts */
167 TestKeyInRootRecursive(subRootBundle
, rootName
, subBundle
, locale
);
170 int32_t minSize
= ures_getSize(subRootBundle
);
172 UBool sameArray
= TRUE
;
174 if (minSize
> ures_getSize(subBundle
)) {
175 minSize
= ures_getSize(subBundle
);
178 if ((subBundleKey
== NULL
179 || (subBundleKey
!= NULL
&& strcmp(subBundleKey
, "LocaleScript") != 0 && !isCurrencyPreEuro(subBundleKey
)))
180 && ures_getSize(subRootBundle
) != ures_getSize(subBundle
))
182 log_err("Different size array with key \"%s\" in \"%s\" from root for locale \"%s\"\n"
183 "\troot array size=%d, locale array size=%d\n",
185 ures_getKey(currentBundle
),
187 ures_getSize(subRootBundle
),
188 ures_getSize(subBundle
));
191 if(isCurrencyPreEuro(subBundleKey) && ures_getSize(subBundle)!=3){
192 log_err("Different size array with key \"%s\" in \"%s\" for locale \"%s\" the expected size is 3 got size=%d\n",
194 ures_getKey(currentBundle),
196 ures_getSize(subBundle));
199 for (idx
= 0; idx
< minSize
; idx
++) {
200 int32_t rootStrLen
, localeStrLen
;
201 const UChar
*rootStr
= ures_getStringByIndex(subRootBundle
,idx
,&rootStrLen
,&errorCode
);
202 const UChar
*localeStr
= ures_getStringByIndex(subBundle
,idx
,&localeStrLen
,&errorCode
);
203 if (rootStr
&& localeStr
&& U_SUCCESS(errorCode
)) {
204 if (u_strcmp(rootStr
, localeStr
) != 0) {
209 if ( rootStrLen
> 1 && rootStr
[0] == 0x41 && rootStr
[1] >= 0x30 && rootStr
[1] <= 0x39 ) {
210 /* A2 or A4 in the root string indicates that the resource can optionally be an array instead of a */
211 /* string. Attempt to read it as an array. */
212 errorCode
= U_ZERO_ERROR
;
213 arr
= ures_getByIndex(subBundle
,idx
,NULL
,&errorCode
);
214 if (U_FAILURE(errorCode
)) {
215 log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
217 ures_getKey(currentBundle
),
222 if (ures_getType(arr
) != URES_ARRAY
|| ures_getSize(arr
) != (int32_t)rootStr
[1] - 0x30) {
223 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",
226 ures_getKey(currentBundle
),
232 localeStr
= ures_getStringByIndex(arr
,0,&localeStrLen
,&errorCode
);
234 if (U_FAILURE(errorCode
)) {
235 log_err("Got something other than a string or array for key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
237 ures_getKey(currentBundle
),
243 log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
245 ures_getKey(currentBundle
),
251 if (localeStr
[0] == (UChar
)0x20) {
252 log_err("key \"%s\" at index %d in \"%s\" starts with a space in locale \"%s\"\n",
255 ures_getKey(currentBundle
),
258 else if ((localeStr
[localeStrLen
- 1] == (UChar
)0x20) && (strcmp(subBundleKey
,"separator") != 0)) {
259 log_err("key \"%s\" at index %d in \"%s\" ends with a space in locale \"%s\"\n",
262 ures_getKey(currentBundle
),
265 else if (subBundleKey
!= NULL
266 && strcmp(subBundleKey
, "DateTimePatterns") == 0)
269 const UChar
*localeStrItr
= localeStr
;
270 while (*localeStrItr
) {
271 if (*localeStrItr
== (UChar
)0x27 /* ' */) {
274 else if ((quoted
% 2) == 0) {
275 /* Search for unquoted characters */
276 if (4 <= idx
&& idx
<= 7
277 && (*localeStrItr
== (UChar
)0x6B /* k */
278 || *localeStrItr
== (UChar
)0x48 /* H */
279 || *localeStrItr
== (UChar
)0x6D /* m */
280 || *localeStrItr
== (UChar
)0x73 /* s */
281 || *localeStrItr
== (UChar
)0x53 /* S */
282 || *localeStrItr
== (UChar
)0x61 /* a */
283 || *localeStrItr
== (UChar
)0x68 /* h */
284 || *localeStrItr
== (UChar
)0x7A /* z */))
286 log_err("key \"%s\" at index %d has time pattern chars in date for locale \"%s\"\n",
291 else if (0 <= idx
&& idx
<= 3
292 && (*localeStrItr
== (UChar
)0x47 /* G */
293 || *localeStrItr
== (UChar
)0x79 /* y */
294 || *localeStrItr
== (UChar
)0x4D /* M */
295 || *localeStrItr
== (UChar
)0x64 /* d */
296 || *localeStrItr
== (UChar
)0x45 /* E */
297 || *localeStrItr
== (UChar
)0x44 /* D */
298 || *localeStrItr
== (UChar
)0x46 /* F */
299 || *localeStrItr
== (UChar
)0x77 /* w */
300 || *localeStrItr
== (UChar
)0x57 /* W */))
302 log_err("key \"%s\" at index %d has date pattern chars in time for locale \"%s\"\n",
311 else if (idx
== 4 && subBundleKey
!= NULL
312 && strcmp(subBundleKey
, "NumberElements") == 0
313 && u_charDigitValue(localeStr
[0]) != 0)
315 log_err("key \"%s\" at index %d has a non-zero based number for locale \"%s\"\n",
321 (void)sameArray
; /* Suppress set but not used warning. */
322 /* if (sameArray && strcmp(rootName, "root") == 0) {
323 log_err("Arrays are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
325 ures_getKey(currentBundle),
329 ures_close(subSubBundle
);
330 ures_close(subSubRootBundle
);
332 else if (ures_getType(subBundle
) == URES_STRING
) {
334 const UChar
*string
= ures_getString(subBundle
, &len
, &errorCode
);
335 if (U_FAILURE(errorCode
) || string
== NULL
) {
336 log_err("Can't open a string with key \"%s\" in \"%s\" for locale \"%s\"\n",
338 ures_getKey(currentBundle
),
340 } else if (string
[0] == (UChar
)0x20) {
341 log_err("key \"%s\" in \"%s\" starts with a space in locale \"%s\"\n",
343 ures_getKey(currentBundle
),
345 /* localeDisplayPattern/separator can end with a space */
346 } else if (string
[len
- 1] == (UChar
)0x20 && (strcmp(subBundleKey
,"separator"))) {
347 log_err("key \"%s\" in \"%s\" ends with a space in locale \"%s\"\n",
349 ures_getKey(currentBundle
),
351 } else if (strcmp(subBundleKey
, "localPatternChars") == 0) {
352 /* Note: We no longer import localPatternChars data starting
353 * ICU 3.8. So it never comes into this else if block. (ticket#5597)
356 /* Check well-formedness of localPatternChars. First, the
357 * length must match the number of fields defined by
358 * DateFormat. Second, each character in the string must
359 * be in the set [A-Za-z]. Finally, each character must be
363 #if !UCONFIG_NO_FORMATTING
364 if (len
!= UDAT_FIELD_COUNT
) {
365 log_err("key \"%s\" has the wrong number of characters in locale \"%s\"\n",
370 /* Check char validity. */
371 for (i
=0; i
<len
; ++i
) {
372 if (!((string
[i
] >= 65/*'A'*/ && string
[i
] <= 90/*'Z'*/) ||
373 (string
[i
] >= 97/*'a'*/ && string
[i
] <= 122/*'z'*/))) {
374 log_err("key \"%s\" has illegal character '%c' in locale \"%s\"\n",
379 /* Do O(n^2) check for duplicate chars. */
380 for (j
=0; j
<i
; ++j
) {
381 if (string
[j
] == string
[i
]) {
382 log_err("key \"%s\" has duplicate character '%c' in locale \"%s\"\n",
390 /* No fallback was done. Check for duplicate data */
391 /* The ures_* API does not do fallback of sub-resource bundles,
392 So we can't do this now. */
394 else if (strcmp(locale
, "root") != 0 && errorCode
== U_ZERO_ERROR
) {
396 const UChar
*rootString
= ures_getString(subRootBundle
, &len
, &errorCode
);
397 if (U_FAILURE(errorCode
) || rootString
== NULL
) {
398 log_err("Can't open a string with key \"%s\" in \"%s\" in root\n",
399 ures_getKey(subRootBundle
),
400 ures_getKey(currentBundle
));
402 } else if (u_strcmp(string
, rootString
) == 0) {
403 if (strcmp(locale
, "de_CH") != 0 && strcmp(subBundleKey
, "Countries") != 0 &&
404 strcmp(subBundleKey
, "Version") != 0) {
405 log_err("Found duplicate data with key \"%s\" in \"%s\" in locale \"%s\"\n",
406 ures_getKey(subRootBundle
),
407 ures_getKey(currentBundle
),
411 /* Ignore for now. */
412 /* Can be fixed if fallback through de locale was done. */
413 log_verbose("Skipping key %s in %s\n", subBundleKey
, locale
);
419 else if (ures_getType(subBundle
) == URES_TABLE
) {
420 if (strcmp(subBundleKey
, "availableFormats")!=0) {
421 /* Here is one of the recursive parts */
422 TestKeyInRootRecursive(subRootBundle
, rootName
, subBundle
, locale
);
425 log_verbose("Skipping key %s in %s\n", subBundleKey
, locale
);
428 else if (ures_getType(subBundle
) == URES_BINARY
|| ures_getType(subBundle
) == URES_INT
) {
429 /* Can't do anything to check it */
430 /* We'll assume it's all correct */
431 if (strcmp(subBundleKey
, "MeasurementSystem") != 0) {
432 log_verbose("Skipping key \"%s\" in \"%s\" for locale \"%s\"\n",
434 ures_getKey(currentBundle
),
437 /* Testing for MeasurementSystem is done in VerifyTranslation */
440 log_err("Type %d for key \"%s\" in \"%s\" is unknown for locale \"%s\"\n",
441 ures_getType(subBundle
),
443 ures_getKey(currentBundle
),
446 ures_close(subRootBundle
);
447 ures_close(subBundle
);
453 testLCID(UResourceBundle
*currentBundle
,
454 const char *localeName
)
456 UErrorCode status
= U_ZERO_ERROR
;
457 uint32_t expectedLCID
;
458 char lcidStringC
[64] = {0};
461 expectedLCID
= uloc_getLCID(localeName
);
462 if (expectedLCID
== 0) {
463 log_verbose("INFO: %-5s does not have any LCID mapping\n",
468 status
= U_ZERO_ERROR
;
469 len
= uprv_convertToPosix(expectedLCID
, lcidStringC
, UPRV_LENGTHOF(lcidStringC
) - 1, &status
);
470 if (U_FAILURE(status
)) {
471 log_err("ERROR: %.4x does not have a POSIX mapping due to %s\n",
472 expectedLCID
, u_errorName(status
));
474 lcidStringC
[len
] = 0;
476 if(strcmp(localeName
, lcidStringC
) != 0) {
479 uloc_getLanguage(localeName
, langName
, sizeof(langName
), &status
);
480 uloc_getLanguage(lcidStringC
, langLCID
, sizeof(langLCID
), &status
);
482 if (strcmp(langName
, langLCID
) == 0) {
483 log_verbose("WARNING: %-5s resolves to %s (0x%.4x)\n",
484 localeName
, lcidStringC
, expectedLCID
);
487 log_err("ERROR: %-5s has 0x%.4x and the number resolves wrongfully to %s\n",
488 localeName
, expectedLCID
, lcidStringC
);
493 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
495 TestLocaleStructure(void) {
496 // This test checks the locale structure against a key file located
497 // at source/test/testdata/structLocale.txt. When adding new data to
498 // a locale file such as en.txt, the structLocale.txt file must be changed
499 // too to include the the template of the new data. Otherwise this test
502 UResourceBundle
*root
, *currentLocale
;
503 int32_t locCount
= uloc_countAvailable();
505 UErrorCode errorCode
= U_ZERO_ERROR
;
506 const char *currLoc
, *resolvedLoc
;
508 /* TODO: Compare against parent's data too. This code can't handle fallbacks that some tools do already. */
509 /* char locName[ULOC_FULLNAME_CAPACITY];
512 for (locIndex = 0; locIndex < locCount; locIndex++) {
513 errorCode=U_ZERO_ERROR;
514 strcpy(locName, uloc_getAvailable(locIndex));
515 locNamePtr = strrchr(locName, '_');
520 strcpy(locName, "root");
523 root = ures_openDirect(NULL, locName, &errorCode);
524 if(U_FAILURE(errorCode)) {
525 log_err("Can't open %s\n", locName);
530 log_data_err("At least root needs to be installed\n");
533 root
= ures_openDirect(loadTestData(&errorCode
), "structLocale", &errorCode
);
534 if(U_FAILURE(errorCode
)) {
535 log_data_err("Can't open structLocale\n");
538 for (locIndex
= 0; locIndex
< locCount
; locIndex
++) {
539 errorCode
=U_ZERO_ERROR
;
540 currLoc
= uloc_getAvailable(locIndex
);
541 currentLocale
= ures_open(NULL
, currLoc
, &errorCode
);
542 if(errorCode
!= U_ZERO_ERROR
) {
543 if(U_SUCCESS(errorCode
)) {
544 /* It's installed, but there is no data.
545 It's installed for the g18n white paper [grhoten] */
546 log_err("ERROR: Locale %-5s not installed, and it should be, err %s\n",
547 uloc_getAvailable(locIndex
), u_errorName(errorCode
));
549 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
550 u_errorName(errorCode
),
551 uloc_getAvailable(locIndex
));
553 ures_close(currentLocale
);
556 ures_getStringByKey(currentLocale
, "Version", NULL
, &errorCode
);
557 if(errorCode
!= U_ZERO_ERROR
) {
558 log_err("No version information is available for locale %s, and it should be!\n",
561 else if (ures_getStringByKey(currentLocale
, "Version", NULL
, &errorCode
)[0] == (UChar
)(0x78)) {
562 log_verbose("WARNING: The locale %s is experimental! It shouldn't be listed as an installed locale.\n",
565 resolvedLoc
= ures_getLocaleByType(currentLocale
, ULOC_ACTUAL_LOCALE
, &errorCode
);
566 if (strcmp(resolvedLoc
, currLoc
) != 0 && strcmp(currLoc
, "ars") != 0) { /* ars IS an aliased locale */
567 /* All locales have at least a Version resource.
568 If it's absolutely empty, then the previous test will fail too.*/
569 log_err("Locale resolves to different locale. Is %s an alias of %s?\n",
570 currLoc
, resolvedLoc
);
572 TestKeyInRootRecursive(root
, "root", currentLocale
, currLoc
);
574 testLCID(currentLocale
, currLoc
);
576 ures_close(currentLocale
);
584 compareArrays(const char *keyName
,
585 UResourceBundle
*fromArray
, const char *fromLocale
,
586 UResourceBundle
*toArray
, const char *toLocale
,
587 int32_t start
, int32_t end
)
589 int32_t fromSize
= ures_getSize(fromArray
);
590 int32_t toSize
= ures_getSize(fromArray
);
592 UErrorCode errorCode
= U_ZERO_ERROR
;
594 if (fromSize
> toSize
) {
596 log_err("Arrays are different size from \"%s\" to \"%s\"\n",
601 for (idx
= start
; idx
<= end
; idx
++) {
602 const UChar
*fromBundleStr
= ures_getStringByIndex(fromArray
, idx
, NULL
, &errorCode
);
603 const UChar
*toBundleStr
= ures_getStringByIndex(toArray
, idx
, NULL
, &errorCode
);
604 if (fromBundleStr
&& toBundleStr
&& u_strcmp(fromBundleStr
, toBundleStr
) != 0)
606 log_err("Difference for %s at index %d from %s= \"%s\" to %s= \"%s\"\n",
610 austrdup(fromBundleStr
),
612 austrdup(toBundleStr
));
618 compareConsistentCountryInfo(const char *fromLocale
, const char *toLocale
) {
619 UErrorCode errorCode
= U_ZERO_ERROR
;
620 UResourceBundle
*fromArray
, *toArray
;
621 UResourceBundle
*fromLocaleBund
= ures_open(NULL
, fromLocale
, &errorCode
);
622 UResourceBundle
*toLocaleBund
= ures_open(NULL
, toLocale
, &errorCode
);
623 UResourceBundle
*toCalendar
, *fromCalendar
, *toGregorian
, *fromGregorian
;
625 if(U_FAILURE(errorCode
)) {
626 log_err("Can't open resource bundle %s or %s - %s\n", fromLocale
, toLocale
, u_errorName(errorCode
));
629 fromCalendar
= ures_getByKey(fromLocaleBund
, "calendar", NULL
, &errorCode
);
630 fromGregorian
= ures_getByKeyWithFallback(fromCalendar
, "gregorian", NULL
, &errorCode
);
632 toCalendar
= ures_getByKey(toLocaleBund
, "calendar", NULL
, &errorCode
);
633 toGregorian
= ures_getByKeyWithFallback(toCalendar
, "gregorian", NULL
, &errorCode
);
635 fromArray
= ures_getByKey(fromLocaleBund
, "CurrencyElements", NULL
, &errorCode
);
636 toArray
= ures_getByKey(toLocaleBund
, "CurrencyElements", NULL
, &errorCode
);
637 if (strcmp(fromLocale
, "en_CA") != 0)
639 /* The first one is probably localized. */
640 compareArrays("CurrencyElements", fromArray
, fromLocale
, toArray
, toLocale
, 1, 2);
642 ures_close(fromArray
);
645 fromArray
= ures_getByKey(fromLocaleBund
, "NumberPatterns", NULL
, &errorCode
);
646 toArray
= ures_getByKey(toLocaleBund
, "NumberPatterns", NULL
, &errorCode
);
647 if (strcmp(fromLocale
, "en_CA") != 0)
649 compareArrays("NumberPatterns", fromArray
, fromLocale
, toArray
, toLocale
, 0, 3);
651 ures_close(fromArray
);
654 /* Difficult to test properly */
656 fromArray = ures_getByKey(fromLocaleBund, "DateTimePatterns", NULL, &errorCode);
657 toArray = ures_getByKey(toLocaleBund, "DateTimePatterns", NULL, &errorCode);
659 compareArrays("DateTimePatterns", fromArray, fromLocale, toArray, toLocale);
661 ures_close(fromArray);
662 ures_close(toArray);*/
664 fromArray
= ures_getByKey(fromLocaleBund
, "NumberElements", NULL
, &errorCode
);
665 toArray
= ures_getByKey(toLocaleBund
, "NumberElements", NULL
, &errorCode
);
666 if (strcmp(fromLocale
, "en_CA") != 0)
668 compareArrays("NumberElements", fromArray
, fromLocale
, toArray
, toLocale
, 0, 3);
669 /* Index 4 is a script based 0 */
670 compareArrays("NumberElements", fromArray
, fromLocale
, toArray
, toLocale
, 5, 10);
672 ures_close(fromArray
);
674 ures_close(fromCalendar
);
675 ures_close(toCalendar
);
676 ures_close(fromGregorian
);
677 ures_close(toGregorian
);
679 ures_close(fromLocaleBund
);
680 ures_close(toLocaleBund
);
684 TestConsistentCountryInfo(void) {
685 /* UResourceBundle *fromLocale, *toLocale;*/
686 int32_t locCount
= uloc_countAvailable();
687 int32_t fromLocIndex
, toLocIndex
;
689 int32_t fromCountryLen
, toCountryLen
;
690 char fromCountry
[ULOC_FULLNAME_CAPACITY
], toCountry
[ULOC_FULLNAME_CAPACITY
];
692 int32_t fromVariantLen
, toVariantLen
;
693 char fromVariant
[ULOC_FULLNAME_CAPACITY
], toVariant
[ULOC_FULLNAME_CAPACITY
];
695 UErrorCode errorCode
= U_ZERO_ERROR
;
697 for (fromLocIndex
= 0; fromLocIndex
< locCount
; fromLocIndex
++) {
698 const char *fromLocale
= uloc_getAvailable(fromLocIndex
);
700 errorCode
=U_ZERO_ERROR
;
701 fromCountryLen
= uloc_getCountry(fromLocale
, fromCountry
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
702 if (fromCountryLen
<= 0) {
703 /* Ignore countryless locales */
706 fromVariantLen
= uloc_getVariant(fromLocale
, fromVariant
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
707 if (fromVariantLen
> 0) {
708 /* Most variants are ignorable like PREEURO, or collation variants. */
711 /* Start comparing only after the current index.
712 Previous loop should have already compared fromLocIndex.
714 for (toLocIndex
= fromLocIndex
+ 1; toLocIndex
< locCount
; toLocIndex
++) {
715 const char *toLocale
= uloc_getAvailable(toLocIndex
);
717 toCountryLen
= uloc_getCountry(toLocale
, toCountry
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
718 if(U_FAILURE(errorCode
)) {
719 log_err("Unknown failure fromLocale=%s toLocale=%s errorCode=%s\n",
720 fromLocale
, toLocale
, u_errorName(errorCode
));
724 if (toCountryLen
<= 0) {
725 /* Ignore countryless locales */
728 toVariantLen
= uloc_getVariant(toLocale
, toVariant
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
729 if (toVariantLen
> 0) {
730 /* Most variants are ignorable like PREEURO, or collation variants. */
731 /* They're a variant for a reason. */
734 if (strcmp(fromCountry
, toCountry
) == 0) {
735 log_verbose("comparing fromLocale=%s toLocale=%s\n",
736 fromLocale
, toLocale
);
737 compareConsistentCountryInfo(fromLocale
, toLocale
);
744 findStringSetMismatch(const char *currLoc
, const UChar
*string
, int32_t langSize
,
745 USet
* mergedExemplarSet
,
746 UBool ignoreNumbers
, UChar
* badCharPtr
) {
747 UErrorCode errorCode
= U_ZERO_ERROR
;
750 if (mergedExemplarSet
== NULL
) {
753 exemplarSet
= createFlattenSet(mergedExemplarSet
, &errorCode
);
754 if (U_FAILURE(errorCode
)) {
755 log_err("%s: error createFlattenSet returned %s\n", currLoc
, u_errorName(errorCode
));
759 for (strIdx
= 0; strIdx
< langSize
; strIdx
++) {
760 if (!uset_contains(exemplarSet
, string
[strIdx
])
761 && 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
762 && string
[strIdx
] != 0x200C && string
[strIdx
] != 0x200D) {
763 if (!ignoreNumbers
|| (ignoreNumbers
&& (string
[strIdx
] < 0x30 || string
[strIdx
] > 0x39))) {
764 uset_close(exemplarSet
);
766 *badCharPtr
= string
[strIdx
];
772 uset_close(exemplarSet
);
778 /* include non-invariant chars */
780 myUCharsToChars(const UChar
* us
, char* cs
, int32_t len
){
792 findSetMatch( UScriptCode
*scriptCodes
, int32_t scriptsLen
,
795 USet
*scripts
[10]= {0};
796 char pattern
[256] = { '[', ':', 0x000 };
798 UChar uPattern
[256] = {0};
799 UErrorCode status
= U_ZERO_ERROR
;
802 /* create the sets with script codes */
803 for(i
= 0; i
<scriptsLen
; i
++){
804 strcat(pattern
, uscript_getShortName(scriptCodes
[i
]));
805 strcat(pattern
, ":]");
806 patternLen
= (int32_t)strlen(pattern
);
807 u_charsToUChars(pattern
, uPattern
, patternLen
);
808 scripts
[i
] = uset_openPattern(uPattern
, patternLen
, &status
);
809 if(U_FAILURE(status
)){
810 log_err("Could not create set for pattern %s. Error: %s\n", pattern
, u_errorName(status
));
815 if (strcmp(locale
, "uk") == 0 || strcmp(locale
, "uk_UA") == 0) {
816 /* Special addition. Add the modifying apostrophe, which isn't in Cyrillic. */
817 uset_add(scripts
[0], 0x2bc);
819 if(U_SUCCESS(status
)){
820 UBool existsInScript
= FALSE
;
821 /* iterate over the exemplarSet and ascertain if all
822 * UChars in exemplarSet belong to the scripts returned
825 int32_t count
= uset_getItemCount(exemplarSet
);
827 for( i
=0; i
< count
; i
++){
831 int32_t strCapacity
= 0;
833 strCapacity
= uset_getItem(exemplarSet
, i
, &start
, &end
, str
, strCapacity
, &status
);
834 if(U_SUCCESS(status
)){
836 if(strCapacity
== 0){
837 /* ok the item is a range */
838 for( j
= 0; j
< scriptsLen
; j
++){
839 if(uset_containsRange(scripts
[j
], start
, end
) == TRUE
){
840 existsInScript
= TRUE
;
843 if(existsInScript
== FALSE
){
844 for( j
= 0; j
< scriptsLen
; j
++){
845 UChar toPattern
[500]={'\0'};
846 char pat
[500]={'\0'};
847 int32_t len
= uset_toPattern(scripts
[j
], toPattern
, 500, TRUE
, &status
);
848 len
= myUCharsToChars(toPattern
, pat
, len
);
849 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
));
851 log_err("Pattern: %s\n",pat
);
854 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale
);
857 strCapacity
++; /* increment for NUL termination */
858 /* allocate the str and call the api again */
859 str
= (UChar
*) malloc(U_SIZEOF_UCHAR
* strCapacity
);
860 strCapacity
= uset_getItem(exemplarSet
, i
, &start
, &end
, str
, strCapacity
, &status
);
861 /* iterate over the scripts and figure out if the string contained is actually
864 for( j
= 0; j
< scriptsLen
; j
++){
865 if(uset_containsString(scripts
[j
],str
, strCapacity
) == TRUE
){
866 existsInScript
= TRUE
;
869 if(existsInScript
== FALSE
){
870 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale
);
879 for(i
= 0; i
<scriptsLen
; i
++){
880 uset_close(scripts
[i
]);
884 static void VerifyTranslation(void) {
885 UResourceBundle
*root
, *currentLocale
;
886 int32_t locCount
= uloc_countAvailable();
888 UErrorCode errorCode
= U_ZERO_ERROR
;
890 UScriptCode scripts
[USCRIPT_CODE_LIMIT
];
894 UResourceBundle
*resArray
;
897 log_data_err("At least root needs to be installed\n");
900 root
= ures_openDirect(NULL
, "root", &errorCode
);
901 if(U_FAILURE(errorCode
)) {
902 log_data_err("Can't open root\n");
905 for (locIndex
= 0; locIndex
< locCount
; locIndex
++) {
906 USet
* mergedExemplarSet
= NULL
;
907 errorCode
=U_ZERO_ERROR
;
908 currLoc
= uloc_getAvailable(locIndex
);
909 currentLocale
= ures_open(NULL
, currLoc
, &errorCode
);
910 if(errorCode
!= U_ZERO_ERROR
) {
911 if(U_SUCCESS(errorCode
)) {
912 /* It's installed, but there is no data.
913 It's installed for the g18n white paper [grhoten] */
914 log_err("ERROR: Locale %-5s not installed, and it should be!\n",
915 uloc_getAvailable(locIndex
));
917 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
918 u_errorName(errorCode
),
919 uloc_getAvailable(locIndex
));
921 ures_close(currentLocale
);
925 UErrorCode exemplarStatus
= U_ZERO_ERROR
;
926 ULocaleData
* uld
= ulocdata_open(currLoc
, &exemplarStatus
);
927 if (U_SUCCESS(exemplarStatus
)) {
928 USet
* exemplarSet
= ulocdata_getExemplarSet(uld
, NULL
, USET_ADD_CASE_MAPPINGS
, ULOCDATA_ES_STANDARD
, &exemplarStatus
);
929 if (U_SUCCESS(exemplarStatus
)) {
930 mergedExemplarSet
= uset_cloneAsThawed(exemplarSet
);
931 uset_close(exemplarSet
);
932 exemplarSet
= ulocdata_getExemplarSet(uld
, NULL
, USET_ADD_CASE_MAPPINGS
, ULOCDATA_ES_AUXILIARY
, &exemplarStatus
);
933 if (U_SUCCESS(exemplarStatus
)) {
934 uset_addAll(mergedExemplarSet
, exemplarSet
);
935 uset_close(exemplarSet
);
937 exemplarStatus
= U_ZERO_ERROR
;
938 exemplarSet
= ulocdata_getExemplarSet(uld
, NULL
, 0, ULOCDATA_ES_PUNCTUATION
, &exemplarStatus
);
939 if (U_SUCCESS(exemplarStatus
)) {
940 uset_addAll(mergedExemplarSet
, exemplarSet
);
941 uset_close(exemplarSet
);
944 log_err("error ulocdata_getExemplarSet (main) for locale %s returned %s\n", currLoc
, u_errorName(errorCode
));
948 log_err("error ulocdata_open for locale %s returned %s\n", currLoc
, u_errorName(errorCode
));
951 if (mergedExemplarSet
== NULL
/*|| (getTestOption(QUICK_OPTION) && uset_size() > 2048)*/) {
952 log_verbose("skipping test for %s\n", currLoc
);
954 //else if (uprv_strncmp(currLoc,"bem",3) == 0 || uprv_strncmp(currLoc,"mgo",3) == 0 || uprv_strncmp(currLoc,"nl",2) == 0) {
955 // log_verbose("skipping test for %s, some month and country names known to use aux exemplars\n", currLoc);
958 UChar langBuffer
[128];
962 langSize
= uloc_getDisplayLanguage(currLoc
, currLoc
, langBuffer
, UPRV_LENGTHOF(langBuffer
), &errorCode
);
963 if (U_FAILURE(errorCode
)) {
964 log_err("error uloc_getDisplayLanguage returned %s\n", u_errorName(errorCode
));
967 strIdx
= findStringSetMismatch(currLoc
, langBuffer
, langSize
, mergedExemplarSet
, FALSE
, &badChar
);
970 log_err("getDisplayLanguage(%s) at index %d returned characters not in the exemplar characters: %04X in \"%s\"\n",
971 currLoc
, strIdx
, badChar
, u_austrncpy(bbuf
,langBuffer
,langSize
));
974 langSize
= uloc_getDisplayCountry(currLoc
, currLoc
, langBuffer
, UPRV_LENGTHOF(langBuffer
), &errorCode
);
975 if (U_FAILURE(errorCode
)) {
976 log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode
));
979 UResourceBundle
* cal
= ures_getByKey(currentLocale
, "calendar", NULL
, &errorCode
);
980 UResourceBundle
* greg
= ures_getByKeyWithFallback(cal
, "gregorian", NULL
, &errorCode
);
981 UResourceBundle
* names
= ures_getByKeyWithFallback(greg
, "dayNames", NULL
, &errorCode
);
982 UResourceBundle
* format
= ures_getByKeyWithFallback(names
, "format", NULL
, &errorCode
);
983 resArray
= ures_getByKeyWithFallback(format
, "wide", NULL
, &errorCode
);
985 if (U_FAILURE(errorCode
)) {
986 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode
));
988 if (getTestOption(QUICK_OPTION
)) {
992 end
= ures_getSize(resArray
);
995 if ((uprv_strncmp(currLoc
,"lrc",3) == 0 || uprv_strncmp(currLoc
,"mzn",3) == 0) &&
996 log_knownIssue("cldrbug:8899", "lrc and mzn locales don't have translated day names")) {
1000 for (idx
= 0; idx
< end
; idx
++) {
1001 const UChar
*fromBundleStr
= ures_getStringByIndex(resArray
, idx
, &langSize
, &errorCode
);
1002 if (U_FAILURE(errorCode
)) {
1003 log_err("error ures_getStringByIndex(%d) returned %s\n", idx
, u_errorName(errorCode
));
1006 strIdx
= findStringSetMismatch(currLoc
, fromBundleStr
, langSize
, mergedExemplarSet
, TRUE
, &badChar
);
1007 if ( strIdx
>= 0 ) {
1008 log_err("getDayNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1009 currLoc
, idx
, strIdx
, badChar
);
1012 ures_close(resArray
);
1016 names
= ures_getByKeyWithFallback(greg
, "monthNames", NULL
, &errorCode
);
1017 format
= ures_getByKeyWithFallback(names
,"format", NULL
, &errorCode
);
1018 resArray
= ures_getByKeyWithFallback(format
, "wide", NULL
, &errorCode
);
1019 if (U_FAILURE(errorCode
)) {
1020 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode
));
1022 if (getTestOption(QUICK_OPTION
)) {
1026 end
= ures_getSize(resArray
);
1029 for (idx
= 0; idx
< end
; idx
++) {
1030 const UChar
*fromBundleStr
= ures_getStringByIndex(resArray
, idx
, &langSize
, &errorCode
);
1031 if (U_FAILURE(errorCode
)) {
1032 log_err("error ures_getStringByIndex(%d) returned %s\n", idx
, u_errorName(errorCode
));
1035 strIdx
= findStringSetMismatch(currLoc
, fromBundleStr
, langSize
, mergedExemplarSet
, TRUE
, &badChar
);
1037 log_err("getMonthNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1038 currLoc
, idx
, strIdx
, badChar
);
1041 ures_close(resArray
);
1047 errorCode
= U_ZERO_ERROR
;
1048 numScripts
= uscript_getCode(currLoc
, scripts
, UPRV_LENGTHOF(scripts
), &errorCode
);
1049 if (strcmp(currLoc
, "yi") == 0 && numScripts
> 0 && log_knownIssue("11217", "Fix result of uscript_getCode for yi: USCRIPT_YI -> USCRIPT_HEBREW")) {
1050 scripts
[0] = USCRIPT_HEBREW
;
1052 if (numScripts
== 0) {
1053 log_err("uscript_getCode(%s) doesn't work.\n", currLoc
);
1054 }else if(scripts
[0] == USCRIPT_COMMON
){
1055 log_err("uscript_getCode(%s) returned USCRIPT_COMMON.\n", currLoc
);
1058 /* test that the scripts are a superset of exemplar characters. */
1060 ULocaleData
*uld
= ulocdata_open(currLoc
,&errorCode
);
1061 USet
*exemplarSet
= ulocdata_getExemplarSet(uld
, NULL
, 0, ULOCDATA_ES_STANDARD
, &errorCode
);
1062 /* test if exemplar characters are part of script code */
1063 findSetMatch(scripts
, numScripts
, exemplarSet
, currLoc
);
1064 uset_close(exemplarSet
);
1065 ulocdata_close(uld
);
1068 /* test that the paperSize API works */
1070 int32_t height
=0, width
=0;
1071 ulocdata_getPaperSize(currLoc
, &height
, &width
, &errorCode
);
1072 if(U_FAILURE(errorCode
)){
1073 log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc
, u_errorName(errorCode
));
1075 if(strstr(currLoc
, "_US")!=NULL
&& height
!= 279 && width
!= 216 ){
1076 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc
);
1079 /* test that the MeasurementSystem API works */
1081 char fullLoc
[ULOC_FULLNAME_CAPACITY
];
1082 UMeasurementSystem measurementSystem
;
1083 int32_t height
= 0, width
= 0;
1085 uloc_addLikelySubtags(currLoc
, fullLoc
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
1087 errorCode
= U_ZERO_ERROR
;
1088 measurementSystem
= ulocdata_getMeasurementSystem(currLoc
, &errorCode
);
1089 if (U_FAILURE(errorCode
)) {
1090 log_err("ulocdata_getMeasurementSystem failed for locale %s with error: %s \n", currLoc
, u_errorName(errorCode
));
1092 if ( strstr(fullLoc
, "_US")!=NULL
|| strstr(fullLoc
, "_MM")!=NULL
|| strstr(fullLoc
, "_LR")!=NULL
) {
1093 if(measurementSystem
!= UMS_US
){
1094 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc
);
1096 } else if ( strstr(fullLoc
, "_GB")!=NULL
) {
1097 if(measurementSystem
!= UMS_UK
){
1098 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc
);
1100 } else if (measurementSystem
!= UMS_SI
) {
1101 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc
);
1105 errorCode
= U_ZERO_ERROR
;
1106 ulocdata_getPaperSize(currLoc
, &height
, &width
, &errorCode
);
1107 if (U_FAILURE(errorCode
)) {
1108 log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc
, u_errorName(errorCode
));
1110 if ( strstr(fullLoc
, "_US")!=NULL
|| strstr(fullLoc
, "_BZ")!=NULL
|| strstr(fullLoc
, "_CA")!=NULL
|| strstr(fullLoc
, "_CL")!=NULL
||
1111 strstr(fullLoc
, "_CO")!=NULL
|| strstr(fullLoc
, "_CR")!=NULL
|| strstr(fullLoc
, "_GT")!=NULL
|| strstr(fullLoc
, "_MX")!=NULL
||
1112 strstr(fullLoc
, "_NI")!=NULL
|| strstr(fullLoc
, "_PA")!=NULL
|| strstr(fullLoc
, "_PH")!=NULL
|| strstr(fullLoc
, "_PR")!=NULL
||
1113 strstr(fullLoc
, "_SV")!=NULL
|| strstr(fullLoc
, "_VE")!=NULL
) {
1114 if (height
!= 279 || width
!= 216) {
1115 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc
);
1117 } else if (height
!= 297 || width
!= 210) {
1118 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc
);
1123 if (mergedExemplarSet
!= NULL
) {
1124 uset_close(mergedExemplarSet
);
1126 ures_close(currentLocale
);
1132 /* adjust this limit as appropriate */
1133 #define MAX_SCRIPTS_PER_LOCALE 8
1135 static void TestExemplarSet(void){
1136 int32_t i
, j
, k
, m
, n
;
1137 int32_t equalCount
= 0;
1138 UErrorCode ec
= U_ZERO_ERROR
;
1139 UEnumeration
* avail
;
1140 USet
* exemplarSets
[2];
1141 USet
* unassignedSet
;
1142 UScriptCode code
[MAX_SCRIPTS_PER_LOCALE
];
1143 USet
* codeSets
[MAX_SCRIPTS_PER_LOCALE
];
1145 char cbuf
[32]; /* 9 should be enough */
1146 UChar ubuf
[64]; /* adjust as needed */
1147 UBool existsInScript
;
1152 unassignedSet
= NULL
;
1153 exemplarSets
[0] = NULL
;
1154 exemplarSets
[1] = NULL
;
1155 for (i
=0; i
<MAX_SCRIPTS_PER_LOCALE
; ++i
) {
1159 avail
= ures_openAvailableLocales(NULL
, &ec
);
1160 if (!assertSuccess("ures_openAvailableLocales", &ec
)) goto END
;
1161 n
= uenum_count(avail
, &ec
);
1162 if (!assertSuccess("uenum_count", &ec
)) goto END
;
1164 u_uastrcpy(ubuf
, "[:unassigned:]");
1165 unassignedSet
= uset_openPattern(ubuf
, -1, &ec
);
1166 if (!assertSuccess("uset_openPattern", &ec
)) goto END
;
1169 const char* locale
= uenum_next(avail
, NULL
, &ec
);
1170 if (!assertSuccess("uenum_next", &ec
)) goto END
;
1171 log_verbose("%s\n", locale
);
1172 for (k
=0; k
<2; ++k
) {
1173 uint32_t option
= (k
==0) ? 0 : USET_CASE_INSENSITIVE
;
1174 ULocaleData
*uld
= ulocdata_open(locale
,&ec
);
1175 USet
* exemplarSet
= ulocdata_getExemplarSet(uld
,NULL
, option
, ULOCDATA_ES_STANDARD
, &ec
);
1176 uset_close(exemplarSets
[k
]);
1177 ulocdata_close(uld
);
1178 exemplarSets
[k
] = exemplarSet
;
1179 if (!assertSuccess("ulocaledata_getExemplarSet", &ec
)) goto END
;
1181 if (uset_containsSome(exemplarSet
, unassignedSet
)) {
1182 log_err("ExemplarSet contains unassigned characters for locale : %s\n", locale
);
1184 codeLen
= uscript_getCode(locale
, code
, 8, &ec
);
1185 if (strcmp(locale
, "yi") == 0 && codeLen
> 0 && log_knownIssue("11217", "Fix result of uscript_getCode for yi: USCRIPT_YI -> USCRIPT_HEBREW")) {
1186 code
[0] = USCRIPT_HEBREW
;
1188 if (!assertSuccess("uscript_getCode", &ec
)) goto END
;
1190 for (j
=0; j
<MAX_SCRIPTS_PER_LOCALE
; ++j
) {
1191 uset_close(codeSets
[j
]);
1194 for (j
=0; j
<codeLen
; ++j
) {
1195 uprv_strcpy(cbuf
, "[:");
1197 log_err("USCRIPT_INVALID_CODE returned for locale: %s\n", locale
);
1200 uprv_strcat(cbuf
, uscript_getShortName(code
[j
]));
1201 uprv_strcat(cbuf
, ":]");
1202 u_uastrcpy(ubuf
, cbuf
);
1203 codeSets
[j
] = uset_openPattern(ubuf
, -1, &ec
);
1205 if (!assertSuccess("uset_openPattern", &ec
)) goto END
;
1207 existsInScript
= FALSE
;
1208 itemCount
= uset_getItemCount(exemplarSet
);
1209 for (m
=0; m
<itemCount
&& !existsInScript
; ++m
) {
1210 strLen
= uset_getItem(exemplarSet
, m
, &start
, &end
, ubuf
,
1211 UPRV_LENGTHOF(ubuf
), &ec
);
1212 /* failure here might mean str[] needs to be larger */
1213 if (!assertSuccess("uset_getItem", &ec
)) goto END
;
1215 for (j
=0; j
<codeLen
; ++j
) {
1216 if (codeSets
[j
]!=NULL
&& uset_containsRange(codeSets
[j
], start
, end
)) {
1217 existsInScript
= TRUE
;
1222 for (j
=0; j
<codeLen
; ++j
) {
1223 if (codeSets
[j
]!=NULL
&& uset_containsString(codeSets
[j
], ubuf
, strLen
)) {
1224 existsInScript
= TRUE
;
1231 if (existsInScript
== FALSE
){
1232 log_err("ExemplarSet containment failed for locale : %s\n", locale
);
1235 assertTrue("case-folded is a superset",
1236 uset_containsAll(exemplarSets
[1], exemplarSets
[0]));
1237 if (uset_equals(exemplarSets
[1], exemplarSets
[0])) {
1241 /* Note: The case-folded set should sometimes be a strict superset
1242 and sometimes be equal. */
1243 assertTrue("case-folded is sometimes a strict superset, and sometimes equal",
1244 equalCount
> 0 && equalCount
< n
);
1248 uset_close(exemplarSets
[0]);
1249 uset_close(exemplarSets
[1]);
1250 uset_close(unassignedSet
);
1251 for (i
=0; i
<MAX_SCRIPTS_PER_LOCALE
; ++i
) {
1252 uset_close(codeSets
[i
]);
1256 enum { kUBufMax
= 32 };
1257 static void TestLocaleDisplayPattern(void){
1259 UChar pattern
[kUBufMax
] = {0,};
1260 UChar separator
[kUBufMax
] = {0,};
1262 static const UChar enExpectPat
[] = { 0x007B,0x0030,0x007D,0x0020,0x0028,0x007B,0x0031,0x007D,0x0029,0 }; /* "{0} ({1})" */
1263 static const UChar enExpectSep
[] = { 0x002C,0x0020,0 }; /* ", " */
1264 static const UChar zhExpectPat
[] = { 0x007B,0x0030,0x007D,0xFF08,0x007B,0x0031,0x007D,0xFF09,0 };
1265 static const UChar zhExpectSep
[] = { 0xFF0C,0 };
1267 status
= U_ZERO_ERROR
;
1268 uld
= ulocdata_open("en", &status
);
1269 if(U_FAILURE(status
)){
1270 log_data_err("ulocdata_open en error %s", u_errorName(status
));
1272 ulocdata_getLocaleDisplayPattern(uld
, pattern
, kUBufMax
, &status
);
1273 if (U_FAILURE(status
)){
1274 log_err("ulocdata_getLocaleDisplayPattern en error %s", u_errorName(status
));
1275 } else if (u_strcmp(pattern
, enExpectPat
) != 0) {
1276 log_err("ulocdata_getLocaleDisplayPattern en returns unexpected pattern");
1278 status
= U_ZERO_ERROR
;
1279 ulocdata_getLocaleSeparator(uld
, separator
, kUBufMax
, &status
);
1280 if (U_FAILURE(status
)){
1281 log_err("ulocdata_getLocaleSeparator en error %s", u_errorName(status
));
1282 } else if (u_strcmp(separator
, enExpectSep
) != 0) {
1283 log_err("ulocdata_getLocaleSeparator en returns unexpected string ");
1285 ulocdata_close(uld
);
1288 status
= U_ZERO_ERROR
;
1289 uld
= ulocdata_open("zh", &status
);
1290 if(U_FAILURE(status
)){
1291 log_data_err("ulocdata_open zh error %s", u_errorName(status
));
1293 ulocdata_getLocaleDisplayPattern(uld
, pattern
, kUBufMax
, &status
);
1294 if (U_FAILURE(status
)){
1295 log_err("ulocdata_getLocaleDisplayPattern zh error %s", u_errorName(status
));
1296 } else if (u_strcmp(pattern
, zhExpectPat
) != 0) {
1297 log_err("ulocdata_getLocaleDisplayPattern zh returns unexpected pattern");
1299 status
= U_ZERO_ERROR
;
1300 ulocdata_getLocaleSeparator(uld
, separator
, kUBufMax
, &status
);
1301 if (U_FAILURE(status
)){
1302 log_err("ulocdata_getLocaleSeparator zh error %s", u_errorName(status
));
1303 } else if (u_strcmp(separator
, zhExpectSep
) != 0) {
1304 log_err("ulocdata_getLocaleSeparator zh returns unexpected string ");
1306 ulocdata_close(uld
);
1310 static void TestCoverage(void){
1311 ULocaleDataDelimiterType types
[] = {
1312 ULOCDATA_QUOTATION_START
, /* Quotation start */
1313 ULOCDATA_QUOTATION_END
, /* Quotation end */
1314 ULOCDATA_ALT_QUOTATION_START
, /* Alternate quotation start */
1315 ULOCDATA_ALT_QUOTATION_END
, /* Alternate quotation end */
1316 ULOCDATA_DELIMITER_COUNT
1320 UErrorCode status
= U_ZERO_ERROR
;
1321 ULocaleData
*uld
= ulocdata_open(uloc_getDefault(), &status
);
1323 if(U_FAILURE(status
)){
1324 log_data_err("ulocdata_open error");
1329 for(i
= 0; i
< ULOCDATA_DELIMITER_COUNT
; i
++){
1330 UChar result
[32] = {0,};
1331 status
= U_ZERO_ERROR
;
1332 ulocdata_getDelimiter(uld
, types
[i
], result
, 32, &status
);
1333 if (U_FAILURE(status
)){
1334 log_err("ulocdata_getgetDelimiter error with type %d", types
[i
]);
1338 sub
= ulocdata_getNoSubstitute(uld
);
1339 ulocdata_setNoSubstitute(uld
,sub
);
1340 ulocdata_close(uld
);
1343 static void TestIndexChars(void) {
1344 /* Very basic test of ULOCDATA_ES_INDEX.
1345 * No comprehensive test of data, just basic check that the code path is alive.
1347 UErrorCode status
= U_ZERO_ERROR
;
1349 USet
*exemplarChars
;
1352 uld
= ulocdata_open("en", &status
);
1353 exemplarChars
= uset_openEmpty();
1354 indexChars
= uset_openEmpty();
1355 ulocdata_getExemplarSet(uld
, exemplarChars
, 0, ULOCDATA_ES_STANDARD
, &status
);
1356 ulocdata_getExemplarSet(uld
, indexChars
, 0, ULOCDATA_ES_INDEX
, &status
);
1357 if (U_FAILURE(status
)) {
1358 log_data_err("File %s, line %d, Failure opening exemplar chars: %s", __FILE__
, __LINE__
, u_errorName(status
));
1361 /* en data, standard exemplars are [a-z], lower case. */
1362 /* en data, index characters are [A-Z], upper case. */
1363 if ((uset_contains(exemplarChars
, (UChar32
)0x41) || uset_contains(indexChars
, (UChar32
)0x61))) {
1364 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__
, __LINE__
);
1367 if (!(uset_contains(exemplarChars
, (UChar32
)0x61) && uset_contains(indexChars
, (UChar32
)0x41) )) {
1368 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__
, __LINE__
);
1373 uset_close(exemplarChars
);
1374 uset_close(indexChars
);
1375 ulocdata_close(uld
);
1380 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1381 static void TestCurrencyList(void){
1382 #if !UCONFIG_NO_FORMATTING
1383 UErrorCode errorCode
= U_ZERO_ERROR
;
1384 int32_t structLocaleCount
, currencyCount
;
1385 UEnumeration
*en
= ucurr_openISOCurrencies(UCURR_ALL
, &errorCode
);
1386 const char *isoCode
, *structISOCode
;
1387 UResourceBundle
*subBundle
;
1388 UResourceBundle
*currencies
= ures_openDirect(loadTestData(&errorCode
), "structLocale", &errorCode
);
1389 if(U_FAILURE(errorCode
)) {
1390 log_data_err("Can't open structLocale\n");
1393 currencies
= ures_getByKey(currencies
, "Currencies", currencies
, &errorCode
);
1394 currencyCount
= uenum_count(en
, &errorCode
);
1395 structLocaleCount
= ures_getSize(currencies
);
1396 if (currencyCount
!= structLocaleCount
) {
1397 log_err("structLocale(%d) and ISO4217(%d) currency list are out of sync.\n", structLocaleCount
, currencyCount
);
1398 #if U_CHARSET_FAMILY == U_ASCII_FAMILY
1399 ures_resetIterator(currencies
);
1400 while ((isoCode
= uenum_next(en
, NULL
, &errorCode
)) != NULL
&& ures_hasNext(currencies
)) {
1401 subBundle
= ures_getNextResource(currencies
, NULL
, &errorCode
);
1402 structISOCode
= ures_getKey(subBundle
);
1403 ures_close(subBundle
);
1404 if (strcmp(structISOCode
, isoCode
) != 0) {
1405 log_err("First difference found at structLocale(%s) and ISO4217(%s).\n", structISOCode
, isoCode
);
1411 ures_close(currencies
);
1417 static void TestAvailableIsoCodes(void){
1418 #if !UCONFIG_NO_FORMATTING
1419 UErrorCode errorCode
= U_ZERO_ERROR
;
1420 const char* eurCode
= "EUR";
1421 const char* usdCode
= "USD";
1422 const char* lastCode
= "RHD";
1423 const char* zzzCode
= "ZZZ";
1424 UDate date1950
= (UDate
)-630720000000.0;/* year 1950 */
1425 UDate date1970
= (UDate
)0.0; /* year 1970 */
1426 UDate date1975
= (UDate
)173448000000.0; /* year 1975 */
1427 UDate date1978
= (UDate
)260172000000.0; /* year 1978 */
1428 UDate date1981
= (UDate
)346896000000.0; /* year 1981 */
1429 UDate date1992
= (UDate
)693792000000.0; /* year 1992 */
1430 UChar
* isoCode
= (UChar
*)malloc(sizeof(UChar
) * (uprv_strlen(usdCode
) + 1));
1432 /* testing available codes with no time ranges */
1433 u_charsToUChars(eurCode
, isoCode
, uprv_strlen(usdCode
) + 1);
1434 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1435 log_data_err("FAIL: ISO code (%s) is not found.\n", eurCode
);
1438 u_charsToUChars(usdCode
, isoCode
, uprv_strlen(zzzCode
) + 1);
1439 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1440 log_data_err("FAIL: ISO code (%s) is not found.\n", usdCode
);
1443 u_charsToUChars(zzzCode
, isoCode
, uprv_strlen(zzzCode
) + 1);
1444 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == TRUE
) {
1445 log_err("FAIL: ISO code (%s) is reported as available, but it doesn't exist.\n", zzzCode
);
1448 u_charsToUChars(lastCode
, isoCode
, uprv_strlen(zzzCode
) + 1);
1449 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1450 log_data_err("FAIL: ISO code (%s) is not found.\n", lastCode
);
1453 /* RHD was used from 1970-02-17 to 1980-04-18*/
1456 if (ucurr_isAvailable(isoCode
, date1970
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1457 log_data_err("FAIL: ISO code (%s) was available in time range >1970-01-01.\n", lastCode
);
1460 if (ucurr_isAvailable(isoCode
, date1975
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1461 log_data_err("FAIL: ISO code (%s) was available in time range >1975.\n", lastCode
);
1464 if (ucurr_isAvailable(isoCode
, date1981
, U_DATE_MAX
, &errorCode
) == TRUE
) {
1465 log_err("FAIL: ISO code (%s) was not available in time range >1981.\n", lastCode
);
1469 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1970
, &errorCode
) == TRUE
) {
1470 log_err("FAIL: ISO code (%s) was not available in time range <1970.\n", lastCode
);
1473 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1975
, &errorCode
) == FALSE
) {
1474 log_data_err("FAIL: ISO code (%s) was available in time range <1975.\n", lastCode
);
1477 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1981
, &errorCode
) == FALSE
) {
1478 log_data_err("FAIL: ISO code (%s) was available in time range <1981.\n", lastCode
);
1482 if (ucurr_isAvailable(isoCode
, date1975
, date1978
, &errorCode
) == FALSE
) {
1483 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1978.\n", lastCode
);
1486 if (ucurr_isAvailable(isoCode
, date1970
, date1975
, &errorCode
) == FALSE
) {
1487 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1975.\n", lastCode
);
1490 if (ucurr_isAvailable(isoCode
, date1975
, date1981
, &errorCode
) == FALSE
) {
1491 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1981.\n", lastCode
);
1494 if (ucurr_isAvailable(isoCode
, date1970
, date1981
, &errorCode
) == FALSE
) {
1495 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1981.\n", lastCode
);
1498 if (ucurr_isAvailable(isoCode
, date1981
, date1992
, &errorCode
) == TRUE
) {
1499 log_err("FAIL: ISO code (%s) was not available in time range 1981-1992.\n", lastCode
);
1502 if (ucurr_isAvailable(isoCode
, date1950
, date1970
, &errorCode
) == TRUE
) {
1503 log_err("FAIL: ISO code (%s) was not available in time range 1950-1970.\n", lastCode
);
1506 /* wrong range - from > to*/
1507 if (ucurr_isAvailable(isoCode
, date1975
, date1970
, &errorCode
) == TRUE
) {
1508 log_err("FAIL: Wrong range 1975-1970 for ISO code (%s) was not reported.\n", lastCode
);
1509 } else if (errorCode
!= U_ILLEGAL_ARGUMENT_ERROR
) {
1510 log_data_err("FAIL: Error code not reported for wrong range 1975-1970 for ISO code (%s).\n", lastCode
);
1517 #define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name)
1519 void addCLDRTest(TestNode
** root
);
1521 void addCLDRTest(TestNode
** root
)
1523 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1524 TESTCASE(TestLocaleStructure
);
1525 TESTCASE(TestCurrencyList
);
1527 TESTCASE(TestConsistentCountryInfo
);
1528 TESTCASE(VerifyTranslation
);
1529 TESTCASE(TestExemplarSet
);
1530 TESTCASE(TestLocaleDisplayPattern
);
1531 TESTCASE(TestCoverage
);
1532 TESTCASE(TestIndexChars
);
1533 TESTCASE(TestAvailableIsoCodes
);