This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

a test for an iconv converter bug


Here is the test against the previous bug in the EUC-JISX0213 converter.
It also tests the TSCII converter.


2002-09-22  Bruno Haible  <bruno@clisp.org>

	* iconvdata/tst-e2big.c: New file.
	* iconvdata/Makefile (tests): Add tst-e2big.

--- /dev/null	Sat Apr 13 17:23:13 2002
+++ glibc-20020828/iconvdata/tst-e2big.c	Sun Sep 22 20:50:46 2002
@@ -0,0 +1,103 @@
+/* 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, "wrong iconv result: %d/%d\n", result, errno);
+      exit (1);
+    }
+  empty_input = (inptr == inbuf && inlen == inbufsize);
+  empty_output = (outptr == outbuf && outlen == outbufsize);
+
+  if (!empty_input && empty_output)
+    {
+      fprintf (stderr, "ate %d input bytes\n", inptr - inbuf);
+      exit (1);
+    }
+  if (empty_input && !empty_output)
+    {
+      fprintf (stderr, "produced %d output bytes\n", 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;
+}
--- glibc-20020828/iconvdata/Makefile.bak	Wed Aug 28 12:51:02 2002
+++ glibc-20020828/iconvdata/Makefile	Sun Sep 22 23:49:26 2002
@@ -58,7 +58,7 @@
 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]