Search in sources :

Example 1 with UResourceTypeMismatchException

use of android.icu.util.UResourceTypeMismatchException 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 2 with UResourceTypeMismatchException

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

the class ICUResourceBundleTest method TestCoverage.

public void TestCoverage() {
    UResourceBundle bundle;
    bundle = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME);
    if (bundle == null) {
        errln("UResourceBundle.getBundleInstance(String baseName) failed");
    }
    bundle = null;
    bundle = UResourceBundle.getBundleInstance(ULocale.getDefault());
    if (bundle == null) {
        errln("UResourceBundle.getBundleInstance(ULocale) failed");
        return;
    }
    if (new UResourceTypeMismatchException("coverage") == null) {
        errln("Create UResourceTypeMismatchException error");
    }
    class Stub extends UResourceBundle {

        @Override
        public ULocale getULocale() {
            return ULocale.ROOT;
        }

        @Override
        protected String getLocaleID() {
            return null;
        }

        @Override
        protected String getBaseName() {
            return null;
        }

        @Override
        protected UResourceBundle getParent() {
            return null;
        }

        @Override
        public Enumeration getKeys() {
            return null;
        }

        @Override
        protected Object handleGetObject(String aKey) {
            return null;
        }
    }
    Stub stub = new Stub();
    if (!stub.getLocale().equals(ULocale.ROOT.toLocale())) {
        errln("UResourceBundle.getLoclae(Locale) should delegate to (ULocale)");
    }
}
Also used : ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) UResourceTypeMismatchException(android.icu.util.UResourceTypeMismatchException)

Example 3 with UResourceTypeMismatchException

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

the class ResourceModule method getFromTable.

static UResourceBundle getFromTable(UResourceBundle res, String key, int[] expResTypes) throws DataModuleFormatError {
    assert_is(res != null && key != null && res.getType() == UResourceBundle.TABLE);
    UResourceBundle t = res.get(key);
    assert_not(t == null);
    int type = t.getType();
    Arrays.sort(expResTypes);
    if (Arrays.binarySearch(expResTypes, type) >= 0) {
        return t;
    } else {
        throw new DataModuleFormatError(new UResourceTypeMismatchException("Actual type " + t.getType() + " != expected types " + Arrays.toString(expResTypes) + "."));
    }
}
Also used : UResourceBundle(android.icu.util.UResourceBundle) ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceTypeMismatchException(android.icu.util.UResourceTypeMismatchException)

Aggregations

ICUResourceBundle (android.icu.impl.ICUResourceBundle)3 UResourceBundle (android.icu.util.UResourceBundle)3 UResourceTypeMismatchException (android.icu.util.UResourceTypeMismatchException)3 ULocale (android.icu.util.ULocale)1 UResourceBundleIterator (android.icu.util.UResourceBundleIterator)1 Locale (java.util.Locale)1 MissingResourceException (java.util.MissingResourceException)1 NoSuchElementException (java.util.NoSuchElementException)1 Test (org.junit.Test)1