mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-19 11:45:45 +00:00
ICU-2180 improve api coverage
X-SVN-Rev: 12283
This commit is contained in:
parent
dd9f455a49
commit
e4b1bd6ff8
9 changed files with 185 additions and 73 deletions
|
@ -4,8 +4,8 @@
|
|||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/collator/CollationServiceTest.java,v $
|
||||
* $Date: 2003/05/14 19:03:18 $
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2003/06/04 20:24:14 $
|
||||
* $Revision: 1.4 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
@ -35,12 +35,21 @@ public class CollationServiceTest extends TestFmwk {
|
|||
Collator frcol = Collator.getInstance(Locale.FRANCE);
|
||||
Collator uscol = Collator.getInstance(Locale.US);
|
||||
|
||||
{
|
||||
// coverage
|
||||
Locale[] locales = Collator.getAvailableLocales();
|
||||
}
|
||||
|
||||
{ // try override en_US collator
|
||||
Object key = Collator.registerInstance(frcol, Locale.US);
|
||||
Collator ncol = Collator.getInstance(Locale.US);
|
||||
if (!frcol.equals(ncol)) {
|
||||
errln("register of french collator for en_US failed");
|
||||
}
|
||||
|
||||
// coverage
|
||||
Collator test = Collator.getInstance(Locale.GERMANY); // CollatorFactory.handleCreate
|
||||
|
||||
if (!Collator.unregister(key)) {
|
||||
errln("failed to unregister french collator");
|
||||
}
|
||||
|
@ -90,6 +99,13 @@ public class CollationServiceTest extends TestFmwk {
|
|||
errln("collator after unregister does not match original fu_FU");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// coverage after return to default
|
||||
Locale[] locales = Collator.getAvailableLocales();
|
||||
|
||||
Collator ncol = Collator.getInstance(Locale.US);
|
||||
}
|
||||
}
|
||||
|
||||
public void TestRegisterFactory() {
|
||||
|
@ -159,6 +175,24 @@ public class CollationServiceTest extends TestFmwk {
|
|||
return ids;
|
||||
}
|
||||
}
|
||||
|
||||
class TestFactoryWrapper extends CollatorFactory {
|
||||
CollatorFactory delegate;
|
||||
|
||||
TestFactoryWrapper(CollatorFactory delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
public Collator createCollator(Locale loc) {
|
||||
return delegate.createCollator(loc);
|
||||
}
|
||||
|
||||
// use CollatorFactory getDisplayName(Locale, Locale) for coverage
|
||||
|
||||
public Set getSupportedLocaleIDs() {
|
||||
return delegate.getSupportedLocaleIDs();
|
||||
}
|
||||
}
|
||||
|
||||
Locale fu_FU = new Locale("fu", "FU", "");
|
||||
Locale fu_FU_FOO = new Locale("fu", "FU", "FOO");
|
||||
|
@ -182,6 +216,17 @@ public class CollationServiceTest extends TestFmwk {
|
|||
|
||||
TestFactory factory = new TestFactory(info);
|
||||
|
||||
// coverage
|
||||
{
|
||||
TestFactoryWrapper wrapper = new TestFactoryWrapper(factory); // in java, gc lets us easily multiply reference!
|
||||
Object key = Collator.registerFactory(wrapper);
|
||||
String name = Collator.getDisplayName(fu_FU, fu_FU_FOO);
|
||||
System.out.println("***default name: " + name);
|
||||
Collator.unregister(key);
|
||||
|
||||
Collator col = Collator.getInstance(new Locale("bar", "BAR"));
|
||||
}
|
||||
|
||||
{
|
||||
Object key = Collator.registerFactory(factory);
|
||||
Collator ncol = Collator.getInstance(Locale.US);
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatRegistrationTest.java,v $
|
||||
* $Date: 2003/02/26 05:32:57 $
|
||||
* $Revision: 1.2 $
|
||||
* $Date: 2003/06/04 20:24:14 $
|
||||
* $Revision: 1.3 $
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.format;
|
||||
|
@ -13,6 +13,7 @@ package com.ibm.icu.dev.test.format;
|
|||
import com.ibm.icu.text.*;
|
||||
import com.ibm.icu.text.NumberFormat.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
public class NumberFormatRegistrationTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
|
@ -29,10 +30,14 @@ public class NumberFormatRegistrationTest extends com.ibm.icu.dev.test.TestFmwk
|
|||
NumberFormat currencyStyle;
|
||||
|
||||
TestFactory() {
|
||||
super(SRC_LOC, true);
|
||||
currencyStyle = NumberFormat.getIntegerInstance(SWAP_LOC);
|
||||
this(SRC_LOC, SWAP_LOC);
|
||||
}
|
||||
|
||||
TestFactory(Locale srcLoc, Locale swapLoc) {
|
||||
super(srcLoc);
|
||||
currencyStyle = NumberFormat.getIntegerInstance(swapLoc);
|
||||
}
|
||||
|
||||
public NumberFormat createFormat(Locale loc, int formatType) {
|
||||
if (formatType == FORMAT_CURRENCY) {
|
||||
return currencyStyle;
|
||||
|
@ -40,16 +45,45 @@ public class NumberFormatRegistrationTest extends com.ibm.icu.dev.test.TestFmwk
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// coverage before registration
|
||||
|
||||
try {
|
||||
NumberFormat.unregister(null);
|
||||
errln("did not throw exception on null unregister");
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
NumberFormat.registerFactory(null);
|
||||
errln("did not throw exception on null register");
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
|
||||
if (NumberFormat.unregister("")) {
|
||||
errln("unregister of empty string key succeeded");
|
||||
}
|
||||
}
|
||||
|
||||
Locale fu_FU = new Locale("fu", "FU");
|
||||
NumberFormat f0 = NumberFormat.getIntegerInstance(SWAP_LOC);
|
||||
NumberFormat f1 = NumberFormat.getIntegerInstance(SRC_LOC);
|
||||
NumberFormat f2 = NumberFormat.getCurrencyInstance(SRC_LOC);
|
||||
Object key = NumberFormat.registerFactory(new TestFactory());
|
||||
Object key2 = NumberFormat.registerFactory(new TestFactory(fu_FU, Locale.GERMANY));
|
||||
if (!Arrays.asList(NumberFormat.getAvailableLocales()).contains(fu_FU)) {
|
||||
errln("did not list fu_FU");
|
||||
}
|
||||
NumberFormat f3 = NumberFormat.getCurrencyInstance(SRC_LOC);
|
||||
NumberFormat f4 = NumberFormat.getIntegerInstance(SRC_LOC);
|
||||
NumberFormat.unregister(key); // restore for other tests
|
||||
NumberFormat f5 = NumberFormat.getCurrencyInstance(SRC_LOC);
|
||||
|
||||
NumberFormat.unregister(key2);
|
||||
|
||||
float n = 1234.567f;
|
||||
logln("f0 swap int: " + f0.format(n));
|
||||
logln("f1 src int: " + f1.format(n));
|
||||
|
@ -67,5 +101,8 @@ public class NumberFormatRegistrationTest extends com.ibm.icu.dev.test.TestFmwk
|
|||
if (!f5.format(n).equals(f2.format(n))) {
|
||||
errln("unregistered service did not match original");
|
||||
}
|
||||
|
||||
// coverage
|
||||
NumberFormat f6 = NumberFormat.getNumberInstance(fu_FU);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatTest.java,v $
|
||||
* $Date: 2003/06/03 18:49:29 $
|
||||
* $Revision: 1.17 $
|
||||
* $Date: 2003/06/04 20:24:14 $
|
||||
* $Revision: 1.18 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
@ -21,9 +21,10 @@ import com.ibm.icu.text.*;
|
|||
import com.ibm.icu.text.NumberFormat.*;
|
||||
import com.ibm.icu.util.*;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.text.ParsePosition;
|
||||
import java.math.BigInteger;
|
||||
import java.text.FieldPosition;
|
||||
import java.text.ParsePosition;
|
||||
import java.util.Locale;
|
||||
|
||||
public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
private static final char EURO = '\u20ac';
|
||||
|
@ -238,52 +239,6 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Currency registration-related API.
|
||||
*/
|
||||
public void TestCurrencyRegistration() {
|
||||
/* dlf
|
||||
// available locales
|
||||
Locale[] locales = Currency.getAvailableLocales();
|
||||
logln("available locales");
|
||||
for (int i = 0; i < locales.length; ++i) {
|
||||
logln("[" + i + "] " + locales[i].toString());
|
||||
}
|
||||
|
||||
// identical instance
|
||||
Currency fr0 = Currency.getInstance(Locale.FRANCE);
|
||||
Currency fr1 = Currency.getInstance(Locale.FRANCE);
|
||||
if (fr0 != fr1) {
|
||||
errln("non-identical currencies for locale");
|
||||
}
|
||||
|
||||
Currency us0 = Currency.getInstance(Locale.US);
|
||||
|
||||
// replace US with FR
|
||||
Object key = Currency.register(fr0, Locale.US);
|
||||
|
||||
logln("FRENCH currency: " + fr0);
|
||||
logln("US currency: " + us0);
|
||||
|
||||
// query US and get FR back
|
||||
Currency us1 = Currency.getInstance(Locale.US);
|
||||
logln("got currency: " + us1);
|
||||
if (us1 != fr0) {
|
||||
errln("registry failed");
|
||||
}
|
||||
logln("new US currency: " + us1);
|
||||
|
||||
// unregister and get US back
|
||||
if (!Currency.unregister(key)) {
|
||||
errln("failed to unregister key: " + key);
|
||||
}
|
||||
Currency us2 = Currency.getInstance(Locale.US);
|
||||
if (!us2.equals(us0)) {
|
||||
errln("after unregister US didn't get original currency back: " + us2 + " != " + us0);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Currency object handling, new as of ICU 2.2.
|
||||
*/
|
||||
|
@ -779,6 +734,42 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
|||
}
|
||||
}
|
||||
|
||||
// additional coverage tests
|
||||
|
||||
// sigh, can't have static inner classes, why not?
|
||||
|
||||
static final class PI extends Number {
|
||||
private PI() {};
|
||||
public int intValue() { return (int)Math.PI; }
|
||||
public long longValue() { return (long)Math.PI; }
|
||||
public float floatValue() { return (float)Math.PI; }
|
||||
public double doubleValue() { return (double)Math.PI; }
|
||||
public byte byteValue() { return (byte)Math.PI; }
|
||||
public short shortValue() { return (short)Math.PI; }
|
||||
|
||||
public static final Number INSTANCE = new PI();
|
||||
}
|
||||
|
||||
public void TestCoverage() {
|
||||
NumberFormat fmt = NumberFormat.getNumberInstance(); // default locale
|
||||
logln(fmt.format(new BigInteger("1234567890987654321234567890987654321", 10)));
|
||||
|
||||
fmt = NumberFormat.getScientificInstance(); // default locale
|
||||
|
||||
logln(fmt.format(PI.INSTANCE));
|
||||
|
||||
try {
|
||||
logln(fmt.format("12345"));
|
||||
errln("numberformat of string did not throw exception");
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
|
||||
int hash = fmt.hashCode();
|
||||
|
||||
logln("compare to string returns: " + fmt.equals(""));
|
||||
}
|
||||
|
||||
public void TestWhiteSpaceParsing() {
|
||||
DecimalFormatSymbols US = new DecimalFormatSymbols(Locale.US);
|
||||
DecimalFormat fmt = new DecimalFormat("a b#0c ", US);
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/rbbi/TestAll.java,v $
|
||||
* $Date: 2003/06/03 18:49:30 $
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2003/06/04 20:24:14 $
|
||||
* $Revision: 1.4 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -30,6 +30,7 @@ public class TestAll extends TestGroup {
|
|||
"BreakIteratorTest",
|
||||
"RBBITest",
|
||||
"RBBIAPITest",
|
||||
"BreakIteratorRegTest",
|
||||
},
|
||||
" BreakIterator and RuleBasedBreakIterator Tests");
|
||||
}
|
||||
|
|
|
@ -47,6 +47,13 @@ public class CurrencyTest extends TestFmwk {
|
|||
if(avail==null){
|
||||
errln("FAIL: getAvailableLocales returned null");
|
||||
}
|
||||
|
||||
try {
|
||||
usd.getName(Locale.US, 5, new boolean[1]);
|
||||
errln("expected getName with invalid type parameter to throw exception");
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,6 +63,17 @@ public class CurrencyTest extends TestFmwk {
|
|||
final Currency jpy = Currency.getInstance("JPY");
|
||||
final Currency usd = Currency.getInstance(Locale.US);
|
||||
|
||||
try {
|
||||
Currency.unregister(null); // should fail, coverage
|
||||
errln("expected unregister of null to throw exception");
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
|
||||
if (Currency.unregister("")) { // coverage
|
||||
errln("unregister before register erroneously succeeded");
|
||||
}
|
||||
|
||||
Locale fu_FU = new Locale("fu", "FU", "");
|
||||
|
||||
Object key1 = Currency.registerInstance(jpy, Locale.US);
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/BreakIterator.java,v $
|
||||
* $Date: 2003/06/03 18:49:33 $
|
||||
* $Revision: 1.22 $
|
||||
* $Date: 2003/06/04 20:24:14 $
|
||||
* $Revision: 1.23 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
@ -226,7 +226,9 @@ public abstract class BreakIterator implements Cloneable
|
|||
return super.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
///CLOVER:OFF
|
||||
throw new InternalError();
|
||||
///CLOVER:ON
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -575,10 +577,20 @@ public abstract class BreakIterator implements Cloneable
|
|||
if (key == null) {
|
||||
throw new IllegalArgumentException("registry key must not be null");
|
||||
}
|
||||
// TODO: we don't do code coverage for the following lines
|
||||
// because in getBreakInstance we always instantiate the shim,
|
||||
// and test execution is such that we always instantiate a
|
||||
// breakiterator before we get to the break iterator tests.
|
||||
// this is for modularization, and we could remove the
|
||||
// dependencies in getBreakInstance by rewriting part of the
|
||||
// LocaleData code, or perhaps by accepting it into the
|
||||
// module.
|
||||
///CLOVER:OFF
|
||||
if (shim != null) {
|
||||
return shim.unregister(key);
|
||||
}
|
||||
return false;
|
||||
///CLOVER:ON
|
||||
}
|
||||
|
||||
// end of registration
|
||||
|
@ -653,8 +665,10 @@ public abstract class BreakIterator implements Cloneable
|
|||
shim = (BreakIteratorServiceShim)cls.newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
///CLOVER:OFF
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage());
|
||||
///CLOVER:ON
|
||||
}
|
||||
}
|
||||
return shim;
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/BreakIteratorFactory.java,v $
|
||||
* $Date: 2003/06/03 18:49:33 $
|
||||
* $Revision: 1.5 $
|
||||
* $Date: 2003/06/04 20:24:14 $
|
||||
* $Revision: 1.6 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
@ -112,11 +112,19 @@ final class BreakIteratorFactory extends BreakIterator.BreakIteratorServiceShim
|
|||
}
|
||||
catch(MissingResourceException e) {
|
||||
}
|
||||
// TODO: we don't have 'bad' resource data, so this should never happen
|
||||
// in our current tests.
|
||||
///CLOVER:OFF
|
||||
return new RuleBasedBreakIterator(rules);
|
||||
///CLOVER:ON
|
||||
}
|
||||
else {
|
||||
// TODO: we don't have 'bad' resource data, so this should never happen
|
||||
// in our current tests.
|
||||
///CLOVER:OFF
|
||||
throw new IllegalArgumentException("Invalid break iterator class \"" +
|
||||
classNames[kind] + "\"");
|
||||
///CLOVER:ON
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Collator.java,v $
|
||||
* $Date: 2003/06/03 18:49:33 $
|
||||
* $Revision: 1.31 $
|
||||
* $Date: 2003/06/04 20:24:14 $
|
||||
* $Revision: 1.32 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -389,7 +389,6 @@ public abstract class Collator implements Comparator, Cloneable
|
|||
abstract Object registerFactory(CollatorFactory f);
|
||||
abstract boolean unregister(Object k);
|
||||
abstract Locale[] getAvailableLocales();
|
||||
abstract Map getDisplayNames(Locale l);
|
||||
abstract String getDisplayName(Locale ol, Locale dl);
|
||||
}
|
||||
|
||||
|
@ -405,8 +404,10 @@ public abstract class Collator implements Comparator, Cloneable
|
|||
shim = (ServiceShim)cls.newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
///CLOVER:OFF
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage());
|
||||
///CLOVER:ON
|
||||
}
|
||||
}
|
||||
return shim;
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/CollatorServiceShim.java,v $
|
||||
* $Date: 2003/05/14 19:03:31 $
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2003/06/04 20:24:14 $
|
||||
* $Revision: 1.5 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -36,7 +36,9 @@ final class CollatorServiceShim extends Collator.ServiceShim {
|
|||
return (Collator)((Collator)service.get(locale)).clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
///CLOVER:OFF
|
||||
throw new InternalError(e.getMessage());
|
||||
///CLOVER:ON
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,11 +87,6 @@ final class CollatorServiceShim extends Collator.ServiceShim {
|
|||
return service.getAvailableLocales();
|
||||
}
|
||||
|
||||
Map getDisplayNames(Locale locale) {
|
||||
Collator col = Collator.getInstance(locale);
|
||||
return service.getDisplayNames(locale, col, null);
|
||||
}
|
||||
|
||||
String getDisplayName(Locale objectLocale, Locale displayLocale) {
|
||||
String id = LocaleUtility.canonicalLocaleString(objectLocale);
|
||||
return service.getDisplayName(id, displayLocale);
|
||||
|
|
Loading…
Add table
Reference in a new issue