tst-strtod-nan-locale-main.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Test strtod functions work with all ASCII letters in NAN(...) in
  2. Turkish locales (bug 19266).
  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 <math.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <wchar.h>
  21. #include <stdlib/tst-strtod.h>
  22. #define STR_(X) #X
  23. #define STR(X) STR_(X)
  24. #define FNPFXS STR (FNPFX)
  25. #define CONCAT_(X, Y) X ## Y
  26. #define CONCAT(X, Y) CONCAT_ (X, Y)
  27. #define FNX(FN) CONCAT (FNPFX, FN)
  28. #define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
  29. static int \
  30. test_strto ## FSUF (const char * loc, CHAR * s) \
  31. { \
  32. CHAR *ep; \
  33. FTYPE val = FNX (FSUF) (s, &ep); \
  34. if (isnan (val) && *ep == 0) \
  35. printf ("PASS: %s: " FNPFXS #FSUF " (" SFMT ")\n", loc, s); \
  36. else \
  37. { \
  38. printf ("FAIL: %s: " FNPFXS #FSUF " (" SFMT ")\n", loc, s); \
  39. return 1; \
  40. } \
  41. return 0; \
  42. }
  43. GEN_TEST_STRTOD_FOREACH (TEST_STRTOD)
  44. static int
  45. test_one_locale (const char *loc)
  46. {
  47. if (setlocale (LC_ALL, loc) == NULL)
  48. {
  49. printf ("setlocale (LC_ALL, \"%s\") failed\n", loc);
  50. return 1;
  51. }
  52. int result = 0;
  53. for (int i = 10; i < 36; i++)
  54. {
  55. CHAR s[7];
  56. s[0] = L_('N');
  57. s[1] = L_('A');
  58. s[2] = L_('N');
  59. s[3] = L_('(');
  60. s[4] = L_('A') + i - 10;
  61. s[5] = L_(')');
  62. s[6] = 0;
  63. result |= STRTOD_TEST_FOREACH (test_strto, loc, s);
  64. s[4] = L_('a') + i - 10;
  65. result |= STRTOD_TEST_FOREACH (test_strto, loc, s);
  66. }
  67. return result;
  68. }
  69. static int
  70. do_test (void)
  71. {
  72. int result = 0;
  73. result |= test_one_locale ("C");
  74. result |= test_one_locale ("tr_TR.UTF-8");
  75. result |= test_one_locale ("tr_TR.ISO-8859-9");
  76. return result;
  77. }
  78. #define TEST_FUNCTION do_test ()
  79. #include "../test-skeleton.c"