Home | History | Annotate | Download | only in tests
      1 //  2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html#License
      3 /*
      4  *******************************************************************************
      5  * Copyright (C) 2006-2011, International Business Machines Corporation and    *
      6  * others. All Rights Reserved.                                                *
      7  *******************************************************************************
      8  */
      9 
     10 package com.ibm.icu.tests;
     11 
     12 import java.util.Iterator;
     13 import java.util.Locale;
     14 
     15 import com.ibm.icu.util.ULocale;
     16 import com.ibm.icu.util.ULocale.Category;
     17 
     18 public class ULocaleTest extends ICUTestCase {
     19     private String sampleName;
     20     private String longULocaleName;
     21     private String longULocaleBasename;
     22     private String nonNormalizedName;
     23     private ULocale longULocale;
     24     private Locale sampleLocale;
     25 
     26     /**
     27      * @Override
     28      */
     29     protected void setUp() throws Exception {
     30         super.setUp();
     31 
     32         sampleName = "ll_CC_VVVV";
     33         longULocaleName = "ll_Ssss_CC_VVVV@collation=phonebook;key=value";
     34         longULocaleBasename = longULocaleName.substring(0, longULocaleName.indexOf('@'));
     35         nonNormalizedName = "LL_ssss_cc_VVVV@ Key = value ; Collation = phonebook ; ";
     36         longULocale = new ULocale(longULocaleName);
     37         sampleLocale = new ULocale(sampleName).toLocale();
     38     }
     39 
     40     /*
     41      * Test method for 'com.ibm.icu.x.util.ULocale.hashCode()'
     42      */
     43     public void testHashCode() {
     44         ULocale obj = ULocale.GERMANY;
     45         ULocale eq = new ULocale("de_DE");
     46         ULocale neq = new ULocale("de_DE_FRENCH");
     47 
     48         ICUTestCase.testEHCS(obj, eq, neq);
     49     }
     50 
     51     /*
     52      * Test method for 'com.ibm.icu.x.util.ULocale.forLocale(Locale)'
     53      */
     54     public void testForLocale() {
     55         assertEquals(ULocale.GERMANY, ULocale.forLocale(Locale.GERMANY));
     56     }
     57 
     58     /*
     59      * Test method for 'com.ibm.icu.x.util.ULocale.ULocale(String)'
     60      */
     61     public void testULocaleString() {
     62         assertEquals(ULocale.GERMAN, new ULocale("de"));
     63     }
     64 
     65     /*
     66      * Test method for 'com.ibm.icu.x.util.ULocale.ULocale(String, String)'
     67      */
     68     public void testULocaleStringString() {
     69         assertEquals(ULocale.GERMANY, new ULocale("de", "DE"));
     70     }
     71 
     72     /*
     73      * Test method for 'com.ibm.icu.x.util.ULocale.ULocale(String, String, String)'
     74      */
     75     public void testULocaleStringStringString() {
     76         assertEquals(sampleLocale, new ULocale("ll", "cc", "VVVV").toLocale());
     77     }
     78 
     79     /*
     80      * Test method for 'com.ibm.icu.x.util.ULocale.createCanonical(String)'
     81      */
     82     public void testCreateCanonical() {
     83         ULocale result = ULocale.createCanonical("de__PHONEBOOK");
     84         assertEquals(new ULocale("de@collation=phonebook"), result);
     85     }
     86 
     87     /*
     88      * Test method for 'com.ibm.icu.x.util.ULocale.toLocale()'
     89      */
     90     public void testToLocale() {
     91         assertEquals(sampleLocale, new ULocale("ll", "cc", "VVVV").toLocale());
     92     }
     93 
     94     /*
     95      * Test method for 'com.ibm.icu.x.util.ULocale.getDefault()'
     96      */
     97     public void testGetDefault() {
     98         assertEquals(Locale.getDefault(), ULocale.getDefault().toLocale());
     99     }
    100 
    101     /*
    102      * Test method for 'com.ibm.icu.x.util.ULocale.setDefault(ULocale)'
    103      */
    104     public void testSetDefault() {
    105         Locale oldLocale = Locale.getDefault();
    106         ULocale oldULocale = ULocale.getDefault();
    107         try {
    108             ULocale.setDefault(longULocale);
    109             ICUTestCase.assertNotEqual(Locale.getDefault(), oldLocale);
    110             ICUTestCase.assertNotEqual(ULocale.getDefault(), oldULocale);
    111             assertEquals(longULocale, ULocale.getDefault());
    112             assertEquals(sampleLocale, Locale.getDefault());
    113         }
    114         finally {
    115             ULocale.setDefault(oldULocale);
    116             Locale.setDefault(oldLocale); // in case of some error
    117         }
    118     }
    119 
    120     /*
    121      * Test method for 'com.ibm.icu.x.util.ULocale.clone()'
    122      */
    123     public void testClone() {
    124         // see testHashcode
    125     }
    126 
    127     /*
    128      * Test method for 'com.ibm.icu.x.util.ULocale.equals(Object)'
    129      */
    130     public void testEqualsObject() {
    131         // see testHashcode
    132     }
    133 
    134     /*
    135      * Test method for 'com.ibm.icu.x.util.ULocale.getAvailableLocales()'
    136      */
    137     public void testGetAvailableLocales() {
    138         ULocale[] ulocales = ULocale.getAvailableLocales();
    139         if (ICUTestCase.testingWrapper) {
    140             Locale[] locales = Locale.getAvailableLocales();
    141             for (int i = 0; i < ulocales.length; ++i) {
    142                 assertEquals(ulocales[i].toLocale(), locales[i]);
    143             }
    144         }
    145         // else nothing to test except that the function returned.
    146     }
    147 
    148     /*
    149      * Test method for 'com.ibm.icu.x.util.ULocale.getISOCountries()'
    150      */
    151     public void testGetISOCountries() {
    152         String[] ucountries = ULocale.getISOCountries();
    153         assertNotNull(ucountries);
    154         if (ICUTestCase.testingWrapper) {
    155             // keep our own data for now
    156             // our data doesn't match java's so this test would fail
    157             // TODO: enable if we decide to use java's data
    158             // String[] countries = Locale.getISOCountries();
    159             // TestBoilerplate.assertArraysEqual(ucountries, countries);
    160         }
    161         // else nothing to test except that the function returned.
    162     }
    163 
    164     /*
    165      * Test method for 'com.ibm.icu.x.util.ULocale.getISOLanguages()'
    166      */
    167     public void testGetISOLanguages() {
    168         String[] ulanguages = ULocale.getISOLanguages();
    169         assertNotNull(ulanguages);
    170         if (ICUTestCase.testingWrapper) {
    171             // keep our own data for now
    172             // our data doesn't match java's so this test would fail
    173             // TODO: enable if we decide to use java's data
    174             // String[] languages = Locale.getISOLanguages();
    175             // TestBoilerplate.assertArraysEqual(ulanguages, languages);
    176         }
    177         // else nothing to test except that the function returned.
    178     }
    179 
    180     /*
    181      * Test method for 'com.ibm.icu.x.util.ULocale.getLanguage()'
    182      */
    183     public void testGetLanguage() {
    184         assertEquals("ll", longULocale.getLanguage());
    185         assertEquals("ll", longULocale.toLocale().getLanguage());
    186     }
    187 
    188     /*
    189      * Test method for 'com.ibm.icu.x.util.ULocale.getLanguage(String)'
    190      */
    191     public void testGetLanguageString() {
    192         assertEquals("ll", ULocale.getLanguage(longULocale.getName()));
    193     }
    194 
    195     /*
    196      * Test method for 'com.ibm.icu.x.util.ULocale.getScript()'
    197      */
    198     public void testGetScript() {
    199         assertEquals("Ssss", longULocale.getScript());
    200     }
    201 
    202     /*
    203      * Test method for 'com.ibm.icu.x.util.ULocale.getScript(String)'
    204      */
    205     public void testGetScriptString() {
    206         assertEquals("Ssss", ULocale.getScript(longULocale.getName()));
    207     }
    208 
    209     /*
    210      * Test method for 'com.ibm.icu.x.util.ULocale.getCountry()'
    211      */
    212     public void testGetCountry() {
    213         assertEquals("CC", longULocale.getCountry());
    214         assertEquals("CC", longULocale.toLocale().getCountry());
    215     }
    216 
    217     /*
    218      * Test method for 'com.ibm.icu.x.util.ULocale.getCountry(String)'
    219      */
    220     public void testGetCountryString() {
    221         assertEquals("CC", ULocale.getCountry(longULocale.getName()));
    222     }
    223 
    224     /*
    225      * Test method for 'com.ibm.icu.x.util.ULocale.getVariant()'
    226      */
    227     public void testGetVariant() {
    228         assertEquals("VVVV", longULocale.getVariant());
    229         assertEquals("VVVV", longULocale.toLocale().getVariant());
    230     }
    231 
    232     /*
    233      * Test method for 'com.ibm.icu.x.util.ULocale.getVariant(String)'
    234      */
    235     public void testGetVariantString() {
    236         assertEquals("VVVV", ULocale.getVariant(longULocale.getName()));
    237     }
    238 
    239     /*
    240      * Test method for 'com.ibm.icu.x.util.ULocale.getFallback(String)'
    241      */
    242     public void testGetFallbackString() {
    243         assertEquals(ULocale.GERMAN, ULocale.getFallback(ULocale.GERMANY.getName()));
    244     }
    245 
    246     /*
    247      * Test method for 'com.ibm.icu.x.util.ULocale.getFallback()'
    248      */
    249     public void testGetFallback() {
    250         assertEquals(ULocale.GERMAN, ULocale.GERMANY.getFallback());
    251     }
    252 
    253     /*
    254      * Test method for 'com.ibm.icu.x.util.ULocale.getBaseName()'
    255      */
    256     public void testGetBaseName() {
    257         assertEquals(longULocaleBasename, longULocale.getBaseName());
    258     }
    259 
    260     /*
    261      * Test method for 'com.ibm.icu.x.util.ULocale.getBaseName(String)'
    262      */
    263     public void testGetBaseNameString() {
    264         assertEquals(longULocaleBasename, longULocale.getBaseName());
    265     }
    266 
    267     /*
    268      * Test method for 'com.ibm.icu.x.util.ULocale.getName()'
    269      */
    270     public void testGetName() {
    271         assertEquals(longULocaleName, longULocale.getName());
    272     }
    273 
    274     /*
    275      * Test method for 'com.ibm.icu.x.util.ULocale.getName(String)'
    276      */
    277     public void testGetNameString() {
    278         assertEquals(longULocaleName, ULocale.getName(nonNormalizedName));
    279     }
    280 
    281     /*
    282      * Test method for 'com.ibm.icu.x.util.ULocale.toString()'
    283      */
    284     public void testToString() {
    285         assertEquals(longULocaleName, longULocale.toString());
    286     }
    287 
    288     /*
    289      * Test method for 'com.ibm.icu.x.util.ULocale.getKeywords()'
    290      */
    291     public void testGetKeywords() {
    292         Iterator<String> iter = longULocale.getKeywords();
    293         assertEquals(iter.next(), "collation");
    294         assertEquals(iter.next(), "key");
    295         assertFalse(iter.hasNext());
    296     }
    297 
    298     /*
    299      * Test method for 'com.ibm.icu.x.util.ULocale.getKeywords(String)'
    300      */
    301     public void testGetKeywordsString() {
    302         Iterator<String> iter = ULocale.getKeywords(nonNormalizedName);
    303         assertEquals(iter.next(), "collation");
    304         assertEquals(iter.next(), "key");
    305         assertFalse(iter.hasNext());
    306     }
    307 
    308     /*
    309      * Test method for 'com.ibm.icu.x.util.ULocale.getKeywordValue(String)'
    310      */
    311     public void testGetKeywordValueString() {
    312         assertEquals("value", longULocale.getKeywordValue("key"));
    313         assertEquals("phonebook", longULocale.getKeywordValue("collation"));
    314         assertNull(longULocale.getKeywordValue("zzyzx"));
    315     }
    316 
    317     /*
    318      * Test method for 'com.ibm.icu.x.util.ULocale.getKeywordValue(String, String)'
    319      */
    320     public void testGetKeywordValueStringString() {
    321         assertEquals("value", ULocale.getKeywordValue(longULocaleName, "key"));
    322         assertEquals("phonebook", ULocale.getKeywordValue(longULocaleName, "collation"));
    323         assertNull(ULocale.getKeywordValue(longULocaleName, "zzyzx"));
    324 
    325     }
    326 
    327     /*
    328      * Test method for 'com.ibm.icu.x.util.ULocale.canonicalize(String)'
    329      */
    330     public void testCanonicalize() {
    331         assertEquals("de@collation=phonebook", ULocale.canonicalize("de__PHONEBOOK"));
    332     }
    333 
    334     /*
    335      * Test method for 'com.ibm.icu.x.util.ULocale.setKeywordValue(String, String)'
    336      */
    337     public void testSetKeywordValueStringString() {
    338         ULocale munged = longULocale.setKeywordValue("key", "C#");
    339         assertEquals("C#", munged.getKeywordValue("key"));
    340         munged = munged.setKeywordValue("zzyzx", "grue");
    341         assertEquals("grue", munged.getKeywordValue("zzyzx"));
    342     }
    343 
    344     /*
    345      * Test method for 'com.ibm.icu.x.util.ULocale.setKeywordValue(String, String, String)'
    346      */
    347     public void testSetKeywordValueStringStringString() {
    348         String munged = ULocale.setKeywordValue(longULocaleName, "key", "C#");
    349         assertEquals("C#", ULocale.getKeywordValue(munged, "key"));
    350         munged = ULocale.setKeywordValue(munged, "zzyzx", "grue");
    351         assertEquals("grue", ULocale.getKeywordValue(munged, "zzyzx"));
    352     }
    353 
    354     /*
    355      * Test method for 'com.ibm.icu.x.util.ULocale.getISO3Language()'
    356      */
    357     public void testGetISO3Language() {
    358         String il = ULocale.GERMANY.getISO3Language();
    359         String jl = Locale.GERMANY.getISO3Language();
    360         assertEquals(il, jl);
    361     }
    362 
    363     /*
    364      * Test method for 'com.ibm.icu.x.util.ULocale.getISO3Language(String)'
    365      */
    366     public void testGetISO3LanguageString() {
    367         String il = ULocale.getISO3Language(ULocale.GERMANY.getName());
    368         String jl = Locale.GERMANY.getISO3Language();
    369         assertEquals(il, jl);
    370     }
    371 
    372     /*
    373      * Test method for 'com.ibm.icu.x.util.ULocale.getISO3Country()'
    374      */
    375     public void testGetISO3Country() {
    376         String ic = ULocale.GERMANY.getISO3Country();
    377         String jc = Locale.GERMANY.getISO3Country();
    378         assertEquals(ic, jc);
    379     }
    380 
    381     /*
    382      * Test method for 'com.ibm.icu.x.util.ULocale.getISO3Country(String)'
    383      */
    384     public void testGetISO3CountryString() {
    385         String ic = ULocale.getISO3Country(ULocale.GERMANY.getName());
    386         String jc = Locale.GERMANY.getISO3Country();
    387         assertEquals(ic, jc);
    388     }
    389 
    390     /*
    391      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayLanguage()'
    392      */
    393     public void testGetDisplayLanguage() {
    394         String idl = ULocale.GERMANY.getDisplayLanguage();
    395         String jdl = Locale.GERMANY.getDisplayLanguage();
    396         assertEquals(idl, jdl);
    397     }
    398 
    399     /*
    400      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayLanguage(ULocale)'
    401      */
    402     public void testGetDisplayLanguageULocale() {
    403         String idl = ULocale.GERMANY.getDisplayLanguage(ULocale.GERMANY);
    404         String jdl = Locale.GERMANY.getDisplayLanguage(Locale.GERMANY);
    405         assertEquals(idl, jdl);
    406     }
    407 
    408     /*
    409      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayLanguage(String, String)'
    410      */
    411     public void testGetDisplayLanguageStringString() {
    412         String idl = ULocale.getDisplayLanguage(ULocale.GERMANY.getName(), "de_DE");
    413         String jdl = Locale.GERMANY.getDisplayLanguage(Locale.GERMANY);
    414         assertEquals(idl, jdl);
    415     }
    416 
    417     /*
    418      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayLanguage(String, ULocale)'
    419      */
    420     public void testGetDisplayLanguageStringULocale() {
    421         String idl = ULocale.getDisplayLanguage(ULocale.GERMANY.getName(), ULocale.GERMANY);
    422         String jdl = Locale.GERMANY.getDisplayLanguage(Locale.GERMANY);
    423         assertEquals(idl, jdl);
    424     }
    425 
    426     /*
    427      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayScript()'
    428      */
    429     public void testGetDisplayScript() {
    430         String is = ULocale.TRADITIONAL_CHINESE.getDisplayScript();
    431         if (ICUTestCase.testingWrapper) {
    432             assertEquals("Hant", is);
    433         } else {
    434             assertEquals("Traditional Chinese", is);
    435         }
    436     }
    437 
    438     /*
    439      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayScript(ULocale)'
    440      */
    441     public void testGetDisplayScriptULocale() {
    442         String is = ULocale.TRADITIONAL_CHINESE.getDisplayScript(ULocale.GERMANY);
    443         if (ICUTestCase.testingWrapper) {
    444             assertEquals("Hant", is);
    445         } else {
    446             // TODO: look up expected value
    447             assertEquals("Hant", is);
    448         }
    449     }
    450 
    451     /*
    452      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayScript(String, String)'
    453      */
    454     public void testGetDisplayScriptStringString() {
    455         String is = ULocale.getDisplayScript("zh_Hant", "de_DE");
    456         if (ICUTestCase.testingWrapper) {
    457             assertEquals("Hant", is);
    458         } else {
    459             // TODO: look up expected value
    460             assertEquals("Hant", is);
    461         }
    462     }
    463 
    464     /*
    465      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayScript(String, ULocale)'
    466      */
    467     public void testGetDisplayScriptStringULocale() {
    468         String is = ULocale.getDisplayScript("zh_Hant", ULocale.GERMANY);
    469         if (ICUTestCase.testingWrapper) {
    470             assertEquals("Hant", is);
    471         } else {
    472             // TODO: look up expected value
    473             assertEquals("Hant", is);
    474         }
    475     }
    476 
    477     /*
    478      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayCountry()'
    479      */
    480     public void testGetDisplayCountry() {
    481         String idc = ULocale.GERMANY.getDisplayCountry();
    482         String jdc = Locale.GERMANY.getDisplayCountry();
    483         assertEquals(idc, jdc);
    484     }
    485 
    486     /*
    487      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayCountry(ULocale)'
    488      */
    489     public void testGetDisplayCountryULocale() {
    490         String idc = ULocale.GERMANY.getDisplayCountry(ULocale.GERMANY);
    491         String jdc = Locale.GERMANY.getDisplayCountry(Locale.GERMANY);
    492         assertEquals(idc, jdc);
    493     }
    494 
    495     /*
    496      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayCountry(String, String)'
    497      */
    498     public void testGetDisplayCountryStringString() {
    499         String idc = ULocale.getDisplayCountry("de_DE", "de_DE");
    500         String jdc = Locale.GERMANY.getDisplayCountry(Locale.GERMANY);
    501         assertEquals(idc, jdc);
    502     }
    503 
    504     /*
    505      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayCountry(String, ULocale)'
    506      */
    507     public void testGetDisplayCountryStringULocale() {
    508         String idc = ULocale.getDisplayCountry("de_DE", ULocale.GERMANY);
    509         String jdc = Locale.GERMANY.getDisplayCountry(Locale.GERMANY);
    510         assertEquals(idc, jdc);
    511     }
    512 
    513     /*
    514      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayVariant()'
    515      */
    516     public void testGetDisplayVariant() {
    517         String idv = new ULocale("de_DE_PHONEBOOK").getDisplayVariant();
    518         String jdv = new Locale("de", "DE", "PHONEBOOK").getDisplayVariant();
    519         assertEquals(jdv, idv);
    520     }
    521 
    522     /*
    523      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayVariant(ULocale)'
    524      */
    525     public void testGetDisplayVariantULocale() {
    526         String idv = new ULocale("de_DE_PHONEBOOK").getDisplayVariant(ULocale.GERMANY);
    527         String jdv = new Locale("de", "DE", "PHONEBOOK").getDisplayVariant(Locale.GERMANY);
    528         assertEquals(jdv, idv);
    529     }
    530 
    531     /*
    532      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayVariant(String, String)'
    533      */
    534     public void testGetDisplayVariantStringString() {
    535         String idv = ULocale.getDisplayVariant("de_DE_PHONEBOOK", "de_DE");
    536         String jdv = new Locale("de", "DE", "PHONEBOOK").getDisplayVariant(Locale.GERMANY);
    537         assertEquals(jdv, idv);
    538     }
    539 
    540     /*
    541      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayVariant(String, ULocale)'
    542      */
    543     public void testGetDisplayVariantStringULocale() {
    544         String idv = ULocale.getDisplayVariant("de_DE_PHONEBOOK", ULocale.GERMANY);
    545         String jdv = new Locale("de", "DE", "PHONEBOOK").getDisplayVariant(Locale.GERMANY);
    546         assertEquals(jdv, idv);
    547     }
    548 
    549     /*
    550      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeyword(String)'
    551      */
    552     public void testGetDisplayKeywordString() {
    553         String idk = ULocale.getDisplayKeyword("collation");
    554         assertEquals("collation", idk);
    555     }
    556 
    557     /*
    558      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeyword(String, String)'
    559      */
    560     public void testGetDisplayKeywordStringString() {
    561         String idk = ULocale.getDisplayKeyword("collation", "de_DE");
    562         if (ICUTestCase.testingWrapper) {
    563             assertEquals("collation", idk);
    564         } else {
    565             // TODO: find real value
    566             assertEquals("collation", idk);
    567         }
    568     }
    569 
    570     /*
    571      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeyword(String, ULocale)'
    572      */
    573     public void testGetDisplayKeywordStringULocale() {
    574         String idk = ULocale.getDisplayKeyword("collation", ULocale.GERMANY);
    575         if (ICUTestCase.testingWrapper) {
    576             assertEquals("collation", idk);
    577         } else {
    578             // TODO: find real value
    579             assertEquals("collation", idk);
    580         }
    581     }
    582 
    583     /*
    584      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeywordValue(String)'
    585      */
    586     public void testGetDisplayKeywordValueString() {
    587         ULocale ul = new ULocale("de_DE@collation=phonebook");
    588         String idk = ul.getDisplayKeywordValue("collation");
    589         if (ICUTestCase.testingWrapper) {
    590             assertEquals("phonebook", idk);
    591         } else {
    592             // TODO: find real value
    593             assertEquals("phonebook", idk);
    594         }
    595     }
    596 
    597     /*
    598      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeywordValue(String, ULocale)'
    599      */
    600     public void testGetDisplayKeywordValueStringULocale() {
    601         ULocale ul = new ULocale("de_DE@collation=phonebook");
    602         String idk = ul.getDisplayKeywordValue("collation", ULocale.GERMANY);
    603         if (ICUTestCase.testingWrapper) {
    604             assertEquals("phonebook", idk);
    605         } else {
    606             // TODO: find real value
    607             assertEquals("phonebook", idk);
    608         }
    609     }
    610 
    611     /*
    612      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeywordValue(String, String, String)'
    613      */
    614     public void testGetDisplayKeywordValueStringStringString() {
    615         String idk = ULocale.getDisplayKeywordValue("de_DE@collation=phonebook", "collation", "de_DE");
    616         if (ICUTestCase.testingWrapper) {
    617             assertEquals("phonebook", idk);
    618         } else {
    619             // TODO: find real value
    620             assertEquals("phonebook", idk);
    621         }
    622     }
    623 
    624     /*
    625      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeywordValue(String, String, ULocale)'
    626      */
    627     public void testGetDisplayKeywordValueStringStringULocale() {
    628         String idk = ULocale.getDisplayKeywordValue("de_DE@collation=phonebook", "collation", ULocale.GERMANY);
    629         if (ICUTestCase.testingWrapper) {
    630             assertEquals("phonebook", idk);
    631         } else {
    632             // TODO: find real value
    633             assertEquals("phonebook", idk);
    634         }
    635     }
    636 
    637     /*
    638      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayName()'
    639      */
    640     public void testGetDisplayName() {
    641         String idn = ULocale.GERMANY.getDisplayName();
    642         String jdn = Locale.GERMANY.getDisplayName();
    643         assertEquals(idn, jdn);
    644     }
    645 
    646     /*
    647      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayName(ULocale)'
    648      */
    649     public void testGetDisplayNameULocale() {
    650         String idn = ULocale.GERMANY.getDisplayName(ULocale.GERMANY);
    651         String jdn = Locale.GERMANY.getDisplayName(Locale.GERMANY);
    652         assertEquals(idn, jdn);
    653     }
    654 
    655     /*
    656      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayName(String, String)'
    657      */
    658     public void testGetDisplayNameStringString() {
    659         String idn = ULocale.getDisplayName("de_DE", "de_DE");
    660         String jdn = Locale.GERMANY.getDisplayName(Locale.GERMANY);
    661         assertEquals(idn, jdn);
    662     }
    663 
    664     /*
    665      * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayName(String, ULocale)'
    666      */
    667     public void testGetDisplayNameStringULocale() {
    668         String idn = ULocale.getDisplayName("de_DE", ULocale.GERMANY);
    669         String jdn = Locale.GERMANY.getDisplayName(Locale.GERMANY);
    670         assertEquals(idn, jdn);
    671     }
    672 
    673     /*
    674      * Test method for 'com.ibm.icu.x.util.ULocale.acceptLanguage(String, ULocale[], boolean[])'
    675      */
    676     public void testAcceptLanguageStringULocaleArrayBooleanArray() {
    677         boolean[] fallback = new boolean[1];
    678         ULocale[] locales = {
    679             new ULocale("en_CA"),
    680             new ULocale("es_US"),
    681         };
    682         ULocale result = ULocale.acceptLanguage("en-US, en-GB, en-CA, es-US", locales, fallback);
    683         assertEquals(new ULocale("en_CA"), result);
    684         assertFalse(fallback[0]);
    685         result = ULocale.acceptLanguage("en-US, en-GB, es-US-NEWMEXICO", locales, fallback);
    686         assertEquals(new ULocale("es_US"), result);
    687         assertTrue(fallback[0]);
    688     }
    689 
    690     /*
    691      * Test method for 'com.ibm.icu.x.util.ULocale.acceptLanguage(ULocale[], ULocale[], boolean[])'
    692      */
    693     public void testAcceptLanguageULocaleArrayULocaleArrayBooleanArray() {
    694         boolean[] fallback = new boolean[1];
    695         ULocale[] locales = {
    696             new ULocale("en_CA"),
    697             new ULocale("es_US"),
    698         };
    699         ULocale[] accept_locales = {
    700             new ULocale("en_US"),
    701             new ULocale("en_GB"),
    702             new ULocale("en_CA"),
    703             new ULocale("es_US"),
    704         };
    705         ULocale[] accept_locales2 = {
    706             new ULocale("en_US"),
    707             new ULocale("en_GB"),
    708             new ULocale("es_US_NEWMEXICO"),
    709         };
    710         ULocale result = ULocale.acceptLanguage(accept_locales, locales, fallback);
    711         assertEquals(new ULocale("en_CA"), result);
    712         assertFalse(fallback[0]);
    713         result = ULocale.acceptLanguage(accept_locales2, locales, fallback);
    714         assertEquals(new ULocale("es_US"), result);
    715         assertTrue(fallback[0]);
    716     }
    717 
    718     /*
    719      * Test method for 'com.ibm.icu.x.util.ULocale.acceptLanguage(String, boolean[])'
    720      */
    721     public void testAcceptLanguageStringBooleanArray() {
    722         boolean[] fallback = new boolean[1];
    723         ULocale result = ULocale.acceptLanguage("en-CA, en-GB, es-US", fallback);
    724         assertEquals(new ULocale("en_CA"), result);
    725         assertFalse(fallback[0]);
    726         result = ULocale.acceptLanguage("es-US-NEWMEXICO", fallback);
    727         assertNotNull(result); // actual result depends on jdk
    728         assertTrue(fallback[0]);
    729     }
    730 
    731     /*
    732      * Test method for 'com.ibm.icu.x.util.ULocale.acceptLanguage(ULocale[], boolean[])'
    733      */
    734     public void testAcceptLanguageULocaleArrayBooleanArray() {
    735         boolean[] fallback = new boolean[1];
    736         ULocale[] accept_locales = {
    737             new ULocale("en_CA"),
    738             new ULocale("en_GB"),
    739             new ULocale("es_US"),
    740         };
    741         ULocale[] accept_locales2 = {
    742             new ULocale("es_US_NEWMEXICO"),
    743         };
    744         ULocale result = ULocale.acceptLanguage(accept_locales, fallback);
    745         assertEquals(new ULocale("en_CA"), result);
    746         assertFalse(fallback[0]);
    747         result = ULocale.acceptLanguage(accept_locales2, fallback);
    748         assertNotNull(result); // actual result depends on jdk
    749         assertTrue(fallback[0]);
    750     }
    751 
    752     /*
    753      * Test method for 'com.ibm.icu.x.util.ULocale.toLanguageTag()'
    754      */
    755     public void testToLanguageTag() {
    756         ULocale[] test_ulocales = {
    757             new ULocale("en_US"),
    758             new ULocale(""),
    759             new ULocale("de_DE@collation=phonebook"),
    760             new ULocale("en_Latn_US_POSIX"),
    761             new ULocale("th_TH@numbers=thai;calendar=buddhist"),
    762             new ULocale("und_CN@timezone=PRC"),
    763             new ULocale("iw_IL"),
    764         };
    765 
    766         String[] expected = {
    767             "en-US",
    768             "und",
    769             "de-DE-u-co-phonebk",
    770             "en-Latn-US-u-va-posix",
    771             "th-TH-u-ca-buddhist-nu-thai",
    772             "und-CN-u-tz-cnsha",
    773             "he-IL",
    774         };
    775 
    776         for (int i = 0; i < test_ulocales.length; i++) {
    777             String result = test_ulocales[i].toLanguageTag();
    778             assertEquals(expected[i], result);
    779         }
    780     }
    781 
    782     /*
    783      * Test method for 'com.ibm.icu.x.util.ULocale.forLanguageTag()'
    784      */
    785     public void testForLanguageTag() {
    786         String[] test_tags = {
    787             "en-us",
    788             "Und-Us",
    789             "ja-jp-u-ca-japanese",
    790             "fr-FR-u-tz-frpar-ca-gregory",
    791         };
    792 
    793         ULocale[] expected = {
    794             new ULocale("en_US"),
    795             new ULocale("und_US"),
    796             new ULocale("ja_JP@calendar=japanese"),
    797             new ULocale("fr_FR@calendar=gregorian;timezone=Europe/Paris"),
    798         };
    799 
    800         for (int i = 0; i < test_tags.length; i++) {
    801             ULocale result = ULocale.forLanguageTag(test_tags[i]);
    802             assertEquals(expected[i], result);
    803         }
    804     }
    805 
    806     /*
    807      * Test method for 'com.ibm.icu.x.util.ULocale.getDefault(Category)'
    808      */
    809     public void testGetDefaultCategory() {
    810         ULocale dispLoc = ULocale.getDefault(Category.DISPLAY);
    811         assertNotNull(dispLoc);
    812         ULocale formLoc = ULocale.getDefault(Category.FORMAT);
    813         assertNotNull(formLoc);
    814     }
    815 
    816     /*
    817      * Test method for 'com.ibm.icu.x.util.ULocale.setDefault(Category, ULocale)'
    818      */
    819     public void testSetDefaultCategoryULocale() {
    820         ULocale orgDefault = ULocale.getDefault();
    821         ULocale orgDisplay = ULocale.getDefault(Category.DISPLAY);
    822         ULocale orgFormat = ULocale.getDefault(Category.FORMAT);
    823 
    824         ULocale jaUS = new ULocale("ja_US");
    825         ULocale.setDefault(jaUS);
    826 
    827         // setDefault(ULocale) updates category defaults
    828         assertEquals(ULocale.getDefault(), jaUS);
    829         assertEquals(ULocale.getDefault(Category.DISPLAY), jaUS);
    830         assertEquals(ULocale.getDefault(Category.FORMAT), jaUS);
    831 
    832         ULocale frDE = new ULocale("fr_DE");
    833         ULocale.setDefault(Category.DISPLAY, frDE);
    834 
    835         // setDefault(Category, ULocale) only updates the category default
    836         assertEquals(ULocale.getDefault(), jaUS);
    837         assertEquals(ULocale.getDefault(Category.DISPLAY), frDE);
    838         assertEquals(ULocale.getDefault(Category.FORMAT), jaUS);
    839 
    840         // restore the original
    841         ULocale.setDefault(orgDefault);
    842         ULocale.setDefault(Category.DISPLAY, orgDisplay);
    843         ULocale.setDefault(Category.FORMAT, orgFormat);
    844 
    845         assertEquals(ULocale.getDefault(), orgDefault);
    846         assertEquals(ULocale.getDefault(Category.DISPLAY), orgDisplay);
    847         assertEquals(ULocale.getDefault(Category.FORMAT), orgFormat);
    848     }
    849 }
    850