diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | iconvdata/Makefile | 2 | ||||
-rw-r--r-- | iconvdata/tst-e2big.c | 105 |
3 files changed, 111 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog index a4fe591c8f..185ce4dac2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-09-22 Bruno Haible <bruno@clisp.org> + + * iconvdata/tst-e2big.c: New file. + * iconvdata/Makefile (tests): Add tst-e2big. + 2002-09-23 Roland McGrath <roland@redhat.com> * elf/Makefile (test-extras): Define this instead of test-srcs. diff --git a/iconvdata/Makefile b/iconvdata/Makefile index 3996d70814..49cf62c35f 100644 --- a/iconvdata/Makefile +++ b/iconvdata/Makefile @@ -58,7 +58,7 @@ modules.so := $(addsuffix .so, $(modules)) include ../Makeconfig ifeq (yes,$(build-shared)) -tests = bug-iconv1 bug-iconv2 tst-loading +tests = bug-iconv1 bug-iconv2 tst-loading tst-e2big test-srcs := tst-table-from tst-table-to endif diff --git a/iconvdata/tst-e2big.c b/iconvdata/tst-e2big.c new file mode 100644 index 0000000000..f47171636c --- /dev/null +++ b/iconvdata/tst-e2big.c @@ -0,0 +1,105 @@ +/* Test for a tricky E2BIG situation. + Copyright (C) 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Bruno Haible <bruno@clisp.org>, 2002. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <alloca.h> +#include <errno.h> +#include <iconv.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> + +/* In EUC-JISX0213 and TSCII, a single input character can convert to + a sequence of two or more Unicode characters. When the output buffer + has room for less Unicode characters than would be produced with an + unconstrained output buffer, the conversion must give errno = E2BIG. */ + +void +test (const char *encoding, char *inbuf, size_t inbufsize, size_t outbufsize) +{ + char *outbuf = alloca (outbufsize); + iconv_t cd; + char *inptr; + size_t inlen; + char *outptr; + size_t outlen; + int result; + bool empty_input; + bool empty_output; + + cd = iconv_open ("UTF-8", encoding); + if (cd == (iconv_t) -1) + { + fprintf (stderr, "cannot convert from %s\n", encoding); + exit (1); + } + + inptr = inbuf; + inlen = inbufsize; + outptr = outbuf; + outlen = outbufsize; + + result = iconv (cd, &inptr, &inlen, &outptr, &outlen); + if (!(result == -1 && errno == E2BIG)) + { + fprintf (stderr, "%s: wrong iconv result: %d/%d (%m)\n", + encoding, result, errno); + exit (1); + } + empty_input = (inptr == inbuf && inlen == inbufsize); + empty_output = (outptr == outbuf && outlen == outbufsize); + + if (!empty_input && empty_output) + { + fprintf (stderr, "%s: ate %d input bytes\n", encoding, inptr - inbuf); + exit (1); + } + if (empty_input && !empty_output) + { + fprintf (stderr, "%s: produced %d output bytes\n", + encoding, outptr - outbuf); + exit (1); + } + + iconv_close (cd); +} + +void +test_euc_jisx0213 (void) +{ + char inbuf[2] = { 0xa4, 0xf7 }; + test ("EUC-JISX0213", inbuf, sizeof (inbuf), 3); +} + +void +test_tscii (void) +{ + char inbuf[1] = { 0x82 }; + test ("TSCII", inbuf, sizeof (inbuf), 3); + test ("TSCII", inbuf, sizeof (inbuf), 6); + test ("TSCII", inbuf, sizeof (inbuf), 9); +} + +int +main (void) +{ + test_euc_jisx0213 (); + test_tscii (); + return 0; +} |