1 /* Test for the long double conversions in *warn* functions.
2 Copyright (C) 2018-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
26 #include <support/check.h>
27 #include <support/xmemstream.h>
29 enum {WARN
, WARNX
, VWARN
, VWARNX
};
32 do_one_test (int select
, const char *format
, va_list args
,
33 long double arg1
, double arg2
, long double arg3
,
34 double arg4
, const char *expected
)
36 /* Prepare in-memory buffer to hold the output. */
37 struct xmemstream stream
;
38 xopen_memstream (&stream
);
39 FILE *old_stderr
= stderr
;
42 /* Write to the buffer using one of the *warn* functions. */
47 warn (format
, arg1
, arg2
, arg3
, arg4
);
50 warnx (format
, arg1
, arg2
, arg3
, arg4
);
56 vwarnx (format
, args
);
62 /* Close the in-memory stream. */
63 xfclose_memstream (&stream
);
65 /* Filter out the name of the program (which should always end with
66 warn), so that the test case can be reused by ldbl-opt and
67 ldbl-128ibm-compat. */
68 const char *needle
= "warn: ";
70 message
= strstr (stream
.buffer
, needle
);
72 FAIL_EXIT1 ("test case error");
73 message
+= strlen (needle
);
75 /* Check that the rest of the output is as expected. */
76 TEST_COMPARE_STRING (message
, expected
);
78 if (stream
.buffer
!= NULL
)
83 do_test_call_varg (const char *format
, ...)
87 va_start (args
, format
);
88 do_one_test (VWARN
, format
, args
, 0, 0, 0, 0,
89 "-1.000000 - -2.000000 - -3.000000 - -4.000000: Success\n");
92 va_start (args
, format
);
93 do_one_test (VWARNX
, format
, args
, 0, 0, 0, 0,
94 "-1.000000 - -2.000000 - -3.000000 - -4.000000\n");
99 do_test_call_rarg (const char *format
, long double arg1
, double arg2
,
100 long double arg3
, double arg4
)
103 memset (&args
, 0, sizeof (args
));
104 do_one_test (WARN
, format
, args
, arg1
, arg2
, arg3
, arg4
,
105 "-1.000000 - -2.000000 - -3.000000 - -4.000000: Success\n");
106 do_one_test (WARNX
, format
, args
, arg1
, arg2
, arg3
, arg4
,
107 "-1.000000 - -2.000000 - -3.000000 - -4.000000\n");
113 long double arg1
= -1;
114 long double arg3
= -3;
118 do_test_call_rarg ("%Lf - %f - %Lf - %f", arg1
, arg2
, arg3
, arg4
);
119 do_test_call_varg ("%Lf - %f - %Lf - %f", arg1
, arg2
, arg3
, arg4
);
124 #include <support/test-driver.c>