about summary refs log tree commit diff
path: root/libio/tst-swscanf.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-08-09 19:10:37 +0000
committerUlrich Drepper <drepper@redhat.com>2001-08-09 19:10:37 +0000
commitcc7f258f32352916d508a6f034f51f14abfc7efe (patch)
tree334b195b585e4d24e70a4731da630552a8c8e198 /libio/tst-swscanf.c
parent3926e63db245e06807988a1fe4129dde072d1154 (diff)
downloadglibc-cc7f258f32352916d508a6f034f51f14abfc7efe.tar.gz
glibc-cc7f258f32352916d508a6f034f51f14abfc7efe.tar.xz
glibc-cc7f258f32352916d508a6f034f51f14abfc7efe.zip
Update.
2001-08-09  Ulrich Drepper  <drepper@redhat.com>

	* stdio-common/vfscanf.c: Fix handling of %[] for COMPILE_WSCANF.
	* libio/Makefile (tests): Add tst-swscanf.
	* libio/tst-swscanf.c: New file.
Diffstat (limited to 'libio/tst-swscanf.c')
-rw-r--r--libio/tst-swscanf.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/libio/tst-swscanf.c b/libio/tst-swscanf.c
new file mode 100644
index 0000000000..86472de16e
--- /dev/null
+++ b/libio/tst-swscanf.c
@@ -0,0 +1,100 @@
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <wchar.h>
+
+
+static int do_test (const char *loc);
+
+
+int
+main (void)
+{
+  int result;
+
+  result = do_test ("C");
+  result |= do_test ("de_DE.ISO-8859-1");
+  result |= do_test ("de_DE.UTF-8");
+  result |= do_test ("ja_JP.EUC-JP");
+
+  return result;
+}
+
+
+static const struct
+{
+  const wchar_t *fmt;
+  const wchar_t *wfmt;
+  const wchar_t *arg;
+  const char *res;
+  const wchar_t *wres;
+  int only_C_locale;
+} tests[] =
+  {
+    { L"%[abc]", L"%l[abc]", L"aabbccddaabb", "aabbcc", L"aabbcc", 0 },
+    { L"%[^def]", L"%l[^def]", L"aabbccddaabb", "aabbcc", L"aabbcc", 0 },
+    { L"%[^abc]", L"%l[^abc]", L"aabbccddaabb", "", L"", 0 },
+    { L"%[a-c]", L"%l[a-c]", L"aabbccddaabb", "aabbcc", L"aabbcc", 1 },
+    { L"%[^d-f]", L"%l[^d-f]", L"aabbccddaabb", "aabbcc", L"aabbcc", 1 },
+    { L"%[^a-c]", L"%l[^a-c]", L"aabbccddaabb", "", L"", 1 },
+    { L"%[^a-c]", L"%l[^a-c]", L"bbccddaabb", "", L"", 1 }
+  };
+
+
+static int
+do_test (const char *loc)
+{
+  size_t n;
+  int result = 0;
+
+  if (setlocale (LC_ALL, loc) == NULL)
+    {
+      printf ("cannot set locale \"%s\": %m\n", loc);
+      return 1;
+    }
+
+  printf ("\nnew locale: \"%s\"\n", loc);
+
+  for (n = 0; n < sizeof (tests) / sizeof (tests[0]); ++n)
+    {
+      char buf[100];
+      wchar_t wbuf[100];
+
+      if (tests[n].only_C_locale && strcmp (loc, "C") != 0)
+	continue;
+
+      if (swscanf (tests[n].arg, tests[n].fmt, buf) != 1)
+	{
+	  printf ("swscanf (\"%S\", \"%S\", ...) failed\n",
+		  tests[n].arg, tests[n].fmt);
+	  result = 1;
+	}
+      else if (strcmp (buf, tests[n].res) != 0)
+	{
+	  printf ("swscanf (\"%S\", \"%S\", ...) return \"%s\", expected \"%s\"\n",
+		  tests[n].arg, tests[n].fmt, buf, tests[n].res);
+	  result = 1;
+	}
+      else
+	printf ("swscanf (\"%S\", \"%S\", ...) OK\n",
+		tests[n].arg, tests[n].fmt);
+
+      if (swscanf (tests[n].arg, tests[n].wfmt, wbuf) != 1)
+	{
+	  printf ("swscanf (\"%S\", \"%S\", ...) failed\n",
+		  tests[n].arg, tests[n].wfmt);
+	  result = 1;
+	}
+      else if (wcscmp (wbuf, tests[n].wres) != 0)
+	{
+	  printf ("swscanf (\"%S\", \"%S\", ...) return \"%S\", expected \"%S\"\n",
+		  tests[n].arg, tests[n].wfmt, wbuf, tests[n].wres);
+	  result = 1;
+	}
+      else
+	printf ("swscanf (\"%S\", \"%S\", ...) OK\n",
+		tests[n].arg, tests[n].wfmt);
+    }
+
+  return result;
+}