1 | #include <ctype.h> |
---|---|
2 | #include <locale.h> |
3 | #include <stdio.h> |
4 | #include <stdlib.h> |
5 | |
6 | |
7 | static int do_test (locale_t l); |
8 | |
9 | int |
10 | main (void) |
11 | { |
12 | locale_t l; |
13 | locale_t l2; |
14 | int result; |
15 | |
16 | l = newlocale (category_mask: 1 << LC_ALL, locale: "de_DE.ISO-8859-1", NULL); |
17 | if (l == NULL) |
18 | { |
19 | printf (format: "newlocale failed: %m\n"); |
20 | exit (EXIT_FAILURE); |
21 | } |
22 | puts (s: "Running tests of created locale"); |
23 | result = do_test (l); |
24 | |
25 | l2 = duplocale (dataset: l); |
26 | if (l2 == NULL) |
27 | { |
28 | printf (format: "duplocale failed: %m\n"); |
29 | exit (EXIT_FAILURE); |
30 | } |
31 | freelocale (dataset: l); |
32 | puts (s: "Running tests of duplicated locale"); |
33 | result |= do_test (l: l2); |
34 | |
35 | return result; |
36 | } |
37 | |
38 | |
39 | static const char str[] = "0123456789abcdef ABCDEF ghijklmnopqrstuvwxyz������"; |
40 | static const char exd[] = "11111111110000000000000000000000000000000000000000"; |
41 | static const char exa[] = "00000000001111110111111011111111111111111111111111"; |
42 | static const char exx[] = "11111111111111110111111000000000000000000000000000"; |
43 | |
44 | |
45 | static int |
46 | do_test (locale_t l) |
47 | { |
48 | int result = 0; |
49 | size_t n; |
50 | |
51 | #define DO_TEST(TEST, RES) \ |
52 | for (n = 0; n < sizeof (str) - 1; ++n) \ |
53 | if ('0' + (TEST (str[n], l) != 0) != RES[n]) \ |
54 | { \ |
55 | printf ("%s(%c) failed\n", #TEST, str[n]); \ |
56 | result = 1; \ |
57 | } |
58 | |
59 | DO_TEST (isdigit_l, exd); |
60 | DO_TEST (isalpha_l, exa); |
61 | DO_TEST (isxdigit_l, exx); |
62 | |
63 | return result; |
64 | } |
65 |