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

index 9f89cb8718d01be6ade821564eae4a2b85b0ee24..c5e2e8b1b2301666caf7fbcdaac03484ab68ec12 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2024-12-23  Bruno Haible  <bruno@clisp.org>
 
+       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 <windows.h>.
        (setlocale_unixlike): In the UTF-8 environment, append a suffix ".65001"
index ad0a536bc664d41f8a083c1bc1f4c727c919d88a..23cc6ddd17d97b66e323b1a9cc94f703db04f46a 100644 (file)
@@ -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 (file)
index 0000000..f0bbce0
--- /dev/null
@@ -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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2024.  */
+
+#include <config.h>
+
+#include <locale.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+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 (executable)
index 0000000..e8f7484
--- /dev/null
@@ -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}