Back to index

glibc  2.9
tst-strfmon1.c
Go to the documentation of this file.
00001 #include <monetary.h>
00002 #include <locale.h>
00003 #include <stdio.h>
00004 #include <string.h>
00005 
00006 static const struct
00007 {
00008   const char *locale;
00009   const char *expected;
00010 } tests[] =
00011   {
00012     { "de_DE.ISO-8859-1", "|-12,34 EUR|-12,34|" },
00013     { "da_DK.ISO-8859-1", "|kr -12,34|-12,34|" },
00014     { "zh_TW.EUC-TW", "|-NT$12.34|-12.34|" },
00015     { "sv_SE.ISO-8859-1", "|-12,34 kr|-12,34|" }
00016   };
00017 #define ntests (sizeof (tests) / sizeof (tests[0]))
00018 
00019 
00020 static int
00021 do_test (void)
00022 {
00023   int res = 0;
00024   for (int i = 0; i < ntests; ++i)
00025     {
00026       char buf[500];
00027       if (setlocale (LC_ALL, tests[i].locale) == NULL)
00028        {
00029          printf ("failed to set locale %s\n", tests[i].locale);
00030          res = 1;
00031          continue;
00032        }
00033       strfmon (buf, sizeof (buf), "|%n|%!n|", -12.34, -12.34);
00034       int fail = strcmp (buf, tests[i].expected) != 0;
00035       printf ("%s%s\n", buf, fail ? " *** FAIL ***" : "");
00036       res |= fail;
00037     }
00038   return res;
00039 }
00040 
00041 #define TEST_FUNCTION do_test ()
00042 #include "../test-skeleton.c"