1/* Tests of __strtod_internal in a locale using decimal comma.
2 Copyright (C) 2007-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#include <locale.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <math.h>
24
25#define NNBSP "\xe2\x80\xaf"
26
27static const struct
28{
29 const char *in;
30 int group;
31 double expected;
32} tests[] =
33 {
34 { "0", 0, 0.0 },
35 { "000", 0, 0.0 },
36 { "-0", 0, -0.0 },
37 { "-000", 0, -0.0 },
38 { "0,", 0, 0.0 },
39 { "-0,", 0, -0.0 },
40 { "0,0", 0, 0.0 },
41 { "-0,0", 0, -0.0 },
42 { "0e-10", 0, 0.0 },
43 { "-0e-10", 0, -0.0 },
44 { "0,e-10", 0, 0.0 },
45 { "-0,e-10", 0, -0.0 },
46 { "0,0e-10", 0, 0.0 },
47 { "-0,0e-10", 0, -0.0 },
48 { "0e-1000000", 0, 0.0 },
49 { "-0e-1000000", 0, -0.0 },
50 { "0,0e-1000000", 0, 0.0 },
51 { "-0,0e-1000000", 0, -0.0 },
52 { "0", 1, 0.0 },
53 { "000", 1, 0.0 },
54 { "-0", 1, -0.0 },
55 { "-000", 1, -0.0 },
56 { "0e-10", 1, 0.0 },
57 { "-0e-10", 1, -0.0 },
58 { "0e-1000000", 1, 0.0 },
59 { "-0e-1000000", 1, -0.0 },
60 { "000"NNBSP"000"NNBSP"000", 1, 0.0 },
61 { "-000"NNBSP"000"NNBSP"000", 1, -0.0 }
62 };
63#define NTESTS (sizeof (tests) / sizeof (tests[0]))
64
65
66static int
67do_test (void)
68{
69 if (setlocale (LC_ALL, "cs_CZ.UTF-8") == NULL)
70 {
71 puts (s: "could not set locale");
72 return 1;
73 }
74
75 int status = 0;
76
77 for (int i = 0; i < NTESTS; ++i)
78 {
79 char *ep;
80 double r = __strtod_internal (tests[i].in, &ep, tests[i].group);
81
82 if (*ep != '\0')
83 {
84 printf (format: "%d: got rest string \"%s\", expected \"\"\n", i, ep);
85 status = 1;
86 }
87
88 if (r != tests[i].expected
89 || copysign (10.0, r) != copysign (10.0, tests[i].expected))
90 {
91 printf (format: "%d: got wrong results %g, expected %g\n",
92 i, r, tests[i].expected);
93 status = 1;
94 }
95 }
96
97 return status;
98}
99
100#include <support/test-driver.c>
101

source code of glibc/stdlib/tst-strtod5i.c