.
[glibc/history.git] / localedata / tst-xlocale2.c
blob30d87de72b56d3f2430558371906467fd7dafea1
1 #include <ctype.h>
2 #include <locale.h>
3 #include <stdio.h>
4 #include <stdlib.h>
7 static int do_test (__locale_t l);
9 int
10 main (void)
12 locale_t l;
13 locale_t l2;
14 int result;
16 l = newlocale (1 << LC_ALL, "de_DE.ISO-8859-1", NULL);
17 if (l == NULL)
19 printf ("newlocale failed: %m\n");
20 exit (EXIT_FAILURE);
22 puts ("Running tests of created locale");
23 result = do_test (l);
25 l2 = duplocale (l);
26 if (l2 == NULL)
28 printf ("duplocale failed: %m\n");
29 exit (EXIT_FAILURE);
31 freelocale (l);
32 puts ("Running tests of duplicated locale");
33 result |= do_test (l2);
35 return result;
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";
45 static int
46 do_test (locale_t l)
48 int result = 0;
49 size_t n;
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; \
59 DO_TEST (isdigit_l, exd);
60 DO_TEST (isalpha_l, exa);
61 DO_TEST (isxdigit_l, exx);
63 return result;