ICU-3004 Make sure that tests that change the default locale, change the default locale back to its original value.

This helps to make sure that the tests are not order dependent, and that Turkish casing problems appear more easily.

X-SVN-Rev: 17004
This commit is contained in:
George Rhoten 2004-12-22 19:28:42 +00:00
parent 1b9f1f50a6
commit 56c5df7e01
6 changed files with 24 additions and 1 deletions

View file

@ -26,11 +26,13 @@ void IntlTestDecimalFormatAPI::runIndexedTest( int32_t index, UBool exec, const
if (exec) {
logln((UnicodeString)"DecimalFormat API test---"); logln((UnicodeString)"");
UErrorCode status = U_ZERO_ERROR;
Locale saveLocale;
Locale::setDefault(Locale::getEnglish(), status);
if(U_FAILURE(status)) {
errln((UnicodeString)"ERROR: Could not set default locale, test may not give correct results");
}
testAPI(/*par*/);
Locale::setDefault(saveLocale, status);
}
break;
case 1: name = "Rounding test";

View file

@ -29,11 +29,13 @@ void IntlTestDateFormatAPI::runIndexedTest( int32_t index, UBool exec, const cha
if (exec) {
logln("DateFormat API test---"); logln("");
UErrorCode status = U_ZERO_ERROR;
Locale saveLocale;
Locale::setDefault(Locale::getEnglish(), status);
if(U_FAILURE(status)) {
errln("ERROR: Could not set default locale, test may not give correct results");
}
testAPI(/*par*/);
Locale::setDefault(saveLocale, status);
}
break;

View file

@ -1136,6 +1136,8 @@ main(int argc, char* argv[])
}
}
Locale originalLocale; // Save the default locale for comparison later on.
/* TODO: Add option to call u_cleanup and rerun tests. */
if (all) {
major.runTest();
@ -1172,12 +1174,17 @@ main(int argc, char* argv[])
free(_testDataPath);
_testDataPath = 0;
Locale lastDefaultLocale;
if (originalLocale != lastDefaultLocale) {
major.errln("FAILURE: A test changed the default locale without resetting it.");
}
fprintf(stdout, "\n--------------------------------------\n");
if (major.getErrors() == 0) {
/* Call it twice to make sure that the defaults were reset. */
/* Call it before the OK message to verify proper cleanup. */
u_cleanup();
u_cleanup();
u_cleanup();
fprintf(stdout, "OK: All tests passed without error.\n");
}else{

View file

@ -1063,6 +1063,7 @@ LocaleTest::TestAtypicalLocales()
int32_t i;
UErrorCode status = U_ZERO_ERROR;
Locale saveLocale;
Locale::setDefault(Locale::getUS(), status);
for (i = 0; i < 9; ++i) {
UnicodeString name;
@ -1107,6 +1108,7 @@ LocaleTest::TestAtypicalLocales()
errln("Lookup in Bengali failed: expected \"" + bengaliDisplayNames[i]
+ "\", got \"" + name + "\"");
}
Locale::setDefault(saveLocale, status);
}
#if !UCONFIG_NO_FORMATTING
@ -1429,7 +1431,10 @@ LocaleTest::Test4147552()
"norsk (Noreg, NY)"
//"Norsk (Noreg, Nynorsk)"
};
UErrorCode status = U_ZERO_ERROR;
Locale saveLocale;
Locale::setDefault(Locale::getEnglish(), status);
for (int32_t i = 0; i < 3; ++i) {
Locale loc = locales[i];
UnicodeString temp;
@ -1441,6 +1446,7 @@ LocaleTest::Test4147552()
norwegianDisplayNames[i] + ", got " +
loc.getDisplayName(loc, temp));
}
Locale::setDefault(saveLocale, status);
}
void

View file

@ -28,22 +28,26 @@ void IntlTestNumberFormatAPI::runIndexedTest( int32_t index, UBool exec, const c
if (exec) {
logln("NumberFormat API test---"); logln("");
UErrorCode status = U_ZERO_ERROR;
Locale saveLocale;
Locale::setDefault(Locale::getEnglish(), status);
if(U_FAILURE(status)) {
errln("ERROR: Could not set default locale, test may not give correct results");
}
testAPI(/* par */);
Locale::setDefault(saveLocale, status);
}
break;
case 1: name = "NumberFormatRegistration";
if (exec) {
logln("NumberFormat Registration test---"); logln("");
UErrorCode status = U_ZERO_ERROR;
Locale saveLocale;
Locale::setDefault(Locale::getEnglish(), status);
if(U_FAILURE(status)) {
errln("ERROR: Could not set default locale, test may not give correct results");
}
testRegistration();
Locale::setDefault(saveLocale, status);
}
break;
default: name = ""; break;

View file

@ -26,11 +26,13 @@ void IntlTestSimpleDateFormatAPI::runIndexedTest( int32_t index, UBool exec, con
if (exec) {
logln("SimpleDateFormat API test---"); logln("");
UErrorCode status = U_ZERO_ERROR;
Locale saveLocale;
Locale::setDefault(Locale::getEnglish(), status);
if(U_FAILURE(status)) {
errln("ERROR: Could not set default locale, test may not give correct results");
}
testAPI(/*par*/);
Locale::setDefault(saveLocale, status);
}
break;