summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2014-06-19 12:28:24 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-06-19 12:28:24 +0000
commit8c83d2aa1fd7b7e3f9ca7415f9dfdf94de1314ec (patch)
tree1bfabea79e99fcf3957e99dd27e574592a948eba
parentbfbc1b512b2c31907dd9a90dace17a4346912d03 (diff)
parent2eb56b69de339978a29d94531759b465742f027f (diff)
downloadlibcore-8c83d2aa1fd7b7e3f9ca7415f9dfdf94de1314ec.zip
libcore-8c83d2aa1fd7b7e3f9ca7415f9dfdf94de1314ec.tar.gz
libcore-8c83d2aa1fd7b7e3f9ca7415f9dfdf94de1314ec.tar.bz2
am 2eb56b69: Merge "Fix CurrencyTest.test_getSymbol for unknown variants"
* commit '2eb56b69de339978a29d94531759b465742f027f': Fix CurrencyTest.test_getSymbol for unknown variants
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/util/CurrencyTest.java59
-rw-r--r--luni/src/main/java/libcore/icu/ICU.java7
-rw-r--r--luni/src/test/java/libcore/icu/ICUTest.java35
3 files changed, 60 insertions, 41 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/CurrencyTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/CurrencyTest.java
index 092cc54..07256e4 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/CurrencyTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/CurrencyTest.java
@@ -28,7 +28,18 @@ import java.util.Set;
public class CurrencyTest extends junit.framework.TestCase {
- private static Locale defaultLocale = Locale.getDefault();
+ private Locale originalLocale;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ originalLocale = Locale.getDefault();
+ }
+
+ @Override
+ protected void tearDown() {
+ Locale.setDefault(originalLocale);
+ }
/**
* java.util.Currency#getInstance(java.lang.String)
@@ -146,14 +157,16 @@ public class CurrencyTest extends junit.framework.TestCase {
assertEquals("currUS.getSymbol()", "$", currUS.getSymbol());
// END android-changed
- // test what happens if this is an invalid locale,
- // one with Korean country but an India language
+ // Test what happens if the default is an invalid locale, one with the country Korea (KR)
+ // but a currently unsupported language. "kr" == Kanuri (Korean is actually "ko").
+ // All these values are those defined in the "root" locale or the currency code if one isn't
+ // defined.
Locale.setDefault(new Locale("kr", "KR"));
// BEGIN android-changed
assertEquals("currK.getSymbol()", "\u20a9", currK.getSymbol());
assertEquals("currI.getSymbol()", "IEP", currI.getSymbol());
+ assertEquals("currUS.getSymbol()", "US$", currUS.getSymbol());
// END android-changed
- assertEquals("currUS.getSymbol()", "$", currUS.getSymbol());
}
/**
@@ -161,7 +174,7 @@ public class CurrencyTest extends junit.framework.TestCase {
*/
public void test_getSymbolLjava_util_Locale() {
//Tests was simplified because java specification not
- // includes strong requirements for returnig symbol.
+ // includes strong requirements for returning symbol.
// on android platform used wrong character for yen
// sign: \u00a5 instead of \uffe5
Locale[] desiredLocales = new Locale[]{
@@ -243,8 +256,6 @@ public class CurrencyTest extends junit.framework.TestCase {
for (i = 0; i < loc1.length; i++) {
flag = false;
for (j = 0; j < yen.length; j++) {
- byte[] b1 = null;
- byte[] b2 = null;
if (currJ.getSymbol(loc1[i]).equals(yen[j])) {
flag = true;
break;
@@ -391,38 +402,4 @@ public class CurrencyTest extends junit.framework.TestCase {
Currency.getInstance(l).toString(), d);
}
}
-
- protected void setUp() {
- Locale.setDefault(defaultLocale);
- }
-
- protected void tearDown() {
- }
-
- /**
- * Helper method to display Currency info
- *
- * @param c
- */
- private void printCurrency(Currency c) {
- System.out.println();
- System.out.println(c.getCurrencyCode());
- System.out.println(c.getSymbol());
- System.out.println(c.getDefaultFractionDigits());
- }
-
- /**
- * helper method to display Locale info
- */
- private static void printLocale(Locale loc) {
- System.out.println();
- System.out.println(loc.getDisplayName());
- System.out.println(loc.getCountry());
- System.out.println(loc.getLanguage());
- System.out.println(loc.getDisplayCountry());
- System.out.println(loc.getDisplayLanguage());
- System.out.println(loc.getDisplayName());
- System.out.println(loc.getISO3Country());
- System.out.println(loc.getISO3Language());
- }
}
diff --git a/luni/src/main/java/libcore/icu/ICU.java b/luni/src/main/java/libcore/icu/ICU.java
index 5978a5b..33c899e 100644
--- a/luni/src/main/java/libcore/icu/ICU.java
+++ b/luni/src/main/java/libcore/icu/ICU.java
@@ -448,6 +448,13 @@ public final class ICU {
static native boolean initLocaleDataNative(String locale, LocaleData result);
+ /**
+ * Takes a BCP-47 language tag (Locale.toLanguageTag()). e.g. en-US, not en_US
+ */
public static native void setDefaultLocale(String languageTag);
+
+ /**
+ * Returns a locale name, not a BCP-47 language tag. e.g. en_US not en-US.
+ */
public static native String getDefaultLocale();
}
diff --git a/luni/src/test/java/libcore/icu/ICUTest.java b/luni/src/test/java/libcore/icu/ICUTest.java
index be2da25..3fa1f46 100644
--- a/luni/src/test/java/libcore/icu/ICUTest.java
+++ b/luni/src/test/java/libcore/icu/ICUTest.java
@@ -216,4 +216,39 @@ public class ICUTest extends junit.framework.TestCase {
assertTrue(c.compare("รค", "AF") < 0);
assertTrue(c.compare("AF", "af") < 0);
}
+
+ // Test for the behavior of currency symbol lookup when an unrecognized locale has been set as the
+ // default.
+ public void testIcuDefaultAffectsCurrencySymbol() {
+ // A locale that is not going to be recognized by ICU and should fallback to "root" for the
+ // currency symbol.
+ final Locale unrecognizedLocale = new Locale("xy", "KR");
+
+ // A known locale with a relatively stable representation for its currency symbol.
+ final Locale enUsLocale = new Locale("en", "US");
+ final String usDollar = "USD";
+
+ String initialDefaultLocale = ICU.getDefaultLocale();
+ try {
+ // Confirm the "$" symbol for USD in en-US.
+ assertEquals("$", ICU.getCurrencySymbol(enUsLocale, usDollar));
+
+ // Set the default so this will be used as fallback for the unrecognized locale symbol lookup.
+ ICU.setDefaultLocale(enUsLocale.toLanguageTag());
+
+ // Demonstrate the USD symbol is reported as "$" for the unrecognized locale (which is using
+ // the default).
+ assertEquals("$", ICU.getCurrencySymbol(unrecognizedLocale, usDollar));
+
+ // Change the default.
+ ICU.setDefaultLocale(unrecognizedLocale.toLanguageTag());
+
+ String currencySymbolAfterDefaultChange = ICU.getCurrencySymbol(unrecognizedLocale, usDollar);
+ // "$US" is the value from root. With an unrecognized locale argument, and an unrecognized
+ // locale as the default, ICU has returns the value in root.
+ assertEquals("US$", currencySymbolAfterDefaultChange);
+ } finally {
+ ICU.setDefaultLocale(initialDefaultLocale);
+ }
+ }
}