This patch avoids two long-standing test failures on MSVC.

2023-07-28  Bruno Haible  <br...@clisp.org>

        mbmemcasecmp, mbmemcasecoll: Avoid test failure on MSVC.
        * tests/test-mbmemcasecmp.h (test_utf_8): Disable two tests on platforms
        that don't have the upper/lower mappings for 'ü'/'Ü'.
        * tests/test-mbmemcasecmp.c: Include <wchar.h>, <wctype.h>.
        * tests/test-mbmemcasecoll.c: Likewise.
        * modules/mbmemcasecmp-tests (Depends-on): Add mbrtowc, wctype-h.
        * modules/mbmemcasecoll-tests (Depends-on): Likewise.

diff --git a/modules/mbmemcasecmp-tests b/modules/mbmemcasecmp-tests
index 50e9d68366..52cb80def7 100644
--- a/modules/mbmemcasecmp-tests
+++ b/modules/mbmemcasecmp-tests
@@ -12,6 +12,8 @@ m4/codeset.m4
 Depends-on:
 stdbool
 setlocale
+mbrtowc
+wctype-h
 
 configure.ac:
 gt_LOCALE_FR
diff --git a/modules/mbmemcasecoll-tests b/modules/mbmemcasecoll-tests
index 28a982e4e6..8cba105846 100644
--- a/modules/mbmemcasecoll-tests
+++ b/modules/mbmemcasecoll-tests
@@ -12,6 +12,8 @@ m4/codeset.m4
 Depends-on:
 stdbool
 setlocale
+mbrtowc
+wctype-h
 
 configure.ac:
 gt_LOCALE_FR
diff --git a/tests/test-mbmemcasecmp.c b/tests/test-mbmemcasecmp.c
index 477f68ba54..f8ae91e401 100644
--- a/tests/test-mbmemcasecmp.c
+++ b/tests/test-mbmemcasecmp.c
@@ -22,6 +22,8 @@
 
 #include <locale.h>
 #include <string.h>
+#include <wchar.h>
+#include <wctype.h>
 
 #include "macros.h"
 
diff --git a/tests/test-mbmemcasecmp.h b/tests/test-mbmemcasecmp.h
index ed72bd5efc..1727ff3160 100644
--- a/tests/test-mbmemcasecmp.h
+++ b/tests/test-mbmemcasecmp.h
@@ -123,8 +123,19 @@ test_utf_8 (int (*my_casecmp) (const char *, size_t, const 
char *, size_t), bool
   /* The following tests shows how my_casecmp() is different from
      strcasecmp().  */
 
-  ASSERT (my_casecmp ("\303\266zg\303\274r", 7, "\303\226ZG\303\234R", 7) == 
0); /* özgür */
-  ASSERT (my_casecmp ("\303\226ZG\303\234R", 7, "\303\266zg\303\274r", 7) == 
0); /* özgür */
+  {
+    /* Some platforms, e.g. MSVC 14, lack the upper/lower mappings for these
+       wide characters in the *.65001 locales.  */
+    mbstate_t state;
+    wchar_t wc;
+    memset (&state, 0, sizeof (mbstate_t));
+    if (mbrtowc (&wc, "\303\274", 2, &state) == 2
+        && towupper (wc) != wc)
+      {
+        ASSERT (my_casecmp ("\303\266zg\303\274r", 7, "\303\226ZG\303\234R", 
7) == 0); /* özgür */
+        ASSERT (my_casecmp ("\303\226ZG\303\234R", 7, "\303\266zg\303\274r", 
7) == 0); /* özgür */
+      }
+  }
 
   /* This test shows how strings of different size can compare equal.  */
   if (turkish)
@@ -234,7 +245,18 @@ test_utf_8 (int (*my_casecmp) (const char *, size_t, const 
char *, size_t), bool
     ASSERT (my_casecmp (input1, SIZEOF (input1), input3, SIZEOF (input3)) == 
0);
     #endif
 
-    ASSERT (my_casecmp (input2, SIZEOF (input2), input3, SIZEOF (input3)) == 
0);
+    {
+      /* Some platforms, e.g. MSVC 14, lack the upper/lower mappings for the
+         'ü'/'Ü' wide characters in the *.65001 locales.  */
+      mbstate_t state;
+      wchar_t wc;
+      memset (&state, 0, sizeof (mbstate_t));
+      if (mbrtowc (&wc, "\303\234", 2, &state) == 2
+          && towlower (wc) != wc)
+        {
+          ASSERT (my_casecmp (input2, SIZEOF (input2), input3, SIZEOF 
(input3)) == 0);
+        }
+    }
   }
 
   #if 0 /* This functionality requires ulc_casecmp.  */
diff --git a/tests/test-mbmemcasecoll.c b/tests/test-mbmemcasecoll.c
index d5b274bffa..ebcc0618c4 100644
--- a/tests/test-mbmemcasecoll.c
+++ b/tests/test-mbmemcasecoll.c
@@ -22,6 +22,8 @@
 
 #include <locale.h>
 #include <string.h>
+#include <wchar.h>
+#include <wctype.h>
 
 #include "macros.h"
 




Reply via email to