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

index d9f282c21e07789b90c9da394d22be1bbb314d04..fd3cf9f7cae8dbec974a4c05999eeca55d728c9c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2024-12-23  Bruno Haible  <bruno@clisp.org>
 
+       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.
index 0c24d5b4b680d319f4848ae26e792dae21cfea93..cf4d5868065d06d71db4e30a46874e761ae0a043 100644 (file)
@@ -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 <locale.h>]])
 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 (file)
index 0000000..72a01c0
--- /dev/null
@@ -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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2024.  */
+
+#include <config.h>
+
+#include "localename.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#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 (executable)
index 0000000..de7629c
--- /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-localename-w32utf8${EXEEXT}