Search in sources :

Example 16 with UResourceBundle

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

the class ICUResourceBundleTest method TestUResourceBundleCoverage.

@Test
public void TestUResourceBundleCoverage() {
    Locale locale = null;
    ULocale ulocale = null;
    String baseName = null;
    UResourceBundle rb1, rb2, rb3, rb4, rb5, rb6, rb7;
    rb1 = UResourceBundle.getBundleInstance(ulocale);
    rb2 = UResourceBundle.getBundleInstance(baseName);
    rb3 = UResourceBundle.getBundleInstance(baseName, ulocale);
    rb4 = UResourceBundle.getBundleInstance(baseName, locale);
    rb5 = UResourceBundle.getBundleInstance(baseName, ulocale, testLoader);
    rb6 = UResourceBundle.getBundleInstance(baseName, locale, testLoader);
    try {
        rb7 = UResourceBundle.getBundleInstance("bogus", Locale.getDefault(), testLoader);
        errln("Should have thrown exception with bogus baseName.");
    } catch (java.util.MissingResourceException ex) {
    }
    if (rb1 == null || rb2 == null || rb3 == null || rb4 == null || rb5 == null || rb6 == null) {
        errln("Error getting resource bundle.");
    }
    rb7 = UResourceBundle.getBundleInstance("android.icu.dev.data.resources.TestDataElements", Locale.getDefault(), testLoader);
    try {
        rb1.getBinary();
        errln("getBinary() call should have thrown UResourceTypeMismatchException.");
    } catch (UResourceTypeMismatchException ex) {
    }
    try {
        rb1.getStringArray();
        errln("getStringArray() call should have thrown UResourceTypeMismatchException.");
    } catch (UResourceTypeMismatchException ex) {
    }
    try {
        byte[] ba = { 0x00 };
        rb1.getBinary(ba);
        errln("getBinary(byte[]) call should have thrown UResourceTypeMismatchException.");
    } catch (UResourceTypeMismatchException ex) {
    }
    try {
        rb1.getInt();
        errln("getInt() call should have thrown UResourceTypeMismatchException.");
    } catch (UResourceTypeMismatchException ex) {
    }
    try {
        rb1.getIntVector();
        errln("getIntVector() call should have thrown UResourceTypeMismatchException.");
    } catch (UResourceTypeMismatchException ex) {
    }
    try {
        rb1.getUInt();
        errln("getUInt() call should have thrown UResourceTypeMismatchException.");
    } catch (UResourceTypeMismatchException ex) {
    }
    if (rb1.getVersion() != null) {
        errln("getVersion() call should have returned null.");
    }
    if (rb7.getType() != UResourceBundle.NONE) {
        errln("getType() call should have returned NONE.");
    }
    if (rb7.getKey() != null) {
        errln("getKey() call should have returned null.");
    }
    if (((ICUResourceBundle) rb1).findTopLevel(0) == null) {
        errln("Error calling findTopLevel().");
    }
    if (ICUResourceBundle.getFullLocaleNameSet() == null) {
        errln("Error calling getFullLocaleNameSet().");
    }
    UResourceBundleIterator itr = rb1.getIterator();
    while (itr.hasNext()) {
        itr.next();
    }
    try {
        itr.next();
        errln("NoSuchElementException exception should have been thrown.");
    } catch (NoSuchElementException ex) {
    }
    try {
        itr.nextString();
        errln("NoSuchElementException exception should have been thrown.");
    } catch (NoSuchElementException ex) {
    }
}
Also used : Locale(java.util.Locale) ULocale(android.icu.util.ULocale) ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) UResourceBundleIterator(android.icu.util.UResourceBundleIterator) ULocale(android.icu.util.ULocale) MissingResourceException(java.util.MissingResourceException) UResourceTypeMismatchException(android.icu.util.UResourceTypeMismatchException) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 17 with UResourceBundle

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

the class ICUResourceBundleTest method TestAlias.

@Test
public void TestAlias() {
    logln("Testing %%ALIAS");
    UResourceBundle rb = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "iw_IL");
    UResourceBundle b = rb.get("NumberElements");
    if (b != null) {
        if (b.getSize() > 0) {
            logln("%%ALIAS mechanism works");
        } else {
            errln("%%ALIAS mechanism failed for iw_IL NumberElements");
        }
    } else {
        errln("%%ALIAS mechanism failed for iw_IL");
    }
}
Also used : ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) Test(org.junit.Test)

Example 18 with UResourceBundle

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

the class ICUResourceBundleTest method TestICUGetKeysForResourceItem.

/**
 * Test ICUResourceBundle.getKeys() for a resource item (not a whole bundle/top-level resource).
 * This does not take parent bundles into account.
 */
@Test
public void TestICUGetKeysForResourceItem() {
    String baseName = "android/icu/dev/data/testdata";
    UResourceBundle te = UResourceBundle.getBundleInstance(baseName, "te", testLoader);
    UResourceBundle tagged_array_in_Root_te = te.get("tagged_array_in_Root_te");
    Set<String> keys = setFromEnumeration(tagged_array_in_Root_te.getKeys());
    assertTrue("tagged_array_in_Root_te.getKeys().contains(tag0)", keys.contains("tag0"));
    assertTrue("tagged_array_in_Root_te.getKeys().contains(tag1)", keys.contains("tag1"));
    assertFalse("tagged_array_in_Root_te.getKeys().contains(tag7)", keys.contains("tag7"));
    assertFalse("tagged_array_in_Root_te.getKeys().contains(tag12)", keys.contains("tag12"));
    UResourceBundle array_in_Root_te = te.get("array_in_Root_te");
    assertFalse("array_in_Root_te.getKeys().hasMoreElements()", array_in_Root_te.getKeys().hasMoreElements());
    UResourceBundle string_in_Root_te = te.get("string_in_Root_te");
    assertFalse("string_in_Root_te.getKeys().hasMoreElements()", string_in_Root_te.getKeys().hasMoreElements());
}
Also used : ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) Test(org.junit.Test)

Example 19 with UResourceBundle

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

the class ICUResourceBundleTest method TestOpen.

@Test
public void TestOpen() {
    UResourceBundle bundle = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "en_US_POSIX");
    if (bundle == null) {
        errln("could not create the resource bundle");
    }
    UResourceBundle obj = bundle.get("NumberElements").get("latn").get("patterns");
    int size = obj.getSize();
    int type = obj.getType();
    if (type == UResourceBundle.TABLE) {
        UResourceBundle sub;
        for (int i = 0; i < size; i++) {
            sub = obj.get(i);
            String temp = sub.getString();
            if (temp.length() == 0) {
                errln("Failed to get the items from number patterns table in bundle: " + bundle.getULocale().getBaseName());
            }
        // System.out.println("\""+prettify(temp)+"\"");
        }
    }
    obj = bundle.get("NumberElements").get("latn").get("symbols");
    size = obj.getSize();
    type = obj.getType();
    if (type == UResourceBundle.TABLE) {
        UResourceBundle sub;
        for (int i = 0; i < size; i++) {
            sub = obj.get(i);
            String temp = sub.getString();
            if (temp.length() == 0) {
                errln("Failed to get the items from number symbols table in bundle: " + bundle.getULocale().getBaseName());
            }
        // System.out.println("\""+prettify(temp)+"\"");
        }
    }
    if (bundle == null) {
        errln("could not create the resource bundle");
    }
    bundle = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "zzz_ZZ_very_very_very_long_bogus_bundle");
    if (!bundle.getULocale().equals(ULocale.getDefault())) {
        errln("UResourceBundle did not load the default bundle when bundle was not found. Default: " + ULocale.getDefault() + ", Bundle locale: " + bundle.getULocale());
    }
}
Also used : ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) Test(org.junit.Test)

Example 20 with UResourceBundle

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

the class ICUResourceBundleTest method TestCircularAliases.

@Test
public void TestCircularAliases() {
    try {
        UResourceBundle rb = UResourceBundle.getBundleInstance("android/icu/dev/data/testdata", "testaliases", testLoader);
        UResourceBundle sub = rb.get("aaa");
        String s1 = sub.getString();
        if (s1 != null) {
            errln("Did not get the expected exception");
        }
    } catch (IllegalArgumentException ex) {
        logln("got expected exception for circular references");
    } catch (MissingResourceException ex) {
        warnln("could not load resource data: " + ex.getMessage());
    }
}
Also used : ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) MissingResourceException(java.util.MissingResourceException) Test(org.junit.Test)

Aggregations

UResourceBundle (android.icu.util.UResourceBundle)46 ICUResourceBundle (android.icu.impl.ICUResourceBundle)26 MissingResourceException (java.util.MissingResourceException)24 Test (org.junit.Test)17 ULocale (android.icu.util.ULocale)8 UResourceBundleIterator (android.icu.util.UResourceBundleIterator)6 UResourceTypeMismatchException (android.icu.util.UResourceTypeMismatchException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 SimpleTimeZone (android.icu.util.SimpleTimeZone)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 EnumSet (java.util.EnumSet)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 JavaTimeZone (android.icu.impl.JavaTimeZone)1