Search in sources :

Example 11 with GlobalizationPreferences

use of android.icu.util.GlobalizationPreferences in project j2objc by google.

the class GlobalizationPreferencesTest method TestDefault.

@Test
public void TestDefault() {
    GlobalizationPreferences gp = new GlobalizationPreferences();
    ULocale defLocale = new ULocale("en_US");
    ULocale defFallbackLocale = new ULocale("en");
    if (!defLocale.equals(ULocale.getDefault())) {
        // Locale.US is always used as the default locale in the test environment
        // If not, some test cases will fail...
        errln("FAIL: The default locale of the test environment must be en_US");
    }
    logln("Default locale: " + defLocale.toString());
    // First locale is en_US
    ULocale gpLocale0 = gp.getLocale(0);
    logln("Primary locale: " + gpLocale0.toString());
    if (!gpLocale0.equals(defLocale)) {
        errln("FAIL: The primary locale is not en_US");
    }
    // Second locale is en
    ULocale gpLocale1 = gp.getLocale(1);
    logln("Secondary locale: " + gpLocale1.toString());
    if (!gpLocale1.equals(defFallbackLocale)) {
        errln("FAIL: The secondary locale is not en");
    }
    // Third locale is null
    ULocale gpLocale2 = gp.getLocale(2);
    if (gpLocale2 != null) {
        errln("FAIL: Number of locales must be 2");
    }
    // Calendar locale
    Calendar cal = gp.getCalendar();
    ULocale calLocale = cal.getLocale(ULocale.VALID_LOCALE);
    logln("Calendar locale: " + calLocale.toString());
    if (!calLocale.equals(defLocale)) {
        errln("FAIL: The calendar locale must match with the default JVM locale");
    }
    // Collator locale
    Collator coll = gp.getCollator();
    ULocale collLocale = coll.getLocale(ULocale.VALID_LOCALE);
    logln("Collator locale: " + collLocale.toString());
    if (!collLocale.equals(defLocale)) {
        errln("FAIL: The collator locale must match with the default JVM locale");
    }
    // BreakIterator locale
    BreakIterator brk = gp.getBreakIterator(GlobalizationPreferences.BI_CHARACTER);
    ULocale brkLocale = brk.getLocale(ULocale.VALID_LOCALE);
    logln("BreakIterator locale: " + brkLocale.toString());
    if (!brkLocale.equals(defLocale)) {
        errln("FAIL: The break iterator locale must match with the default JVM locale");
    }
    /* Skip - Bug#5209
        // DateFormat locale
        DateFormat df = gp.getDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_NONE);
        ULocale dfLocale = df.getLocale(ULocale.VALID_LOCALE);
        logln("DateFormat locale: " + dfLocale.toString());
        if (!dfLocale.equals(defLocale)) {
            errln("FAIL: The date format locale must match with the default JVM locale");
        }
        */
    // NumberFormat locale
    NumberFormat nf = gp.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
    ULocale nfLocale = nf.getLocale(ULocale.VALID_LOCALE);
    logln("NumberFormat locale: " + nfLocale.toString());
    if (!nfLocale.equals(defLocale)) {
        errln("FAIL: The number format locale must match with the default JVM locale");
    }
}
Also used : GlobalizationPreferences(android.icu.util.GlobalizationPreferences) ULocale(android.icu.util.ULocale) IslamicCalendar(android.icu.util.IslamicCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) BuddhistCalendar(android.icu.util.BuddhistCalendar) Calendar(android.icu.util.Calendar) JapaneseCalendar(android.icu.util.JapaneseCalendar) Collator(android.icu.text.Collator) BreakIterator(android.icu.text.BreakIterator) NumberFormat(android.icu.text.NumberFormat) Test(org.junit.Test)

Example 12 with GlobalizationPreferences

use of android.icu.util.GlobalizationPreferences in project j2objc by google.

the class GlobalizationPreferencesTest method TestTerritory.

@Test
public void TestTerritory() {
    GlobalizationPreferences gp = new GlobalizationPreferences();
    // Territory for unsupported language locale
    logln("Set locale - ang");
    gp.setLocale(new ULocale("ang"));
    String territory = gp.getTerritory();
    if (!territory.equals("US")) {
        errln("FAIL: Territory is " + territory + " - Expected: US");
    }
    // Territory for language only locale "fr"
    logln("Set locale - fr");
    gp.setLocale(new ULocale("fr"));
    territory = gp.getTerritory();
    if (!territory.equals("FR")) {
        errln("FAIL: Territory is " + territory + " - Expected: FR");
    }
    // Set explicity territory
    logln("Set explicit territory - CA");
    gp.setTerritory("CA");
    territory = gp.getTerritory();
    if (!territory.equals("CA")) {
        errln("FAIL: Territory is " + territory + " - Expected: CA");
    }
    // Freeze
    logln("Freeze this object");
    gp.freeze();
    boolean bFrozen = false;
    try {
        gp.setTerritory("FR");
    } catch (UnsupportedOperationException uoe) {
        logln("setTerritory is blocked");
        bFrozen = true;
    }
    if (!bFrozen) {
        errln("FAIL: setTerritory must be blocked after frozen");
    }
    territory = gp.getTerritory();
    if (!territory.equals("CA")) {
        errln("FAIL: Territory is not CA");
    }
    // Safe clone
    GlobalizationPreferences gp1 = (GlobalizationPreferences) gp.cloneAsThawed();
    territory = gp1.getTerritory();
    if (!territory.equals("CA")) {
        errln("FAIL: Territory is " + territory + " - Expected: CA");
    }
    gp1.reset();
    ULocale[] locales = new ULocale[2];
    locales[0] = new ULocale("ja");
    locales[1] = new ULocale("zh_Hant_TW");
    logln("Set locales - ja, zh_Hant_TW");
    gp1.setLocales(locales);
    territory = gp1.getTerritory();
    if (!territory.equals("TW")) {
        errln("FAIL: Territory is " + territory + " - Expected: TW");
    }
}
Also used : GlobalizationPreferences(android.icu.util.GlobalizationPreferences) ULocale(android.icu.util.ULocale) Test(org.junit.Test)

Example 13 with GlobalizationPreferences

use of android.icu.util.GlobalizationPreferences in project j2objc by google.

the class GlobalizationPreferencesTest method TestJB5380.

/*
     * JB#5380 GlobalizationPreferences#getCalendar() should return a Calendar object
     * initialized with the current time
     */
@Test
public void TestJB5380() {
    GlobalizationPreferences gp = new GlobalizationPreferences();
    GregorianCalendar gcal = new GregorianCalendar();
    // set way old date
    gcal.set(Calendar.YEAR, 1950);
    // set calendar to GP
    gp.setCalendar(gcal);
    Calendar cal = gp.getCalendar();
    // Calendar instance returned from GP should be initialized
    // by the current time
    long timeDiff = System.currentTimeMillis() - cal.getTimeInMillis();
    if (Math.abs(timeDiff) > 1000) {
        // if difference is more than 1 second..
        errln("FAIL: The Calendar was not initialized by current time - difference:" + timeDiff);
    }
}
Also used : GlobalizationPreferences(android.icu.util.GlobalizationPreferences) IslamicCalendar(android.icu.util.IslamicCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) BuddhistCalendar(android.icu.util.BuddhistCalendar) Calendar(android.icu.util.Calendar) JapaneseCalendar(android.icu.util.JapaneseCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) Test(org.junit.Test)

Example 14 with GlobalizationPreferences

use of android.icu.util.GlobalizationPreferences in project j2objc by google.

the class GlobalizationPreferencesTest method TestCalendar.

@Test
public void TestCalendar() {
    GlobalizationPreferences gp = new GlobalizationPreferences();
    // Set locale - pt_BR
    logln("Set locale - pt");
    gp.setLocale(new ULocale("pt"));
    Calendar cal = gp.getCalendar();
    String calType = cal.getType();
    if (!calType.equals("gregorian")) {
        errln("FAIL: Calendar type is " + calType + " Expected: gregorian");
    }
    // Set a list of locales
    logln("Set locales - en, en_JP, en_GB");
    ULocale[] locales = new ULocale[3];
    locales[0] = new ULocale("en");
    locales[1] = new ULocale("en_JP");
    locales[2] = new ULocale("en_GB");
    gp.setLocales(locales);
    cal = gp.getCalendar();
    ULocale calLocale = cal.getLocale(ULocale.VALID_LOCALE);
    if (!calLocale.equals(locales[2])) {
        errln("FAIL: Calendar locale is " + calLocale.toString() + " - Expected: en_GB");
    }
    // Set ecplicit calendar
    logln("Set Japanese calendar to this object");
    JapaneseCalendar jcal = new JapaneseCalendar();
    gp.setCalendar(jcal);
    cal = gp.getCalendar();
    calType = cal.getType();
    if (!calType.equals("japanese")) {
        errln("FAIL: Calendar type is " + calType + " Expected: japanese");
    }
    jcal.setFirstDayOfWeek(3);
    if (cal.getFirstDayOfWeek() == jcal.getFirstDayOfWeek()) {
        errln("FAIL: Calendar returned by getCalendar must be a safe copy");
    }
    cal.setFirstDayOfWeek(3);
    Calendar cal1 = gp.getCalendar();
    if (cal1.getFirstDayOfWeek() == cal.getFirstDayOfWeek()) {
        errln("FAIL: Calendar returned by getCalendar must be a safe copy");
    }
    // Freeze
    logln("Freeze this object");
    IslamicCalendar ical = new IslamicCalendar();
    boolean bFrozen = false;
    gp.freeze();
    try {
        gp.setCalendar(ical);
    } catch (UnsupportedOperationException uoe) {
        logln("setCalendar is blocked");
        bFrozen = true;
    }
    if (!bFrozen) {
        errln("FAIL: setCalendar must be blocked");
    }
    // Safe clone
    logln("cloneAsThawed");
    GlobalizationPreferences gp1 = (GlobalizationPreferences) gp.cloneAsThawed();
    cal = gp.getCalendar();
    calType = cal.getType();
    if (!calType.equals("japanese")) {
        errln("FAIL: Calendar type afte clone is " + calType + " Expected: japanese");
    }
    logln("Set islamic calendar");
    gp1.setCalendar(ical);
    cal = gp1.getCalendar();
    calType = cal.getType();
    if (!calType.equals("islamic-civil")) {
        // default constructed IslamicCalendar is islamic-civil
        errln("FAIL: Calendar type afte clone is " + calType + " Expected: islamic-civil");
    }
}
Also used : GlobalizationPreferences(android.icu.util.GlobalizationPreferences) ULocale(android.icu.util.ULocale) IslamicCalendar(android.icu.util.IslamicCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) BuddhistCalendar(android.icu.util.BuddhistCalendar) Calendar(android.icu.util.Calendar) JapaneseCalendar(android.icu.util.JapaneseCalendar) JapaneseCalendar(android.icu.util.JapaneseCalendar) IslamicCalendar(android.icu.util.IslamicCalendar) Test(org.junit.Test)

Aggregations

GlobalizationPreferences (android.icu.util.GlobalizationPreferences)14 Test (org.junit.Test)14 ULocale (android.icu.util.ULocale)13 BuddhistCalendar (android.icu.util.BuddhistCalendar)4 Calendar (android.icu.util.Calendar)4 GregorianCalendar (android.icu.util.GregorianCalendar)4 IslamicCalendar (android.icu.util.IslamicCalendar)4 JapaneseCalendar (android.icu.util.JapaneseCalendar)4 ArrayList (java.util.ArrayList)4 BreakIterator (android.icu.text.BreakIterator)2 Collator (android.icu.text.Collator)2 NumberFormat (android.icu.text.NumberFormat)2 TimeZone (android.icu.util.TimeZone)2 DateFormat (android.icu.text.DateFormat)1 SimpleDateFormat (android.icu.text.SimpleDateFormat)1 Currency (android.icu.util.Currency)1 List (java.util.List)1 MissingResourceException (java.util.MissingResourceException)1 ResourceBundle (java.util.ResourceBundle)1