1 /* Test for the long double variants of *w*printf_chk functions.
2 Copyright (C) 2019-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/>. */
19 #define _FORTIFY_SOURCE 2
26 #include <support/capture_subprocess.h>
27 #include <support/check.h>
30 do_test_call_varg (FILE *stream
, const wchar_t *format
, ...)
35 wprintf (L
"%20Ls", L
"__vfwprintf_chk: ");
36 va_start (args
, format
);
37 __vfwprintf_chk (stream
, 1, format
, args
);
41 wprintf (L
"%20Ls", L
"__vswprintf_chk: ");
42 va_start (args
, format
);
43 __vswprintf_chk (string
, 79, 1, 127, format
, args
);
45 wprintf (L
"%Ls", string
);
48 wprintf (L
"%20Ls", L
"__vwprintf_chk: ");
49 va_start (args
, format
);
50 __vwprintf_chk (1, format
, args
);
56 do_test_call_rarg (FILE *stream
, const wchar_t *format
, long double ld
,
61 wprintf (L
"%20Ls", L
"__fwprintf_chk: ");
62 __fwprintf_chk (stream
, 1, format
, ld
, d
);
65 wprintf (L
"%20Ls", L
"__swprintf_chk: ");
66 __swprintf_chk (string
, 79, 1, 127, format
, ld
, d
);
67 wprintf (L
"%Ls", string
);
70 wprintf (L
"%20Ls", L
"__wprintf_chk: ");
71 __wprintf_chk (1, format
, ld
, d
);
81 /* Print in decimal notation. */
82 do_test_call_rarg (stdout
, L
"%.10Lf, %.10f", ld
, d
);
83 do_test_call_varg (stdout
, L
"%.10Lf, %.10f", ld
, d
);
85 /* Print in hexadecimal notation. */
86 do_test_call_rarg (stdout
, L
"%.10La, %.10a", ld
, d
);
87 do_test_call_varg (stdout
, L
"%.10La, %.10a", ld
, d
);
89 /* Test positional parameters. */
90 do_test_call_varg (stdout
, L
"%3$Lf, %2$Lf, %1$f",
91 (double) 1, (long double) 2, (long double) 3);
97 struct support_capture_subprocess result
;
98 result
= support_capture_subprocess ((void *) &do_test_call
, NULL
);
100 /* Compare against the expected output. */
101 const char *expected
=
102 " __fwprintf_chk: -1.0000000000, -1.0000000000\n"
103 " __swprintf_chk: -1.0000000000, -1.0000000000\n"
104 " __wprintf_chk: -1.0000000000, -1.0000000000\n"
105 " __vfwprintf_chk: -1.0000000000, -1.0000000000\n"
106 " __vswprintf_chk: -1.0000000000, -1.0000000000\n"
107 " __vwprintf_chk: -1.0000000000, -1.0000000000\n"
108 " __fwprintf_chk: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
109 " __swprintf_chk: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
110 " __wprintf_chk: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
111 " __vfwprintf_chk: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
112 " __vswprintf_chk: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
113 " __vwprintf_chk: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
114 " __vfwprintf_chk: 3.000000, 2.000000, 1.000000\n"
115 " __vswprintf_chk: 3.000000, 2.000000, 1.000000\n"
116 " __vwprintf_chk: 3.000000, 2.000000, 1.000000\n";
117 TEST_COMPARE_STRING (expected
, result
.out
.buffer
);
122 #include <support/test-driver.c>