2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
2009-04-22 22:07:52 +00:00
|
|
|
* COPYRIGHT:
|
2010-08-13 21:23:00 +00:00
|
|
|
* Copyright (c) 1997-2010, International Business Machines Corporation and
|
2000-01-15 02:00:06 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
2002-09-21 00:43:14 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/dcfmtsym.h"
|
2000-06-01 18:46:31 +00:00
|
|
|
#include "unicode/decimfmt.h"
|
2000-05-25 01:10:55 +00:00
|
|
|
#include "unicode/unum.h"
|
|
|
|
#include "tsdcfmsy.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-23 19:11:16 +00:00
|
|
|
void IntlTestDecimalFormatSymbols::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
if (exec) logln("TestSuite DecimalFormatSymbols");
|
|
|
|
switch (index) {
|
2009-04-22 22:07:52 +00:00
|
|
|
case 0: name = "DecimalFormatSymbols test";
|
1999-08-16 21:50:52 +00:00
|
|
|
if (exec) {
|
|
|
|
logln("DecimalFormatSymbols test---"); logln("");
|
2000-08-23 19:11:16 +00:00
|
|
|
testSymbols(/*par*/);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: name = ""; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the API of DecimalFormatSymbols; primarily a simple get/set set.
|
|
|
|
*/
|
2000-08-23 19:11:16 +00:00
|
|
|
void IntlTestDecimalFormatSymbols::testSymbols(/* char *par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
DecimalFormatSymbols fr(Locale::getFrench(), status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)) {
|
2009-06-12 19:34:21 +00:00
|
|
|
errcheckln(status, "ERROR: Couldn't create French DecimalFormatSymbols - %s", u_errorName(status));
|
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
1999-10-07 00:07:53 +00:00
|
|
|
status = U_ZERO_ERROR;
|
2001-09-17 21:50:19 +00:00
|
|
|
DecimalFormatSymbols en(Locale::getEnglish(), status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)) {
|
2009-06-12 19:34:21 +00:00
|
|
|
errcheckln(status, "ERROR: Couldn't create English DecimalFormatSymbols - %s", u_errorName(status));
|
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(en == fr || ! (en != fr) ) {
|
|
|
|
errln("ERROR: English DecimalFormatSymbols equal to French");
|
|
|
|
}
|
|
|
|
|
|
|
|
// just do some VERY basic tests to make sure that get/set work
|
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
UnicodeString zero = en.getSymbol(DecimalFormatSymbols::kZeroDigitSymbol);
|
|
|
|
fr.setSymbol(DecimalFormatSymbols::kZeroDigitSymbol, zero);
|
|
|
|
if(fr.getSymbol(DecimalFormatSymbols::kZeroDigitSymbol) != en.getSymbol(DecimalFormatSymbols::kZeroDigitSymbol)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("ERROR: get/set ZeroDigit failed");
|
|
|
|
}
|
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
UnicodeString group = en.getSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol);
|
|
|
|
fr.setSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol, group);
|
|
|
|
if(fr.getSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol) != en.getSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("ERROR: get/set GroupingSeparator failed");
|
|
|
|
}
|
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
UnicodeString decimal = en.getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol);
|
|
|
|
fr.setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, decimal);
|
|
|
|
if(fr.getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol) != en.getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("ERROR: get/set DecimalSeparator failed");
|
|
|
|
}
|
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
UnicodeString perMill = en.getSymbol(DecimalFormatSymbols::kPerMillSymbol);
|
|
|
|
fr.setSymbol(DecimalFormatSymbols::kPerMillSymbol, perMill);
|
|
|
|
if(fr.getSymbol(DecimalFormatSymbols::kPerMillSymbol) != en.getSymbol(DecimalFormatSymbols::kPerMillSymbol)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("ERROR: get/set PerMill failed");
|
|
|
|
}
|
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
UnicodeString percent = en.getSymbol(DecimalFormatSymbols::kPercentSymbol);
|
|
|
|
fr.setSymbol(DecimalFormatSymbols::kPercentSymbol, percent);
|
|
|
|
if(fr.getSymbol(DecimalFormatSymbols::kPercentSymbol) != en.getSymbol(DecimalFormatSymbols::kPercentSymbol)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("ERROR: get/set Percent failed");
|
|
|
|
}
|
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
UnicodeString digit(en.getSymbol(DecimalFormatSymbols::kDigitSymbol));
|
|
|
|
fr.setSymbol(DecimalFormatSymbols::kDigitSymbol, digit);
|
|
|
|
if(fr.getSymbol(DecimalFormatSymbols::kDigitSymbol) != en.getSymbol(DecimalFormatSymbols::kDigitSymbol)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("ERROR: get/set Percent failed");
|
|
|
|
}
|
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
UnicodeString patternSeparator = en.getSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol);
|
|
|
|
fr.setSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol, patternSeparator);
|
|
|
|
if(fr.getSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol) != en.getSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("ERROR: get/set PatternSeparator failed");
|
|
|
|
}
|
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
UnicodeString infinity(en.getSymbol(DecimalFormatSymbols::kInfinitySymbol));
|
|
|
|
fr.setSymbol(DecimalFormatSymbols::kInfinitySymbol, infinity);
|
|
|
|
UnicodeString infinity2(fr.getSymbol(DecimalFormatSymbols::kInfinitySymbol));
|
1999-08-16 21:50:52 +00:00
|
|
|
if(infinity != infinity2) {
|
|
|
|
errln("ERROR: get/set Infinity failed");
|
|
|
|
}
|
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
UnicodeString nan(en.getSymbol(DecimalFormatSymbols::kNaNSymbol));
|
|
|
|
fr.setSymbol(DecimalFormatSymbols::kNaNSymbol, nan);
|
|
|
|
UnicodeString nan2(fr.getSymbol(DecimalFormatSymbols::kNaNSymbol));
|
1999-08-16 21:50:52 +00:00
|
|
|
if(nan != nan2) {
|
|
|
|
errln("ERROR: get/set NaN failed");
|
|
|
|
}
|
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
UnicodeString minusSign = en.getSymbol(DecimalFormatSymbols::kMinusSignSymbol);
|
|
|
|
fr.setSymbol(DecimalFormatSymbols::kMinusSignSymbol, minusSign);
|
|
|
|
if(fr.getSymbol(DecimalFormatSymbols::kMinusSignSymbol) != en.getSymbol(DecimalFormatSymbols::kMinusSignSymbol)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("ERROR: get/set MinusSign failed");
|
|
|
|
}
|
2009-04-22 22:07:52 +00:00
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
UnicodeString exponential(en.getSymbol(DecimalFormatSymbols::kExponentialSymbol));
|
|
|
|
fr.setSymbol(DecimalFormatSymbols::kExponentialSymbol, exponential);
|
|
|
|
if(fr.getSymbol(DecimalFormatSymbols::kExponentialSymbol) != en.getSymbol(DecimalFormatSymbols::kExponentialSymbol)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("ERROR: get/set Exponential failed");
|
|
|
|
}
|
|
|
|
|
2009-04-22 22:07:52 +00:00
|
|
|
// Test get currency spacing before the currency.
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
for (int32_t i = 0; i < (int32_t)DecimalFormatSymbols::kCurrencySpacingCount; i++) {
|
|
|
|
UnicodeString enCurrencyPattern = en.getPatternForCurrencySpacing(
|
|
|
|
(DecimalFormatSymbols::ECurrencySpacing)i, TRUE, status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Error: cannot get CurrencyMatch for locale:en");
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
UnicodeString frCurrencyPattern = fr.getPatternForCurrencySpacing(
|
|
|
|
(DecimalFormatSymbols::ECurrencySpacing)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 < DecimalFormatSymbols::kCurrencySpacingCount; i++) {
|
|
|
|
UnicodeString enCurrencyPattern = en.getPatternForCurrencySpacing(
|
|
|
|
(DecimalFormatSymbols::ECurrencySpacing)i, FALSE, status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Error: cannot get CurrencyMatch for locale:en");
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
UnicodeString frCurrencyPattern = fr.getPatternForCurrencySpacing(
|
|
|
|
(DecimalFormatSymbols::ECurrencySpacing)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(DecimalFormatSymbols::kInsert, TRUE, dash);
|
|
|
|
UnicodeString enCurrencyInsert = en.getPatternForCurrencySpacing(
|
|
|
|
DecimalFormatSymbols::kInsert, TRUE, status);
|
|
|
|
if (dash != enCurrencyInsert) {
|
|
|
|
errln("Error: Failed to setCurrencyInsert for locale:en");
|
|
|
|
}
|
|
|
|
|
1999-10-07 00:07:53 +00:00
|
|
|
status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
DecimalFormatSymbols foo(status);
|
2009-04-22 22:07:52 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
DecimalFormatSymbols bar(foo);
|
|
|
|
|
|
|
|
en = fr;
|
|
|
|
|
|
|
|
if(en != fr || foo != bar) {
|
|
|
|
errln("ERROR: Copy Constructor or Assignment failed");
|
|
|
|
}
|
2000-05-25 01:10:55 +00:00
|
|
|
|
|
|
|
// test get/setSymbol()
|
2000-06-09 18:38:02 +00:00
|
|
|
if((int) UNUM_FORMAT_SYMBOL_COUNT != (int) DecimalFormatSymbols::kFormatSymbolCount) {
|
2000-05-25 01:10:55 +00:00
|
|
|
errln("unum.h and decimfmt.h have inconsistent numbers of format symbols!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int i;
|
2000-05-25 23:15:29 +00:00
|
|
|
for(i = 0; i < (int)DecimalFormatSymbols::kFormatSymbolCount; ++i) {
|
2000-05-25 01:10:55 +00:00
|
|
|
foo.setSymbol((DecimalFormatSymbols::ENumberFormatSymbol)i, UnicodeString((UChar32)(0x10330 + i)));
|
|
|
|
}
|
2000-05-25 23:15:29 +00:00
|
|
|
for(i = 0; i < (int)DecimalFormatSymbols::kFormatSymbolCount; ++i) {
|
2000-05-25 01:10:55 +00:00
|
|
|
if(foo.getSymbol((DecimalFormatSymbols::ENumberFormatSymbol)i) != UnicodeString((UChar32)(0x10330 + i))) {
|
|
|
|
errln("get/setSymbol did not roundtrip, got " +
|
|
|
|
foo.getSymbol((DecimalFormatSymbols::ENumberFormatSymbol)i) +
|
|
|
|
", expected " +
|
|
|
|
UnicodeString((UChar32)(0x10330 + i)));
|
|
|
|
}
|
|
|
|
}
|
2009-04-22 22:07:52 +00:00
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
DecimalFormatSymbols sym(Locale::getUS(), status);
|
2000-06-01 18:46:31 +00:00
|
|
|
|
|
|
|
UnicodeString customDecSeperator("S");
|
|
|
|
Verify(34.5, (UnicodeString)"00.00", sym, (UnicodeString)"34.50");
|
2010-08-13 21:23:00 +00:00
|
|
|
sym.setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, customDecSeperator);
|
2000-06-01 18:46:31 +00:00
|
|
|
Verify(34.5, (UnicodeString)"00.00", sym, (UnicodeString)"34S50");
|
2010-08-13 21:23:00 +00:00
|
|
|
sym.setSymbol(DecimalFormatSymbols::kPercentSymbol, (UnicodeString)"P");
|
2000-06-01 18:46:31 +00:00
|
|
|
Verify(34.5, (UnicodeString)"00 %", sym, (UnicodeString)"3450 P");
|
2010-08-13 21:23:00 +00:00
|
|
|
sym.setSymbol(DecimalFormatSymbols::kCurrencySymbol, (UnicodeString)"D");
|
2000-06-01 18:46:31 +00:00
|
|
|
Verify(34.5, CharsToUnicodeString("\\u00a4##.##"), sym, (UnicodeString)"D34.5");
|
2010-08-13 21:23:00 +00:00
|
|
|
sym.setSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol, (UnicodeString)"|");
|
2000-06-01 18:46:31 +00:00
|
|
|
Verify(3456.5, (UnicodeString)"0,000.##", sym, (UnicodeString)"3|456S5");
|
2009-04-22 22:07:52 +00:00
|
|
|
|
2000-06-01 18:46:31 +00:00
|
|
|
}
|
2001-09-17 21:50:19 +00:00
|
|
|
|
2000-06-02 00:45:36 +00:00
|
|
|
void IntlTestDecimalFormatSymbols::Verify(double value, const UnicodeString& pattern, DecimalFormatSymbols sym, const UnicodeString& expected){
|
2000-06-01 18:46:31 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
DecimalFormat *df = new DecimalFormat(pattern, sym, status);
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
errln("ERROR: construction of decimal format failed");
|
|
|
|
}
|
|
|
|
UnicodeString buffer;
|
|
|
|
FieldPosition pos(FieldPosition::DONT_CARE);
|
|
|
|
buffer = df->format(value, buffer, pos);
|
|
|
|
if(buffer != expected){
|
2009-04-22 22:07:52 +00:00
|
|
|
errln((UnicodeString)"ERROR: format failed after setSymbols()\n Expected " +
|
2000-06-01 18:46:31 +00:00
|
|
|
expected + ", Got " + buffer);
|
|
|
|
}
|
|
|
|
delete df;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2002-09-21 00:43:14 +00:00
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|