From ef2d2d353fb083023616c838b3d67996d0ba4bb8 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 30 Jul 2023 00:25:57 +0200 Subject: [PATCH] mbsrtowcs tests: Renumber tests. * tests/test-mbsrtowcs*.sh: Renamed 1 -> 2 -> 3 -> 4 -> 5 -> 1. * tests/test-mbsrtowcs.c: Update. * modules/mbsrtowcs-tests: Update. --- ChangeLog | 5 + modules/mbsrtowcs-tests | 14 +- ...test-mbsrtowcs5.sh => test-mbsrtowcs-1.sh} | 4 +- ...test-mbsrtowcs1.sh => test-mbsrtowcs-2.sh} | 2 +- ...test-mbsrtowcs2.sh => test-mbsrtowcs-3.sh} | 2 +- ...test-mbsrtowcs3.sh => test-mbsrtowcs-4.sh} | 2 +- ...test-mbsrtowcs4.sh => test-mbsrtowcs-5.sh} | 2 +- tests/test-mbsrtowcs.c | 384 +++++++++--------- 8 files changed, 210 insertions(+), 205 deletions(-) rename tests/{test-mbsrtowcs5.sh => test-mbsrtowcs-1.sh} (50%) rename tests/{test-mbsrtowcs1.sh => test-mbsrtowcs-2.sh} (89%) rename tests/{test-mbsrtowcs2.sh => test-mbsrtowcs-3.sh} (90%) rename tests/{test-mbsrtowcs3.sh => test-mbsrtowcs-4.sh} (89%) rename tests/{test-mbsrtowcs4.sh => test-mbsrtowcs-5.sh} (90%) diff --git a/ChangeLog b/ChangeLog index 89cbd4cfd9..4d450df4a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2023-07-29 Bruno Haible + mbsrtowcs tests: Renumber tests. + * tests/test-mbsrtowcs*.sh: Renamed 1 -> 2 -> 3 -> 4 -> 5 -> 1. + * tests/test-mbsrtowcs.c: Update. + * modules/mbsrtowcs-tests: Update. + mbsnrtowcs tests: Renumber tests. * tests/test-mbsnrtowcs*.sh: Renamed 1 -> 2 -> 3 -> 4 -> 5 -> 1. * tests/test-mbsnrtowcs.c: Update. diff --git a/modules/mbsrtowcs-tests b/modules/mbsrtowcs-tests index 36050c670d..ec7c5c9f6a 100644 --- a/modules/mbsrtowcs-tests +++ b/modules/mbsrtowcs-tests @@ -1,9 +1,9 @@ Files: -tests/test-mbsrtowcs1.sh -tests/test-mbsrtowcs2.sh -tests/test-mbsrtowcs3.sh -tests/test-mbsrtowcs4.sh -tests/test-mbsrtowcs5.sh +tests/test-mbsrtowcs-1.sh +tests/test-mbsrtowcs-2.sh +tests/test-mbsrtowcs-3.sh +tests/test-mbsrtowcs-4.sh +tests/test-mbsrtowcs-5.sh tests/test-mbsrtowcs.c tests/signature.h tests/macros.h @@ -26,8 +26,8 @@ gt_LOCALE_ZH_CN Makefile.am: TESTS += \ - test-mbsrtowcs1.sh test-mbsrtowcs2.sh test-mbsrtowcs3.sh test-mbsrtowcs4.sh \ - test-mbsrtowcs5.sh + test-mbsrtowcs-1.sh test-mbsrtowcs-2.sh test-mbsrtowcs-3.sh \ + test-mbsrtowcs-4.sh test-mbsrtowcs-5.sh TESTS_ENVIRONMENT += \ LOCALE_FR='@LOCALE_FR@' \ LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \ diff --git a/tests/test-mbsrtowcs5.sh b/tests/test-mbsrtowcs-1.sh similarity index 50% rename from tests/test-mbsrtowcs5.sh rename to tests/test-mbsrtowcs-1.sh index 96734a73bd..abac8d2eec 100755 --- a/tests/test-mbsrtowcs5.sh +++ b/tests/test-mbsrtowcs-1.sh @@ -2,8 +2,8 @@ # Test whether the POSIX locale has encoding errors. LC_ALL=C \ -${CHECKER} ./test-mbsrtowcs${EXEEXT} 5 || exit 1 +${CHECKER} ./test-mbsrtowcs${EXEEXT} 1 || exit 1 LC_ALL=POSIX \ -${CHECKER} ./test-mbsrtowcs${EXEEXT} 5 || exit 1 +${CHECKER} ./test-mbsrtowcs${EXEEXT} 1 || exit 1 exit 0 diff --git a/tests/test-mbsrtowcs1.sh b/tests/test-mbsrtowcs-2.sh similarity index 89% rename from tests/test-mbsrtowcs1.sh rename to tests/test-mbsrtowcs-2.sh index f8c54ab243..508159e62a 100755 --- a/tests/test-mbsrtowcs1.sh +++ b/tests/test-mbsrtowcs-2.sh @@ -12,4 +12,4 @@ if test $LOCALE_FR = none; then fi LC_ALL=$LOCALE_FR \ -${CHECKER} ./test-mbsrtowcs${EXEEXT} 1 +${CHECKER} ./test-mbsrtowcs${EXEEXT} 2 diff --git a/tests/test-mbsrtowcs2.sh b/tests/test-mbsrtowcs-3.sh similarity index 90% rename from tests/test-mbsrtowcs2.sh rename to tests/test-mbsrtowcs-3.sh index 1cae31cb1f..9c7caee5d5 100755 --- a/tests/test-mbsrtowcs2.sh +++ b/tests/test-mbsrtowcs-3.sh @@ -12,4 +12,4 @@ if test $LOCALE_FR_UTF8 = none; then fi LC_ALL=$LOCALE_FR_UTF8 \ -${CHECKER} ./test-mbsrtowcs${EXEEXT} 2 +${CHECKER} ./test-mbsrtowcs${EXEEXT} 3 diff --git a/tests/test-mbsrtowcs3.sh b/tests/test-mbsrtowcs-4.sh similarity index 89% rename from tests/test-mbsrtowcs3.sh rename to tests/test-mbsrtowcs-4.sh index 908c140e57..87dc7e758c 100755 --- a/tests/test-mbsrtowcs3.sh +++ b/tests/test-mbsrtowcs-4.sh @@ -12,4 +12,4 @@ if test $LOCALE_JA = none; then fi LC_ALL=$LOCALE_JA \ -${CHECKER} ./test-mbsrtowcs${EXEEXT} 3 +${CHECKER} ./test-mbsrtowcs${EXEEXT} 4 diff --git a/tests/test-mbsrtowcs4.sh b/tests/test-mbsrtowcs-5.sh similarity index 90% rename from tests/test-mbsrtowcs4.sh rename to tests/test-mbsrtowcs-5.sh index 135bc5f719..8e2de64cb3 100755 --- a/tests/test-mbsrtowcs4.sh +++ b/tests/test-mbsrtowcs-5.sh @@ -12,4 +12,4 @@ if test $LOCALE_ZH_CN = none; then fi LC_ALL=$LOCALE_ZH_CN \ -${CHECKER} ./test-mbsrtowcs${EXEEXT} 4 +${CHECKER} ./test-mbsrtowcs${EXEEXT} 5 diff --git a/tests/test-mbsrtowcs.c b/tests/test-mbsrtowcs.c index 3c351f2346..822d329a4b 100644 --- a/tests/test-mbsrtowcs.c +++ b/tests/test-mbsrtowcs.c @@ -77,8 +77,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) @@ -101,196 +101,6 @@ main (int argc, char *argv[]) switch (argv[1][0]) { case '1': - /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ - { - char input[] = "B\374\337er"; /* "Büßer" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'B'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 1, &state); - ASSERT (ret == 1); - ASSERT (wctob (wc) == (unsigned char) '\374'); - ASSERT (mbsinit (&state)); - input[1] = '\0'; - - src = input + 2; - temp_state = state; - ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 1, &temp_state); - ASSERT (ret == 3); - ASSERT (src == input + 2); - ASSERT (mbsinit (&state)); - - src = input + 2; - ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 1, &state); - ASSERT (ret == (unlimited ? 3 : 1)); - ASSERT (src == (unlimited ? NULL : input + 3)); - ASSERT (wctob (buf[0]) == (unsigned char) '\337'); - if (unlimited) - { - ASSERT (buf[1] == 'e'); - ASSERT (buf[2] == 'r'); - ASSERT (buf[3] == 0); - ASSERT (buf[4] == (wchar_t) 0xBADFACE); - } - else - ASSERT (buf[1] == (wchar_t) 0xBADFACE); - ASSERT (mbsinit (&state)); - } - break; - - case '2': - /* Locale encoding is UTF-8. */ - { - char input[] = "B\303\274\303\237er"; /* "Büßer" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'B'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 1, &state); - ASSERT (ret == (size_t)(-2)); - ASSERT (wc == (wchar_t) 0xBADFACE); - ASSERT (!mbsinit (&state)); - input[1] = '\0'; - - src = input + 2; - temp_state = state; - ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state); - ASSERT (ret == 4); - ASSERT (src == input + 2); - ASSERT (!mbsinit (&state)); - - src = input + 2; - ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state); - ASSERT (ret == (unlimited ? 4 : 2)); - ASSERT (src == (unlimited ? NULL : input + 5)); - ASSERT (wctob (buf[0]) == EOF); - ASSERT (wctob (buf[1]) == EOF); - if (unlimited) - { - ASSERT (buf[2] == 'e'); - ASSERT (buf[3] == 'r'); - ASSERT (buf[4] == 0); - ASSERT (buf[5] == (wchar_t) 0xBADFACE); - } - else - ASSERT (buf[2] == (wchar_t) 0xBADFACE); - ASSERT (mbsinit (&state)); - } - break; - - case '3': - /* Locale encoding is EUC-JP. */ - { - char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == '<'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 2, &state); - ASSERT (ret == 2); - ASSERT (wctob (wc) == EOF); - ASSERT (mbsinit (&state)); - input[1] = '\0'; - input[2] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 3, 1, &state); - ASSERT (ret == (size_t)(-2)); - ASSERT (wc == (wchar_t) 0xBADFACE); - ASSERT (!mbsinit (&state)); - input[3] = '\0'; - - src = input + 4; - temp_state = state; - ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state); - ASSERT (ret == 3); - ASSERT (src == input + 4); - ASSERT (!mbsinit (&state)); - - src = input + 4; - ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state); - ASSERT (ret == (unlimited ? 3 : 2)); - ASSERT (src == (unlimited ? NULL : input + 7)); - ASSERT (wctob (buf[0]) == EOF); - ASSERT (wctob (buf[1]) == EOF); - if (unlimited) - { - ASSERT (buf[2] == '>'); - ASSERT (buf[3] == 0); - ASSERT (buf[4] == (wchar_t) 0xBADFACE); - } - else - ASSERT (buf[2] == (wchar_t) 0xBADFACE); - ASSERT (mbsinit (&state)); - } - break; - - case '4': - /* Locale encoding is GB18030. */ - { - char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'B'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 1, &state); - ASSERT (ret == (size_t)(-2)); - ASSERT (wc == (wchar_t) 0xBADFACE); - ASSERT (!mbsinit (&state)); - input[1] = '\0'; - - src = input + 2; - temp_state = state; - ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state); - ASSERT (ret == 4); - ASSERT (src == input + 2); - ASSERT (!mbsinit (&state)); - - src = input + 2; - ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state); - ASSERT (ret == (unlimited ? 4 : 2)); - ASSERT (src == (unlimited ? NULL : input + 7)); - ASSERT (wctob (buf[0]) == EOF); - ASSERT (wctob (buf[1]) == EOF); - if (unlimited) - { - ASSERT (buf[2] == 'e'); - ASSERT (buf[3] == 'r'); - ASSERT (buf[4] == 0); - ASSERT (buf[5] == (wchar_t) 0xBADFACE); - } - else - ASSERT (buf[2] == (wchar_t) 0xBADFACE); - ASSERT (mbsinit (&state)); - } - break; - - case '5': /* C or POSIX locale. */ { char input[] = "n/a"; @@ -356,6 +166,196 @@ main (int argc, char *argv[]) } break; + case '2': + /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ + { + char input[] = "B\374\337er"; /* "Büßer" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'B'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 1, &state); + ASSERT (ret == 1); + ASSERT (wctob (wc) == (unsigned char) '\374'); + ASSERT (mbsinit (&state)); + input[1] = '\0'; + + src = input + 2; + temp_state = state; + ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 1, &temp_state); + ASSERT (ret == 3); + ASSERT (src == input + 2); + ASSERT (mbsinit (&state)); + + src = input + 2; + ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 1, &state); + ASSERT (ret == (unlimited ? 3 : 1)); + ASSERT (src == (unlimited ? NULL : input + 3)); + ASSERT (wctob (buf[0]) == (unsigned char) '\337'); + if (unlimited) + { + ASSERT (buf[1] == 'e'); + ASSERT (buf[2] == 'r'); + ASSERT (buf[3] == 0); + ASSERT (buf[4] == (wchar_t) 0xBADFACE); + } + else + ASSERT (buf[1] == (wchar_t) 0xBADFACE); + ASSERT (mbsinit (&state)); + } + break; + + case '3': + /* Locale encoding is UTF-8. */ + { + char input[] = "B\303\274\303\237er"; /* "Büßer" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'B'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 1, &state); + ASSERT (ret == (size_t)(-2)); + ASSERT (wc == (wchar_t) 0xBADFACE); + ASSERT (!mbsinit (&state)); + input[1] = '\0'; + + src = input + 2; + temp_state = state; + ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state); + ASSERT (ret == 4); + ASSERT (src == input + 2); + ASSERT (!mbsinit (&state)); + + src = input + 2; + ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state); + ASSERT (ret == (unlimited ? 4 : 2)); + ASSERT (src == (unlimited ? NULL : input + 5)); + ASSERT (wctob (buf[0]) == EOF); + ASSERT (wctob (buf[1]) == EOF); + if (unlimited) + { + ASSERT (buf[2] == 'e'); + ASSERT (buf[3] == 'r'); + ASSERT (buf[4] == 0); + ASSERT (buf[5] == (wchar_t) 0xBADFACE); + } + else + ASSERT (buf[2] == (wchar_t) 0xBADFACE); + ASSERT (mbsinit (&state)); + } + break; + + case '4': + /* Locale encoding is EUC-JP. */ + { + char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == '<'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 2, &state); + ASSERT (ret == 2); + ASSERT (wctob (wc) == EOF); + ASSERT (mbsinit (&state)); + input[1] = '\0'; + input[2] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 3, 1, &state); + ASSERT (ret == (size_t)(-2)); + ASSERT (wc == (wchar_t) 0xBADFACE); + ASSERT (!mbsinit (&state)); + input[3] = '\0'; + + src = input + 4; + temp_state = state; + ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state); + ASSERT (ret == 3); + ASSERT (src == input + 4); + ASSERT (!mbsinit (&state)); + + src = input + 4; + ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state); + ASSERT (ret == (unlimited ? 3 : 2)); + ASSERT (src == (unlimited ? NULL : input + 7)); + ASSERT (wctob (buf[0]) == EOF); + ASSERT (wctob (buf[1]) == EOF); + if (unlimited) + { + ASSERT (buf[2] == '>'); + ASSERT (buf[3] == 0); + ASSERT (buf[4] == (wchar_t) 0xBADFACE); + } + else + ASSERT (buf[2] == (wchar_t) 0xBADFACE); + ASSERT (mbsinit (&state)); + } + break; + + case '5': + /* Locale encoding is GB18030. */ + { + char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'B'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 1, &state); + ASSERT (ret == (size_t)(-2)); + ASSERT (wc == (wchar_t) 0xBADFACE); + ASSERT (!mbsinit (&state)); + input[1] = '\0'; + + src = input + 2; + temp_state = state; + ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state); + ASSERT (ret == 4); + ASSERT (src == input + 2); + ASSERT (!mbsinit (&state)); + + src = input + 2; + ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state); + ASSERT (ret == (unlimited ? 4 : 2)); + ASSERT (src == (unlimited ? NULL : input + 7)); + ASSERT (wctob (buf[0]) == EOF); + ASSERT (wctob (buf[1]) == EOF); + if (unlimited) + { + ASSERT (buf[2] == 'e'); + ASSERT (buf[3] == 'r'); + ASSERT (buf[4] == 0); + ASSERT (buf[5] == (wchar_t) 0xBADFACE); + } + else + ASSERT (buf[2] == (wchar_t) 0xBADFACE); + ASSERT (mbsinit (&state)); + } + break; + default: return 1; }