tst-xlocale1.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <locale.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. static struct
  5. {
  6. const char *locale;
  7. const char *str1;
  8. const char *str2;
  9. int result;
  10. } tests[] =
  11. {
  12. { "C", "TRANSLIT", "translit", 0 },
  13. { "de_DE.ISO-8859-1", "TRANSLIT", "translit", 0 },
  14. { "de_DE.ISO-8859-1", "TRANSLIT", "trÄnslit", -1 },
  15. { "de_DE.UTF-8", "TRANSLIT", "translit", 0 },
  16. { "de_DE.ISO-8859-1", "ä", "Ä", 1 }
  17. };
  18. #define ntests (sizeof (tests) / sizeof (tests[0]))
  19. int
  20. main (void)
  21. {
  22. size_t cnt;
  23. int result = 0;
  24. locale_t loc = newlocale (1 << LC_ALL, "C", NULL);
  25. for (cnt = 0; cnt < ntests; ++cnt)
  26. {
  27. int r;
  28. if (setlocale (LC_ALL, tests[cnt].locale) == NULL)
  29. {
  30. printf ("cannot set locale \"%s\": %m\n", tests[cnt].locale);
  31. result = 1;
  32. continue;
  33. }
  34. printf ("\nstrcasecmp_l (\"%s\", \"%s\", loc)\n",
  35. tests[cnt].str1, tests[cnt].str2);
  36. r = strcasecmp_l (tests[cnt].str1, tests[cnt].str2, loc);
  37. if (tests[cnt].result == 0)
  38. {
  39. if (r != 0)
  40. {
  41. printf ("\"%s\" and \"%s\" expected to be the same, result %d\n",
  42. tests[cnt].str1, tests[cnt].str2, r);
  43. result = 1;
  44. }
  45. }
  46. else if (tests[cnt].result < 0)
  47. {
  48. if (r >= 0)
  49. {
  50. printf ("\"%s\" expected to be smaller than \"%s\", result %d\n",
  51. tests[cnt].str1, tests[cnt].str2, r);
  52. result = 1;
  53. }
  54. }
  55. else
  56. {
  57. if (r <= 0)
  58. {
  59. printf ("\"%s\" expected to be larger than \"%s\", result %d\n",
  60. tests[cnt].str1, tests[cnt].str2, r);
  61. result = 1;
  62. }
  63. }
  64. }
  65. return result;
  66. }