X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..d25163bfc042dbef00577180ee21dd3460fc3715:/icuSources/test/intltest/dtfmapts.cpp diff --git a/icuSources/test/intltest/dtfmapts.cpp b/icuSources/test/intltest/dtfmapts.cpp index db443f1e..54bb1a5b 100644 --- a/icuSources/test/intltest/dtfmapts.cpp +++ b/icuSources/test/intltest/dtfmapts.cpp @@ -1,6 +1,6 @@ /*********************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2005, International Business Machines Corporation + * Copyright (c) 1997-2011, International Business Machines Corporation * and others. All Rights Reserved. ***********************************************************************/ @@ -53,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. */ @@ -79,10 +108,11 @@ void IntlTestDateFormatAPI::TestEquals(void) 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) @@ -110,7 +140,7 @@ void IntlTestDateFormatAPI::testAPI(/* char* par */) DateFormat *de = DateFormat::createDateTimeInstance(DateFormat::LONG, DateFormat::LONG, Locale::getGerman()); if (def == NULL || fr == NULL || it == NULL || de == NULL){ - dataerrln("Error creating instnaces."); + dataerrln("Error creating DateFormat instances."); } // ======= Test equality @@ -225,7 +255,7 @@ if (fr != NULL && it != NULL && de != NULL) 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()) { @@ -267,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"); } } @@ -276,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 @@ -296,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()"); } } @@ -317,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)); } }