ICU-6991 Add test for better code coverage in various calendar classes and dateformat.

X-SVN-Rev: 26646
This commit is contained in:
Michael Ow 2009-09-17 21:55:11 +00:00
parent 2c2d76044f
commit 30ef01e564
5 changed files with 84 additions and 7 deletions

View file

@ -18,6 +18,7 @@
#include "cmemory.h"
#include "unicode/putil.h"
#include "unicode/ustring.h"
#include "unicode/icudataver.h"
#include "cstring.h"
#include "putilimp.h"
@ -187,6 +188,9 @@ static void TestVersion()
char versionString[17]; /* xxx.xxx.xxx.xxx\0 */
UChar versionUString[] = { 0x0031, 0x002E, 0x0030, 0x002E,
0x0032, 0x002E, 0x0038, 0x0000 }; /* 1.0.2.8 */
UBool isModified = FALSE;
UVersionInfo version;
UErrorCode status = U_ZERO_ERROR;
log_verbose("Testing the API u_versionToString().....\n");
u_versionToString(versionArray, versionString);
@ -267,6 +271,17 @@ static void TestVersion()
else {
log_verbose(" from UString: %s\n", versionString);
}
/* Test the data version API for better code coverage */
u_getDataVersion(version, &status);
if (U_FAILURE(status)) {
log_err("ERROR: Unable to get data version.");
} else {
u_isDataOlder(version, &isModified, &status);
if (U_FAILURE(status)) {
log_err("ERROR: Unable to compare data version.");
}
}
}
static void TestCompareVersions()

View file

@ -478,14 +478,24 @@ CalendarTest::TestGenericAPI()
/* Code coverage for Calendar class. */
cal = Calendar::createInstance(status);
if (cal != NULL && !U_FAILURE(status)) {
((Calendar *)cal)->roll(UCAL_HOUR, 100, status);
if (failure(status, "Calendar::createInstance")) {
return;
}else {
((Calendar *)cal)->roll(UCAL_HOUR, (int32_t)100, status);
((Calendar *)cal)->clear(UCAL_HOUR);
URegistryKey key = cal->registerFactory(NULL, status);
cal->unregister(key, status);
} else {
errln("FAIL: Unable to create calendar instance.");
}
delete cal;
status = U_ZERO_ERROR;
cal = Calendar::createInstance(Locale("he_IL@calendar=hebrew"), status);
if (failure(status, "Calendar::createInstance")) {
return;
} else {
cal->roll(Calendar::MONTH, (int32_t)100, status);
}
StringEnumeration *en = Calendar::getKeywordValuesForLocale(NULL, Locale::getDefault(),FALSE, status);
if (en == NULL || U_FAILURE(status)) {
errln("FAIL: getKeywordValuesForLocale for Calendar.");

View file

@ -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.
*/
@ -110,7 +139,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

View file

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2001, International Business Machines Corporation and
* Copyright (c) 1997-2009, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
@ -36,6 +36,11 @@ private:
* Test that no parse or format methods are hidden.
*/
void TestNameHiding(void);
/**
* Add better code coverage.
*/
void TestCoverage(void);
};
#endif /* #if !UCONFIG_NO_FORMATTING */

View file

@ -262,9 +262,27 @@ void DateIntervalFormatTest::testAPI() {
delete dtitvfmt;
//====== test format in testFormat()
//====== test DateInterval class (better coverage)
DateInterval dtitv1(3600*24*365, 3600*24*366);
DateInterval dtitv2(dtitv1);
if (!(dtitv1 == dtitv2)) {
errln("ERROR: Copy constructor failed for DateInterval.");
}
DateInterval dtitv3(3600*365, 3600*366);
dtitv3 = dtitv1;
if (!(dtitv3 == dtitv1)) {
errln("ERROR: Equal operator failed for DateInterval.");
}
DateInterval *dtitv4 = dtitv1.clone();
if (*dtitv4 != dtitv1) {
errln("ERROR: Equal operator failed for DateInterval.");
}
delete dtitv4;
}