/********************************************************************
- * COPYRIGHT:
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * COPYRIGHT:
+ * Copyright (c) 1997-2010, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
{
if (exec) logln("TestSuite DecimalFormatSymbols");
switch (index) {
- case 0: name = "DecimalFormatSymbols test";
+ case 0: name = "DecimalFormatSymbols test";
if (exec) {
logln("DecimalFormatSymbols test---"); logln("");
testSymbols(/*par*/);
DecimalFormatSymbols fr(Locale::getFrench(), status);
if(U_FAILURE(status)) {
- errln("ERROR: Couldn't create French DecimalFormatSymbols");
+ errcheckln(status, "ERROR: Couldn't create French DecimalFormatSymbols - %s", u_errorName(status));
+ return;
}
status = U_ZERO_ERROR;
DecimalFormatSymbols en(Locale::getEnglish(), status);
if(U_FAILURE(status)) {
- errln("ERROR: Couldn't create English DecimalFormatSymbols");
+ errcheckln(status, "ERROR: Couldn't create English DecimalFormatSymbols - %s", u_errorName(status));
+ return;
}
if(en == fr || ! (en != fr) ) {
if(fr.getSymbol(DecimalFormatSymbols::kMinusSignSymbol) != en.getSymbol(DecimalFormatSymbols::kMinusSignSymbol)) {
errln("ERROR: get/set MinusSign failed");
}
-
+
UnicodeString exponential(en.getSymbol(DecimalFormatSymbols::kExponentialSymbol));
fr.setSymbol(DecimalFormatSymbols::kExponentialSymbol, exponential);
if(fr.getSymbol(DecimalFormatSymbols::kExponentialSymbol) != en.getSymbol(DecimalFormatSymbols::kExponentialSymbol)) {
errln("ERROR: get/set Exponential failed");
}
+ // Test get currency spacing before the currency.
+ status = U_ZERO_ERROR;
+ for (int32_t i = 0; i < (int32_t)UNUM_CURRENCY_SPACING_COUNT; i++) {
+ UnicodeString enCurrencyPattern = en.getPatternForCurrencySpacing(
+ (UCurrencySpacing)i, TRUE, status);
+ if(U_FAILURE(status)) {
+ errln("Error: cannot get CurrencyMatch for locale:en");
+ status = U_ZERO_ERROR;
+ }
+ UnicodeString frCurrencyPattern = fr.getPatternForCurrencySpacing(
+ (UCurrencySpacing)i, TRUE, status);
+ if(U_FAILURE(status)) {
+ errln("Error: cannot get CurrencyMatch for locale:fr");
+ }
+ if (enCurrencyPattern != frCurrencyPattern) {
+ errln("ERROR: get CurrencySpacing failed");
+ }
+ }
+ // Test get currencySpacing after the currency.
+ status = U_ZERO_ERROR;
+ for (int32_t i = 0; i < UNUM_CURRENCY_SPACING_COUNT; i++) {
+ UnicodeString enCurrencyPattern = en.getPatternForCurrencySpacing(
+ (UCurrencySpacing)i, FALSE, status);
+ if(U_FAILURE(status)) {
+ errln("Error: cannot get CurrencyMatch for locale:en");
+ status = U_ZERO_ERROR;
+ }
+ UnicodeString frCurrencyPattern = fr.getPatternForCurrencySpacing(
+ (UCurrencySpacing)i, FALSE, status);
+ if(U_FAILURE(status)) {
+ errln("Error: cannot get CurrencyMatch for locale:fr");
+ }
+ if (enCurrencyPattern != frCurrencyPattern) {
+ errln("ERROR: get CurrencySpacing failed");
+ }
+ }
+ // Test set curerncySpacing APIs
+ status = U_ZERO_ERROR;
+ UnicodeString dash = UnicodeString("-");
+ en.setPatternForCurrencySpacing(UNUM_CURRENCY_INSERT, TRUE, dash);
+ UnicodeString enCurrencyInsert = en.getPatternForCurrencySpacing(
+ UNUM_CURRENCY_INSERT, TRUE, status);
+ if (dash != enCurrencyInsert) {
+ errln("Error: Failed to setCurrencyInsert for locale:en");
+ }
+
status = U_ZERO_ERROR;
DecimalFormatSymbols foo(status);
-
+
DecimalFormatSymbols bar(foo);
en = fr;
UnicodeString((UChar32)(0x10330 + i)));
}
}
-
-
+
DecimalFormatSymbols sym(Locale::getUS(), status);
UnicodeString customDecSeperator("S");
Verify(34.5, (UnicodeString)"00.00", sym, (UnicodeString)"34.50");
- sym.setSymbol((DecimalFormatSymbols::ENumberFormatSymbol)0, customDecSeperator);
+ sym.setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, customDecSeperator);
Verify(34.5, (UnicodeString)"00.00", sym, (UnicodeString)"34S50");
- sym.setSymbol((DecimalFormatSymbols::ENumberFormatSymbol)3, (UnicodeString)"P");
+ sym.setSymbol(DecimalFormatSymbols::kPercentSymbol, (UnicodeString)"P");
Verify(34.5, (UnicodeString)"00 %", sym, (UnicodeString)"3450 P");
- sym.setSymbol((DecimalFormatSymbols::ENumberFormatSymbol)8, (UnicodeString)"D");
+ sym.setSymbol(DecimalFormatSymbols::kCurrencySymbol, (UnicodeString)"D");
Verify(34.5, CharsToUnicodeString("\\u00a4##.##"), sym, (UnicodeString)"D34.5");
- sym.setSymbol((DecimalFormatSymbols::ENumberFormatSymbol)1, (UnicodeString)"|");
+ sym.setSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol, (UnicodeString)"|");
Verify(3456.5, (UnicodeString)"0,000.##", sym, (UnicodeString)"3|456S5");
-
+
}
void IntlTestDecimalFormatSymbols::Verify(double value, const UnicodeString& pattern, DecimalFormatSymbols sym, const UnicodeString& expected){
FieldPosition pos(FieldPosition::DONT_CARE);
buffer = df->format(value, buffer, pos);
if(buffer != expected){
- errln((UnicodeString)"ERROR: format failed after setSymbols()\n Expected " +
+ errln((UnicodeString)"ERROR: format failed after setSymbols()\n Expected " +
expected + ", Got " + buffer);
}
delete df;