Search in sources :

Example 6 with GlobalizationPreferences

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

the class GlobalizationPreferencesTest method TestNumberFormat.

@Test
public void TestNumberFormat() {
    GlobalizationPreferences gp = new GlobalizationPreferences();
    NumberFormat nf;
    String numStr;
    double num = 123456.789;
    // Set unsupported locale with supported territory ang_KR
    logln("Set locale - ang_KR");
    gp.setLocale(new ULocale("ang_KR"));
    nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
    numStr = nf.format(num);
    if (!numStr.equals("\u20a9\u00a0123,457")) {
        errln("FAIL: Number string is " + numStr + " Expected: \u20a9\u00a0123,457");
    }
    // Set locale - de_DE
    logln("Set locale - de_DE");
    gp.setLocale(new ULocale("de_DE"));
    // NF_NUMBER
    logln("NUMBER type");
    nf = gp.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
    numStr = nf.format(num);
    if (!numStr.equals("123.456,789")) {
        errln("FAIL: Number string is " + numStr + " Expected: 123.456,789");
    }
    // NF_CURRENCY
    logln("CURRENCY type");
    nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
    numStr = nf.format(num);
    if (!numStr.equals("123.456,79\u00a0\u20AC")) {
        errln("FAIL: Number string is " + numStr + " Expected: 123.456,79\u00a0\u20AC");
    }
    // NF_PERCENT
    logln("PERCENT type");
    nf = gp.getNumberFormat(GlobalizationPreferences.NF_PERCENT);
    numStr = nf.format(num);
    if (!numStr.equals("12.345.679\u00a0%")) {
        errln("FAIL: Number string is " + numStr + " Expected: 12.345.679\u00a0%");
    }
    // NF_SCIENTIFIC
    logln("SCIENTIFIC type");
    nf = gp.getNumberFormat(GlobalizationPreferences.NF_SCIENTIFIC);
    numStr = nf.format(num);
    if (!numStr.equals("1,23456789E5")) {
        errln("FAIL: Number string is " + numStr + " Expected: 1,23456789E5");
    }
    // NF_INTEGER
    logln("INTEGER type");
    nf = gp.getNumberFormat(GlobalizationPreferences.NF_INTEGER);
    numStr = nf.format(num);
    if (!numStr.equals("123.457")) {
        errln("FAIL: Number string is " + numStr + " Expected: 123.457");
    }
    // Invalid number type
    logln("INVALID type");
    boolean illegalArg = false;
    try {
        nf = gp.getNumberFormat(100);
    } catch (IllegalArgumentException iae) {
        logln("Illegal number format type 100");
        illegalArg = true;
    }
    if (!illegalArg) {
        errln("FAIL: getNumberFormat must throw IllegalArgumentException for type 100");
    }
    illegalArg = false;
    try {
        nf = gp.getNumberFormat(-1);
    } catch (IllegalArgumentException iae) {
        logln("Illegal number format type -1");
        illegalArg = true;
    }
    if (!illegalArg) {
        errln("FAIL: getNumberFormat must throw IllegalArgumentException for type -1");
    }
    // Set explicit territory
    logln("Set territory - US");
    gp.setTerritory("US");
    nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
    numStr = nf.format(num);
    if (!numStr.equals("123.456,79\u00a0$")) {
        errln("FAIL: Number string is " + numStr + " Expected: 123.456,79\u00a0$");
    }
    // Set explicit currency
    logln("Set currency - GBP");
    gp.setCurrency(Currency.getInstance("GBP"));
    nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
    numStr = nf.format(num);
    if (!numStr.equals("123.456,79\u00a0\u00A3")) {
        errln("FAIL: Number string is " + numStr + " Expected: 123.456,79\u00a0\u00A3");
    }
    // Set exliplicit NumberFormat
    logln("Set explicit NumberFormat objects");
    NumberFormat customNum = NumberFormat.getNumberInstance(new ULocale("he_IL"));
    gp.setNumberFormat(GlobalizationPreferences.NF_NUMBER, customNum);
    NumberFormat customCur = NumberFormat.getCurrencyInstance(new ULocale("zh_CN"));
    gp.setNumberFormat(GlobalizationPreferences.NF_CURRENCY, customCur);
    NumberFormat customPct = NumberFormat.getPercentInstance(new ULocale("el_GR"));
    gp.setNumberFormat(GlobalizationPreferences.NF_PERCENT, customPct);
    NumberFormat customSci = NumberFormat.getScientificInstance(new ULocale("ru_RU"));
    gp.setNumberFormat(GlobalizationPreferences.NF_SCIENTIFIC, customSci);
    NumberFormat customInt = NumberFormat.getIntegerInstance(new ULocale("pt_PT"));
    gp.setNumberFormat(GlobalizationPreferences.NF_INTEGER, customInt);
    nf = gp.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
    if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("he_IL")) {
        errln("FAIL: The NumberFormat instance must use locale he_IL");
    }
    nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
    if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("zh_CN")) {
        errln("FAIL: The NumberFormat instance must use locale zh_CN");
    }
    nf = gp.getNumberFormat(GlobalizationPreferences.NF_PERCENT);
    if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("el_GR")) {
        errln("FAIL: The NumberFormat instance must use locale el_GR");
    }
    nf = gp.getNumberFormat(GlobalizationPreferences.NF_SCIENTIFIC);
    if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("ru_RU")) {
        errln("FAIL: The NumberFormat instance must use locale ru_RU");
    }
    nf = gp.getNumberFormat(GlobalizationPreferences.NF_INTEGER);
    if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("pt_PT")) {
        errln("FAIL: The NumberFormat instance must use locale pt_PT");
    }
    NumberFormat customNum1 = NumberFormat.getNumberInstance(new ULocale("hi_IN"));
    // Freeze
    logln("Freeze this object");
    boolean isFrozen = false;
    gp.freeze();
    try {
        gp.setNumberFormat(GlobalizationPreferences.NF_NUMBER, customNum1);
    } catch (UnsupportedOperationException uoe) {
        logln("setNumberFormat is blocked");
        isFrozen = true;
    }
    if (!isFrozen) {
        errln("FAIL: setNumberFormat must be blocked after frozen");
    }
    // Create a modifiable clone
    GlobalizationPreferences gp1 = (GlobalizationPreferences) gp.cloneAsThawed();
    // Number type format's locale is still he_IL
    nf = gp1.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
    if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("he_IL")) {
        errln("FAIL: The NumberFormat instance must use locale he_IL");
    }
    logln("Set custom number format using locale hi_IN");
    gp1.setNumberFormat(GlobalizationPreferences.NF_NUMBER, customNum1);
    nf = gp1.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
    if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals("hi_IN")) {
        errln("FAIL: The NumberFormat instance must use locale hi_IN");
    }
}
Also used : GlobalizationPreferences(android.icu.util.GlobalizationPreferences) ULocale(android.icu.util.ULocale) NumberFormat(android.icu.text.NumberFormat) Test(org.junit.Test)

Example 7 with GlobalizationPreferences

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

the class GlobalizationPreferencesTest method TestDisplayName.

@Test
public void TestDisplayName() {
    GlobalizationPreferences gp = new GlobalizationPreferences();
    ULocale loc_fr_FR_Paris = new ULocale("fr_FR_Paris");
    ULocale loc_peo = new ULocale("peo");
    // Locale list - fr_FR_Paris
    ArrayList locales1 = new ArrayList(1);
    locales1.add(loc_fr_FR_Paris);
    // Locale list - ain, fr_FR_Paris
    ArrayList locales2 = new ArrayList(2);
    locales2.add(loc_peo);
    locales2.add(loc_fr_FR_Paris);
    logln("Locales: <default> | <fr_FR_Paris> | <ain, fr_FR_Paris>");
    // ID_LOCALE
    String id = "zh_Hant_HK";
    String name1 = gp.getDisplayName(id, GlobalizationPreferences.ID_LOCALE);
    gp.setLocales(locales1);
    String name2 = gp.getDisplayName(id, GlobalizationPreferences.ID_LOCALE);
    gp.setLocales(locales2);
    String name3 = gp.getDisplayName(id, GlobalizationPreferences.ID_LOCALE);
    logln("Locale[zh_Hant_HK]: " + name1 + " | " + name2 + " | " + name3);
    if (name1.equals(name2) || !name2.equals(name3)) {
        errln("FAIL: Locale ID");
    }
    // ID_LANGUAGE
    gp.reset();
    id = "fr";
    name1 = gp.getDisplayName(id, GlobalizationPreferences.ID_LANGUAGE);
    gp.setLocales(locales1);
    name2 = gp.getDisplayName(id, GlobalizationPreferences.ID_LANGUAGE);
    gp.setLocales(locales2);
    name3 = gp.getDisplayName(id, GlobalizationPreferences.ID_LANGUAGE);
    logln("Language[fr]: " + name1 + " | " + name2 + " | " + name3);
    if (name1.equals(name2) || !name2.equals(name3)) {
        errln("FAIL: Language ID");
    }
    // ID_SCRIPT
    gp.reset();
    id = "cyrl";
    name1 = gp.getDisplayName(id, GlobalizationPreferences.ID_SCRIPT);
    gp.setLocales(locales1);
    name2 = gp.getDisplayName(id, GlobalizationPreferences.ID_SCRIPT);
    gp.setLocales(locales2);
    name3 = gp.getDisplayName(id, GlobalizationPreferences.ID_SCRIPT);
    logln("Script[cyrl]: " + name1 + " | " + name2 + " | " + name3);
    if (name1.equals(name2) || !name2.equals(name3)) {
        errln("FAIL: Script ID");
    }
    // ID_TERRITORY
    gp.reset();
    id = "JP";
    name1 = gp.getDisplayName(id, GlobalizationPreferences.ID_TERRITORY);
    gp.setLocales(locales1);
    name2 = gp.getDisplayName(id, GlobalizationPreferences.ID_TERRITORY);
    gp.setLocales(locales2);
    name3 = gp.getDisplayName(id, GlobalizationPreferences.ID_TERRITORY);
    logln("Territory[JP]: " + name1 + " | " + name2 + " | " + name3);
    if (name1.equals(name2) || !name2.equals(name3)) {
        errln("FAIL: Territory ID");
    }
    // ID_VARIANT
    gp.reset();
    id = "NEDIS";
    name1 = gp.getDisplayName(id, GlobalizationPreferences.ID_VARIANT);
    gp.setLocales(locales1);
    name2 = gp.getDisplayName(id, GlobalizationPreferences.ID_VARIANT);
    gp.setLocales(locales2);
    name3 = gp.getDisplayName(id, GlobalizationPreferences.ID_VARIANT);
    logln("Variant[NEDIS]: " + name1 + " | " + name2 + " | " + name3);
    if (name1.equals(name2) || !name2.equals(name3)) {
        errln("FAIL: Variant ID");
    }
    // ID_KEYWORD
    gp.reset();
    id = "collation";
    name1 = gp.getDisplayName(id, GlobalizationPreferences.ID_KEYWORD);
    gp.setLocales(locales1);
    name2 = gp.getDisplayName(id, GlobalizationPreferences.ID_KEYWORD);
    gp.setLocales(locales2);
    name3 = gp.getDisplayName(id, GlobalizationPreferences.ID_KEYWORD);
    logln("Keyword[collation]: " + name1 + " | " + name2 + " | " + name3);
    if (name1.equals(name2) || !name2.equals(name3)) {
        errln("FAIL: Keyword ID");
    }
    // ID_KEYWORD_VALUE
    gp.reset();
    id = "collation=traditional";
    name1 = gp.getDisplayName(id, GlobalizationPreferences.ID_KEYWORD_VALUE);
    gp.setLocales(locales1);
    name2 = gp.getDisplayName(id, GlobalizationPreferences.ID_KEYWORD_VALUE);
    gp.setLocales(locales2);
    name3 = gp.getDisplayName(id, GlobalizationPreferences.ID_KEYWORD_VALUE);
    logln("Keyword value[traditional]: " + name1 + " | " + name2 + " | " + name3);
    if (name1.equals(name2) || !name2.equals(name3)) {
        errln("FAIL: Keyword value ID");
    }
    // ID_CURRENCY_SYMBOL
    gp.reset();
    id = "USD";
    name1 = gp.getDisplayName(id, GlobalizationPreferences.ID_CURRENCY_SYMBOL);
    gp.setLocales(locales1);
    name2 = gp.getDisplayName(id, GlobalizationPreferences.ID_CURRENCY_SYMBOL);
    gp.setLocales(locales2);
    name3 = gp.getDisplayName(id, GlobalizationPreferences.ID_CURRENCY_SYMBOL);
    logln("Currency symbol[USD]: " + name1 + " | " + name2 + " | " + name3);
    String dollar = "$";
    String us_dollar = "$US";
    if (!name1.equals(dollar) || !name2.equals(us_dollar) || !name3.equals(us_dollar)) {
        errln("FAIL: Currency symbol ID");
    }
    // ID_CURRENCY
    gp.reset();
    id = "USD";
    name1 = gp.getDisplayName(id, GlobalizationPreferences.ID_CURRENCY);
    gp.setLocales(locales1);
    name2 = gp.getDisplayName(id, GlobalizationPreferences.ID_CURRENCY);
    gp.setLocales(locales2);
    name3 = gp.getDisplayName(id, GlobalizationPreferences.ID_CURRENCY);
    logln("Currency[USD]: " + name1 + " | " + name2 + " | " + name3);
    if (name1.equals(name2) || !name2.equals(name3)) {
        errln("FAIL: Currency ID");
    }
    // ID_TIMEZONE
    gp.reset();
    id = "Europe/Paris";
    name1 = gp.getDisplayName(id, GlobalizationPreferences.ID_TIMEZONE);
    gp.setLocales(locales1);
    name2 = gp.getDisplayName(id, GlobalizationPreferences.ID_TIMEZONE);
    gp.setLocales(locales2);
    name3 = gp.getDisplayName(id, GlobalizationPreferences.ID_TIMEZONE);
    logln("Timezone[Europe/Paris]: " + name1 + " | " + name2 + " | " + name3);
    if (name1.equals(name2) || !name2.equals(name3)) {
        errln("FAIL: Timezone ID");
    }
    // Illegal ID
    gp.reset();
    boolean illegalArg = false;
    try {
        name1 = gp.getDisplayName(id, -1);
    } catch (IllegalArgumentException iae) {
        logln("Illegal type -1");
        illegalArg = true;
    }
    if (!illegalArg) {
        errln("FAIL: getDisplayName must throw IllegalArgumentException for type -1");
    }
    illegalArg = false;
    try {
        name1 = gp.getDisplayName(id, 100);
    } catch (IllegalArgumentException iae) {
        logln("Illegal type 100");
        illegalArg = true;
    }
    if (!illegalArg) {
        errln("FAIL: getDisplayName must throw IllegalArgumentException for type 100");
    }
}
Also used : GlobalizationPreferences(android.icu.util.GlobalizationPreferences) ULocale(android.icu.util.ULocale) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with GlobalizationPreferences

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

the class GlobalizationPreferencesTest method TestCurrency.

@Test
public void TestCurrency() {
    GlobalizationPreferences gp = new GlobalizationPreferences();
    // Set language only locale - ja
    logln("Set locale - ja");
    gp.setLocale(new ULocale("ja"));
    Currency cur = gp.getCurrency();
    String code = cur.getCurrencyCode();
    if (!code.equals("JPY")) {
        errln("FAIL: Currency is " + code + " - Expected: JPY");
    }
    gp.reset();
    // Set locales with territory
    logln("Set locale - ja_US");
    gp.setLocale(new ULocale("ja_US"));
    cur = gp.getCurrency();
    code = cur.getCurrencyCode();
    if (!code.equals("USD")) {
        errln("FAIL: Currency is " + code + " - Expected: USD");
    }
    // Set locales with territory in the second locale
    logln("Set locales - it, en_US");
    ULocale[] locales = new ULocale[2];
    locales[0] = new ULocale("it");
    locales[1] = new ULocale("en_US");
    gp.setLocales(locales);
    cur = gp.getCurrency();
    code = cur.getCurrencyCode();
    if (!code.equals("USD")) {
        errln("FAIL: Currency is " + code + " - Expected: USD");
    }
    // Set explicit territory
    logln("Set territory - DE");
    gp.setTerritory("DE");
    cur = gp.getCurrency();
    code = cur.getCurrencyCode();
    if (!code.equals("EUR")) {
        errln("FAIL: Currency is " + code + " - Expected: EUR");
    }
    // Set explicit currency
    Currency ecur = Currency.getInstance("BRL");
    gp.setCurrency(ecur);
    logln("Set explicit currency - BRL");
    cur = gp.getCurrency();
    code = cur.getCurrencyCode();
    if (!code.equals("BRL")) {
        errln("FAIL: Currency is " + code + " - Expected: BRL");
    }
    // Set explicit territory again
    logln("Set territory - JP");
    cur = gp.getCurrency();
    code = cur.getCurrencyCode();
    if (!code.equals("BRL")) {
        errln("FAIL: Currency is " + code + " - Expected: BRL");
    }
    // Freeze
    logln("Freeze this object");
    Currency ecur2 = Currency.getInstance("CHF");
    boolean bFrozen = false;
    gp.freeze();
    try {
        gp.setCurrency(ecur2);
    } catch (UnsupportedOperationException uoe) {
        logln("setCurrency is blocked");
        bFrozen = true;
    }
    if (!bFrozen) {
        errln("FAIL: setCurrency must be blocked");
    }
    // Safe clone
    logln("cloneAsThawed");
    GlobalizationPreferences gp1 = (GlobalizationPreferences) gp.cloneAsThawed();
    cur = gp.getCurrency();
    code = cur.getCurrencyCode();
    if (!code.equals("BRL")) {
        errln("FAIL: Currency is " + code + " - Expected: BRL");
    }
    // Set ecplicit currency
    gp1.setCurrency(ecur2);
    cur = gp1.getCurrency();
    code = cur.getCurrencyCode();
    if (!code.equals("CHF")) {
        errln("FAIL: Currency is " + code + " - Expected: CHF");
    }
}
Also used : GlobalizationPreferences(android.icu.util.GlobalizationPreferences) ULocale(android.icu.util.ULocale) Currency(android.icu.util.Currency) Test(org.junit.Test)

Example 9 with GlobalizationPreferences

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

the class GlobalizationPreferencesTest method TestSetLocales.

@Test
public void TestSetLocales() {
    GlobalizationPreferences gp = new GlobalizationPreferences();
    // setLocales(List)
    for (int i = 0; i < INPUT_LOCALEIDS.length; i++) {
        String[] localeStrings = INPUT_LOCALEIDS[i];
        ArrayList locales = new ArrayList();
        StringBuffer sb = new StringBuffer();
        for (int j = 0; j < localeStrings.length; j++) {
            locales.add(new ULocale(localeStrings[j]));
            if (j != 0) {
                sb.append(", ");
            }
            sb.append(localeStrings[j]);
        }
        logln("Input locales: " + sb.toString());
        gp.reset();
        gp.setLocales(locales);
        List resultLocales = gp.getLocales();
        if (resultLocales.size() != RESULTS_LOCALEIDS[i].length) {
            errln("FAIL: Number of locales mismatch - GP:" + resultLocales.size() + " Expected:" + RESULTS_LOCALEIDS[i].length);
        } else {
            for (int j = 0; j < RESULTS_LOCALEIDS[i].length; j++) {
                ULocale loc = gp.getLocale(j);
                logln("Locale[" + j + "]: " + loc.toString());
                if (!gp.getLocale(j).toString().equals(RESULTS_LOCALEIDS[i][j])) {
                    errln("FAIL: Locale index(" + j + ") does not match - GP:" + loc.toString() + " Expected:" + RESULTS_LOCALEIDS[i][j]);
                }
            }
        }
    }
    // setLocales(ULocale[])
    for (int i = 0; i < INPUT_LOCALEIDS.length; i++) {
        String[] localeStrings = INPUT_LOCALEIDS[i];
        ULocale[] localeArray = new ULocale[INPUT_LOCALEIDS[i].length];
        StringBuffer sb = new StringBuffer();
        for (int j = 0; j < localeStrings.length; j++) {
            localeArray[j] = new ULocale(localeStrings[j]);
            if (j != 0) {
                sb.append(", ");
            }
            sb.append(localeStrings[j]);
        }
        logln("Input locales: " + sb.toString());
        gp.reset();
        gp.setLocales(localeArray);
        List resultLocales = gp.getLocales();
        if (resultLocales.size() != RESULTS_LOCALEIDS[i].length) {
            errln("FAIL: Number of locales mismatch - GP:" + resultLocales.size() + " Expected:" + RESULTS_LOCALEIDS[i].length);
        } else {
            for (int j = 0; j < RESULTS_LOCALEIDS[i].length; j++) {
                ULocale loc = gp.getLocale(j);
                logln("Locale[" + j + "]: " + loc.toString());
                if (!gp.getLocale(j).toString().equals(RESULTS_LOCALEIDS[i][j])) {
                    errln("FAIL: Locale index(" + j + ") does not match - GP:" + loc.toString() + " Expected:" + RESULTS_LOCALEIDS[i][j]);
                }
            }
        }
    }
    // setLocales(String)
    for (int i = 0; i < ACCEPT_LANGUAGES.length; i++) {
        String acceptLanguage = ACCEPT_LANGUAGES[i];
        logln("Accept language: " + acceptLanguage);
        gp.reset();
        gp.setLocales(acceptLanguage);
        List resultLocales = gp.getLocales();
        if (resultLocales.size() != RESULTS_LOCALEIDS[i].length) {
            errln("FAIL: Number of locales mismatch - GP:" + resultLocales.size() + " Expected:" + RESULTS_LOCALEIDS[i].length);
        } else {
            for (int j = 0; j < RESULTS_LOCALEIDS[i].length; j++) {
                ULocale loc = gp.getLocale(j);
                logln("Locale[" + j + "]: " + loc.toString());
                if (!gp.getLocale(j).toString().equals(RESULTS_LOCALEIDS[i][j])) {
                    errln("FAIL: Locale index(" + j + ") does not match - GP:" + loc.toString() + " Expected:" + RESULTS_LOCALEIDS[i][j]);
                }
            }
        }
    }
    // accept-language without q-value
    logln("Set accept-language - de,de-AT");
    gp.setLocales("de,de-AT");
    if (!gp.getLocale(0).toString().equals("de_AT")) {
        errln("FAIL: getLocale(0) returns " + gp.getLocale(0).toString() + " Expected: de_AT");
    }
    // Invalid accept-language
    logln("Set locale - ko_KR");
    gp.setLocale(new ULocale("ko_KR"));
    boolean bException = false;
    try {
        logln("Set invlaid accept-language - ko=100");
        gp.setLocales("ko=100");
    } catch (IllegalArgumentException iae) {
        logln("IllegalArgumentException was thrown");
        bException = true;
    }
    if (!bException) {
        errln("FAIL: IllegalArgumentException was not thrown for illegal accept-language - ko=100");
    }
    if (!gp.getLocale(0).toString().equals("ko_KR")) {
        errln("FAIL: Previous valid locale list had gone");
    }
}
Also used : GlobalizationPreferences(android.icu.util.GlobalizationPreferences) ULocale(android.icu.util.ULocale) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 10 with GlobalizationPreferences

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

the class GlobalizationPreferencesTest method TestFreezable.

@Test
public void TestFreezable() {
    logln("Create a new GlobalizationPreference object");
    GlobalizationPreferences gp = new GlobalizationPreferences();
    if (gp.isFrozen()) {
        errln("FAIL: This object is not yet frozen");
    }
    logln("Call reset()");
    boolean bSet = true;
    try {
        gp.reset();
    } catch (UnsupportedOperationException uoe) {
        bSet = false;
    }
    if (!bSet) {
        errln("FAIL: reset() must not throw an exception before frozen");
    }
    // Freeze the object
    logln("Freeze the object");
    gp.freeze();
    if (!gp.isFrozen()) {
        errln("FAIL: This object is already fronzen");
    }
    // reset()
    logln("Call reset() after frozen");
    bSet = true;
    try {
        gp.reset();
    } catch (UnsupportedOperationException uoe) {
        bSet = false;
    }
    if (bSet) {
        errln("FAIL: reset() must be blocked after frozen");
    }
    // setLocales(ULocale[])
    logln("Call setLocales(ULocale[]) after frozen");
    bSet = true;
    try {
        gp.setLocales(new ULocale[] { new ULocale("fr_FR") });
    } catch (UnsupportedOperationException uoe) {
        bSet = false;
    }
    if (bSet) {
        errln("FAIL: setLocales(ULocale[]) must be blocked after frozen");
    }
    // setLocales(ULocale[])
    logln("Call setLocales(List) after frozen");
    bSet = true;
    ArrayList list = new ArrayList(1);
    list.add(new ULocale("fr_FR"));
    try {
        gp.setLocales(list);
    } catch (UnsupportedOperationException uoe) {
        bSet = false;
    }
    if (bSet) {
        errln("FAIL: setLocales(List) must be blocked after frozen");
    }
    // setLocales(String)
    logln("Call setLocales(String) after frozen");
    bSet = true;
    try {
        gp.setLocales("pt-BR,es;q=0.7");
    } catch (UnsupportedOperationException uoe) {
        bSet = false;
    }
    if (bSet) {
        errln("FAIL: setLocales(String) must be blocked after frozen");
    }
    // setLocale(ULocale)
    logln("Call setLocale(ULocale) after frozen");
    bSet = true;
    try {
        gp.setLocale(new ULocale("fi_FI"));
    } catch (UnsupportedOperationException uoe) {
        bSet = false;
    }
    if (bSet) {
        errln("FAIL: setLocale(ULocale) must be blocked after frozen");
    }
    // setTerritory(String)
    logln("Call setTerritory(String) after frozen");
    bSet = true;
    try {
        gp.setTerritory("AU");
    } catch (UnsupportedOperationException uoe) {
        bSet = false;
    }
    if (bSet) {
        errln("FAIL: setTerritory(String) must be blocked after frozen");
    }
    // Modifiable clone
    logln("Create a modifiable clone");
    GlobalizationPreferences gp1 = (GlobalizationPreferences) gp.cloneAsThawed();
    if (gp1.isFrozen()) {
        errln("FAIL: The object returned by cloneAsThawed() must not be frozen yet");
    }
    // setLocale(ULocale)
    logln("Call setLocale(ULocale) of the modifiable clone");
    bSet = true;
    try {
        gp1.setLocale(new ULocale("fr_FR"));
    } catch (UnsupportedOperationException uoe) {
        bSet = false;
    }
    if (!bSet) {
        errln("FAIL: setLocales(ULocale) must not throw an exception before frozen");
    }
}
Also used : GlobalizationPreferences(android.icu.util.GlobalizationPreferences) ULocale(android.icu.util.ULocale) ArrayList(java.util.ArrayList) 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