ICU-6991 Improve coverage for calendar, bms, and msgfmt.
X-SVN-Rev: 26638
This commit is contained in:
parent
712b165172
commit
1cc5cd1a8b
@ -947,7 +947,8 @@ Calendar::getAvailableLocales(int32_t& count)
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* key,
|
||||
StringEnumeration* U_EXPORT2
|
||||
Calendar::getKeywordValuesForLocale(const char* key,
|
||||
const Locale& locale, UBool commonlyUsed, UErrorCode& status)
|
||||
{
|
||||
// This is a wrapper over ucal_getKeywordValuesForLocale
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1997-2008, International Business Machines Corporation and *
|
||||
* Copyright (C) 1997-2009, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
@ -150,7 +150,7 @@ static const UDate kPapalCutover = (2299161.0 - kEpochStartAsJulianDay) * U_MILL
|
||||
// -------------------------------------
|
||||
|
||||
GregorianCalendar::GregorianCalendar(UErrorCode& status)
|
||||
: Calendar(TimeZone::createDefault(), Locale::getDefault(), status),
|
||||
: Calendar(status),
|
||||
fGregorianCutover(kPapalCutover),
|
||||
fCutoverJulianDay(kCutoverJulianDay), fNormalizedGregorianCutover(fGregorianCutover), fGregorianCutoverYear(1582),
|
||||
fIsGregorian(TRUE), fInvertGregorian(FALSE)
|
||||
|
@ -475,6 +475,23 @@ CalendarTest::TestGenericAPI()
|
||||
if (gc2 != *gc || !(gc2 == *gc)) errln("FAIL: GregorianCalendar assignment/operator==/operator!= failed");
|
||||
delete gc;
|
||||
delete z;
|
||||
|
||||
/* Code coverage for Calendar class. */
|
||||
cal = Calendar::createInstance(status);
|
||||
if (cal != NULL && !U_FAILURE(status)) {
|
||||
((Calendar *)cal)->roll(UCAL_HOUR, 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.");
|
||||
}
|
||||
StringEnumeration *en = Calendar::getKeywordValuesForLocale(NULL, Locale::getDefault(),FALSE, status);
|
||||
if (en == NULL || U_FAILURE(status)) {
|
||||
errln("FAIL: getKeywordValuesForLocale for Calendar.");
|
||||
}
|
||||
delete en;
|
||||
delete cal;
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
|
@ -1425,6 +1425,21 @@ void SSearchTest::bmsTest()
|
||||
}
|
||||
}
|
||||
|
||||
/* Add better coverage for bms code. */
|
||||
if(bms_empty(longPattern)) {
|
||||
errln("FAIL: longgPattern is empty.");
|
||||
}
|
||||
|
||||
if (!bms_getData(longPattern)) {
|
||||
errln("FAIL: bms_getData returned NULL.");
|
||||
}
|
||||
|
||||
if (!ucd_getCollator(data)) {
|
||||
errln("FAIL: ucd_getCollator returned NULL.");
|
||||
}
|
||||
|
||||
ucd_freeCache();
|
||||
|
||||
close_patterns:
|
||||
bms_close(shortPattern);
|
||||
bms_close(longPattern);
|
||||
|
@ -53,6 +53,7 @@ TestMessageFormat::runIndexedTest(int32_t index, UBool exec,
|
||||
TESTCASE(19,TestTurkishCasing);
|
||||
TESTCASE(20,testAutoQuoteApostrophe);
|
||||
TESTCASE(21,testMsgFormatPlural);
|
||||
TESTCASE(22,testCoverage);
|
||||
default: name = ""; break;
|
||||
}
|
||||
}
|
||||
@ -1348,4 +1349,71 @@ void TestMessageFormat::testAutoQuoteApostrophe(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void TestMessageFormat::testCoverage(void) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UnicodeString testformat("{argument, plural, one{C''est # fichier} other {Ce sont # fichiers}} dans la liste.");
|
||||
MessageFormat *msgfmt = new MessageFormat(testformat, Locale("fr"), status);
|
||||
if (msgfmt == NULL || U_FAILURE(status)) {
|
||||
errln("FAIL: Unable to create MessageFormat.");
|
||||
return;
|
||||
}
|
||||
if (!msgfmt->usesNamedArguments()) {
|
||||
errln("FAIL: Unable to detect usage of named arguments.");
|
||||
}
|
||||
const double limit[] = {0.0, 1.0, 2.0};
|
||||
const UnicodeString formats[] = {"0.0<=Arg<1.0",
|
||||
"1.0<=Arg<2.0",
|
||||
"2.0<-Arg"};
|
||||
ChoiceFormat cf(limit, formats, 3);
|
||||
|
||||
msgfmt->setFormat("set", cf, status);
|
||||
|
||||
StringEnumeration *en = msgfmt->getFormatNames(status);
|
||||
if (en == NULL || U_FAILURE(status)) {
|
||||
errln("FAIL: Unable to get format names enumeration.");
|
||||
} else {
|
||||
int32_t count = 0;
|
||||
en->reset(status);
|
||||
count = en->count(status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("FAIL: Unable to get format name enumeration count.");
|
||||
} else {
|
||||
for (int32_t i = 0; i < count; i++) {
|
||||
en->snext(status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("FAIL: Error enumerating through names.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msgfmt->adoptFormat("adopt", &cf, status);
|
||||
|
||||
delete en;
|
||||
delete msgfmt;
|
||||
|
||||
msgfmt = new MessageFormat("'", status);
|
||||
if (msgfmt == NULL || U_FAILURE(status)) {
|
||||
errln("FAIL: Unable to create MessageFormat.");
|
||||
return;
|
||||
}
|
||||
if (msgfmt->usesNamedArguments()) {
|
||||
errln("FAIL: Unable to detect usage of named arguments.");
|
||||
}
|
||||
|
||||
msgfmt->setFormat("formatName", cf, status);
|
||||
if (!U_FAILURE(status)) {
|
||||
errln("FAIL: Should fail to setFormat instead of passing.");
|
||||
}
|
||||
status = U_ZERO_ERROR;
|
||||
en = msgfmt->getFormatNames(status);
|
||||
if (!U_FAILURE(status)) {
|
||||
errln("FAIL: Should fail to get format names enumeration instead of passing.");
|
||||
}
|
||||
|
||||
delete en;
|
||||
delete msgfmt;
|
||||
}
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
@ -1,6 +1,6 @@
|
||||
/***********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2005, International Business Machines Corporation
|
||||
* Copyright (c) 1997-2009, International Business Machines Corporation
|
||||
* and others. All Rights Reserved.
|
||||
***********************************************************************/
|
||||
|
||||
@ -92,6 +92,9 @@ public:
|
||||
void TestTurkishCasing(void);
|
||||
void testAutoQuoteApostrophe(void);
|
||||
|
||||
/* Provide better code coverage */
|
||||
void testCoverage(void);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user