Back to index

glibc  2.9
tst-xlocale2.c
Go to the documentation of this file.
00001 #include <ctype.h>
00002 #include <locale.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 
00006 
00007 static int do_test (__locale_t l);
00008 
00009 int
00010 main (void)
00011 {
00012   locale_t l;
00013   locale_t l2;
00014   int result;
00015 
00016   l = newlocale (1 << LC_ALL, "de_DE.ISO-8859-1", NULL);
00017   if (l == NULL)
00018     {
00019       printf ("newlocale failed: %m\n");
00020       exit (EXIT_FAILURE);
00021     }
00022   puts ("Running tests of created locale");
00023   result = do_test (l);
00024 
00025   l2 = duplocale (l);
00026   if (l2 == NULL)
00027     {
00028       printf ("duplocale failed: %m\n");
00029       exit (EXIT_FAILURE);
00030     }
00031   freelocale (l);
00032   puts ("Running tests of duplicated locale");
00033   result |= do_test (l2);
00034 
00035   return result;
00036 }
00037 
00038 
00039 static const char str[] = "0123456789abcdef ABCDEF ghijklmnopqrstuvwxyz";
00040 static const char exd[] = "11111111110000000000000000000000000000000000000000";
00041 static const char exa[] = "00000000001111110111111011111111111111111111111111";
00042 static const char exx[] = "11111111111111110111111000000000000000000000000000";
00043 
00044 
00045 static int
00046 do_test (locale_t l)
00047 {
00048   int result = 0;
00049 size_t n;
00050 
00051 #define DO_TEST(TEST, RES) \
00052   for (n = 0; n < sizeof (str) - 1; ++n)                             \
00053     if ('0' + (TEST (str[n], l) != 0) != RES[n])                     \
00054       {                                                                     \
00055        printf ("%s(%c) failed\n", #TEST, str[n]);                           \
00056        result = 1;                                                   \
00057       }
00058 
00059   DO_TEST (isdigit_l, exd);
00060   DO_TEST (isalpha_l, exa);
00061   DO_TEST (isxdigit_l, exx);
00062 
00063   return result;
00064 }