spawn: Use special invocation for <spawn.h> on OS/2 kLIBC.
[gnulib.git] / tests / test-strfmon_l.c
blobb23ca266f7f7f2607c630b2506ebf961d076265c
1 /*
2 * Copyright (C) 2017-2021 Free Software Foundation, Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 #include <config.h>
19 #if HAVE_MONETARY_H
20 # include <monetary.h>
21 #endif
23 #include "signature.h"
24 #if HAVE_STRFMON_L
25 SIGNATURE_CHECK (strfmon_l, ssize_t, (char *s, size_t maxsize, locale_t locale,
26 const char *format, ...));
27 #endif
29 #include <locale.h>
30 #include <stdio.h>
31 #include <string.h>
33 #include "macros.h"
35 int
36 main (void)
38 #if HAVE_STRFMON_L
39 /* Simple test in the C locale. */
41 char buf[80];
42 locale_t loc;
43 ssize_t ret;
45 loc = newlocale (LC_ALL_MASK, "C", NULL);
46 ASSERT (loc != NULL);
47 ret = strfmon_l (buf, sizeof (buf), loc, "%^#5.0n", 123.4);
48 ASSERT ( (ret == 5 && strcmp (buf, " 123") == 0) /* AIX, Solaris */
49 || (ret == 6 && strcmp (buf, " 123") == 0) /* glibc */
50 || (ret == 7 && strcmp (buf, " 123 ") == 0) /* Mac OS X */
54 /* Test whether the decimal point comes from the right locale:
55 glibc bug <https://sourceware.org/bugzilla/show_bug.cgi?id=19633>. */
56 if (setlocale (LC_ALL, "en_US.UTF-8") == NULL)
58 fprintf (stderr, "Skipping test: English Unicode locale is not installed\n");
59 return 77;
61 if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
63 fprintf (stderr, "Skipping test: English Unicode locale is not installed\n");
64 return 77;
67 char expected_buf[80];
68 locale_t loc;
69 char buf[80];
71 setlocale (LC_ALL, "en_US.UTF-8");
72 ASSERT (strfmon (expected_buf, sizeof (expected_buf), "%.2n", 123.5) >= 0);
73 setlocale (LC_ALL, "de_DE.UTF-8");
74 loc = newlocale (LC_ALL_MASK, "en_US.UTF-8", NULL);
75 ASSERT (strfmon_l (buf, sizeof (buf), loc, "%.2n", 123.5) >= 0);
76 ASSERT (strcmp (buf, expected_buf) == 0);
77 freelocale (loc);
80 char expected_buf[80];
81 locale_t loc;
82 char buf[80];
84 setlocale (LC_ALL, "de_DE.UTF-8");
85 ASSERT (strfmon (expected_buf, sizeof (expected_buf), "%.2n", 123.5) >= 0);
86 setlocale (LC_ALL, "en_US.UTF-8");
87 loc = newlocale (LC_ALL_MASK, "de_DE.UTF-8", NULL);
88 ASSERT (strfmon_l (buf, sizeof (buf), loc, "%.2n", 123.5) >= 0);
89 ASSERT (strcmp (buf, expected_buf) == 0);
90 freelocale (loc);
92 #endif
94 return 0;