usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-strfmon_l.c
blobc9a75449324bc6c959e75e677e9d8f21c973395c
1 /*
2 * Copyright (C) 2017-2024 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 if (test_exit_status != EXIT_SUCCESS)
59 return test_exit_status;
60 fprintf (stderr, "Skipping test: English Unicode locale is not installed\n");
61 return 77;
63 if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
65 if (test_exit_status != EXIT_SUCCESS)
66 return test_exit_status;
67 fprintf (stderr, "Skipping test: English Unicode locale is not installed\n");
68 return 77;
71 char expected_buf[80];
72 locale_t loc;
73 char buf[80];
75 setlocale (LC_ALL, "en_US.UTF-8");
76 ASSERT (strfmon (expected_buf, sizeof (expected_buf), "%.2n", 123.5) >= 0);
77 setlocale (LC_ALL, "de_DE.UTF-8");
78 loc = newlocale (LC_ALL_MASK, "en_US.UTF-8", NULL);
79 ASSERT (strfmon_l (buf, sizeof (buf), loc, "%.2n", 123.5) >= 0);
80 ASSERT (strcmp (buf, expected_buf) == 0);
81 freelocale (loc);
84 char expected_buf[80];
85 locale_t loc;
86 char buf[80];
88 setlocale (LC_ALL, "de_DE.UTF-8");
89 ASSERT (strfmon (expected_buf, sizeof (expected_buf), "%.2n", 123.5) >= 0);
90 setlocale (LC_ALL, "en_US.UTF-8");
91 loc = newlocale (LC_ALL_MASK, "de_DE.UTF-8", NULL);
92 ASSERT (strfmon_l (buf, sizeof (buf), loc, "%.2n", 123.5) >= 0);
93 ASSERT (strcmp (buf, expected_buf) == 0);
94 freelocale (loc);
96 #endif
98 return test_exit_status;