use of android.icu.util.Currency in project j2objc by google.
the class CurrencyTest method testGetDefaultFractionDigits_CurrencyUsage.
/**
* Test cases for rounding and fractions.
*/
@Test
public void testGetDefaultFractionDigits_CurrencyUsage() {
Currency currency = Currency.getInstance(ULocale.CHINA);
int cashFractionDigits = currency.getDefaultFractionDigits(Currency.CurrencyUsage.CASH);
assertEquals("number of digits in fraction incorrect", 2, cashFractionDigits);
}
use of android.icu.util.Currency in project j2objc by google.
the class GlobalizationPreferencesTest method TestCurrency.
@Test
public void TestCurrency() {
GlobalizationPreferences gp = new GlobalizationPreferences();
// Set language only locale - ja
logln("Set locale - ja");
gp.setLocale(new ULocale("ja"));
Currency cur = gp.getCurrency();
String code = cur.getCurrencyCode();
if (!code.equals("JPY")) {
errln("FAIL: Currency is " + code + " - Expected: JPY");
}
gp.reset();
// Set locales with territory
logln("Set locale - ja_US");
gp.setLocale(new ULocale("ja_US"));
cur = gp.getCurrency();
code = cur.getCurrencyCode();
if (!code.equals("USD")) {
errln("FAIL: Currency is " + code + " - Expected: USD");
}
// Set locales with territory in the second locale
logln("Set locales - it, en_US");
ULocale[] locales = new ULocale[2];
locales[0] = new ULocale("it");
locales[1] = new ULocale("en_US");
gp.setLocales(locales);
cur = gp.getCurrency();
code = cur.getCurrencyCode();
if (!code.equals("USD")) {
errln("FAIL: Currency is " + code + " - Expected: USD");
}
// Set explicit territory
logln("Set territory - DE");
gp.setTerritory("DE");
cur = gp.getCurrency();
code = cur.getCurrencyCode();
if (!code.equals("EUR")) {
errln("FAIL: Currency is " + code + " - Expected: EUR");
}
// Set explicit currency
Currency ecur = Currency.getInstance("BRL");
gp.setCurrency(ecur);
logln("Set explicit currency - BRL");
cur = gp.getCurrency();
code = cur.getCurrencyCode();
if (!code.equals("BRL")) {
errln("FAIL: Currency is " + code + " - Expected: BRL");
}
// Set explicit territory again
logln("Set territory - JP");
cur = gp.getCurrency();
code = cur.getCurrencyCode();
if (!code.equals("BRL")) {
errln("FAIL: Currency is " + code + " - Expected: BRL");
}
// Freeze
logln("Freeze this object");
Currency ecur2 = Currency.getInstance("CHF");
boolean bFrozen = false;
gp.freeze();
try {
gp.setCurrency(ecur2);
} catch (UnsupportedOperationException uoe) {
logln("setCurrency is blocked");
bFrozen = true;
}
if (!bFrozen) {
errln("FAIL: setCurrency must be blocked");
}
// Safe clone
logln("cloneAsThawed");
GlobalizationPreferences gp1 = (GlobalizationPreferences) gp.cloneAsThawed();
cur = gp.getCurrency();
code = cur.getCurrencyCode();
if (!code.equals("BRL")) {
errln("FAIL: Currency is " + code + " - Expected: BRL");
}
// Set ecplicit currency
gp1.setCurrency(ecur2);
cur = gp1.getCurrency();
code = cur.getCurrencyCode();
if (!code.equals("CHF")) {
errln("FAIL: Currency is " + code + " - Expected: CHF");
}
}
use of android.icu.util.Currency in project j2objc by google.
the class IntlTestDecimalFormatSymbols method TestSymbols.
// Test the API of DecimalFormatSymbols; primarily a simple get/set set.
@Test
public void TestSymbols() {
DecimalFormatSymbols fr = new DecimalFormatSymbols(Locale.FRENCH);
DecimalFormatSymbols en = new DecimalFormatSymbols(Locale.ENGLISH);
if (en.equals(fr)) {
errln("ERROR: English DecimalFormatSymbols equal to French");
}
if (!en.getLocale().equals(Locale.ENGLISH)) {
errln("ERROR: getLocale failed");
}
if (!en.getULocale().equals(ULocale.ENGLISH)) {
errln("ERROR: getULocale failed");
}
if (!en.getLocale().equals(Locale.ENGLISH)) {
errln("ERROR: getLocale failed");
}
if (!en.getULocale().equals(ULocale.ENGLISH)) {
errln("ERROR: getULocale failed");
}
char zero = en.getZeroDigit();
fr.setZeroDigit(zero);
if (fr.getZeroDigit() != en.getZeroDigit()) {
errln("ERROR: get/set ZeroDigit failed");
}
String[] digits = en.getDigitStrings();
fr.setDigitStrings(digits);
if (!Arrays.equals(fr.getDigitStrings(), en.getDigitStrings())) {
errln("ERROR: get/set DigitStrings failed");
}
char sigDigit = en.getSignificantDigit();
fr.setSignificantDigit(sigDigit);
if (fr.getSignificantDigit() != en.getSignificantDigit()) {
errln("ERROR: get/set SignificantDigit failed");
}
Currency currency = Currency.getInstance("USD");
fr.setCurrency(currency);
if (!fr.getCurrency().equals(currency)) {
errln("ERROR: get/set Currency failed");
}
char group = en.getGroupingSeparator();
fr.setGroupingSeparator(group);
if (fr.getGroupingSeparator() != en.getGroupingSeparator()) {
errln("ERROR: get/set GroupingSeparator failed");
}
String groupStr = en.getGroupingSeparatorString();
fr.setGroupingSeparatorString(groupStr);
if (!fr.getGroupingSeparatorString().equals(en.getGroupingSeparatorString())) {
errln("ERROR: get/set GroupingSeparatorString failed");
}
char decimal = en.getDecimalSeparator();
fr.setDecimalSeparator(decimal);
if (fr.getDecimalSeparator() != en.getDecimalSeparator()) {
errln("ERROR: get/set DecimalSeparator failed");
}
String decimalStr = en.getDecimalSeparatorString();
fr.setDecimalSeparatorString(decimalStr);
if (!fr.getDecimalSeparatorString().equals(en.getDecimalSeparatorString())) {
errln("ERROR: get/set DecimalSeparatorString failed");
}
char monetaryGroup = en.getMonetaryGroupingSeparator();
fr.setMonetaryGroupingSeparator(monetaryGroup);
if (fr.getMonetaryGroupingSeparator() != en.getMonetaryGroupingSeparator()) {
errln("ERROR: get/set MonetaryGroupingSeparator failed");
}
String monetaryGroupStr = en.getMonetaryGroupingSeparatorString();
fr.setMonetaryGroupingSeparatorString(monetaryGroupStr);
if (!fr.getMonetaryGroupingSeparatorString().equals(en.getMonetaryGroupingSeparatorString())) {
errln("ERROR: get/set MonetaryGroupingSeparatorString failed");
}
char monetaryDecimal = en.getMonetaryDecimalSeparator();
fr.setMonetaryDecimalSeparator(monetaryDecimal);
if (fr.getMonetaryDecimalSeparator() != en.getMonetaryDecimalSeparator()) {
errln("ERROR: get/set MonetaryDecimalSeparator failed");
}
String monetaryDecimalStr = en.getMonetaryDecimalSeparatorString();
fr.setMonetaryDecimalSeparatorString(monetaryDecimalStr);
if (!fr.getMonetaryDecimalSeparatorString().equals(en.getMonetaryDecimalSeparatorString())) {
errln("ERROR: get/set MonetaryDecimalSeparatorString failed");
}
char perMill = en.getPerMill();
fr.setPerMill(perMill);
if (fr.getPerMill() != en.getPerMill()) {
errln("ERROR: get/set PerMill failed");
}
String perMillStr = en.getPerMillString();
fr.setPerMillString(perMillStr);
if (!fr.getPerMillString().equals(en.getPerMillString())) {
errln("ERROR: get/set PerMillString failed");
}
char percent = en.getPercent();
fr.setPercent(percent);
if (fr.getPercent() != en.getPercent()) {
errln("ERROR: get/set Percent failed");
}
String percentStr = en.getPercentString();
fr.setPercentString(percentStr);
if (!fr.getPercentString().equals(en.getPercentString())) {
errln("ERROR: get/set PercentString failed");
}
char digit = en.getDigit();
fr.setDigit(digit);
if (fr.getDigit() != en.getDigit()) {
errln("ERROR: get/set Digit failed");
}
char patternSeparator = en.getPatternSeparator();
fr.setPatternSeparator(patternSeparator);
if (fr.getPatternSeparator() != en.getPatternSeparator()) {
errln("ERROR: get/set PatternSeparator failed");
}
String infinity = en.getInfinity();
fr.setInfinity(infinity);
String infinity2 = fr.getInfinity();
if (!infinity.equals(infinity2)) {
errln("ERROR: get/set Infinity failed");
}
String nan = en.getNaN();
fr.setNaN(nan);
String nan2 = fr.getNaN();
if (!nan.equals(nan2)) {
errln("ERROR: get/set NaN failed");
}
char minusSign = en.getMinusSign();
fr.setMinusSign(minusSign);
if (fr.getMinusSign() != en.getMinusSign()) {
errln("ERROR: get/set MinusSign failed");
}
String minusSignStr = en.getMinusSignString();
fr.setMinusSignString(minusSignStr);
if (!fr.getMinusSignString().equals(en.getMinusSignString())) {
errln("ERROR: get/set MinusSignString failed");
}
char plusSign = en.getPlusSign();
fr.setPlusSign(plusSign);
if (fr.getPlusSign() != en.getPlusSign()) {
errln("ERROR: get/set PlusSign failed");
}
String plusSignStr = en.getPlusSignString();
fr.setPlusSignString(plusSignStr);
if (!fr.getPlusSignString().equals(en.getPlusSignString())) {
errln("ERROR: get/set PlusSignString failed");
}
char padEscape = en.getPadEscape();
fr.setPadEscape(padEscape);
if (fr.getPadEscape() != en.getPadEscape()) {
errln("ERROR: get/set PadEscape failed");
}
String exponential = en.getExponentSeparator();
fr.setExponentSeparator(exponential);
if (fr.getExponentSeparator() != en.getExponentSeparator()) {
errln("ERROR: get/set Exponential failed");
}
String exponentMultiplicationSign = en.getExponentMultiplicationSign();
fr.setExponentMultiplicationSign(exponentMultiplicationSign);
if (fr.getExponentMultiplicationSign() != en.getExponentMultiplicationSign()) {
errln("ERROR: get/set ExponentMultiplicationSign failed");
}
// be different between en and fr in the future.
for (int i = DecimalFormatSymbols.CURRENCY_SPC_CURRENCY_MATCH; i <= DecimalFormatSymbols.CURRENCY_SPC_INSERT; i++) {
if (en.getPatternForCurrencySpacing(i, true) != fr.getPatternForCurrencySpacing(i, true)) {
errln("ERROR: get currency spacing item:" + i + " before the currency");
if (en.getPatternForCurrencySpacing(i, false) != fr.getPatternForCurrencySpacing(i, false)) {
errln("ERROR: get currency spacing item:" + i + " after currency");
}
}
}
String dash = "-";
en.setPatternForCurrencySpacing(DecimalFormatSymbols.CURRENCY_SPC_INSERT, true, dash);
if (dash != en.getPatternForCurrencySpacing(DecimalFormatSymbols.CURRENCY_SPC_INSERT, true)) {
errln("ERROR: set currency spacing pattern for before currency.");
}
// DecimalFormatSymbols foo = new DecimalFormatSymbols(); //The variable is never used
en = (DecimalFormatSymbols) fr.clone();
if (!en.equals(fr)) {
errln("ERROR: Clone failed");
}
}
Aggregations