]>
Commit | Line | Data |
---|---|---|
3c504879 UD |
1 | /* Based on a test case by Paul Eggert. */ |
2 | #include <locale.h> | |
3 | #include <stdio.h> | |
4 | #include <stdlib.h> | |
5 | #include <string.h> | |
6 | ||
7 | ||
8 | char const string[] = ""; | |
9 | ||
10 | ||
11 | static int | |
12 | test (const char *locale) | |
13 | { | |
14 | size_t bufsize; | |
15 | size_t r; | |
16 | size_t l; | |
17 | char *buf; | |
86ad5f0c | 18 | locale_t loc; |
3c504879 UD |
19 | int result = 0; |
20 | ||
21 | if (setlocale (LC_COLLATE, locale) == NULL) | |
22 | { | |
23 | printf ("cannot set locale \"%s\"\n", locale); | |
24 | return 1; | |
25 | } | |
26 | bufsize = strxfrm (NULL, string, 0) + 1; | |
27 | buf = malloc (bufsize); | |
28 | if (buf == NULL) | |
29 | { | |
30 | printf ("cannot allocate %zd bytes\n", bufsize); | |
31 | return 1; | |
32 | } | |
33 | r = strxfrm (buf, string, bufsize); | |
34 | l = strlen (buf); | |
35 | if (r != l) | |
36 | { | |
37 | printf ("locale \"%s\": strxfrm returned %zu, strlen returned %zu\n", | |
38 | locale, r, l); | |
39 | result = 1; | |
40 | } | |
95eaff64 | 41 | |
86ad5f0c | 42 | loc = newlocale (1 << LC_ALL, locale, NULL); |
95eaff64 | 43 | |
86ad5f0c | 44 | r = strxfrm_l (buf, string, bufsize, loc); |
95eaff64 UD |
45 | l = strlen (buf); |
46 | if (r != l) | |
47 | { | |
48 | printf ("locale \"%s\": strxfrm_l returned %zu, strlen returned %zu\n", | |
49 | locale, r, l); | |
50 | result = 1; | |
51 | } | |
52 | ||
86ad5f0c | 53 | freelocale (loc); |
95eaff64 | 54 | |
3c504879 UD |
55 | free (buf); |
56 | ||
57 | return result; | |
58 | } | |
59 | ||
60 | ||
29955b5d AS |
61 | static int |
62 | do_test (void) | |
3c504879 UD |
63 | { |
64 | int result = 0; | |
65 | ||
66 | result |= test ("C"); | |
67 | result |= test ("en_US.ISO-8859-1"); | |
68 | result |= test ("de_DE.UTF-8"); | |
69 | ||
70 | return result; | |
71 | } | |
29955b5d AS |
72 | |
73 | #define TEST_FUNCTION do_test () | |
74 | #include "../test-skeleton.c" |