ICU-20808 Add test for the C locale to default to en_US_POSIX
diff --git a/.ci-builds/.azure-pipelines.yml b/.ci-builds/.azure-pipelines.yml
index 4e9039c..9e5e37c 100644
--- a/.ci-builds/.azure-pipelines.yml
+++ b/.ci-builds/.azure-pipelines.yml
@@ -37,6 +37,12 @@
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 b6bc201..f9642af 100644
--- a/icu4c/source/test/cintltst/cloctst.c
+++ b/icu4c/source/test/cintltst/cloctst.c
@@ -261,6 +261,7 @@
TESTCASE(TestToLanguageTag);
TESTCASE(TestBug20132);
TESTCASE(TestBug20149);
+ TESTCASE(TestCDefaultLocale);
TESTCASE(TestForLanguageTag);
TESTCASE(TestLangAndRegionCanonicalize);
TESTCASE(TestTrailingNull);
@@ -409,6 +410,10 @@
}
}
+ 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 @@
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 6f03ce6..c1529b0 100644
--- a/icu4c/source/test/cintltst/cloctst.h
+++ b/icu4c/source/test/cintltst/cloctst.h
@@ -136,6 +136,8 @@
static void TestToUnicodeLocaleType(void);
static void TestToLegacyType(void);
static void TestBug20149(void);
+static void TestCDefaultLocale(void);
+
/**
* U_USING_DEFAULT_WARNING