From: Bruno Haible Date: Fri, 28 Jul 2023 11:56:15 +0000 (+0200) Subject: mbmemcasecmp, mbmemcasecoll: Avoid test failure on MSVC. X-Git-Tag: v1.0~1020 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=0b8b7c9068bb0b1f503adfad1a32315535fb4240;p=gnulib.git 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 , . * tests/test-mbmemcasecoll.c: Likewise. * modules/mbmemcasecmp-tests (Depends-on): Add mbrtowc, wctype-h. * modules/mbmemcasecoll-tests (Depends-on): Likewise. --- diff --git a/ChangeLog b/ChangeLog index 8b08c235cf..b1ccb85e9a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2023-07-28 Bruno Haible + + 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 , . + * tests/test-mbmemcasecoll.c: Likewise. + * modules/mbmemcasecmp-tests (Depends-on): Add mbrtowc, wctype-h. + * modules/mbmemcasecoll-tests (Depends-on): Likewise. + 2023-07-27 Bruno Haible gnulib-tool: Include ftruncate in testdirs. 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 #include +#include +#include #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 #include +#include +#include #include "macros.h"