>From e63eea8ea358041610c3f9a9ed4d5a1e44be5cc4 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 23 Dec 2024 16:57:02 +0100 Subject: [PATCH 4/7] localename tests: Test in the UTF-8 environment on native Windows. * tests/test-localename-w32utf8.sh: New file. * tests/test-localename-w32utf8.c: New file. * modules/localename-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-localename-w32utf8 and run test-localename-w32utf8.sh. --- ChangeLog | 10 +++++++ modules/localename-tests | 15 ++++++++++ tests/test-localename-w32utf8.c | 47 ++++++++++++++++++++++++++++++++ tests/test-localename-w32utf8.sh | 7 +++++ 4 files changed, 79 insertions(+) create mode 100644 tests/test-localename-w32utf8.c create mode 100755 tests/test-localename-w32utf8.sh diff --git a/ChangeLog b/ChangeLog index d9f282c21e..fd3cf9f7ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2024-12-23 Bruno Haible + localename tests: Test in the UTF-8 environment on native Windows. + * tests/test-localename-w32utf8.sh: New file. + * tests/test-localename-w32utf8.c: New file. + * modules/localename-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-localename-w32utf8 and run + test-localename-w32utf8.sh. + localename-unsafe: Support the UTF-8 environment on native Windows. * lib/localename-unsafe.c (gl_locale_name_from_win32_LANGID): Append a suffix ".UTF-8" to the result if GetACP() is UTF-8. diff --git a/modules/localename-tests b/modules/localename-tests index 0c24d5b4b6..cf4d586806 100644 --- a/modules/localename-tests +++ b/modules/localename-tests @@ -1,7 +1,12 @@ Files: tests/test-localename.c +tests/test-localename-w32utf8.sh +tests/test-localename-w32utf8.c +tests/windows-utf8.rc +tests/windows-utf8.manifest tests/macros.h m4/musl.m4 +m4/windows-rc.m4 Depends-on: locale @@ -9,13 +14,23 @@ setenv unsetenv setlocale strdup +test-xfail configure.ac: gl_CHECK_FUNCS_ANDROID([newlocale], [[#include ]]) gl_MUSL_LIBC +gl_WINDOWS_RC Makefile.am: TESTS += test-localename check_PROGRAMS += test-localename test_localename_LDADD = $(LDADD) $(SETLOCALE_LIB) @INTL_MACOSX_LIBS@ $(LIBTHREAD) +if OS_IS_NATIVE_WINDOWS +TESTS += test-localename-w32utf8.sh +noinst_PROGRAMS += test-localename-w32utf8 +test_localename_w32utf8_LDADD = $(LDADD) test-localename-windows-utf8.res $(SETLOCALE_LIB) +test-localename-windows-utf8.res : $(srcdir)/windows-utf8.rc + $(WINDRES) -i $(srcdir)/windows-utf8.rc -o test-localename-windows-utf8.res --output-format=coff +MOSTLYCLEANFILES += test-localename-windows-utf8.res +endif diff --git a/tests/test-localename-w32utf8.c b/tests/test-localename-w32utf8.c new file mode 100644 index 0000000000..72a01c0749 --- /dev/null +++ b/tests/test-localename-w32utf8.c @@ -0,0 +1,47 @@ +/* Test of gl_locale_name function and its variants + 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 "localename.h" + +#include +#include + +#include "macros.h" + +int +main (void) +{ +#ifdef _UCRT + const char *name = gl_locale_name_default (); + + ASSERT (name != NULL); + + /* With the legacy system settings, expect "C.UTF-8", not "C", because "C" is + a single-byte locale. + With the modern system settings, expect some "ll_CC.UTF-8" name. */ + ASSERT (strlen (name) > 6 && strcmp (name + strlen (name)- 6, ".UTF-8") == 0); + + return test_exit_status; +#else + fputs ("Skipping test: not using the UCRT runtime\n", stderr); + return 77; +#endif +} diff --git a/tests/test-localename-w32utf8.sh b/tests/test-localename-w32utf8.sh new file mode 100755 index 0000000000..de7629c3a7 --- /dev/null +++ b/tests/test-localename-w32utf8.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# Test the UTF-8 environment on native Windows. +unset LC_ALL +unset LC_CTYPE +unset LANG +${CHECKER} ./test-localename-w32utf8${EXEEXT} -- 2.43.0