+
+static void TestIsRightToLeft() {
+ // API test only. More test cases in intltest/LocaleTest.
+ if(uloc_isRightToLeft("root") || !uloc_isRightToLeft("EN-HEBR")) {
+ log_err("uloc_isRightToLeft() failed");
+ }
+}
+
+typedef struct {
+ const char * badLocaleID;
+ const char * displayLocale;
+ const char * expectedName;
+ UErrorCode expectedStatus;
+} BadLocaleItem;
+
+static const BadLocaleItem badLocaleItems[] = {
+ { "-9223372036854775808", "en", "9223372036854775808", U_USING_DEFAULT_WARNING },
+ /* add more in the future */
+ { NULL, NULL, NULL, U_ZERO_ERROR } /* terminator */
+};
+
+enum { kUBufDispNameMax = 128, kBBufDispNameMax = 256 };
+
+static void TestBadLocaleIDs() {
+ const BadLocaleItem* itemPtr;
+ for (itemPtr = badLocaleItems; itemPtr->badLocaleID != NULL; itemPtr++) {
+ UChar ubufExpect[kUBufDispNameMax], ubufGet[kUBufDispNameMax];
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t ulenExpect = u_unescape(itemPtr->expectedName, ubufExpect, kUBufDispNameMax);
+ int32_t ulenGet = uloc_getDisplayName(itemPtr->badLocaleID, itemPtr->displayLocale, ubufGet, kUBufDispNameMax, &status);
+ if (status != itemPtr->expectedStatus ||
+ (U_SUCCESS(status) && (ulenGet != ulenExpect || u_strncmp(ubufGet, ubufExpect, ulenExpect) != 0))) {
+ char bbufExpect[kBBufDispNameMax], bbufGet[kBBufDispNameMax];
+ u_austrncpy(bbufExpect, ubufExpect, ulenExpect);
+ u_austrncpy(bbufGet, ubufGet, ulenGet);
+ log_err("FAIL: For localeID %s, displayLocale %s, calling uloc_getDisplayName:\n"
+ " expected status %-26s, name (len %2d): %s\n"
+ " got status %-26s, name (len %2d): %s\n",
+ itemPtr->badLocaleID, itemPtr->displayLocale,
+ u_errorName(itemPtr->expectedStatus), ulenExpect, bbufExpect,
+ u_errorName(status), ulenGet, bbufGet );
+ }
+ }
+}
+
+typedef enum UldnNameType {
+ TEST_ULDN_LOCALE,
+ TEST_ULDN_LANGUAGE,
+ TEST_ULDN_SCRIPT,
+ TEST_ULDN_REGION,
+} UldnNameType;
+
+typedef struct {
+ const char * localeToName; // NULL to terminate a list of these
+ UldnNameType nameType;
+ const char * expectResult;
+} UldnItem;
+
+typedef struct {
+ const char * displayLocale;
+ const UDisplayContext * displayOptions; // set of 3 UDisplayContext items
+ const UldnItem * testItems;
+ int32_t countItems;
+} UldnLocAndOpts;
+
+static const UDisplayContext optStdMidLong[3] = {UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDISPCTX_LENGTH_FULL};
+static const UDisplayContext optStdMidShrt[3] = {UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDISPCTX_LENGTH_SHORT};
+static const UDisplayContext optDiaMidLong[3] = {UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDISPCTX_LENGTH_FULL};
+static const UDisplayContext optDiaMidShrt[3] = {UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDISPCTX_LENGTH_SHORT};
+
+static const UDisplayContext optStdBegLong[3] = {UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL};
+static const UDisplayContext optStdBegShrt[3] = {UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_SHORT};
+static const UDisplayContext optDiaBegLong[3] = {UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL};
+static const UDisplayContext optDiaBegShrt[3] = {UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_SHORT};
+
+static const UDisplayContext optStdLstLong[3] = {UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UDISPCTX_LENGTH_FULL};
+static const UDisplayContext optStdLstShrt[3] = {UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UDISPCTX_LENGTH_SHORT};
+static const UDisplayContext optDiaLstLong[3] = {UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UDISPCTX_LENGTH_FULL};
+static const UDisplayContext optDiaLstShrt[3] = {UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UDISPCTX_LENGTH_SHORT};
+
+static const UldnItem en_StdMidLong[] = {
+ { "en_US", TEST_ULDN_LOCALE, "English (US)" },
+ { "en_US_POSIX", TEST_ULDN_LOCALE, "English (US, Computer)" },
+ { "en_US@calendar=chinese", TEST_ULDN_LOCALE, "English (US, Chinese Calendar)" },
+ { "en_CA", TEST_ULDN_LOCALE, "English (Canada)" },
+ { "pt", TEST_ULDN_LOCALE, "Portuguese" },
+ { "pt_BR", TEST_ULDN_LOCALE, "Portuguese (Brazil)" },
+ { "pt_PT", TEST_ULDN_LOCALE, "Portuguese (Portugal)" },
+ { "zh_Hans", TEST_ULDN_LOCALE, "Chinese (Simplified)" },
+ { "zh_Hant_HK", TEST_ULDN_LOCALE, "Chinese (Traditional, Hong Kong)" },
+ { "zh_HK", TEST_ULDN_LOCALE, "Chinese (Hong Kong)" },
+ { "Latn", TEST_ULDN_SCRIPT, "Latin" },
+ { "Hans", TEST_ULDN_SCRIPT, "Simplified Han" },
+ { "Hant", TEST_ULDN_SCRIPT, "Traditional Han" },
+ { "US", TEST_ULDN_REGION, "United States" },
+ { "CA", TEST_ULDN_REGION, "Canada" },
+ { "GB", TEST_ULDN_REGION, "United Kingdom" },
+ { "HK", TEST_ULDN_REGION, "Hong Kong (China)" },
+};
+
+static const UldnItem en_StdMidShrt[] = {
+ { "en_US", TEST_ULDN_LOCALE, "English (US)" },
+ { "en_US_POSIX", TEST_ULDN_LOCALE, "English (US, Computer)" },
+ { "en_US@calendar=chinese", TEST_ULDN_LOCALE, "English (US, Calendar: chinese)" },
+ { "en_CA", TEST_ULDN_LOCALE, "English (Canada)" },
+ { "pt", TEST_ULDN_LOCALE, "Portuguese" },
+ { "pt_BR", TEST_ULDN_LOCALE, "Portuguese (Brazil)" },
+ { "pt_PT", TEST_ULDN_LOCALE, "Portuguese (Portugal)" },
+ { "zh_Hans", TEST_ULDN_LOCALE, "Chinese (Simplified)" },
+ { "zh_Hant_HK", TEST_ULDN_LOCALE, "Chinese (Traditional, Hong Kong)" },
+ { "zh_HK", TEST_ULDN_LOCALE, "Chinese (Hong Kong)" },
+ { "Latn", TEST_ULDN_SCRIPT, "Latin" },
+ { "Hans", TEST_ULDN_SCRIPT, "Simplified Han" },
+ { "Hant", TEST_ULDN_SCRIPT, "Traditional Han" },
+ { "US", TEST_ULDN_REGION, "US" },
+ { "CA", TEST_ULDN_REGION, "Canada" },
+ { "GB", TEST_ULDN_REGION, "UK" },
+ { "HK", TEST_ULDN_REGION, "Hong Kong" },
+};
+
+static const UldnItem en_DiaMidLong[] = {
+ { "en_US", TEST_ULDN_LOCALE, "American English" },
+ { "en_US_POSIX", TEST_ULDN_LOCALE, "American English (Computer)" },
+ { "en_US@calendar=chinese", TEST_ULDN_LOCALE, "American English (Chinese Calendar)" },
+ { "en_CA", TEST_ULDN_LOCALE, "Canadian English" },
+ { "pt", TEST_ULDN_LOCALE, "Portuguese" },
+ { "pt_BR", TEST_ULDN_LOCALE, "Brazilian Portuguese" },
+ { "pt_PT", TEST_ULDN_LOCALE, "European Portuguese" },
+ { "zh_Hans", TEST_ULDN_LOCALE, "Simplified Chinese" },
+ { "zh_Hant_HK", TEST_ULDN_LOCALE, "Traditional Chinese (Hong Kong)" },
+ { "zh_HK", TEST_ULDN_LOCALE, "Chinese (Hong Kong)" },
+ { "Latn", TEST_ULDN_SCRIPT, "Latin" },
+ { "Hans", TEST_ULDN_SCRIPT, "Simplified Han" },
+ { "Hant", TEST_ULDN_SCRIPT, "Traditional Han" },
+ { "US", TEST_ULDN_REGION, "United States" },
+ { "CA", TEST_ULDN_REGION, "Canada" },
+ { "GB", TEST_ULDN_REGION, "United Kingdom" },
+ { "HK", TEST_ULDN_REGION, "Hong Kong (China)" },
+};
+
+static const UldnItem en_DiaMidShrt[] = {
+ { "en_US", TEST_ULDN_LOCALE, "US English" },
+ { "en_US_POSIX", TEST_ULDN_LOCALE, "US English (Computer)" },
+ { "en_US@calendar=chinese", TEST_ULDN_LOCALE, "US English (Calendar: chinese)" },
+ { "en_CA", TEST_ULDN_LOCALE, "Canadian English" },
+ { "pt", TEST_ULDN_LOCALE, "Portuguese" },
+ { "pt_BR", TEST_ULDN_LOCALE, "Brazilian Portuguese" },
+ { "pt_PT", TEST_ULDN_LOCALE, "European Portuguese" },
+ { "zh_Hans", TEST_ULDN_LOCALE, "Simplified Chinese" },
+ { "zh_Hant_HK", TEST_ULDN_LOCALE, "Traditional Chinese (Hong Kong)" },
+ { "zh_HK", TEST_ULDN_LOCALE, "Chinese (Hong Kong)" },
+ { "Latn", TEST_ULDN_SCRIPT, "Latin" },
+ { "Hans", TEST_ULDN_SCRIPT, "Simplified Han" },
+ { "Hant", TEST_ULDN_SCRIPT, "Traditional Han" },
+ { "US", TEST_ULDN_REGION, "US" },
+ { "CA", TEST_ULDN_REGION, "Canada" },
+ { "GB", TEST_ULDN_REGION, "UK" },
+ { "HK", TEST_ULDN_REGION, "Hong Kong" },
+};
+
+static const UldnItem fr_StdMidLong[] = {
+ { "en_US", TEST_ULDN_LOCALE, "anglais (\\u00C9.-U.)" },
+ { "US", TEST_ULDN_REGION, "\\u00C9tats-Unis" },
+ { "HK", TEST_ULDN_REGION, "Hong Kong (Chine)" },
+};
+
+static const UldnItem fr_StdMidShrt[] = {
+ { "en_US", TEST_ULDN_LOCALE, "anglais (\\u00C9.-U.)" },
+ { "US", TEST_ULDN_REGION, "\\u00C9.-U." },
+ { "HK", TEST_ULDN_REGION, "Hong Kong" },
+};
+
+static const UldnItem fr_StdBegLong[] = {
+ { "en_US", TEST_ULDN_LOCALE, "Anglais (\\u00C9.-U.)" },
+};
+
+static const UldnItem fr_StdLstLong[] = {
+ { "en_US", TEST_ULDN_LOCALE, "Anglais (\\u00C9.-U.)" },
+ { "PS", TEST_ULDN_REGION, "Territoires palestiniens" },
+};
+
+static const UldnItem fr_DiaMidLong[] = {
+ { "en_US", TEST_ULDN_LOCALE, "anglais am\\u00E9ricain" },
+};
+
+static const UldnItem ca_StdLstLong[] = {
+ { "PS", TEST_ULDN_REGION, "Territoris palestins" },
+};
+
+static const UldnLocAndOpts uldnLocAndOpts[] = {
+ { "en", optStdMidLong, en_StdMidLong, UPRV_LENGTHOF(en_StdMidLong) },
+ { "en", optStdMidShrt, en_StdMidShrt, UPRV_LENGTHOF(en_StdMidShrt) },
+ { "en", optDiaMidLong, en_DiaMidLong, UPRV_LENGTHOF(en_DiaMidLong) },
+ { "en", optDiaMidShrt, en_DiaMidShrt, UPRV_LENGTHOF(en_DiaMidShrt) },
+ { "fr", optStdMidLong, fr_StdMidLong, UPRV_LENGTHOF(fr_StdMidLong) },
+ { "fr", optStdMidShrt, fr_StdMidShrt, UPRV_LENGTHOF(fr_StdMidShrt) },
+ { "fr", optStdBegLong, fr_StdBegLong, UPRV_LENGTHOF(fr_StdBegLong) },
+ { "fr", optStdLstLong, fr_StdLstLong, UPRV_LENGTHOF(fr_StdLstLong) },
+ { "fr_CA", optStdLstLong, fr_StdLstLong, UPRV_LENGTHOF(fr_StdLstLong) },
+ { "fr", optDiaMidLong, fr_DiaMidLong, UPRV_LENGTHOF(fr_DiaMidLong) },
+ { "ca", optStdLstLong, ca_StdLstLong, UPRV_LENGTHOF(ca_StdLstLong) },
+ { NULL, NULL, NULL, 0 }
+};
+
+enum { kUNameBuf = 128, kBNameBuf = 256 };
+
+static void TestUldnNameVariants() {
+ const UldnLocAndOpts * uloPtr;
+ for (uloPtr = uldnLocAndOpts; uloPtr->displayLocale != NULL; uloPtr++) {
+ UErrorCode status = U_ZERO_ERROR;
+ ULocaleDisplayNames * uldn = uldn_openForContext(uloPtr->displayLocale, (UDisplayContext*)uloPtr->displayOptions, 3, &status);
+ if (U_FAILURE(status)) {
+ log_data_err("uldn_openForContext fails, displayLocale %s, contexts %03X %03X %03X: %s - Are you missing data?\n",
+ uloPtr->displayLocale, uloPtr->displayOptions[0], uloPtr->displayOptions[1], uloPtr->displayOptions[2],
+ u_errorName(status) );
+ continue;
+ }
+ const UldnItem * itemPtr = uloPtr->testItems;
+ int32_t itemCount = uloPtr->countItems;
+ for (; itemCount-- > 0; itemPtr++) {
+ UChar uget[kUNameBuf], uexp[kUNameBuf];
+ int32_t ulenget, ulenexp;
+ const char* typeString;
+
+ status = U_ZERO_ERROR;
+ switch (itemPtr->nameType) {
+ case TEST_ULDN_LOCALE:
+ ulenget = uldn_localeDisplayName(uldn, itemPtr->localeToName, uget, kUNameBuf, &status);
+ typeString = "locale";
+ break;
+ case TEST_ULDN_LANGUAGE:
+ ulenget = uldn_languageDisplayName(uldn, itemPtr->localeToName, uget, kUNameBuf, &status);
+ typeString = "language";
+ break;
+ case TEST_ULDN_SCRIPT:
+ ulenget = uldn_scriptDisplayName(uldn, itemPtr->localeToName, uget, kUNameBuf, &status);
+ typeString = "script";
+ break;
+ case TEST_ULDN_REGION:
+ ulenget = uldn_regionDisplayName(uldn, itemPtr->localeToName, uget, kUNameBuf, &status);
+ typeString = "region";
+ break;
+ default:
+ continue;
+ }
+ if (U_FAILURE(status)) {
+ log_data_err("uldn_%sDisplayName fails, displayLocale %s, contexts %03X %03X %03X, localeToName %s: %s\n",
+ typeString, uloPtr->displayLocale, uloPtr->displayOptions[0], uloPtr->displayOptions[1], uloPtr->displayOptions[2],
+ itemPtr->localeToName, u_errorName(status) );
+ continue;
+ }
+ ulenexp = u_unescape(itemPtr->expectResult, uexp, kUNameBuf);
+ if (ulenget != ulenexp || u_strncmp(uget, uexp, ulenexp) != 0) {
+ char bexp[kBNameBuf], bget[kBNameBuf];
+ u_strToUTF8(bexp, kBNameBuf, NULL, uexp, ulenexp, &status);
+ u_strToUTF8(bget, kBNameBuf, NULL, uget, ulenget, &status);
+ log_data_err("uldn_%sDisplayName fails, displayLocale %s, contexts %03X %03X %03X, localeToName %s:\n expect %2d: %s\n get %2d: %s\n",
+ typeString, uloPtr->displayLocale, uloPtr->displayOptions[0], uloPtr->displayOptions[1], uloPtr->displayOptions[2],
+ itemPtr->localeToName, ulenexp, bexp, ulenget, bget );
+ }
+ }
+
+ uldn_close(uldn);
+ }
+}
+
+/* Apple-specific, test for Apple-specific function ualoc_getAppleParent */
+static const char* localesAndAppleParent[] = {
+ "en", "root",
+ "en-US", "en",
+ "en-CA", "en_001",
+ "en-CN", "en",
+ "en-JP", "en",
+ "en-TW", "en",
+ "en-001", "en",
+ "en_001", "en",
+ "en-150", "en_GB",
+ "en-GB", "en_001",
+ "en_GB", "en_001",
+ "en-AU", "en_GB",
+ "en-BE", "en_150",
+ "en-DG", "en_GB",
+ "en-FK", "en_GB",
+ "en-GG", "en_GB",
+ "en-GI", "en_GB",
+ "en-HK", "en_GB",
+ "en-IE", "en_GB",
+ "en-IM", "en_GB",
+ "en-IN", "en_GB",
+ "en-IO", "en_GB",
+ "en-JE", "en_GB",
+ "en-JM", "en_GB",
+ "en-MO", "en_GB",
+ "en-MT", "en_GB",
+ "en-MV", "en_GB",
+ "en-NZ", "en_AU",
+ "en-PK", "en_GB",
+ "en-SG", "en_GB",
+ "en-SH", "en_GB",
+ "en-VG", "en_GB",
+ "es", "root",
+ "es-ES", "es",
+ "es-419", "es",
+ "es_419", "es",
+ "es-MX", "es_419",
+ "es-AR", "es_419",
+ "es-BR", "es_419",
+ "es-BZ", "es_419",
+ "es-AG", "es_419",
+ "es-AW", "es_419",
+ "es-CA", "es_419",
+ "es-CW", "es_419",
+ "es-SX", "es_419",
+ "es-TT", "es_419",
+ "fr", "root",
+ "fr-CA", "fr",
+ "fr-CH", "fr",
+ "haw", "root",
+ "nl", "root",
+ "nl-BE", "nl",
+ "pt", "root",
+ "pt-BR", "pt",
+ "pt-PT", "pt",
+ "pt-MO", "pt_PT",
+ "pt-CH", "pt_PT",
+ "pt-GQ", "pt_PT",
+ "pt-LU", "pt_PT",
+ "sr", "root",
+ "sr-Cyrl", "sr",
+ "sr-Latn", "root",
+ "tlh", "root",
+ "zh_CN", "root",
+ "zh-CN", "root",
+ "zh", "zh_CN",
+ "zh-Hans", "zh",
+ "zh_TW", "root",
+ "zh-TW", "root",
+ "zh-Hant", "zh_TW",
+ "zh_HK", "zh_Hant_HK",
+ "zh-HK", "zh_Hant_HK",
+ "zh_Hant", "zh_TW",
+ "zh-Hant-HK", "zh_Hant",
+ "zh_Hant_HK", "zh_Hant",
+ "zh-Hant-MO", "zh_Hant_HK",
+ "zh-Hans-HK", "zh_Hans",
+ "root", "root",
+ "en-Latn", "en",
+ "en-Latn-US", "en_Latn",
+ "en_US_POSIX", "en_US",
+ "en_Latn_US_POSIX", "en_Latn_US",
+ "en-u-ca-hebrew", "root",
+ "en@calendar=hebrew", "root",
+ "en_@calendar=hebrew", "root",
+ "en-", "root",
+ "en_", "root",
+ "Default@2x", "root",
+ "default", "root",
+ NULL /* terminator */
+};
+
+static void TestGetAppleParent() {
+ const char **localesPtr = localesAndAppleParent;
+ const char * locale;
+ while ((locale = *localesPtr++) != NULL) {
+ const char * expectParent = *localesPtr++;
+ UErrorCode status = U_ZERO_ERROR;
+ char getParent[ULOC_FULLNAME_CAPACITY];
+ int32_t plen = ualoc_getAppleParent(locale, getParent, ULOC_FULLNAME_CAPACITY, &status);
+ if (U_FAILURE(status)) {
+ log_err("FAIL: ualoc_getAppleParent input \"%s\", status %s\n", locale, u_errorName(status));
+ } else if (uprv_strcmp(expectParent, getParent) != 0) {
+ log_err("FAIL: ualoc_getAppleParent input \"%s\", expected parent \"%s\", got parent \"%s\"\n", locale, expectParent, getParent);
+ }
+ }
+}
+
+/* Apple-specific, test for Apple-specific function ualoc_getLanguagesForRegion */
+enum { kUALanguageEntryMax = 10 };
+
+static void TestGetLanguagesForRegion() {
+ UALanguageEntry entries[kUALanguageEntryMax];
+ int32_t entryCount;
+ UErrorCode status;
+ const char * region;
+
+ status = U_ZERO_ERROR;
+ region = "CN";
+ entryCount = ualoc_getLanguagesForRegion(region, 0.001, entries, kUALanguageEntryMax, &status);
+ if (U_FAILURE(status)) {
+ log_err("FAIL: ualoc_getLanguagesForRegion %s, status %s\n", region, u_errorName(status));
+ } else {
+ // Expect approximately:
+ // zh_Hans 0.90 UALANGSTATUS_OFFICIAL
+ // wuu 0.06 Wu
+ // hsn 0.06 Xiang
+ // yue 0.043 Yue including Cantonese
+ // hak 0.023 Hakka
+ // nan 0.019 Minnan
+ // gan 0.017 Gan
+ // ii 0.006 Yi
+ // ug_Arab 0.0055 Uighur UALANGSTATUS_REGIONAL_OFFICIAL
+ // ...at least 4 more with fractions >= 0.001
+ if (entryCount < kUALanguageEntryMax) {
+ log_err("FAIL: ualoc_getLanguagesForRegion %s, entryCount %d is too small\n", region, entryCount);
+ } else {
+ UALanguageEntry* entryPtr = entries;
+ if (uprv_strcmp(entryPtr->languageCode, "zh_Hans") != 0 || entryPtr->userFraction < 0.8 || entryPtr->userFraction > 1.0 || entryPtr->status != UALANGSTATUS_OFFICIAL) {
+ log_err("FAIL: ualoc_getLanguagesForRegion %s, invalid entries[0] { %s, %.3f, %d }\n", region, entryPtr->languageCode, entryPtr->userFraction, (int)entryPtr->status);
+ }
+ for (entryPtr++; entryPtr < entries + kUALanguageEntryMax && uprv_strcmp(entryPtr->languageCode, "ug_Arab") != 0; entryPtr++)
+ ;
+ if (entryPtr < entries + kUALanguageEntryMax) {
+ // we found ug_Arab, make sure it has correct status
+ if (entryPtr->status != UALANGSTATUS_REGIONAL_OFFICIAL) {
+ log_err("FAIL: ualoc_getLanguagesForRegion %s, ug_Arab had incorrect status %d\n", (int)entryPtr->status);
+ }
+ } else {
+ // did not find ug_Arab
+ log_err("FAIL: ualoc_getLanguagesForRegion %s, entries did not include ug_Arab\n", region);
+ }
+ }
+ }
+
+ status = U_ZERO_ERROR;
+ region = "CA";
+ entryCount = ualoc_getLanguagesForRegion(region, 0.001, entries, kUALanguageEntryMax, &status);
+ if (U_FAILURE(status)) {
+ log_err("FAIL: ualoc_getLanguagesForRegion %s, status %s\n", region, u_errorName(status));
+ } else {
+ // Expect approximately:
+ // en 0.85 UALANGSTATUS_OFFICIAL
+ // fr 0.22 UALANGSTATUS_OFFICIAL
+ // ...
+ if (entryCount < 2) {
+ log_err("FAIL: ualoc_getLanguagesForRegion %s, entryCount %d is too small\n", region, entryCount);
+ } else {
+ if (uprv_strcmp(entries[0].languageCode, "en") != 0 || entries[0].userFraction < 0.7 || entries[0].userFraction > 1.0 || entries[0].status != UALANGSTATUS_OFFICIAL) {
+ log_err("FAIL: ualoc_getLanguagesForRegion %s, invalid entries[0] { %s, %.3f, %d }\n", region, entries[0].languageCode, entries[0].userFraction, (int)entries[0].status);
+ }
+ if (uprv_strcmp(entries[1].languageCode, "fr") != 0 || entries[1].userFraction < 0.1 || entries[1].userFraction > 1.0 || entries[1].status != UALANGSTATUS_OFFICIAL) {
+ log_err("FAIL: ualoc_getLanguagesForRegion %s, invalid entries[1] { %s, %.3f, %d }\n", region, entries[1].languageCode, entries[1].userFraction, (int)entries[1].status);
+ }
+ }
+ }
+
+ status = U_ZERO_ERROR;
+ region = "IN";
+ entryCount = ualoc_getLanguagesForRegion(region, 0.001, NULL, 0, &status);
+ if (U_FAILURE(status)) {
+ log_err("FAIL: ualoc_getLanguagesForRegion %s, status %s\n", region, u_errorName(status));
+ } else {
+ if (entryCount < 40) {
+ log_err("FAIL: ualoc_getLanguagesForRegion %s, entryCount %d is too small\n", region, entryCount);
+ }
+ }
+}
+
+/* data for TestAppleLocalizationsToUse */
+
+typedef struct {
+ const char * const *locs;
+ int32_t locCount;
+} AppleLocsAndCount;
+
+enum { kNumLocSets = 6 };
+
+typedef struct {
+ const char * language;
+ const char ** expLocsForSets[kNumLocSets];
+} LangAndExpLocs;
+
+
+static const char * appleLocs1[] = {
+ "Arabic",
+ "Danish",
+ "Dutch",
+ "English",
+ "Finnish",
+ "French",
+ "German",
+ "Italian",
+ "Japanese",
+ "Korean",
+ "Norwegian",
+ "Polish",
+ "Portuguese",
+ "Russian",
+ "Spanish",
+ "Swedish",
+ "Thai",
+ "Turkish",
+ "ca",
+ "cs",
+ "el",
+ "he",
+ "hr",
+ "hu",
+ "id",
+ "ms",
+ "ro",
+ "sk",
+ "uk",
+ "vi",
+ "zh_CN", "zh_TW",
+};
+
+static const char * appleLocs2[] = {
+ "ar",
+ "ca",
+ "cs",
+ "da",
+ "de",
+ "el",
+ "en", "en_AU", "en_GB",
+ "es", "es_MX",
+ "fi",
+ "fr", "fr_CA",
+ "he",
+ "hr",
+ "hu",
+ "id",
+ "it",
+ "ja",
+ "ko",
+ "ms",
+ "nl",
+ "no",
+ "pl",
+ "pt", "pt_PT",
+ "ro",
+ "ru",
+ "sk",
+ "sv",
+ "th",
+ "tr",
+ "uk",
+ "vi",
+ "zh_CN", "zh_HK", "zh_TW",
+};
+
+static const char * appleLocs3[] = {
+ "ar",
+ "ca",
+ "cs",
+ "da",
+ "de",
+ "el",
+ "en", "en_AU", "en_CA", "en_GB",
+ "es", "es_419",
+ "fi",
+ "fr", "fr_CA", "fr_FR",
+ "he",
+ "hr",
+ "hu",
+ "id",
+ "it",
+ "ja",
+ "ko",
+ "ms",
+ "nb",
+ "nl",
+ "pl",
+ "pt", "pt_BR", "pt_PT",
+ "ro",
+ "ru",
+ "sk",
+ "sv",
+ "th",
+ "tr",
+ "uk",
+ "vi",
+ "zh_CN", "zh_HK", "zh_MO", "zh_TW",
+};
+
+static const char * appleLocs4[] = {
+ "en", "en_AU", "en_CA", "en_GB", "en_IN", "en_US",
+ "es", "es_419", "es_MX",
+ "fr", "fr_CA", "fr_CH", "fr_FR",
+ "nl", "nl_BE", "nl_NL",
+ "pt", "pt_BR",
+ "ro", "ro_MD", "ro_RO",
+ "zh_Hans", "zh_Hant", "zh_Hant_HK",
+};
+
+static const char * appleLocs5[] = {
+ "en", "en_001", "en_AU", "en_GB",
+ "es", "es_ES", "es_MX",
+ "zh_CN", "zh_Hans", "zh_Hant", "zh_TW",
+ "yi",
+ "fil",
+ "haw",
+ "tlh",
+ "sr",
+ "sr-Latn",
+};
+
+// list 6
+static const char * appleLocs6[] = {
+ "en", "en_001", "en_150", "en_AU", "en_GB",
+ "es", "es_419", "es_ES", "es_MX",
+ "zh_CN", "zh_Hans", "zh_Hant", "zh_Hant_HK", "zh_HK", "zh_TW",
+ "iw",
+ "in",
+ "mo",
+ "tl",
+};
+
+static const AppleLocsAndCount locAndCountEntries[kNumLocSets] = {
+ { appleLocs1, UPRV_LENGTHOF(appleLocs1) },
+ { appleLocs2, UPRV_LENGTHOF(appleLocs2) },
+ { appleLocs3, UPRV_LENGTHOF(appleLocs3) },
+ { appleLocs4, UPRV_LENGTHOF(appleLocs4) },
+ { appleLocs5, UPRV_LENGTHOF(appleLocs5) },
+ { appleLocs6, UPRV_LENGTHOF(appleLocs6) },
+};
+
+
+static const char* l1_ar[] = { "ar", NULL };
+static const char* l1_Ara[] = { "Arabic", NULL };
+static const char* l1_ca[] = { "ca", NULL };
+static const char* l1_cs[] = { "cs", NULL };
+static const char* l1_da[] = { "da", NULL };
+static const char* l1_Dan[] = { "Danish", NULL };
+static const char* l1_de[] = { "de", NULL };
+static const char* l1_Ger[] = { "German", NULL };
+static const char* l1_el[] = { "el", NULL };
+static const char* l1_en[] = { "en", NULL };
+static const char* l1_Eng[] = { "English", NULL };
+static const char* l2_en_001_[] = { "en_001", "en", NULL };
+static const char* l2_en_CA_[] = { "en_CA", "en", NULL };
+static const char* l2_en_GB_[] = { "en_GB", "en", NULL };
+static const char* l2_en_US_[] = { "en_US", "en", NULL };
+static const char* l2_en_GB_Eng[] = { "en_GB", "English", NULL };
+static const char* l3_en_GB001_[] = { "en_GB", "en_001", "en", NULL };
+static const char* l3_en_AUGB_[] = { "en_AU", "en_GB", "en", NULL };
+static const char* l3_en_INGB_[] = { "en_IN", "en_GB", "en", NULL };
+static const char* l4_en_150GB001_[] = { "en_150", "en_GB", "en_001", "en", NULL };
+static const char* l4_en_AUGB001_[] = { "en_AU", "en_GB", "en_001", "en", NULL };
+static const char* l1_es[] = { "es", NULL };
+static const char* l1_Spa[] = { "Spanish", NULL };
+static const char* l2_es_419_[] = { "es_419", "es", NULL };
+static const char* l2_es_ES_[] = { "es_ES", "es", NULL };
+static const char* l2_es_MX_[] = { "es_MX", "es", NULL };
+static const char* l2_es_MX_Spa[] = { "es_MX", "Spanish", NULL };
+static const char* l3_es_MX419_[] = { "es_MX", "es_419", "es", NULL };
+static const char* l1_fi[] = { "fi", NULL };
+static const char* l1_Fin[] = { "Finnish", NULL };
+static const char* l1_fil[] = { "fil", NULL };
+static const char* l1_tl[] = { "tl", NULL };
+static const char* l1_fr[] = { "fr", NULL };
+static const char* l1_Fre[] = { "French", NULL };
+static const char* l2_fr_CA_[] = { "fr_CA", "fr", NULL };
+static const char* l2_fr_CH_[] = { "fr_CH", "fr", NULL };
+static const char* l2_fr_FR_[] = { "fr_FR", "fr", NULL };
+static const char* l1_haw[] = { "haw", NULL };
+static const char* l1_he[] = { "he", NULL };
+static const char* l1_hr[] = { "hr", NULL };
+static const char* l1_hu[] = { "hu", NULL };
+static const char* l1_id[] = { "id", NULL };
+static const char* l1_in[] = { "in", NULL };
+static const char* l1_it[] = { "it", NULL };
+static const char* l1_Ita[] = { "Italian", NULL };
+static const char* l1_ja[] = { "ja", NULL };
+static const char* l1_Japn[] = { "Japanese", NULL };
+static const char* l1_ko[] = { "ko", NULL };
+static const char* l1_Kor[] = { "Korean", NULL };
+static const char* l1_ms[] = { "ms", NULL };
+static const char* l1_nb[] = { "nb", NULL };
+static const char* l1_no[] = { "no", NULL };
+static const char* l1_Nor[] = { "Norwegian", NULL };
+static const char* l2_no_NO_[] = { "no_NO", "no", NULL };
+static const char* l1_nl[] = { "nl", NULL };
+static const char* l1_Dut[] = { "Dutch", NULL };
+static const char* l2_nl_BE_[] = { "nl_BE", "nl", NULL };
+static const char* l1_pl[] = { "pl", NULL };
+static const char* l1_Pol[] = { "Polish", NULL };
+static const char* l1_pt[] = { "pt", NULL };
+static const char* l1_pt_PT[] = { "pt_PT", NULL };
+static const char* l1_Port[] = { "Portuguese", NULL };
+static const char* l2_pt_BR_[] = { "pt_BR", "pt", NULL };
+static const char* l2_pt_PT_[] = { "pt_PT", "pt", NULL };
+static const char* l1_ro[] = { "ro", NULL };
+static const char* l2_ro_MD_[] = { "ro_MD", "ro", NULL };
+static const char* l1_mo[] = { "mo", NULL };
+static const char* l1_ru[] = { "ru", NULL };
+static const char* l1_Rus[] = { "Russian", NULL };
+static const char* l1_sk[] = { "sk", NULL };
+static const char* l1_sr[] = { "sr", NULL };
+static const char* l1_srLatn[] = { "sr-Latn", NULL };
+static const char* l1_sv[] = { "sv", NULL };
+static const char* l1_Swe[] = { "Swedish", NULL };
+static const char* l1_th[] = { "th", NULL };
+static const char* l1_Thai[] = { "Thai", NULL };
+static const char* l1_tlh[] = { "tlh", NULL };
+static const char* l1_tr[] = { "tr", NULL };
+static const char* l1_Tur[] = { "Turkish", NULL };
+static const char* l1_uk[] = { "uk", NULL };
+static const char* l1_vi[] = { "vi", NULL };
+static const char* l1_yi[] = { "yi", NULL };
+static const char* l1_iw[] = { "iw", NULL };
+static const char* l1_zh_CN[] = { "zh_CN", NULL };
+static const char* l1_zh_TW[] = { "zh_TW", NULL };
+static const char* l1_zh_Hans[] = { "zh_Hans", NULL };
+static const char* l1_zh_Hant[] = { "zh_Hant", NULL };
+static const char* l1_zhHant[] = { "zh-Hant", NULL };
+static const char* l2_zh_HKTW[] = { "zh_HK", "zh_TW", NULL };
+static const char* l2_zh_Hant_HK_[] = { "zh_Hant_HK", "zh_Hant", NULL };
+static const char* l2_zh_CN_Hans[] = { "zh_CN", "zh_Hans", NULL };
+static const char* l2_zh_TW_Hant[] = { "zh_TW", "zh_Hant", NULL };
+static const char* l3_zh_MOHKTW[] = { "zh_MO", "zh_HK", "zh_TW", NULL };
+static const char* l3_zh_HK_HantHK_Hant[] = { "zh_HK", "zh_Hant_HK", "zh_Hant", NULL };
+
+static const LangAndExpLocs appleLangAndLoc[] = {
+// language\ result for appleLocs1 appleLocs2 appleLocs3 appleLocs4 appleLocs5 appleLocs6
+ { "zh", { l1_zh_CN, l1_zh_CN, l1_zh_CN, l1_zh_Hans, l1_zh_Hans, l1_zh_Hans } },
+ { "zh-Hans", { l1_zh_CN, l1_zh_CN, l1_zh_CN, l1_zh_Hans, l1_zh_Hans, l1_zh_Hans } },
+ { "zh-Hant", { l1_zh_TW, l1_zh_TW, l1_zh_TW, l1_zh_Hant, l1_zh_Hant, l1_zh_Hant } },
+ { "zh-Hans-CN", { l1_zh_CN, l1_zh_CN, l1_zh_CN, l1_zh_Hans, l2_zh_CN_Hans, l2_zh_CN_Hans } },
+ { "zh-Hans-SG", { l1_zh_CN, l1_zh_CN, l1_zh_CN, l1_zh_Hans, l1_zh_Hans, l1_zh_Hans } },
+ { "zh-Hant-TW", { l1_zh_TW, l1_zh_TW, l1_zh_TW, l1_zh_Hant, l2_zh_TW_Hant, l2_zh_TW_Hant } },
+ { "zh-Hant-HK", { l1_zh_TW, l2_zh_HKTW, l2_zh_HKTW, l2_zh_Hant_HK_, l1_zh_Hant, l2_zh_Hant_HK_ } },
+ { "zh-Hant-MO", { l1_zh_TW, l2_zh_HKTW, l3_zh_MOHKTW, l2_zh_Hant_HK_, l1_zh_Hant, l2_zh_Hant_HK_ } },
+ { "zh-Hans-HK", { l1_zh_CN, l1_zh_CN, l1_zh_CN, l1_zh_Hans, l1_zh_Hans, l1_zh_Hans } },
+ { "zh-CN", { l1_zh_CN, l1_zh_CN, l1_zh_CN, l1_zh_Hans, l2_zh_CN_Hans, l2_zh_CN_Hans } },
+ { "zh-SG", { l1_zh_CN, l1_zh_CN, l1_zh_CN, l1_zh_Hans, l1_zh_Hans, l1_zh_Hans } },
+ { "zh-TW", { l1_zh_TW, l1_zh_TW, l1_zh_TW, l1_zh_Hant, l2_zh_TW_Hant, l2_zh_TW_Hant } },
+ { "zh-HK", { l1_zh_TW, l2_zh_HKTW, l2_zh_HKTW, l2_zh_Hant_HK_, l1_zh_Hant, l3_zh_HK_HantHK_Hant } },
+ { "zh-MO", { l1_zh_TW, l2_zh_HKTW, l3_zh_MOHKTW, l2_zh_Hant_HK_, l1_zh_Hant, l2_zh_Hant_HK_ } },
+ { "en", { l1_Eng, l1_en, l1_en, l1_en, l1_en, l1_en } },
+ { "en-US", { l1_Eng, l1_en, l1_en, l2_en_US_, l1_en, l1_en } },
+ { "en_US", { l1_Eng, l1_en, l1_en, l2_en_US_, l1_en, l1_en } },
+ { "en-CN", { l1_Eng, l1_en, l1_en, l1_en, l1_en, l1_en } },
+ { "en-JP", { l1_Eng, l1_en, l1_en, l1_en, l1_en, l1_en } },
+ { "en-TW", { l1_Eng, l1_en, l1_en, l1_en, l1_en, l1_en } },
+ { "en-TR", { l1_Eng, l1_en, l1_en, l1_en, l1_en, l1_en } },
+ { "en-001", { l1_Eng, l1_en, l1_en, l1_en, l2_en_001_, l2_en_001_ } },
+ { "en-CA", { l1_Eng, l1_en, l2_en_CA_, l2_en_CA_, l2_en_001_, l2_en_001_ } },
+ { "en-IL", { l1_Eng, l1_en, l1_en, l1_en, l2_en_001_, l2_en_001_ } },
+ { "en-GB", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l3_en_GB001_ } },
+ { "en-IN", { l1_Eng, l2_en_GB_, l2_en_GB_, l3_en_INGB_, l3_en_GB001_, l3_en_GB001_ } },
+ { "en-BD", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l3_en_GB001_ } },
+ { "en-GG", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l3_en_GB001_ } },
+ { "en-HK", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l3_en_GB001_ } },
+ { "en-IE", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l3_en_GB001_ } },
+ { "en-JM", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l3_en_GB001_ } },
+ { "en-MO", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l3_en_GB001_ } },
+ { "en-MT", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l3_en_GB001_ } },
+ { "en-PK", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l3_en_GB001_ } },
+ { "en-SG", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l3_en_GB001_ } },
+ { "en-VG", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l3_en_GB001_ } },
+ { "en-ZA", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l3_en_GB001_ } },
+ { "en-AU", { l1_Eng, l3_en_AUGB_, l3_en_AUGB_, l3_en_AUGB_, l4_en_AUGB001_, l4_en_AUGB001_ } },
+ { "en-NZ", { l1_Eng, l3_en_AUGB_, l3_en_AUGB_, l3_en_AUGB_, l4_en_AUGB001_, l4_en_AUGB001_ } },
+ { "en-WS", { l1_Eng, l3_en_AUGB_, l3_en_AUGB_, l3_en_AUGB_, l4_en_AUGB001_, l4_en_AUGB001_ } },
+ { "en-150", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l4_en_150GB001_ } },
+ { "en-FR", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l4_en_150GB001_ } },
+ { "en-BE", { l1_Eng, l2_en_GB_, l2_en_GB_, l2_en_GB_, l3_en_GB001_, l4_en_150GB001_ } },
+ { "en-Latn", { l1_Eng, l1_en, l1_en, l1_en, l1_en, l1_en } },
+ { "en-Latn-US", { l1_Eng, l1_en, l1_en, l1_en,/*TODO*/ l1_en, l1_en } },
+ { "en-US-POSIX", { l1_Eng, l1_en, l1_en, l2_en_US_, l1_en, l1_en } },
+ { "en-Latn-US-POSIX", { l1_Eng, l1_en, l1_en, l1_en, l1_en, l1_en } },
+ { "en-u-ca-hebrew", { l1_Eng, l1_en, l1_en, l1_en, l1_en, l1_en } },
+ { "en@calendar=hebrew", { l1_Eng, l1_en, l1_en, l1_en, l1_en, l1_en } },
+ { "en-", { l1_Eng, l1_en, l1_en, l1_en, l1_en, l1_en } },
+ { "en_", { l1_Eng, l1_en, l1_en, l1_en, l1_en, l1_en } },
+ { "es", { l1_Spa, l1_es, l1_es, l1_es, l1_es, l1_es } },
+ { "es-ES", { l1_Spa, l1_es, l1_es, l1_es, l2_es_ES_, l2_es_ES_ } },
+ { "es-419", { l1_Spa, l1_es, l2_es_419_, l2_es_419_, l1_es, l2_es_419_ } },
+ { "es-MX", { l1_Spa, l2_es_MX_, l2_es_419_, l3_es_MX419_, l2_es_MX_, l3_es_MX419_ } },
+ { "es-AR", { l1_Spa, l1_es, l2_es_419_, l2_es_419_, l1_es, l2_es_419_ } },
+ { "es-BR", { l1_Spa, l1_es, l2_es_419_, l2_es_419_, l1_es, l2_es_419_ } },
+ { "es-BZ", { l1_Spa, l1_es, l2_es_419_, l2_es_419_, l1_es, l2_es_419_ } },
+ { "es-AG", { l1_Spa, l1_es, l2_es_419_, l2_es_419_, l1_es, l2_es_419_ } },
+ { "es-AW", { l1_Spa, l1_es, l2_es_419_, l2_es_419_, l1_es, l2_es_419_ } },
+ { "es-CA", { l1_Spa, l1_es, l2_es_419_, l2_es_419_, l1_es, l2_es_419_ } },
+ { "es-CW", { l1_Spa, l1_es, l2_es_419_, l2_es_419_, l1_es, l2_es_419_ } },
+ { "es-SX", { l1_Spa, l1_es, l2_es_419_, l2_es_419_, l1_es, l2_es_419_ } },
+ { "es-TT", { l1_Spa, l1_es, l2_es_419_, l2_es_419_, l1_es, l2_es_419_ } },
+ { "es-Latn", { l1_Spa, l1_es, l1_es, l1_es, l1_es, l1_es } },
+ { "es-Latn-MX", { l1_Spa, l1_es, l1_es, l1_es, l1_es, l1_es } },
+ { "pt", { l1_Port, l1_pt, l1_pt, l1_pt, NULL, NULL } },
+ { "pt-BR", { l1_Port, l1_pt, l2_pt_BR_, l2_pt_BR_, NULL, NULL } },
+ { "pt-PT", { l1_Port, l2_pt_PT_, l2_pt_PT_, l1_pt, NULL, NULL } },
+ { "pt-MO", { l1_Port, l2_pt_PT_, l2_pt_PT_, l1_pt, NULL, NULL } },
+ { "pt-CH", { l1_Port, l2_pt_PT_, l2_pt_PT_, l1_pt, NULL, NULL } },
+ { "pt-FR", { l1_Port, l2_pt_PT_, l2_pt_PT_, l1_pt, NULL, NULL } },
+ { "pt-GQ", { l1_Port, l2_pt_PT_, l2_pt_PT_, l1_pt, NULL, NULL } },
+ { "pt-LU", { l1_Port, l2_pt_PT_, l2_pt_PT_, l1_pt, NULL, NULL } },
+ { "fr", { l1_Fre, l1_fr, l1_fr, l1_fr, NULL, NULL } },
+ { "fr-FR", { l1_Fre, l1_fr, l2_fr_FR_, l2_fr_FR_, NULL, NULL } },
+ { "fr-CA", { l1_Fre, l2_fr_CA_, l2_fr_CA_, l2_fr_CA_, NULL, NULL } },
+ { "fr-CH", { l1_Fre, l1_fr, l1_fr, l2_fr_CH_, NULL, NULL } },
+ { "ar", { l1_Ara, l1_ar, l1_ar, NULL, NULL, NULL } },
+ { "da", { l1_Dan, l1_da, l1_da, NULL, NULL, NULL } },
+ { "nl", { l1_Dut, l1_nl, l1_nl, l1_nl, NULL, NULL } },
+ { "nl-BE", { l1_Dut, l1_nl, l1_nl, l2_nl_BE_, NULL, NULL } },
+ { "fi", { l1_Fin, l1_fi, l1_fi, NULL, NULL, NULL } },
+ { "de", { l1_Ger, l1_de, l1_de, NULL, NULL, NULL } },
+ { "it", { l1_Ita, l1_it, l1_it, NULL, NULL, NULL } },
+ { "ja", { l1_Japn, l1_ja, l1_ja, NULL, NULL, NULL } },
+ { "ko", { l1_Kor, l1_ko, l1_ko, NULL, NULL, NULL } },
+ { "nb", { l1_Nor, l1_no, l1_nb, NULL, NULL, NULL } },
+ { "no", { l1_Nor, l1_no, l1_nb, NULL, NULL, NULL } },
+ { "pl", { l1_Pol, l1_pl, l1_pl, NULL, NULL, NULL } },
+ { "ru", { l1_Rus, l1_ru, l1_ru, NULL, NULL, NULL } },
+ { "sv", { l1_Swe, l1_sv, l1_sv, NULL, NULL, NULL } },
+ { "th", { l1_Thai, l1_th, l1_th, NULL, NULL, NULL } },
+ { "tr", { l1_Tur, l1_tr, l1_tr, NULL, NULL, NULL } },
+ { "ca", { l1_ca, l1_ca, l1_ca, NULL, NULL, NULL } },
+ { "cs", { l1_cs, l1_cs, l1_cs, NULL, NULL, NULL } },
+ { "el", { l1_el, l1_el, l1_el, NULL, NULL, NULL } },
+ { "he", { l1_he, l1_he, l1_he, NULL, NULL, l1_iw } },
+ { "iw", { l1_he, l1_he, l1_he, NULL, NULL, l1_iw } },
+ { "hr", { l1_hr, l1_hr, l1_hr, NULL, NULL, NULL } },
+ { "hu", { l1_hu, l1_hu, l1_hu, NULL, NULL, NULL } },
+ { "id", { l1_id, l1_id, l1_id, NULL, NULL, l1_in } },
+ { "in", { l1_id, l1_id, l1_id, NULL, NULL, l1_in } },
+ { "ms", { l1_ms, l1_ms, l1_ms, NULL, NULL, NULL } },
+ { "ro", { l1_ro, l1_ro, l1_ro, l1_ro, NULL, l1_mo } },
+ { "mo", { l1_ro, l1_ro, l1_ro, l2_ro_MD_, NULL, l1_mo } },
+ { "sk", { l1_sk, l1_sk, l1_sk, NULL, NULL, NULL } },
+ { "uk", { l1_uk, l1_uk, l1_uk, NULL, NULL, NULL } },
+ { "vi", { l1_vi, l1_vi, l1_vi, NULL, NULL, NULL } },
+ { "yi", { NULL, NULL, NULL, NULL, l1_yi, NULL } },
+ { "ji", { NULL, NULL, NULL, NULL, l1_yi, NULL } },
+ { "fil", { NULL, NULL, NULL, NULL, l1_fil, l1_tl } },
+ { "tl", { NULL, NULL, NULL, NULL, l1_fil, l1_tl } },
+ { "haw", { NULL, NULL, NULL, NULL, l1_haw, NULL } },
+ { "sr", { NULL, NULL, NULL, NULL, l1_sr, NULL } },
+ { "sr-Cyrl", { NULL, NULL, NULL, NULL, l1_sr, NULL } },
+ { "sr-Latn", { NULL, NULL, NULL, NULL, l1_srLatn, NULL } },
+ { "tlh", { NULL, NULL, NULL, NULL, l1_tlh, NULL } },
+ { "Default@2x", { NULL, NULL, NULL, NULL, NULL, NULL } },
+ { "default", { NULL, NULL, NULL, NULL, NULL, NULL } },
+ { "root", { NULL, NULL, NULL, NULL, NULL, NULL } },
+ { "", { NULL, NULL, NULL, NULL, NULL, NULL } },
+ { "_US", { NULL, NULL, NULL, NULL, NULL, NULL } },
+ { "-US", { NULL, NULL, NULL, NULL, NULL, NULL } },
+ { "-u-ca-hebrew", { NULL, NULL, NULL, NULL, NULL, NULL } },
+ { "-u-ca-hebrew", { NULL, NULL, NULL, NULL, NULL, NULL } },
+ { "@calendar=hebrew", { NULL, NULL, NULL, NULL, NULL, NULL } },
+};
+enum { kNumAppleLangAndLoc = UPRV_LENGTHOF(appleLangAndLoc) };
+
+/* tests from <rdar://problem/21518031> */
+
+static const char * appleLocsA1[] = { "en", "fr", "no", "zh-Hant" };
+static const char * appleLocsA2[] = { "en", "fr", "nb", "zh_TW", "zh_CN", "zh-Hant" };
+static const char * appleLocsA3[] = { "en", "en_IN", "en_GB", "fr", "de", "zh_TW" };
+static const char * appleLocsA4[] = { "Spanish", "es_MX", "English", "en_GB" };
+static const char * appleLocsA5[] = { "en", "fr", "de", "pt", "pt_PT" };
+static const char * appleLocsA6[] = { "en", "no", "no_NO", "pt_PT" };
+
+static const AppleLocsAndCount locAndCountEntriesA[kNumLocSets] = {
+ { appleLocsA1, UPRV_LENGTHOF(appleLocsA1) },
+ { appleLocsA2, UPRV_LENGTHOF(appleLocsA2) },
+ { appleLocsA3, UPRV_LENGTHOF(appleLocsA3) },
+ { appleLocsA4, UPRV_LENGTHOF(appleLocsA4) },
+ { appleLocsA5, UPRV_LENGTHOF(appleLocsA5) },
+ { appleLocsA6, UPRV_LENGTHOF(appleLocsA6) },
+};
+
+static const LangAndExpLocs appleLangAndLocA[] = {
+// language\ result for appleLocsA1 appleLocsA2 appleLocsA3 appleLocsA4 appleLocsA5 appleLocsA6
+ { "zh-Hant", { l1_zhHant,/*0*/ l1_zhHant,/*zh_TW*/ l1_zh_TW, NULL, NULL, NULL } },
+ { "zh_Hant", { l1_zhHant, l1_zhHant,/*zh_TW*/ l1_zh_TW, NULL, NULL, NULL } },
+ { "zh_HK", { l1_zhHant, l1_zhHant,/*zh_TW*/ l1_zh_TW, NULL, NULL, NULL } },
+ { "en_IN", { l1_en, l1_en, l3_en_INGB_, l2_en_GB_Eng, l1_en, l1_en } },
+ { "es_MX", { NULL, NULL, NULL, l2_es_MX_Spa, NULL, NULL } },
+ { "pt_PT", { NULL, NULL, NULL, NULL, l2_pt_PT_, l1_pt_PT } },
+ { "pt", { NULL, NULL, NULL, NULL, l1_pt, l1_pt_PT } },
+ { "no", { l1_no, l1_nb, NULL, NULL, NULL, l1_no } },
+ { "no_NO", { l1_no, l1_nb, NULL, NULL, NULL, l2_no_NO_ } },
+ { "nb", { l1_no, l1_nb, NULL, NULL, NULL, l1_no } },
+ { "nb_NO", { l1_no, l1_nb, NULL, NULL, NULL, l2_no_NO_ } },
+};
+enum { kNumAppleLangAndLocA = UPRV_LENGTHOF(appleLangAndLocA) };
+
+/* tests from log attached to 21682790 */
+
+static const char * appleLocsB1[] = {
+ "ar", "Base", "ca", "cs",
+ "da", "Dutch", "el", "English",
+ "es_MX", "fi", "French", "German",
+ "he", "hr", "hu", "id",
+ "Italian", "Japanese", "ko", "ms",
+ "no", "pl", "pt", "pt_PT",
+ "ro", "ru", "sk", "Spanish",
+ "sv", "th", "tr", "uk",
+ "vi", "zh_CN", "zh_TW"
+};
+
+static const char * appleLocsB2[] = {
+ "ar", "ca", "cs",
+ "da", "Dutch", "el", "English",
+ "es_MX", "fi", "French", "German",
+ "he", "hr", "hu", "id",
+ "Italian", "Japanese", "ko", "ms",
+ "no", "pl", "pt", "pt_PT",
+ "ro", "ru", "sk", "Spanish",
+ "sv", "th", "tr", "uk",
+ "vi", "zh_CN", "zh_TW"
+};
+
+static const char * appleLocsB3[] = {
+ "ar", "ca", "cs", "da",
+ "de", "el", "en", "es",
+ "es_MX", "fi", "French", "he",
+ "hr", "hu", "id", "Italian",
+ "ja", "ko", "ms", "nl",
+ "no", "pl", "pt", "pt_PT",
+ "ro", "ru", "sk", "sv",
+ "th", "tr", "uk", "vi",
+ "zh_CN", "zh_TW"
+};
+
+static const char * appleLocsB4[] = {
+ "ar", "ca", "cs", "da",
+ "de", "el", "en", "es",
+ "es_MX", "fi", "fr", "he",
+ "hr", "hu", "id", "it",
+ "ja", "ko", "ms", "nl",
+ "no", "pl", "pt", "pt_PT",
+ "ro", "ru", "sk", "sv",
+ "th", "tr", "uk", "vi",
+ "zh_CN", "zh_TW"
+};
+
+static const char * appleLocsB5[] = { "en" };
+
+static const char * appleLocsB6[] = { "English" };
+
+static const AppleLocsAndCount locAndCountEntriesB[kNumLocSets] = {
+ { appleLocsB1, UPRV_LENGTHOF(appleLocsB1) },
+ { appleLocsB2, UPRV_LENGTHOF(appleLocsB2) },
+ { appleLocsB3, UPRV_LENGTHOF(appleLocsB3) },
+ { appleLocsB4, UPRV_LENGTHOF(appleLocsB4) },
+ { appleLocsB5, UPRV_LENGTHOF(appleLocsB5) },
+ { appleLocsB6, UPRV_LENGTHOF(appleLocsB6) },
+};
+
+static const LangAndExpLocs appleLangAndLocB[] = {
+// language\ result for appleLocsB1 appleLocsB2 appleLocsB3 appleLocsB4 appleLocsB5 appleLocsB6
+// Prefs 1, logged with sets B1-B3
+ { "en", { l1_Eng, l1_Eng, l1_en, l1_en, l1_en, l1_Eng } },
+ { "es", { l1_Spa, l1_Spa, l1_es, l1_es, NULL, NULL } },
+// Prefs 2, logged with sets B1-B6
+ { "English", { l1_Eng, l1_Eng, l1_en, l1_en, l1_en, l1_Eng } },
+ { "Spanish", { l1_Spa, l1_Spa, l1_es, l1_es, NULL, NULL } },
+};
+enum { kNumAppleLangAndLocB = UPRV_LENGTHOF(appleLangAndLocB) };
+
+typedef struct {
+ const AppleLocsAndCount * locAndCountEntriesPtr;
+ const LangAndExpLocs * appleLangAndLocPtr;
+ int32_t appleLangAndLocCount;
+} AppleLocToUseTestSet;
+
+static const AppleLocToUseTestSet altuTestSets[] = {
+ { locAndCountEntries, appleLangAndLoc, kNumAppleLangAndLoc },
+ { locAndCountEntriesA, appleLangAndLocA, kNumAppleLangAndLocA },
+ { locAndCountEntriesB, appleLangAndLocB, kNumAppleLangAndLocB },
+ { NULL, NULL, 0 }
+};
+
+/* tests for multiple prefs sets */
+
+static const char * appleLocsM1[] = { "en", "en_GB", "pt", "pt_PT", "zh_CN", "zh_Hant" };
+static const char * prefLangsM1[] = { "tlh", "zh_HK", "zh_SG", "zh_Hans", "pt_BR", "pt_PT", "en_IN", "en" };
+static const char * locsToUseM1[] = { "zh_Hant" };
+
+// Tests from first pass at <rdar://problem/22012864>, 2015-11-18
+
+static const char * appleLocsM2[] = { "fr-FR", "en-US", "en-GB" };
+static const char * prefLangsM2[] = { "fr-CH" };
+static const char * locsToUseM2[] = { "fr-FR" };
+
+static const char * appleLocsM3[] = { "es-es", "fr-fr" };
+static const char * prefLangsM3[] = { "fr-US", "fr", "en-US" };
+static const char * locsToUseM3[] = { "fr-fr" };
+
+static const char * appleLocsM4[] = { "es-es", "fr-fr", "fr" };
+static const char * prefLangsM4[] = { "fr-US", "fr", "en-US" };
+static const char * locsToUseM4[] = { "fr" };
+
+// Tests from second pass at <rdar://problem/22012864>, 2015-12-08
+// Per Karan M
+static const char * appleLocsM5[] = { "en-US", "fr-FR", "de-DE", "es-ES", "es-419", "pt-PT", "pt-BR", "zh-CN", "zh-TW", "zh-HK", "ja-JP", "ko-KR" };
+static const char * prefLangsM5[] = { "fr-US", "en-US" };
+static const char * locsToUseM5[] = { "fr-FR" };
+// Per Peter E; expected result changed from "en-US" to "de-CH" per <rdar://problem/26559053>
+static const char * appleLocsM6[] = { "de-CH", "en-US" };
+static const char * prefLangsM6[] = { "de-DE", "en-US" };
+static const char * locsToUseM6[] = { "de-CH" };
+// The following is used for M7-MD
+static const char * appleLocsMx[] = { "de-DE", "en-AU", "es-ES", "fr-FR", "hi-IN", "pt-BR", "zh-HK", "zh-TW" };
+// Per Karan M
+static const char * prefLangsM7[] = { "fr-ES", "en-AU" };
+static const char * locsToUseM7[] = { "fr-FR" };
+// Per Karan M
+static const char * prefLangsM8[] = { "de-IT", "en-AU" };
+static const char * locsToUseM8[] = { "de-DE" };
+// Per Karan M
+static const char * prefLangsM9[] = { "hi-US", "en-AU" };
+static const char * locsToUseM9[] = { "hi-IN" };
+// Per Karan M
+static const char * prefLangsMA[] = { "en-IN", "zh-HK" };
+static const char * locsToUseMA[] = { "en-AU" };
+// Per Karan M
+static const char * prefLangsMB[] = { "pt-PT", "en-AU" };
+static const char * locsToUseMB[] = { "en-AU" };
+// per Paul B:
+static const char * prefLangsMC[] = { "pt-PT", "ar" };
+static const char * locsToUseMC[] = { "pt-BR" };
+// Per Karan M
+static const char * prefLangsMD[] = { "zh-CN", "en-AU" };
+static const char * locsToUseMD[] = { "en-AU" };
+// Per Karan M
+static const char * appleLocsME[] = { "de-DE", "en-AU", "es-ES", "fr-FR", "hi-IN", "pt-BR", "zh-CN", "zh-HK" };
+static const char * prefLangsME[] = { "zh-TW", "en-AU" };
+static const char * locsToUseME[] = { "zh-HK" };
+// Per Peter E in diagnosis for <rdar://problem/22012864> and <rdar://problem/23815194>
+static const char * appleLocsMF[] = { "en", "en-GB", "fr", "es" };
+static const char * prefLangsMF[] = { "en-IN", "en-GB", "de", "fr" };
+static const char * locsToUseMF[] = { "en-GB", "en" };
+// Per Karan M in <rdar://problem/23982460>
+static const char * appleLocsMG[] = { "zh-Hans", "zh-Hant", "zh-HK" };
+static const char * prefLangsMG[] = { "zh-Hans-US", "zh-HK", "en-US" };
+static const char * locsToUseMG[] = { "zh-Hans" };
+// Per <rdar://problem/25903891>
+static const char * appleLocsMH[] = { "zh-TW", "zh-CN", "zh-HK" };
+static const char * prefLangsMH[] = { "zh-Hans-HK", "zh-HK", "en" };
+static const char * locsToUseMH[] = { "zh-CN" };
+// Per <rdar://problem/26559053>
+static const char * appleLocsMI[] = { "unk", "en-US", "ar-SA" };
+static const char * prefLangsMI[] = { "ar-US" };
+static const char * locsToUseMI[] = { "ar-SA" };
+// Per <rdar://problem/30501523> - first for comparison with zh, then real test
+static const char * appleLocsMJ[] = { "zh-CN", "en-US" };
+static const char * prefLangsMJ[] = { "zh", "zh_AC" };
+static const char * locsToUseMJ[] = { "zh-CN" };
+static const char * appleLocsMK[] = { "yue-CN", "en-US" };
+static const char * prefLangsMK[] = { "yue", "yue_AC" };
+static const char * locsToUseMK[] = { "yue-CN" };
+// Per <rdar://problem/30433534>
+static const char * appleLocsML[] = { "nl_NL", "es_MX", "fr_FR", "zh_TW", "it_IT", "vi_VN", "fr_CH", "es_CL",
+ "en_ZA", "ko_KR", "ca_ES", "ro_RO", "en_PH", "en_CA", "en_SG", "en_IN",
+ "en_NZ", "it_CH", "fr_CA", "da_DK", "de_AT", "pt_BR", "yue_CN", "zh_CN",
+ "sv_SE", "es_ES", "ar_SA", "hu_HU", "fr_BE", "en_GB", "ja_JP", "zh_HK",
+ "fi_FI", "tr_TR", "nb_NO", "en_ID", "en_SA", "pl_PL", "ms_MY", "cs_CZ",
+ "el_GR", "id_ID", "hr_HR", "en_AE", "he_IL", "ru_RU", "wuu_CN", "de_DE",
+ "de_CH", "en_AU", "nl_BE", "th_TH", "pt_PT", "sk_SK", "en_US", "en_IE",
+ "es_CO", "uk_UA", "es_US" };
+static const char * prefLangsML[] = { "en-JP" };
+static const char * locsToUseML[] = { "en_US" };
+// Per <rdar://problem/32421203>
+static const char * appleLocsMM1[] = { "pt-PT" };
+static const char * appleLocsMM2[] = { "pt-BR" };
+static const char * appleLocsMM3[] = { "pt-PT", "pt-BR" };
+static const char * appleLocsMM4[] = { "en", "pt-PT" };
+static const char * appleLocsMM5[] = { "en", "pt-BR" };
+static const char * appleLocsMM6[] = { "en", "pt-PT", "pt-BR" };
+static const char * prefLangsMM1[] = { "pt-PT" };
+static const char * prefLangsMM2[] = { "pt-BR" };
+static const char * prefLangsMM3[] = { "pt" };
+static const char * prefLangsMM4[] = { "pt-PT", "en" };
+static const char * prefLangsMM5[] = { "pt-BR", "en" };
+static const char * prefLangsMM6[] = { "pt", "en" };
+static const char * locsToUseMMptPT[] = { "pt-PT" };
+static const char * locsToUseMMptBR[] = { "pt-BR" };
+static const char * locsToUseMMen[] = { "en" };
+// Per <rdar://problem/32658828>
+static const char * appleLocsMN[] = { "en-US", "en-GB" };
+static const char * prefLangsMN1[] = { "en-KR" };
+static const char * prefLangsMN2[] = { "en-SA" };
+static const char * prefLangsMN3[] = { "en-TW" };
+static const char * prefLangsMN4[] = { "en-JP" };
+static const char * locsToUseMN_U[] = { "en-US" };
+// Per <rdar://problem/36010857>
+static const char * appleLocsMO[] = { "Dutch", "French", "German", "Italian", "Japanese", "Spanish",
+ "ar", "ca", "cs", "da", "el", "en_AU", "en_GB", "en_IN",
+ "es_419", "fi", "fr_CA", "he", "hi", "hr", "hu", "id", "ko",
+ "ms", "no", "pl", "pt", "pt_PT", "ro", "ru", "sk", "sv",
+ "th", "tr", "uk", "vi", "zh_CN", "zh_HK", "zh_TW" };
+static const char * prefLangsMO1[] = { "en-US" };
+static const char * locsToUseMO1[] = { "en_GB" };
+
+typedef struct {
+ const char * name;
+ const char ** availLocs;
+ int32_t availLocsCount;
+ const char ** prefLangs;
+ int32_t prefLangsCount;
+ const char ** locsToUse;
+ int32_t locsToUseCount;
+} MultiPrefTest;
+
+static const MultiPrefTest multiTestSets[] = {
+ { "M1", appleLocsM1, UPRV_LENGTHOF(appleLocsM1), prefLangsM1, UPRV_LENGTHOF(prefLangsM1), locsToUseM1, UPRV_LENGTHOF(locsToUseM1) },
+ //
+ { "M2", appleLocsM2, UPRV_LENGTHOF(appleLocsM2), prefLangsM2, UPRV_LENGTHOF(prefLangsM2), locsToUseM2, UPRV_LENGTHOF(locsToUseM2) },
+ { "M3", appleLocsM3, UPRV_LENGTHOF(appleLocsM3), prefLangsM3, UPRV_LENGTHOF(prefLangsM3), locsToUseM3, UPRV_LENGTHOF(locsToUseM3) },
+ { "M4", appleLocsM4, UPRV_LENGTHOF(appleLocsM4), prefLangsM4, UPRV_LENGTHOF(prefLangsM4), locsToUseM4, UPRV_LENGTHOF(locsToUseM4) },
+ //
+ { "M5", appleLocsM5, UPRV_LENGTHOF(appleLocsM5), prefLangsM5, UPRV_LENGTHOF(prefLangsM5), locsToUseM5, UPRV_LENGTHOF(locsToUseM5) },
+ { "M6", appleLocsM6, UPRV_LENGTHOF(appleLocsM6), prefLangsM6, UPRV_LENGTHOF(prefLangsM6), locsToUseM6, UPRV_LENGTHOF(locsToUseM6) },
+ { "M7", appleLocsMx, UPRV_LENGTHOF(appleLocsMx), prefLangsM7, UPRV_LENGTHOF(prefLangsM7), locsToUseM7, UPRV_LENGTHOF(locsToUseM7) },
+ { "M8", appleLocsMx, UPRV_LENGTHOF(appleLocsMx), prefLangsM8, UPRV_LENGTHOF(prefLangsM8), locsToUseM8, UPRV_LENGTHOF(locsToUseM8) },
+ { "M9", appleLocsMx, UPRV_LENGTHOF(appleLocsMx), prefLangsM9, UPRV_LENGTHOF(prefLangsM9), locsToUseM9, UPRV_LENGTHOF(locsToUseM9) },
+ { "MA", appleLocsMx, UPRV_LENGTHOF(appleLocsMx), prefLangsMA, UPRV_LENGTHOF(prefLangsMA), locsToUseMA, UPRV_LENGTHOF(locsToUseMA) },
+ { "MB", appleLocsMx, UPRV_LENGTHOF(appleLocsMx), prefLangsMB, UPRV_LENGTHOF(prefLangsMB), locsToUseMB, UPRV_LENGTHOF(locsToUseMB) },
+ { "MC", appleLocsMx, UPRV_LENGTHOF(appleLocsMx), prefLangsMC, UPRV_LENGTHOF(prefLangsMC), locsToUseMC, UPRV_LENGTHOF(locsToUseMC) },
+ { "MD", appleLocsMx, UPRV_LENGTHOF(appleLocsMx), prefLangsMD, UPRV_LENGTHOF(prefLangsMD), locsToUseMD, UPRV_LENGTHOF(locsToUseMD) },
+ { "ME", appleLocsME, UPRV_LENGTHOF(appleLocsME), prefLangsME, UPRV_LENGTHOF(prefLangsME), locsToUseME, UPRV_LENGTHOF(locsToUseME) },
+ { "MF", appleLocsMF, UPRV_LENGTHOF(appleLocsMF), prefLangsMF, UPRV_LENGTHOF(prefLangsMF), locsToUseMF, UPRV_LENGTHOF(locsToUseMF) },
+ { "MG", appleLocsMG, UPRV_LENGTHOF(appleLocsMG), prefLangsMG, UPRV_LENGTHOF(prefLangsMG), locsToUseMG, UPRV_LENGTHOF(locsToUseMG) },
+ { "MH", appleLocsMH, UPRV_LENGTHOF(appleLocsMH), prefLangsMH, UPRV_LENGTHOF(prefLangsMH), locsToUseMH, UPRV_LENGTHOF(locsToUseMH) },
+ { "MI", appleLocsMI, UPRV_LENGTHOF(appleLocsMI), prefLangsMI, UPRV_LENGTHOF(prefLangsMI), locsToUseMI, UPRV_LENGTHOF(locsToUseMI) },
+ { "MJ", appleLocsMJ, UPRV_LENGTHOF(appleLocsMJ), prefLangsMJ, UPRV_LENGTHOF(prefLangsMJ), locsToUseMJ, UPRV_LENGTHOF(locsToUseMJ) },
+ { "MK", appleLocsMK, UPRV_LENGTHOF(appleLocsMK), prefLangsMK, UPRV_LENGTHOF(prefLangsMK), locsToUseMK, UPRV_LENGTHOF(locsToUseMK) },
+ { "ML", appleLocsML, UPRV_LENGTHOF(appleLocsML), prefLangsML, UPRV_LENGTHOF(prefLangsML), locsToUseML, UPRV_LENGTHOF(locsToUseML) },
+ { "MM11", appleLocsMM1, UPRV_LENGTHOF(appleLocsMM1), prefLangsMM1, UPRV_LENGTHOF(prefLangsMM1), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM21", appleLocsMM2, UPRV_LENGTHOF(appleLocsMM2), prefLangsMM1, UPRV_LENGTHOF(prefLangsMM1), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM31", appleLocsMM3, UPRV_LENGTHOF(appleLocsMM3), prefLangsMM1, UPRV_LENGTHOF(prefLangsMM1), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM41", appleLocsMM4, UPRV_LENGTHOF(appleLocsMM4), prefLangsMM1, UPRV_LENGTHOF(prefLangsMM1), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM51", appleLocsMM5, UPRV_LENGTHOF(appleLocsMM5), prefLangsMM1, UPRV_LENGTHOF(prefLangsMM1), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM61", appleLocsMM6, UPRV_LENGTHOF(appleLocsMM6), prefLangsMM1, UPRV_LENGTHOF(prefLangsMM1), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM12", appleLocsMM1, UPRV_LENGTHOF(appleLocsMM1), prefLangsMM2, UPRV_LENGTHOF(prefLangsMM2), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM22", appleLocsMM2, UPRV_LENGTHOF(appleLocsMM2), prefLangsMM2, UPRV_LENGTHOF(prefLangsMM2), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM32", appleLocsMM3, UPRV_LENGTHOF(appleLocsMM3), prefLangsMM2, UPRV_LENGTHOF(prefLangsMM2), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM42", appleLocsMM4, UPRV_LENGTHOF(appleLocsMM4), prefLangsMM2, UPRV_LENGTHOF(prefLangsMM2), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM52", appleLocsMM5, UPRV_LENGTHOF(appleLocsMM5), prefLangsMM2, UPRV_LENGTHOF(prefLangsMM2), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM62", appleLocsMM6, UPRV_LENGTHOF(appleLocsMM6), prefLangsMM2, UPRV_LENGTHOF(prefLangsMM2), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM13", appleLocsMM1, UPRV_LENGTHOF(appleLocsMM1), prefLangsMM3, UPRV_LENGTHOF(prefLangsMM3), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM23", appleLocsMM2, UPRV_LENGTHOF(appleLocsMM2), prefLangsMM3, UPRV_LENGTHOF(prefLangsMM3), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM33", appleLocsMM3, UPRV_LENGTHOF(appleLocsMM3), prefLangsMM3, UPRV_LENGTHOF(prefLangsMM3), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM43", appleLocsMM4, UPRV_LENGTHOF(appleLocsMM4), prefLangsMM3, UPRV_LENGTHOF(prefLangsMM3), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM53", appleLocsMM5, UPRV_LENGTHOF(appleLocsMM5), prefLangsMM3, UPRV_LENGTHOF(prefLangsMM3), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM63", appleLocsMM6, UPRV_LENGTHOF(appleLocsMM6), prefLangsMM3, UPRV_LENGTHOF(prefLangsMM3), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM14", appleLocsMM1, UPRV_LENGTHOF(appleLocsMM1), prefLangsMM4, UPRV_LENGTHOF(prefLangsMM4), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM24", appleLocsMM2, UPRV_LENGTHOF(appleLocsMM2), prefLangsMM4, UPRV_LENGTHOF(prefLangsMM4), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM34", appleLocsMM3, UPRV_LENGTHOF(appleLocsMM3), prefLangsMM4, UPRV_LENGTHOF(prefLangsMM4), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM44", appleLocsMM4, UPRV_LENGTHOF(appleLocsMM4), prefLangsMM4, UPRV_LENGTHOF(prefLangsMM4), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM54", appleLocsMM5, UPRV_LENGTHOF(appleLocsMM5), prefLangsMM4, UPRV_LENGTHOF(prefLangsMM4), locsToUseMMen, UPRV_LENGTHOF(locsToUseMMen) }, // want en, see <rdar://problem/22012864>
+ { "MM64", appleLocsMM6, UPRV_LENGTHOF(appleLocsMM6), prefLangsMM4, UPRV_LENGTHOF(prefLangsMM4), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM15", appleLocsMM1, UPRV_LENGTHOF(appleLocsMM1), prefLangsMM5, UPRV_LENGTHOF(prefLangsMM5), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM25", appleLocsMM2, UPRV_LENGTHOF(appleLocsMM2), prefLangsMM5, UPRV_LENGTHOF(prefLangsMM5), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM35", appleLocsMM3, UPRV_LENGTHOF(appleLocsMM3), prefLangsMM5, UPRV_LENGTHOF(prefLangsMM5), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM45", appleLocsMM4, UPRV_LENGTHOF(appleLocsMM4), prefLangsMM5, UPRV_LENGTHOF(prefLangsMM5), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM55", appleLocsMM5, UPRV_LENGTHOF(appleLocsMM5), prefLangsMM5, UPRV_LENGTHOF(prefLangsMM5), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM65", appleLocsMM6, UPRV_LENGTHOF(appleLocsMM6), prefLangsMM5, UPRV_LENGTHOF(prefLangsMM5), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM16", appleLocsMM1, UPRV_LENGTHOF(appleLocsMM1), prefLangsMM6, UPRV_LENGTHOF(prefLangsMM6), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM26", appleLocsMM2, UPRV_LENGTHOF(appleLocsMM2), prefLangsMM6, UPRV_LENGTHOF(prefLangsMM6), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM36", appleLocsMM3, UPRV_LENGTHOF(appleLocsMM3), prefLangsMM6, UPRV_LENGTHOF(prefLangsMM6), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM46", appleLocsMM4, UPRV_LENGTHOF(appleLocsMM4), prefLangsMM6, UPRV_LENGTHOF(prefLangsMM6), locsToUseMMptPT, UPRV_LENGTHOF(locsToUseMMptPT) },
+ { "MM56", appleLocsMM5, UPRV_LENGTHOF(appleLocsMM5), prefLangsMM6, UPRV_LENGTHOF(prefLangsMM6), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MM66", appleLocsMM6, UPRV_LENGTHOF(appleLocsMM6), prefLangsMM6, UPRV_LENGTHOF(prefLangsMM6), locsToUseMMptBR, UPRV_LENGTHOF(locsToUseMMptBR) },
+ { "MN1", appleLocsMN, UPRV_LENGTHOF(appleLocsMN), prefLangsMN1, UPRV_LENGTHOF(prefLangsMN1), locsToUseMN_U, UPRV_LENGTHOF(locsToUseMN_U) },
+ { "MN2", appleLocsMN, UPRV_LENGTHOF(appleLocsMN), prefLangsMN2, UPRV_LENGTHOF(prefLangsMN2), locsToUseMN_U, UPRV_LENGTHOF(locsToUseMN_U) },
+ { "MN3", appleLocsMN, UPRV_LENGTHOF(appleLocsMN), prefLangsMN3, UPRV_LENGTHOF(prefLangsMN3), locsToUseMN_U, UPRV_LENGTHOF(locsToUseMN_U) },
+ { "MN4", appleLocsMN, UPRV_LENGTHOF(appleLocsMN), prefLangsMN4, UPRV_LENGTHOF(prefLangsMN4), locsToUseMN_U, UPRV_LENGTHOF(locsToUseMN_U) },
+ { "MO", appleLocsMO, UPRV_LENGTHOF(appleLocsMO), prefLangsMO1, UPRV_LENGTHOF(prefLangsMO1), locsToUseMO1, UPRV_LENGTHOF(locsToUseMO1) },
+
+ { NULL, NULL, 0, NULL, 0, NULL, 0 }
+};
+
+
+/* general enums */
+
+enum { kMaxLocalizationsToUse = 8, kPrintArrayBufSize = 128 };
+
+// array, array of pointers to strings to print
+// count, count of array elements, may be -1 if array is terminated by a NULL entry
+// buf, buffer into which to put concatenated strings
+// bufSize, length of buf
+static void printStringArray(const char **array, int32_t count, char *buf, int32_t bufSize) {
+ char * bufPtr = buf;
+ const char * curEntry;
+ int32_t idx, countMax = bufSize/16;
+ if (count < 0 || count > countMax) {
+ count = countMax;
+ }
+ for (idx = 0; idx < count && (curEntry = *array++) != NULL; idx++) {
+ int32_t len = sprintf(bufPtr, "%s\"%.12s\"", (idx > 0)? ", ": "", curEntry);
+ if (len <= 0) {
+ break;
+ }
+ bufPtr += len;
+ }
+ *bufPtr = 0; /* ensure termination */
+}
+
+static UBool equalStringArrays(const char **array1, int32_t count1, const char **array2, int32_t count2) {
+ const char ** array1Ptr = array1;
+ const char ** array2Ptr = array2;
+ int32_t idx;
+ if (count1 < 0) {
+ count1 = 0;
+ while (*array1Ptr++ != NULL) {
+ count1++;
+ }
+ }
+ if (count2 < 0) {
+ count2 = 0;
+ while (*array2Ptr++ != NULL) {
+ count2++;
+ }
+ }
+ if (count1 != count2) {
+ return FALSE;
+ }
+ for (idx = 0; idx < count1; idx++) {
+ if (uprv_strcmp(array1[idx], array2[idx]) != 0) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+static void TestAppleLocalizationsToUse() {
+ const AppleLocToUseTestSet * testSetPtr;
+ const MultiPrefTest * multiSetPtr;
+ const char * locsToUse[kMaxLocalizationsToUse];
+ int32_t numLocsToUse;
+ UErrorCode status;
+ char printExpected[kPrintArrayBufSize];
+ char printActual[kPrintArrayBufSize];
+
+ for (testSetPtr = altuTestSets; testSetPtr->locAndCountEntriesPtr != NULL; testSetPtr++) {
+ int32_t iLocSet, iLang;
+
+ for (iLocSet = 0; iLocSet < kNumLocSets; iLocSet++) {
+ for (iLang = 0; iLang < testSetPtr->appleLangAndLocCount; iLang++) {
+ const char * language = testSetPtr->appleLangAndLocPtr[iLang].language;
+ const char ** expLocsForSet = testSetPtr->appleLangAndLocPtr[iLang].expLocsForSets[iLocSet];
+ status = U_ZERO_ERROR;
+
+ numLocsToUse = ualoc_localizationsToUse(&language, 1,
+ testSetPtr->locAndCountEntriesPtr[iLocSet].locs, testSetPtr->locAndCountEntriesPtr[iLocSet].locCount,
+ locsToUse, kMaxLocalizationsToUse, &status);
+ if (U_FAILURE(status)) {
+ log_err("FAIL: ualoc_localizationsToUse testSet %d, locSet %d, lang %s, status %s\n",
+ testSetPtr-altuTestSets, iLocSet+1, language, u_errorName(status));
+ } else if (numLocsToUse == 0 && expLocsForSet != NULL) {
+ printStringArray(expLocsForSet, -1, printExpected, kPrintArrayBufSize);
+ log_err("FAIL: ualoc_localizationsToUse testSet %d, locSet %d, lang %s, expect {%s}, get no results\n",
+ testSetPtr-altuTestSets, iLocSet+1, language, printExpected);
+ } else if (numLocsToUse > 0 && expLocsForSet == NULL) {
+ printStringArray(locsToUse, numLocsToUse, printActual, kPrintArrayBufSize);
+ log_err("FAIL: ualoc_localizationsToUse testSet %d, locSet %d, lang %s, expect no results, get {%s}\n",
+ testSetPtr-altuTestSets, iLocSet+1, language, printActual);
+ } else if (numLocsToUse > 0 && !equalStringArrays(expLocsForSet, -1, locsToUse, numLocsToUse)) {
+ printStringArray(expLocsForSet, -1, printExpected, kPrintArrayBufSize);
+ printStringArray(locsToUse, numLocsToUse, printActual, kPrintArrayBufSize);
+ log_err("FAIL: ualoc_localizationsToUse testSet %d, locSet %d, lang %s:\n expect {%s}\n get {%s}\n",
+ testSetPtr-altuTestSets, iLocSet+1, language, printExpected, printActual);
+ }
+ }
+ }
+ }
+
+ for (multiSetPtr = multiTestSets; multiSetPtr->name != NULL; multiSetPtr++) {
+ status = U_ZERO_ERROR;
+ numLocsToUse = ualoc_localizationsToUse(multiSetPtr->prefLangs, multiSetPtr->prefLangsCount, multiSetPtr->availLocs, multiSetPtr->availLocsCount, locsToUse, kMaxLocalizationsToUse, &status);
+ if (U_FAILURE(status)) {
+ log_err("FAIL: ualoc_localizationsToUse appleLocs%s, langs prefLangs%s, status %s\n", multiSetPtr->name, multiSetPtr->name, u_errorName(status));
+ } else if (!equalStringArrays(multiSetPtr->locsToUse, multiSetPtr->locsToUseCount, locsToUse, numLocsToUse)) {
+ printStringArray(multiSetPtr->locsToUse, multiSetPtr->locsToUseCount, printExpected, kPrintArrayBufSize);
+ printStringArray(locsToUse, numLocsToUse, printActual, kPrintArrayBufSize);
+ log_err("FAIL: ualoc_localizationsToUse appleLocs%s, langs prefLangs%s:\n expect {%s}\n get {%s}\n",
+ multiSetPtr->name, multiSetPtr->name, printExpected, printActual);
+ }
+ }
+}
+