ICU-4452 add coverage tests

X-SVN-Rev: 18251
This commit is contained in:
Ram Viswanadha 2005-07-14 23:24:38 +00:00
parent ec2eabd38e
commit 7d1fac1020
14 changed files with 294 additions and 30 deletions

View File

@ -1140,6 +1140,39 @@ static void TestExemplarSet(void){
}
}
static void TestCoverage(void){
ULocaleDataDelimiterType types[] = {
ULOCDATA_QUOTATION_START, /* Quotation start */
ULOCDATA_QUOTATION_END, /* Quotation end */
ULOCDATA_ALT_QUOTATION_START, /* Alternate quotation start */
ULOCDATA_ALT_QUOTATION_END, /* Alternate quotation end */
ULOCDATA_DELIMITER_COUNT
};
int i;
UBool sub;
UErrorCode status = U_ZERO_ERROR;
ULocaleData *uld = ulocdata_open(uloc_getDefault(), &status);
if(U_FAILURE(status)){
log_err("ulocdata_open error");
return;
}
for(i = 0; i < ULOCDATA_DELIMITER_COUNT; i++){
UErrorCode status = U_ZERO_ERROR;
UChar result[32] = {0,};
ulocdata_getDelimiter(uld, types[i], result, 32, &status);
if (U_FAILURE(status)){
log_err("ulocdata_getgetDelimiter error with type %d", types[i]);
}
}
sub = ulocdata_getNoSubstitute(uld);
ulocdata_setNoSubstitute(uld,sub);
ulocdata_close(uld);
}
static void TestCurrencyList(void){
#if !UCONFIG_NO_FORMATTING
UErrorCode errorCode = U_ZERO_ERROR;
@ -1186,4 +1219,5 @@ void addCLDRTest(TestNode** root)
TESTCASE(VerifyTranslation);
TESTCASE(TestExemplarSet);
TESTCASE(TestCurrencyList);
TESTCASE(TestCoverage);
}

View File

@ -20,6 +20,7 @@
#include "unicode/ucnv.h"
#include "unicode/ures.h"
#include "unicode/ustring.h"
#include "unicode/uclean.h"
#include "cmemory.h"
#include "cstring.h"
#include "filestrm.h"
@ -69,6 +70,7 @@ static void TestICUDataName(void);
static void TestSwapData(void);
static void PointerTableOfContents(void);
static void SetBadCommonData(void);
static void TestUDataFileAccess(void);
void addUDataTest(TestNode** root);
@ -88,6 +90,7 @@ addUDataTest(TestNode** root)
addTest(root, &TestSwapData, "udatatst/TestSwapData" );
addTest(root, &PointerTableOfContents, "udatatst/PointerTableOfContents" );
addTest(root, &SetBadCommonData, "udatatst/SetBadCommonData" );
addTest(root, &TestUDataFileAccess, "udatatst/TestUDataFileAccess" );
}
#if 0
@ -448,6 +451,42 @@ cleanupAndReturn:
return;
}
static void TestUDataFileAccess(){
UErrorCode status=U_ZERO_ERROR;
/** UDATA_NO_FILES, ICU does not access the file system for data loading. */
u_cleanup();
udata_setFileAccess(UDATA_NO_FILES,&status);
u_init(&status);
/** UDATA_ONLY_PACKAGES, ICU only loads data from packages, not from single files. */
u_cleanup();
udata_setFileAccess(UDATA_ONLY_PACKAGES,&status);
u_init(&status);
/** UDATA_PACKAGES_FIRST, ICU loads data from packages first, and only from single files
if the data cannot be found in a package. */
u_cleanup();
udata_setFileAccess(UDATA_PACKAGES_FIRST,&status);
u_init(&status);
/** UDATA_FILES_FIRST, ICU looks for data in single files first, then in packages. (default) */
u_cleanup();
udata_setFileAccess(UDATA_FILES_FIRST,&status);
u_init(&status);
/** An alias for the default access mode. */
u_cleanup();
udata_setFileAccess(UDATA_DEFAULT_ACCESS,&status);
u_init(&status);
if(U_FAILURE(status)){
log_err(u_errorName(status));
}
}
static UBool U_CALLCONV
isAcceptable1(void *context,

View File

@ -180,6 +180,12 @@ IntlTestRBNF::TestAPI() {
if(!(ruleCtorResult == *formatter)) {
errln("Formatter constructed from the original rules should be semantically equivalent to the original!");
}
// Jitterbug 4452, for coverage
RuleBasedNumberFormat nf(spelloutRules, (UnicodeString)"", Locale::getUS(), perror, status);
if(!(nf == *formatter)) {
errln("Formatter constructed from the original rules should be semantically equivalent to the original!");
}
}
ures_close(en);
}
@ -297,6 +303,16 @@ IntlTestRBNF::TestAPI() {
logln("Formatted 4 int64_t, expected " + expected + " got " + result);
}
//Jitterbug 4452, for coverage
result.remove();
FieldPosition pos2;
formatter->format((int64_t)4, formatter->getRuleSetName(0), result, pos2, status = U_ZERO_ERROR);
if(result != expected) {
errln("Formatted 4 int64_t, expected " + expected + " got " + result);
} else {
logln("Formatted 4 int64_t, expected " + expected + " got " + result);
}
// clean up
logln("Cleaning up");
delete formatter;

View File

@ -78,6 +78,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
CASE(28,TestCurrencyNames);
CASE(29,TestCurrencyAmount);
CASE(30,TestCurrencyUnit);
CASE(31,TestCoverage);
default: name = ""; break;
}
@ -118,17 +119,43 @@ NumberFormatTest::TestAPI(void)
if (result != "12.00"){
errln("format int64_t error");
}
result.remove();
FieldPosition pos2;
test->format(ll, result, pos2);
if (result != "12.00"){
errln("format int64_t error");
}
delete test;
}
}
void
NumberFormatTest::TestCoverage(void){
class StubNumberForamt :public NumberFormat{
public:
StubNumberForamt(){};
virtual UnicodeString& format(double number,UnicodeString& appendTo,FieldPosition& pos) const {
return appendTo;
}
virtual UnicodeString& format(int32_t number,UnicodeString& appendTo,FieldPosition& pos) const {
return appendTo.append(UChar('3'));
}
virtual UnicodeString& format(int64_t number,UnicodeString& appendTo,FieldPosition& pos) const {
return NumberFormat::format(number, appendTo, pos);
}
virtual void parse(const UnicodeString& text,
Formattable& result,
ParsePosition& parsePosition) const {}
virtual UClassID getDynamicClassID(void) const {
static char classID = 0;
return (UClassID)&classID;
}
virtual Format* clone() const {return NULL;}
} stub;
UnicodeString agent("agent");
FieldPosition pos;
int64_t num = 4;
if (stub.format(num, agent, pos) != UnicodeString("agent3")){
errln("NumberFormat::format(int64, UnicodString&, FieldPosition&) should delegate to (int32, ,)");
};
}
// Test various patterns
void
NumberFormatTest::TestPatterns(void)
@ -1511,6 +1538,11 @@ void NumberFormatTest::TestCurrencyAmount(void){
if (!(ca2 == ca)){
errln("CurrencyAmount copy constructed object should be same");
}
ca2=ca;
if (!(ca2 == ca)){
errln("CurrencyAmount assigned object should be same");
}
CurrencyAmount *ca3 = (CurrencyAmount *)ca.clone();
if (!(*ca3 == ca)){

View File

@ -28,6 +28,9 @@ class NumberFormatTest: public CalendarTimeZoneTest {
* Test APIs (to increase code coverage)
*/
void TestAPI(void);
void TestCoverage(void);
/**
* Test the handling of quotes
**/

View File

@ -342,6 +342,12 @@ void RBBIAPITest::TestGetSetAdoptText()
pos = wordIter1->previous();
TEST_ASSERT(pos==UBRK_DONE);
status = U_ZERO_ERROR;
UText *gut2 = utext_openUnicodeString(NULL,NULL,&status);
wordIter1->getUText(gut2, status);
TEST_ASSERT_SUCCESS(status);
utext_close(gut2);
utext_close(ut);
utext_close(ut2);

View File

@ -1,6 +1,6 @@
/*
*****************************************************************************
* Copyright (C) 2001-2004, International Business Machines orporation
* Copyright (C) 2001-2005, International Business Machines orporation
* and others. All Rights Reserved.
****************************************************************************/
@ -150,6 +150,7 @@ void StringSearchTest::runIndexedTest(int32_t index, UBool exec,
CASE(32, TestContractionCanonical)
CASE(33, TestUClassID)
CASE(34, TestSubclass)
CASE(35, TestCoverage)
default: name = ""; break;
}
}
@ -2272,4 +2273,36 @@ void StringSearchTest::TestSubclass()
}
}
void StringSearchTest::TestCoverage(){
class StubSearchIterator:public SearchIterator{
public:
StubSearchIterator(){}
virtual void setOffset(int32_t position, UErrorCode &status) {};
virtual int32_t getOffset(void) const {return 0;};
virtual SearchIterator* safeClone(void) const {return NULL;};
virtual int32_t handleNext(int32_t position, UErrorCode &status){return 0;};
virtual int32_t handlePrev(int32_t position, UErrorCode &status) {return 0;};
virtual inline UClassID getDynamicClassID() const {
static char classID = 0;
return (UClassID)&classID;
}
};
StubSearchIterator stub1, stub2;
if (stub1 != stub2){
errln("new StubSearchIterator should same");
}
UErrorCode status = U_ZERO_ERROR;
stub2.setText(UnicodeString("ABC"), status);
if (U_FAILURE(status)) {
errln("Error: SearchIterator::SetText");
}
stub1 = stub2;
if (stub1 != stub2){
errln("SearchIterator::operator = assigned object should same");
}
}
#endif /* #if !UCONFIG_NO_COLLATION */

View File

@ -1,6 +1,6 @@
/****************************************************************************
* COPYRIGHT:
* Copyright (c) 2001, International Business Machines Corporation and others
* Copyright (c) 2001-2005, International Business Machines Corporation and others
* All Rights Reserved.
***************************************************************************/
@ -87,6 +87,7 @@ private:
void TestContractionCanonical();
void TestUClassID();
void TestSubclass();
void TestCoverage();
};
#endif /* #if !UCONFIG_NO_COLLATION */

View File

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2001-2004, International Business Machines Corporation and
* Copyright (c) 2001-2005, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/************************************************************************
@ -43,6 +43,7 @@ TransliteratorErrorTest::runIndexedTest(int32_t index, UBool exec,
TESTCASE(0,TestTransliteratorErrors);
TESTCASE(1, TestUnicodeSetErrors);
TESTCASE(2, TestRBTErrors);
TESTCASE(3, TestCoverage);
//TESTCASE(3, TestUniToHexErrors);
//TESTCASE(4, TestHexToUniErrors);
// TODO: Add a subclass to test clone().
@ -264,4 +265,23 @@ void TransliteratorErrorTest::TestRBTErrors() {
// delete t;
//}
void TransliteratorErrorTest::TestCoverage() {
class StubTransliterator: public Transliterator{
public:
StubTransliterator(): Transliterator(UNICODE_STRING_SIMPLE("Any-Null"), 0) {}
virtual void handleTransliterate(Replaceable& ,UTransPosition& offsets,UBool) const {
offsets.start = offsets.limit;
}
virtual UClassID getDynamicClassID() const{
static char classID = 0;
return (UClassID)&classID;
}
} stub;
if (stub.clone() != 0){
errln("FAIL: default Transliterator::clone() should retrun 0");
}
}
#endif /* #if !UCONFIG_NO_TRANSLITERATION */

View File

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2001-2004, International Business Machines Corporation and
* Copyright (c) 2001-2005, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/************************************************************************
@ -43,6 +43,10 @@ public:
//void TestHexToUniErrors(void);
// JitterBug 4452, for coverage. The reason to put this method here is
// this class is comparable smaller than other Transliterator*Test classes
void TestCoverage(void);
};
#endif /* #if !UCONFIG_NO_TRANSLITERATION */

View File

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2004, International Business Machines Corporation and
* Copyright (c) 1997-2005, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
@ -47,6 +47,7 @@
#include "ucaconf.h"
#include "svccoll.h"
#include "cmemory.h"
//#include "rndmcoll.h"
#define TESTCLASS(n,classname) \
case n: \
@ -87,6 +88,7 @@ void IntlTestCollator::runIndexedTest( int32_t index, UBool exec, const char* &n
TESTCLASS(18, UCAConformanceTest);
TESTCLASS(19, CollationServiceTest);
TESTCLASS(20, CollationFinnishTest); // removed by weiv - we have changed Finnish collation
//TESTCLASS(21, RandomCollator);
default: name = ""; break;
}

View File

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2003, International Business Machines Corporation and
* Copyright (c) 1997-2005, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
@ -17,20 +17,11 @@ void IntlTestDateFormatSymbols::runIndexedTest( int32_t index, UBool exec, const
{
if (exec) logln("TestSuite DateFormatSymbols");
switch (index) {
case 0: name = "DateFormatSymbols test";
if (exec) {
logln("DateFormatSymbols test---"); logln("");
testSymbols(/*par*/);
}
break;
case 1: name = "TestGetMonths";
if (exec) {
logln("TestGetMonths test---"); logln("");
TestGetMonths();
}
break;
TESTCASE(0,TestSymbols);
TESTCASE(1,TestGetMonths);
TESTCASE(2,TestGetMonths2);
TESTCASE(3,TestGetWeekdays2);
TESTCASE(4,TestGetEraNames);
default: name = ""; break;
}
}
@ -59,10 +50,82 @@ void IntlTestDateFormatSymbols::TestGetMonths()
delete symbol;
}
void IntlTestDateFormatSymbols::TestGetMonths2()
{
UErrorCode status = U_ZERO_ERROR;
DateFormatSymbols *symbol;
symbol=new DateFormatSymbols(Locale::getDefault(), status);
DateFormatSymbols::DtContextType context[] = {DateFormatSymbols::STANDALONE, DateFormatSymbols::FORMAT};
DateFormatSymbols::DtWidthType width[] = {DateFormatSymbols::WIDE, DateFormatSymbols::ABBREVIATED, DateFormatSymbols::NARROW};
for (int32_t i = 0; i < 2; i++) {
for (int32_t j = 0; j < 3; j++) {
int32_t cnt;
const UnicodeString * month = symbol->getMonths(cnt,context[i],width[j]);
logln((UnicodeString)"size = " + cnt);
for (int32_t k = 0; k < cnt; k++) {
logln(month[k]);
}
}
}
delete symbol;
}
void IntlTestDateFormatSymbols::TestGetWeekdays2()
{
UErrorCode status = U_ZERO_ERROR;
DateFormatSymbols *symbol;
symbol=new DateFormatSymbols(Locale::getDefault(), status);
DateFormatSymbols::DtContextType context[] = {DateFormatSymbols::STANDALONE, DateFormatSymbols::FORMAT};
DateFormatSymbols::DtWidthType width[] = {DateFormatSymbols::WIDE, DateFormatSymbols::ABBREVIATED, DateFormatSymbols::NARROW};
for (int32_t i = 0; i < 2; i++) {
for (int32_t j = 0; j < 3; j++) {
int32_t cnt;
const UnicodeString * wd = symbol->getWeekdays(cnt,context[i],width[j]);
logln((UnicodeString)"size = " + cnt);
for (int32_t k = 0; k < cnt; k++) {
logln(wd[k]);
}
}
}
delete symbol;
}
void IntlTestDateFormatSymbols::TestGetEraNames()
{
UErrorCode status = U_ZERO_ERROR;
int32_t cnt;
const UnicodeString* name;
DateFormatSymbols *symbol;
symbol=new DateFormatSymbols(Locale::getDefault(), status);
name=symbol->getEraNames(cnt);
logln((UnicodeString)"size = " + cnt);
for (int32_t i=0; i<cnt; ++i)
{
logln(name[i]);
}
delete symbol;
}
/**
* Test the API of DateFormatSymbols; primarily a simple get/set set.
*/
void IntlTestDateFormatSymbols::testSymbols(/* char *par */)
void IntlTestDateFormatSymbols::TestSymbols(/* char *par */)
{
UErrorCode status = U_ZERO_ERROR;

View File

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2001, International Business Machines Corporation and
* Copyright (c) 1997-2005, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
@ -23,11 +23,15 @@ private:
/**
* Test the API of DateFormatSymbols; primarily a simple get/set set.
*/
void testSymbols(/* char *par */);
void TestSymbols(/* char *par */);
/**
* Test getMonths.
*/
void TestGetMonths(void);
void TestGetMonths2(void);
void TestGetWeekdays2(void);
void TestGetEraNames(void);
};
#endif /* #if !UCONFIG_NO_FORMATTING */

View File

@ -414,6 +414,13 @@ void UObjectTest::testUMemory() {
// destroy object and delete space manually
p->~UnicodeString();
UnicodeString::operator delete(p, stackMemory);
// Jitterbug 4452, for coverage
UnicodeString *pa = new UnicodeString[2];
if ( !pa[0].isEmpty() || !pa[1].isEmpty()){
errln("constructor used with array new did not work right");
}
delete [] pa;
#endif
// try to call the compiler-generated UMemory::operator=(class UMemory const &)
@ -429,7 +436,7 @@ void UObjectTest::TestMFCCompatibility() {
if(str->charAt(0) != 0x0040) {
errln("debug new doesn't work.");
}
delete str;
UnicodeString::operator delete(str, __FILE__, __LINE__);
#endif
}