ICU-699 add missing clone() functions

X-SVN-Rev: 13579
This commit is contained in:
Markus Scherer 2003-11-05 02:06:36 +00:00
parent a9cdcba39e
commit 1e06e62069
7 changed files with 126 additions and 7 deletions

View file

@ -301,6 +301,13 @@ void LocaleTest::TestBasicGetters() {
) {
errln("assignment to bogus Locale does not unbogus it or sets bad data");
}
Locale a("eo_DE@currency=DEM");
Locale *pb=a.clone();
if(pb==&a || *pb!=a) {
errln("Locale.clone() failed");
}
delete pb;
}
void LocaleTest::TestParallelAPIValues() {
@ -1526,6 +1533,17 @@ LocaleTest::TestKeywordVariants(void) {
err("Expected to get keyword value %s, got %s\n", testCases[i].expectedKeywords[j], keyword);
}
j++;
if(j == keyCount / 2) {
// replace keywords with a clone of itself
StringEnumeration *k2 = keywords->clone();
if(k2 == NULL || keyCount != k2->count(status)) {
errln("KeywordEnumeration.clone() failed");
} else {
delete keywords;
keywords = k2;
}
}
}
}
delete keywords;

View file

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2001, International Business Machines Corporation and
* Copyright (c) 1997-2003, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
@ -91,6 +91,11 @@ void ParsePositionTest::TestParsePosition()
errln("*** PP operator= operator== or operator != result");
}
ParsePosition *ppp = pp5.clone();
if(ppp == &pp5 || *ppp != pp5) {
errln("ParsePosition.clone() failed");
}
delete ppp;
}
void ParsePositionTest::TestFieldPosition()
@ -142,6 +147,12 @@ void ParsePositionTest::TestFieldPosition()
}
logln("");
FieldPosition *pfp = fp.clone();
if(pfp == &fp || *pfp != fp) {
errln("FieldPosition.clone() failed");
}
delete pfp;
}
void ParsePositionTest::TestFieldPosition_example()

View file

@ -376,6 +376,25 @@ NewResourceBundleTest::TestIteration()
delete locale;
}
// TODO: add operator== and != to ResourceBundle
static UBool
equalRB(ResourceBundle &a, ResourceBundle &b) {
UResType type;
UErrorCode status;
type=a.getType();
status=U_ZERO_ERROR;
return
type==b.getType() &&
a.getLocale()==b.getLocale() &&
0==strcmp(a.getName(), b.getName()) &&
type==URES_STRING ?
a.getString(status)==b.getString(status) :
type==URES_INT ?
a.getInt(status)==b.getInt(status) :
TRUE;
}
void
NewResourceBundleTest::TestOtherAPI(){
UErrorCode err = U_ZERO_ERROR;
@ -435,7 +454,19 @@ NewResourceBundleTest::TestOtherAPI(){
errln("copy construction for subresource failed\n");
}
ResourceBundle *p;
p = defaultresource.clone();
if(p == &defaultresource || !equalRB(*p, defaultresource)) {
errln("ResourceBundle.clone() failed");
}
delete p;
p = defaultSub.clone();
if(p == &defaultSub || !equalRB(*p, defaultSub)) {
errln("2nd ResourceBundle.clone() failed");
}
delete p;
UVersionInfo ver;
copyRes.getVersion(ver);

View file

@ -345,7 +345,7 @@ UBool StringSearchTest::assertEqual(const SearchData *search)
Collator *collator = getCollator(search->collator);
BreakIterator *breaker = getBreakIterator(search->breaker);
StringSearch *strsrch;
StringSearch *strsrch, *strsrch2;
UChar temp[128];
#if UCONFIG_NO_BREAK_ITERATION
@ -378,6 +378,19 @@ UBool StringSearchTest::assertEqual(const SearchData *search)
delete strsrch;
return FALSE;
}
strsrch2 = strsrch->clone();
if( strsrch2 == strsrch || *strsrch2 != *strsrch ||
!assertEqualWithStringSearch(strsrch2, search)
) {
errln("failure with StringSearch.clone()");
collator->setStrength(getECollationStrength(UCOL_TERTIARY));
delete strsrch;
delete strsrch2;
return FALSE;
}
delete strsrch2;
collator->setStrength(getECollationStrength(UCOL_TERTIARY));
delete strsrch;
return TRUE;

View file

@ -97,7 +97,7 @@ void CollationServiceTest::TestRegister()
UnicodeString locName = fu_FU.getName();
StringEnumeration* localeEnum = Collator::getAvailableLocales();
UBool found = FALSE;
const UnicodeString* locStr;
const UnicodeString* locStr, *ls2;
for (locStr = localeEnum->snext(status);
!found && locStr != NULL;
locStr = localeEnum->snext(status)) {
@ -106,7 +106,32 @@ void CollationServiceTest::TestRegister()
found = TRUE;
}
}
StringEnumeration *le2 = NULL;
localeEnum->reset(status);
int32_t i, count;
count = localeEnum->count(status);
for(i = 0; i < count; ++i) {
if(i == count / 2) {
le2 = localeEnum->clone();
if(le2 == NULL || count != le2->count(status)) {
errln("ServiceEnumeration.clone() failed");
break;
}
}
if(i >= count / 2) {
locStr = localeEnum->snext(status);
ls2 = le2->snext(status);
if(*locStr != *ls2) {
errln("ServiceEnumeration.clone() failed for item %d", i);
}
} else {
localeEnum->snext(status);
}
}
delete localeEnum;
delete le2;
if (!found) {
errln("new locale fu_FU not reported as supported locale");

View file

@ -1,7 +1,7 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2001, International Business Machines Corporation and
* Copyright (c) 1997-2003, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
@ -19,6 +19,7 @@
#include "unicode/fieldpos.h"
#include "unicode/fmtable.h"
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
/*static UBool chkstatus( UErrorCode &status, char* msg = NULL )
{
@ -212,7 +213,7 @@ void test_Formattable( void )
ucs,
ucs_ptr
};
const int32_t ft_cnt = (int32_t)(sizeof(ftarray) / sizeof(Formattable));
const int32_t ft_cnt = LENGTHOF(ftarray);
Formattable ft_arr( ftarray, ft_cnt );
UnicodeString temp;
if ((ft_arr[0].getType() == Formattable::kDate) && (ft_arr[0].getDate() == 1.0)
@ -225,11 +226,11 @@ void test_Formattable( void )
it_errln("*** FT constr. for date, double, long, ustring, ustring* or array");
}
int32_t res_cnt;
int32_t i, res_cnt;
const Formattable* res_array = ft_arr.getArray( res_cnt );
if (res_cnt == ft_cnt) {
UBool same = TRUE;
for (int32_t i = 0; i < res_cnt; i++ ) {
for (i = 0; i < res_cnt; i++ ) {
if (res_array[i] != ftarray[i]) {
same = FALSE;
}
@ -243,6 +244,15 @@ void test_Formattable( void )
it_errln(UnicodeString("*** FT getArray count res_cnt=") + res_cnt + UnicodeString("ft_cnt=") + ft_cnt);
}
Formattable *pf;
for(i = 0; i < ft_cnt; ++i) {
pf = ftarray[i].clone();
if(pf == (ftarray + i) || *pf != ftarray[i]) {
it_errln("Formattable.clone() failed for item %d" + i);
}
delete pf;
}
const Formattable ftarr1[] = { Formattable( (int32_t)1 ), Formattable( (int32_t)2 ) };
const Formattable ftarr2[] = { Formattable( (int32_t)3 ), Formattable( (int32_t)4 ) };

View file

@ -381,6 +381,17 @@ TimeZoneTest::TestGetAvailableIDs913()
for (i = 0; i < s_length;++i) {
if (i > 0) *buf += ", ";
*buf += *s->snext(ec);
if((i % 5) == 4) {
// replace s with a clone of itself
StringEnumeration *s2 = s->clone();
if(s2 == NULL || s_length != s2->count(ec)) {
errln("TimezoneEnumeration.clone() failed");
} else {
delete s;
s = s2;
}
}
}
*buf += " };";
logln(*buf);