diff --git a/icu4c/source/test/intltest/Makefile.in b/icu4c/source/test/intltest/Makefile.in index 586a5549905..8e8214a6e64 100644 --- a/icu4c/source/test/intltest/Makefile.in +++ b/icu4c/source/test/intltest/Makefile.in @@ -37,7 +37,8 @@ dadrcoll.o dcfmapts.o decoll.o dtfmapts.o dtfmrgts.o dtfmtrtts.o dtfmttst.o \ encoll.o escoll.o ficoll.o frcoll.o g7coll.o intltest.o \ itercoll.o itformat.o itmajor.o itutil.o jacoll.o lcukocol.o \ loctest.o miscdtfm.o mnkytst.o msfmrgts.o nmfmapts.o nmfmtrt.o \ -numfmtst.o numrgts.o pptest.o regcoll.o restest.o restsnew.o sdtfmtts.o svccoll.o tchcfmt.o \ +numfmtst.o numrgts.o pptest.o regcoll.o restest.o restsnew.o rndmcoll.o \ +sdtfmtts.o svccoll.o tchcfmt.o \ tfsmalls.o tmsgfmt.o trcoll.o tscoll.o tsdate.o tsdcfmsy.o tsdtfmsy.o \ tsmthred.o tsnmfmt.o tsputil.o tstnrapi.o tstnorm.o tzbdtest.o \ tzregts.o tztest.o ucdtest.o usettest.o ustrtest.o strcase.o transtst.o strtest.o thcoll.o \ diff --git a/icu4c/source/test/intltest/calcasts.cpp b/icu4c/source/test/intltest/calcasts.cpp index ff99fa0a79d..17b9caea71a 100644 --- a/icu4c/source/test/intltest/calcasts.cpp +++ b/icu4c/source/test/intltest/calcasts.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2003-2004, International Business Machines Corporation + * Copyright (c) 2003-2005, International Business Machines Corporation * and others. All Rights Reserved. ******************************************************************** * Calendar Case Test is a type of CalendarTest which compares the @@ -168,6 +168,13 @@ void CalendarCaseTest::IslamicCivil() }; UnicodeString result; DateFormat *fmt = DateFormat::createDateInstance(DateFormat::kFull, Locale("ar_JO@calendar=islamic-civil")); + if (fmt == NULL) { + dataerrln("Error calling DateFormat::createDateInstance"); + delete c; + delete fmt; + return; + } + fmt->setTimeZone(*TimeZone::getGMT()); fmt->format((UDate)2486076.5, result); if (result != expectedUChars) { diff --git a/icu4c/source/test/intltest/dtfmapts.cpp b/icu4c/source/test/intltest/dtfmapts.cpp index 3c8fd4a6cab..db443f1e446 100644 --- a/icu4c/source/test/intltest/dtfmapts.cpp +++ b/icu4c/source/test/intltest/dtfmapts.cpp @@ -1,6 +1,6 @@ /*********************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2004, International Business Machines Corporation + * Copyright (c) 1997-2005, International Business Machines Corporation * and others. All Rights Reserved. ***********************************************************************/ @@ -69,6 +69,13 @@ void IntlTestDateFormatAPI::TestEquals(void) while (Calendar::getNow() == start) ; // Wait for time to change DateFormat *b = DateFormat::createInstance(); + if (a == NULL || b == NULL){ + dataerrln("Error calling DateFormat::createInstance()"); + delete a; + delete b; + return; + } + if (!(*a == *b)) errln("FAIL: DateFormat objects created at different times are unequal."); @@ -102,16 +109,23 @@ void IntlTestDateFormatAPI::testAPI(/* char* par */) DateFormat *it = DateFormat::createDateInstance(DateFormat::MEDIUM, Locale::getItalian()); DateFormat *de = DateFormat::createDateTimeInstance(DateFormat::LONG, DateFormat::LONG, Locale::getGerman()); -// ======= Test equality + if (def == NULL || fr == NULL || it == NULL || de == NULL){ + dataerrln("Error creating instnaces."); + } +// ======= Test equality +if (fr != NULL && def != NULL) +{ logln("Testing equality operator"); if( *fr == *it ) { errln("ERROR: == failed"); } +} // ======= Test various format() methods - +if (fr != NULL && it != NULL && de != NULL) +{ logln("Testing various format() methods"); UDate d = 837039928046.0; @@ -132,9 +146,11 @@ void IntlTestDateFormatAPI::testAPI(/* char* par */) res3 = de->format(d, res3); logln( (UnicodeString) "" + d + " formatted to " + res3); +} // ======= Test parse() - +if (def != NULL) +{ logln("Testing parse()"); UnicodeString text("02/03/76 2:50 AM, CST"); @@ -157,10 +173,11 @@ void IntlTestDateFormatAPI::testAPI(/* char* par */) result3 = def->parse(text, pos01); logln(text + " parsed into " + result3); - +} // ======= Test getters and setters - +if (fr != NULL && it != NULL && de != NULL) +{ logln("Testing getters and setters"); int32_t count = 0; @@ -200,7 +217,7 @@ void IntlTestDateFormatAPI::testAPI(/* char* par */) if( de->getTimeZone() != it->getTimeZone()) { errln("ERROR: adopt or set TimeZone() failed"); } - +} // ======= Test getStaticClassID() logln("Testing getStaticClassID()"); diff --git a/icu4c/source/test/intltest/dtfmrgts.cpp b/icu4c/source/test/intltest/dtfmrgts.cpp index 6e007bcbd28..7eae05692d6 100644 --- a/icu4c/source/test/intltest/dtfmrgts.cpp +++ b/icu4c/source/test/intltest/dtfmrgts.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2004, International Business Machines Corporation and + * Copyright (c) 1997-2005, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -69,8 +69,15 @@ void DateFormatRegressionTest::Test4029195(void) logln((UnicodeString) "today: " + today); SimpleDateFormat *sdf = (SimpleDateFormat*) DateFormat::createDateInstance(); - failure(status, "SimpleDateFormat::createDateInstance"); + if (failure(status, "SimpleDateFormat::createDateInstance")) { + return; + } UnicodeString pat; + if(sdf == NULL){ + dataerrln("Error calling DateFormat::createDateTimeInstance"); + return; + } + pat = sdf->toPattern(pat); logln("pattern: " + pat); UnicodeString fmtd; @@ -114,6 +121,11 @@ void DateFormatRegressionTest::Test4052408(void) DateFormat *fmt = DateFormat::createDateTimeInstance(DateFormat::SHORT, DateFormat::SHORT, Locale::getUS()); + if (fmt == NULL) { + dataerrln("Error calling DateFormat::createDateTimeInstance"); + return; + } + UDate dt = date(97, UCAL_MAY, 3, 8, 55); UnicodeString str; str = fmt->format(dt, str); @@ -329,6 +341,12 @@ void DateFormatRegressionTest::Test4060212(void) UnicodeString myString; DateFormat *fmt = DateFormat::createDateTimeInstance( DateFormat::FULL, DateFormat::LONG); + if (fmt == NULL) { + dataerrln("Error calling DateFormat::createDateTimeInstance"); + delete formatter; + return; + } + myString = fmt->format( myDate, myString); logln( myString ); @@ -417,7 +435,16 @@ void DateFormatRegressionTest::Test4065240(void) TimeZone::adoptDefault(TimeZone::createTimeZone("EST")); curDate = date(98, 0, 1); shortdate = DateFormat::createDateInstance(DateFormat::SHORT); + if (shortdate == NULL){ + dataerrln("Error calling DateFormat::createDateInstance"); + return; + } + fulldate = DateFormat::createDateTimeInstance(DateFormat::LONG, DateFormat::LONG); + if (fulldate == NULL){ + dataerrln("Error calling DateFormat::createDateTimeInstance"); + return; + } strShortDate = "The current date (short form) is "; UnicodeString temp; temp = shortdate->format(curDate, temp); @@ -454,7 +481,6 @@ void DateFormatRegressionTest::Test4065240(void) failure(status, "Locale::setDefault"); TimeZone::setDefault(*saveZone); //} - delete shortdate; delete fulldate; delete saveZone; @@ -478,7 +504,14 @@ void DateFormatRegressionTest::Test4071441(void) { DateFormat *fmtA = DateFormat::createInstance(); DateFormat *fmtB = DateFormat::createInstance(); - + + if (fmtA == NULL || fmtB == NULL){ + dataerrln("Error calling DateFormat::createInstance"); + delete fmtA; + delete fmtB; + return; + } + // {sfb} Is it OK to cast away const here? Calendar *calA = (Calendar*) fmtA->getCalendar(); Calendar *calB = (Calendar*) fmtB->getCalendar(); @@ -1197,6 +1230,11 @@ void DateFormatRegressionTest::Test714(void) DateFormat *fmt = DateFormat::createDateTimeInstance(DateFormat::NONE, DateFormat::MEDIUM, Locale::getUS()); + if (fmt == NULL) { + dataerrln("Error calling DateFormat::createDateTimeInstance"); + return; + } + UnicodeString s; UnicodeString tests = (UnicodeString) "7:25:43 AM" ; @@ -1284,6 +1322,15 @@ void DateFormatRegressionTest::Test1684(void) UnicodeString pattern("yyyy MM WW EEE",""); Calendar *cal = new GregorianCalendar(status); SimpleDateFormat *sdf = new SimpleDateFormat(pattern,status); + if (U_FAILURE(status)) { + dataerrln("Error constructing SimpleDateFormat"); + for(i=0;isetFirstDayOfWeek(UCAL_SUNDAY); cal->setMinimalDaysInFirstWeek(1); @@ -1368,7 +1415,7 @@ void DateFormatRegressionTest::Test1684(void) } else { logln(info); } - + for(i=0;itoPattern(pattern)); UDate june = date(97, UCAL_JUNE, 15); @@ -589,6 +601,10 @@ DateFormatTest::TestDayOfYearPattern195() UDate expected = date(year, month, day); logln((UnicodeString)"Test Date: " + dateToString(today)); SimpleDateFormat* sdf = (SimpleDateFormat*)DateFormat::createDateInstance(); + if (sdf == NULL){ + dataerrln("Error calling DateFormat::createDateInstance()"); + return; + } tryPattern(*sdf, today, 0, expected); tryPattern(*sdf, today, "G yyyy DDD", expected); delete sdf; @@ -665,6 +681,10 @@ DateFormatTest::TestBadInput135() for (int32_t k = 0; k < looks_length;++k) { DateFormat::EStyle timeLook = looks[k]; DateFormat *df = DateFormat::createDateTimeInstance(dateLook, timeLook); + if (df == NULL){ + dataerrln("Error calling DateFormat::createDateTimeInstance()"); + continue; + } UnicodeString prefix = UnicodeString(text) + ", " + dateLook + "/" + timeLook + ": "; //try { UDate when = df->parse(text, status); @@ -968,6 +988,13 @@ DateFormatTest::TestLocaleDateFormat() // Bug 495 UnicodeString expectedUS ( "Monday, September 15, 1997 12:00:00 AM PDT" ); logln((UnicodeString)"Date set to : " + dateToString(testDate)); UnicodeString out; + if (dfUS == NULL || dfFrench == NULL){ + dataerrln("Error calling DateFormat::createDateTimeInstance)"); + delete dfUS; + delete dfFrench; + return; + } + dfFrench->format(testDate, out); logln((UnicodeString)"Date Formated with French Locale " + out); if (!(out == expectedFRENCH)) diff --git a/icu4c/source/test/intltest/incaltst.cpp b/icu4c/source/test/intltest/incaltst.cpp index f286b456b18..339f3178128 100644 --- a/icu4c/source/test/intltest/incaltst.cpp +++ b/icu4c/source/test/intltest/incaltst.cpp @@ -143,6 +143,10 @@ void IntlCalendarTest::quasiGregorianTest(Calendar& cal, const Locale& gcl, cons // due to the JDK 1.4 incorporation of historical time zones. //java.util.Calendar grego = java.util.Calendar.getInstance(); Calendar *grego = Calendar::createInstance(gcl, status); + if (U_FAILURE(status)) { + dataerrln("Error calling Calendar::createInstance"); + return; + } int32_t tz1 = cal.get(UCAL_ZONE_OFFSET,status); int32_t tz2 = grego -> get (UCAL_ZONE_OFFSET, status); diff --git a/icu4c/source/test/intltest/intltest.cpp b/icu4c/source/test/intltest/intltest.cpp index a7a872f9700..13639e29682 100644 --- a/icu4c/source/test/intltest/intltest.cpp +++ b/icu4c/source/test/intltest/intltest.cpp @@ -480,6 +480,17 @@ void it_errln( UnicodeString message ) IntlTest::gTest->errln( message ); } +void it_dataerr( UnicodeString message ) +{ + if (IntlTest::gTest) + IntlTest::gTest->dataerr( message ); +} + +void it_dataerrln( UnicodeString message ) +{ + if (IntlTest::gTest) + IntlTest::gTest->dataerrln( message ); +} IntlTest::IntlTest() { @@ -898,6 +909,7 @@ void IntlTest::LL_message( UnicodeString message, UBool newline ) // stream out the message length = message.extract(0, message.length(), buffer, sizeof(buffer)); if (length > 0) { + length = length > 10000 ? 10000 : length; fwrite(buffer, sizeof(*buffer), length, (FILE *)testoutfp); } diff --git a/icu4c/source/test/intltest/intltest.h b/icu4c/source/test/intltest/intltest.h index 6c0e1278d63..c460af2f8e0 100644 --- a/icu4c/source/test/intltest/intltest.h +++ b/icu4c/source/test/intltest/intltest.h @@ -234,6 +234,8 @@ void it_infoln( void ); void it_err(void); void it_err( UnicodeString message ); void it_errln( UnicodeString message ); +void it_dataerr( UnicodeString message ); +void it_dataerrln( UnicodeString message ); /** * This is a variant of cintltst/ccolltst.c:CharsToUChars(). diff --git a/icu4c/source/test/intltest/loctest.cpp b/icu4c/source/test/intltest/loctest.cpp index 89121a88987..c18ea0a3f25 100644 --- a/icu4c/source/test/intltest/loctest.cpp +++ b/icu4c/source/test/intltest/loctest.cpp @@ -1815,11 +1815,11 @@ void LocaleTest::TestGetLocale(void) { #if !UCONFIG_NO_FORMATTING req = "fr_FR_NICE"; DecimalFormat* dec = (DecimalFormat*) - NumberFormat::createInstance(Locale::createFromName(req), ec); - U_ASSERT(dec->getDynamicClassID() == DecimalFormat::getStaticClassID()); + NumberFormat::createInstance(Locale::createFromName(req), ec); if (U_FAILURE(ec)) { errln("FAIL: NumberFormat::createInstance failed"); } else { + U_ASSERT(dec->getDynamicClassID() == DecimalFormat::getStaticClassID()); valid = dec->getLocale(ULOC_VALID_LOCALE, ec); actual = dec->getLocale(ULOC_ACTUAL_LOCALE, ec); if (U_FAILURE(ec)) { @@ -1847,25 +1847,28 @@ void LocaleTest::TestGetLocale(void) { SimpleDateFormat* dat = (SimpleDateFormat*) DateFormat::createDateInstance(DateFormat::kDefault, Locale::createFromName(req)); - U_ASSERT(dat != 0); - U_ASSERT(dat->getDynamicClassID() == SimpleDateFormat::getStaticClassID()); - valid = dat->getLocale(ULOC_VALID_LOCALE, ec); - actual = dat->getLocale(ULOC_ACTUAL_LOCALE, ec); - if (U_FAILURE(ec)) { - errln("FAIL: SimpleDateFormat::getLocale() failed"); + if (dat == 0){ + dataerrln("Error calling DateFormat::createDateInstance()"); } else { - _checklocs("SimpleDateFormat", req, valid, actual); - } + U_ASSERT(dat->getDynamicClassID() == SimpleDateFormat::getStaticClassID()); + valid = dat->getLocale(ULOC_VALID_LOCALE, ec); + actual = dat->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: SimpleDateFormat::getLocale() failed"); + } else { + _checklocs("SimpleDateFormat", req, valid, actual); + } - const DateFormatSymbols* sym = dat->getDateFormatSymbols(); - U_ASSERT(sym != 0); - valid = sym->getLocale(ULOC_VALID_LOCALE, ec); - actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec); - if (U_FAILURE(ec)) { - errln("FAIL: DateFormatSymbols::getLocale() failed"); - } else { - _checklocs("DateFormatSymbols", req, valid, actual); - } + const DateFormatSymbols* sym = dat->getDateFormatSymbols(); + U_ASSERT(sym != 0); + valid = sym->getLocale(ULOC_VALID_LOCALE, ec); + actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: DateFormatSymbols::getLocale() failed"); + } else { + _checklocs("DateFormatSymbols", req, valid, actual); + } + } delete dat; #endif diff --git a/icu4c/source/test/intltest/msfmrgts.cpp b/icu4c/source/test/intltest/msfmrgts.cpp index 343d135a55f..97465a09be7 100644 --- a/icu4c/source/test/intltest/msfmrgts.cpp +++ b/icu4c/source/test/intltest/msfmrgts.cpp @@ -1,6 +1,6 @@ /*********************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2004, International Business Machines Corporation + * Copyright (c) 1997-2005, International Business Machines Corporation * and others. All Rights Reserved. ***********************************************************************/ @@ -757,8 +757,12 @@ void MessageFormatRegressionTest::Test4118594() pp.setIndex(0); Formattable *newobjs = mf->parse(result, pp, count1); // newobjs now equals {new Double(3.1)} - if (newobjs[0].getDouble() != 3.1) - errln( UnicodeString("newobjs[0] = ") + newobjs[0].getDouble()); + if (newobjs == NULL) { + dataerrln("Error calling MessageFormat::parse"); + } else { + if (newobjs[0].getDouble() != 3.1) + errln( UnicodeString("newobjs[0] = ") + newobjs[0].getDouble()); + } delete [] objs; delete [] newobjs; diff --git a/icu4c/source/test/intltest/nmfmapts.cpp b/icu4c/source/test/intltest/nmfmapts.cpp index e10998f2807..117b2ed3159 100644 --- a/icu4c/source/test/intltest/nmfmapts.cpp +++ b/icu4c/source/test/intltest/nmfmapts.cpp @@ -1,6 +1,6 @@ /*********************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2004, International Business Machines Corporation + * Copyright (c) 1997-2005, International Business Machines Corporation * and others. All Rights Reserved. ***********************************************************************/ @@ -100,15 +100,18 @@ void IntlTestNumberFormatAPI::testAPI(/* char* par */) } // ======= Test equality - +if (per_fr != NULL && cur_fr != NULL) +{ logln("Testing equality operator"); if( *per_fr == *cur_fr || ! ( *per_fr != *cur_fr) ) { errln("ERROR: == failed"); } +} // ======= Test various format() methods - +if (cur_fr != NULL) +{ logln("Testing various format() methods"); double d = -10456.0037; @@ -144,12 +147,14 @@ void IntlTestNumberFormatAPI::testAPI(/* char* par */) errln("ERROR: format(Formattable [long]) failed"); } logln((UnicodeString) "" + fL.getLong() + " formatted to " + res6); - +} // ======= Test parse() - +if (fr != NULL) +{ logln("Testing parse()"); + double d = -10456.0037; UnicodeString text("-10,456.0037"); Formattable result1, result2, result3; ParsePosition pos(0), pos01(0); @@ -174,10 +179,11 @@ void IntlTestNumberFormatAPI::testAPI(/* char* par */) errln("ERROR: Roundtrip failed (via parse()) for " + text); } logln(text + " parsed into " + (int32_t) result3.getDouble()); - +} // ======= Test getters and setters - +if (fr != NULL && def != NULL) +{ logln("Testing getters and setters"); int32_t count = 0; @@ -217,7 +223,7 @@ void IntlTestNumberFormatAPI::testAPI(/* char* par */) if(fr->getMinimumFractionDigits() != def->getMinimumFractionDigits() ) { errln("ERROR: setMinimumFractionDigits() failed"); } - +} // ======= Test getStaticClassID() @@ -315,60 +321,65 @@ IntlTestNumberFormatAPI::testRegistration() NumberFormat::unregister(key, status); // restore for other tests NumberFormat* f5 = NumberFormat::createCurrencyInstance(SRC_LOC, status); UNumberFormat* uf5 = unum_open(UNUM_CURRENCY, NULL, 0, SRC_LOC.getName(),NULL, &status); - - float n = 1234.567f; - UnicodeString res0, res1, res2, res3, res4, res5; - UChar ures3[50]; - UChar ures4[50]; - UChar ures5[50]; - - f0->format(n, res0); - f1->format(n, res1); - f2->format(n, res2); - f3->format(n, res3); - f4->format(n, res4); - f5->format(n, res5); - unum_formatDouble(uf3, n, ures3, 50, NULL, &status); - unum_formatDouble(uf4, n, ures4, 50, NULL, &status); - unum_formatDouble(uf5, n, ures5, 50, NULL, &status); - - logln((UnicodeString)"f0 swap int: " + res0); - logln((UnicodeString)"f1 src int: " + res1); - logln((UnicodeString)"f2 src cur: " + res2); - logln((UnicodeString)"f3 reg cur: " + res3); - logln((UnicodeString)"f4 reg int: " + res4); - logln((UnicodeString)"f5 unreg cur: " + res5); - log("uf3 reg cur: "); - logln(ures3); - log("uf4 reg int: "); - logln(ures4); - log("uf5 ureg cur: "); - logln(ures5); - - if (f3 == f3a) { - errln("did not get new instance from service"); + if (U_FAILURE(status)) { + dataerrln("Error creating instnaces."); + return; } else { - delete f3a; - } - if (res3 != res0) { - errln("registered service did not match"); - } - if (res4 != res1) { - errln("registered service did not inherit"); - } - if (res5 != res2) { - errln("unregistered service did not match original"); - } + float n = 1234.567f; + UnicodeString res0, res1, res2, res3, res4, res5; + UChar ures3[50]; + UChar ures4[50]; + UChar ures5[50]; - if (res0 != ures3) { - errln("registered service did not match / unum"); - } - if (res1 != ures4) { - errln("registered service did not inherit / unum"); - } - if (res2 != ures5) { - errln("unregistered service did not match original / unum"); + f0->format(n, res0); + f1->format(n, res1); + f2->format(n, res2); + f3->format(n, res3); + f4->format(n, res4); + f5->format(n, res5); + + unum_formatDouble(uf3, n, ures3, 50, NULL, &status); + unum_formatDouble(uf4, n, ures4, 50, NULL, &status); + unum_formatDouble(uf5, n, ures5, 50, NULL, &status); + + logln((UnicodeString)"f0 swap int: " + res0); + logln((UnicodeString)"f1 src int: " + res1); + logln((UnicodeString)"f2 src cur: " + res2); + logln((UnicodeString)"f3 reg cur: " + res3); + logln((UnicodeString)"f4 reg int: " + res4); + logln((UnicodeString)"f5 unreg cur: " + res5); + log("uf3 reg cur: "); + logln(ures3); + log("uf4 reg int: "); + logln(ures4); + log("uf5 ureg cur: "); + logln(ures5); + + if (f3 == f3a) { + errln("did not get new instance from service"); + } else { + delete f3a; + } + if (res3 != res0) { + errln("registered service did not match"); + } + if (res4 != res1) { + errln("registered service did not inherit"); + } + if (res5 != res2) { + errln("unregistered service did not match original"); + } + + if (res0 != ures3) { + errln("registered service did not match / unum"); + } + if (res1 != ures4) { + errln("registered service did not inherit / unum"); + } + if (res2 != ures5) { + errln("unregistered service did not match original / unum"); + } } unum_close(uf5); diff --git a/icu4c/source/test/intltest/nmfmtrt.cpp b/icu4c/source/test/intltest/nmfmtrt.cpp index 36bc7c446dc..77da5c6823f 100644 --- a/icu4c/source/test/intltest/nmfmtrt.cpp +++ b/icu4c/source/test/intltest/nmfmtrt.cpp @@ -1,6 +1,6 @@ /*********************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2004, International Business Machines Corporation + * Copyright (c) 1997-2005, International Business Machines Corporation * and others. All Rights Reserved. ***********************************************************************/ @@ -90,18 +90,21 @@ NumberFormatRoundTripTest::start() logln("Default Locale"); fmt = NumberFormat::createInstance(status); - failure(status, "NumberFormat::createInstance"); - test(fmt); + if (!failure(status, "NumberFormat::createInstance")){ + test(fmt); + } delete fmt; fmt = NumberFormat::createCurrencyInstance(status); - failure(status, "NumberFormat::createCurrencyInstance"); - test(fmt); + if (!failure(status, "NumberFormat::createCurrencyInstance")){ + test(fmt); + } delete fmt; fmt = NumberFormat::createPercentInstance(status); - failure(status, "NumberFormat::createPercentInstance"); - test(fmt); + if (!failure(status, "NumberFormat::createPercentInstance")){ + test(fmt); + } delete fmt; diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp index a9b5c97d5b7..c6650e4af0a 100644 --- a/icu4c/source/test/intltest/numfmtst.cpp +++ b/icu4c/source/test/intltest/numfmtst.cpp @@ -620,6 +620,11 @@ NumberFormatTest::TestCurrency(void) { UErrorCode status = U_ZERO_ERROR; NumberFormat* currencyFmt = NumberFormat::createCurrencyInstance(Locale::getCanadaFrench(), status); + if (U_FAILURE(status)) { + dataerrln("Error calling NumberFormat::createCurrencyInstance()"); + return; + } + UnicodeString s; currencyFmt->format(1.50, s); logln((UnicodeString)"Un pauvre ici a..........." + s); if (!(s=="1,50 $")) @@ -763,6 +768,11 @@ NumberFormatTest::TestRounding487(void) { UErrorCode status = U_ZERO_ERROR; NumberFormat *nf = NumberFormat::createInstance(status); + if (U_FAILURE(status)) { + dataerrln("Error calling NumberFormat::createInstance()"); + return; + } + roundingTest(*nf, 0.00159999, 4, "0.0016"); roundingTest(*nf, 0.00995, 4, "0.01"); @@ -1742,6 +1752,10 @@ void NumberFormatTest::TestCases() { delete ref; ref = new DecimalFormat(tok, new DecimalFormatSymbols(Locale::getUS(), ec), ec); + if (U_FAILURE(ec)) { + dataerrln("Error constructing DecimalFormat"); + goto error; + } break; case 1: // loc= diff --git a/icu4c/source/test/intltest/numrgts.cpp b/icu4c/source/test/intltest/numrgts.cpp index 0fff8a13cd1..b22a118dcf2 100644 --- a/icu4c/source/test/intltest/numrgts.cpp +++ b/icu4c/source/test/intltest/numrgts.cpp @@ -1,6 +1,6 @@ /*********************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2004, International Business Machines Corporation + * Copyright (c) 1997-2005, International Business Machines Corporation * and others. All Rights Reserved. ***********************************************************************/ @@ -380,7 +380,10 @@ NumberFormatRegressionTest::assignFloatValue(float returnfloat) logln(UnicodeString(" VALUE ") + returnfloat); UErrorCode status = U_ZERO_ERROR; NumberFormat *nfcommon = NumberFormat::createCurrencyInstance(Locale::getUS(), status); - failure(status, "NumberFormat::createCurrencyInstance", Locale::getUS()); + if (failure(status, "NumberFormat::createCurrencyInstance", Locale::getUS())){ + delete nfcommon; + return returnfloat; + } nfcommon->setGroupingUsed(FALSE); UnicodeString stringValue; @@ -451,7 +454,10 @@ void NumberFormatRegressionTest::Test4071492 (void) double x = 0.00159999; UErrorCode status = U_ZERO_ERROR; NumberFormat *nf = NumberFormat::createInstance(status); - failure(status, "NumberFormat::createInstance", Locale::getUS()); + if (failure(status, "NumberFormat::createInstance", Locale::getUS())) { + delete nf; + return; + } nf->setMaximumFractionDigits(4); UnicodeString out; FieldPosition pos(FieldPosition::DONT_CARE); @@ -956,7 +962,10 @@ void NumberFormatRegressionTest::Test4071005 (void) UErrorCode status = U_ZERO_ERROR; formatter = NumberFormat::createInstance(Locale::getCanadaFrench(), status); - failure(status, "NumberFormat::createNumberInstance", Locale::getCanadaFrench()); + if (failure(status, "NumberFormat::createNumberInstance", Locale::getCanadaFrench())){ + delete formatter; + return; + }; tempString = formatter->format (-5789.9876, tempString); if (tempString == expectedDefault) { @@ -1018,7 +1027,10 @@ void NumberFormatRegressionTest::Test4071014 (void) char loc[256]={0}; uloc_canonicalize("de_DE_PREEURO", loc, 256, &status); formatter = NumberFormat::createInstance(Locale(loc), status); - failure(status, "NumberFormat::createNumberInstance", loc); + if (failure(status, "NumberFormat::createNumberInstance", loc)){ + delete formatter; + return; + } tempString.remove(); tempString = formatter->format (-5789.9876, tempString); @@ -1081,7 +1093,10 @@ void NumberFormatRegressionTest::Test4071859 (void) char loc[256]={0}; uloc_canonicalize("it_IT_PREEURO", loc, 256, &status); formatter = NumberFormat::createInstance(Locale(loc), status); - failure(status, "NumberFormat::createNumberInstance"); + if (failure(status, "NumberFormat::createNumberInstance")){ + delete formatter; + return; + }; tempString = formatter->format (-5789.9876, tempString); if (tempString == expectedDefault) { @@ -1170,6 +1185,12 @@ void NumberFormatRegressionTest::Test4098741(void) //try { UErrorCode status = U_ZERO_ERROR; NumberFormat *fmt = NumberFormat::createPercentInstance(status); + if (U_FAILURE(status)) { + dataerrln("Error calling NumberFormat::createPercentInstance"); + delete fmt; + return; + } + fmt->setMaximumFractionDigits(20); UnicodeString temp; logln(fmt->format(.001, temp)); @@ -1845,7 +1866,10 @@ void NumberFormatRegressionTest::Test4145457() { //try { UErrorCode status = U_ZERO_ERROR; NumberFormat *nff = NumberFormat::createInstance(status); - failure(status, "NumberFormat::createInstance"); + if (failure(status, "NumberFormat::createInstance")){ + delete nff; + return; + }; if(nff->getDynamicClassID() != DecimalFormat::getStaticClassID()) { errln("DecimalFormat needed to continue"); return; @@ -2080,7 +2104,10 @@ static double _u_abs(double a) { return a<0?-a:a; } void NumberFormatRegressionTest::Test4167494(void) { UErrorCode status = U_ZERO_ERROR; NumberFormat *fmt = NumberFormat::createInstance(Locale::getUS(), status); - failure(status, "NumberFormat::createInstance"); + if (failure(status, "NumberFormat::createInstance")){ + delete fmt; + return; + }; double a = DBL_MAX * 0.99; // DBL_MAX itself overflows to +Inf UnicodeString s; @@ -2113,7 +2140,10 @@ void NumberFormatRegressionTest::Test4167494(void) { void NumberFormatRegressionTest::Test4170798(void) { UErrorCode status = U_ZERO_ERROR; NumberFormat *nf = NumberFormat::createInstance(Locale::getUS(), status); - failure(status, "NumberFormat::createInstance"); + if (failure(status, "NumberFormat::createInstance")){ + delete nf; + return; + }; if(nf->getDynamicClassID() != DecimalFormat::getStaticClassID()) { errln("DecimalFormat needed to continue"); return; @@ -2377,7 +2407,10 @@ void NumberFormatRegressionTest::Test4212072(void) { void NumberFormatRegressionTest::Test4216742(void) { UErrorCode status = U_ZERO_ERROR; DecimalFormat *fmt = (DecimalFormat*) NumberFormat::createInstance(Locale::getUS(), status); - failure(status, "createInstance", Locale::getUS()); + if (failure(status, "createInstance", Locale::getUS())){ + delete fmt; + return; + }; int32_t DATA[] = { INT32_MIN, INT32_MAX, -100000000, 100000000 }; int DATA_length = (int)(sizeof(DATA) / sizeof(DATA[0])); for (int i=0; isetMaximumFractionDigits(2); for (int i=0; isetMinimumFractionDigits(1); nf->setMaximumFractionDigits(1); double a = -0.09; diff --git a/icu4c/source/test/intltest/pptest.cpp b/icu4c/source/test/intltest/pptest.cpp index 61ec4e78d4d..2159183b17a 100644 --- a/icu4c/source/test/intltest/pptest.cpp +++ b/icu4c/source/test/intltest/pptest.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2003, International Business Machines Corporation and + * Copyright (c) 1997-2005, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -173,7 +173,10 @@ void ParsePositionTest::TestFieldPosition_example() UErrorCode status = U_ZERO_ERROR; NumberFormat *nf = NumberFormat::createInstance(status); - failure(status, "NumberFormat::createInstance"); + if (failure(status, "NumberFormat::createInstance")){ + delete nf; + return; + }; if(nf->getDynamicClassID() != DecimalFormat::getStaticClassID()) { errln("NumberFormat::createInstance returned unexpected class type"); diff --git a/icu4c/source/test/intltest/rbbitst.cpp b/icu4c/source/test/intltest/rbbitst.cpp index 693622a7842..fb326592e9d 100644 --- a/icu4c/source/test/intltest/rbbitst.cpp +++ b/icu4c/source/test/intltest/rbbitst.cpp @@ -2408,7 +2408,7 @@ RBBILineMonkey::RBBILineMonkey() { UErrorCode status = U_ZERO_ERROR; - fSets = new UVector(status); + fSets = new UVector(status); fBK = new UnicodeSet("[\\p{Line_Break=BK}]", status); fCR = new UnicodeSet("[\\p{Line_break=CR}]", status); @@ -2446,6 +2446,13 @@ RBBILineMonkey::RBBILineMonkey() fSA = new UnicodeSet("[\\p{Line_break=SA}]", status); fXX = new UnicodeSet("[\\p{Line_break=XX}]", status); + if (U_FAILURE(status)) { + deferredStatus = status; + fCharBI = NULL; + fNumberMatcher = NULL; + return; + } + fAL->addAll(*fXX); // Default behavior for XX is identical to AL fAL->addAll(*fAI); // Default behavior for AI is identical to AL fAL->addAll(*fSA); // Default behavior for SA is XX, which defaults to AL @@ -3264,6 +3271,9 @@ void RBBITest::TestLineBreaks(void) u_unescape(strlist[loop], str, 20); UnicodeString ustr(str); RBBILineMonkey monkey; + if (U_FAILURE(monkey.deferredStatus)) { + continue; + } const int EXPECTEDSIZE = 50; int expected[EXPECTEDSIZE]; diff --git a/icu4c/source/test/intltest/regextst.cpp b/icu4c/source/test/intltest/regextst.cpp index 1ace4cb30ad..6e9f8850cac 100644 --- a/icu4c/source/test/intltest/regextst.cpp +++ b/icu4c/source/test/intltest/regextst.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2002-2004, International Business Machines Corporation and + * Copyright (c) 2002-2005, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -1489,7 +1489,11 @@ void RegexTest::Extended() { UnicodeString testFlags; // the flags for a test. UnicodeString matchString; // The marked up string to be used as input - + if (U_FAILURE(status)){ + dataerrln("Construct RegexMatcher() error."); + delete [] testData; + return; + } // // Loop over the test data file, once per line. @@ -1812,6 +1816,10 @@ void RegexTest::PerlTests() { // One line per match, capture group one is the desired data. // RegexPattern* linePat = RegexPattern::compile("(.+?)[\\r\\n]+", 0, pe, status); + if (U_FAILURE(status)) { + dataerrln("RegexPattern::compile() error"); + return; + } RegexMatcher* lineMat = linePat->matcher(testDataString, status); // diff --git a/icu4c/source/test/intltest/tfsmalls.cpp b/icu4c/source/test/intltest/tfsmalls.cpp index 8d1407a533e..6cc69a01210 100644 --- a/icu4c/source/test/intltest/tfsmalls.cpp +++ b/icu4c/source/test/intltest/tfsmalls.cpp @@ -88,6 +88,10 @@ void test_FieldPosition_example( void ) UErrorCode status = U_ZERO_ERROR; DecimalFormat* fmt = (DecimalFormat*) NumberFormat::createInstance(status); + if (U_FAILURE(status)) { + it_dataerrln("NumberFormat::createInstance() error"); + return; + } fmt->setDecimalSeparatorAlwaysShown(TRUE); const int32_t tempLen = 20; diff --git a/icu4c/source/test/intltest/tmsgfmt.cpp b/icu4c/source/test/intltest/tmsgfmt.cpp index 78c2496c0d6..3e214f7ddff 100644 --- a/icu4c/source/test/intltest/tmsgfmt.cpp +++ b/icu4c/source/test/intltest/tmsgfmt.cpp @@ -1181,9 +1181,15 @@ void TestMessageFormat::TestRBNF(void) { Formattable args[1]; NumberFormat* numFmt = NumberFormat::createInstance(locale, ec); + if (U_FAILURE(ec)) { + dataerrln("Error calling NumberFormat::createInstance()"); + return; + } + for (int i = 0; i < formats_count; ++i) { MessageFormat* fmt = new MessageFormat(formats[i], locale, ec); logln((UnicodeString)"Testing format pattern: '" + formats[i] + "'"); + for (int j = 0; j < values_count; ++j) { ec = U_ZERO_ERROR; numFmt->parse(values[j], args[0], ec); diff --git a/icu4c/source/test/intltest/tztest.cpp b/icu4c/source/test/intltest/tztest.cpp index cd9a99fe9cc..18c12fbfbe3 100644 --- a/icu4c/source/test/intltest/tztest.cpp +++ b/icu4c/source/test/intltest/tztest.cpp @@ -800,6 +800,16 @@ void TimeZoneTest::TestCustomParse() UnicodeString id(kData[i].customId); int32_t exp = kData[i].expectedOffset; + { // for no data test Jitterbug 4354 + UErrorCode success = U_ZERO_ERROR; + NumberFormat* numberFormat = NumberFormat::createInstance(success); + if (U_FAILURE(success)) { + dataerrln(" NumberFormat::createInstance() error"); + return; + } + delete numberFormat; + } + TimeZone *zone = TimeZone::createTimeZone(id); UnicodeString itsID, temp;