From 09fb90f3f14038c6b0b1565cc308e75f64f4bb53 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Fri, 30 Jun 2023 18:12:22 -0700 Subject: [PATCH] ICU-22365 Add more tests --- icu4c/source/test/cintltst/ulocbuildertst.c | 41 ++++++++++++--------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/icu4c/source/test/cintltst/ulocbuildertst.c b/icu4c/source/test/cintltst/ulocbuildertst.c index d8aa1b6ed576..781ff3a32eef 100644 --- a/icu4c/source/test/cintltst/ulocbuildertst.c +++ b/icu4c/source/test/cintltst/ulocbuildertst.c @@ -862,7 +862,6 @@ static void TestSetVariantIllFormed() { } } -/* static void TestSetUnicodeLocaleKeywordWellFormed() { // http://www.unicode.org/reports/tr35/tr35.html#unicode_locale_extensions // keyword = key (sep type)? ; @@ -878,16 +877,17 @@ static void TestSetUnicodeLocaleKeywordWellFormed() { }; for (int i = 0; i < UPRV_LENGTHOF(wellFormed_key_value); i += 2) { UErrorCode status = U_ZERO_ERROR; - LocaleBuilder bld; - bld.setUnicodeLocaleKeyword(wellFormed_key_value[i], - wellFormed_key_value[i + 1]); - Locale loc = bld.build(status); + ULocaleBuilder bld = ulb_open(); + ulb_setUnicodeLocaleKeyword(bld, wellFormed_key_value[i], wellFormed_key_value[i + 1]); + char buffer[ULOC_FULLNAME_CAPACITY]; + ulb_build(bld, buffer, ULOC_FULLNAME_CAPACITY, &status); if (U_FAILURE(status)) { - errln("setUnicodeLocaleKeyword(\"%s\", \"%s\") got Error: %s\n", + log_err("setUnicodeLocaleKeyword(\"%s\", \"%s\") got Error: %s\n", wellFormed_key_value[i], wellFormed_key_value[i + 1], u_errorName(status)); } + ulb_close(bld); } } @@ -900,15 +900,18 @@ static void TestSetUnicodeLocaleKeywordIllFormedKey() { "zyzabcdef", "Z0", }; - for (const char* ill : illFormed) { + for (int i = 0; i < UPRV_LENGTHOF(illFormed); i++) { + const char* ill = illFormed[i]; UErrorCode status = U_ZERO_ERROR; - LocaleBuilder bld; - bld.setUnicodeLocaleKeyword(ill, "abc"); - Locale loc = bld.build(status); + ULocaleBuilder bld = ulb_open(); + ulb_setUnicodeLocaleKeyword(bld, ill, "abc"); + char buffer[ULOC_FULLNAME_CAPACITY]; + ulb_build(bld, buffer, ULOC_FULLNAME_CAPACITY, &status); if (status != U_ILLEGAL_ARGUMENT_ERROR) { - errln("setUnicodeLocaleKeyword(\"%s\", \"abc\") should fail but has no Error\n", + log_err("setUnicodeLocaleKeyword(\"%s\", \"abc\") should fail but has no Error\n", ill); } + ulb_close(bld); } } @@ -923,18 +926,22 @@ static void TestSetUnicodeLocaleKeywordIllFormedValue() { "1ZB30zfk9-abc", "2ck30zfk9-adsf023-234kcZ", }; - for (const char* ill : illFormed) { + for (int i = 0; i < UPRV_LENGTHOF(illFormed); i++) { + const char* ill = illFormed[i]; UErrorCode status = U_ZERO_ERROR; - LocaleBuilder bld; - bld.setUnicodeLocaleKeyword("ab", ill); - Locale loc = bld.build(status); + ULocaleBuilder bld = ulb_open(); + ulb_setUnicodeLocaleKeyword(bld, "ab", ill); + char buffer[ULOC_FULLNAME_CAPACITY]; + ulb_build(bld, buffer, ULOC_FULLNAME_CAPACITY, &status); if (status != U_ILLEGAL_ARGUMENT_ERROR) { - errln("setUnicodeLocaleKeyword(\"ab\", \"%s\") should fail but has no Error\n", + log_err("setUnicodeLocaleKeyword(\"ab\", \"%s\") should fail but has no Error\n", ill); } + ulb_close(bld); } } +/* static void TestAddRemoveUnicodeLocaleAttribute() { LocaleBuilder bld; UErrorCode status = U_ZERO_ERROR; @@ -1693,10 +1700,10 @@ void addLocaleBuilderTest(TestNode** root) TESTCASE(TestSetRegionIllFormed); TESTCASE(TestSetVariantWellFormed); TESTCASE(TestSetVariantIllFormed); - /* TESTCASE(TestSetUnicodeLocaleKeywordWellFormed); TESTCASE(TestSetUnicodeLocaleKeywordIllFormedKey); TESTCASE(TestSetUnicodeLocaleKeywordIllFormedValue); + /* TESTCASE(TestAddRemoveUnicodeLocaleAttribute); TESTCASE(TestAddRemoveUnicodeLocaleAttributeWellFormed); TESTCASE(TestAddUnicodeLocaleAttributeIllFormed);