From a5c87eca2b85c624582eabeb6b409dc6fb50bfbd Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 23 Dec 2024 16:56:37 +0100 Subject: [PATCH] localcharset tests: Test in the UTF-8 environment on native Windows. * m4/windows-rc.m4: New file. * tests/test-localcharset-w32utf8.sh: New file. * tests/test-localcharset-w32utf8.c: New file. * tests/windows-utf8.rc: New file. * tests/windows-utf8.manifest: New file. * modules/localcharset-tests (Files): Add these files. (Depends-on): Add test-xfail. (configure.ac): Invoke gl_WINDOWS_RC. (Makefile.am): Arrange to compile test-localcharset-w32utf8 and run test-localcharset-w32utf8.sh. --- ChangeLog | 12 ++++++ m4/windows-rc.m4 | 21 ++++++++++ modules/localcharset-tests | 16 ++++++++ tests/test-localcharset-w32utf8.c | 61 ++++++++++++++++++++++++++++++ tests/test-localcharset-w32utf8.sh | 7 ++++ tests/windows-utf8.manifest | 20 ++++++++++ tests/windows-utf8.rc | 9 +++++ 7 files changed, 146 insertions(+) create mode 100644 m4/windows-rc.m4 create mode 100644 tests/test-localcharset-w32utf8.c create mode 100755 tests/test-localcharset-w32utf8.sh create mode 100644 tests/windows-utf8.manifest create mode 100644 tests/windows-utf8.rc diff --git a/ChangeLog b/ChangeLog index 1ac323da3e..bb9f076353 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2024-12-23 Bruno Haible + localcharset tests: Test in the UTF-8 environment on native Windows. + * m4/windows-rc.m4: New file. + * tests/test-localcharset-w32utf8.sh: New file. + * tests/test-localcharset-w32utf8.c: New file. + * tests/windows-utf8.rc: New file. + * tests/windows-utf8.manifest: New file. + * modules/localcharset-tests (Files): Add these files. + (Depends-on): Add test-xfail. + (configure.ac): Invoke gl_WINDOWS_RC. + (Makefile.am): Arrange to compile test-localcharset-w32utf8 and run + test-localcharset-w32utf8.sh. + localcharset: Support the UTF-8 environment on native Windows. * lib/localcharset.c (locale_charset): Recognize also the special case of a setlocale() result that ends in ".UTF-8". diff --git a/m4/windows-rc.m4 b/m4/windows-rc.m4 new file mode 100644 index 0000000000..8a4deb14b8 --- /dev/null +++ b/m4/windows-rc.m4 @@ -0,0 +1,21 @@ +# windows-rc.m4 +# serial 1 +dnl Copyright (C) 2024 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl This file is offered as-is, without any warranty. + +dnl Find the tool that "compiles" a Windows resource file (.rc) to an +dnl object file. + +AC_DEFUN_ONCE([gl_WINDOWS_RC], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) + case "$host_os" in + mingw* | windows*) + dnl Check for a program that compiles Windows resource files. + AC_CHECK_TOOL([WINDRES], [windres]) + ;; + esac +]) diff --git a/modules/localcharset-tests b/modules/localcharset-tests index 3f2dde6dfd..a171c0cfbf 100644 --- a/modules/localcharset-tests +++ b/modules/localcharset-tests @@ -1,11 +1,27 @@ Files: tests/test-localcharset.c +tests/test-localcharset-w32utf8.sh +tests/test-localcharset-w32utf8.c +tests/windows-utf8.rc +tests/windows-utf8.manifest +m4/windows-rc.m4 Depends-on: setlocale +test-xfail configure.ac: +gl_WINDOWS_RC Makefile.am: noinst_PROGRAMS += test-localcharset test_localcharset_LDADD = $(LDADD) $(SETLOCALE_LIB) + +if OS_IS_NATIVE_WINDOWS +TESTS += test-localcharset-w32utf8.sh +noinst_PROGRAMS += test-localcharset-w32utf8 +test_localcharset_w32utf8_LDADD = $(LDADD) test-localcharset-windows-utf8.res $(SETLOCALE_LIB) +test-localcharset-windows-utf8.res : $(srcdir)/windows-utf8.rc + $(WINDRES) -i $(srcdir)/windows-utf8.rc -o test-localcharset-windows-utf8.res --output-format=coff +MOSTLYCLEANFILES += test-localcharset-windows-utf8.res +endif diff --git a/tests/test-localcharset-w32utf8.c b/tests/test-localcharset-w32utf8.c new file mode 100644 index 0000000000..f40db9c397 --- /dev/null +++ b/tests/test-localcharset-w32utf8.c @@ -0,0 +1,61 @@ +/* Test of localcharset() function + 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 "localcharset.h" + +#include +#include +#include +#include + +#define WIN32_LEAN_AND_MEAN +#include + +int +main (void) +{ +#ifdef _UCRT + unsigned int active_codepage = GetACP (); + if (!(active_codepage == 65001)) + { + fprintf (stderr, + "The active codepage is %u, not 65001 as expected.\n" + "(This is normal on Windows older than Windows 10.)\n", + active_codepage); + exit (1); + } + + setlocale (LC_ALL, ""); + const char *lc = locale_charset (); + if (!(strcmp (lc, "UTF-8") == 0)) + { + fprintf (stderr, + "locale_charset () is \"%s\", not \"UTF-8\" as expected.\n", + lc); + exit (1); + } + + return 0; +#else + fputs ("Skipping test: not using the UCRT runtime\n", stderr); + return 77; +#endif +} diff --git a/tests/test-localcharset-w32utf8.sh b/tests/test-localcharset-w32utf8.sh new file mode 100755 index 0000000000..1e6a95b545 --- /dev/null +++ b/tests/test-localcharset-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-localcharset-w32utf8${EXEEXT} diff --git a/tests/windows-utf8.manifest b/tests/windows-utf8.manifest new file mode 100644 index 0000000000..3a43a70c6d --- /dev/null +++ b/tests/windows-utf8.manifest @@ -0,0 +1,20 @@ + + + + + + + + UTF-8 + + + diff --git a/tests/windows-utf8.rc b/tests/windows-utf8.rc new file mode 100644 index 0000000000..110241aa16 --- /dev/null +++ b/tests/windows-utf8.rc @@ -0,0 +1,9 @@ +/* This file is in the public domain. */ + +/* This file is a resource definition file. + When compiled to an object file, it embeds the windows-utf8.manifest file, + that has the effect that in the application, GetACP () == 65001 instead + of e.g. 1252. */ + +#include /* includes , */ +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "windows-utf8.manifest" -- 2.39.5