From 725657cd3d9796dfdc57b5a21b834f5ef5a5a9e8 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Wed, 27 Aug 2014 21:27:37 +0000 Subject: [PATCH] ICU-10477 drop already-marginal support for ULOC_REQUESTED_LOCALE X-SVN-Rev: 36252 --- icu4c/source/common/uresbund.cpp | 1 - icu4c/source/i18n/rulebasedcollator.cpp | 4 ++-- icu4c/source/test/cintltst/capitst.c | 7 +++++-- icu4c/source/test/cintltst/cmsccoll.c | 6 +++--- icu4c/source/test/cintltst/crestst.c | 6 +++--- icu4c/source/test/intltest/apicoll.cpp | 7 +++++-- icu4c/source/test/intltest/restest.cpp | 8 +++----- icu4c/source/test/intltest/svccoll.cpp | 6 ++++-- 8 files changed, 25 insertions(+), 20 deletions(-) diff --git a/icu4c/source/common/uresbund.cpp b/icu4c/source/common/uresbund.cpp index 9930657450b..266ed0af13a 100644 --- a/icu4c/source/common/uresbund.cpp +++ b/icu4c/source/common/uresbund.cpp @@ -1988,7 +1988,6 @@ ures_getLocaleByType(const UResourceBundle* resourceBundle, case ULOC_VALID_LOCALE: return resourceBundle->fTopLevelData->fName; case ULOC_REQUESTED_LOCALE: - return NULL; default: *status = U_ILLEGAL_ARGUMENT_ERROR; return NULL; diff --git a/icu4c/source/i18n/rulebasedcollator.cpp b/icu4c/source/i18n/rulebasedcollator.cpp index 538da7d56ce..ca86453644e 100644 --- a/icu4c/source/i18n/rulebasedcollator.cpp +++ b/icu4c/source/i18n/rulebasedcollator.cpp @@ -310,8 +310,8 @@ RuleBasedCollator::getLocale(ULocDataLocaleType type, UErrorCode& errorCode) con case ULOC_ACTUAL_LOCALE: return actualLocaleIsSameAsValid ? validLocale : tailoring->actualLocale; case ULOC_VALID_LOCALE: - case ULOC_REQUESTED_LOCALE: // TODO: Drop this, see ticket #10477. return validLocale; + case ULOC_REQUESTED_LOCALE: default: errorCode = U_ILLEGAL_ARGUMENT_ERROR; return Locale::getRoot(); @@ -329,9 +329,9 @@ RuleBasedCollator::internalGetLocaleID(ULocDataLocaleType type, UErrorCode &erro result = actualLocaleIsSameAsValid ? &validLocale : &tailoring->actualLocale; break; case ULOC_VALID_LOCALE: - case ULOC_REQUESTED_LOCALE: // TODO: Drop this, see ticket #10477. result = &validLocale; break; + case ULOC_REQUESTED_LOCALE: default: errorCode = U_ILLEGAL_ARGUMENT_ERROR; return NULL; diff --git a/icu4c/source/test/cintltst/capitst.c b/icu4c/source/test/cintltst/capitst.c index 6457fa161d5..b85b95ca796 100644 --- a/icu4c/source/test/cintltst/capitst.c +++ b/icu4c/source/test/cintltst/capitst.c @@ -1432,9 +1432,11 @@ void TestGetLocale() { * or may not be supported at all. See ticket #10477. */ locale = ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status); - if(strcmp(locale, testStruct[i].requestedLocale) != 0 && strcmp(locale, testStruct[i].validLocale) != 0) { + if(U_SUCCESS(status) && + strcmp(locale, testStruct[i].requestedLocale) != 0 && strcmp(locale, testStruct[i].validLocale) != 0) { log_err("[Coll %s]: Error in requested locale, expected %s, got %s\n", testStruct[i].requestedLocale, testStruct[i].requestedLocale, locale); } + status = U_ZERO_ERROR; locale = ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status); if(strcmp(locale, testStruct[i].validLocale) != 0) { log_err("[Coll %s]: Error in valid locale, expected %s, got %s\n", testStruct[i].requestedLocale, testStruct[i].validLocale, locale); @@ -1477,9 +1479,10 @@ void TestGetLocale() { /* collator instantiated from rules should have all three locales NULL */ coll = ucol_openRules(rlz, rlzLen, UCOL_DEFAULT, UCOL_DEFAULT, NULL, &status); locale = ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status); - if(locale != NULL) { + if(U_SUCCESS(status) && locale != NULL) { log_err("For collator instantiated from rules, requested locale returned %s instead of NULL\n", locale); } + status = U_ZERO_ERROR; locale = ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status); if(locale != NULL) { log_err("For collator instantiated from rules, valid locale returned %s instead of NULL\n", locale); diff --git a/icu4c/source/test/cintltst/cmsccoll.c b/icu4c/source/test/cintltst/cmsccoll.c index 2f9f1746f8a..d20cd9a93ae 100644 --- a/icu4c/source/test/cintltst/cmsccoll.c +++ b/icu4c/source/test/cintltst/cmsccoll.c @@ -2783,7 +2783,7 @@ static int32_t TestEqualsForCollator(const char* locName, UCollator *source, UCo errorNo++; } ucol_close(target); - if(uprv_strcmp(ucol_getLocaleByType(source, ULOC_REQUESTED_LOCALE, &status), ucol_getLocaleByType(source, ULOC_ACTUAL_LOCALE, &status)) == 0) { + if(uprv_strcmp(locName, ucol_getLocaleByType(source, ULOC_ACTUAL_LOCALE, &status)) == 0) { target = ucol_safeClone(source, NULL, NULL, &status); if(U_FAILURE(status)) { log_err("Error creating clone\n"); @@ -2886,8 +2886,8 @@ static void TestEquals(void) { if(!ucol_equals(source, source)) { log_err("Same collator not equal\n"); } - if(TestEqualsForCollator(locName, source, target)) { - log_err("Errors for root\n", locName); + if(TestEqualsForCollator("root", source, target)) { + log_err("Errors for root\n"); } ucol_close(source); diff --git a/icu4c/source/test/cintltst/crestst.c b/icu4c/source/test/cintltst/crestst.c index 7a57a9935ca..bd7193dd301 100644 --- a/icu4c/source/test/cintltst/crestst.c +++ b/icu4c/source/test/cintltst/crestst.c @@ -996,11 +996,12 @@ static void TestGetLocaleByType(void) { status = U_ZERO_ERROR; continue; } - + locale = ures_getLocaleByType(res, ULOC_REQUESTED_LOCALE, &status); - if(locale) { + if(U_SUCCESS(status) && locale != NULL) { log_err("Requested locale should return NULL\n"); } + status = U_ZERO_ERROR; locale = ures_getLocaleByType(res, ULOC_VALID_LOCALE, &status); if(!locale || strcmp(locale, test[i].validLocale) != 0) { log_err("Expected valid locale to be %s. Got %s\n", test[i].requestedLocale, locale); @@ -1013,4 +1014,3 @@ static void TestGetLocaleByType(void) { } ures_close(res); } - diff --git a/icu4c/source/test/intltest/apicoll.cpp b/icu4c/source/test/intltest/apicoll.cpp index bbd36ca53ef..ec3a1c54eda 100644 --- a/icu4c/source/test/intltest/apicoll.cpp +++ b/icu4c/source/test/intltest/apicoll.cpp @@ -1674,11 +1674,13 @@ void CollationAPITest::TestGetLocale() { // The requested locale may be the same as the valid locale, // or may not be supported at all. See ticket #10477. locale = coll->getLocale(ULOC_REQUESTED_LOCALE, status); - if(locale != testStruct[i].requestedLocale && locale != testStruct[i].validLocale) { + if(U_SUCCESS(status) && + locale != testStruct[i].requestedLocale && locale != testStruct[i].validLocale) { errln("[Coll %s]: Error in requested locale, expected %s or %s, got %s", testStruct[i].requestedLocale, testStruct[i].requestedLocale, testStruct[i].validLocale, locale.getName()); } + status = U_ZERO_ERROR; locale = coll->getLocale(ULOC_VALID_LOCALE, status); if(locale != testStruct[i].validLocale) { errln("[Coll %s]: Error in valid locale, expected %s, got %s", @@ -1736,9 +1738,10 @@ void CollationAPITest::TestGetLocale() { /* collator instantiated from rules should have all three locales NULL */ coll = new RuleBasedCollator(rlz, status); locale = coll->getLocale(ULOC_REQUESTED_LOCALE, status); - if(!locale.isBogus()) { + if(U_SUCCESS(status) && !locale.isBogus()) { errln("For collator instantiated from rules, requested locale %s is not bogus", locale.getName()); } + status = U_ZERO_ERROR; locale = coll->getLocale(ULOC_VALID_LOCALE, status); if(!locale.isBogus()) { errln("For collator instantiated from rules, valid locale %s is not bogus", locale.getName()); diff --git a/icu4c/source/test/intltest/restest.cpp b/icu4c/source/test/intltest/restest.cpp index 0711b01ec23..530fbb7ee19 100644 --- a/icu4c/source/test/intltest/restest.cpp +++ b/icu4c/source/test/intltest/restest.cpp @@ -612,11 +612,12 @@ ResourceBundleTest::TestGetLocaleByType(void) status = U_ZERO_ERROR; continue; } - + locale = res.getLocale(ULOC_REQUESTED_LOCALE, status); - if(locale != Locale::getDefault()) { + if(U_SUCCESS(status) && locale != Locale::getDefault()) { err("Expected requested locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName()); } + status = U_ZERO_ERROR; locale = res.getLocale(ULOC_VALID_LOCALE, status); if(strcmp(locale.getName(), test[i].validLocale) != 0) { err("Expected valid locale to be %s. Got %s\n", test[i].requestedLocale, locale.getName()); @@ -627,6 +628,3 @@ ResourceBundleTest::TestGetLocaleByType(void) } } } - -//eof - diff --git a/icu4c/source/test/intltest/svccoll.cpp b/icu4c/source/test/intltest/svccoll.cpp index f9dfb5188cc..20aeb41171e 100644 --- a/icu4c/source/test/intltest/svccoll.cpp +++ b/icu4c/source/test/intltest/svccoll.cpp @@ -62,9 +62,10 @@ void CollationServiceTest::TestRegister() // The requested locale may be the same as the valid locale, // or may not be supported at all. See ticket #10477. Locale loc = ncol->getLocale(ULOC_REQUESTED_LOCALE, status); - if (loc != US_FOO && loc != US) { + if (U_SUCCESS(status) && loc != US_FOO && loc != US) { errln(UnicodeString("requested locale for en_US_FOO is not en_US_FOO nor en_US but ") + loc.getName()); } + status = U_ZERO_ERROR; loc = ncol->getLocale(ULOC_VALID_LOCALE, status); if (loc != US) { errln(UnicodeString("valid locale for en_US_FOO is not en_US but ") + loc.getName()); @@ -413,9 +414,10 @@ void CollationServiceTest::TestRegisterFactory(void) // The requested locale may be the same as the valid locale, // or may not be supported at all. See ticket #10477. Locale loc = ncol->getLocale(ULOC_REQUESTED_LOCALE, status); - if (loc != fu_FU_FOO && loc != fu_FU) { + if (U_SUCCESS(status) && loc != fu_FU_FOO && loc != fu_FU) { errln(UnicodeString("requested locale for fu_FU_FOO is not fu_FU_FOO nor fu_FU but ") + loc.getName()); } + status = U_ZERO_ERROR; loc = ncol->getLocale(ULOC_VALID_LOCALE, status); if (loc != fu_FU) { errln(UnicodeString("valid locale for fu_FU_FOO is not fu_FU but ") + loc.getName()); -- 2.40.0