1 /* Test for the long double variants of strfmon* functions.
2    Copyright (C) 2019-2021 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
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 
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <https://www.gnu.org/licenses/>.  */
18 
19 #include <locale/locale.h>
20 #include <monetary.h>
21 
22 #include <support/check.h>
23 
24 static int
do_test(void)25 do_test (void)
26 {
27   size_t written;
28   char buffer[64];
29   char *bufptr = buffer;
30   locale_t loc;
31 
32   /* Using the C locale is enough for the purpose of this test case,
33      i.e.: to test that strfmon correctly reads long double values with
34      binary128 format.  Grouping and currency are irrelevant, here.  */
35   setlocale (LC_MONETARY, "C");
36   loc = newlocale (LC_MONETARY_MASK, "C", (locale_t) 0);
37 
38   /* Write to the buffer.  */
39   written = strfmon (bufptr, 32, "%.10i, %.10Li\n",
40                      (double) -2, (long double) -1);
41   if (written < 0)
42     support_record_failure ();
43   else
44     bufptr += written;
45   written = strfmon_l (bufptr, 32, loc, "%.10i, %.10Li\n",
46                        (double) -2, (long double) -1);
47   if (written < 0)
48     support_record_failure ();
49 
50   /* Compare against the expected output.  */
51   const char *expected =
52     "-2.0000000000, -1.0000000000\n"
53     "-2.0000000000, -1.0000000000\n";
54   TEST_COMPARE_STRING (expected, buffer);
55 
56   return 0;
57 }
58 
59 #include <support/test-driver.c>
60