]> Savannah Git Hosting - gnulib.git/commitdiff
localcharset tests: Test in the UTF-8 environment on native Windows.
authorBruno Haible <bruno@clisp.org>
Mon, 23 Dec 2024 15:56:37 +0000 (16:56 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 23 Dec 2024 15:56:46 +0000 (16:56 +0100)
* 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
m4/windows-rc.m4 [new file with mode: 0644]
modules/localcharset-tests
tests/test-localcharset-w32utf8.c [new file with mode: 0644]
tests/test-localcharset-w32utf8.sh [new file with mode: 0755]
tests/windows-utf8.manifest [new file with mode: 0644]
tests/windows-utf8.rc [new file with mode: 0644]

index 1ac323da3e85d5a645002fe0b7c2770a800f757d..bb9f07635391c4bdab6908d8c694a9ed1210d550 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 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".
diff --git a/m4/windows-rc.m4 b/m4/windows-rc.m4
new file mode 100644 (file)
index 0000000..8a4deb1
--- /dev/null
@@ -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
+])
index 3f2dde6dfdd63578ea9aa4a1a6a352951cd4d75c..a171c0cfbfc034be9a9b9c5892400519238ab881 100644 (file)
@@ -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 (file)
index 0000000..f40db9c
--- /dev/null
@@ -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 <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
+}
diff --git a/tests/test-localcharset-w32utf8.sh b/tests/test-localcharset-w32utf8.sh
new file mode 100755 (executable)
index 0000000..1e6a95b
--- /dev/null
@@ -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 (file)
index 0000000..3a43a70
--- /dev/null
@@ -0,0 +1,20 @@
+<?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>
diff --git a/tests/windows-utf8.rc b/tests/windows-utf8.rc
new file mode 100644 (file)
index 0000000..110241a
--- /dev/null
@@ -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 <winresrc.h>  /* includes <winuser.h>, <winver.h> */
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "windows-utf8.manifest"