mirror of
https://git.savannah.gnu.org/git/gnulib.git
synced 2026-10-24 00:48:56 +03:00
mbsrtowcs tests: Renumber tests.
* tests/test-mbsrtowcs*.sh: Renamed 1 -> 2 -> 3 -> 4 -> 5 -> 1. * tests/test-mbsrtowcs.c: Update. * modules/mbsrtowcs-tests: Update.
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
2023-07-29 Bruno Haible <bruno@clisp.org>
|
||||
|
||||
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.
|
||||
|
||||
@@ -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@' \
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user