hppa: timerfd.h: move to common sys/timerfd.h
[glibc.git] / libio / tst-swscanf.c
blob05be4e6e7128662a06cea3d3431226814b0d7651
1 #include <locale.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <wchar.h>
7 static int do_test (const char *loc);
10 int
11 main (void)
13 int result;
15 result = do_test ("C");
16 result |= do_test ("de_DE.ISO-8859-1");
17 result |= do_test ("de_DE.UTF-8");
18 result |= do_test ("ja_JP.EUC-JP");
20 return result;
24 static const struct
26 const wchar_t *fmt;
27 const wchar_t *wfmt;
28 const wchar_t *arg;
29 int retval;
30 const char *res;
31 const wchar_t *wres;
32 int only_C_locale;
33 } tests[] =
35 { L"%[abc]", L"%l[abc]", L"aabbccddaabb", 1 ,"aabbcc", L"aabbcc", 0 },
36 { L"%[^def]", L"%l[^def]", L"aabbccddaabb", 1, "aabbcc", L"aabbcc", 0 },
37 { L"%[^abc]", L"%l[^abc]", L"aabbccddaabb", 0, "", L"", 0 },
38 { L"%[a-c]", L"%l[a-c]", L"aabbccddaabb", 1, "aabbcc", L"aabbcc", 1 },
39 { L"%[^d-f]", L"%l[^d-f]", L"aabbccddaabb", 1, "aabbcc", L"aabbcc", 1 },
40 { L"%[^a-c]", L"%l[^a-c]", L"aabbccddaabb", 0, "", L"", 1 },
41 { L"%[^a-c]", L"%l[^a-c]", L"bbccddaabb", 0, "", L"", 1 }
45 static int
46 do_test (const char *loc)
48 size_t n;
49 int result = 0;
51 if (setlocale (LC_ALL, loc) == NULL)
53 printf ("cannot set locale \"%s\": %m\n", loc);
54 return 1;
57 printf ("\nnew locale: \"%s\"\n", loc);
59 for (n = 0; n < sizeof (tests) / sizeof (tests[0]); ++n)
61 char buf[100];
62 wchar_t wbuf[100];
64 if (tests[n].only_C_locale && strcmp (loc, "C") != 0)
65 continue;
67 if (swscanf (tests[n].arg, tests[n].fmt, buf) != tests[n].retval)
69 printf ("swscanf (\"%S\", \"%S\", ...) failed\n",
70 tests[n].arg, tests[n].fmt);
71 result = 1;
73 else if (tests[n].retval != 0 && strcmp (buf, tests[n].res) != 0)
75 printf ("swscanf (\"%S\", \"%S\", ...) return \"%s\", expected \"%s\"\n",
76 tests[n].arg, tests[n].fmt, buf, tests[n].res);
77 result = 1;
79 else
80 printf ("swscanf (\"%S\", \"%S\", ...) OK\n",
81 tests[n].arg, tests[n].fmt);
83 if (swscanf (tests[n].arg, tests[n].wfmt, wbuf) != tests[n].retval)
85 printf ("swscanf (\"%S\", \"%S\", ...) failed\n",
86 tests[n].arg, tests[n].wfmt);
87 result = 1;
89 else if (tests[n].retval != 0 && wcscmp (wbuf, tests[n].wres) != 0)
91 printf ("swscanf (\"%S\", \"%S\", ...) return \"%S\", expected \"%S\"\n",
92 tests[n].arg, tests[n].wfmt, wbuf, tests[n].wres);
93 result = 1;
95 else
96 printf ("swscanf (\"%S\", \"%S\", ...) OK\n",
97 tests[n].arg, tests[n].wfmt);
100 return result;