tst-fmon.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Testing the implementation of strfmon(3).
  2. Copyright (C) 1996, 1997, 2000, 2003, 2004 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Jochen Hein <jochen.hein@delphi.central.de>, 1997.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library 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 GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <stdio.h>
  17. #include <locale.h>
  18. #include <monetary.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21. /*
  22. test-strfmon gets called with three parameters:
  23. - the locale
  24. - the format-string to be used
  25. - the actual number to be formatted
  26. - the expected string
  27. If the test passes, test-strfmon terminates with returncode 0,
  28. otherwise with 1
  29. */
  30. #define EXIT_SUCCESS 0
  31. #define EXIT_FAILURE 1
  32. #define EXIT_SETLOCALE 2
  33. #define EXIT_STRFMON 3
  34. int
  35. main (int argc, char *argv[])
  36. {
  37. char *s = malloc (201);
  38. if (setlocale (LC_MONETARY, argv[1]) == NULL)
  39. {
  40. fprintf (stderr, "setlocale(LC_MONETARY, \"%s\"): %m\n", argv[1]);
  41. exit (EXIT_SETLOCALE);
  42. }
  43. if (strfmon (s, 200, argv[2], (double) atof (argv[3])) == -1)
  44. {
  45. perror ("strfmon");
  46. exit (EXIT_STRFMON);
  47. }
  48. if (strcmp (s, argv[4]) != 0)
  49. {
  50. printf ("\
  51. Locale: \"%s\" Format: \"%s\" Value: \"%s\" Received: \"%s\" Expected: \"%s\" => %s\n",
  52. argv[1], argv[2], argv[3], s, argv[4],
  53. strcmp (s, argv[4]) != 0 ? "false" : "correct");
  54. exit (EXIT_FAILURE);
  55. }
  56. return EXIT_SUCCESS;
  57. }