ICU-5976 Supplied setters in DecimalFormatSymbolsICU. Added more test cases.

X-SVN-Rev: 24123
This commit is contained in:
Yoshito Umaoka 2008-06-06 22:33:07 +00:00
parent 5130b1e429
commit 3bb3a27338
7 changed files with 599 additions and 26 deletions

View file

@ -99,4 +99,122 @@ public class BreakIteratorTest extends TestFmwk {
}
}
}
/*
* Testing the behavior of text break between ICU instance and its
* equivalent created via the Locale SPI framework.
*/
public void TestICUEquivalent() {
Locale[] TEST_LOCALES = {
new Locale("en", "US"),
new Locale("fr", "FR"),
new Locale("th", "TH"),
new Locale("zh", "CN"),
};
String[] TEST_DATA = {
"International Components for Unicode (ICU) is an open source project of mature "
+ "C/C++ and Java libraries for Unicode support, software internationalization and "
+ "software globalization. ICU is widely portable to many operating systems and "
+ "environments. It gives applications the same results on all platforms and between "
+ "C/C++ and Java software. The ICU project is an open source development project "
+ "that is sponsored, supported and used by IBM and many other companies.",
"L'International Components for Unicode (ICU) est un projet open source qui fourni "
+ "des biblioth\u00e8ques pour les langages informatique C/C++ et Java pour supporter "
+ "Unicode, l'internationalisation et la mondialisation des logiciels. ICU est largement "
+ "portable vers beaucoup de syst\u00e8mes d'exploitations et d'environnements. Il "
+ "donne aux applications les m\u00eames comportements et r\u00e9sultats sur toutes "
+ "les plateformes et entre les logiciels C/C++ et Java. Le projet ICU est un projet "
+ "dont les code sources sont disponibles qui est sponsoris\u00e9, support\u00e9 et "
+ "utilis\u00e9 par IBM et beaucoup d'autres entreprises.",
"\u5728IBM\u7b49\u4f01\u696d\u4e2d\uff0c\u56fd\u9645\u5316\u7ecf\u5e38\u7b80\u5199"
+ "\u4e3aI18N (\u6216i18n\u6216I18n)\uff0c\u5176\u4e2d18\u4ee3\u8868\u4e86\u4e2d\u95f4"
+ "\u7701\u7565\u768418\u4e2a\u5b57\u6bcd\uff1b\u800c\u201c\u672c\u5730\u5316\u201d"
+ "\u540c\u53ef\u7b80\u5199\u4e3al10n\u3002\u9019\u4e24\u4e2a\u6982\u5ff5\u6709\u65f6"
+ "\u5408\u79f0\u5168\u7403\u5316\uff08g11n\uff09\uff0c\u4f46\u662f\u5168\u7403\u5316"
+ "\u7684\u6db5\u4e49\u66f4\u4e3a\u4e00\u822c\u5316\u3002\u53e6\u5916\u5076\u5c14\u4f1a"
+ "\u51fa\u73b0\u201cp13n\u201d\uff0c\u4ee3\u8868\u4e2a\u4eba\u5316\uff08personalization"
+ "\uff09\u3002",
"\u0e01\u0e23\u0e38\u0e07\u0e40\u0e17\u0e1e\u0e21\u0e2b\u0e32\u0e19\u0e04\u0e23"
+ "\u0e43\u0e19\u0e1b\u0e31\u0e08\u0e08\u0e38\u0e1a\u0e31\u0e19\u0e40\u0e1b\u0e47"
+ "\u0e19\u0e28\u0e39\u0e19\u0e22\u0e4c\u0e01\u0e25\u0e32\u0e07\u0e01\u0e32\u0e23"
+ "\u0e1b\u0e01\u0e04\u0e23\u0e2d\u0e07 \u0e01\u0e32\u0e23\u0e28\u0e36\u0e01\u0e29"
+ "\u0e32 \u0e01\u0e32\u0e23\u0e04\u0e21\u0e19\u0e32\u0e04\u0e21\u0e02\u0e19\u0e2a"
+ "\u0e48\u0e07 \u0e01\u0e32\u0e23\u0e40\u0e07\u0e34\u0e19\u0e01\u0e32\u0e23\u0e18"
+ "\u0e19\u0e32\u0e04\u0e32\u0e23 \u0e01\u0e32\u0e23\u0e1e\u0e32\u0e13\u0e34\u0e0a"
+ "\u0e22\u0e4c \u0e01\u0e32\u0e23\u0e2a\u0e37\u0e48\u0e2d\u0e2a\u0e32\u0e23 \u0e2f"
+ "\u0e25\u0e2f \u0e42\u0e14\u0e22\u0e21\u0e35\u0e1e\u0e37\u0e49\u0e19\u0e17\u0e35"
+ "\u0e48\u0e17\u0e31\u0e49\u0e07\u0e2b\u0e21\u0e14 1,562.2 \u0e15\u0e32\u0e23\u0e32"
+ "\u0e07\u0e01\u0e34\u0e42\u0e25\u0e40\u0e21\u0e15\u0e23 \u0e1e\u0e34\u0e01\u0e31"
+ "\u0e14\u0e17\u0e32\u0e07\u0e20\u0e39\u0e21\u0e34\u0e28\u0e32\u0e2a\u0e15\u0e23"
+ "\u0e4c\u0e04\u0e37\u0e2d \u0e25\u0e30\u0e15\u0e34\u0e08\u0e39\u0e14 13\u00b0 45"
+ "\u2019 \u0e40\u0e2b\u0e19\u0e37\u0e2d \u0e25\u0e2d\u0e07\u0e08\u0e34\u0e08\u0e39"
+ "\u0e14 100\u00b0 31\u2019 \u0e15\u0e30\u0e27\u0e31\u0e19\u0e2d\u0e2d\u0e01"
};
BreakIterator[] jdkBrkItrs = new BreakIterator[4];
com.ibm.icu.text.BreakIterator[] icuBrkItrs = new com.ibm.icu.text.BreakIterator[4];
for (Locale loc : TEST_LOCALES) {
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
jdkBrkItrs[0] = BreakIterator.getCharacterInstance(iculoc);
jdkBrkItrs[1] = BreakIterator.getWordInstance(iculoc);
jdkBrkItrs[2] = BreakIterator.getLineInstance(iculoc);
jdkBrkItrs[3] = BreakIterator.getSentenceInstance(iculoc);
icuBrkItrs[0] = com.ibm.icu.text.BreakIterator.getCharacterInstance(iculoc);
icuBrkItrs[1] = com.ibm.icu.text.BreakIterator.getWordInstance(iculoc);
icuBrkItrs[2] = com.ibm.icu.text.BreakIterator.getLineInstance(iculoc);
icuBrkItrs[3] = com.ibm.icu.text.BreakIterator.getSentenceInstance(iculoc);
for (String text : TEST_DATA) {
for (int i = 0; i < 4; i++) {
compareBreaks(text, jdkBrkItrs[i], icuBrkItrs[i]);
}
}
}
}
private void compareBreaks(String text, BreakIterator jdkBrk, com.ibm.icu.text.BreakIterator icuBrk) {
jdkBrk.setText(text);
icuBrk.setText(text);
// Forward
int jidx = jdkBrk.first();
int iidx = icuBrk.first();
if (jidx != iidx) {
errln("FAIL: Different first boundaries (jdk=" + jidx + ",icu=" + iidx + ") for text:\n" + text);
}
while (true) {
jidx = jdkBrk.next();
iidx = icuBrk.next();
if (jidx != iidx) {
errln("FAIL: Different boundaries (jdk=" + jidx + ",icu=" + iidx + "direction=forward) for text:\n" + text);
}
if (jidx == BreakIterator.DONE) {
break;
}
}
// Backward
jidx = jdkBrk.last();
iidx = jdkBrk.last();
if (jidx != iidx) {
errln("FAIL: Different last boundaries (jdk=" + jidx + ",icu=" + iidx + ") for text:\n" + text);
}
while (true) {
jidx = jdkBrk.previous();
iidx = icuBrk.previous();
if (jidx != iidx) {
errln("FAIL: Different boundaries (jdk=" + jidx + ",icu=" + iidx + "direction=backward) for text:\n" + text);
}
if (jidx == BreakIterator.DONE) {
break;
}
}
}
}

View file

@ -6,6 +6,7 @@
*/
package com.ibm.icu.dev.test.localespi;
import java.text.CollationKey;
import java.text.Collator;
import java.util.Locale;
@ -48,4 +49,79 @@ public class CollatorTest extends TestFmwk {
}
}
}
/*
* Testing the behavior of text collation between ICU instance and its
* equivalent created via the Locale SPI framework.
*/
public void TestICUEquivalent() {
Locale[] TEST_LOCALES = {
new Locale("en", "US"),
new Locale("de", "DE"),
new Locale("ja", "JP"),
};
String[] TEST_DATA = {
"Cafe",
"cafe",
"CAFE",
"caf\u00e9",
"cafe\u0301",
"\u304b\u3075\u3047",
"\u304c\u3075\u3047",
"\u304b\u3075\u3048",
"\u30ab\u30d5\u30a7",
"\uff76\uff8c\uff6a",
};
for (Locale loc : TEST_LOCALES) {
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
Collator jdkColl = Collator.getInstance(iculoc);
com.ibm.icu.text.Collator icuColl = com.ibm.icu.text.Collator.getInstance(loc);
// Default strength = TERITIARY
checkCollation(jdkColl, icuColl, TEST_DATA, "TERITIARY", loc);
// PRIMARY
jdkColl.setStrength(Collator.PRIMARY);
icuColl.setStrength(com.ibm.icu.text.Collator.PRIMARY);
checkCollation(jdkColl, icuColl, TEST_DATA, "PRIMARY", loc);
// SECONDARY
jdkColl.setStrength(Collator.SECONDARY);
icuColl.setStrength(com.ibm.icu.text.Collator.SECONDARY);
checkCollation(jdkColl, icuColl, TEST_DATA, "SECONDARY", loc);
}
}
private void checkCollation(Collator jdkColl, com.ibm.icu.text.Collator icuColl,
String[] data, String strength, Locale loc) {
for (String text1 : data) {
for (String text2 : data) {
int jdkRes = jdkColl.compare(text1, text2);
int icuRes = icuColl.compare(text1, text2);
if (jdkRes != icuRes) {
errln("FAIL: Different results for [text1=" + text1 + ",text2=" + text2 + ") for locale "
+ loc + " with strength " + strength + " - Result (jdk=" + jdkRes + ",icu=" + icuRes + ")");
}
// Evaluate collationKey
CollationKey jdkKey1 = jdkColl.getCollationKey(text1);
CollationKey jdkKey2 = jdkColl.getCollationKey(text2);
com.ibm.icu.text.CollationKey icuKey1 = icuColl.getCollationKey(text1);
com.ibm.icu.text.CollationKey icuKey2 = icuColl.getCollationKey(text2);
int jdkKeyRes = jdkKey1.compareTo(jdkKey2);
int icuKeyRes = icuKey1.compareTo(icuKey2);
if (jdkKeyRes != icuKeyRes) {
errln("FAIL: Different collationKey comparison results for [text1=" + text1 + ",text2=" + text2
+ ") for locale " + loc + " with strength " + strength
+ " - Result (jdk=" + jdkRes + ",icu=" + icuRes + ")");
}
}
}
}
}

View file

@ -49,6 +49,102 @@ public class DateFormatSymbolsTest extends TestFmwk {
}
}
/*
* Testing the contents of DateFormatSymbols between ICU instance and its
* equivalent created via the Locale SPI framework.
*/
public void TestICUEquivalent() {
Locale[] TEST_LOCALES = {
new Locale("en", "US"),
new Locale("es", "ES"),
new Locale("ja", "JP", "JP"),
new Locale("th", "TH"),
};
for (Locale loc : TEST_LOCALES) {
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
DateFormatSymbols jdkDfs = DateFormatSymbols.getInstance(iculoc);
com.ibm.icu.text.DateFormatSymbols icuDfs = com.ibm.icu.text.DateFormatSymbols.getInstance(loc);
compareArrays(jdkDfs.getAmPmStrings(), icuDfs.getAmPmStrings(), loc, "getAmPmStrings");
compareArrays(jdkDfs.getEras(), icuDfs.getEras(), loc, "getEras");
compareArrays(jdkDfs.getMonths(), icuDfs.getMonths(), loc, "getMonths");
compareArrays(jdkDfs.getShortMonths(), icuDfs.getShortMonths(), loc, "getShortMonths");
compareArrays(jdkDfs.getShortWeekdays(), icuDfs.getShortWeekdays(), loc, "getShortWeekdays");
compareArrays(jdkDfs.getWeekdays(), icuDfs.getWeekdays(), loc, "getWeekdays");
compareArrays(jdkDfs.getZoneStrings(), icuDfs.getZoneStrings(), loc, "getZoneStrings");
}
}
/*
* Testing setters
*/
public void TestSetSymbols() {
// ICU's JDK DateFormatSymbols implementation for ja_JP locale
DateFormatSymbols dfs = DateFormatSymbols.getInstance(new Locale("ja", "JP", "ICU"));
// en_US is supported by JDK, so this is the JDK's own DateFormatSymbols
Locale loc = new Locale("en", "US");
DateFormatSymbols dfsEnUS = DateFormatSymbols.getInstance(loc);
// Copying over all symbols
dfs.setAmPmStrings(dfsEnUS.getAmPmStrings());
dfs.setEras(dfsEnUS.getEras());
dfs.setMonths(dfsEnUS.getMonths());
dfs.setShortMonths(dfsEnUS.getShortMonths());
dfs.setShortWeekdays(dfsEnUS.getShortWeekdays());
dfs.setWeekdays(dfsEnUS.getWeekdays());
dfs.setZoneStrings(dfsEnUS.getZoneStrings());
compareArrays(dfs.getAmPmStrings(), dfsEnUS.getAmPmStrings(), loc, "getAmPmStrings");
compareArrays(dfs.getEras(), dfsEnUS.getEras(), loc, "getEras");
compareArrays(dfs.getMonths(), dfsEnUS.getMonths(), loc, "getMonths");
compareArrays(dfs.getShortMonths(), dfsEnUS.getShortMonths(), loc, "getShortMonths");
compareArrays(dfs.getShortWeekdays(), dfsEnUS.getShortWeekdays(), loc, "getShortWeekdays");
compareArrays(dfs.getWeekdays(), dfsEnUS.getWeekdays(), loc, "getWeekdays");
compareArrays(dfs.getZoneStrings(), dfsEnUS.getZoneStrings(), loc, "getZoneStrings");
}
private void compareArrays(Object jarray, Object iarray, Locale loc, String method) {
if (jarray instanceof String[][]) {
String[][] jaa = (String[][])jarray;
String[][] iaa = (String[][])iarray;
if (jaa.length != iaa.length || jaa[0].length != iaa[0].length) {
errln("FAIL: Different array size returned by " + method + "for locale "
+ loc + "(jdksize=" + jaa.length + "x" + jaa[0].length
+ ",icusize=" + iaa.length + "x" + iaa[0].length + ")");
}
for (int i = 0; i < jaa.length; i++) {
for (int j = 0; j < jaa[i].length; j++) {
if (!TestUtil.equals(jaa[i][j], iaa[i][j])) {
errln("FAIL: Different symbols returned by " + method + "for locale "
+ loc + " at index " + i + "," + j
+ " (jdk=" + jaa[i][j] + ",icu=" + iaa[i][j] + ")");
}
}
}
} else {
String[] ja = (String[])jarray;
String[] ia = (String[])iarray;
if (ja.length != ia.length) {
errln("FAIL: Different array size returned by " + method + "for locale "
+ loc + "(jdksize=" + ja.length
+ ",icusize=" + ia.length + ")");
} else {
for (int i = 0; i < ja.length; i++) {
if (!TestUtil.equals(ja[i], ia[i])) {
errln("FAIL: Different symbols returned by " + method + "for locale "
+ loc + " at index " + i + " (jdk=" + ja[i] + ",icu=" + ia[i] + ")");
}
}
}
}
}
/*
* Testing Nynorsk locales
*/

View file

@ -7,6 +7,7 @@
package com.ibm.icu.dev.test.localespi;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Locale;
@ -30,46 +31,137 @@ public class DateFormatTest extends TestFmwk {
}
private void checkGetInstance(int dstyle, int tstyle, Locale loc) {
DateFormat df;
String method;
if (dstyle < 0) {
df = DateFormat.getTimeInstance(DateFormat.SHORT, loc);
method = "getTimeInstance";
} else if (tstyle < 0) {
df = DateFormat.getDateInstance(DateFormat.MEDIUM, loc);
method = "getDateInstance";
} else {
df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG, loc);
method = "getDateTimeInstance";
}
String method[] = new String[1];
DateFormat df = getJDKInstance(dstyle, tstyle, loc, method);
boolean isIcuImpl = (df instanceof com.ibm.icu.impl.jdkadapter.SimpleDateFormatICU);
if (TestUtil.isICUExtendedLocale(loc)) {
if (!isIcuImpl) {
errln("FAIL: " + method + " returned JDK DateFormat for locale " + loc);
errln("FAIL: " + method[0] + " returned JDK DateFormat for locale " + loc);
}
} else {
if (isIcuImpl) {
logln("INFO: " + method + " returned ICU DateFormat for locale " + loc);
logln("INFO: " + method[0] + " returned ICU DateFormat for locale " + loc);
}
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
DateFormat dfIcu;
if (dstyle < 0) {
dfIcu = DateFormat.getTimeInstance(DateFormat.SHORT, iculoc);
} else if (tstyle < 0) {
dfIcu = DateFormat.getDateInstance(DateFormat.MEDIUM, iculoc);
} else {
dfIcu = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG, iculoc);
}
DateFormat dfIcu = getJDKInstance(dstyle, tstyle, iculoc, null);
if (isIcuImpl) {
if (!df.equals(dfIcu)) {
errln("FAIL: " + method + " returned ICU DateFormat for locale " + loc
errln("FAIL: " + method[0] + " returned ICU DateFormat for locale " + loc
+ ", but different from the one for locale " + iculoc);
}
} else {
if (!(dfIcu instanceof com.ibm.icu.impl.jdkadapter.SimpleDateFormatICU)) {
errln("FAIL: " + method + " returned JDK DateFormat for locale " + iculoc);
errln("FAIL: " + method[0] + " returned JDK DateFormat for locale " + iculoc);
}
}
}
}
private DateFormat getJDKInstance(int dstyle, int tstyle, Locale loc, String[] methodName) {
DateFormat df;
String method;
if (dstyle < 0) {
df = DateFormat.getTimeInstance(tstyle, loc);
method = "getTimeInstance";
} else if (tstyle < 0) {
df = DateFormat.getDateInstance(dstyle, loc);
method = "getDateInstance";
} else {
df = DateFormat.getDateTimeInstance(dstyle, tstyle, loc);
method = "getDateTimeInstance";
}
if (methodName != null) {
methodName[0] = method;
}
return df;
}
private com.ibm.icu.text.DateFormat getICUInstance(int dstyle, int tstyle, Locale loc, String[] methodName) {
com.ibm.icu.text.DateFormat icudf;;
String method;
if (dstyle < 0) {
icudf = com.ibm.icu.text.DateFormat.getTimeInstance(tstyle, loc);
method = "getTimeInstance";
} else if (tstyle < 0) {
icudf = com.ibm.icu.text.DateFormat.getDateInstance(dstyle, loc);
method = "getDateInstance";
} else {
icudf = com.ibm.icu.text.DateFormat.getDateTimeInstance(dstyle, tstyle, loc);
method = "getDateTimeInstance";
}
if (methodName != null) {
methodName[0] = method;
}
return icudf;
}
/*
* Testing the behavior of date format between ICU instance and its
* equivalent created via the Locale SPI framework.
*/
public void TestICUEquivalent() {
Locale[] TEST_LOCALES = {
new Locale("en", "US"),
new Locale("it", "IT"),
new Locale("iw", "IL"),
new Locale("ja", "JP", "JP"),
new Locale("th", "TH"),
new Locale("zh", "TW"),
};
long[] TEST_DATES = {
1199499330543L, // 2008-01-05T02:15:30.543Z
1217001308085L, // 2008-07-25T15:55:08.085Z
};
for (Locale loc : TEST_LOCALES) {
for (int dstyle = -1; dstyle <= 3; dstyle++) {
for (int tstyle = -1; tstyle <= 3; tstyle++) {
if (tstyle == -1 && dstyle == -1) {
continue;
}
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
DateFormat df = getJDKInstance(dstyle, tstyle, iculoc, null);
com.ibm.icu.text.DateFormat icudf = getICUInstance(dstyle, tstyle, loc, null);
for (long t : TEST_DATES) {
// Format
Date d = new Date(t);
String dstr1 = df.format(d);
String dstr2 = icudf.format(d);
if (!dstr1.equals(dstr2)) {
errln("FAIL: Different format results for locale " + loc + " (dstyle=" + dstyle
+ ",tstyle=" + tstyle + ") at time " + t + " - JDK:" + dstr1
+ " ICU:" + dstr2);
continue;
}
// Parse
Date d1, d2;
try {
d1 = df.parse(dstr1);
} catch (ParseException e) {
errln("FAIL: ParseException thrown for JDK DateFormat for string "
+ dstr1 + "(locale=" + iculoc + ",dstyle=" + dstyle + ",tstyle=" + tstyle + ")");
continue;
}
try {
d2 = icudf.parse(dstr1);
} catch (ParseException e) {
errln("FAIL: ParseException thrown for ICU DateFormat for string "
+ dstr1 + "(locale=" + loc + ",dstyle=" + dstyle + ",tstyle=" + tstyle + ")");
continue;
}
if (!d1.equals(d2)) {
errln("FAIL: Different parse results for locale " + loc
+ " for date string " + dstr1 + " (dstyle=" + dstyle
+ ",tstyle=" + tstyle + ") at time " + t + " - JDK:" + dstr1
+ " ICU:" + dstr2);
}
}
}
}
}

View file

@ -7,10 +7,10 @@
package com.ibm.icu.dev.test.localespi;
import java.text.DecimalFormatSymbols;
import java.util.Currency;
import java.util.Locale;
import com.ibm.icu.dev.test.TestFmwk;
import com.ibm.icu.text.DateFormatSymbols;
public class DecimalFormatSymbolsTest extends TestFmwk {
public static void main(String[] args) throws Exception {
@ -21,7 +21,7 @@ public class DecimalFormatSymbolsTest extends TestFmwk {
* Check if getInstance returns the ICU implementation.
*/
public void TestGetInstance() {
for (Locale loc : DateFormatSymbols.getAvailableLocales()) {
for (Locale loc : DecimalFormatSymbols.getAvailableLocales()) {
DecimalFormatSymbols decfs = DecimalFormatSymbols.getInstance(loc);
boolean isIcuImpl = (decfs instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatSymbolsICU);
@ -49,4 +49,106 @@ public class DecimalFormatSymbolsTest extends TestFmwk {
}
}
}
/*
* Testing the contents of DecimalFormatSymbols between ICU instance and its
* equivalent created via the Locale SPI framework.
*/
public void TestICUEquivalent() {
Locale[] TEST_LOCALES = {
new Locale("en", "US"),
new Locale("pt", "BR"),
new Locale("ko", "KR"),
};
for (Locale loc : TEST_LOCALES) {
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
DecimalFormatSymbols jdkDecfs = DecimalFormatSymbols.getInstance(iculoc);
com.ibm.icu.text.DecimalFormatSymbols icuDecfs = com.ibm.icu.text.DecimalFormatSymbols.getInstance(loc);
Currency jdkCur = jdkDecfs.getCurrency();
com.ibm.icu.util.Currency icuCur = icuDecfs.getCurrency();
if ((jdkCur != null && icuCur == null)
|| (jdkCur == null && icuCur != null)
|| !jdkCur.getCurrencyCode().equals(icuCur.getCurrencyCode())) {
errln("FAIL: Different results returned by getCurrency for locale " + loc);
}
checkEquivalence(jdkDecfs.getCurrencySymbol(), icuDecfs.getCurrencySymbol(), loc, "getCurrencySymbol");
checkEquivalence(jdkDecfs.getDecimalSeparator(), icuDecfs.getDecimalSeparator(), loc, "getDecimalSeparator");
checkEquivalence(jdkDecfs.getDigit(), icuDecfs.getDigit(), loc, "getDigit");
checkEquivalence(jdkDecfs.getExponentSeparator(), icuDecfs.getExponentSeparator(), loc, "getExponentSeparator");
checkEquivalence(jdkDecfs.getGroupingSeparator(), icuDecfs.getGroupingSeparator(), loc, "getGroupingSeparator");
checkEquivalence(jdkDecfs.getInfinity(), icuDecfs.getInfinity(), loc, "getInfinity");
checkEquivalence(jdkDecfs.getInternationalCurrencySymbol(), icuDecfs.getInternationalCurrencySymbol(), loc, "getInternationalCurrencySymbol");
checkEquivalence(jdkDecfs.getMinusSign(), icuDecfs.getMinusSign(), loc, "getMinusSign");
checkEquivalence(jdkDecfs.getMonetaryDecimalSeparator(), icuDecfs.getMonetaryDecimalSeparator(), loc, "getMonetaryDecimalSeparator");
checkEquivalence(jdkDecfs.getNaN(), icuDecfs.getNaN(), loc, "getNaN");
checkEquivalence(jdkDecfs.getPatternSeparator(), icuDecfs.getPatternSeparator(), loc, "getPatternSeparator");
checkEquivalence(jdkDecfs.getPercent(), icuDecfs.getPercent(), loc, "getPercent");
checkEquivalence(jdkDecfs.getPerMill(), icuDecfs.getPerMill(), loc, "getPerMill");
checkEquivalence(jdkDecfs.getZeroDigit(), icuDecfs.getZeroDigit(), loc, "getZeroDigit");
}
}
private void checkEquivalence(Object jo, Object io, Locale loc, String method) {
if (!jo.equals(io)) {
errln("FAIL: Different results returned by " + method + " for locale "
+ loc + " (jdk=" + jo + ",icu=" + io + ")");
}
}
/*
* Testing setters
*/
public void TestSetSymbols() {
// ICU's JDK DecimalFormatSymbols implementation for de_DE locale
DecimalFormatSymbols decfs = DecimalFormatSymbols.getInstance(new Locale("de", "DE", "ICU"));
// en_US is supported by JDK, so this is the JDK's own DecimalFormatSymbols
Locale loc = new Locale("en", "US");
DecimalFormatSymbols decfsEnUS = DecimalFormatSymbols.getInstance(loc);
// Copying over all symbols
decfs.setCurrency(decfsEnUS.getCurrency());
decfs.setCurrencySymbol(decfsEnUS.getCurrencySymbol());
decfs.setDecimalSeparator(decfsEnUS.getDecimalSeparator());
decfs.setDigit(decfsEnUS.getDigit());
decfs.setExponentSeparator(decfsEnUS.getExponentSeparator());
decfs.setGroupingSeparator(decfsEnUS.getGroupingSeparator());
decfs.setInfinity(decfsEnUS.getInfinity());
decfs.setInternationalCurrencySymbol(decfsEnUS.getInternationalCurrencySymbol());
decfs.setMinusSign(decfsEnUS.getMinusSign());
decfs.setMonetaryDecimalSeparator(decfsEnUS.getMonetaryDecimalSeparator());
decfs.setNaN(decfsEnUS.getNaN());
decfs.setPatternSeparator(decfsEnUS.getPatternSeparator());
decfs.setPercent(decfsEnUS.getPercent());
decfs.setPerMill(decfsEnUS.getPerMill());
decfs.setZeroDigit(decfsEnUS.getZeroDigit());
// Check
Currency cur = decfs.getCurrency();
Currency curEnUS = decfsEnUS.getCurrency();
if ((cur != null && curEnUS == null)
|| (cur == null && curEnUS != null)
|| !cur.equals(curEnUS)) {
errln("FAIL: Different results returned by getCurrency");
}
checkEquivalence(decfs.getCurrencySymbol(), decfsEnUS.getCurrencySymbol(), loc, "getCurrencySymbol");
checkEquivalence(decfs.getDecimalSeparator(), decfsEnUS.getDecimalSeparator(), loc, "getDecimalSeparator");
checkEquivalence(decfs.getDigit(), decfsEnUS.getDigit(), loc, "getDigit");
checkEquivalence(decfs.getExponentSeparator(), decfsEnUS.getExponentSeparator(), loc, "getExponentSeparator");
checkEquivalence(decfs.getGroupingSeparator(), decfsEnUS.getGroupingSeparator(), loc, "getGroupingSeparator");
checkEquivalence(decfs.getInfinity(), decfsEnUS.getInfinity(), loc, "getInfinity");
checkEquivalence(decfs.getInternationalCurrencySymbol(), decfsEnUS.getInternationalCurrencySymbol(), loc, "getInternationalCurrencySymbol");
checkEquivalence(decfs.getMinusSign(), decfsEnUS.getMinusSign(), loc, "getMinusSign");
checkEquivalence(decfs.getMonetaryDecimalSeparator(), decfsEnUS.getMonetaryDecimalSeparator(), loc, "getMonetaryDecimalSeparator");
checkEquivalence(decfs.getNaN(), decfsEnUS.getNaN(), loc, "getNaN");
checkEquivalence(decfs.getPatternSeparator(), decfsEnUS.getPatternSeparator(), loc, "getPatternSeparator");
checkEquivalence(decfs.getPercent(), decfsEnUS.getPercent(), loc, "getPercent");
checkEquivalence(decfs.getPerMill(), decfsEnUS.getPerMill(), loc, "getPerMill");
checkEquivalence(decfs.getZeroDigit(), decfsEnUS.getZeroDigit(), loc, "getZeroDigit");
}
}

View file

@ -29,4 +29,14 @@ public class TestUtil {
}
return false;
}
public static boolean equals(Object o1, Object o2) {
if (o1 == null && o2 == null) {
return true;
}
if (o1 == null || o2 == null) {
return false;
}
return o1.equals(o2);
}
}

View file

@ -126,6 +126,85 @@ public class DecimalFormatSymbolsICU extends java.text.DecimalFormatSymbols {
return fIcuDecfs.getZeroDigit();
}
@Override
public void setCurrency(Currency currency) {
com.ibm.icu.util.Currency icuCurrency = null;
if (currency != null) {
icuCurrency = com.ibm.icu.util.Currency.getInstance(currency.getCurrencyCode());
}
fIcuDecfs.setCurrency(icuCurrency);
}
@Override
public void setCurrencySymbol(String currency) {
fIcuDecfs.setCurrencySymbol(currency);
}
@Override
public void setDecimalSeparator(char decimalSeparator) {
fIcuDecfs.setDecimalSeparator(decimalSeparator);
}
@Override
public void setDigit(char digit) {
fIcuDecfs.setDigit(digit);
}
@Override
public void setExponentSeparator(String exp) {
fIcuDecfs.setExponentSeparator(exp);
}
@Override
public void setGroupingSeparator(char groupingSeparator) {
fIcuDecfs.setGroupingSeparator(groupingSeparator);
}
@Override
public void setInfinity(String infinity) {
fIcuDecfs.setInfinity(infinity);
}
@Override
public void setInternationalCurrencySymbol(String currencyCode) {
fIcuDecfs.setInternationalCurrencySymbol(currencyCode);
}
@Override
public void setMinusSign(char minusSign) {
fIcuDecfs.setMinusSign(minusSign);
}
@Override
public void setMonetaryDecimalSeparator(char sep) {
fIcuDecfs.setMonetaryDecimalSeparator(sep);
}
@Override
public void setNaN(String NaN) {
fIcuDecfs.setNaN(NaN);
}
@Override
public void setPatternSeparator(char patternSeparator) {
fIcuDecfs.setPatternSeparator(patternSeparator);
}
@Override
public void setPercent(char percent) {
fIcuDecfs.setPercent(percent);
}
@Override
public void setPerMill(char perMill) {
fIcuDecfs.setPerMill(perMill);
}
@Override
public void setZeroDigit(char zeroDigit) {
fIcuDecfs.setZeroDigit(zeroDigit);
}
@Override
public int hashCode() {
return fIcuDecfs.hashCode();