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