* posix/tst-rfc3484-2.c (do_test): Likewise.
[glibc.git] / localedata / tst-numeric.c
blob9d3c91d155e821e83737bf8c7669fcf3e44e5321
1 /* Testing the implementation of LC_NUMERIC and snprintf().
2 Copyright (C) 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Petter Reinholdtsen <pere@hungry.com>, 2003
6 Based on tst-fmon.c by Jochen Hein <jochen.hein@delphi.central.de>, 1997.
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.
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.
18 You should have received a copy of the GNU Lesser General Public
19 License along with the GNU C Library; if not, write to the Free
20 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 02111-1307 USA. */
23 #include <stdio.h>
24 #include <locale.h>
25 #include <string.h>
26 #include <stdlib.h>
29 test-numeric gets called with three parameters:
30 - the locale
31 - the format-string to be used
32 - the actual number to be formatted
33 - the expected string
34 If the test passes, test-numeric terminates with returncode 0,
35 otherwise with 1
37 #define EXIT_SUCCESS 0
38 #define EXIT_FAILURE 1
39 #define EXIT_SETLOCALE 2
40 #define EXIT_SNPRINTF 3
42 int
43 main (int argc, char *argv[])
45 char *s = malloc (201);
46 double val;
48 /* Make sure to read the value before setting of the locale, as
49 strtod() is locale-dependent. */
50 val = strtod (argv[3], NULL);
52 if (setlocale (LC_ALL, argv[1]) == NULL)
54 fprintf (stderr, "setlocale(LC_ALL, \"%s\"): %m\n", argv[1]);
55 exit (EXIT_SETLOCALE);
58 if (snprintf (s, 200, argv[2], val) == -1)
60 perror ("snprintf");
61 exit (EXIT_SNPRINTF);
64 if (strcmp (s, argv[4]) != 0)
66 printf ("\
67 locale: \"%s\", format: \"%s\", expected: \"%s\", got: \"%s\" => %s\n",
68 argv[1], argv[2], argv[4], s,
69 strcmp (s, argv[4]) != 0 ? "false" : "correct");
70 exit (EXIT_FAILURE);
73 return EXIT_SUCCESS;