From: Bruno Haible Date: Mon, 3 Apr 2023 12:24:42 +0000 (+0200) Subject: btoc32 tests: Check behaviour in the C locale. X-Git-Tag: v1.0~1525 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=d36467df509b488bc069a3c247a3ee595874f431;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 901aa4331a..b05eb8f846 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2023-04-03 Bruno Haible + + 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 mbrtoc32 tests: Prefer *c32* functions. diff --git a/modules/btoc32-tests b/modules/btoc32-tests index b3373f3cf8..b9d14eefd1 100644 --- a/modules/btoc32-tests +++ b/modules/btoc32-tests @@ -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 index 0000000000..422c3daed5 --- /dev/null +++ b/tests/test-btoc32-3.sh @@ -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 diff --git a/tests/test-btoc32.c b/tests/test-btoc32.c index 90b38cfcf5..a2c48dde6f 100644 --- a/tests/test-btoc32.c +++ b/tests/test-btoc32.c @@ -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;