tests: remove test for buggy mbrtowc

These tests should no longer be needed, as we no longer restart
mbrtowc after an incomplete scan.  This effectively reverts commit
77a7c6a731 dated 2016-07-04.
* init.cfg (require_valid_ja_shiftjis_locale_)
(require_valid_ja_eucjp_locale_): Remove.  All uses removed.
* testsuite/local.mk (check_PROGRAMS): Remove testsuite/test-mbrtowc.
(testsuite_test_mbrtowc_LDADD): Remove.
* testsuite/test-mbrtowc.c: Remove.
This commit is contained in:
Paul Eggert committed 2026-08-17 01:17:23 -07:00
1 parent 228652f200
commit f3b29e0d76
6 files changed
+1 -203

No files matched your search

-1
View File
@@ -60,7 +60,6 @@
/testsuite/eval.in2
/testsuite/get-mb-cur-max
/testsuite/init.sh
/testsuite/test-mbrtowc
Makefile
Makefile.in
gt-bug*
-24
View File
@@ -99,30 +99,6 @@ require_ja_shiftjis_locale_()
test -z "$LOCALE_JA_SJIS" && skip_ 'ja_JP shift-jis locale not found'
}
# Ensure the implementation of mbrtowc can detect invalid
# multibyte shiftjis sequences. Otherwise, skip the test, to avoid
# false-alarms.
# "$1" should be the name of the SHIFT-JIS locale
# (as set by 'require_ja_shiftjis_locale_' above)
require_valid_ja_shiftjis_locale_()
{
path_prepend_ ./testsuite
local n=$(printf '\203:' | LC_ALL="$1" test-mbrtowc)
test "x$n" = "x-2,-1" || skip_ "locale '$1' is buggy"
}
# Ensure the implementation of mbrtowc can detect invalid
# multibyte eucJP sequences. Otherwise, skip the test, to avoid
# false-alarms.
# "$1" should be the name of the ja_JP.eucJP locale
# (as set in $LOCALE_JA by m4/locale-ja.m4)
require_valid_ja_eucjp_locale_()
{
path_prepend_ .
local n=$(printf '\262C' | LC_ALL="$1" test-mbrtowc)
test "x$n" = "x-2,-1" || skip_ "locale '$1' is buggy"
}
# When testing on a Windows machine, sed might output
# line endings as CR,LF (\r\n) pairs - which will
# then fail comparison with the expected output files.
-3
View File
@@ -23,9 +23,6 @@ require_valgrind_
test "$LOCALE_JA" = none && skip_ found no Japanese EUC locale
# Ensure the implementation is not buggy (skip otherwise)
require_valid_ja_eucjp_locale_ "$LOCALE_JA"
echo a > in || framework_failure_
printf 'b\262C\n' > exp || framework_failure_
LC_ALL=$LOCALE_JA valgrind --quiet --error-exitcode=1 \
+1 -2
View File
@@ -127,9 +127,8 @@ TESTS = $(SEDTESTS) $(T)
SEDTESTS =
check_PROGRAMS = testsuite/get-mb-cur-max testsuite/test-mbrtowc
check_PROGRAMS = testsuite/get-mb-cur-max
testsuite_get_mb_cur_max_LDADD = lib/libsed.a $(INTLLIBS)
testsuite_test_mbrtowc_LDADD = lib/libsed.a $(INTLLIBS)
# Note that the first lines are statements. They ensure that environment
# variables that can perturb tests are unset or set to expected values.
-3
View File
@@ -24,9 +24,6 @@ print_ver_ sed
# If found, LOCALE_JA_SJIS will contain the locale name.
require_ja_shiftjis_locale_
# Ensure the implementation is not buggy (skip otherwise)
require_valid_ja_shiftjis_locale_ "$LOCALE_JA_SJIS"
# This test uses two characters:
# Unicode Character 'KATAKANA LETTER ZE' (U+30BC)
# Unicode Character 'KATAKANA LETTER ZO' (U+30BE)
-170
View File
@@ -1,170 +0,0 @@
/* Auxiliary program to test mbrtowc(3) behaviour.
Copyright 2016-2026 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; If not, see <https://www.gnu.org/licenses/>. */
/* Test the operating-system's native mbrtowc(3) function,
by feeding it multibyte sequences one byte at a time,
and reporting the result.
The program prints the following values after each mbrtowc invocation,
separated by commas:
-2 the octet is contributes to a valid yet incomplete multibyte sequence
in the current locale.
-1 the octet causes an encoding error.
0 the octet represents a NUL byte
1 the octet is a valid single-byte character, OR
completes a valid multibyte sequence.
Because the program invokes mbrtowc(3) byte-by-byte, the reported
result should never be larger than 1.
Example of typical output with UTF-8 encoding
---------------------------------------------
The unicode character 'N-ARY SUMMATION' (U+2211), encoded in UTF-8 as:
hex: 0xE2 0x88 0x91
oct: 342 210 211
Decoding the valid sequence byte-by-byte gives:
$ printf '\342\210\221' | LC_ALL=en_US.UTF-8 test-mbrtowc
-2,-2,1
'\210' is not a valid leading byte in UTF-8,
thus the first byte gives -1, and the 'X' is treated
as a valid single-byte character:
$ printf '\210X' | LC_ALL=en_US.UTF-8 test-mbrtowc
-1,1
'\342' is a valid yet incomplete multibyte sequence.
Passing it to mbrtowc results in value '-2'.
The following value 'X' gives an encoding error '-1'
(as 'X' is not a valid trailing byte in a multibyte UTF-8 sequence):
$ printf '\342X' | LC_ALL=en_US.UTF-8 test-mbrtowc
-2,-1
Detecting implementation bugs in mbrtowc
----------------------------------------
UTF-8 implementation is correct on most operating systems.
Other multibyte locales might present more difficulties.
An example is the Japanese SHIFT-JIS locale under Mac OS X.
NOTE: The locale is 'ja_JP.SJIS' under Mac OS X, 'ja_JP.shiftjis'
under Ubuntu. 'ja_JP.sjis' was also found on some systems.
Using unicode character 'KATAKANA LETTER ZE' (U+30BC)
UTF-8: hex: 0xE3 0x82 0xBC
Shift-jis hex: 0x83 0x5B
oct: 203 133
The following is a valid multibyte sequence in SHIFT-JIS,
the first byte should result in '-2' (valid yet incomplete),
and the second byte should result in '1' (a valid multibyte sequence
completed):
$ printf '\203\133' | LC_ALL=ja_JP.SJIS test-mbrtowc
-2,1
The following is an INVALID multibyte sequence in SHIFT-JIS
(The byte ':' is not valid as a second octet).
Buggy implementations will accept this as a valid multibyte sequence:
# NOTE: this result indicates a buggy mbrtowc
$ printf '\203:' | LC_ALL=ja_JP.SJIS test-mbrtowc
-2,1
A correct implementations should report '-1' for the second byte (i.e.
an encoding error):
$ printf '\203:' | LC_ALL=ja_JP.SJIS test-mbrtowc
-2,-1
Expected results with correct implementations
---------------------------------------------
In GNU Sed some tests purposely use invalid multibyte sequences
to test sed's behaviour. A buggy implementation of mbrtowc
would result in false-alarm failures.
The following are expected results in correct implementations:
(locale names are from Mac OS X):
$ printf '\203\133' | LC_ALL=ja_JP.SJIS test-mbrtowc
-2,1
$ printf '\203:' | LC_ALL=ja_JP.SJIS test-mbrtowc
-2,-1
$ printf '\262C' | LC_ALL=ja_JP.eucJP test-mbrtowc
-2,-1
*/
#include <config.h>
#include <error.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include "progname.h"
/* stub replacement for non-standard err(3) */
static int
die (const char *msg)
{
error (0, 0, "%s: error: %s\n", program_name, msg);
exit (EXIT_FAILURE);
}
int
main (int argc, char **argv)
{
int c;
int first = 1;
set_program_name (argv[0]);
if (!setlocale (LC_ALL, ""))
die ("failed to set locale");
while ((c = getchar ()) != EOF)
{
wchar_t wc;
char ch = (unsigned char) c;
int i = (int) mbrtowc (&wc, &ch, 1, NULL);
if (!first)
putchar (',');
first = 0;
printf ("%d", i);
}
if (first)
die ("empty input");
putchar ('\n');
if (ferror (stdin))
die ("read error");
if (ferror (stdout) || fclose (stdout) != 0)
die ("write error");
exit (EXIT_SUCCESS);
}