From: Bruno Haible Date: Sat, 29 Jul 2023 22:34:41 +0000 (+0200) Subject: mbsnrtoc32s tests: Renumber tests. X-Git-Tag: v1.0~997 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=05ca72b07e1354e8d0709439a1772d14866d06fc;p=gnulib.git mbsnrtoc32s tests: Renumber tests. * tests/test-mbsnrtoc32s-*.sh: Renamed 1 -> 2 -> 3 -> 4 -> 5 -> 1. * tests/test-mbsnrtoc32s.c: Update. --- diff --git a/ChangeLog b/ChangeLog index db32bd6920..a11baf1a97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2023-07-29 Bruno Haible + mbsnrtoc32s tests: Renumber tests. + * tests/test-mbsnrtoc32s-*.sh: Renamed 1 -> 2 -> 3 -> 4 -> 5 -> 1. + * tests/test-mbsnrtoc32s.c: Update. + mbstowcs tests: Renumber tests. * tests/test-mbstowcs*.sh: Renamed 1 -> 2 -> 3 -> 4 -> 5 -> 1. * tests/test-mbstowcs.c: Update. diff --git a/tests/test-mbsnrtoc32s-1.sh b/tests/test-mbsnrtoc32s-1.sh index e33a90be64..e64c2657a7 100755 --- a/tests/test-mbsnrtoc32s-1.sh +++ b/tests/test-mbsnrtoc32s-1.sh @@ -1,15 +1,9 @@ #!/bin/sh -# Test in an ISO-8859-1 or ISO-8859-15 locale. -: "${LOCALE_FR=fr_FR}" -if test $LOCALE_FR = none; then - if test -f /usr/bin/localedef; then - echo "Skipping test: no traditional french locale is installed" - else - echo "Skipping test: no traditional french locale is supported" - fi - exit 77 -fi +# Test whether the POSIX locale has encoding errors. +LC_ALL=C \ +${CHECKER} ./test-mbsnrtoc32s${EXEEXT} 1 || exit 1 +LC_ALL=POSIX \ +${CHECKER} ./test-mbsnrtoc32s${EXEEXT} 1 || exit 1 -LC_ALL=$LOCALE_FR \ -${CHECKER} ./test-mbsnrtoc32s${EXEEXT} 1 +exit 0 diff --git a/tests/test-mbsnrtoc32s-2.sh b/tests/test-mbsnrtoc32s-2.sh index c402683e79..4636a861ee 100755 --- a/tests/test-mbsnrtoc32s-2.sh +++ b/tests/test-mbsnrtoc32s-2.sh @@ -1,15 +1,15 @@ #!/bin/sh -# Test whether a specific UTF-8 locale is installed. -: "${LOCALE_FR_UTF8=fr_FR.UTF-8}" -if test $LOCALE_FR_UTF8 = none; then +# Test in an ISO-8859-1 or ISO-8859-15 locale. +: "${LOCALE_FR=fr_FR}" +if test $LOCALE_FR = none; then if test -f /usr/bin/localedef; then - echo "Skipping test: no french Unicode locale is installed" + echo "Skipping test: no traditional french locale is installed" else - echo "Skipping test: no french Unicode locale is supported" + echo "Skipping test: no traditional french locale is supported" fi exit 77 fi -LC_ALL=$LOCALE_FR_UTF8 \ +LC_ALL=$LOCALE_FR \ ${CHECKER} ./test-mbsnrtoc32s${EXEEXT} 2 diff --git a/tests/test-mbsnrtoc32s-3.sh b/tests/test-mbsnrtoc32s-3.sh index afdfea9fb5..d81bc5c957 100755 --- a/tests/test-mbsnrtoc32s-3.sh +++ b/tests/test-mbsnrtoc32s-3.sh @@ -1,15 +1,15 @@ #!/bin/sh -# Test whether a specific EUC-JP locale is installed. -: "${LOCALE_JA=ja_JP}" -if test $LOCALE_JA = none; then +# Test whether a specific UTF-8 locale is installed. +: "${LOCALE_FR_UTF8=fr_FR.UTF-8}" +if test $LOCALE_FR_UTF8 = none; then if test -f /usr/bin/localedef; then - echo "Skipping test: no traditional japanese locale is installed" + echo "Skipping test: no french Unicode locale is installed" else - echo "Skipping test: no traditional japanese locale is supported" + echo "Skipping test: no french Unicode locale is supported" fi exit 77 fi -LC_ALL=$LOCALE_JA \ +LC_ALL=$LOCALE_FR_UTF8 \ ${CHECKER} ./test-mbsnrtoc32s${EXEEXT} 3 diff --git a/tests/test-mbsnrtoc32s-4.sh b/tests/test-mbsnrtoc32s-4.sh index 4399f1ea1c..dc4166738e 100755 --- a/tests/test-mbsnrtoc32s-4.sh +++ b/tests/test-mbsnrtoc32s-4.sh @@ -1,15 +1,15 @@ #!/bin/sh -# Test whether a specific GB18030 locale is installed. -: "${LOCALE_ZH_CN=zh_CN.GB18030}" -if test $LOCALE_ZH_CN = none; then +# Test whether a specific EUC-JP locale is installed. +: "${LOCALE_JA=ja_JP}" +if test $LOCALE_JA = none; then if test -f /usr/bin/localedef; then - echo "Skipping test: no transitional chinese locale is installed" + echo "Skipping test: no traditional japanese locale is installed" else - echo "Skipping test: no transitional chinese locale is supported" + echo "Skipping test: no traditional japanese locale is supported" fi exit 77 fi -LC_ALL=$LOCALE_ZH_CN \ +LC_ALL=$LOCALE_JA \ ${CHECKER} ./test-mbsnrtoc32s${EXEEXT} 4 diff --git a/tests/test-mbsnrtoc32s-5.sh b/tests/test-mbsnrtoc32s-5.sh index 768d10b1e8..f56c1cfcaa 100755 --- a/tests/test-mbsnrtoc32s-5.sh +++ b/tests/test-mbsnrtoc32s-5.sh @@ -1,9 +1,15 @@ #!/bin/sh -# Test whether the POSIX locale has encoding errors. -LC_ALL=C \ -${CHECKER} ./test-mbsnrtoc32s${EXEEXT} 5 || exit 1 -LC_ALL=POSIX \ -${CHECKER} ./test-mbsnrtoc32s${EXEEXT} 5 || exit 1 +# Test whether a specific GB18030 locale is installed. +: "${LOCALE_ZH_CN=zh_CN.GB18030}" +if test $LOCALE_ZH_CN = none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no transitional chinese locale is installed" + else + echo "Skipping test: no transitional chinese locale is supported" + fi + exit 77 +fi -exit 0 +LC_ALL=$LOCALE_ZH_CN \ +${CHECKER} ./test-mbsnrtoc32s${EXEEXT} 5 diff --git a/tests/test-mbsnrtoc32s.c b/tests/test-mbsnrtoc32s.c index 342626d2a2..09ebf2e76f 100644 --- a/tests/test-mbsnrtoc32s.c +++ b/tests/test-mbsnrtoc32s.c @@ -78,8 +78,8 @@ main (int argc, char *argv[]) "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], "5") == 0 && MB_CUR_MAX > 1) - argv[1] = "2"; + if (argc > 1 && strcmp (argv[1], "1") == 0 && MB_CUR_MAX > 1) + argv[1] = "3"; #endif if (argc > 1) @@ -102,6 +102,74 @@ main (int argc, char *argv[]) switch (argv[1][0]) { case '1': + /* C or POSIX locale. */ + { + char input[] = "n/a"; + memset (&state, '\0', sizeof (mbstate_t)); + + src = input; + temp_state = state; + ret = mbsnrtoc32s (NULL, &src, 4, unlimited ? BUFSIZE : 1, &temp_state); + ASSERT (ret == 3); + ASSERT (src == input); + ASSERT (mbsinit (&state)); + + src = input; + ret = mbsnrtoc32s (buf, &src, 4, unlimited ? BUFSIZE : 1, &state); + ASSERT (ret == (unlimited ? 3 : 1)); + ASSERT (src == (unlimited ? NULL : input + 1)); + ASSERT (buf[0] == 'n'); + if (unlimited) + { + ASSERT (buf[1] == '/'); + ASSERT (buf[2] == 'a'); + ASSERT (buf[3] == 0); + ASSERT (buf[4] == (char32_t) 0xBADFACE); + } + else + ASSERT (buf[1] == (char32_t) 0xBADFACE); + ASSERT (mbsinit (&state)); + } + { + int c; + char input[2]; + + memset (&state, '\0', sizeof (mbstate_t)); + for (c = 0; c < 0x100; c++) + if (c != 0) + { + /* We are testing all nonnull bytes. */ + input[0] = c; + input[1] = '\0'; + + src = input; + ret = mbsnrtoc32s (NULL, &src, 2, unlimited ? BUFSIZE : 1, &state); + ASSERT (ret == 1); + ASSERT (src == input); + ASSERT (mbsinit (&state)); + + buf[0] = buf[1] = (char32_t) 0xBADFACE; + src = input; + ret = mbsnrtoc32s (buf, &src, 2, unlimited ? BUFSIZE : 1, &state); + /* POSIX:2018 says regarding mbsnrtowcs: "In the POSIX locale an + [EILSEQ] error cannot occur since all byte values are valid + characters." It is reasonable to expect mbsnrtoc32s to behave + in the same way. */ + ASSERT (ret == 1); + ASSERT (src == (unlimited ? NULL : input + 1)); + if (c < 0x80) + /* c is an ASCII character. */ + ASSERT (buf[0] == 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 (buf[0] == (btoc32 (c) == 0xDF00 + c ? btoc32 (c) : c)); + ASSERT (mbsinit (&state)); + } + } + break; + + case '2': /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ { char input[] = "B\374\337er"; /* "Büßer" */ @@ -146,7 +214,7 @@ main (int argc, char *argv[]) } break; - case '2': + case '3': /* Locale encoding is UTF-8. */ { char input[] = "s\303\274\303\237\360\237\230\213!"; /* "süß😋!" */ @@ -192,7 +260,7 @@ main (int argc, char *argv[]) } break; - case '3': + case '4': /* Locale encoding is EUC-JP. */ { char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ @@ -245,7 +313,7 @@ main (int argc, char *argv[]) } break; - case '4': + case '5': /* Locale encoding is GB18030. */ #if GL_CHAR32_T_IS_UNICODE && (defined __NetBSD__ || defined __sun) fputs ("Skipping test: The GB18030 converter in this system's iconv is broken.\n", stderr); @@ -295,74 +363,6 @@ main (int argc, char *argv[]) } break; - case '5': - /* C or POSIX locale. */ - { - char input[] = "n/a"; - memset (&state, '\0', sizeof (mbstate_t)); - - src = input; - temp_state = state; - ret = mbsnrtoc32s (NULL, &src, 4, unlimited ? BUFSIZE : 1, &temp_state); - ASSERT (ret == 3); - ASSERT (src == input); - ASSERT (mbsinit (&state)); - - src = input; - ret = mbsnrtoc32s (buf, &src, 4, unlimited ? BUFSIZE : 1, &state); - ASSERT (ret == (unlimited ? 3 : 1)); - ASSERT (src == (unlimited ? NULL : input + 1)); - ASSERT (buf[0] == 'n'); - if (unlimited) - { - ASSERT (buf[1] == '/'); - ASSERT (buf[2] == 'a'); - ASSERT (buf[3] == 0); - ASSERT (buf[4] == (char32_t) 0xBADFACE); - } - else - ASSERT (buf[1] == (char32_t) 0xBADFACE); - ASSERT (mbsinit (&state)); - } - { - int c; - char input[2]; - - memset (&state, '\0', sizeof (mbstate_t)); - for (c = 0; c < 0x100; c++) - if (c != 0) - { - /* We are testing all nonnull bytes. */ - input[0] = c; - input[1] = '\0'; - - src = input; - ret = mbsnrtoc32s (NULL, &src, 2, unlimited ? BUFSIZE : 1, &state); - ASSERT (ret == 1); - ASSERT (src == input); - ASSERT (mbsinit (&state)); - - buf[0] = buf[1] = (char32_t) 0xBADFACE; - src = input; - ret = mbsnrtoc32s (buf, &src, 2, unlimited ? BUFSIZE : 1, &state); - /* POSIX:2018 says regarding mbsnrtowcs: "In the POSIX locale an - [EILSEQ] error cannot occur since all byte values are valid - characters." It is reasonable to expect mbsnrtoc32s to behave - in the same way. */ - ASSERT (ret == 1); - ASSERT (src == (unlimited ? NULL : input + 1)); - if (c < 0x80) - /* c is an ASCII character. */ - ASSERT (buf[0] == 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 (buf[0] == (btoc32 (c) == 0xDF00 + c ? btoc32 (c) : c)); - ASSERT (mbsinit (&state)); - } - } - break; - default: return 1; }