Home | History | Annotate | Download | only in test
      1 /* GENERATED SOURCE. DO NOT MODIFY. */
      2 //  2016 and later: Unicode, Inc. and others.
      3 // License & terms of use: http://www.unicode.org/copyright.html#License
      4 /*
      5  *******************************************************************************
      6  * Copyright (C) 2009-2014, International Business Machines Corporation and    *
      7  * others. All Rights Reserved.                                                *
      8  *******************************************************************************
      9  */
     10 package android.icu.dev.test;
     11 
     12 import static android.icu.impl.LocaleDisplayNamesImpl.DataTableType.LANG;
     13 import static android.icu.impl.LocaleDisplayNamesImpl.DataTableType.REGION;
     14 
     15 import java.util.Locale;
     16 
     17 import org.junit.Test;
     18 import org.junit.runner.RunWith;
     19 import org.junit.runners.JUnit4;
     20 
     21 import android.icu.impl.LocaleDisplayNamesImpl;
     22 import android.icu.text.LocaleDisplayNames;
     23 import android.icu.text.LocaleDisplayNames.DialectHandling;
     24 import android.icu.util.ULocale;
     25 import android.icu.testsharding.MainTestShard;
     26 
     27 @MainTestShard
     28 @RunWith(JUnit4.class)
     29 public class TestLocaleNamePackaging extends TestFmwk {
     30     public TestLocaleNamePackaging() {
     31     }
     32 
     33     public boolean validate() {
     34         logln("language data: " + LocaleDisplayNamesImpl.haveData(LANG));
     35         logln("  region data: " + LocaleDisplayNamesImpl.haveData(REGION));
     36         return true;
     37     }
     38 
     39     private static ULocale[] locales = {
     40         ULocale.ROOT, ULocale.US, new ULocale("es_ES"), ULocale.GERMANY,
     41         new ULocale("und_TH")
     42     };
     43 
     44     // Java Locales equivalent to above
     45     private static Locale[] javaLocales = {
     46         new Locale(""), Locale.US, new Locale("es", "ES"), Locale.GERMANY,
     47         new Locale("und", "TH")
     48     };
     49 
     50     @Test
     51     public void testRegionDisplayNames() {
     52         String[] expectedWithRegionData = {
     53             "",
     54             "US",
     55             "ES",
     56             "DE",
     57             "TH",
     58             "",
     59             "United States",
     60             "Spain",
     61             "Germany",
     62             "Thailand",
     63             "",
     64             "Estados Unidos",
     65             "Espa\u00f1a",
     66             "Alemania",
     67             "Tailandia",
     68             "",
     69             "Vereinigte Staaten",
     70             "Spanien",
     71             "Deutschland",
     72             "Thailand",
     73             "",
     74             "United States",
     75             "Spain",
     76             "Germany",
     77             "Thailand",
     78         };
     79         String[] expectedWithoutRegionData = {
     80             "",
     81             "US",
     82             "ES",
     83             "DE",
     84             "TH",
     85         };
     86         String[] expected = LocaleDisplayNamesImpl.haveData(REGION) ?
     87             expectedWithRegionData : expectedWithoutRegionData;
     88 
     89         int n = 0;
     90         for (ULocale displayLocale : locales) {
     91             LocaleDisplayNames dn = LocaleDisplayNames.getInstance(displayLocale);
     92             for (ULocale targetLocale : locales) {
     93                 String result = dn.regionDisplayName(targetLocale.getCountry());
     94                 assertEquals(targetLocale + " in " + displayLocale, expected[n++], result);
     95                 if (n == expected.length) {
     96                     n = 0;
     97                 }
     98             }
     99         }
    100 
    101         // Same test with Java Locale
    102         n = 0;
    103         for (Locale displayJavaLocale : javaLocales) {
    104             LocaleDisplayNames dn = LocaleDisplayNames.getInstance(displayJavaLocale);
    105             for (Locale targetLocale : javaLocales) {
    106                 String result = dn.regionDisplayName(targetLocale.getCountry());
    107                 assertEquals(targetLocale + " in " + displayJavaLocale, expected[n++], result);
    108                 if (n == expected.length) {
    109                     n = 0;
    110                 }
    111             }
    112         }
    113 
    114     }
    115 
    116     @Test
    117     public void testLanguageDisplayNames() {
    118         String[] expectedWithLanguageData = {
    119             "",
    120             "en",
    121             "es",
    122             "de",
    123             "und",
    124             "",
    125             "English",
    126             "Spanish",
    127             "German",
    128             "Unknown Language",
    129             "",
    130             "ingl\u00E9s",
    131             "espa\u00F1ol",
    132             "alem\u00E1n",
    133             "lengua desconocida",
    134             "",
    135             "Englisch",
    136             "Spanisch",
    137             "Deutsch",
    138             "Unbestimmte Sprache",
    139             "",
    140             "English",
    141             "Spanish",
    142             "German",
    143             "Unknown Language",
    144         };
    145         String[] expectedWithoutLanguageData = {
    146             "",
    147             "en",
    148             "es",
    149             "de",
    150             "und"
    151         };
    152         String[] expected = LocaleDisplayNamesImpl.haveData(LANG) ?
    153             expectedWithLanguageData : expectedWithoutLanguageData;
    154 
    155         int n = 0;
    156         for (ULocale displayLocale : locales) {
    157             LocaleDisplayNames dn = LocaleDisplayNames.getInstance(displayLocale);
    158             for (ULocale targetLocale : locales) {
    159                 String result = dn.languageDisplayName(targetLocale.getLanguage());
    160                 assertEquals(targetLocale + " in " + displayLocale, expected[n++], result);
    161                 if (n == expected.length) {
    162                     n = 0;
    163                 }
    164             }
    165         }
    166 
    167         // Same test with Java Locale
    168         n = 0;
    169         for (Locale displayJavaLocale : javaLocales) {
    170             LocaleDisplayNames dn = LocaleDisplayNames.getInstance(displayJavaLocale);
    171             for (Locale targetLocale : javaLocales) {
    172                 String result = dn.languageDisplayName(targetLocale.getLanguage());
    173                 assertEquals(targetLocale + " in " + displayJavaLocale, expected[n++], result);
    174                 if (n == expected.length) {
    175                     n = 0;
    176                 }
    177             }
    178         }
    179 
    180     }
    181 
    182     // test a 'root' locale, with keywords
    183     @Test
    184     public void testLocaleDisplayNameWithKeywords() {
    185         String[] expectedWithLanguageData = {
    186             "root (collation=phonebook)",
    187             "Root (Phonebook Sort Order)",
    188             "ra\u00EDz (orden de list\u00EDn telef\u00F3nico)",
    189             "Root (Telefonbuch-Sortierung)",
    190             "Root (Phonebook Sort Order)",
    191         };
    192         String[] expectedWithoutLanguageData = {
    193             "root (collation=phonebook)",
    194         };
    195         String[] expected = LocaleDisplayNamesImpl.haveData(LANG) ?
    196             expectedWithLanguageData : expectedWithoutLanguageData;
    197 
    198         ULocale kl = new ULocale("@collation=phonebook");
    199 
    200         int n = 0;
    201         for (ULocale displayLocale : locales) {
    202             LocaleDisplayNames dn = LocaleDisplayNames.getInstance(displayLocale);
    203             String result = dn.localeDisplayName(kl);
    204             assertEquals(kl + " in " + displayLocale, expected[n++], result);
    205             if (n == expected.length) {
    206                 n = 0;
    207             }
    208         }
    209     }
    210 
    211     @Test
    212     public void testLanguageDisplayNameDoesNotTranslateRoot() {
    213         // "root" is not a language code-- the fact that we have our data organized this
    214         // way is immaterial.  "root" remains untranslated whether we have data or not.
    215         LocaleDisplayNames dn = LocaleDisplayNames.getInstance(ULocale.US);
    216         assertEquals("root", "root", dn.languageDisplayName("root"));
    217     }
    218 
    219     @Test
    220     public void testLanguageDisplayNameDoesNotTranslateDialects() {
    221         // Dialect ids are also not language codes.
    222         LocaleDisplayNames dn = LocaleDisplayNames.getInstance(ULocale.US,
    223                                                                DialectHandling.DIALECT_NAMES);
    224         assertEquals("dialect", "en_GB", dn.languageDisplayName("en_GB"));
    225 
    226         String target = LocaleDisplayNamesImpl.haveData(LANG)
    227             ? "British English"
    228             : (LocaleDisplayNamesImpl.haveData(REGION)
    229                ? "en (United Kingdom)"
    230                : "en (GB)");
    231         assertEquals("dialect 2", target, dn.localeDisplayName("en_GB"));
    232     }
    233 
    234     @Test
    235     public void testLocaleKeywords() {
    236         LocaleDisplayNames dn = LocaleDisplayNames.getInstance(ULocale.US,
    237                 DialectHandling.DIALECT_NAMES);
    238         String name = dn.localeDisplayName("de@collation=phonebook");
    239         String target = LocaleDisplayNamesImpl.haveData(LANG) ?
    240                 "German (Phonebook Sort Order)" : "de (collation=phonebook)";
    241         assertEquals("collation", target, name);
    242 
    243     }
    244 }
    245