]> Savannah Git Hosting - gnulib.git/commitdiff
btoc32 tests: Check behaviour in the C locale.
authorBruno Haible <bruno@clisp.org>
Mon, 3 Apr 2023 12:24:42 +0000 (14:24 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 3 Apr 2023 12:24:42 +0000 (14:24 +0200)
* tests/test-btoc32.c (main): Test behaviour in the C locale. Based on
tests/test-btowc.c.
* tests/test-btoc32-3.sh: New file, based on tests/test-btowc3.sh.
* modules/btoc32-tests (Files): Add it.
(Makefile.am): Test it.

ChangeLog
modules/btoc32-tests
tests/test-btoc32-3.sh [new file with mode: 0755]
tests/test-btoc32.c

index 901aa4331aa1d9e80b9cbf383441a2745713c979..b05eb8f8467e58128f49d80370cd65cad77bfb15 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-04-03  Bruno Haible  <bruno@clisp.org>
+
+       btoc32 tests: Check behaviour in the C locale.
+       * tests/test-btoc32.c (main): Test behaviour in the C locale. Based on
+       tests/test-btowc.c.
+       * tests/test-btoc32-3.sh: New file, based on tests/test-btowc3.sh.
+       * modules/btoc32-tests (Files): Add it.
+       (Makefile.am): Test it.
+
 2023-04-03  Bruno Haible  <bruno@clisp.org>
 
        mbrtoc32 tests: Prefer *c32* functions.
index b3373f3cf8eca8209da3b061f15fd6d61b523939..b9d14eefd1c73e32ebd09ff4f1bccbc705b7f52f 100644 (file)
@@ -1,6 +1,7 @@
 Files:
 tests/test-btoc32-1.sh
 tests/test-btoc32-2.sh
+tests/test-btoc32-3.sh
 tests/test-btoc32.c
 tests/signature.h
 tests/macros.h
@@ -15,7 +16,7 @@ gt_LOCALE_FR
 gt_LOCALE_FR_UTF8
 
 Makefile.am:
-TESTS += test-btoc32-1.sh test-btoc32-2.sh
+TESTS += test-btoc32-1.sh test-btoc32-2.sh test-btoc32-3.sh
 TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@' LOCALE_FR_UTF8='@LOCALE_FR_UTF8@'
 check_PROGRAMS += test-btoc32
 test_btoc32_LDADD = $(LDADD) $(SETLOCALE_LIB)
diff --git a/tests/test-btoc32-3.sh b/tests/test-btoc32-3.sh
new file mode 100755 (executable)
index 0000000..422c3da
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+# Test whether the POSIX locale has encoding errors.
+LC_ALL=C \
+${CHECKER} ./test-btoc32${EXEEXT} 3 || exit 1
+LC_ALL=POSIX \
+${CHECKER} ./test-btoc32${EXEEXT} 3 || exit 1
+
+exit 0
index 90b38cfcf59719adbcf84e1d0f093f542d68abc1..a2c48dde6f03abc70a5c445663a9a8649566dffb 100644 (file)
@@ -40,6 +40,15 @@ main (int argc, char *argv[])
 
   ASSERT (btoc32 (EOF) == WEOF);
 
+#ifdef __ANDROID__
+  /* On Android ≥ 5.0, the default locale is the "C.UTF-8" locale, not the
+     "C" locale.  Furthermore, when you attempt to set the "C" or "POSIX"
+     locale via setlocale(), what you get is a "C" locale with UTF-8 encoding,
+     that is, effectively the "C.UTF-8" locale.  */
+  if (argc > 1 && strcmp (argv[1], "3") == 0 && MB_CUR_MAX > 1)
+    argv[1] = "2";
+#endif
+
   if (argc > 1)
     switch (argv[1][0])
       {
@@ -58,6 +67,27 @@ main (int argc, char *argv[])
         for (c = 0x80; c < 0x100; c++)
           ASSERT (btoc32 (c) == WEOF);
         return 0;
+
+      case '3':
+        /* C or POSIX locale.  */
+        for (c = 0; c < 0x100; c++)
+          if (c != 0)
+            {
+              /* We are testing all nonnull bytes.  */
+              wint_t wc = btoc32 (c);
+              /* POSIX:2018 says regarding btowc: "In the POSIX locale, btowc()
+                 shall not return WEOF if c has a value in the range 0 to 255
+                 inclusive."  It is reasonable to expect btoc32 to behave in
+                 the same way.  */
+              if (c < 0x80)
+                /* c is an ASCII character.  */
+                ASSERT (wc == c);
+              else
+                /* On most platforms, the bytes 0x80..0xFF map to U+0080..U+00FF.
+                   But on musl libc, the bytes 0x80..0xFF map to U+DF80..U+DFFF.  */
+                ASSERT (wc == c || wc == 0xDF00 + c);
+            }
+        return 0;
       }
 
   return 1;