From a7a8cc38092d5ff21e8ae136c781f32d497e834b Mon Sep 17 00:00:00 2001 From: Erik Torres <26077674+erik0686@users.noreply.github.com> Date: Wed, 12 Aug 2020 19:28:32 +0000 Subject: [PATCH] ICU-20808 Add test for the C locale to default to en_US_POSIX --- .ci-builds/.azure-pipelines.yml | 6 ++++++ icu4c/source/test/cintltst/cloctst.c | 19 +++++++++++++++++++ icu4c/source/test/cintltst/cloctst.h | 2 ++ 3 files changed, 27 insertions(+) diff --git a/.ci-builds/.azure-pipelines.yml b/.ci-builds/.azure-pipelines.yml index 4e9039c9583..9e5e37c723a 100644 --- a/.ci-builds/.azure-pipelines.yml +++ b/.ci-builds/.azure-pipelines.yml @@ -37,6 +37,12 @@ jobs: env: CC: clang CXX: clang++ + - script: | + cd icu4c/source/test/cintltst && LANG=C LD_LIBRARY_PATH=../../lib:../../tools/ctestfw ./cintltst /tsutil/cloctst/TestCDefaultLocale + displayName: 'Test C Default locale' + - script: | + cd icu4c/source/test/cintltst && LANG=C.UTF-8 LD_LIBRARY_PATH=../../lib:../../tools/ctestfw ./cintltst /tsutil/cloctst/TestCDefaultLocale + displayName: 'Test C.UTF-8 Default locale' #------------------------------------------------------------------------- - job: ICU4C_Clang_Ubuntu_1604_WarningsAsErrors displayName: 'C: Linux Clang WarningsAsErrors (Ubuntu 16.04)' diff --git a/icu4c/source/test/cintltst/cloctst.c b/icu4c/source/test/cintltst/cloctst.c index b6bc201034f..f9642afe065 100644 --- a/icu4c/source/test/cintltst/cloctst.c +++ b/icu4c/source/test/cintltst/cloctst.c @@ -261,6 +261,7 @@ void addLocaleTest(TestNode** root) TESTCASE(TestToLanguageTag); TESTCASE(TestBug20132); TESTCASE(TestBug20149); + TESTCASE(TestCDefaultLocale); TESTCASE(TestForLanguageTag); TESTCASE(TestLangAndRegionCanonicalize); TESTCASE(TestTrailingNull); @@ -409,6 +410,10 @@ static void TestNullDefault() { } } + uloc_setDefault(original, &status); + if (U_FAILURE(status)) { + log_err("Failed to change the default locale back to %s\n", original); + } } /* Test the i- and x- and @ and . functionality @@ -6812,5 +6817,19 @@ static void TestUsingDefaultWarning() { u_UCharsToChars(buff, errorOutputBuff, length+1); log_err("ERROR: in uloc_getDisplayKeywordValue %s %s return len:%d %s with status %d %s\n", keyword_value, keyword, length, errorOutputBuff, status, myErrorName(status)); + } +} +// Test case for ICU-20575 +// This test checks if the environment variable LANG is set, +// and if so ensures that both C and C.UTF-8 cause ICU's default locale to be en_US_POSIX. +static void TestCDefaultLocale(){ + const char *defaultLocale = uloc_getDefault(); + char *env_var = getenv("LANG"); + if (env_var == NULL) { + log_verbose("Skipping TestCDefaultLocale test, as the LANG variable is not set."); + return; + } + if ((strcmp(env_var, "C") == 0 || strcmp(env_var, "C.UTF-8") == 0) && strcmp(defaultLocale, "en_US_POSIX") != 0) { + log_err("The default locale for LANG=%s should be en_US_POSIX, not %s\n", env_var, defaultLocale); } } diff --git a/icu4c/source/test/cintltst/cloctst.h b/icu4c/source/test/cintltst/cloctst.h index 6f03ce620ca..c1529b0c0c7 100644 --- a/icu4c/source/test/cintltst/cloctst.h +++ b/icu4c/source/test/cintltst/cloctst.h @@ -136,6 +136,8 @@ static void TestToLegacyKey(void); static void TestToUnicodeLocaleType(void); static void TestToLegacyType(void); static void TestBug20149(void); +static void TestCDefaultLocale(void); + /** * U_USING_DEFAULT_WARNING -- 2.40.0