Home | History | Annotate | Download | only in intltest
      1 //  2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html
      3 /*********************************************************************
      4  * COPYRIGHT:
      5  * Copyright (c) 2010-2016, International Business Machines Corporation and
      6  * others. All Rights Reserved.
      7  *********************************************************************/
      8 
      9 #include "locnmtst.h"
     10 #include "unicode/ustring.h"
     11 #include "cstring.h"
     12 
     13 /*
     14  Usage:
     15     test_assert(    Test (should be TRUE)  )
     16 
     17    Example:
     18        test_assert(i==3);
     19 
     20    the macro is ugly but makes the tests pretty.
     21 */
     22 
     23 #define test_assert(test) \
     24     { \
     25         if(!(test)) \
     26             errln("FAIL: " #test " was not true. In " __FILE__ " on line %d", __LINE__ ); \
     27         else \
     28             logln("PASS: asserted " #test); \
     29     }
     30 
     31 /*
     32  Usage:
     33     test_assert_print(    Test (should be TRUE),  printable  )
     34 
     35    Example:
     36        test_assert(i==3, toString(i));
     37 
     38    the macro is ugly but makes the tests pretty.
     39 */
     40 
     41 #define test_assert_print(test,print) \
     42     { \
     43         if(!(test)) \
     44             errln("FAIL: " #test " was not true. " + UnicodeString(print) ); \
     45         else \
     46             logln("PASS: asserted " #test "-> " + UnicodeString(print)); \
     47     }
     48 
     49 #define test_assert_equal(target,value) \
     50   { \
     51     if (UnicodeString(target)!=(value)) { \
     52       logln("unexpected value '" + (value) + "'"); \
     53       dataerrln("FAIL: " #target " == " #value " was not true. In " __FILE__ " on line %d", __LINE__); \
     54     } else { \
     55       logln("PASS: asserted " #target " == " #value); \
     56     } \
     57   }
     58 
     59 #define test_dumpLocale(l) { logln(#l " = " + UnicodeString(l.getName(), "")); }
     60 
     61 LocaleDisplayNamesTest::LocaleDisplayNamesTest() {
     62 }
     63 
     64 LocaleDisplayNamesTest::~LocaleDisplayNamesTest() {
     65 }
     66 
     67 void LocaleDisplayNamesTest::runIndexedTest(int32_t index, UBool exec, const char* &name,
     68                         char* /*par*/) {
     69     switch (index) {
     70 #if !UCONFIG_NO_FORMATTING
     71         TESTCASE(0, TestCreate);
     72         TESTCASE(1, TestCreateDialect);
     73         TESTCASE(2, TestWithKeywordsAndEverything);
     74         TESTCASE(3, TestUldnOpen);
     75         TESTCASE(4, TestUldnOpenDialect);
     76         TESTCASE(5, TestUldnWithKeywordsAndEverything);
     77         TESTCASE(6, TestUldnComponents);
     78         TESTCASE(7, TestRootEtc);
     79         TESTCASE(8, TestCurrencyKeyword);
     80         TESTCASE(9, TestUnknownCurrencyKeyword);
     81         TESTCASE(10, TestUntranslatedKeywords);
     82         TESTCASE(11, TestPrivateUse);
     83         TESTCASE(12, TestUldnDisplayContext);
     84         TESTCASE(13, TestUldnWithGarbage);
     85 #endif
     86         default:
     87             name = "";
     88             break;
     89     }
     90 }
     91 
     92 #if !UCONFIG_NO_FORMATTING
     93 void LocaleDisplayNamesTest::TestCreate() {
     94   UnicodeString temp;
     95   LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getGermany());
     96   ldn->localeDisplayName("de_DE", temp);
     97   delete ldn;
     98   test_assert_equal("Deutsch (Deutschland)", temp);
     99 }
    100 
    101 void LocaleDisplayNamesTest::TestCreateDialect() {
    102   UnicodeString temp;
    103   LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS(), ULDN_DIALECT_NAMES);
    104   ldn->localeDisplayName("en_GB", temp);
    105   delete ldn;
    106   test_assert_equal("British English", temp);
    107 }
    108 
    109 void LocaleDisplayNamesTest::TestWithKeywordsAndEverything() {
    110   UnicodeString temp;
    111   LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS());
    112   const char *locname = "en_Hant_US_VALLEY@calendar=gregorian;collation=phonebook";
    113   const char *target = "English (Traditional, United States, VALLEY, "
    114     "Gregorian Calendar, Phonebook Sort Order)";
    115   ldn->localeDisplayName(locname, temp);
    116   delete ldn;
    117   test_assert_equal(target, temp);
    118 }
    119 
    120 void LocaleDisplayNamesTest::TestCurrencyKeyword() {
    121   UnicodeString temp;
    122   LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS());
    123   const char *locname = "ja@currency=JPY";
    124   const char *target = "Japanese (Japanese Yen)";
    125   ldn->localeDisplayName(locname, temp);
    126   delete ldn;
    127   test_assert_equal(target, temp);
    128 }
    129 
    130 void LocaleDisplayNamesTest::TestUnknownCurrencyKeyword() {
    131   UnicodeString temp;
    132   LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS());
    133   const char *locname = "de@currency=XYZ";
    134   const char *target = "German (Currency: XYZ)";
    135   ldn->localeDisplayName(locname, temp);
    136   delete ldn;
    137   test_assert_equal(target, temp);
    138 }
    139 
    140 void LocaleDisplayNamesTest::TestUntranslatedKeywords() {
    141   UnicodeString temp;
    142   LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS());
    143   const char *locname = "de@foo=bar";
    144   const char *target = "German (foo=bar)";
    145   ldn->localeDisplayName(locname, temp);
    146   delete ldn;
    147   test_assert_equal(target, temp);
    148 }
    149 
    150 void LocaleDisplayNamesTest::TestPrivateUse() {
    151   UnicodeString temp;
    152   LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS());
    153   const char *locname = "de@x=foobar";
    154   const char *target = "German (Private-Use: foobar)";
    155   ldn->localeDisplayName(locname, temp);
    156   delete ldn;
    157   test_assert_equal(target, temp);
    158 }
    159 
    160 void LocaleDisplayNamesTest::TestUldnOpen() {
    161   UErrorCode status = U_ZERO_ERROR;
    162   const int32_t kMaxResultSize = 150;  // long enough
    163   UChar result[150];
    164   ULocaleDisplayNames *ldn = uldn_open(Locale::getGermany().getName(), ULDN_STANDARD_NAMES, &status);
    165   int32_t len = uldn_localeDisplayName(ldn, "de_DE", result, kMaxResultSize, &status);
    166   uldn_close(ldn);
    167   test_assert(U_SUCCESS(status));
    168 
    169   UnicodeString str(result, len, kMaxResultSize);
    170   test_assert_equal("Deutsch (Deutschland)", str);
    171 
    172   // make sure that NULL gives us the default locale as usual
    173   ldn = uldn_open(NULL, ULDN_STANDARD_NAMES, &status);
    174   const char *locale = uldn_getLocale(ldn);
    175   if(0 != uprv_strcmp(uloc_getDefault(), locale)) {
    176     errln("uldn_getLocale(uldn_open(NULL))=%s != default locale %s\n", locale, uloc_getDefault());
    177   }
    178   uldn_close(ldn);
    179   test_assert(U_SUCCESS(status));
    180 }
    181 
    182 void LocaleDisplayNamesTest::TestUldnOpenDialect() {
    183   UErrorCode status = U_ZERO_ERROR;
    184   const int32_t kMaxResultSize = 150;  // long enough
    185   UChar result[150];
    186   ULocaleDisplayNames *ldn = uldn_open(Locale::getUS().getName(), ULDN_DIALECT_NAMES, &status);
    187   int32_t len = uldn_localeDisplayName(ldn, "en_GB", result, kMaxResultSize, &status);
    188   uldn_close(ldn);
    189   test_assert(U_SUCCESS(status));
    190 
    191   UnicodeString str(result, len, kMaxResultSize);
    192   test_assert_equal("British English", str);
    193 }
    194 
    195 void LocaleDisplayNamesTest::TestUldnWithGarbage() {
    196   UErrorCode status = U_ZERO_ERROR;
    197   const int32_t kMaxResultSize = 150;  // long enough
    198   UChar result[150];
    199   ULocaleDisplayNames *ldn = uldn_open(Locale::getUS().getName(), ULDN_DIALECT_NAMES, &status);
    200   int32_t len = uldn_localeDisplayName(ldn, "english (United States) [w", result, kMaxResultSize, &status);
    201   uldn_close(ldn);
    202   test_assert(U_FAILURE(status) && len == 0);
    203 }
    204 
    205 void LocaleDisplayNamesTest::TestUldnWithKeywordsAndEverything() {
    206   UErrorCode status = U_ZERO_ERROR;
    207   const int32_t kMaxResultSize = 150;  // long enough
    208   UChar result[150];
    209   const char *locname = "en_Hant_US_VALLEY@calendar=gregorian;collation=phonebook";
    210   const char *target = "English (Traditional, United States, VALLEY, "
    211     "Gregorian Calendar, Phonebook Sort Order)";
    212   ULocaleDisplayNames *ldn = uldn_open(Locale::getUS().getName(), ULDN_STANDARD_NAMES, &status);
    213   int32_t len = uldn_localeDisplayName(ldn, locname, result, kMaxResultSize, &status);
    214   uldn_close(ldn);
    215   test_assert(U_SUCCESS(status));
    216 
    217   UnicodeString str(result, len, kMaxResultSize);
    218   test_assert_equal(target, str);
    219 }
    220 
    221 void LocaleDisplayNamesTest::TestUldnComponents() {
    222   UErrorCode status = U_ZERO_ERROR;
    223   const int32_t kMaxResultSize = 150;  // long enough
    224   UChar result[150];
    225 
    226   ULocaleDisplayNames *ldn = uldn_open(Locale::getGermany().getName(), ULDN_STANDARD_NAMES, &status);
    227   test_assert(U_SUCCESS(status));
    228   if (U_FAILURE(status)) {
    229     return;
    230   }
    231 
    232   // "en_Hant_US_PRE_EURO@calendar=gregorian";
    233 
    234   {
    235     int32_t len = uldn_languageDisplayName(ldn, "en", result, kMaxResultSize, &status);
    236     UnicodeString str(result, len, kMaxResultSize);
    237     test_assert_equal("Englisch", str);
    238   }
    239 
    240 
    241   {
    242     int32_t len = uldn_scriptDisplayName(ldn, "Hant", result, kMaxResultSize, &status);
    243     UnicodeString str(result, len, kMaxResultSize);
    244     test_assert_equal("Traditionell", str);
    245   }
    246 
    247   {
    248     int32_t len = uldn_scriptCodeDisplayName(ldn, USCRIPT_TRADITIONAL_HAN, result, kMaxResultSize,
    249                          &status);
    250     UnicodeString str(result, len, kMaxResultSize);
    251     test_assert_equal("Traditionell", str);
    252   }
    253 
    254   {
    255     int32_t len = uldn_regionDisplayName(ldn, "US", result, kMaxResultSize, &status);
    256     UnicodeString str(result, len, kMaxResultSize);
    257     test_assert_equal("Vereinigte Staaten", str);
    258   }
    259 
    260   {
    261     int32_t len = uldn_variantDisplayName(ldn, "PRE_EURO", result, kMaxResultSize, &status);
    262     UnicodeString str(result, len, kMaxResultSize);
    263     test_assert_equal("PRE_EURO", str);
    264   }
    265 
    266   {
    267     int32_t len = uldn_keyDisplayName(ldn, "calendar", result, kMaxResultSize, &status);
    268     UnicodeString str(result, len, kMaxResultSize);
    269     test_assert_equal("Kalender", str);
    270   }
    271 
    272   {
    273     int32_t len = uldn_keyValueDisplayName(ldn, "calendar", "gregorian", result,
    274                        kMaxResultSize, &status);
    275     UnicodeString str(result, len, kMaxResultSize);
    276     test_assert_equal("Gregorianischer Kalender", str);
    277   }
    278 
    279   uldn_close(ldn);
    280 }
    281 
    282 
    283 typedef struct {
    284     const char * displayLocale;
    285     UDisplayContext dialectHandling;
    286     UDisplayContext capitalization;
    287     UDisplayContext displayLength;
    288     const char * localeToBeNamed;
    289     const UChar * result;
    290 } LocNameDispContextItem;
    291 
    292 static char en[] = "en";
    293 static char en_cabud[] = "en@calendar=buddhist";
    294 static char en_GB[] = "en_GB";
    295 static char uz_Latn[] = "uz_Latn";
    296 
    297 static UChar daFor_en[]       = {0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"engelsk"
    298 static UChar daFor_en_cabud[] = {0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x62,0x75,0x64,0x64,0x68,0x69,0x73,0x74,0x69,0x73,0x6B,0x20,
    299                                  0x6B,0x61,0x6C,0x65,0x6E,0x64,0x65,0x72,0x29,0}; //"engelsk (buddhistisk kalender)"
    300 static UChar daFor_en_GB[]    = {0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x53,0x74,0x6F,0x72,0x62,0x72,0x69,0x74,0x61,0x6E,0x6E,0x69,0x65,0x6E,0x29,0}; //"engelsk (Storbritannien)"
    301 static UChar daFor_en_GB_S[]  = {0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x55,0x4B,0x29,0}; //"engelsk (UK)"
    302 static UChar daFor_en_GB_D[]  = {0x62,0x72,0x69,0x74,0x69,0x73,0x6B,0x20,0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"britisk engelsk"
    303 static UChar esFor_en[]       = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0}; //"ingles" with acute on the e
    304 static UChar esFor_en_GB[]    = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x65,0x69,0x6E,0x6F,0x20,0x55,0x6E,0x69,0x64,0x6F,0x29,0}; //"ingles (Reino Unido)" ...
    305 static UChar esFor_en_GB_S[]  = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x55,0x29,0}; //"ingles (RU)" ...
    306 static UChar esFor_en_GB_D[]  = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x62,0x72,0x69,0x74,0xE1,0x6E,0x69,0x63,0x6F,0}; //"ingles britanico" with acute on the e, a
    307 static UChar ruFor_uz_Latn[]  = {0x0443,0x0437,0x0431,0x0435,0x043A,0x0441,0x043A,0x0438,0x0439,0x20,0x28,0x043B,0x0430,0x0442,0x0438,0x043D,0x0438,0x0446,0x0430,0x29,0}; // all lowercase
    308 #if !UCONFIG_NO_BREAK_ITERATION
    309 static UChar daFor_en_T[]     = {0x45,0x6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"Engelsk"
    310 static UChar daFor_en_cabudT[]= {0x45,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x62,0x75,0x64,0x64,0x68,0x69,0x73,0x74,0x69,0x73,0x6B,0x20,
    311                                  0x6B,0x61,0x6C,0x65,0x6E,0x64,0x65,0x72,0x29,0}; //"Engelsk (buddhistisk kalender)"
    312 static UChar daFor_en_GB_T[]  = {0x45,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x53,0x74,0x6F,0x72,0x62,0x72,0x69,0x74,0x61,0x6E,0x6E,0x69,0x65,0x6E,0x29,0}; //"Engelsk (Storbritannien)"
    313 static UChar daFor_en_GB_ST[] = {0x45,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x55,0x4B,0x29,0}; //"Engelsk (UK)"
    314 static UChar daFor_en_GB_DT[] = {0x42,0x72,0x69,0x74,0x69,0x73,0x6B,0x20,0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"Britisk engelsk"
    315 static UChar esFor_en_T[]     = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0}; //"Ingles" with acute on the e
    316 static UChar esFor_en_GB_T[]  = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x65,0x69,0x6E,0x6F,0x20,0x55,0x6E,0x69,0x64,0x6F,0x29,0}; //"Ingles (Reino Unido)" ...
    317 static UChar esFor_en_GB_ST[] = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x55,0x29,0}; //"Ingles (RU)" ...
    318 static UChar esFor_en_GB_DT[] = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x62,0x72,0x69,0x74,0xE1,0x6E,0x69,0x63,0x6F,0}; //"Ingles britanico" with acute on the e, a
    319 static UChar ruFor_uz_Latn_T[]= {0x0423,0x0437,0x0431,0x0435,0x043A,0x0441,0x043A,0x0438,0x0439,0x20,0x28,0x043B,0x0430,0x0442,0x0438,0x043D,0x0438,0x0446,0x0430,0x29,0}; // first char upper
    320 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
    321 
    322 static const LocNameDispContextItem ctxtItems[] = {
    323     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    UDISPCTX_LENGTH_FULL,   en,    daFor_en },
    324     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    UDISPCTX_LENGTH_FULL,   en_cabud, daFor_en_cabud },
    325     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    UDISPCTX_LENGTH_FULL,   en_GB, daFor_en_GB },
    326     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    UDISPCTX_LENGTH_SHORT,  en_GB, daFor_en_GB_S },
    327     { "da", UDISPCTX_DIALECT_NAMES,  UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    UDISPCTX_LENGTH_FULL,   en_GB, daFor_en_GB_D },
    328     { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    UDISPCTX_LENGTH_FULL,   en,    esFor_en },
    329     { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    UDISPCTX_LENGTH_FULL,   en_GB, esFor_en_GB },
    330     { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    UDISPCTX_LENGTH_SHORT,  en_GB, esFor_en_GB_S },
    331     { "es", UDISPCTX_DIALECT_NAMES,  UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    UDISPCTX_LENGTH_FULL,   en_GB, esFor_en_GB_D },
    332     { "ru", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,    UDISPCTX_LENGTH_FULL,   uz_Latn, ruFor_uz_Latn },
    333 #if !UCONFIG_NO_BREAK_ITERATION
    334     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL,   en,    daFor_en_T },
    335     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL,   en_cabud, daFor_en_cabudT },
    336     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL,   en_GB, daFor_en_GB_T },
    337     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_SHORT,  en_GB, daFor_en_GB_ST },
    338     { "da", UDISPCTX_DIALECT_NAMES,  UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL,   en_GB, daFor_en_GB_DT },
    339     { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL,   en,    esFor_en_T },
    340     { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL,   en_GB, esFor_en_GB_T },
    341     { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_SHORT,  en_GB, esFor_en_GB_ST },
    342     { "es", UDISPCTX_DIALECT_NAMES,  UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL,   en_GB, esFor_en_GB_DT },
    343     { "ru", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL,   uz_Latn, ruFor_uz_Latn_T },
    344 
    345     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU,       UDISPCTX_LENGTH_FULL,   en,    daFor_en_T },
    346     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU,       UDISPCTX_LENGTH_FULL,   en_cabud, daFor_en_cabudT },
    347     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU,       UDISPCTX_LENGTH_FULL,   en_GB, daFor_en_GB_T },
    348     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU,       UDISPCTX_LENGTH_SHORT,  en_GB, daFor_en_GB_ST },
    349     { "da", UDISPCTX_DIALECT_NAMES,  UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU,       UDISPCTX_LENGTH_FULL,   en_GB, daFor_en_GB_DT },
    350     { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU,       UDISPCTX_LENGTH_FULL,   en,    esFor_en_T },
    351     { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU,       UDISPCTX_LENGTH_FULL,   en_GB, esFor_en_GB_T },
    352     { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU,       UDISPCTX_LENGTH_SHORT,  en_GB, esFor_en_GB_ST },
    353     { "es", UDISPCTX_DIALECT_NAMES,  UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU,       UDISPCTX_LENGTH_FULL,   en_GB, esFor_en_GB_DT },
    354     { "ru", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU,       UDISPCTX_LENGTH_FULL,   uz_Latn, ruFor_uz_Latn_T },
    355 
    356     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,            UDISPCTX_LENGTH_FULL,   en,    daFor_en },
    357     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,            UDISPCTX_LENGTH_FULL,   en_cabud, daFor_en_cabud },
    358     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,            UDISPCTX_LENGTH_FULL,   en_GB, daFor_en_GB },
    359     { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,            UDISPCTX_LENGTH_SHORT,  en_GB, daFor_en_GB_S },
    360     { "da", UDISPCTX_DIALECT_NAMES,  UDISPCTX_CAPITALIZATION_FOR_STANDALONE,            UDISPCTX_LENGTH_FULL,   en_GB, daFor_en_GB_D },
    361     { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,            UDISPCTX_LENGTH_FULL,   en,    esFor_en_T },
    362     { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,            UDISPCTX_LENGTH_FULL,   en_GB, esFor_en_GB_T },
    363     { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,            UDISPCTX_LENGTH_SHORT,  en_GB, esFor_en_GB_ST },
    364     { "es", UDISPCTX_DIALECT_NAMES,  UDISPCTX_CAPITALIZATION_FOR_STANDALONE,            UDISPCTX_LENGTH_FULL,   en_GB, esFor_en_GB_DT },
    365     { "ru", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,            UDISPCTX_LENGTH_FULL,   uz_Latn, ruFor_uz_Latn_T },
    366  #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
    367     { NULL, (UDisplayContext)0,      (UDisplayContext)0,                                (UDisplayContext)0,     NULL,  NULL }
    368 };
    369 
    370 void LocaleDisplayNamesTest::TestUldnDisplayContext() {
    371     const LocNameDispContextItem * ctxtItemPtr;
    372     for (ctxtItemPtr = ctxtItems; ctxtItemPtr->displayLocale != NULL; ctxtItemPtr++) {
    373         UDisplayContext contexts[3] = {ctxtItemPtr->dialectHandling, ctxtItemPtr->capitalization, ctxtItemPtr->displayLength};
    374         UErrorCode status = U_ZERO_ERROR;
    375         ULocaleDisplayNames * uldn = uldn_openForContext(ctxtItemPtr->displayLocale, contexts, 3, &status);
    376         if (U_FAILURE(status)) {
    377             errln(UnicodeString("FAIL: uldn_openForContext failed for locale ") + ctxtItemPtr->displayLocale +
    378                   ", dialectHandling " + ctxtItemPtr->dialectHandling +
    379                   ", capitalization " +  ctxtItemPtr->capitalization +
    380                   ", displayLength " +  ctxtItemPtr->displayLength);
    381         } else {
    382             UDisplayContext dialectHandling = uldn_getContext(uldn, UDISPCTX_TYPE_DIALECT_HANDLING, &status);
    383             UDisplayContext capitalization = uldn_getContext(uldn, UDISPCTX_TYPE_CAPITALIZATION, &status);
    384             UDisplayContext displayLength = uldn_getContext(uldn, UDISPCTX_TYPE_DISPLAY_LENGTH, &status);
    385             if (U_FAILURE(status)) {
    386                 errln(UnicodeString("FAIL: uldn_getContext status ") + (int)status);
    387             } else if (dialectHandling != ctxtItemPtr->dialectHandling ||
    388                        capitalization != ctxtItemPtr->capitalization ||
    389                        displayLength != ctxtItemPtr->displayLength) {
    390                 errln("FAIL: uldn_getContext retrieved incorrect dialectHandling, capitalization, or displayLength");
    391             } else {
    392                 UChar nameBuf[ULOC_FULLNAME_CAPACITY];
    393                 int32_t len = uldn_localeDisplayName(uldn, ctxtItemPtr->localeToBeNamed, nameBuf, ULOC_FULLNAME_CAPACITY, &status);
    394                 if (U_FAILURE(status)) {
    395                     dataerrln(UnicodeString("FAIL: uldn_localeDisplayName status: ") + u_errorName(status));
    396                 } else if (u_strcmp(ctxtItemPtr->result, nameBuf) != 0) {
    397                     UnicodeString exp(ctxtItemPtr->result, u_strlen(ctxtItemPtr->result));
    398                     UnicodeString got(nameBuf, len);
    399                     dataerrln(UnicodeString("FAIL: uldn_localeDisplayName, capitalization ") + ctxtItemPtr->capitalization +
    400                           ", expected " + exp + ", got " + got );
    401                 }
    402             }
    403             uldn_close(uldn);
    404         }
    405     }
    406 }
    407 
    408 void LocaleDisplayNamesTest::TestRootEtc() {
    409   UnicodeString temp;
    410   LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS());
    411   const char *locname = "@collation=phonebook";
    412   const char *target = "Root (Phonebook Sort Order)";
    413   ldn->localeDisplayName(locname, temp);
    414   test_assert_equal(target, temp);
    415 
    416   ldn->languageDisplayName("root", temp);
    417   test_assert_equal("root", temp);
    418 
    419   ldn->languageDisplayName("en_GB", temp);
    420   test_assert_equal("en_GB", temp);
    421 
    422   delete ldn;
    423 }
    424 
    425 #endif   /*  UCONFIG_NO_FORMATTING */
    426