gettext: Sync with gettext 0.23.
[gnulib.git] / tests / test-c-strtod1.c
blobe0d7baf41a6e786a8de076730fed3834fae4c68b
1 /* Test of c_strtod() 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 double result;
40 errno = 0;
41 result = c_strtod (input, &ptr);
42 ASSERT (result == 1.0);
43 ASSERT (ptr == input + 2);
44 ASSERT (errno == 0);
47 const char input[] = ".5";
48 char *ptr;
49 double result;
50 errno = 0;
51 result = c_strtod (input, &ptr);
52 ASSERT (result == 0.5);
53 ASSERT (ptr == input + 2);
54 ASSERT (errno == 0);
57 const char input[] = "1.5";
58 char *ptr;
59 double result;
60 errno = 0;
61 result = c_strtod (input, &ptr);
62 ASSERT (result == 1.5);
63 ASSERT (ptr == input + 3);
64 ASSERT (errno == 0);
67 const char input[] = "1,5";
68 char *ptr;
69 double result;
70 errno = 0;
71 result = c_strtod (input, &ptr);
72 ASSERT (result == 1.0);
73 ASSERT (ptr == input + 1);
74 ASSERT (errno == 0);
77 const char input[] = "123,456.789";
78 char *ptr;
79 double result;
80 errno = 0;
81 result = c_strtod (input, &ptr);
82 ASSERT (result == 123.0);
83 ASSERT (ptr == input + 3);
84 ASSERT (errno == 0);
87 const char input[] = "123.456,789";
88 char *ptr;
89 double result;
90 errno = 0;
91 result = c_strtod (input, &ptr);
92 ASSERT (result > 123.45 && result < 123.46);
93 ASSERT (ptr == input + 7);
94 ASSERT (errno == 0);
97 return test_exit_status;