use of android.icu.text.NumberFormat.SimpleNumberFormatFactory in project j2objc by google.
the class NumberFormatRegistrationTest method TestRegistration.
@Test
public void TestRegistration() {
final ULocale SRC_LOC = ULocale.FRANCE;
final ULocale SWAP_LOC = ULocale.US;
class TestFactory extends SimpleNumberFormatFactory {
NumberFormat currencyStyle;
TestFactory() {
this(SRC_LOC, SWAP_LOC);
}
TestFactory(ULocale srcLoc, ULocale swapLoc) {
super(srcLoc);
currencyStyle = NumberFormat.getIntegerInstance(swapLoc);
}
public NumberFormat createFormat(ULocale loc, int formatType) {
if (formatType == FORMAT_CURRENCY) {
return currencyStyle;
}
return null;
}
}
{
try {
NumberFormat.unregister(null);
errln("did not throw exception on null unregister");
} catch (Exception e) {
logln("PASS: null unregister failed as expected");
}
try {
NumberFormat.registerFactory(null);
errln("did not throw exception on null register");
} catch (Exception e) {
logln("PASS: null register failed as expected");
}
try {
// an exception.
if (NumberFormat.unregister("")) {
errln("unregister of empty string key succeeded");
}
} catch (Exception e) {
}
}
ULocale fu_FU = new ULocale("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, ULocale.GERMANY));
if (!Arrays.asList(NumberFormat.getAvailableULocales()).contains(fu_FU)) {
errln("did not list fu_FU");
}
NumberFormat f3 = NumberFormat.getCurrencyInstance(SRC_LOC);
NumberFormat f4 = NumberFormat.getIntegerInstance(SRC_LOC);
// restore for other tests
NumberFormat.unregister(key);
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));
logln("f2 src cur: " + f2.format(n));
logln("f3 reg cur: " + f3.format(n));
logln("f4 reg int: " + f4.format(n));
logln("f5 unreg cur: " + f5.format(n));
if (!f3.format(n).equals(f0.format(n))) {
errln("registered service did not match");
}
if (!f4.format(n).equals(f1.format(n))) {
errln("registered service did not inherit");
}
if (!f5.format(n).equals(f2.format(n))) {
errln("unregistered service did not match original");
}
// coverage
NumberFormat f6 = NumberFormat.getNumberInstance(fu_FU);
if (f6 == null) {
errln("getNumberInstance(fu_FU) returned null");
}
}
use of android.icu.text.NumberFormat.SimpleNumberFormatFactory in project j2objc by google.
the class NumberFormatTest method TestRegistration.
@Test
public void TestRegistration() {
final ULocale SRC_LOC = ULocale.FRANCE;
final ULocale SWAP_LOC = ULocale.US;
class TestFactory extends SimpleNumberFormatFactory {
NumberFormat currencyStyle;
TestFactory() {
super(SRC_LOC, true);
currencyStyle = NumberFormat.getIntegerInstance(SWAP_LOC);
}
@Override
public NumberFormat createFormat(ULocale loc, int formatType) {
if (formatType == FORMAT_CURRENCY) {
return currencyStyle;
}
return null;
}
}
NumberFormat f0 = NumberFormat.getIntegerInstance(SWAP_LOC);
NumberFormat f1 = NumberFormat.getIntegerInstance(SRC_LOC);
NumberFormat f2 = NumberFormat.getCurrencyInstance(SRC_LOC);
Object key = NumberFormat.registerFactory(new TestFactory());
NumberFormat f3 = NumberFormat.getCurrencyInstance(SRC_LOC);
NumberFormat f4 = NumberFormat.getIntegerInstance(SRC_LOC);
// restore for other tests
NumberFormat.unregister(key);
NumberFormat f5 = NumberFormat.getCurrencyInstance(SRC_LOC);
float n = 1234.567f;
logln("f0 swap int: " + f0.format(n));
logln("f1 src int: " + f1.format(n));
logln("f2 src cur: " + f2.format(n));
logln("f3 reg cur: " + f3.format(n));
logln("f4 reg int: " + f4.format(n));
logln("f5 unreg cur: " + f5.format(n));
if (!f3.format(n).equals(f0.format(n))) {
errln("registered service did not match");
}
if (!f4.format(n).equals(f1.format(n))) {
errln("registered service did not inherit");
}
if (!f5.format(n).equals(f2.format(n))) {
errln("unregistered service did not match original");
}
}
Aggregations