tst-strfmon1.c 952 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <monetary.h>
  2. #include <locale.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. static const struct
  6. {
  7. const char *locale;
  8. const char *expected;
  9. } tests[] =
  10. {
  11. { "de_DE.ISO-8859-1", "|-12,34 EUR|-12,34|" },
  12. { "da_DK.ISO-8859-1", "|kr -12,34|-12,34|" },
  13. { "zh_TW.EUC-TW", "|-NT$12.34|-12.34|" },
  14. { "sv_SE.ISO-8859-1", "|-12,34 kr|-12,34|" }
  15. };
  16. #define ntests (sizeof (tests) / sizeof (tests[0]))
  17. static int
  18. do_test (void)
  19. {
  20. int res = 0;
  21. for (int i = 0; i < ntests; ++i)
  22. {
  23. char buf[500];
  24. if (setlocale (LC_ALL, tests[i].locale) == NULL)
  25. {
  26. printf ("failed to set locale %s\n", tests[i].locale);
  27. res = 1;
  28. continue;
  29. }
  30. strfmon (buf, sizeof (buf), "|%n|%!n|", -12.34, -12.34);
  31. int fail = strcmp (buf, tests[i].expected) != 0;
  32. printf ("%s%s\n", buf, fail ? " *** FAIL ***" : "");
  33. res |= fail;
  34. }
  35. return res;
  36. }
  37. #define TEST_FUNCTION do_test ()
  38. #include "../test-skeleton.c"