From 112d50c90c1b0c4196148c6ac79f1f28f5f64c5e Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Mon, 24 Apr 2023 12:48:31 +0200
Subject: [PATCH] unicodeio tests: Avoid test failures on native Windows.

* tests/test-unicodeio.c: Include localcharset.h.
(main): Handle C locales whose encoding is CP1252 or similar.
* modules/unicodeio-tests (Depends-on): Add localcharset.
---
 ChangeLog               |  7 +++++++
 modules/unicodeio-tests |  1 +
 tests/test-unicodeio.c  | 23 ++++++++++++++++++++++-
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 173a3602d7..ffca8174c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-04-24  Bruno Haible  <bruno@clisp.org>
+
+	unicodeio tests: Avoid test failures on native Windows.
+	* tests/test-unicodeio.c: Include localcharset.h.
+	(main): Handle C locales whose encoding is CP1252 or similar.
+	* modules/unicodeio-tests (Depends-on): Add localcharset.
+
 2023-04-23  Bruno Haible  <bruno@clisp.org>
 
 	category-none: Fix link errors on MSVC, when libunistring is installed.
diff --git a/modules/unicodeio-tests b/modules/unicodeio-tests
index c53f26f2b5..527dfa458f 100644
--- a/modules/unicodeio-tests
+++ b/modules/unicodeio-tests
@@ -10,6 +10,7 @@ m4/codeset.m4
 
 Depends-on:
 setlocale
+localcharset
 
 configure.ac:
 gt_LOCALE_FR_UTF8
diff --git a/tests/test-unicodeio.c b/tests/test-unicodeio.c
index 1b7010c1ae..3a4af1345e 100644
--- a/tests/test-unicodeio.c
+++ b/tests/test-unicodeio.c
@@ -25,6 +25,7 @@
 #include <locale.h>
 #include <string.h>
 
+#include "localcharset.h"
 #include "macros.h"
 
 #define TEST_CODE 0x2022
@@ -62,7 +63,27 @@ main (int argc, char *argv[])
       if (argc > 1)
         switch (argv[1][0])
           {
-          case '1': /* On some platforms, the "C" locale has UTF-8 encoding.  */
+          case '1':
+            /* On some platforms, the "C" locale has UTF-8 encoding.
+               And on native Windows, the "C" locale may have an 8-bit encoding
+               such as CP1252, that contains the U+2022 character.  */
+            {
+              const char *charset = locale_charset ();
+              if (strcmp (charset, "CP874") == 0
+                  || strcmp (charset, "CP1250") == 0
+                  || strcmp (charset, "CP1251") == 0
+                  || strcmp (charset, "CP1252") == 0
+                  || strcmp (charset, "CP1253") == 0
+                  || strcmp (charset, "CP1254") == 0
+                  || strcmp (charset, "CP1255") == 0
+                  || strcmp (charset, "CP1256") == 0
+                  || strcmp (charset, "CP1257") == 0
+                  || strcmp (charset, "CP1258") == 0)
+                ASSERT (strcmp (result, "\x95") == 0);
+              else
+                ASSERT (strcmp (result, TEST_CODE_AS_UTF8) == 0);
+            }
+            break;
           case '2':
             ASSERT (strcmp (result, TEST_CODE_AS_UTF8) == 0);
             break;
-- 
2.39.5