X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..2be6500137966bba13903b24204a44804f9e133a:/icuSources/test/intltest/dtfmapts.cpp diff --git a/icuSources/test/intltest/dtfmapts.cpp b/icuSources/test/intltest/dtfmapts.cpp index 971213c2..54bb1a5b 100644 --- a/icuSources/test/intltest/dtfmapts.cpp +++ b/icuSources/test/intltest/dtfmapts.cpp @@ -1,6 +1,6 @@ /*********************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2004, International Business Machines Corporation + * Copyright (c) 1997-2011, International Business Machines Corporation * and others. All Rights Reserved. ***********************************************************************/ @@ -29,11 +29,13 @@ void IntlTestDateFormatAPI::runIndexedTest( int32_t index, UBool exec, const cha if (exec) { logln("DateFormat API test---"); logln(""); UErrorCode status = U_ZERO_ERROR; + Locale saveLocale; Locale::setDefault(Locale::getEnglish(), status); if(U_FAILURE(status)) { errln("ERROR: Could not set default locale, test may not give correct results"); } testAPI(/*par*/); + Locale::setDefault(saveLocale, status); } break; @@ -51,10 +53,39 @@ void IntlTestDateFormatAPI::runIndexedTest( int32_t index, UBool exec, const cha } break; + case 3: name = "TestCoverage"; + if (exec) { + logln("TestCoverage---"); logln(""); + TestCoverage(); + } + break; + default: name = ""; break; } } +/** + * Add better code coverage. + */ +void IntlTestDateFormatAPI::TestCoverage(void) +{ + const char *LOCALES[] = { + "zh_CN@calendar=chinese", + "cop_EG@calendar=coptic", + "hi_IN@calendar=indian", + "am_ET@calendar=ethiopic" + }; + int32_t numOfLocales = 4; + + for (int32_t i = 0; i < numOfLocales; i++) { + DateFormat *df = DateFormat::createDateTimeInstance(DateFormat::kMedium, DateFormat::kMedium, Locale(LOCALES[i])); + if (df == NULL){ + dataerrln("Error creating DateFormat instances."); + return; + } + delete df; + } +} /** * Test that the equals method works correctly. */ @@ -67,13 +98,21 @@ 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."); - if (b->getDynamicClassID() == SimpleDateFormat::getStaticClassID()) + SimpleDateFormat *sdtfmt = dynamic_cast(b); + if (sdtfmt != NULL) { double ONE_YEAR = 365*24*60*60*1000.0; - ((SimpleDateFormat*)b)->set2DigitYearStart(start + 50*ONE_YEAR, status); + sdtfmt->set2DigitYearStart(start + 50*ONE_YEAR, status); if (U_FAILURE(status)) errln("FAIL: setTwoDigitStartDate failed."); else if (*a == *b) @@ -100,16 +139,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 DateFormat instances."); + } +// ======= 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; @@ -130,9 +176,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"); @@ -155,10 +203,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; @@ -198,7 +247,7 @@ void IntlTestDateFormatAPI::testAPI(/* char* par */) if( de->getTimeZone() != it->getTimeZone()) { errln("ERROR: adopt or set TimeZone() failed"); } - +} // ======= Test getStaticClassID() logln("Testing getStaticClassID()"); @@ -206,7 +255,7 @@ void IntlTestDateFormatAPI::testAPI(/* char* par */) status = U_ZERO_ERROR; DateFormat *test = new SimpleDateFormat(status); if(U_FAILURE(status)) { - errln("ERROR: Couldn't create a DateFormat"); + dataerrln("ERROR: Couldn't create a DateFormat - %s", u_errorName(status)); } if(test->getDynamicClassID() != SimpleDateFormat::getStaticClassID()) { @@ -248,7 +297,7 @@ IntlTestDateFormatAPI::TestNameHiding(void) { dateFmt->format(dateObj, str, fpos, status); delete dateFmt; } else { - errln("FAIL: Can't create DateFormat"); + dataerrln("FAIL: Can't create DateFormat"); } } @@ -257,14 +306,19 @@ IntlTestDateFormatAPI::TestNameHiding(void) { logln("SimpleDateFormat"); status = U_ZERO_ERROR; SimpleDateFormat sdf(status); - // Format API - sdf.format(dateObj, str, status); - sdf.format(dateObj, str, fpos, status); - // DateFormat API - sdf.format((UDate)0, str, fpos); - sdf.format((UDate)0, str); - sdf.parse(str, status); - sdf.parse(str, ppos); + if (U_SUCCESS(status)) { + // Format API + sdf.format(dateObj, str, status); + sdf.format(dateObj, str, fpos, status); + // DateFormat API + sdf.format((UDate)0, str, fpos); + sdf.format((UDate)0, str); + sdf.parse(str, status); + sdf.parse(str, ppos); + sdf.getNumberFormat(); + } else { + dataerrln("FAIL: Can't create SimpleDateFormat() - %s", u_errorName(status)); + } } // NumberFormat calling Format API @@ -277,7 +331,7 @@ IntlTestDateFormatAPI::TestNameHiding(void) { fmt->format(numObj, str, fpos, status); delete fmt; } else { - errln("FAIL: Can't create NumberFormat()"); + dataerrln("FAIL: Can't create NumberFormat()"); } } @@ -298,7 +352,7 @@ IntlTestDateFormatAPI::TestNameHiding(void) { fmt.parse(str, obj, ppos); fmt.parse(str, obj, status); } else { - errln("FAIL: Couldn't instantiate DecimalFormat, error %s. Quitting test", u_errorName(status)); + errcheckln(status, "FAIL: Couldn't instantiate DecimalFormat, error %s. Quitting test", u_errorName(status)); } }