bug-strtod2.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <locale.h>
  2. #include <math.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "tst-strtod.h"
  6. static const char *tests[] =
  7. {
  8. "inf", "Inf", "iNf", "inF", "INf", "iNF", "INF", "InF",
  9. "infinity", "Infinity", "InfInity", "INFINITY"
  10. };
  11. #define ntests (sizeof (tests) / sizeof (tests[0]))
  12. #define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
  13. static int \
  14. test_strto ## FSUF (void) \
  15. { \
  16. int res = 0; \
  17. for (int i = 0; i < ntests; ++i) \
  18. { \
  19. char *endp; \
  20. FTYPE d = strto ## FSUF (tests[i], &endp); \
  21. if (*endp != '\0') \
  22. { \
  23. printf ("did not consume all of '%s'\n", tests[i]); \
  24. res = 1; \
  25. } \
  26. if (!isinf (d)) \
  27. { \
  28. printf ("'%s' does not pass isinf\n", tests[i]); \
  29. res = 1; \
  30. } \
  31. } \
  32. \
  33. return res; \
  34. }
  35. GEN_TEST_STRTOD_FOREACH (TEST_STRTOD)
  36. static int
  37. do_test (void)
  38. {
  39. /* The Turkish locale is notorious because tolower() maps 'I' to the
  40. dotless lowercase 'i' and toupper() maps 'i' to an 'I' with a dot
  41. above. */
  42. if (setlocale (LC_ALL, "tr_TR.UTF-8") == NULL)
  43. {
  44. puts ("cannot set locale");
  45. return 0;
  46. }
  47. return STRTOD_TEST_FOREACH (test_strto);
  48. }
  49. #define TEST_FUNCTION do_test ()
  50. #include "../test-skeleton.c"