ICU-7784 Fix tests that run incorrectly without data.

X-SVN-Rev: 28369
This commit is contained in:
Michael Ow 2010-07-26 22:02:42 +00:00
parent 4824f9c355
commit 2f72159ffb
5 changed files with 95 additions and 75 deletions

View file

@ -6065,13 +6065,17 @@ void NumberFormatTest::TestDecimal() {
UErrorCode status = U_ZERO_ERROR;
NumberFormat *fmtr = NumberFormat::createInstance(
Locale::getUS(), NumberFormat::kNumberStyle, status);
UnicodeString formattedResult;
StringPiece num("244444444444444444444444444444444444446.4");
fmtr->format(num, formattedResult, NULL, status);
ASSERT_SUCCESS(status);
ASSERT_EQUALS("244,444,444,444,444,444,444,444,444,444,444,444,446.4", formattedResult);
//std::string ss; std::cout << formattedResult.toUTF8String(ss);
delete fmtr;
if (U_FAILURE(status) || fmtr == NULL) {
dataerrln("Unable to create NumberFormat");
} else {
UnicodeString formattedResult;
StringPiece num("244444444444444444444444444444444444446.4");
fmtr->format(num, formattedResult, NULL, status);
ASSERT_SUCCESS(status);
ASSERT_EQUALS("244,444,444,444,444,444,444,444,444,444,444,444,446.4", formattedResult);
//std::string ss; std::cout << formattedResult.toUTF8String(ss);
delete fmtr;
}
}
{
@ -6080,28 +6084,31 @@ void NumberFormatTest::TestDecimal() {
UErrorCode status = U_ZERO_ERROR;
NumberFormat *fmtr = NumberFormat::createInstance(
Locale::getUS(), NumberFormat::kNumberStyle, status);
ASSERT_SUCCESS(status);
UnicodeString formattedResult;
DigitList dl;
StringPiece num("123.4566666666666666666666666666666666621E+40");
dl.set(num, status);
ASSERT_SUCCESS(status);
fmtr->format(dl, formattedResult, NULL, status);
ASSERT_SUCCESS(status);
ASSERT_EQUALS("1,234,566,666,666,666,666,666,666,666,666,666,666,621,000", formattedResult);
if (U_FAILURE(status) || fmtr == NULL) {
dataerrln("Unable to create NumberFormat");
} else {
UnicodeString formattedResult;
DigitList dl;
StringPiece num("123.4566666666666666666666666666666666621E+40");
dl.set(num, status);
ASSERT_SUCCESS(status);
fmtr->format(dl, formattedResult, NULL, status);
ASSERT_SUCCESS(status);
ASSERT_EQUALS("1,234,566,666,666,666,666,666,666,666,666,666,666,621,000", formattedResult);
status = U_ZERO_ERROR;
num.set("666.666");
dl.set(num, status);
FieldPosition pos(NumberFormat::FRACTION_FIELD);
ASSERT_SUCCESS(status);
formattedResult.remove();
fmtr->format(dl, formattedResult, pos, status);
ASSERT_SUCCESS(status);
ASSERT_EQUALS("666.666", formattedResult);
ASSERT_EQUALS(4, pos.getBeginIndex());
ASSERT_EQUALS(7, pos.getEndIndex());
delete fmtr;
status = U_ZERO_ERROR;
num.set("666.666");
dl.set(num, status);
FieldPosition pos(NumberFormat::FRACTION_FIELD);
ASSERT_SUCCESS(status);
formattedResult.remove();
fmtr->format(dl, formattedResult, pos, status);
ASSERT_SUCCESS(status);
ASSERT_EQUALS("666.666", formattedResult);
ASSERT_EQUALS(4, pos.getBeginIndex());
ASSERT_EQUALS(7, pos.getEndIndex());
delete fmtr;
}
}
{
@ -6109,14 +6116,17 @@ void NumberFormatTest::TestDecimal() {
UErrorCode status = U_ZERO_ERROR;
NumberFormat *fmtr = NumberFormat::createInstance(
Locale::getUS(), NumberFormat::kPercentStyle, status);
ASSERT_SUCCESS(status);
UnicodeString input = "1.84%";
Formattable result;
fmtr->parse(input, result, status);
ASSERT_SUCCESS(status);
ASSERT_EQUALS(0, strcmp("0.0184", result.getDecimalNumber(status).data()));
//std::cout << result.getDecimalNumber(status).data();
delete fmtr;
if (U_FAILURE(status) || fmtr == NULL) {
dataerrln("Unable to create NumberFormat");
} else {
UnicodeString input = "1.84%";
Formattable result;
fmtr->parse(input, result, status);
ASSERT_SUCCESS(status);
ASSERT_EQUALS(0, strcmp("0.0184", result.getDecimalNumber(status).data()));
//std::cout << result.getDecimalNumber(status).data();
delete fmtr;
}
}
{
@ -6124,15 +6134,18 @@ void NumberFormatTest::TestDecimal() {
UErrorCode status = U_ZERO_ERROR;
NumberFormat *fmtr = NumberFormat::createInstance(
Locale::getUS(), NumberFormat::kNumberStyle, status);
ASSERT_SUCCESS(status);
UnicodeString input = "1.002200044400088880000070000";
Formattable result;
fmtr->parse(input, result, status);
ASSERT_SUCCESS(status);
ASSERT_EQUALS(0, strcmp("1.00220004440008888000007", result.getDecimalNumber(status).data()));
ASSERT_EQUALS(1.00220004440008888, result.getDouble());
//std::cout << result.getDecimalNumber(status).data();
delete fmtr;
if (U_FAILURE(status) || fmtr == NULL) {
dataerrln("Unable to create NumberFormat");
} else {
UnicodeString input = "1.002200044400088880000070000";
Formattable result;
fmtr->parse(input, result, status);
ASSERT_SUCCESS(status);
ASSERT_EQUALS(0, strcmp("1.00220004440008888000007", result.getDecimalNumber(status).data()));
ASSERT_EQUALS(1.00220004440008888, result.getDouble());
//std::cout << result.getDecimalNumber(status).data();
delete fmtr;
}
}
}
@ -6144,19 +6157,22 @@ void NumberFormatTest::TestCurrencyFractionDigits() {
// Create currenct instance
NumberFormat* fmt = NumberFormat::createCurrencyInstance("ja_JP", status);
ASSERT_SUCCESS(status);
fmt->format(value, text1);
if (U_FAILURE(status) || fmt == NULL) {
dataerrln("Unable to create NumberFormat");
} else {
fmt->format(value, text1);
// Reset the same currency and format the test value again
fmt->setCurrency(fmt->getCurrency(), status);
ASSERT_SUCCESS(status);
fmt->format(value, text2);
// Reset the same currency and format the test value again
fmt->setCurrency(fmt->getCurrency(), status);
ASSERT_SUCCESS(status);
fmt->format(value, text2);
if (text1 != text2) {
errln((UnicodeString)"NumberFormat::format() should return the same result - text1="
+ text1 + " text2=" + text2);
if (text1 != text2) {
errln((UnicodeString)"NumberFormat::format() should return the same result - text1="
+ text1 + " text2=" + text2);
}
delete fmt;
}
delete fmt;
}
void NumberFormatTest::TestExponentParse() {
@ -6169,7 +6185,7 @@ void NumberFormatTest::TestExponentParse() {
status = U_ZERO_ERROR;
DecimalFormatSymbols *symbols = new DecimalFormatSymbols(Locale::getDefault(), status);
if(U_FAILURE(status)) {
errln((UnicodeString)"ERROR: Could not create DecimalFormatSymbols (Default)");
dataerrln((UnicodeString)"ERROR: Could not create DecimalFormatSymbols (Default)");
return;
}
symbols->setSymbol(DecimalFormatSymbols::kExponentialSymbol,"e");

View file

@ -101,11 +101,14 @@ void PluralFormatTest::pluralFormatBasicTest(/*char *par*/)
else {
dataerrln("ERROR: PluralFormat constructor failed! - [0]%s [1]%s", u_errorName(status[0]), u_errorName(status[1]));
}
plFmt[2]= new PluralFormat(locale, status[2]);
if ( U_SUCCESS(status[2]) ) {
*plFmt[1] = *plFmt[2];
delete plFmt[0];
status[0] = U_ZERO_ERROR;
plFmt[0]= new PluralFormat(locale, status[0]);
if ( U_SUCCESS(status[0]) ) {
*plFmt[1] = *plFmt[0];
if (plFmt[1]!=NULL) {
if ( *plFmt[1] != *plFmt[2] ) {
if ( *plFmt[1] != *plFmt[0] ) {
errln("ERROR: assignment operator test failed!");
}
}
@ -115,22 +118,21 @@ void PluralFormatTest::pluralFormatBasicTest(/*char *par*/)
}
if ( U_SUCCESS(status[1]) ) {
plFmt[3] = (PluralFormat*) plFmt[1]->clone();
plFmt[2] = (PluralFormat*) plFmt[1]->clone();
if (plFmt[1]!=NULL) {
if ( *plFmt[1] != *plFmt[3] ) {
if ( *plFmt[1] != *plFmt[2] ) {
errln("ERROR: clone function test failed!");
}
}
delete plFmt[1];
delete plFmt[3];
delete plFmt[2];
}
else {
dataerrln("ERROR: PluralFormat clone failed! - %s", u_errorName(status[1]));
}
delete plFmt[0];
delete plFmt[2];
delete numFmt;
delete plRules;

View file

@ -4726,17 +4726,19 @@ void RBBITest::TestBug5532(void) {
BreakIterator *bi = BreakIterator::createWordInstance(Locale("th"), status);
TEST_ASSERT_SUCCESS(status);
bi->setText(&utext, status);
TEST_ASSERT_SUCCESS(status);
if (U_SUCCESS(status)) {
bi->setText(&utext, status);
TEST_ASSERT_SUCCESS(status);
int32_t breakCount = 0;
int32_t previousBreak = -1;
for (bi->first(); bi->next() != BreakIterator::DONE; breakCount++) {
// For now, just make sure that the break iterator doesn't hang.
TEST_ASSERT(previousBreak < bi->current());
previousBreak = bi->current();
int32_t breakCount = 0;
int32_t previousBreak = -1;
for (bi->first(); bi->next() != BreakIterator::DONE; breakCount++) {
// For now, just make sure that the break iterator doesn't hang.
TEST_ASSERT(previousBreak < bi->current());
previousBreak = bi->current();
}
TEST_ASSERT(breakCount > 0);
}
TEST_ASSERT(breakCount > 0);
delete bi;
utext_close(&utext);
}

View file

@ -1779,7 +1779,7 @@ TimeZoneRuleTest::TestVTimeZoneCoverage(void) {
}
vtzFromBasic = VTimeZone::createVTimeZoneFromBasicTimeZone(*simpleTZ, status);
if (U_FAILURE(status) || vtzFromBasic == NULL) {
errln("File %s, line %d, failed with status = %s", __FILE__, __LINE__, u_errorName(status));
dataerrln("File %s, line %d, failed with status = %s", __FILE__, __LINE__, u_errorName(status));
goto end_basic_tz_test;
}

View file

@ -216,7 +216,7 @@ RBTestDataModule::getTestBundle(const char* bundleName, UErrorCode &status)
if (testBundle == NULL) {
testBundle = ures_openDirect(icu_data, bundleName, &status);
if (status != U_ZERO_ERROR) {
fLog.dataerrln(UNICODE_STRING_SIMPLE("Could not load test data from resourcebundle: ") + UnicodeString(bundleName, -1, US_INV) + "\n");
fLog.dataerrln(UNICODE_STRING_SIMPLE("Could not load test data from resourcebundle: ") + UnicodeString(bundleName, -1, US_INV));
fDataTestValid = FALSE;
}
}