tst-strtol-locale-main.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Test strtol functions work with all ASCII letters in Turkish
  2. locales (bug 19242).
  3. Copyright (C) 2015-2019 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <locale.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <wchar.h>
  20. #define STR_(X) #X
  21. #define STR(X) STR_(X)
  22. #define FNPFXS STR (FNPFX)
  23. #define CONCAT_(X, Y) X ## Y
  24. #define CONCAT(X, Y) CONCAT_ (X, Y)
  25. #define FNX(FN) CONCAT (FNPFX, FN)
  26. #define TEST(LOC, STR, EXP_VAL, FN, TYPE, FMT) \
  27. do \
  28. { \
  29. CHAR *ep; \
  30. TYPE val = FNX (FN) (STR, &ep, 36); \
  31. printf ("%s: " FNPFXS #FN " (" SFMT ") == " FMT "\n", LOC, STR, val); \
  32. if (val == (TYPE) (EXP_VAL) && *ep == 0) \
  33. printf ("PASS: %s: " FNPFXS #FN " (" SFMT ")\n", LOC, STR); \
  34. else \
  35. { \
  36. printf ("FAIL: %s: " FNPFXS #FN " (" SFMT ")\n", LOC, STR); \
  37. result = 1; \
  38. } \
  39. } \
  40. while (0)
  41. static int
  42. test_one_locale (const char *loc)
  43. {
  44. if (setlocale (LC_ALL, loc) == NULL)
  45. {
  46. printf ("setlocale (LC_ALL, \"%s\") failed\n", loc);
  47. return 1;
  48. }
  49. int result = 0;
  50. for (int i = 10; i < 36; i++)
  51. {
  52. CHAR s[2];
  53. s[0] = L_('A') + i - 10;
  54. s[1] = 0;
  55. TEST (loc, s, i, l, long int, "%ld");
  56. TEST (loc, s, i, ul, unsigned long int, "%lu");
  57. TEST (loc, s, i, ll, long long int, "%lld");
  58. TEST (loc, s, i, ull, unsigned long long int, "%llu");
  59. s[0] = L_('a') + i - 10;
  60. s[1] = 0;
  61. TEST (loc, s, i, l, long int, "%ld");
  62. TEST (loc, s, i, ul, unsigned long int, "%lu");
  63. TEST (loc, s, i, ll, long long int, "%lld");
  64. TEST (loc, s, i, ull, unsigned long long int, "%llu");
  65. }
  66. return result;
  67. }
  68. static int
  69. do_test (void)
  70. {
  71. int result = 0;
  72. result |= test_one_locale ("C");
  73. result |= test_one_locale ("tr_TR.UTF-8");
  74. result |= test_one_locale ("tr_TR.ISO-8859-9");
  75. return result;
  76. }
  77. #define TEST_FUNCTION do_test ()
  78. #include "../test-skeleton.c"