+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, "R.A.S. chinoise de Hong Kong" },
+};
+
+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.)" },
+};
+
+static const UldnItem fr_DiaMidLong[] = {
+ { "en_US", TEST_ULDN_LOCALE, "anglais am\\u00E9ricain" },
+};
+
+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", optDiaMidLong, fr_DiaMidLong, UPRV_LENGTHOF(fr_DiaMidLong) },
+ { 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);
+ }
+}
+