ICU-11917 Fix no data test errors in ICU4C 56

X-SVN-Rev: 37981
This commit is contained in:
Michael Ow 2015-09-22 04:02:11 +00:00
parent 6097a70d4b
commit fdd235d5e5
10 changed files with 183 additions and 84 deletions

View File

@ -1748,6 +1748,9 @@ RuleBasedNumberFormat::getDecimalFormatSymbols() const
NFRule*
RuleBasedNumberFormat::initializeDefaultInfinityRule(UErrorCode &status)
{
if (U_FAILURE(status)) {
return NULL;
}
if (defaultInfinityRule == NULL) {
UnicodeString rule(UNICODE_STRING_SIMPLE("Inf: "));
rule.append(getDecimalFormatSymbols()->getSymbol(DecimalFormatSymbols::kInfinitySymbol));
@ -1771,6 +1774,9 @@ RuleBasedNumberFormat::getDefaultInfinityRule() const
NFRule*
RuleBasedNumberFormat::initializeDefaultNaNRule(UErrorCode &status)
{
if (U_FAILURE(status)) {
return NULL;
}
if (defaultNaNRule == NULL) {
UnicodeString rule(UNICODE_STRING_SIMPLE("NaN: "));
rule.append(getDecimalFormatSymbols()->getSymbol(DecimalFormatSymbols::kNaNSymbol));

View File

@ -852,6 +852,9 @@ static void TestBreakIteratorRefresh(void) {
bi = ubrk_open(UBRK_LINE, "en_US", NULL, 0, &status);
TEST_ASSERT_SUCCESS(status);
if (U_FAILURE(status)) {
return;
}
utext_openUChars(&ut1, testStr, -1, &status);
TEST_ASSERT_SUCCESS(status);

View File

@ -447,6 +447,7 @@ void IntlTestDecimalFormatAPI::TestCurrencyPluralInfo(){
DecimalFormat *df = new DecimalFormat(status);
if(U_FAILURE(status)) {
errcheckln(status, "ERROR: Could not create DecimalFormat - %s", u_errorName(status));
return;
}
df->adoptCurrencyPluralInfo(cpi);
@ -607,6 +608,9 @@ void IntlTestDecimalFormatAPI::TestFixedDecimal() {
LocalPointer<DecimalFormat> df(new DecimalFormat("###", status), status);
TEST_ASSERT_STATUS(status);
if (status == U_MISSING_RESOURCE_ERROR) {
return;
}
FixedDecimal fd = df->getFixedDecimal(44, status);
TEST_ASSERT_STATUS(status);
ASSERT_EQUAL(44, fd.source);

View File

@ -2147,7 +2147,7 @@ void IntlTestRBNF::TestInfinityNaN() {
{ NULL, NULL }
};
if (U_FAILURE(status)) {
errln("Unable to create RuleBasedNumberFormat - " + UnicodeString(u_errorName(status)));
dataerrln("Unable to create RuleBasedNumberFormat - " + UnicodeString(u_errorName(status)));
return;
}
@ -2200,7 +2200,7 @@ void IntlTestRBNF::TestVariableDecimalPoint() {
{ NULL, NULL }
};
if (U_FAILURE(status)) {
errln("Unable to create RuleBasedNumberFormat - " + UnicodeString(u_errorName(status)));
dataerrln("Unable to create RuleBasedNumberFormat - " + UnicodeString(u_errorName(status)));
return;
}
doTest(&enFormatter, enTestPointData, true);

View File

@ -1409,11 +1409,11 @@ void NumberFormat2Test::TestCurrencyAffixInfo() {
return;
}
info.set("en", rules.getAlias(), USD, status);
assertEquals("", "$", info.getSymbol());
assertEquals("", "USD", info.getISO());
assertEquals("", "US dollar", info.getLong().getByCategory("one").toString());
assertEquals("", "US dollars", info.getLong().getByCategory("other").toString());
assertEquals("", "US dollars", info.getLong().getByCategory("two").toString());
assertEquals("", "$", info.getSymbol(), TRUE);
assertEquals("", "USD", info.getISO(), TRUE);
assertEquals("", "US dollar", info.getLong().getByCategory("one").toString(), TRUE);
assertEquals("", "US dollars", info.getLong().getByCategory("other").toString(), TRUE);
assertEquals("", "US dollars", info.getLong().getByCategory("two").toString(), TRUE);
assertFalse("", info.isDefault());
info.set(NULL, NULL, NULL, status);
assertTrue("", info.isDefault());
@ -1491,6 +1491,10 @@ void NumberFormat2Test::TestAffixPatternParser() {
static UChar USD[] = {0x55, 0x53, 0x44, 0x0};
LocalPointer<PluralRules> rules(PluralRules::forLocale("en", status));
DecimalFormatSymbols symbols("en", status);
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormatSymbols - %s", u_errorName(status));
return;
}
AffixPatternParser parser(symbols);
CurrencyAffixInfo currencyAffixInfo;
currencyAffixInfo.set("en", rules.getAlias(), USD, status);
@ -2679,6 +2683,10 @@ void NumberFormat2Test::TestPluralsAndRoundingScientific() {
void NumberFormat2Test::TestRoundingIncrement() {
UErrorCode status = U_ZERO_ERROR;
DecimalFormatSymbols symbols("en", status);
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormatSymbols - %s", u_errorName(status));
return;
}
DigitFormatter formatter(symbols);
ScientificPrecision precision;
SciFormatterOptions options;

View File

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2014, International Business Machines Corporation and *
* Copyright (C) 2014-2015, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
@ -36,7 +36,10 @@ static NumberFormat *nfWithPattern(const char *pattern) {
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *result = new DecimalFormat(
upattern, new DecimalFormatSymbols("fr", status), status);
U_ASSERT(status == U_ZERO_ERROR);
if (U_FAILURE(status)) {
return NULL;
}
return result;
}
@ -96,6 +99,10 @@ void NumberFormatSpecificationTest::TestBasicPatterns() {
void NumberFormatSpecificationTest::TestNfSetters() {
LocalPointer<NumberFormat> nf(nfWithPattern("#,##0.##"));
if (nf == NULL) {
dataerrln("Error creating NumberFormat");
return;
}
nf->setMaximumIntegerDigits(5);
nf->setMinimumIntegerDigits(4);
assertEquals("", "34 567,89", format(1234567.89, *nf), TRUE);
@ -187,10 +194,14 @@ void NumberFormatSpecificationTest::TestPadding() {
UnicodeString result;
DecimalFormat fmt(
upattern, new DecimalFormatSymbols("fr", status), status);
fmt.setCurrency(kJPY);
fmt.format(433.22, result);
assertSuccess("", status);
assertEquals("", "JPY ****433", result, TRUE);
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
} else {
fmt.setCurrency(kJPY);
fmt.format(433.22, result);
assertSuccess("", status);
assertEquals("", "JPY ****433", result, TRUE);
}
}
{
UnicodeString upattern(
@ -202,9 +213,13 @@ void NumberFormatSpecificationTest::TestPadding() {
upattern,
new DecimalFormatSymbols("en_US", status),
status);
fmt.format(-433.22, result);
assertSuccess("", status);
assertEquals("", "USD (433.22)", result, TRUE);
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
} else {
fmt.format(-433.22, result);
assertSuccess("", status);
assertEquals("", "USD (433.22)", result, TRUE);
}
}
const char *paddedSciPattern = "QU**00.#####E0";
assertPatternFr("QU***43,3E-1", 4.33, paddedSciPattern, TRUE);
@ -216,10 +231,14 @@ void NumberFormatSpecificationTest::TestPadding() {
paddedSciPattern,
sym,
status);
UnicodeString result;
fmt.format(4.33, result);
assertSuccess("", status);
assertEquals("", "QU**43,3EE-1", result, TRUE);
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
} else {
UnicodeString result;
fmt.format(4.33, result);
assertSuccess("", status);
assertEquals("", "QU**43,3EE-1", result, TRUE);
}
}
// padding cannot work as intended with scientific notation.
assertPatternFr("QU**43,32E-1", 4.332, paddedSciPattern, TRUE);
@ -238,6 +257,10 @@ void NumberFormatSpecificationTest::assertPatternFr(
UnicodeString result;
DecimalFormat fmt(
upattern, new DecimalFormatSymbols("fr_FR", status), status);
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormatSymbols - %s", u_errorName(status));
return;
}
fmt.format(x, result);
fixNonBreakingSpace(result);
assertSuccess("", status);

View File

@ -960,6 +960,10 @@ void
NumberFormatTest::TestInt64() {
UErrorCode status = U_ZERO_ERROR;
DecimalFormat fmt("#.#E0",status);
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
return;
}
fmt.setMaximumFractionDigits(20);
if (U_SUCCESS(status)) {
expect(fmt, (Formattable)(int64_t)0, "0E0");
@ -7165,86 +7169,106 @@ void NumberFormatTest::TestFormatFastpaths() {
{
UErrorCode status=U_ZERO_ERROR;
DecimalFormat df(UnicodeString("0000",""),status);
int64_t long_number = 1;
UnicodeString expect = "0001";
UnicodeString result;
FieldPosition pos;
df.format(long_number, result, pos);
if(U_FAILURE(status)||expect!=result) {
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),""));
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
} else {
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),""));
int64_t long_number = 1;
UnicodeString expect = "0001";
UnicodeString result;
FieldPosition pos;
df.format(long_number, result, pos);
if(U_FAILURE(status)||expect!=result) {
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),""));
} else {
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),""));
}
}
}
{
UErrorCode status=U_ZERO_ERROR;
DecimalFormat df(UnicodeString("0000000000000000000",""),status);
int64_t long_number = U_INT64_MIN; // -9223372036854775808L;
// uint8_t bits[8];
// memcpy(bits,&long_number,8);
// for(int i=0;i<8;i++) {
// logln("bits: %02X", (unsigned int)bits[i]);
// }
UnicodeString expect = "-9223372036854775808";
UnicodeString result;
FieldPosition pos;
df.format(long_number, result, pos);
if(U_FAILURE(status)||expect!=result) {
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775808");
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
} else {
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775808");
int64_t long_number = U_INT64_MIN; // -9223372036854775808L;
// uint8_t bits[8];
// memcpy(bits,&long_number,8);
// for(int i=0;i<8;i++) {
// logln("bits: %02X", (unsigned int)bits[i]);
// }
UnicodeString expect = "-9223372036854775808";
UnicodeString result;
FieldPosition pos;
df.format(long_number, result, pos);
if(U_FAILURE(status)||expect!=result) {
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775808");
} else {
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775808");
}
}
}
{
UErrorCode status=U_ZERO_ERROR;
DecimalFormat df(UnicodeString("0000000000000000000",""),status);
int64_t long_number = U_INT64_MAX; // -9223372036854775808L;
// uint8_t bits[8];
// memcpy(bits,&long_number,8);
// for(int i=0;i<8;i++) {
// logln("bits: %02X", (unsigned int)bits[i]);
// }
UnicodeString expect = "9223372036854775807";
UnicodeString result;
FieldPosition pos;
df.format(long_number, result, pos);
if(U_FAILURE(status)||expect!=result) {
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on U_INT64_MAX");
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
} else {
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on U_INT64_MAX");
int64_t long_number = U_INT64_MAX; // -9223372036854775808L;
// uint8_t bits[8];
// memcpy(bits,&long_number,8);
// for(int i=0;i<8;i++) {
// logln("bits: %02X", (unsigned int)bits[i]);
// }
UnicodeString expect = "9223372036854775807";
UnicodeString result;
FieldPosition pos;
df.format(long_number, result, pos);
if(U_FAILURE(status)||expect!=result) {
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on U_INT64_MAX");
} else {
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on U_INT64_MAX");
}
}
}
{
UErrorCode status=U_ZERO_ERROR;
DecimalFormat df(UnicodeString("0000000000000000000",""),status);
int64_t long_number = 0;
// uint8_t bits[8];
// memcpy(bits,&long_number,8);
// for(int i=0;i<8;i++) {
// logln("bits: %02X", (unsigned int)bits[i]);
// }
UnicodeString expect = "0000000000000000000";
UnicodeString result;
FieldPosition pos;
df.format(long_number, result, pos);
if(U_FAILURE(status)||expect!=result) {
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on 0");
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
} else {
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on 0");
int64_t long_number = 0;
// uint8_t bits[8];
// memcpy(bits,&long_number,8);
// for(int i=0;i<8;i++) {
// logln("bits: %02X", (unsigned int)bits[i]);
// }
UnicodeString expect = "0000000000000000000";
UnicodeString result;
FieldPosition pos;
df.format(long_number, result, pos);
if(U_FAILURE(status)||expect!=result) {
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on 0");
} else {
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on 0");
}
}
}
{
UErrorCode status=U_ZERO_ERROR;
DecimalFormat df(UnicodeString("0000000000000000000",""),status);
int64_t long_number = U_INT64_MIN + 1;
UnicodeString expect = "-9223372036854775807";
UnicodeString result;
FieldPosition pos;
df.format(long_number, result, pos);
if(U_FAILURE(status)||expect!=result) {
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775807");
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
} else {
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775807");
int64_t long_number = U_INT64_MIN + 1;
UnicodeString expect = "-9223372036854775807";
UnicodeString result;
FieldPosition pos;
df.format(long_number, result, pos);
if(U_FAILURE(status)||expect!=result) {
errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775807");
} else {
logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775807");
}
}
}
}
@ -8300,7 +8324,10 @@ void NumberFormatTest::TestGetAffixes() {
UnicodeString pattern("\\u00a4\\u00a4\\u00a4 0.00 %\\u00a4\\u00a4");
pattern = pattern.unescape();
DecimalFormat fmt(pattern, sym, status);
assertSuccess("", status);
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
return;
}
UnicodeString affixStr;
assertEquals("", "US dollars ", fmt.getPositivePrefix(affixStr));
assertEquals("", " %USD", fmt.getPositiveSuffix(affixStr));
@ -8354,6 +8381,10 @@ void NumberFormatTest::TestToPatternScientific11648() {
Locale en("en");
DecimalFormatSymbols sym(en, status);
DecimalFormat fmt("0.00", sym, status);
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
return;
}
fmt.setScientificNotation(TRUE);
UnicodeString pattern;
assertEquals("", "0.00E0", fmt.toPattern(pattern));
@ -8416,6 +8447,10 @@ void NumberFormatTest::TestBenchmark() {
void NumberFormatTest::TestFractionalDigitsForCurrency() {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<NumberFormat> fmt(NumberFormat::createCurrencyInstance("en", status));
if (U_FAILURE(status)) {
dataerrln("Error creating NumberFormat - %s", u_errorName(status));
return;
}
UChar JPY[] = {0x4A, 0x50, 0x59, 0x0};
fmt->setCurrency(JPY, status);
if (!assertSuccess("", status)) {
@ -8429,6 +8464,10 @@ void NumberFormatTest::TestFormatCurrencyPlural() {
UErrorCode status = U_ZERO_ERROR;
Locale locale = Locale::createCanonical("en_US");
NumberFormat *fmt = NumberFormat::createInstance(locale, UNUM_CURRENCY_PLURAL, status);
if (U_FAILURE(status)) {
dataerrln("Error creating NumberFormat - %s", u_errorName(status));
return;
}
UnicodeString formattedNum;
fmt->format(11234.567, formattedNum, NULL, status);
assertEquals("", "11,234.57 US dollars", formattedNum);
@ -8440,6 +8479,10 @@ void NumberFormatTest::TestCtorApplyPatternDifference() {
DecimalFormatSymbols sym("en_US", status);
UnicodeString pattern("\\u00a40");
DecimalFormat fmt(pattern.unescape(), sym, status);
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
return;
}
UnicodeString result;
assertEquals(
"ctor favors precision of currency",

View File

@ -346,7 +346,10 @@ void NumberFormatRegressionTest::Test4087535 (void)
{
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = new DecimalFormat(status);
failure(status, "new DecimalFormat", "");
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
return;
}
df->setMinimumIntegerDigits(0);
double n = 0;
@ -371,7 +374,10 @@ void NumberFormatRegressionTest::Test4088503 (void)
{
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = new DecimalFormat(status);
failure(status, "new DecimalFormat", "");
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
return;
}
df->setGroupingSize(0);
UnicodeString sBuf;
FieldPosition fp(FieldPosition::DONT_CARE);
@ -1344,7 +1350,10 @@ void NumberFormatRegressionTest::Test4061302(void)
{
UErrorCode status = U_ZERO_ERROR;
DecimalFormatSymbols *fmt = new DecimalFormatSymbols(status);
failure(status, "new DecimalFormatSymbols");
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormatSymbols - %s", u_errorName(status));
return;
}
UnicodeString currency(fmt->getSymbol(DecimalFormatSymbols::kCurrencySymbol));
UnicodeString intlCurrency(fmt->getSymbol(DecimalFormatSymbols::kIntlCurrencySymbol));
UnicodeString monDecSeparator(fmt->getSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol));
@ -1382,7 +1391,10 @@ void NumberFormatRegressionTest::Test4062486(void)
{
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *fmt = new DecimalFormat(UnicodeString("#,##0.00"), status);
failure(status, "new DecimalFormat");
if (U_FAILURE(status)) {
dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
return;
}
UnicodeString formatted;
FieldPosition field(0);
double num = 1234.5;
@ -2849,12 +2861,12 @@ void NumberFormatRegressionTest::Test9109(void) {
Formattable val;
ParsePosition pos;
DecimalFormat fmt("+##", status);
fmt.setLenient(TRUE);
if (U_FAILURE(status)) {
dataerrln("Failed to create DecimalFormat with pattern '+##' - %s", u_errorName(status));
return;
}
fmt.setLenient(TRUE);
UnicodeString text("123");
int32_t expected = 123;
int32_t expos = 3;

View File

@ -99,7 +99,7 @@ void UnifiedCacheTest::TestEvictionUnderStress() {
}
int64_t evictedCountAfter = cache->autoEvictedCount();
if (evictedCountBefore == evictedCountAfter) {
errln("%s:%d Items should have been evicted from cache",
dataerrln("%s:%d Items should have been evicted from cache",
__FILE__, __LINE__);
}
}

View File

@ -3889,7 +3889,7 @@ void UnicodeSetTest::TestUCAUnsafeBackwards() {
// Get the unsafeBackwardsSet
const CollationCacheEntry *rootEntry = CollationRoot::getRootCacheEntry(errorCode);
if(U_FAILURE(errorCode)) {
errln("FAIL: %s getting root cache entry", u_errorName(errorCode));
dataerrln("FAIL: %s getting root cache entry", u_errorName(errorCode));
return;
}
//const UVersionInfo &version = rootEntry->tailoring->version;