mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-15 01:42:37 +00:00
ICU-5161 Fix memory leaks.
X-SVN-Rev: 19556
This commit is contained in:
parent
7e6b69156d
commit
57206e7d3c
1 changed files with 53 additions and 51 deletions
|
@ -56,27 +56,27 @@ void LocaleAliasTest::runIndexedTest( int32_t index, UBool exec, const char* &na
|
|||
void LocaleAliasTest::TestCalendar() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
for (int i=0; i<_LOCALE_NUMBER; i++) {
|
||||
Locale* oldLoc = new Locale(_LOCALE_ALIAS[i][0]);
|
||||
Locale* newLoc = new Locale(_LOCALE_ALIAS[i][1]);
|
||||
Locale oldLoc(_LOCALE_ALIAS[i][0]);
|
||||
Locale newLoc(_LOCALE_ALIAS[i][1]);
|
||||
if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){
|
||||
logln(UnicodeString(newLoc->getName())+" is not available. Skipping!");
|
||||
logln(UnicodeString(newLoc.getName())+" is not available. Skipping!");
|
||||
continue;
|
||||
}
|
||||
logln("\nold locale:%s new locale:%s",oldLoc->getName(),newLoc->getName());
|
||||
Calendar* c1 = Calendar::createInstance(*oldLoc, status);
|
||||
Calendar* c2 = Calendar::createInstance(*newLoc, status);
|
||||
logln("\nold locale:%s new locale:%s",oldLoc.getName(),newLoc.getName());
|
||||
Calendar* c1 = Calendar::createInstance(oldLoc, status);
|
||||
Calendar* c2 = Calendar::createInstance(newLoc, status);
|
||||
|
||||
//Test function "getLocale(ULocale.VALID_LOCALE)"
|
||||
const char* l1 = c1->getLocaleID(ULOC_VALID_LOCALE, status);
|
||||
const char* l2 = c2->getLocaleID(ULOC_VALID_LOCALE, status);
|
||||
if (strcmp(newLoc->getName(), l1)!=0) {
|
||||
errln("CalendarTest: newLoc!=l1: newLoc= "+UnicodeString(newLoc->getName()) +" l1= "+UnicodeString(l1));
|
||||
if (strcmp(newLoc.getName(), l1)!=0) {
|
||||
errln("CalendarTest: newLoc!=l1: newLoc= "+UnicodeString(newLoc.getName()) +" l1= "+UnicodeString(l1));
|
||||
}
|
||||
if (strcmp(l1, l2)!=0) {
|
||||
errln("CalendarTest: l1!=l2: l1= "+UnicodeString(l1) +" l2= "+UnicodeString(l2));
|
||||
}
|
||||
if(!(c1==c2)){
|
||||
errln("CalendarTest: c1!=c2. newLoc= "+UnicodeString(newLoc->getName()) +" oldLoc= "+UnicodeString(oldLoc->getName()));
|
||||
errln("CalendarTest: c1!=c2. newLoc= "+UnicodeString(newLoc.getName()) +" oldLoc= "+UnicodeString(oldLoc.getName()));
|
||||
}
|
||||
logln("Calendar(getLocale) old:"+UnicodeString(l1)+" new:"+UnicodeString(l2));
|
||||
delete c1;
|
||||
|
@ -86,28 +86,28 @@ void LocaleAliasTest::TestCalendar() {
|
|||
void LocaleAliasTest::TestDateFormat() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
for (int i=0; i<_LOCALE_NUMBER; i++) {
|
||||
Locale* oldLoc = new Locale(_LOCALE_ALIAS[i][0]);
|
||||
Locale* newLoc = new Locale(_LOCALE_ALIAS[i][1]);
|
||||
Locale oldLoc(_LOCALE_ALIAS[i][0]);
|
||||
Locale newLoc(_LOCALE_ALIAS[i][1]);
|
||||
if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){
|
||||
logln(UnicodeString(newLoc->getName())+" is not available. Skipping!");
|
||||
logln(UnicodeString(newLoc.getName())+" is not available. Skipping!");
|
||||
continue;
|
||||
}
|
||||
logln("\nold locale:%s new locale:%s",oldLoc->getName(),newLoc->getName());
|
||||
logln("\nold locale:%s new locale:%s",oldLoc.getName(),newLoc.getName());
|
||||
|
||||
DateFormat* df1 = DateFormat::createDateInstance(DateFormat::FULL, *oldLoc);
|
||||
DateFormat* df2 = DateFormat::createDateInstance(DateFormat::FULL, *newLoc);
|
||||
DateFormat* df1 = DateFormat::createDateInstance(DateFormat::FULL, oldLoc);
|
||||
DateFormat* df2 = DateFormat::createDateInstance(DateFormat::FULL, newLoc);
|
||||
|
||||
//Test function "getLocale"
|
||||
const char* l1 = df1->getLocaleID(ULOC_VALID_LOCALE, status);
|
||||
const char* l2 = df2->getLocaleID(ULOC_VALID_LOCALE, status);
|
||||
if (strcmp(newLoc->getName(), l1)!=0) {
|
||||
errln("CalendarTest: newLoc!=l1: newLoc= "+UnicodeString(newLoc->getName()) +" l1= "+UnicodeString(l1));
|
||||
if (strcmp(newLoc.getName(), l1)!=0) {
|
||||
errln("CalendarTest: newLoc!=l1: newLoc= "+UnicodeString(newLoc.getName()) +" l1= "+UnicodeString(l1));
|
||||
}
|
||||
if (strcmp(l1, l2)!=0) {
|
||||
errln("TestDateFormat: l1!=l2: l1= "+UnicodeString(l1) +" l2= "+UnicodeString(l2));
|
||||
}
|
||||
if(!(df1==df2)){
|
||||
errln("TestDateFormat: c1!=c2. newLoc= "+UnicodeString(newLoc->getName()) +" oldLoc= "+UnicodeString(oldLoc->getName()));
|
||||
errln("TestDateFormat: c1!=c2. newLoc= "+UnicodeString(newLoc.getName()) +" oldLoc= "+UnicodeString(oldLoc.getName()));
|
||||
}
|
||||
logln("DateFormat(getLocale) old:%s new:%s",l1,l2);
|
||||
|
||||
|
@ -118,28 +118,28 @@ void LocaleAliasTest::TestDateFormat() {
|
|||
void LocaleAliasTest::TestCollation() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
for (int i=0; i<_LOCALE_NUMBER; i++) {
|
||||
Locale* oldLoc = new Locale(_LOCALE_ALIAS[i][0]);
|
||||
Locale* newLoc = new Locale(_LOCALE_ALIAS[i][1]);
|
||||
Locale oldLoc(_LOCALE_ALIAS[i][0]);
|
||||
Locale newLoc(_LOCALE_ALIAS[i][1]);
|
||||
if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){
|
||||
logln(UnicodeString(newLoc->getName())+" is not available. Skipping!");
|
||||
logln(UnicodeString(newLoc.getName())+" is not available. Skipping!");
|
||||
continue;
|
||||
}
|
||||
logln("\nold locale:%s new locale:%s",oldLoc->getName(),newLoc->getName());
|
||||
logln("\nold locale:%s new locale:%s",oldLoc.getName(),newLoc.getName());
|
||||
|
||||
Collator* c1 = Collator::createInstance(*oldLoc, status);
|
||||
Collator* c2 = Collator::createInstance(*newLoc, status);
|
||||
Collator* c1 = Collator::createInstance(oldLoc, status);
|
||||
Collator* c2 = Collator::createInstance(newLoc, status);
|
||||
|
||||
Locale l1 = c1->getLocale(ULOC_VALID_LOCALE, status);
|
||||
Locale l2 = c2->getLocale(ULOC_VALID_LOCALE, status);
|
||||
|
||||
if (strcmp(newLoc->getName(), l1.getName())!=0) {
|
||||
errln("CalendarTest: newLoc!=l1: newLoc= "+UnicodeString(newLoc->getName()) +" l1= "+UnicodeString(l1.getName()));
|
||||
if (strcmp(newLoc.getName(), l1.getName())!=0) {
|
||||
errln("CalendarTest: newLoc!=l1: newLoc= "+UnicodeString(newLoc.getName()) +" l1= "+UnicodeString(l1.getName()));
|
||||
}
|
||||
if (strcmp(l1.getName(), l2.getName())!=0) {
|
||||
errln("CollationTest: l1!=l2: l1= "+UnicodeString(l1.getName()) +" l2= "+UnicodeString(l2.getName()));
|
||||
}
|
||||
if(!(c1==c2)){
|
||||
errln("CollationTest: c1!=c2. newLoc= "+UnicodeString(newLoc->getName()) +" oldLoc= "+UnicodeString(oldLoc->getName()));
|
||||
errln("CollationTest: c1!=c2. newLoc= "+UnicodeString(newLoc.getName()) +" oldLoc= "+UnicodeString(oldLoc.getName()));
|
||||
}
|
||||
logln("Collator(getLocale) old:%s new:%s", l1.getName(), l2.getName());
|
||||
delete c1;
|
||||
|
@ -148,18 +148,19 @@ void LocaleAliasTest::TestCollation() {
|
|||
}
|
||||
void LocaleAliasTest::TestULocale() {
|
||||
for (int i=0; i<_LOCALE_NUMBER; i++) {
|
||||
Locale* oldLoc = new Locale(_LOCALE_ALIAS[i][0]);
|
||||
Locale* newLoc = new Locale(_LOCALE_ALIAS[i][1]);
|
||||
Locale oldLoc(_LOCALE_ALIAS[i][0]);
|
||||
Locale newLoc(_LOCALE_ALIAS[i][1]);
|
||||
if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){
|
||||
logln(UnicodeString(newLoc->getName())+" is not available. Skipping!");
|
||||
logln(UnicodeString(newLoc.getName())+" is not available. Skipping!");
|
||||
continue;
|
||||
}
|
||||
logln("\nold locale:%s new locale:%s",oldLoc->getName(),newLoc->getName());
|
||||
logln("\nold locale:%s new locale:%s",oldLoc.getName(),newLoc.getName());
|
||||
|
||||
UnicodeString name1, name2;
|
||||
oldLoc->getDisplayName(name1);
|
||||
newLoc->getDisplayName(name2);
|
||||
oldLoc.getDisplayName(name1);
|
||||
newLoc.getDisplayName(name2);
|
||||
if (name1!=name2) {
|
||||
errln("DisplayNames are not equal. newLoc= "+UnicodeString(newLoc.getName()) +" oldLoc= "+UnicodeString(oldLoc.getName()));
|
||||
}
|
||||
log("ULocale(getDisplayName) old:");
|
||||
log(name1);
|
||||
|
@ -202,29 +203,29 @@ void LocaleAliasTest::TestDisplayName() {
|
|||
int32_t availableNum =0;
|
||||
const Locale* available = Locale::getAvailableLocales(availableNum);
|
||||
for (int i=0; i<_LOCALE_NUMBER; i++) {
|
||||
Locale* oldLoc = new Locale(_LOCALE_ALIAS[i][0]);
|
||||
Locale* newLoc = new Locale(_LOCALE_ALIAS[i][1]);
|
||||
Locale oldLoc(_LOCALE_ALIAS[i][0]);
|
||||
Locale newLoc(_LOCALE_ALIAS[i][1]);
|
||||
if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){
|
||||
logln(UnicodeString(newLoc->getName())+" is not available. Skipping!");
|
||||
logln(UnicodeString(newLoc.getName())+" is not available. Skipping!");
|
||||
continue;
|
||||
}
|
||||
for(int j=0; j<availableNum; j++){
|
||||
UnicodeString dipLocName = UnicodeString(available[j].getName());
|
||||
const UnicodeString oldCountry = oldLoc->getDisplayCountry(dipLocName);
|
||||
const UnicodeString newCountry = newLoc->getDisplayCountry(dipLocName);
|
||||
const UnicodeString oldLang = oldLoc->getDisplayLanguage(dipLocName);
|
||||
const UnicodeString newLang = newLoc->getDisplayLanguage(dipLocName);
|
||||
const UnicodeString oldCountry = oldLoc.getDisplayCountry(dipLocName);
|
||||
const UnicodeString newCountry = newLoc.getDisplayCountry(dipLocName);
|
||||
const UnicodeString oldLang = oldLoc.getDisplayLanguage(dipLocName);
|
||||
const UnicodeString newLang = newLoc.getDisplayLanguage(dipLocName);
|
||||
|
||||
// is there display name for the current country ID
|
||||
if(newCountry != newLoc->getCountry()){
|
||||
if(newCountry != newLoc.getCountry()){
|
||||
if(oldCountry!=newCountry){
|
||||
errln("getCountry() failed for "+ UnicodeString(oldLoc->getName()) +" oldCountry= "+ prettify(oldCountry) +" newCountry = "+prettify(newCountry)+ " in display locale "+ UnicodeString(available[j].getName()));
|
||||
errln("getCountry() failed for "+ UnicodeString(oldLoc.getName()) +" oldCountry= "+ prettify(oldCountry) +" newCountry = "+prettify(newCountry)+ " in display locale "+ UnicodeString(available[j].getName()));
|
||||
}
|
||||
}
|
||||
//there is a display name for the current lang ID
|
||||
if(newLang != newLoc->getLanguage()){
|
||||
if(newLang != newLoc.getLanguage()){
|
||||
if(oldLang != newLang){
|
||||
errln("getLanguage() failed for " + UnicodeString(oldLoc->getName()) + " oldLang = "+ prettify(oldLang) +" newLang = "+prettify(newLang)+ " in display locale "+UnicodeString(available[j].getName()));
|
||||
errln("getLanguage() failed for " + UnicodeString(oldLoc.getName()) + " oldLang = "+ prettify(oldLang) +" newLang = "+prettify(newLang)+ " in display locale "+UnicodeString(available[j].getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -234,13 +235,13 @@ void LocaleAliasTest::TestUResourceBundle() {
|
|||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
for (int i=0; i<_LOCALE_NUMBER; i++) {
|
||||
Locale* oldLoc = new Locale(_LOCALE_ALIAS[i][0]);
|
||||
Locale* newLoc = new Locale(_LOCALE_ALIAS[i][1]);
|
||||
Locale oldLoc(_LOCALE_ALIAS[i][0]);
|
||||
Locale newLoc(_LOCALE_ALIAS[i][1]);
|
||||
if(!isLocaleAvailable(_LOCALE_ALIAS[i][1])){
|
||||
logln(UnicodeString(newLoc->getName())+" is not available. Skipping!");
|
||||
logln(UnicodeString(newLoc.getName())+" is not available. Skipping!");
|
||||
continue;
|
||||
}
|
||||
logln("\nold locale:%s new locale:%s",oldLoc->getName(),newLoc->getName());
|
||||
logln("\nold locale:%s new locale:%s",oldLoc.getName(),newLoc.getName());
|
||||
|
||||
ResourceBundle* rb1 = NULL;
|
||||
ResourceBundle* rb2 = NULL;
|
||||
|
@ -249,19 +250,19 @@ void LocaleAliasTest::TestUResourceBundle() {
|
|||
|
||||
UnicodeString us1("NULL");
|
||||
UnicodeString us2("NULL");
|
||||
rb1 = new ResourceBundle(testdatapath, *oldLoc, status);
|
||||
rb1 = new ResourceBundle(testdatapath, oldLoc, status);
|
||||
if (U_FAILURE(U_ZERO_ERROR)) {
|
||||
|
||||
} else {
|
||||
us1 = rb1->getStringEx("locale", status);
|
||||
}
|
||||
rb2 = new ResourceBundle(testdatapath, *newLoc, status);
|
||||
rb2 = new ResourceBundle(testdatapath, newLoc, status);
|
||||
if (U_FAILURE(U_ZERO_ERROR)){
|
||||
|
||||
} else {
|
||||
us2 = rb2->getStringEx("locale", status);
|
||||
}
|
||||
UnicodeString uNewLoc(newLoc->getName());
|
||||
UnicodeString uNewLoc(newLoc.getName());
|
||||
if (us1.compare(uNewLoc)!=0 || us1.compare(us2)!=0 || status!=U_ZERO_ERROR) {
|
||||
|
||||
}
|
||||
|
@ -277,4 +278,5 @@ void LocaleAliasTest::TestUResourceBundle() {
|
|||
delete rb2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue