2024-12-23 Bruno Haible <bruno@clisp.org>
+ setlocale tests: Test in the UTF-8 environment on native Windows.
+ * tests/test-setlocale-w32utf8.sh: New file.
+ * tests/test-setlocale-w32utf8.c: New file.
+ * modules/setlocale-tests (Files): Add these files and
+ m4/windows-rc.m4, tests/windows-utf8.rc, tests/windows-utf8.manifest.
+ (Depends-on): Add test-xfail.
+ (configure.ac): Invoke gl_WINDOWS_RC.
+ (Makefile.am): Arrange to compile test-setlocale-w32utf8 and run
+ test-setlocale-w32utf8.sh.
+
setlocale: Support the UTF-8 environment on native Windows.
* lib/setlocale.c: Include <windows.h>.
(setlocale_unixlike): In the UTF-8 environment, append a suffix ".65001"
tests/test-setlocale2.sh
tests/test-setlocale2.c
tests/test-setlocale-w32.c
+tests/test-setlocale-w32utf8.sh
+tests/test-setlocale-w32utf8.c
+tests/windows-utf8.rc
+tests/windows-utf8.manifest
tests/signature.h
tests/macros.h
m4/locale-fr.m4
m4/locale-ja.m4
m4/locale-zh.m4
m4/codeset.m4
+m4/windows-rc.m4
Depends-on:
strdup
+test-xfail
configure.ac:
gt_LOCALE_FR
gt_LOCALE_FR_UTF8
gt_LOCALE_JA
gt_LOCALE_ZH_CN
+gl_WINDOWS_RC
Makefile.am:
TESTS += test-setlocale1.sh test-setlocale2.sh test-setlocale-w32
test_setlocale1_LDADD = $(LDADD) @SETLOCALE_LIB@
test_setlocale2_LDADD = $(LDADD) @SETLOCALE_LIB@
test_setlocale_w32_LDADD = $(LDADD) @SETLOCALE_LIB@
+
+if OS_IS_NATIVE_WINDOWS
+TESTS += test-setlocale-w32utf8.sh
+noinst_PROGRAMS += test-setlocale-w32utf8
+test_setlocale_w32utf8_LDADD = $(LDADD) test-setlocale-windows-utf8.res $(SETLOCALE_LIB)
+test-setlocale-windows-utf8.res : $(srcdir)/windows-utf8.rc
+ $(WINDRES) -i $(srcdir)/windows-utf8.rc -o test-setlocale-windows-utf8.res --output-format=coff
+MOSTLYCLEANFILES += test-setlocale-windows-utf8.res
+endif
--- /dev/null
+/* Test of setting the current locale
+ on native Windows in the UTF-8 environment.
+ Copyright (C) 2024 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2024. */
+
+#include <config.h>
+
+#include <locale.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+main (void)
+{
+#ifdef _UCRT
+ /* Test that setlocale() works as expected in a UTF-8 locale. */
+ char *name;
+
+ /* This looks at all LC_*, LANG environment variables, which are all unset
+ at this point. */
+ if (setlocale (LC_ALL, "") == NULL)
+ return 1;
+
+ name = setlocale (LC_ALL, NULL);
+ /* With the legacy system settings, expect some mixed locale, due to the
+ limitations of the native setlocale().
+ With the modern system settings, expect some "ll_CC.UTF-8" name. */
+ if (!((strlen (name) > 6 && strcmp (name + strlen (name) - 6, ".UTF-8") == 0)
+ || strcmp (name, "LC_COLLATE=English_United States.65001;"
+ "LC_CTYPE=English_United States.65001;"
+ "LC_MONETARY=English_United States.65001;"
+ "LC_NUMERIC=English_United States.65001;"
+ "LC_TIME=English_United States.65001;"
+ "LC_MESSAGES=C.UTF-8")
+ == 0
+ || strcmp (name, "LC_COLLATE=English_United States.utf8;"
+ "LC_CTYPE=English_United States.utf8;"
+ "LC_MONETARY=English_United States.utf8;"
+ "LC_NUMERIC=English_United States.utf8;"
+ "LC_TIME=English_United States.utf8;"
+ "LC_MESSAGES=C.UTF-8")
+ == 0))
+ {
+ fprintf (stderr, "setlocale() returned \"%s\".\n", name);
+ exit (1);
+ }
+
+ return 0;
+#else
+ fputs ("Skipping test: not using the UCRT runtime\n", stderr);
+ return 77;
+#endif
+}