From 5f5389b7b8d5037d77b37859a0c7821e61e90d4d Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Fri, 3 Jan 2020 01:23:24 +0100
Subject: [PATCH] mbrtowc: Add more tests.

* tests/test-mbrtowc-w32.c: Include localcharset.h.
(test_one_locale): For the GB18030 and UTF-8 tests, verify that
locale_charset() returns the expected value; otherwise, skip the test.
* tests/test-mbrtowc-w32-6.sh: Remove old comment.
* tests/test-mbrtowc-w32-7.sh: Likewise.
* modules/mbrtowc-tests (Files): Add these files.
(Depends-on): Add localcharset.
(TESTS): Add test-mbrtowc-w32-6.sh, test-mbrtowc-w32-7.sh.
---
 ChangeLog                   | 12 ++++++++++++
 modules/mbrtowc-tests       |  6 +++++-
 tests/test-mbrtowc-w32-6.sh |  3 ---
 tests/test-mbrtowc-w32-7.sh |  3 ---
 tests/test-mbrtowc-w32.c    |  5 +++++
 5 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6c71b81367..1eb44197db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2020-01-02  Bruno Haible  <bruno@clisp.org>
+
+	mbrtowc: Add more tests.
+	* tests/test-mbrtowc-w32.c: Include localcharset.h.
+	(test_one_locale): For the GB18030 and UTF-8 tests, verify that
+	locale_charset() returns the expected value; otherwise, skip the test.
+	* tests/test-mbrtowc-w32-6.sh: Remove old comment.
+	* tests/test-mbrtowc-w32-7.sh: Likewise.
+	* modules/mbrtowc-tests (Files): Add these files.
+	(Depends-on): Add localcharset.
+	(TESTS): Add test-mbrtowc-w32-6.sh, test-mbrtowc-w32-7.sh.
+
 2020-01-02  Bruno Haible  <bruno@clisp.org>
 
 	mbrtowc: Fix test failures on MSVC (regression by previous commit).
diff --git a/modules/mbrtowc-tests b/modules/mbrtowc-tests
index 86008d867d..f5c9166f1d 100644
--- a/modules/mbrtowc-tests
+++ b/modules/mbrtowc-tests
@@ -10,6 +10,8 @@ tests/test-mbrtowc-w32-2.sh
 tests/test-mbrtowc-w32-3.sh
 tests/test-mbrtowc-w32-4.sh
 tests/test-mbrtowc-w32-5.sh
+tests/test-mbrtowc-w32-6.sh
+tests/test-mbrtowc-w32-7.sh
 tests/test-mbrtowc-w32.c
 tests/signature.h
 tests/macros.h
@@ -22,6 +24,7 @@ Depends-on:
 mbsinit
 wctob
 setlocale
+localcharset
 
 configure.ac:
 gt_LOCALE_FR
@@ -34,7 +37,8 @@ TESTS += \
   test-mbrtowc1.sh test-mbrtowc2.sh test-mbrtowc3.sh test-mbrtowc4.sh \
   test-mbrtowc5.sh \
   test-mbrtowc-w32-1.sh test-mbrtowc-w32-2.sh test-mbrtowc-w32-3.sh \
-  test-mbrtowc-w32-4.sh test-mbrtowc-w32-5.sh
+  test-mbrtowc-w32-4.sh test-mbrtowc-w32-5.sh test-mbrtowc-w32-6.sh \
+  test-mbrtowc-w32-7.sh
 TESTS_ENVIRONMENT += \
   LOCALE_FR='@LOCALE_FR@' \
   LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \
diff --git a/tests/test-mbrtowc-w32-6.sh b/tests/test-mbrtowc-w32-6.sh
index e608233caa..c2e8dfe081 100755
--- a/tests/test-mbrtowc-w32-6.sh
+++ b/tests/test-mbrtowc-w32-6.sh
@@ -1,7 +1,4 @@
 #!/bin/sh
 
-# This test is not enabled by default, because MSVCRT does not support and
-# will likely never support locales with MB_CUR_MAX > 2.
-
 # Test a GB18030 locale.
 ${CHECKER} ./test-mbrtowc-w32${EXEEXT} Chinese_China 54936
diff --git a/tests/test-mbrtowc-w32-7.sh b/tests/test-mbrtowc-w32-7.sh
index 0a3eb8f59b..2c5d555f1b 100755
--- a/tests/test-mbrtowc-w32-7.sh
+++ b/tests/test-mbrtowc-w32-7.sh
@@ -1,7 +1,4 @@
 #!/bin/sh
 
-# This test is not enabled by default, because MSVCRT does not support and
-# will likely never support locales with MB_CUR_MAX > 2.
-
 # Test some UTF-8 locales.
 ${CHECKER} ./test-mbrtowc-w32${EXEEXT} French_France Japanese_Japan Chinese_Taiwan Chinese_China 65001
diff --git a/tests/test-mbrtowc-w32.c b/tests/test-mbrtowc-w32.c
index efeee15ace..17908ed607 100644
--- a/tests/test-mbrtowc-w32.c
+++ b/tests/test-mbrtowc-w32.c
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "localcharset.h"
 #include "macros.h"
 
 #if defined _WIN32 && !defined __CYGWIN__
@@ -476,6 +477,8 @@ test_one_locale (const char *name, int codepage)
 
     case 54936:
       /* Locale encoding is CP54936 = GB18030.  */
+      if (strcmp (locale_charset (), "GB18030") != 0)
+        return 77;
       {
         char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */
         memset (&state, '\0', sizeof (mbstate_t));
@@ -572,6 +575,8 @@ test_one_locale (const char *name, int codepage)
 
     case 65001:
       /* Locale encoding is CP65001 = UTF-8.  */
+      if (strcmp (locale_charset (), "UTF-8") != 0)
+        return 77;
       {
         char input[] = "B\303\274\303\237er"; /* "Büßer" */
         memset (&state, '\0', sizeof (mbstate_t));
-- 
2.39.5