/***********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2005, International Business Machines Corporation
+ * Copyright (c) 1997-2011, International Business Machines Corporation
* and others. All Rights Reserved.
***********************************************************************/
}
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.
*/
if (!(*a == *b))
errln("FAIL: DateFormat objects created at different times are unequal.");
- if (b->getDynamicClassID() == SimpleDateFormat::getStaticClassID())
+ SimpleDateFormat *sdtfmt = dynamic_cast<SimpleDateFormat *>(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)
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
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()) {
dateFmt->format(dateObj, str, fpos, status);
delete dateFmt;
} else {
- errln("FAIL: Can't create DateFormat");
+ dataerrln("FAIL: Can't create DateFormat");
}
}
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
fmt->format(numObj, str, fpos, status);
delete fmt;
} else {
- errln("FAIL: Can't create NumberFormat()");
+ dataerrln("FAIL: Can't create NumberFormat()");
}
}
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));
}
}