From 3bdb509ac56206fefacfcbbdecd1ccde7ccf9078 Mon Sep 17 00:00:00 2001 From: Shane Carr Date: Mon, 10 Jun 2019 19:16:37 -0700 Subject: [PATCH] ICU-20661 Adding test that (U)Locale constructor accepts BCP47. --- icu4c/source/test/intltest/loctest.cpp | 40 +++++++++++++++++++ icu4c/source/test/intltest/loctest.h | 1 + .../ibm/icu/dev/test/util/ULocaleTest.java | 20 ++++++++++ 3 files changed, 61 insertions(+) diff --git a/icu4c/source/test/intltest/loctest.cpp b/icu4c/source/test/intltest/loctest.cpp index ee946569c6..79cb887c83 100644 --- a/icu4c/source/test/intltest/loctest.cpp +++ b/icu4c/source/test/intltest/loctest.cpp @@ -253,6 +253,7 @@ void LocaleTest::runIndexedTest( int32_t index, UBool exec, const char* &name, c TESTCASE_AUTO(TestBug13277); TESTCASE_AUTO(TestBug13554); TESTCASE_AUTO(TestBug20410); + TESTCASE_AUTO(TestConstructorAcceptsBCP47); TESTCASE_AUTO(TestForLanguageTag); TESTCASE_AUTO(TestToLanguageTag); TESTCASE_AUTO(TestMoveAssign); @@ -3078,6 +3079,45 @@ void LocaleTest::TestBug20410() { assertEquals(locid4, expected4.getName(), result4.getName()); } +void LocaleTest::TestConstructorAcceptsBCP47() { + IcuTestErrorCode status(*this, "TestConstructorAcceptsBCP47"); + + Locale loc1("ar-EG-u-nu-latn"); + Locale loc2("ar-EG@numbers=latn"); + Locale loc3("ar-EG"); + std::string val; + + // Check getKeywordValue "numbers" + val = loc1.getKeywordValue("numbers", status); + assertEquals("BCP47 syntax has ICU keyword value", "latn", val.c_str()); + + val = loc2.getKeywordValue("numbers", status); + assertEquals("ICU syntax has ICU keyword value", "latn", val.c_str()); + + val = loc3.getKeywordValue("numbers", status); + assertEquals("Default, ICU keyword", "", val.c_str()); + + // Check getUnicodeKeywordValue "nu" + val = loc1.getUnicodeKeywordValue("nu", status); + assertEquals("BCP47 syntax has short unicode keyword value", "latn", val.c_str()); + + val = loc2.getUnicodeKeywordValue("nu", status); + assertEquals("ICU syntax has short unicode keyword value", "latn", val.c_str()); + + val = loc3.getUnicodeKeywordValue("nu", status); + status.expectErrorAndReset(U_ILLEGAL_ARGUMENT_ERROR, "Default, short unicode keyword"); + + // Check getUnicodeKeywordValue "numbers" + val = loc1.getUnicodeKeywordValue("numbers", status); + assertEquals("BCP47 syntax has long unicode keyword value", "latn", val.c_str()); + + val = loc2.getUnicodeKeywordValue("numbers", status); + assertEquals("ICU syntax has long unicode keyword value", "latn", val.c_str()); + + val = loc3.getUnicodeKeywordValue("numbers", status); + status.expectErrorAndReset(U_ILLEGAL_ARGUMENT_ERROR, "Default, long unicode keyword"); +} + void LocaleTest::TestForLanguageTag() { IcuTestErrorCode status(*this, "TestForLanguageTag()"); diff --git a/icu4c/source/test/intltest/loctest.h b/icu4c/source/test/intltest/loctest.h index 2771419ffc..6b6b3a61e0 100644 --- a/icu4c/source/test/intltest/loctest.h +++ b/icu4c/source/test/intltest/loctest.h @@ -117,6 +117,7 @@ public: void TestBug13277(); void TestBug13554(); void TestBug20410(); + void TestConstructorAcceptsBCP47(); void TestAddLikelySubtags(); void TestMinimizeSubtags(); diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java index be4564a9e7..e71a8332cf 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java @@ -4138,6 +4138,26 @@ public class ULocaleTest extends TestFmwk { assertEquals("getExtension(\'0\')", "abc", uloc.getExtension('0')); } + @Test + public void TestConstructorAcceptsBCP47() { + ULocale loc1 = new ULocale("ar-EG-u-nu-latn"); + ULocale loc2 = new ULocale("ar-EG@numbers=latn"); + ULocale loc3 = new ULocale("ar-EG"); + String val; + + // Check getKeywordValue "numbers" + val = loc1.getKeywordValue("numbers"); + assertEquals("BCP47 syntax has ICU keyword value", "latn", val); + + val = loc2.getKeywordValue("numbers"); + assertEquals("ICU syntax has ICU keyword value", "latn", val); + + val = loc3.getKeywordValue("numbers"); + assertEquals("Default, ICU keyword", null, val); + + // Note: ICU does not have getUnicodeKeywordValue() + } + @Test public void TestForLanguageTag() { final Integer NOERROR = Integer.valueOf(-1);