>From 2f4391fde8620749fb3859c568f952a958e2ca2c Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 23 Dec 2024 16:58:53 +0100 Subject: [PATCH 6/7] 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. --- ChangeLog | 10 +++++ modules/setlocale-tests | 16 ++++++++ tests/test-setlocale-w32utf8.c | 69 +++++++++++++++++++++++++++++++++ tests/test-setlocale-w32utf8.sh | 12 ++++++ 4 files changed, 107 insertions(+) create mode 100644 tests/test-setlocale-w32utf8.c create mode 100755 tests/test-setlocale-w32utf8.sh diff --git a/ChangeLog b/ChangeLog index 9f89cb8718..c5e2e8b1b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2024-12-23 Bruno Haible + 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 . (setlocale_unixlike): In the UTF-8 environment, append a suffix ".65001" diff --git a/modules/setlocale-tests b/modules/setlocale-tests index ad0a536bc6..23cc6ddd17 100644 --- a/modules/setlocale-tests +++ b/modules/setlocale-tests @@ -4,21 +4,28 @@ tests/test-setlocale1.c 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 @@ -31,3 +38,12 @@ check_PROGRAMS += test-setlocale1 test-setlocale2 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 diff --git a/tests/test-setlocale-w32utf8.c b/tests/test-setlocale-w32utf8.c new file mode 100644 index 0000000000..f0bbce05b7 --- /dev/null +++ b/tests/test-setlocale-w32utf8.c @@ -0,0 +1,69 @@ +/* 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 . */ + +/* Written by Bruno Haible , 2024. */ + +#include + +#include + +#include +#include +#include + +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 +} diff --git a/tests/test-setlocale-w32utf8.sh b/tests/test-setlocale-w32utf8.sh new file mode 100755 index 0000000000..e8f7484cf0 --- /dev/null +++ b/tests/test-setlocale-w32utf8.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Test the UTF-8 environment on native Windows. +unset LC_ALL +unset LC_CTYPE +unset LC_MESSAGES +unset LC_NUMERIC +unset LC_COLLATE +unset LC_MONETARY +unset LC_TIME +unset LANG +${CHECKER} ./test-setlocale-w32utf8${EXEEXT} -- 2.43.0