Back to index

glibc  2.9
tst-xlocale1.c
Go to the documentation of this file.
00001 #include <locale.h>
00002 #include <stdio.h>
00003 #include <string.h>
00004 
00005 
00006 static struct
00007 {
00008   const char *locale;
00009   const char *str1;
00010   const char *str2;
00011   int result;
00012 } tests[] =
00013   {
00014     { "C", "TRANSLIT", "translit", 0 },
00015     { "de_DE.ISO-8859-1", "TRANSLIT", "translit", 0 },
00016     { "de_DE.ISO-8859-1", "TRANSLIT", "trÄnslit", -1 },
00017     { "de_DE.UTF-8", "TRANSLIT", "translit", 0 },
00018     { "de_DE.ISO-8859-1", "ä", "Ä", 1 }
00019   };
00020 #define ntests (sizeof (tests) / sizeof (tests[0]))
00021 
00022 
00023 int
00024 main (void)
00025 {
00026   size_t cnt;
00027   int result = 0;
00028   locale_t loc = newlocale (1 << LC_ALL, "C", NULL);
00029 
00030   for (cnt = 0; cnt < ntests; ++cnt)
00031     {
00032       int r;
00033 
00034       if (setlocale (LC_ALL, tests[cnt].locale) == NULL)
00035        {
00036          printf ("cannot set locale \"%s\": %m\n", tests[cnt].locale);
00037          result = 1;
00038          continue;
00039        }
00040 
00041       printf ("\nstrcasecmp_l (\"%s\", \"%s\", loc)\n",
00042              tests[cnt].str1, tests[cnt].str2);
00043 
00044       r = strcasecmp_l (tests[cnt].str1, tests[cnt].str2, loc);
00045       if (tests[cnt].result == 0)
00046        {
00047          if (r != 0)
00048            {
00049              printf ("\"%s\" and \"%s\" expected to be the same, result %d\n",
00050                     tests[cnt].str1, tests[cnt].str2, r);
00051              result = 1;
00052            }
00053        }
00054       else if (tests[cnt].result < 0)
00055        {
00056          if (r >= 0)
00057            {
00058              printf ("\"%s\" expected to be smaller than \"%s\", result %d\n",
00059                     tests[cnt].str1, tests[cnt].str2, r);
00060              result = 1;
00061            }
00062        }
00063       else
00064        {
00065          if (r <= 0)
00066            {
00067              printf ("\"%s\" expected to be larger than \"%s\", result %d\n",
00068                     tests[cnt].str1, tests[cnt].str2, r);
00069              result = 1;
00070            }
00071        }
00072     }
00073 
00074   return result;
00075 }