* 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.
2024-12-23 Bruno Haible <bruno@clisp.org>
+ 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".
--- /dev/null
+# 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
+])
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
--- /dev/null
+/* 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 <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2024. */
+
+#include <config.h>
+
+#include "localcharset.h"
+
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+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
+}
--- /dev/null
+#!/bin/sh
+
+# Test the UTF-8 environment on native Windows.
+unset LC_ALL
+unset LC_CTYPE
+unset LANG
+${CHECKER} ./test-localcharset-w32utf8${EXEEXT}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!-- This file is in the public domain. -->
+
+<!-- This file is an application manifest that has the effect that in the
+ application, GetACP () == 65001 instead of e.g. 1252.
+ Documentation:
+ https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests#activeCodePage
+ https://learn.microsoft.com/en-us/windows/apps/design/globalizing/use-utf8-code-page
+ XML schema that this file needs to obey:
+ https://learn.microsoft.com/en-us/windows/win32/sbscs/manifest-file-schema
+ It is supposed to work in Windows 10 version 1903 or newer,
+ when the UCRT runtime is in use (as opposed to old MSVCRT).
+-->
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+ <application xmlns="urn:schemas-microsoft-com:asm.v3">
+ <windowsSettings>
+ <activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
+ </windowsSettings>
+ </application>
+</assembly>
--- /dev/null
+/* 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 <winresrc.h> /* includes <winuser.h>, <winver.h> */
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "windows-utf8.manifest"