summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/iconv/Makefile8
-rw-r--r--test/iconv/Makefile.in2
-rw-r--r--test/iconv/tst-iconv1.c54
-rw-r--r--test/iconv/tst-iconv2.c105
-rw-r--r--test/iconv/tst-iconv3.c63
-rw-r--r--test/iconv/tst-iconv4.c71
-rw-r--r--test/iconv/tst-iconv5.c172
-rw-r--r--test/iconv/tst-iconv6.c124
8 files changed, 599 insertions, 0 deletions
diff --git a/test/iconv/Makefile b/test/iconv/Makefile
new file mode 100644
index 0000000..89e7195
--- /dev/null
+++ b/test/iconv/Makefile
@@ -0,0 +1,8 @@
+# uClibc mmap tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+top_builddir=../../
+top_srcdir=../../
+include ../Rules.mak
+-include Makefile.in
+include ../Test.mak
diff --git a/test/iconv/Makefile.in b/test/iconv/Makefile.in
new file mode 100644
index 0000000..b15ea82
--- /dev/null
+++ b/test/iconv/Makefile.in
@@ -0,0 +1,2 @@
+# uClibc-ng mmap tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
diff --git a/test/iconv/tst-iconv1.c b/test/iconv/tst-iconv1.c
new file mode 100644
index 0000000..67b39ff
--- /dev/null
+++ b/test/iconv/tst-iconv1.c
@@ -0,0 +1,54 @@
+/* Test case by yaoz@nih.gov. */
+
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+#include <iconv.h>
+#endif
+
+static int
+do_test (void)
+{
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+ char utf8[5];
+ wchar_t ucs4[5];
+ iconv_t cd;
+ char *inbuf;
+ char *outbuf;
+ size_t inbytes;
+ size_t outbytes;
+ size_t n;
+
+ strcpy (utf8, "abcd");
+
+ /* From UTF8 to UCS4. */
+ cd = iconv_open ("UCS4", "UTF8");
+ if (cd == (iconv_t) -1)
+ {
+ perror ("iconv_open");
+ return 1;
+ }
+
+ inbuf = utf8;
+ inbytes = 4;
+ outbuf = (char *) ucs4;
+ outbytes = 4 * sizeof (wchar_t); /* "Argument list too long" error. */
+ n = iconv (cd, &inbuf, &inbytes, &outbuf, &outbytes);
+ if (n == (size_t) -1)
+ {
+ printf ("iconv: %m\n");
+ iconv_close (cd);
+ return 1;
+ }
+ iconv_close (cd);
+
+ return 0;
+#else
+ return 23;
+#endif
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/test/iconv/tst-iconv2.c b/test/iconv/tst-iconv2.c
new file mode 100644
index 0000000..9dfff19
--- /dev/null
+++ b/test/iconv/tst-iconv2.c
@@ -0,0 +1,105 @@
+/* Copyright (C) 2001-2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 2001.
+
+ 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, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+#include <iconv.h>
+#endif
+
+static int
+do_test (void)
+{
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+ char buf[3];
+ const wchar_t wc[1] = L"a";
+ iconv_t cd;
+ char *inptr;
+ size_t inlen;
+ char *outptr;
+ size_t outlen;
+ size_t n;
+ int e;
+ int result = 0;
+
+ cd = iconv_open ("UCS4", "WCHAR_T");
+ if (cd == (iconv_t) -1)
+ {
+ printf ("cannot convert from wchar_t to UCS4: %m\n");
+ exit (1);
+ }
+
+ inptr = (char *) wc;
+ inlen = sizeof (wchar_t);
+ outptr = buf;
+ outlen = 3;
+
+ n = iconv (cd, &inptr, &inlen, &outptr, &outlen);
+ e = errno;
+
+ if (n != (size_t) -1)
+ {
+ printf ("incorrect iconv() return value: %zd, expected -1\n", n);
+ result = 1;
+ }
+
+ if (e != E2BIG)
+ {
+ printf ("incorrect error value: %s, expected %s\n",
+ strerror (e), strerror (E2BIG));
+ result = 1;
+ }
+
+ if (inptr != (char *) wc)
+ {
+ puts ("inptr changed");
+ result = 1;
+ }
+
+ if (inlen != sizeof (wchar_t))
+ {
+ puts ("inlen changed");
+ result = 1;
+ }
+
+ if (outptr != buf)
+ {
+ puts ("outptr changed");
+ result = 1;
+ }
+
+ if (outlen != 3)
+ {
+ puts ("outlen changed");
+ result = 1;
+ }
+
+ iconv_close (cd);
+
+ return result;
+#else
+ return 23;
+#endif
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/test/iconv/tst-iconv3.c b/test/iconv/tst-iconv3.c
new file mode 100644
index 0000000..7853fa6
--- /dev/null
+++ b/test/iconv/tst-iconv3.c
@@ -0,0 +1,63 @@
+/* Contributed by Owen Taylor <otaylor@redhat.com>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <stdio.h>
+
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+#include <iconv.h>
+#endif
+
+#define BUFSIZE 10000
+
+static int
+do_test (void)
+{
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+ char inbuf[BUFSIZE];
+ wchar_t outbuf[BUFSIZE];
+
+ iconv_t cd;
+ int i;
+ char *inptr;
+ char *outptr;
+ size_t inbytes_left, outbytes_left;
+ int count;
+ int result = 0;
+
+ for (i=0; i < BUFSIZE; i++)
+ inbuf[i] = 'a';
+
+ cd = iconv_open ("UCS-4LE", "UTF-8");
+
+ inbytes_left = BUFSIZE;
+ outbytes_left = BUFSIZE * 4;
+ inptr = inbuf;
+ outptr = (char *) outbuf;
+
+ count = iconv (cd, &inptr, &inbytes_left, &outptr, &outbytes_left);
+
+ if (count < 0)
+ {
+ if (errno == E2BIG)
+ printf ("Received E2BIG\n");
+ else
+ printf ("Received something else\n");
+
+ printf ("inptr change: %td\n", inptr - inbuf);
+ printf ("inlen change: %zd\n", BUFSIZE - inbytes_left);
+ printf ("outptr change: %td\n", outptr - (char *) outbuf);
+ printf ("outlen change: %zd\n", BUFSIZE * 4 - outbytes_left);
+ result = 1;
+ }
+ else
+ printf ("Succeeded\n");
+
+ return result;
+#else
+ return 23;
+#endif
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/test/iconv/tst-iconv4.c b/test/iconv/tst-iconv4.c
new file mode 100644
index 0000000..bba30f6
--- /dev/null
+++ b/test/iconv/tst-iconv4.c
@@ -0,0 +1,71 @@
+// Derived from BZ #9793
+#include <errno.h>
+#include <stdio.h>
+
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+#include <iconv.h>
+#endif
+
+static int
+do_test (void)
+{
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+ iconv_t cd = iconv_open ("ASCII//TRANSLIT", "UTF-8");
+ if (cd == (iconv_t) -1)
+ {
+ puts ("iconv_open failed");
+ return 1;
+ }
+
+ char input[2] = { 0xc2, 0xae }; /* Registered trademark */
+ char *inptr = input;
+ size_t insize = sizeof (input);
+ char output[2]; /* Too short to contain "(R)". */
+ char *outptr = output;
+ size_t outsize = sizeof (output);
+
+ size_t ret = iconv (cd, &inptr, &insize, &outptr, &outsize);
+ if (ret != (size_t) -1)
+ {
+ puts ("iconv succeeded");
+ return 1;
+ }
+ if (errno != E2BIG)
+ {
+ puts ("iconv did not set errno to E2BIG");
+ return 1;
+ }
+ int res = 0;
+ if (inptr != input)
+ {
+ puts ("inptr changed");
+ res = 1;
+ }
+ if (insize != sizeof (input))
+ {
+ puts ("insize changed");
+ res = 1;
+ }
+ if (outptr != output)
+ {
+ puts ("outptr changed");
+ res = 1;
+ }
+ if (outsize != sizeof (output))
+ {
+ puts ("outsize changed");
+ res = 1;
+ }
+ if (iconv_close (cd) == -1)
+ {
+ puts ("iconv_close failed");
+ res = 1;
+ }
+ return res;
+#else
+ return 23;
+#endif
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/test/iconv/tst-iconv5.c b/test/iconv/tst-iconv5.c
new file mode 100644
index 0000000..ff3fde5
--- /dev/null
+++ b/test/iconv/tst-iconv5.c
@@ -0,0 +1,172 @@
+/* Copyright (C) 2004-2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by GOTO Masanori <gotom@debian.or.jp>, 2004
+
+ 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, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+
+#if defined __UCLIBC_HAS_LIBICONV__ || (defined(__GLIBC__) && !defined __UCLIBC__)
+#include <iconv.h>
+
+#define SIZE 256 /* enough room for conversion */
+#define SAMPLESTR "abc"
+
+struct unalign
+{
+ char str1[1];
+ char str2[SIZE];
+};
+
+struct convcode
+{
+ const char *tocode;
+ const char *fromcode;
+};
+
+/* test builtin transformation */
+static const struct convcode testcode[] = {
+#if defined __UCLIBC_HAS_LIBICONV__ || (defined(__GLIBC__) && !defined __UCLIBC__)
+ {"ASCII", "ASCII"},
+ {"UTF-8", "ASCII"},
+#endif
+#if defined(__GLIBC__) && !defined __UCLIBC__
+ {"UCS-2BE", "ASCII"},
+ {"UCS-2LE", "ASCII"},
+ {"UCS-4BE", "ASCII"},
+ {"UCS-4LE", "ASCII"},
+#endif
+};
+
+static const int number = (int) sizeof (testcode) / sizeof (struct convcode);
+
+static int
+convert (const char *tocode, const char *fromcode, char *inbufp,
+ size_t inbytesleft, char *outbufp, size_t outbytesleft)
+{
+ iconv_t *ic;
+ size_t outbytes = outbytesleft;
+ int ret;
+
+ ic = iconv_open (tocode, fromcode);
+ if (ic == (iconv_t *) - 1)
+ {
+ printf ("iconv_open failed: from: %s, to: %s: %s",
+ fromcode, tocode, strerror (errno));
+ return -1;
+ }
+
+ while (inbytesleft > 0)
+ {
+ ret = iconv (ic, &inbufp, &inbytesleft, &outbufp, &outbytes);
+ if (ret == -1)
+ {
+ printf ("iconv failed: from: %s, to: %s: %s",
+ fromcode, tocode, strerror (errno));
+ return -1;
+ }
+ }
+
+ ret = iconv_close (ic);
+ if (ret == -1)
+ {
+ printf ("iconv_close failed: from: %s, to: %s: %s",
+ fromcode, tocode, strerror (errno));
+ return -1;
+ }
+
+ return outbytesleft - outbytes;
+}
+
+
+static int
+test_unalign (const struct convcode *codes, const char *str, int len)
+{
+ struct unalign *inbufp, *outbufp;
+ char *inbuf, *outbuf;
+ size_t inbytesleft, outbytesleft;
+ int retlen;
+
+ /* allocating unaligned buffer for both inbuf and outbuf */
+ inbufp = (struct unalign *) malloc (sizeof (struct unalign));
+ if (!inbufp)
+ {
+ printf ("no memory available\n");
+ exit (1);
+ }
+ inbuf = inbufp->str2;
+
+ outbufp = (struct unalign *) malloc (sizeof (struct unalign));
+ if (!outbufp)
+ {
+ printf ("no memory available\n");
+ exit (1);
+ }
+ outbuf = outbufp->str2;
+
+ /* first iconv phase */
+ memcpy (inbuf, str, len);
+ inbytesleft = len;
+ outbytesleft = sizeof (struct unalign);
+ retlen = convert (codes->tocode, codes->fromcode, inbuf, inbytesleft,
+ outbuf, outbytesleft);
+ if (retlen == -1) /* failed */
+ return 1;
+
+ /* second round trip iconv phase */
+ memcpy (inbuf, outbuf, retlen);
+ inbytesleft = retlen;
+ outbytesleft = sizeof (struct unalign);
+ retlen = convert (codes->fromcode, codes->tocode, inbuf, inbytesleft,
+ outbuf, outbytesleft);
+ if (retlen == -1) /* failed */
+ return 1;
+
+ free (inbufp);
+ free (outbufp);
+
+ return 0;
+}
+#endif
+
+static int
+do_test (void)
+{
+#if defined __UCLIBC_HAS_LIBICONV__ || (defined(__GLIBC__) && !defined __UCLIBC__)
+ int i;
+ int ret = 0;
+
+ for (i = 0; i < number; i++)
+ {
+ ret = test_unalign (&testcode[i], (char *) SAMPLESTR, sizeof (SAMPLESTR));
+ if (ret)
+ break;
+ printf ("iconv: %s <-> %s: ok\n",
+ testcode[i].fromcode, testcode[i].tocode);
+ }
+ if (ret == 0)
+ printf ("Succeeded.\n");
+
+ return ret;
+#else
+ return 23;
+#endif
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/test/iconv/tst-iconv6.c b/test/iconv/tst-iconv6.c
new file mode 100644
index 0000000..ebd4a89
--- /dev/null
+++ b/test/iconv/tst-iconv6.c
@@ -0,0 +1,124 @@
+/* Testing ucs4le_internal_loop() in gconv_simple.c.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <inttypes.h>
+#include <byteswap.h>
+
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+#include <iconv.h>
+#endif
+
+static int
+do_test (void)
+{
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+ iconv_t cd;
+ char *inptr;
+ size_t inlen;
+ char *outptr;
+ size_t outlen;
+ size_t n;
+ int e;
+ int result = 0;
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+ /* On big-endian machines, ucs4le_internal_loop() swaps the bytes before
+ error checking. Thus the input values has to be swapped. */
+# define VALUE(val) bswap_32 (val)
+#else
+# define VALUE(val) val
+#endif
+ uint32_t inbuf[3] = { VALUE (0x41), VALUE (0x80000000), VALUE (0x42) };
+ uint32_t outbuf[3] = { 0, 0, 0 };
+
+ cd = iconv_open ("WCHAR_T", "UCS-4LE");
+ if (cd == (iconv_t) -1)
+ {
+ printf ("cannot convert from UCS4LE to wchar_t: %m\n");
+ return 1;
+ }
+
+ inptr = (char *) inbuf;
+ inlen = sizeof (inbuf);
+ outptr = (char *) outbuf;
+ outlen = sizeof (outbuf);
+
+ n = iconv (cd, &inptr, &inlen, &outptr, &outlen);
+ e = errno;
+
+ if (n != (size_t) -1)
+ {
+ printf ("incorrect iconv() return value: %zd, expected -1\n", n);
+ result = 1;
+ }
+
+ if (e != EILSEQ)
+ {
+ printf ("incorrect error value: %s, expected %s\n",
+ strerror (e), strerror (EILSEQ));
+ result = 1;
+ }
+
+ if (inptr != (char *) &inbuf[1])
+ {
+ printf ("inptr=0x%p does not point to invalid character! Expected=0x%p\n"
+ , inptr, &inbuf[1]);
+ result = 1;
+ }
+
+ if (inlen != sizeof (inbuf) - sizeof (uint32_t))
+ {
+ printf ("inlen=%zd != %zd\n"
+ , inlen, sizeof (inbuf) - sizeof (uint32_t));
+ result = 1;
+ }
+
+ if (outptr != (char *) &outbuf[1])
+ {
+ printf ("outptr=0x%p does not point to invalid character in inbuf! "
+ "Expected=0x%p\n"
+ , outptr, &outbuf[1]);
+ result = 1;
+ }
+
+ if (outlen != sizeof (inbuf) - sizeof (uint32_t))
+ {
+ printf ("outlen=%zd != %zd\n"
+ , outlen, sizeof (outbuf) - sizeof (uint32_t));
+ result = 1;
+ }
+
+ if (outbuf[0] != 0x41 || outbuf[1] != 0 || outbuf[2] != 0)
+ {
+ puts ("Characters conversion is incorrect!");
+ result = 1;
+ }
+
+ iconv_close (cd);
+
+ return result;
+#else
+ return 23;
+#endif
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"