mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-15 01:42:37 +00:00
ICU-1884 add test for currency patterns
X-SVN-Rev: 9465
This commit is contained in:
parent
2a51b28692
commit
e30eecf51d
2 changed files with 50 additions and 0 deletions
|
@ -12,7 +12,10 @@
|
|||
#include "unicode/dcfmtsym.h"
|
||||
#include "unicode/decimfmt.h"
|
||||
#include "unicode/ucurr.h"
|
||||
#include "unicode/ustring.h"
|
||||
#include <float.h>
|
||||
|
||||
static const UChar EUR[] = {69,85,82,0}; // "EUR"
|
||||
|
||||
// *****************************************************************************
|
||||
// class NumberFormatTest
|
||||
|
@ -44,6 +47,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
|
|||
CASE(13,TestAPI);
|
||||
|
||||
CASE(14,TestCurrencyObject);
|
||||
CASE(15,TestCurrencyPatterns);
|
||||
|
||||
default: name = ""; break;
|
||||
}
|
||||
|
@ -1188,3 +1192,47 @@ void NumberFormatTest::TestSurrogateSupport(void) {
|
|||
expect(new DecimalFormat(patternStr, custom, status),
|
||||
int32_t(-20), expStr, status);
|
||||
}
|
||||
|
||||
void NumberFormatTest::TestCurrencyPatterns(void) {
|
||||
UnicodeString dot00(".00", "");
|
||||
int32_t i, locCount;
|
||||
const Locale* locs = NumberFormat::getAvailableLocales(locCount);
|
||||
for (i=0; i<locCount; ++i) {
|
||||
UErrorCode ec = U_ZERO_ERROR;
|
||||
NumberFormat* nf = NumberFormat::createCurrencyInstance(locs[i], ec);
|
||||
if (U_FAILURE(ec)) {
|
||||
errln("FAIL: Can't create NumberFormat");
|
||||
} else {
|
||||
// Make sure currency formats do not have a variable number
|
||||
// of fraction digits
|
||||
int32_t min = nf->getMinimumFractionDigits();
|
||||
int32_t max = nf->getMaximumFractionDigits();
|
||||
if (min != max) {
|
||||
UnicodeString a, b;
|
||||
nf->format(1.0, a);
|
||||
nf->format(1.125, b);
|
||||
errln((UnicodeString)"FAIL: " + locs[i].getName() +
|
||||
" min fraction digits != max fraction digits; "
|
||||
"x 1.0 => " + escape(a) +
|
||||
"; x 1.125 => " + escape(b));
|
||||
}
|
||||
|
||||
// Make sure EURO currency formats have exactly 2 fraction digits
|
||||
if (nf->getDynamicClassID() == DecimalFormat::getStaticClassID()) {
|
||||
DecimalFormat* df = (DecimalFormat*) nf;
|
||||
if (u_strcmp(EUR, df->getCurrency()) == 0) {
|
||||
if (min != 2 || max != 2) {
|
||||
UnicodeString a;
|
||||
nf->format(1.0, a);
|
||||
errln((UnicodeString)"FAIL: " + locs[i].getName() +
|
||||
" is a EURO format but it does not have 2 fraction digits; "
|
||||
"x 1.0 => " +
|
||||
escape(a));
|
||||
}
|
||||
logln(locs[i].getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
delete nf;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,6 +57,8 @@ public:
|
|||
void expectCurrency(NumberFormat& nf, const Locale& locale,
|
||||
double value, const UnicodeString& string);
|
||||
|
||||
void TestCurrencyPatterns(void);
|
||||
|
||||
/**
|
||||
* Do rudimentary testing of parsing.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue