]>
Commit | Line | Data |
---|---|---|
76352f64 | 1 | /* Testing the implementation of LC_NUMERIC and snprintf(). |
04277e02 | 2 | Copyright (C) 2003-2019 Free Software Foundation, Inc. |
76352f64 UD |
3 | This file is part of the GNU C Library. |
4 | Contributed by Petter Reinholdtsen <pere@hungry.com>, 2003 | |
5 | ||
6 | Based on tst-fmon.c by Jochen Hein <jochen.hein@delphi.central.de>, 1997. | |
7 | ||
8 | The GNU C Library is free software; you can redistribute it and/or | |
9 | modify it under the terms of the GNU Lesser General Public | |
10 | License as published by the Free Software Foundation; either | |
11 | version 2.1 of the License, or (at your option) any later version. | |
12 | ||
13 | The GNU C Library is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 | 19 | License along with the GNU C Library; if not, see |
5a82c748 | 20 | <https://www.gnu.org/licenses/>. */ |
76352f64 UD |
21 | |
22 | #include <stdio.h> | |
23 | #include <locale.h> | |
24 | #include <string.h> | |
25 | #include <stdlib.h> | |
26 | ||
27 | /* | |
28 | test-numeric gets called with three parameters: | |
29 | - the locale | |
30 | - the format-string to be used | |
31 | - the actual number to be formatted | |
32 | - the expected string | |
33 | If the test passes, test-numeric terminates with returncode 0, | |
34 | otherwise with 1 | |
35 | */ | |
36 | #define EXIT_SUCCESS 0 | |
37 | #define EXIT_FAILURE 1 | |
38 | #define EXIT_SETLOCALE 2 | |
39 | #define EXIT_SNPRINTF 3 | |
40 | ||
41 | int | |
42 | main (int argc, char *argv[]) | |
43 | { | |
b2cae5d3 | 44 | char s[200]; |
76352f64 UD |
45 | double val; |
46 | ||
47 | /* Make sure to read the value before setting of the locale, as | |
48 | strtod() is locale-dependent. */ | |
49 | val = strtod (argv[3], NULL); | |
50 | ||
51 | if (setlocale (LC_ALL, argv[1]) == NULL) | |
52 | { | |
a234e27d | 53 | fprintf (stderr, "setlocale(LC_ALL, \"%s\"): %m\n", argv[1]); |
76352f64 UD |
54 | exit (EXIT_SETLOCALE); |
55 | } | |
56 | ||
b2cae5d3 | 57 | if (snprintf (s, sizeof (s), argv[2], val) == -1) |
76352f64 UD |
58 | { |
59 | perror ("snprintf"); | |
60 | exit (EXIT_SNPRINTF); | |
61 | } | |
62 | ||
63 | if (strcmp (s, argv[4]) != 0) | |
64 | { | |
65 | printf ("\ | |
66 | locale: \"%s\", format: \"%s\", expected: \"%s\", got: \"%s\" => %s\n", | |
67 | argv[1], argv[2], argv[4], s, | |
68 | strcmp (s, argv[4]) != 0 ? "false" : "correct"); | |
69 | exit (EXIT_FAILURE); | |
70 | } | |
71 | ||
72 | return EXIT_SUCCESS; | |
73 | } |