1 #include <locale.h>
2 #include <stdio.h>
3 #include <string.h>
4
5
6 static struct
7 {
8 const char *locale;
9 const char *str1;
10 const char *str2;
11 int result;
12 } tests[] =
13 {
14 { "C", "TRANSLIT", "translit", 0 },
15 { "de_DE.ISO-8859-1", "TRANSLIT", "translit", 0 },
16 { "de_DE.ISO-8859-1", "TRANSLIT", "tr�nslit", -1 },
17 { "de_DE.UTF-8", "TRANSLIT", "translit", 0 },
18 { "de_DE.ISO-8859-1", "�", "�", 1 }
19 };
20 #define ntests (sizeof (tests) / sizeof (tests[0]))
21
22
23 static int
do_test(void)24 do_test (void)
25 {
26 size_t cnt;
27 int result = 0;
28 locale_t loc = newlocale (1 << LC_ALL, "C", NULL);
29
30 for (cnt = 0; cnt < ntests; ++cnt)
31 {
32 int r;
33
34 if (setlocale (LC_ALL, tests[cnt].locale) == NULL)
35 {
36 printf ("cannot set locale \"%s\": %m\n", tests[cnt].locale);
37 result = 1;
38 continue;
39 }
40
41 printf ("\nstrcasecmp_l (\"%s\", \"%s\", loc)\n",
42 tests[cnt].str1, tests[cnt].str2);
43
44 r = strcasecmp_l (tests[cnt].str1, tests[cnt].str2, loc);
45 if (tests[cnt].result == 0)
46 {
47 if (r != 0)
48 {
49 printf ("\"%s\" and \"%s\" expected to be the same, result %d\n",
50 tests[cnt].str1, tests[cnt].str2, r);
51 result = 1;
52 }
53 }
54 else if (tests[cnt].result < 0)
55 {
56 if (r >= 0)
57 {
58 printf ("\"%s\" expected to be smaller than \"%s\", result %d\n",
59 tests[cnt].str1, tests[cnt].str2, r);
60 result = 1;
61 }
62 }
63 else
64 {
65 if (r <= 0)
66 {
67 printf ("\"%s\" expected to be larger than \"%s\", result %d\n",
68 tests[cnt].str1, tests[cnt].str2, r);
69 result = 1;
70 }
71 }
72 }
73
74 return result;
75 }
76
77 #define TEST_FUNCTION do_test ()
78 #include "../test-skeleton.c"
79