diff --git a/icu4c/source/test/intltest/dcfmapts.cpp b/icu4c/source/test/intltest/dcfmapts.cpp index 8a798dace9d..792385da664 100644 --- a/icu4c/source/test/intltest/dcfmapts.cpp +++ b/icu4c/source/test/intltest/dcfmapts.cpp @@ -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"; diff --git a/icu4c/source/test/intltest/dtfmapts.cpp b/icu4c/source/test/intltest/dtfmapts.cpp index 971213c2003..3c8fd4a6cab 100644 --- a/icu4c/source/test/intltest/dtfmapts.cpp +++ b/icu4c/source/test/intltest/dtfmapts.cpp @@ -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; diff --git a/icu4c/source/test/intltest/intltest.cpp b/icu4c/source/test/intltest/intltest.cpp index 7382f428324..8378b34a962 100644 --- a/icu4c/source/test/intltest/intltest.cpp +++ b/icu4c/source/test/intltest/intltest.cpp @@ -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{ diff --git a/icu4c/source/test/intltest/loctest.cpp b/icu4c/source/test/intltest/loctest.cpp index 28348ccd5bb..f945fa6c0e8 100644 --- a/icu4c/source/test/intltest/loctest.cpp +++ b/icu4c/source/test/intltest/loctest.cpp @@ -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 diff --git a/icu4c/source/test/intltest/nmfmapts.cpp b/icu4c/source/test/intltest/nmfmapts.cpp index 8d8875e02fc..e10998f2807 100644 --- a/icu4c/source/test/intltest/nmfmapts.cpp +++ b/icu4c/source/test/intltest/nmfmapts.cpp @@ -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; diff --git a/icu4c/source/test/intltest/sdtfmtts.cpp b/icu4c/source/test/intltest/sdtfmtts.cpp index 15817d5d181..fafd375fb5a 100644 --- a/icu4c/source/test/intltest/sdtfmtts.cpp +++ b/icu4c/source/test/intltest/sdtfmtts.cpp @@ -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;