aboutsummaryrefslogtreecommitdiff
path: root/stdlib/tst-strtod3.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-12-11 21:43:56 +0000
committerUlrich Drepper <drepper@redhat.com>2006-12-11 21:43:56 +0000
commit1f55ce483b6f14da23383d7a192a0a9d6b99b7de (patch)
treea789a1908dd3aa2f2f9489cf08340320e1d48b27 /stdlib/tst-strtod3.c
parentf85fb97b9bdd59c6d7b105e81b72b7b69a9647e1 (diff)
downloadglibc-1f55ce483b6f14da23383d7a192a0a9d6b99b7de.zip
glibc-1f55ce483b6f14da23383d7a192a0a9d6b99b7de.tar.gz
glibc-1f55ce483b6f14da23383d7a192a0a9d6b99b7de.tar.bz2
* stdlib/strtod_l.c (____STRTOF_INTERNAL): Parse thousand
separators also if no non-zero digits found. * stdlib/Makefile (tests): Add tst-strtod3.
Diffstat (limited to 'stdlib/tst-strtod3.c')
-rw-r--r--stdlib/tst-strtod3.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/stdlib/tst-strtod3.c b/stdlib/tst-strtod3.c
new file mode 100644
index 0000000..23abec1
--- /dev/null
+++ b/stdlib/tst-strtod3.c
@@ -0,0 +1,55 @@
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static const struct
+{
+ const char *in;
+ const char *out;
+ double expected;
+} tests[] =
+ {
+ { "000,,,e1", ",,,e1", 0.0 },
+ { "000e1", "", 0.0 },
+ { "000,1e1", ",1e1", 0.0 }
+ };
+#define NTESTS (sizeof (tests) / sizeof (tests[0]))
+
+
+static int
+do_test (void)
+{
+ if (setlocale (LC_ALL, "en_US.ISO-8859-1") == NULL)
+ {
+ puts ("could not set locale");
+ return 1;
+ }
+
+ int status = 0;
+
+ for (int i = 0; i < NTESTS; ++i)
+ {
+ char *ep;
+ double r = __strtod_internal (tests[i].in, &ep, 1);
+
+ if (strcmp (ep, tests[i].out) != 0)
+ {
+ printf ("%d: got rest string \"%s\", expected \"%s\"\n",
+ i, ep, tests[i].out);
+ status = 1;
+ }
+
+ if (r != tests[i].expected)
+ {
+ printf ("%d: got wrong results %g, expected %g\n",
+ i, r, tests[i].expected);
+ status = 1;
+ }
+ }
+
+ return status;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"