| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <config.h> |
| 20 |
|
| 21 |
#include "hard-locale.h" |
| 22 |
|
| 23 |
#include <locale.h> |
| 24 |
#include <stdbool.h> |
| 25 |
#include <stdio.h> |
| 26 |
#include <string.h> |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
static bool all_trivial; |
| 31 |
|
| 32 |
static int |
| 33 |
test_one (const char *name, int failure_bitmask) |
| 34 |
{ |
| 35 |
if (setlocale (LC_ALL, name) != NULL) |
| 36 |
{ |
| 37 |
bool expected; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
#if defined MUSL_LIBC || defined __OpenBSD__ || defined __HAIKU__ |
| 44 |
expected = true; |
| 45 |
#else |
| 46 |
expected = !all_trivial; |
| 47 |
#endif |
| 48 |
if (hard_locale (LC_CTYPE) != expected) |
| 49 |
{ |
| 50 |
if (expected) |
| 51 |
fprintf (stderr, "Unexpected: The category LC_CTYPE of the locale '%s' is not equivalent to C or POSIX.\n", |
| 52 |
name); |
| 53 |
else |
| 54 |
fprintf (stderr, "Unexpected: The category LC_CTYPE of the locale '%s' is equivalent to C or POSIX.\n", |
| 55 |
name); |
| 56 |
return failure_bitmask; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
#if defined __NetBSD__ |
| 63 |
expected = false; |
| 64 |
#elif defined MUSL_LIBC |
| 65 |
expected = strcmp (name, "C.UTF-8") != 0; |
| 66 |
#elif (defined __OpenBSD__ && HAVE_DUPLOCALE) || defined __HAIKU__ |
| 67 |
expected = true; |
| 68 |
#else |
| 69 |
expected = !all_trivial; |
| 70 |
#endif |
| 71 |
if (hard_locale (LC_COLLATE) != expected) |
| 72 |
{ |
| 73 |
if (expected) |
| 74 |
fprintf (stderr, "Unexpected: The category LC_COLLATE of the locale '%s' is not equivalent to C or POSIX.\n", |
| 75 |
name); |
| 76 |
else |
| 77 |
fprintf (stderr, "Unexpected: The category LC_COLLATE of the locale '%s' is equivalent to C or POSIX.\n", |
| 78 |
name); |
| 79 |
return failure_bitmask; |
| 80 |
} |
| 81 |
} |
| 82 |
return 0; |
| 83 |
} |
| 84 |
|
| 85 |
int |
| 86 |
main () |
| 87 |
{ |
| 88 |
int fail = 0; |
| 89 |
|
| 90 |
|
| 91 |
if (hard_locale (LC_CTYPE) || hard_locale (LC_COLLATE)) |
| 92 |
{ |
| 93 |
fprintf (stderr, "The initial locale should not be hard!\n"); |
| 94 |
fail |= 1; |
| 95 |
} |
| 96 |
|
| 97 |
all_trivial = (setlocale (LC_ALL, "foobar") != NULL); |
| 98 |
|
| 99 |
fail |= test_one ("de", 2); |
| 100 |
fail |= test_one ("de_DE", 4); |
| 101 |
fail |= test_one ("de_DE.ISO8859-1", 8); |
| 102 |
fail |= test_one ("de_DE.iso88591", 8); |
| 103 |
fail |= test_one ("de_DE.UTF-8", 16); |
| 104 |
fail |= test_one ("de_DE.utf8", 16); |
| 105 |
fail |= test_one ("german", 32); |
| 106 |
fail |= test_one ("C.UTF-8", 64); |
| 107 |
|
| 108 |
return fail; |
| 109 |
} |