tst-strtod3.c 986 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <locale.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. static const struct
  6. {
  7. const char *in;
  8. const char *out;
  9. double expected;
  10. } tests[] =
  11. {
  12. { "000,,,e1", ",,,e1", 0.0 },
  13. { "000e1", "", 0.0 },
  14. { "000,1e1", ",1e1", 0.0 }
  15. };
  16. #define NTESTS (sizeof (tests) / sizeof (tests[0]))
  17. static int
  18. do_test (void)
  19. {
  20. if (setlocale (LC_ALL, "en_US.ISO-8859-1") == NULL)
  21. {
  22. puts ("could not set locale");
  23. return 1;
  24. }
  25. int status = 0;
  26. for (int i = 0; i < NTESTS; ++i)
  27. {
  28. char *ep;
  29. double r = __strtod_internal (tests[i].in, &ep, 1);
  30. if (strcmp (ep, tests[i].out) != 0)
  31. {
  32. printf ("%d: got rest string \"%s\", expected \"%s\"\n",
  33. i, ep, tests[i].out);
  34. status = 1;
  35. }
  36. if (r != tests[i].expected)
  37. {
  38. printf ("%d: got wrong results %g, expected %g\n",
  39. i, r, tests[i].expected);
  40. status = 1;
  41. }
  42. }
  43. return status;
  44. }
  45. #define TEST_FUNCTION do_test ()
  46. #include "../test-skeleton.c"