use of android.icu.util.UResourceBundle in project j2objc by google.
the class ICUResourceBundleTest method TestXPathAlias.
@Test
public void TestXPathAlias() {
UResourceBundle rb = UResourceBundle.getBundleInstance("android/icu/dev/data/testdata", "te_IN", testLoader);
UResourceBundle b = rb.get("aliasClient");
String result = b.getString();
String expResult = "correct";
if (!result.equals(expResult)) {
errln("Did not get the expected result for XPath style alias");
}
try {
UResourceBundle c = rb.get("rootAliasClient");
result = c.getString();
expResult = "correct";
if (!result.equals(expResult)) {
errln("Did not get the expected result for XPath style alias for rootAliasClient");
}
} catch (MissingResourceException ex) {
errln("Could not get rootAliasClient");
}
}
use of android.icu.util.UResourceBundle in project j2objc by google.
the class ICUResourceBundleTest method TestResourceBundleWrapper.
@Test
public void TestResourceBundleWrapper() {
UResourceBundle bundle = UResourceBundle.getBundleInstance("android.icu.impl.data.HolidayBundle", "da_DK");
Object o = bundle.getObject("holidays");
if (o instanceof Holiday[]) {
logln("wrapper mechanism works for Weekend data");
} else {
errln("Did not get the expected output for Weekend data");
}
bundle = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "bogus");
if (bundle instanceof UResourceBundle && bundle.getULocale().getName().equals("en_US")) {
logln("wrapper mechanism works for bogus locale");
} else {
errln("wrapper mechanism failed for bogus locale.");
}
try {
bundle = UResourceBundle.getBundleInstance("bogus", "bogus");
if (bundle != null) {
errln("Did not get the expected exception");
}
} catch (MissingResourceException ex) {
logln("got the expected exception");
}
}
use of android.icu.util.UResourceBundle in project j2objc by google.
the class ICUResourceBundleTest method TestICUGetKeysAtTopLevel.
/**
* Test ICUResourceBundle.getKeys() for a whole bundle (top-level resource).
* JDK JavaDoc for ResourceBundle.getKeys() says that it returns
* "an Enumeration of the keys contained in this ResourceBundle and its parent bundles."
*/
@Test
public void TestICUGetKeysAtTopLevel() {
String baseName = "android/icu/dev/data/testdata";
UResourceBundle te_IN = UResourceBundle.getBundleInstance(baseName, "te_IN", testLoader);
UResourceBundle te = UResourceBundle.getBundleInstance(baseName, "te", testLoader);
Set<String> te_set = setFromEnumeration(te.getKeys());
Set<String> te_IN_set = setFromEnumeration(te_IN.getKeys());
assertTrue("te.getKeys().contains(string_only_in_Root)", te_set.contains("string_only_in_Root"));
assertTrue("te.getKeys().contains(string_only_in_te)", te_set.contains("string_only_in_te"));
assertFalse("te.getKeys().contains(string_only_in_te_IN)", te_set.contains("string_only_in_te_IN"));
assertTrue("te_IN.getKeys().contains(string_only_in_Root)", te_IN_set.contains("string_only_in_Root"));
assertTrue("te_IN.getKeys().contains(string_only_in_te)", te_IN_set.contains("string_only_in_te"));
assertTrue("te_IN.getKeys().contains(string_only_in_te_IN)", te_IN_set.contains("string_only_in_te_IN"));
// TODO: Check for keys of alias resource items
}
use of android.icu.util.UResourceBundle in project j2objc by google.
the class ICUResourceBundleTest method TestAliases.
@Test
public void TestAliases() {
String simpleAlias = "Open";
UResourceBundle rb = UResourceBundle.getBundleInstance("android/icu/dev/data/testdata", "testaliases", testLoader);
if (rb == null) {
warnln("could not load testaliases data");
return;
}
UResourceBundle sub = rb.get("simplealias");
String s1 = sub.getString("simplealias");
if (s1.equals(simpleAlias)) {
logln("Alias mechanism works for simplealias");
} else {
errln("Did not get the expected output for simplealias");
}
{
try {
rb = UResourceBundle.getBundleInstance("android/icu/dev/data/testdata", "testaliases", testLoader);
sub = rb.get("nonexisting");
errln("Did not get the expected exception for nonexisting");
} catch (MissingResourceException ex) {
logln("Alias mechanism works for nonexisting alias");
}
}
{
rb = UResourceBundle.getBundleInstance("android/icu/dev/data/testdata", "testaliases", testLoader);
sub = rb.get("referencingalias");
s1 = sub.getString();
if (s1.equals("H:mm:ss")) {
logln("Alias mechanism works for referencingalias");
} else {
errln("Did not get the expected output for referencingalias");
}
}
{
UResourceBundle rb1 = UResourceBundle.getBundleInstance("android/icu/dev/data/testdata", "testaliases", testLoader);
if (rb1 != rb) {
errln("Caching of the resource bundle failed");
} else {
logln("Caching of resource bundle passed");
}
sub = rb1.get("testGetStringByKeyAliasing");
s1 = sub.get("KeyAlias0PST").getString();
if (s1.equals("America/Los_Angeles")) {
logln("Alias mechanism works for KeyAlias0PST");
} else {
errln("Did not get the expected output for KeyAlias0PST");
}
s1 = sub.getString("KeyAlias1PacificStandardTime");
if (s1.equals("Pacific Standard Time")) {
logln("Alias mechanism works for KeyAlias1PacificStandardTime");
} else {
errln("Did not get the expected output for KeyAlias1PacificStandardTime");
}
s1 = sub.getString("KeyAlias2PDT");
if (s1.equals("PDT")) {
logln("Alias mechanism works for KeyAlias2PDT");
} else {
errln("Did not get the expected output for KeyAlias2PDT");
}
s1 = sub.getString("KeyAlias3LosAngeles");
if (s1.equals("Los Angeles")) {
logln("Alias mechanism works for KeyAlias3LosAngeles. Got: " + s1);
} else {
errln("Did not get the expected output for KeyAlias3LosAngeles. Got: " + s1);
}
}
{
sub = rb.get("testGetStringByIndexAliasing");
s1 = sub.getString(0);
if (s1.equals("America/Los_Angeles")) {
logln("Alias mechanism works for testGetStringByIndexAliasing/0. Got: " + s1);
} else {
errln("Did not get the expected output for testGetStringByIndexAliasing/0. Got: " + s1);
}
s1 = sub.getString(1);
if (s1.equals("Pacific Standard Time")) {
logln("Alias mechanism works for testGetStringByIndexAliasing/1");
} else {
errln("Did not get the expected output for testGetStringByIndexAliasing/1");
}
s1 = sub.getString(2);
if (s1.equals("PDT")) {
logln("Alias mechanism works for testGetStringByIndexAliasing/2");
} else {
errln("Did not get the expected output for testGetStringByIndexAliasing/2");
}
s1 = sub.getString(3);
if (s1.equals("Los Angeles")) {
logln("Alias mechanism works for testGetStringByIndexAliasing/3. Got: " + s1);
} else {
errln("Did not get the expected output for testGetStringByIndexAliasing/3. Got: " + s1);
}
}
// Note: Following test cases are no longer working because collation data is now in the collation module
// {
// sub = rb.get("testAliasToTree" );
//
// ByteBuffer buf = sub.get("standard").get("%%CollationBin").getBinary();
// if(buf==null){
// errln("Did not get the expected output for %%CollationBin");
// }
// }
//
// rb = (UResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME,"zh_TW");
// UResourceBundle b = (UResourceBundle) rb.getObject("collations");
// if(b != null){
// if(b.get(0).getKey().equals( "default")){
// logln("Alias mechanism works");
// }else{
// errln("Alias mechanism failed for zh_TW collations");
// }
// }else{
// errln("Did not get the expected object for collations");
// }
// Test case for #7996
{
UResourceBundle bundle = UResourceBundle.getBundleInstance("android/icu/dev/data/testdata", "te", testLoader);
UResourceBundle table = bundle.get("tableT7996");
try {
String s = table.getString("a7996");
logln("Alias in nested table referring one in sh worked - " + s);
} catch (MissingResourceException e) {
errln("Alias in nested table referring one in sh failed");
}
try {
String s = ((ICUResourceBundle) table).getStringWithFallback("b7996");
logln("Alias with /LOCALE/ in nested table in root referring back to another key in the current locale bundle worked - " + s);
} catch (MissingResourceException e) {
errln("Alias with /LOCALE/ in nested table in root referring back to another key in the current locale bundle failed");
}
}
}
use of android.icu.util.UResourceBundle in project j2objc by google.
the class LocaleAliasTest method TestUResourceBundle.
@Test
public void TestUResourceBundle() {
ULocale defLoc = ULocale.getDefault();
ULocale.setDefault(_DEFAULT_LOCALE);
for (int i = 0; i < _LOCALE_NUMBER; i++) {
if (availableMap.get(_LOCALES[i][1]) == null) {
logln(_LOCALES[i][1] + " is not available. Skipping!");
continue;
}
ULocale oldLoc = _LOCALES[i][0];
ULocale newLoc = _LOCALES[i][1];
UResourceBundle urb1 = null;
UResourceBundle urb2 = null;
urb1 = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, oldLoc);
urb2 = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, newLoc);
ULocale l1 = urb1.getULocale();
ULocale l2 = urb2.getULocale();
if (!newLoc.equals(l1)) {
errln("ResourceBundleTest: newLoc!=l1: newLoc= " + newLoc + " l1= " + l1);
}
if (!l1.equals(l2)) {
errln("ResourceBundleTest: l1!=l2: l1= " + l1 + " l2= " + l2);
}
TestFmwk.logln("UResourceBundle old:" + l1 + " new:" + l2);
}
ULocale.setDefault(defLoc);
}
Aggregations