]>
Commit | Line | Data |
---|---|---|
cc7f258f UD |
1 | #include <locale.h> |
2 | #include <stdio.h> | |
3 | #include <string.h> | |
4 | #include <wchar.h> | |
5 | ||
6 | ||
7 | static int do_test (const char *loc); | |
8 | ||
9 | ||
10 | int | |
11 | main (void) | |
12 | { | |
13 | int result; | |
14 | ||
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"); | |
19 | ||
20 | return result; | |
21 | } | |
22 | ||
23 | ||
24 | static const struct | |
25 | { | |
26 | const wchar_t *fmt; | |
27 | const wchar_t *wfmt; | |
28 | const wchar_t *arg; | |
29 | const char *res; | |
30 | const wchar_t *wres; | |
31 | int only_C_locale; | |
32 | } tests[] = | |
33 | { | |
34 | { L"%[abc]", L"%l[abc]", L"aabbccddaabb", "aabbcc", L"aabbcc", 0 }, | |
35 | { L"%[^def]", L"%l[^def]", L"aabbccddaabb", "aabbcc", L"aabbcc", 0 }, | |
36 | { L"%[^abc]", L"%l[^abc]", L"aabbccddaabb", "", L"", 0 }, | |
37 | { L"%[a-c]", L"%l[a-c]", L"aabbccddaabb", "aabbcc", L"aabbcc", 1 }, | |
38 | { L"%[^d-f]", L"%l[^d-f]", L"aabbccddaabb", "aabbcc", L"aabbcc", 1 }, | |
39 | { L"%[^a-c]", L"%l[^a-c]", L"aabbccddaabb", "", L"", 1 }, | |
40 | { L"%[^a-c]", L"%l[^a-c]", L"bbccddaabb", "", L"", 1 } | |
41 | }; | |
42 | ||
43 | ||
44 | static int | |
45 | do_test (const char *loc) | |
46 | { | |
47 | size_t n; | |
48 | int result = 0; | |
49 | ||
50 | if (setlocale (LC_ALL, loc) == NULL) | |
51 | { | |
52 | printf ("cannot set locale \"%s\": %m\n", loc); | |
53 | return 1; | |
54 | } | |
55 | ||
56 | printf ("\nnew locale: \"%s\"\n", loc); | |
57 | ||
58 | for (n = 0; n < sizeof (tests) / sizeof (tests[0]); ++n) | |
59 | { | |
60 | char buf[100]; | |
61 | wchar_t wbuf[100]; | |
62 | ||
63 | if (tests[n].only_C_locale && strcmp (loc, "C") != 0) | |
64 | continue; | |
65 | ||
66 | if (swscanf (tests[n].arg, tests[n].fmt, buf) != 1) | |
67 | { | |
68 | printf ("swscanf (\"%S\", \"%S\", ...) failed\n", | |
69 | tests[n].arg, tests[n].fmt); | |
70 | result = 1; | |
71 | } | |
72 | else if (strcmp (buf, tests[n].res) != 0) | |
73 | { | |
74 | printf ("swscanf (\"%S\", \"%S\", ...) return \"%s\", expected \"%s\"\n", | |
75 | tests[n].arg, tests[n].fmt, buf, tests[n].res); | |
76 | result = 1; | |
77 | } | |
78 | else | |
79 | printf ("swscanf (\"%S\", \"%S\", ...) OK\n", | |
80 | tests[n].arg, tests[n].fmt); | |
81 | ||
82 | if (swscanf (tests[n].arg, tests[n].wfmt, wbuf) != 1) | |
83 | { | |
84 | printf ("swscanf (\"%S\", \"%S\", ...) failed\n", | |
85 | tests[n].arg, tests[n].wfmt); | |
86 | result = 1; | |
87 | } | |
88 | else if (wcscmp (wbuf, tests[n].wres) != 0) | |
89 | { | |
90 | printf ("swscanf (\"%S\", \"%S\", ...) return \"%S\", expected \"%S\"\n", | |
91 | tests[n].arg, tests[n].wfmt, wbuf, tests[n].wres); | |
92 | result = 1; | |
93 | } | |
94 | else | |
95 | printf ("swscanf (\"%S\", \"%S\", ...) OK\n", | |
96 | tests[n].arg, tests[n].wfmt); | |
97 | } | |
98 | ||
99 | return result; | |
100 | } |