+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.
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
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)
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])
{
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;