From d776b583004bf5171c3189e7e68b43d6974cf735 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 30 Jul 2023 00:29:19 +0200 Subject: [PATCH] mbstowcs tests: Renumber tests. * tests/test-mbstowcs*.sh: Renamed 1 -> 2 -> 3 -> 4 -> 5 -> 1. * tests/test-mbstowcs.c: Update. * modules/mbstowcs-tests: Update. --- ChangeLog | 5 + modules/mbstowcs-tests | 14 +- .../{test-mbstowcs5.sh => test-mbstowcs-1.sh} | 4 +- .../{test-mbstowcs1.sh => test-mbstowcs-2.sh} | 2 +- .../{test-mbstowcs2.sh => test-mbstowcs-3.sh} | 2 +- .../{test-mbstowcs3.sh => test-mbstowcs-4.sh} | 2 +- .../{test-mbstowcs4.sh => test-mbstowcs-5.sh} | 2 +- tests/test-mbstowcs.c | 120 +++++++++--------- 8 files changed, 78 insertions(+), 73 deletions(-) rename tests/{test-mbstowcs5.sh => test-mbstowcs-1.sh} (50%) rename tests/{test-mbstowcs1.sh => test-mbstowcs-2.sh} (89%) rename tests/{test-mbstowcs2.sh => test-mbstowcs-3.sh} (90%) rename tests/{test-mbstowcs3.sh => test-mbstowcs-4.sh} (90%) rename tests/{test-mbstowcs4.sh => test-mbstowcs-5.sh} (90%) diff --git a/ChangeLog b/ChangeLog index 4d450df4a0..db32bd6920 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2023-07-29 Bruno Haible + mbstowcs tests: Renumber tests. + * tests/test-mbstowcs*.sh: Renamed 1 -> 2 -> 3 -> 4 -> 5 -> 1. + * tests/test-mbstowcs.c: Update. + * modules/mbstowcs-tests: Update. + mbsrtowcs tests: Renumber tests. * tests/test-mbsrtowcs*.sh: Renamed 1 -> 2 -> 3 -> 4 -> 5 -> 1. * tests/test-mbsrtowcs.c: Update. diff --git a/modules/mbstowcs-tests b/modules/mbstowcs-tests index a780be2c4e..fa66f816fa 100644 --- a/modules/mbstowcs-tests +++ b/modules/mbstowcs-tests @@ -1,9 +1,9 @@ Files: -tests/test-mbstowcs1.sh -tests/test-mbstowcs2.sh -tests/test-mbstowcs3.sh -tests/test-mbstowcs4.sh -tests/test-mbstowcs5.sh +tests/test-mbstowcs-1.sh +tests/test-mbstowcs-2.sh +tests/test-mbstowcs-3.sh +tests/test-mbstowcs-4.sh +tests/test-mbstowcs-5.sh tests/test-mbstowcs.c tests/signature.h tests/macros.h @@ -26,8 +26,8 @@ gt_LOCALE_ZH_CN Makefile.am: TESTS += \ - test-mbstowcs1.sh test-mbstowcs2.sh test-mbstowcs3.sh test-mbstowcs4.sh \ - test-mbstowcs5.sh + test-mbstowcs-1.sh test-mbstowcs-2.sh test-mbstowcs-3.sh test-mbstowcs-4.sh \ + test-mbstowcs-5.sh TESTS_ENVIRONMENT += \ LOCALE_FR='@LOCALE_FR@' \ LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \ diff --git a/tests/test-mbstowcs5.sh b/tests/test-mbstowcs-1.sh similarity index 50% rename from tests/test-mbstowcs5.sh rename to tests/test-mbstowcs-1.sh index ae2477ed01..544cefcd71 100755 --- a/tests/test-mbstowcs5.sh +++ b/tests/test-mbstowcs-1.sh @@ -2,8 +2,8 @@ # Test whether the POSIX locale has encoding errors. LC_ALL=C \ -${CHECKER} ./test-mbstowcs${EXEEXT} 5 || exit 1 +${CHECKER} ./test-mbstowcs${EXEEXT} 1 || exit 1 LC_ALL=POSIX \ -${CHECKER} ./test-mbstowcs${EXEEXT} 5 || exit 1 +${CHECKER} ./test-mbstowcs${EXEEXT} 1 || exit 1 exit 0 diff --git a/tests/test-mbstowcs1.sh b/tests/test-mbstowcs-2.sh similarity index 89% rename from tests/test-mbstowcs1.sh rename to tests/test-mbstowcs-2.sh index 57f82d80fc..7229f4255d 100755 --- a/tests/test-mbstowcs1.sh +++ b/tests/test-mbstowcs-2.sh @@ -12,4 +12,4 @@ if test $LOCALE_FR = none; then fi LC_ALL=$LOCALE_FR \ -${CHECKER} ./test-mbstowcs${EXEEXT} 1 +${CHECKER} ./test-mbstowcs${EXEEXT} 2 diff --git a/tests/test-mbstowcs2.sh b/tests/test-mbstowcs-3.sh similarity index 90% rename from tests/test-mbstowcs2.sh rename to tests/test-mbstowcs-3.sh index 311b9b5f27..285605623e 100755 --- a/tests/test-mbstowcs2.sh +++ b/tests/test-mbstowcs-3.sh @@ -12,4 +12,4 @@ if test $LOCALE_FR_UTF8 = none; then fi LC_ALL=$LOCALE_FR_UTF8 \ -${CHECKER} ./test-mbstowcs${EXEEXT} 2 +${CHECKER} ./test-mbstowcs${EXEEXT} 3 diff --git a/tests/test-mbstowcs3.sh b/tests/test-mbstowcs-4.sh similarity index 90% rename from tests/test-mbstowcs3.sh rename to tests/test-mbstowcs-4.sh index ebaada5599..8b43b0d779 100755 --- a/tests/test-mbstowcs3.sh +++ b/tests/test-mbstowcs-4.sh @@ -12,4 +12,4 @@ if test $LOCALE_JA = none; then fi LC_ALL=$LOCALE_JA \ -${CHECKER} ./test-mbstowcs${EXEEXT} 3 +${CHECKER} ./test-mbstowcs${EXEEXT} 4 diff --git a/tests/test-mbstowcs4.sh b/tests/test-mbstowcs-5.sh similarity index 90% rename from tests/test-mbstowcs4.sh rename to tests/test-mbstowcs-5.sh index 86da562f02..3b545a4808 100755 --- a/tests/test-mbstowcs4.sh +++ b/tests/test-mbstowcs-5.sh @@ -12,4 +12,4 @@ if test $LOCALE_ZH_CN = none; then fi LC_ALL=$LOCALE_ZH_CN \ -${CHECKER} ./test-mbstowcs${EXEEXT} 4 +${CHECKER} ./test-mbstowcs${EXEEXT} 5 diff --git a/tests/test-mbstowcs.c b/tests/test-mbstowcs.c index 21ee0c95dd..c0cfda49f2 100644 --- a/tests/test-mbstowcs.c +++ b/tests/test-mbstowcs.c @@ -70,8 +70,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) @@ -93,6 +93,61 @@ main (int argc, char *argv[]) switch (argv[1][0]) { case '1': + /* C or POSIX locale. */ + { + char input[] = "n/a"; + + src = input; + ret = mbstowcs (NULL, src, unlimited ? BUFSIZE : 1); + ASSERT (ret == 3); + + src = input; + ret = mbstowcs (buf, src, unlimited ? BUFSIZE : 1); + ASSERT (ret == (unlimited ? 3 : 1)); + ASSERT (buf[0] == 'n'); + if (unlimited) + { + ASSERT (buf[1] == '/'); + ASSERT (buf[2] == 'a'); + ASSERT (buf[3] == 0); + ASSERT (buf[4] == (wchar_t) 0xBADFACE); + } + else + ASSERT (buf[1] == (wchar_t) 0xBADFACE); + } + { + int c; + char input[2]; + + for (c = 0; c < 0x100; c++) + if (c != 0) + { + /* We are testing all nonnull bytes. */ + input[0] = c; + input[1] = '\0'; + + src = input; + ret = mbstowcs (NULL, src, unlimited ? BUFSIZE : 1); + ASSERT (ret == 1); + + buf[0] = buf[1] = (wchar_t) 0xBADFACE; + src = input; + ret = mbstowcs (buf, src, unlimited ? BUFSIZE : 1); + /* POSIX:2018 says: "In the POSIX locale an [EILSEQ] error + cannot occur since all byte values are valid characters." */ + ASSERT (ret == 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] == (btowc (c) == 0xDF00 + c ? btowc (c) : c)); + } + } + break; + + case '2': /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ { char input[] = "B\374\337er"; /* "Büßer" */ @@ -118,7 +173,7 @@ main (int argc, char *argv[]) } break; - case '2': + case '3': /* Locale encoding is UTF-8. */ { char input[] = "B\303\274\303\237er"; /* "Büßer" */ @@ -144,7 +199,7 @@ main (int argc, char *argv[]) } break; - case '3': + case '4': /* Locale encoding is EUC-JP. */ { char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ @@ -170,7 +225,7 @@ main (int argc, char *argv[]) } break; - case '4': + case '5': /* Locale encoding is GB18030. */ { char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ @@ -196,61 +251,6 @@ main (int argc, char *argv[]) } break; - case '5': - /* C or POSIX locale. */ - { - char input[] = "n/a"; - - src = input; - ret = mbstowcs (NULL, src, unlimited ? BUFSIZE : 1); - ASSERT (ret == 3); - - src = input; - ret = mbstowcs (buf, src, unlimited ? BUFSIZE : 1); - ASSERT (ret == (unlimited ? 3 : 1)); - ASSERT (buf[0] == 'n'); - if (unlimited) - { - ASSERT (buf[1] == '/'); - ASSERT (buf[2] == 'a'); - ASSERT (buf[3] == 0); - ASSERT (buf[4] == (wchar_t) 0xBADFACE); - } - else - ASSERT (buf[1] == (wchar_t) 0xBADFACE); - } - { - int c; - char input[2]; - - for (c = 0; c < 0x100; c++) - if (c != 0) - { - /* We are testing all nonnull bytes. */ - input[0] = c; - input[1] = '\0'; - - src = input; - ret = mbstowcs (NULL, src, unlimited ? BUFSIZE : 1); - ASSERT (ret == 1); - - buf[0] = buf[1] = (wchar_t) 0xBADFACE; - src = input; - ret = mbstowcs (buf, src, unlimited ? BUFSIZE : 1); - /* POSIX:2018 says: "In the POSIX locale an [EILSEQ] error - cannot occur since all byte values are valid characters." */ - ASSERT (ret == 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] == (btowc (c) == 0xDF00 + c ? btowc (c) : c)); - } - } - break; - default: return 1; } -- 2.39.5