On native Windows, I see a failure of a 'unicodeio' test:

FAIL: test-unicodeio1.sh
========================

../../gltests/test-unicodeio.c:67: assertion 'strcmp (result, 
TEST_CODE_AS_UTF8) == 0' failed
FAIL test-unicodeio1.sh (exit status: 3)

The reason is that the encoding of the C locale happens to be CP1252, in this
case, and the tested character U+2022 corresponds to 0x95 in CP1252.

This patch adjusts the test accordingly.


2023-04-24  Bruno Haible  <br...@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.

diff --git a/modules/unicodeio-tests b/modules/unicodeio-tests
index 05fcdeb0ba..740552abaf 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;




Reply via email to