Search in sources :

Example 1 with LocaleData

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

the class LocaleDataTest method TestEnglishExemplarCharacters.

// Simple test case for checking exemplar character type coverage
@Test
public void TestEnglishExemplarCharacters() {
    final char[] testChars = { // standard
    0x61, // auxiliary
    0xE1, // index
    0x41, // filler for deprecated currency exemplar
    0, // punctuation
    0x2D };
    LocaleData ld = LocaleData.getInstance(ULocale.ENGLISH);
    for (int type = 0; type < LocaleData.ES_COUNT; type++) {
        UnicodeSet exSet = ld.getExemplarSet(0, type);
        if (exSet != null) {
            if (testChars[type] > 0 && !exSet.contains(testChars[type])) {
                errln("Character '" + testChars[type] + "' is not included in exemplar type " + type);
            }
        }
    }
    try {
        // out of bounds value
        ld.getExemplarSet(0, LocaleData.ES_COUNT);
        throw new ICUException("Test failure; should throw exception");
    } catch (IllegalArgumentException e) {
        assertEquals("", "java.lang.ArrayIndexOutOfBoundsException", e.getCause().getClass().getName());
    }
}
Also used : LocaleData(android.icu.util.LocaleData) ICUException(android.icu.util.ICUException) UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Example 2 with LocaleData

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

the class LocaleDataTest method TestFallback.

@Test
public void TestFallback() {
    LocaleData fr_FR = LocaleData.getInstance(ULocale.FRANCE);
    LocaleData fr_CH = LocaleData.getInstance(new ULocale("fr_CH"));
    // This better not crash when only some values are overridden
    assertEquals("Start quotes are not equal", fr_FR.getDelimiter(LocaleData.QUOTATION_START), fr_CH.getDelimiter(LocaleData.QUOTATION_START));
    assertEquals("End quotes are not equals", fr_FR.getDelimiter(LocaleData.QUOTATION_END), fr_CH.getDelimiter(LocaleData.QUOTATION_END));
    assertNotEquals("Alt start quotes are equal", fr_FR.getDelimiter(LocaleData.ALT_QUOTATION_START), fr_CH.getDelimiter(LocaleData.ALT_QUOTATION_START));
    assertNotEquals("Alt end quotes are equals", fr_FR.getDelimiter(LocaleData.ALT_QUOTATION_END), fr_CH.getDelimiter(LocaleData.ALT_QUOTATION_END));
}
Also used : LocaleData(android.icu.util.LocaleData) ULocale(android.icu.util.ULocale) Test(org.junit.Test)

Example 3 with LocaleData

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

the class LocaleDataTest method TestLocaleDisplayPattern.

@Test
public void TestLocaleDisplayPattern() {
    ULocale locale = ULocale.ENGLISH;
    LocaleData ld = LocaleData.getInstance(locale);
    String pattern = ld.getLocaleDisplayPattern();
    String separator = ld.getLocaleSeparator();
    logln("LocaleDisplayPattern for locale " + locale + ": " + pattern);
    if (!pattern.equals("{0} ({1})")) {
        errln("Unexpected LocaleDisplayPattern for locale: " + locale);
    }
    logln("LocaleSeparator for locale " + locale + ": " + separator);
    if (!separator.equals(", ")) {
        errln("Unexpected LocaleSeparator for locale: " + locale);
    }
    locale = ULocale.CHINESE;
    ld = LocaleData.getInstance(locale);
    pattern = ld.getLocaleDisplayPattern();
    separator = ld.getLocaleSeparator();
    logln("LocaleDisplayPattern for locale " + locale + ": " + pattern);
    if (!pattern.equals("{0}\uFF08{1}\uFF09")) {
        errln("Unexpected LocaleDisplayPattern for locale: " + locale);
    }
    logln("LocaleSeparator for locale " + locale + ": " + separator);
    if (!separator.equals("\uFF0C")) {
        errln("Unexpected LocaleSeparator for locale: " + locale);
    }
    for (int i = 0; i < availableLocales.length; i++) {
        locale = availableLocales[i];
        ld = LocaleData.getInstance(locale);
        logln(locale.toString() + " LocaleDisplayPattern:" + ld.getLocaleDisplayPattern());
        logln(locale.toString() + " LocaleSeparator:" + ld.getLocaleSeparator());
    }
}
Also used : LocaleData(android.icu.util.LocaleData) ULocale(android.icu.util.ULocale) Test(org.junit.Test)

Example 4 with LocaleData

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

the class LocaleDataTest method TestExemplarSet2.

@Test
public void TestExemplarSet2() {
    int equalCount = 0;
    HashSet testedExemplars = new HashSet();
    for (int i = 0; i < availableLocales.length; i++) {
        ULocale locale = availableLocales[i];
        LocaleData ld = LocaleData.getInstance(locale);
        int[] scriptCodes = UScript.getCode(locale);
        if (scriptCodes == null) {
            if (locale.toString().indexOf(("in")) < 0) {
                errln("UScript.getCode returned null for locale: " + locale);
            }
            continue;
        }
        UnicodeSet[] exemplarSets = new UnicodeSet[4];
        for (int k = 0; k < 2; ++k) {
            // for casing option in (normal, uncased)
            int option = (k == 0) ? 0 : UnicodeSet.CASE;
            for (int h = 0; h < 2; ++h) {
                int type = (h == 0) ? LocaleData.ES_STANDARD : LocaleData.ES_AUXILIARY;
                UnicodeSet exemplarSet = ld.getExemplarSet(option, type);
                exemplarSets[k * 2 + h] = exemplarSet;
                ExemplarGroup exGrp = new ExemplarGroup(exemplarSet, scriptCodes);
                if (!testedExemplars.contains(exGrp)) {
                    testedExemplars.add(exGrp);
                    UnicodeSet[] sets = new UnicodeSet[scriptCodes.length];
                    // create the UnicodeSets for the script
                    for (int j = 0; j < scriptCodes.length; j++) {
                        sets[j] = new UnicodeSet("[:" + UScript.getShortName(scriptCodes[j]) + ":]");
                    }
                    boolean existsInScript = false;
                    UnicodeSetIterator iter = new UnicodeSetIterator(exemplarSet);
                    // iterate over the
                    while (!existsInScript && iter.nextRange()) {
                        if (iter.codepoint != UnicodeSetIterator.IS_STRING) {
                            for (int j = 0; j < sets.length; j++) {
                                if (sets[j].contains(iter.codepoint, iter.codepointEnd)) {
                                    existsInScript = true;
                                    break;
                                }
                            }
                        } else {
                            for (int j = 0; j < sets.length; j++) {
                                if (sets[j].contains(iter.string)) {
                                    existsInScript = true;
                                    break;
                                }
                            }
                        }
                    }
                    // TODO: How to verify LocaleData.ES_AUXILIARY ???
                    if (existsInScript == false && h == 0) {
                        errln("ExemplarSet containment failed for locale,option,type : " + locale + ", " + option + ", " + type);
                    }
                }
            }
        }
        // This is expensive, so only do it if it will be visible
        if (isVerbose()) {
            logln(locale.toString() + " exemplar(ES_STANDARD)" + exemplarSets[0]);
            logln(locale.toString() + " exemplar(ES_AUXILIARY) " + exemplarSets[1]);
            logln(locale.toString() + " exemplar(case-folded,ES_STANDARD) " + exemplarSets[2]);
            logln(locale.toString() + " exemplar(case-folded,ES_AUXILIARY) " + exemplarSets[3]);
        }
        assertTrue(locale.toString() + " case-folded is a superset", exemplarSets[2].containsAll(exemplarSets[0]));
        assertTrue(locale.toString() + " case-folded is a superset", exemplarSets[3].containsAll(exemplarSets[1]));
        if (exemplarSets[2].equals(exemplarSets[0])) {
            ++equalCount;
        }
        if (exemplarSets[3].equals(exemplarSets[1])) {
            ++equalCount;
        }
    }
    // Note: The case-folded set should sometimes be a strict superset
    // and sometimes be equal.
    assertTrue("case-folded is sometimes a strict superset, and sometimes equal", equalCount > 0 && equalCount < availableLocales.length * 2);
}
Also used : UnicodeSetIterator(android.icu.text.UnicodeSetIterator) LocaleData(android.icu.util.LocaleData) ULocale(android.icu.util.ULocale) UnicodeSet(android.icu.text.UnicodeSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with LocaleData

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

the class LocaleDataTest method TestCoverage.

@Test
public void TestCoverage() {
    LocaleData ld = LocaleData.getInstance();
    boolean t = ld.getNoSubstitute();
    ld.setNoSubstitute(t);
    assertEquals("LocaleData get/set NoSubstitute", t, ld.getNoSubstitute());
    logln(ld.getDelimiter(LocaleData.QUOTATION_START));
    logln(ld.getDelimiter(LocaleData.QUOTATION_END));
    logln(ld.getDelimiter(LocaleData.ALT_QUOTATION_START));
    logln(ld.getDelimiter(LocaleData.ALT_QUOTATION_END));
}
Also used : LocaleData(android.icu.util.LocaleData) Test(org.junit.Test)

Aggregations

LocaleData (android.icu.util.LocaleData)5 Test (org.junit.Test)5 ULocale (android.icu.util.ULocale)3 UnicodeSet (android.icu.text.UnicodeSet)2 UnicodeSetIterator (android.icu.text.UnicodeSetIterator)1 ICUException (android.icu.util.ICUException)1 HashSet (java.util.HashSet)1