2001-08-18 10:46:36 +08:00
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int do_test (__locale_t l);
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (void)
|
|
|
|
|
{
|
2002-08-28 16:44:07 +08:00
|
|
|
|
locale_t l;
|
|
|
|
|
locale_t l2;
|
2001-08-18 10:46:36 +08:00
|
|
|
|
int result;
|
|
|
|
|
|
2002-08-28 16:44:07 +08:00
|
|
|
|
l = newlocale (1 << LC_ALL, "de_DE.ISO-8859-1", NULL);
|
2001-08-18 10:46:36 +08:00
|
|
|
|
if (l == NULL)
|
|
|
|
|
{
|
2002-08-28 16:44:07 +08:00
|
|
|
|
printf ("newlocale failed: %m\n");
|
2001-08-18 10:46:36 +08:00
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
puts ("Running tests of created locale");
|
|
|
|
|
result = do_test (l);
|
|
|
|
|
|
2002-08-28 16:44:07 +08:00
|
|
|
|
l2 = duplocale (l);
|
2001-08-18 10:46:36 +08:00
|
|
|
|
if (l2 == NULL)
|
|
|
|
|
{
|
2002-08-28 16:44:07 +08:00
|
|
|
|
printf ("duplocale failed: %m\n");
|
2001-08-18 10:46:36 +08:00
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
|
}
|
2002-08-28 16:44:07 +08:00
|
|
|
|
freelocale (l);
|
2001-08-18 10:46:36 +08:00
|
|
|
|
puts ("Running tests of duplicated locale");
|
|
|
|
|
result |= do_test (l2);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char str[] = "0123456789abcdef ABCDEF ghijklmnopqrstuvwxyz<79><7A><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|
|
|
|
static const char exd[] = "11111111110000000000000000000000000000000000000000";
|
|
|
|
|
static const char exa[] = "00000000001111110111111011111111111111111111111111";
|
|
|
|
|
static const char exx[] = "11111111111111110111111000000000000000000000000000";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2002-08-28 16:44:07 +08:00
|
|
|
|
do_test (locale_t l)
|
2001-08-18 10:46:36 +08:00
|
|
|
|
{
|
|
|
|
|
int result = 0;
|
2002-09-25 11:26:16 +08:00
|
|
|
|
size_t n;
|
2001-08-18 10:46:36 +08:00
|
|
|
|
|
|
|
|
|
#define DO_TEST(TEST, RES) \
|
|
|
|
|
for (n = 0; n < sizeof (str) - 1; ++n) \
|
|
|
|
|
if ('0' + (TEST (str[n], l) != 0) != RES[n]) \
|
|
|
|
|
{ \
|
|
|
|
|
printf ("%s(%c) failed\n", #TEST, str[n]); \
|
|
|
|
|
result = 1; \
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-28 16:44:07 +08:00
|
|
|
|
DO_TEST (isdigit_l, exd);
|
|
|
|
|
DO_TEST (isalpha_l, exa);
|
|
|
|
|
DO_TEST (isxdigit_l, exx);
|
2001-08-18 10:46:36 +08:00
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|