Back to index

glibc  2.9
tst-fmon.c
Go to the documentation of this file.
00001 /* Testing the implementation of strfmon(3).
00002    Copyright (C) 1996, 1997, 2000, 2003, 2004 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Jochen Hein <jochen.hein@delphi.central.de>, 1997.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <stdio.h>
00022 #include <locale.h>
00023 #include <monetary.h>
00024 #include <string.h>
00025 #include <stdlib.h>
00026 
00027 /*
00028   test-strfmon gets called with three parameters:
00029    - the locale
00030    - the format-string to be used
00031    - the actual number to be formatted
00032    - the expected string
00033    If the test passes, test-strfmon terminates with returncode 0,
00034    otherwise with 1
00035 */
00036 #define EXIT_SUCCESS 0
00037 #define EXIT_FAILURE 1
00038 #define EXIT_SETLOCALE 2
00039 #define EXIT_STRFMON 3
00040 
00041 int
00042 main (int argc, char *argv[])
00043 {
00044   char *s = malloc (201);
00045 
00046   if (setlocale (LC_MONETARY, argv[1]) == NULL)
00047     {
00048       fprintf (stderr, "setlocale(LC_MONETARY, \"%s\"): %m\n", argv[1]);
00049       exit (EXIT_SETLOCALE);
00050     }
00051 
00052   if (strfmon (s, 200, argv[2], (double) atof (argv[3])) == -1)
00053     {
00054       perror ("strfmon");
00055       exit (EXIT_STRFMON);
00056     }
00057 
00058   if (strcmp (s, argv[4]) != 0)
00059     {
00060       printf ("\
00061 Locale: \"%s\" Format: \"%s\" Value: \"%s\" Received: \"%s\" Expected: \"%s\" => %s\n",
00062              argv[1], argv[2], argv[3], s, argv[4],
00063              strcmp (s, argv[4]) != 0 ? "false" : "correct");
00064       exit (EXIT_FAILURE);
00065     }
00066 
00067   return EXIT_SUCCESS;
00068 }