tst-xlocale2.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <ctype.h>
  2. #include <locale.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. static int do_test (__locale_t l);
  6. int
  7. main (void)
  8. {
  9. locale_t l;
  10. locale_t l2;
  11. int result;
  12. l = newlocale (1 << LC_ALL, "de_DE.ISO-8859-1", NULL);
  13. if (l == NULL)
  14. {
  15. printf ("newlocale failed: %m\n");
  16. exit (EXIT_FAILURE);
  17. }
  18. puts ("Running tests of created locale");
  19. result = do_test (l);
  20. l2 = duplocale (l);
  21. if (l2 == NULL)
  22. {
  23. printf ("duplocale failed: %m\n");
  24. exit (EXIT_FAILURE);
  25. }
  26. freelocale (l);
  27. puts ("Running tests of duplicated locale");
  28. result |= do_test (l2);
  29. return result;
  30. }
  31. static const char str[] = "0123456789abcdef ABCDEF ghijklmnopqrstuvwxyzäÄöÖüÜ";
  32. static const char exd[] = "11111111110000000000000000000000000000000000000000";
  33. static const char exa[] = "00000000001111110111111011111111111111111111111111";
  34. static const char exx[] = "11111111111111110111111000000000000000000000000000";
  35. static int
  36. do_test (locale_t l)
  37. {
  38. int result = 0;
  39. size_t n;
  40. #define DO_TEST(TEST, RES) \
  41. for (n = 0; n < sizeof (str) - 1; ++n) \
  42. if ('0' + (TEST (str[n], l) != 0) != RES[n]) \
  43. { \
  44. printf ("%s(%c) failed\n", #TEST, str[n]); \
  45. result = 1; \
  46. }
  47. DO_TEST (isdigit_l, exd);
  48. DO_TEST (isalpha_l, exa);
  49. DO_TEST (isxdigit_l, exx);
  50. return result;
  51. }