From: Frank Tang Date: Fri, 31 Jul 2020 06:37:31 +0000 (+0000) Subject: ICU-21158 Fix doc of UDISPCTX_NO_SUBSTITUTE X-Git-Tag: cldr/2020-09-22~151 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ca80c4b6d7c5dace5cad2e020726bc365a5a908;p=icu ICU-21158 Fix doc of UDISPCTX_NO_SUBSTITUTE See #1200 --- diff --git a/icu4c/source/common/unicode/udisplaycontext.h b/icu4c/source/common/unicode/udisplaycontext.h index 398481c6812..6e142179805 100644 --- a/icu4c/source/common/unicode/udisplaycontext.h +++ b/icu4c/source/common/unicode/udisplaycontext.h @@ -156,7 +156,8 @@ enum UDisplayContext { UDISPCTX_SUBSTITUTE = (UDISPCTX_TYPE_SUBSTITUTE_HANDLING<<8) + 0, /** * A possible setting for SUBSTITUTE_HANDLING: - * Returns a null value when no data is available. + * Returns a null value with error code set to U_ILLEGAL_ARGUMENT_ERROR when no + * data is available. * @stable ICU 58 */ UDISPCTX_NO_SUBSTITUTE = (UDISPCTX_TYPE_SUBSTITUTE_HANDLING<<8) + 1 diff --git a/icu4c/source/test/cintltst/cloctst.c b/icu4c/source/test/cintltst/cloctst.c index 2dc4a08cd38..bc87be0ce17 100644 --- a/icu4c/source/test/cintltst/cloctst.c +++ b/icu4c/source/test/cintltst/cloctst.c @@ -47,6 +47,7 @@ static void TestLocDataErrorCodeChaining(void); static void TestLocDataWithRgTag(void); static void TestLanguageExemplarsFallbacks(void); static void TestDisplayNameBrackets(void); +static void TestIllegalArgumentWhenNoDataWithNoSubstitute(void); static void TestUnicodeDefines(void); @@ -264,6 +265,7 @@ void addLocaleTest(TestNode** root) TESTCASE(TestUnicodeDefines); TESTCASE(TestEnglishExemplarCharacters); TESTCASE(TestDisplayNameBrackets); + TESTCASE(TestIllegalArgumentWhenNoDataWithNoSubstitute); TESTCASE(TestIsRightToLeft); TESTCASE(TestToUnicodeLocaleKey); TESTCASE(TestToLegacyKey); @@ -1215,6 +1217,70 @@ static void TestDisplayNameBrackets() } } +/*------------------------------ + * TestIllegalArgumentWhenNoDataWithNoSubstitute + */ + +static void TestIllegalArgumentWhenNoDataWithNoSubstitute() +{ + UErrorCode status = U_ZERO_ERROR; + UChar getName[kDisplayNameBracketsMax]; + UDisplayContext contexts[] = { + UDISPCTX_NO_SUBSTITUTE, + }; + ULocaleDisplayNames* ldn = uldn_openForContext("en", contexts, 1, &status); + + uldn_localeDisplayName(ldn, "efg", getName, kDisplayNameBracketsMax, &status); + if (status != U_ILLEGAL_ARGUMENT_ERROR) { + log_err("FAIL uldn_localeDisplayName should return U_ILLEGAL_ARGUMENT_ERROR " + "while no resource under UDISPCTX_NO_SUBSTITUTE"); + } + + status = U_ZERO_ERROR; + uldn_languageDisplayName(ldn, "zz", getName, kDisplayNameBracketsMax, &status); + if (status != U_ILLEGAL_ARGUMENT_ERROR) { + log_err("FAIL uldn_languageDisplayName should return U_ILLEGAL_ARGUMENT_ERROR " + "while no resource under UDISPCTX_NO_SUBSTITUTE"); + } + + status = U_ZERO_ERROR; + uldn_scriptDisplayName(ldn, "Aaaa", getName, kDisplayNameBracketsMax, &status); + if (status != U_ILLEGAL_ARGUMENT_ERROR) { + log_err("FAIL uldn_scriptDisplayName should return U_ILLEGAL_ARGUMENT_ERROR " + "while no resource under UDISPCTX_NO_SUBSTITUTE"); + } + + status = U_ZERO_ERROR; + uldn_regionDisplayName(ldn, "KK", getName, kDisplayNameBracketsMax, &status); + if (status != U_ILLEGAL_ARGUMENT_ERROR) { + log_err("FAIL uldn_regionDisplayName should return U_ILLEGAL_ARGUMENT_ERROR " + "while no resource under UDISPCTX_NO_SUBSTITUTE"); + } + + status = U_ZERO_ERROR; + uldn_variantDisplayName(ldn, "ZZ", getName, kDisplayNameBracketsMax, &status); + if (status != U_ILLEGAL_ARGUMENT_ERROR) { + log_err("FAIL uldn_variantDisplayName should return U_ILLEGAL_ARGUMENT_ERROR " + "while no resource under UDISPCTX_NO_SUBSTITUTE"); + } + + status = U_ZERO_ERROR; + uldn_keyDisplayName(ldn, "zz", getName, kDisplayNameBracketsMax, &status); + if (status != U_ILLEGAL_ARGUMENT_ERROR) { + log_err("FAIL uldn_keyDisplayName should return U_ILLEGAL_ARGUMENT_ERROR " + "while no resource under UDISPCTX_NO_SUBSTITUTE"); + } + + status = U_ZERO_ERROR; + uldn_keyValueDisplayName(ldn, "ca", "zz", getName, kDisplayNameBracketsMax, &status); + if (status != U_ILLEGAL_ARGUMENT_ERROR) { + log_err("FAIL uldn_keyValueDisplayName should return U_ILLEGAL_ARGUMENT_ERROR " + "while no resource under UDISPCTX_NO_SUBSTITUTE"); + } + + uldn_close(ldn); +} + /*------------------------------ * TestISOFunctions */