maint.mk: Update system header list for #include syntax checks.
[gnulib.git] / tests / test-c-strtold1.c
blob86b4009ffb2ad77957b45a80aaa1c1ead4fdd289
1 /* Test of c_strtold() in a French locale.
2 Copyright (C) 2019-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 #include <config.h>
19 /* Specification. */
20 #include "c-strtod.h"
22 #include <errno.h>
23 #include <locale.h>
25 #include "macros.h"
27 int
28 main (int argc, char *argv[])
30 /* Try to set the locale by implicitly looking at the LC_ALL environment
31 variable.
32 configure should already have checked that the locale is supported. */
33 if (setlocale (LC_ALL, "") == NULL)
34 return 1;
37 const char input[] = "1.";
38 char *ptr;
39 long double result;
40 errno = 0;
41 result = c_strtold (input, &ptr);
42 ASSERT (result == 1.0L);
43 ASSERT (ptr == input + 2);
44 ASSERT (errno == 0);
47 const char input[] = ".5";
48 char *ptr;
49 long double result;
50 errno = 0;
51 result = c_strtold (input, &ptr);
52 ASSERT (result == 0.5L);
53 ASSERT (ptr == input + 2);
54 ASSERT (errno == 0);
57 const char input[] = "1.5";
58 char *ptr;
59 long double result;
60 errno = 0;
61 result = c_strtold (input, &ptr);
62 ASSERT (result == 1.5L);
63 ASSERT (ptr == input + 3);
64 ASSERT (errno == 0);
67 const char input[] = "1,5";
68 char *ptr;
69 long double result;
70 errno = 0;
71 result = c_strtold (input, &ptr);
72 ASSERT (result == 1.0L);
73 ASSERT (ptr == input + 1);
74 ASSERT (errno == 0);
77 const char input[] = "123,456.789";
78 char *ptr;
79 long double result;
80 errno = 0;
81 result = c_strtold (input, &ptr);
82 ASSERT (result == 123.0L);
83 ASSERT (ptr == input + 3);
84 ASSERT (errno == 0);
87 const char input[] = "123.456,789";
88 char *ptr;
89 long double result;
90 errno = 0;
91 result = c_strtold (input, &ptr);
92 ASSERT (result > 123.45L && result < 123.46L);
93 ASSERT (ptr == input + 7);
94 ASSERT (errno == 0);
97 return test_exit_status;