X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/57a6839dcb3bba09e8228b822b290604668416fe..5ea0322b6ab2af986e4c764284141380031dd014:/icuSources/test/cintltst/capitst.c diff --git a/icuSources/test/cintltst/capitst.c b/icuSources/test/cintltst/capitst.c index 693a6c91..56f3275b 100644 --- a/icuSources/test/cintltst/capitst.c +++ b/icuSources/test/cintltst/capitst.c @@ -1,5 +1,5 @@ /******************************************************************** - * Copyright (c) 1997-2014, International Business Machines + * Copyright (c) 1997-2016, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************/ /***************************************************************************** @@ -33,8 +33,6 @@ #include "cstring.h" #include "ucol_imp.h" -#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) - static void TestAttribute(void); static void TestDefault(void); static void TestDefaultKeyword(void); @@ -117,7 +115,7 @@ void TestGetSetAttr(void) { log_err_status(status, "Unable to open collator. %s\n", u_errorName(status)); return; } - for(i = 0; i 0) { @@ -1837,7 +1859,7 @@ void TestGetTailoredSet() { int32_t buffLen = 0; USet *set = NULL; - for(i = 0; i < LENGTHOF(setTest); i++) { + for(i = 0; i < UPRV_LENGTHOF(setTest); i++) { buffLen = u_unescape(setTest[i].rules, buff, 1024); coll = ucol_openRules(buff, buffLen, UCOL_DEFAULT, UCOL_DEFAULT, &pError, &status); if(U_SUCCESS(status)) { @@ -1882,7 +1904,7 @@ void TestMergeSortKeys(void) { "abcd", "abcde" }; - uint32_t casesSize = sizeof(cases)/sizeof(cases[0]); + uint32_t casesSize = UPRV_LENGTHOF(cases); const char* prefix = "foo"; const char* suffix = "egg"; char outBuff1[256], outBuff2[256]; @@ -2039,7 +2061,7 @@ static void TestShortString(void) const char* locale = NULL; - for(i = 0; i < sizeof(testCases)/sizeof(testCases[0]); i++) { + for(i = 0; i < UPRV_LENGTHOF(testCases); i++) { status = U_ZERO_ERROR; if(testCases[i].locale) { locale = testCases[i].locale; @@ -2105,9 +2127,9 @@ doSetsTest(const char *locale, const USet *ref, USet *set, const char* inSet, co if(!uset_containsAll(ref, set)) { log_err("%s: Some stuff from %s is not present in the set\n", locale, inSet); uset_removeAll(set, ref); - bufLen = uset_toPattern(set, buffer, LENGTHOF(buffer), TRUE, status); + bufLen = uset_toPattern(set, buffer, UPRV_LENGTHOF(buffer), TRUE, status); log_info(" missing: %s\n", aescstrdup(buffer, bufLen)); - bufLen = uset_toPattern(ref, buffer, LENGTHOF(buffer), TRUE, status); + bufLen = uset_toPattern(ref, buffer, UPRV_LENGTHOF(buffer), TRUE, status); log_info(" total: size=%i %s\n", uset_getItemCount(ref), aescstrdup(buffer, bufLen)); } @@ -2195,7 +2217,7 @@ TestGetContractionsAndUnsafes(void) UChar buffer[65536]; int32_t setLen = 0; - for(i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) { + for(i = 0; i < UPRV_LENGTHOF(tests); i++) { log_verbose("Testing locale: %s\n", tests[i].locale); coll = ucol_open(tests[i].locale, &status); if (coll == NULL || U_FAILURE(status)) { @@ -2310,11 +2332,11 @@ TestOpenBinary(void) } #endif - genericOrderingTest(coll, wUCA, sizeof(wUCA)/sizeof(wUCA[0])); + genericOrderingTest(coll, wUCA, UPRV_LENGTHOF(wUCA)); - genericOrderingTest(cloneWUCA, wUCA, sizeof(wUCA)/sizeof(wUCA[0])); + genericOrderingTest(cloneWUCA, wUCA, UPRV_LENGTHOF(wUCA)); #if OPEN_BINARY_ACCEPTS_NULL_BASE - genericOrderingTest(cloneNOUCA, noUCA, sizeof(noUCA)/sizeof(noUCA[0])); + genericOrderingTest(cloneNOUCA, noUCA, UPRV_LENGTHOF(noUCA)); #endif if(image != imageBuffer) { @@ -2366,53 +2388,47 @@ static void TestDefaultKeyword(void) { ucol_close(coll); } +static UBool uenum_contains(UEnumeration *e, const char *s, UErrorCode *status) { + const char *t; + uenum_reset(e, status); + while(((t = uenum_next(e, NULL, status)) != NULL) && U_SUCCESS(*status)) { + if(uprv_strcmp(s, t) == 0) { + return TRUE; + } + } + return FALSE; +} + static void TestGetKeywordValuesForLocale(void) { -#define INCLUDE_UNIHAN_COLLATION 1 -#define PREFERRED_SIZE 16 #define MAX_NUMBER_OF_KEYWORDS 9 - const char *PREFERRED[PREFERRED_SIZE][MAX_NUMBER_OF_KEYWORDS+1] = { + const char *PREFERRED[][MAX_NUMBER_OF_KEYWORDS+1] = { { "und", "standard", "eor", "search", NULL, NULL, NULL, NULL, NULL, NULL }, { "en_US", "standard", "eor", "search", NULL, NULL, NULL, NULL, NULL, NULL }, { "en_029", "standard", "eor", "search", NULL, NULL, NULL, NULL, NULL, NULL }, { "de_DE", "standard", "phonebook", "search", "eor", NULL, NULL, NULL, NULL, NULL }, { "de_Latn_DE", "standard", "phonebook", "search", "eor", NULL, NULL, NULL, NULL, NULL }, -#if INCLUDE_UNIHAN_COLLATION - { "zh", "pinyin", "big5han", "gb2312han", "stroke", "unihan", "zhuyin", "eor", "search", "standard" }, - { "zh_Hans", "pinyin", "big5han", "gb2312han", "stroke", "unihan", "zhuyin", "eor", "search", "standard" }, - { "zh_CN", "pinyin", "big5han", "gb2312han", "stroke", "unihan", "zhuyin", "eor", "search", "standard" }, - { "zh_Hant", "stroke", "big5han", "gb2312han", "pinyin", "unihan", "zhuyin", "eor", "search", "standard" }, - { "zh_TW", "stroke", "big5han", "gb2312han", "pinyin", "unihan", "zhuyin", "eor", "search", "standard" }, - { "zh__PINYIN", "pinyin", "big5han", "gb2312han", "stroke", "unihan", "zhuyin", "eor", "search", "standard" }, -#else - { "zh", "pinyin", "big5han", "gb2312han", "stroke", "zhuyin", "eor", "search", "standard", NULL }, - { "zh_Hans", "pinyin", "big5han", "gb2312han", "stroke", "zhuyin", "eor", "search", "standard", NULL }, - { "zh_CN", "pinyin", "big5han", "gb2312han", "stroke", "zhuyin", "eor", "search", "standard", NULL }, - { "zh_Hant", "stroke", "big5han", "gb2312han", "pinyin", "zhuyin", "eor", "search", "standard", NULL }, - { "zh_TW", "stroke", "big5han", "gb2312han", "pinyin", "zhuyin", "eor", "search", "standard", NULL }, - { "zh__PINYIN", "pinyin", "big5han", "gb2312han", "stroke", "zhuyin", "eor", "search", "standard", NULL }, -#endif + { "zh", "pinyin", "stroke", "eor", "search", "standard", NULL }, + { "zh_Hans", "pinyin", "stroke", "eor", "search", "standard", NULL }, + { "zh_CN", "pinyin", "stroke", "eor", "search", "standard", NULL }, + { "zh_Hant", "stroke", "pinyin", "eor", "search", "standard", NULL }, + { "zh_TW", "stroke", "pinyin", "eor", "search", "standard", NULL }, + { "zh__PINYIN", "pinyin", "stroke", "eor", "search", "standard", NULL }, { "es_ES", "standard", "search", "traditional", "eor", NULL, NULL, NULL, NULL, NULL }, { "es__TRADITIONAL","traditional", "search", "standard", "eor", NULL, NULL, NULL, NULL, NULL }, { "und@collation=phonebook", "standard", "eor", "search", NULL, NULL, NULL, NULL, NULL, NULL }, - { "de_DE@collation=big5han", "standard", "phonebook", "search", "eor", NULL, NULL, NULL, NULL, NULL }, + { "de_DE@collation=pinyin", "standard", "phonebook", "search", "eor", NULL, NULL, NULL, NULL, NULL }, { "zzz@collation=xxx", "standard", "eor", "search", NULL, NULL, NULL, NULL, NULL, NULL } }; -#if INCLUDE_UNIHAN_COLLATION - const int32_t expectedLength[PREFERRED_SIZE] = { 3, 3, 3, 4, 4, 9, 9, 9, 9, 9, 9, 4, 4, 3, 4, 3 }; -#else - const int32_t expectedLength[PREFERRED_SIZE] = { 3, 3, 3, 4, 4, 8, 8, 8, 8, 8, 8, 4, 4, 3, 4, 3 }; -#endif UErrorCode status = U_ZERO_ERROR; UEnumeration *keywordValues = NULL; - int32_t i, n, size, valueLength; + int32_t i, n, size; const char *locale = NULL, *value = NULL; UBool errorOccurred = FALSE; - for (i = 0; i < PREFERRED_SIZE; i++) { + for (i = 0; i < UPRV_LENGTHOF(PREFERRED) && !errorOccurred; i++) { locale = PREFERRED[i][0]; value = NULL; - valueLength = 0; size = 0; keywordValues = ucol_getKeywordValuesForLocale("collation", locale, TRUE, &status); @@ -2421,35 +2437,23 @@ static void TestGetKeywordValuesForLocale(void) { break; } size = uenum_count(keywordValues, &status); + (void)size; - if (size == expectedLength[i]) { - for (n = 0; n < expectedLength[i]; n++) { - if ((value = uenum_next(keywordValues, &valueLength, &status)) != NULL && U_SUCCESS(status)) { - if (uprv_strcmp(value, PREFERRED[i][n+1]) != 0) { - log_err("Keyword values differ: Got [%s] Expected [%s] for locale: %s\n", value, PREFERRED[i][n+1], locale); - errorOccurred = TRUE; - break; - } - + for (n = 0; (value = PREFERRED[i][n+1]) != NULL; n++) { + if (!uenum_contains(keywordValues, value, &status)) { + if (U_SUCCESS(status)) { + log_err("Keyword value \"%s\" missing for locale: %s\n", value, locale); } else { log_err("While getting keyword value from locale: %s got this error: %s\n", locale, u_errorName(status)); errorOccurred = TRUE; break; } } - if (errorOccurred) { - break; - } - } else { - log_err("Number of keywords (%d) does not match expected size (%d) for locale: %s\n", size, expectedLength[i], locale); - break; } uenum_close(keywordValues); keywordValues = NULL; } - if (keywordValues != NULL) { - uenum_close(keywordValues); - } + uenum_close(keywordValues); } static void TestStrcollNull(void) {