]>
Commit | Line | Data |
---|---|---|
329037ce | 1 | /* Test for the long double variants of *w*printf_chk functions. |
2b778ceb | 2 | Copyright (C) 2019-2021 Free Software Foundation, Inc. |
329037ce GG |
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 | |
5d39f37b | 17 | <https://www.gnu.org/licenses/>. */ |
329037ce GG |
18 | |
19 | #define _FORTIFY_SOURCE 2 | |
20 | ||
21 | #include <stdarg.h> | |
22 | #include <stdint.h> | |
23 | #include <stdio.h> | |
24 | #include <wchar.h> | |
25 | ||
26 | #include <support/capture_subprocess.h> | |
27 | #include <support/check.h> | |
28 | ||
29 | static void | |
30 | do_test_call_varg (FILE *stream, const wchar_t *format, ...) | |
31 | { | |
32 | wchar_t string[128]; | |
33 | va_list args; | |
34 | ||
35 | wprintf (L"%20Ls", L"__vfwprintf_chk: "); | |
36 | va_start (args, format); | |
37 | __vfwprintf_chk (stream, 1, format, args); | |
38 | va_end (args); | |
39 | wprintf (L"\n"); | |
40 | ||
41 | wprintf (L"%20Ls", L"__vswprintf_chk: "); | |
42 | va_start (args, format); | |
43 | __vswprintf_chk (string, 79, 1, 127, format, args); | |
44 | va_end (args); | |
45 | wprintf (L"%Ls", string); | |
46 | wprintf (L"\n"); | |
47 | ||
48 | wprintf (L"%20Ls", L"__vwprintf_chk: "); | |
49 | va_start (args, format); | |
50 | __vwprintf_chk (1, format, args); | |
51 | va_end (args); | |
52 | wprintf (L"\n"); | |
53 | } | |
54 | ||
55 | static void | |
5bbbd5ae GG |
56 | do_test_call_rarg (FILE *stream, const wchar_t *format, long double ld, |
57 | double d) | |
329037ce GG |
58 | { |
59 | wchar_t string[128]; | |
60 | ||
61 | wprintf (L"%20Ls", L"__fwprintf_chk: "); | |
5bbbd5ae | 62 | __fwprintf_chk (stream, 1, format, ld, d); |
329037ce GG |
63 | wprintf (L"\n"); |
64 | ||
65 | wprintf (L"%20Ls", L"__swprintf_chk: "); | |
5bbbd5ae | 66 | __swprintf_chk (string, 79, 1, 127, format, ld, d); |
329037ce GG |
67 | wprintf (L"%Ls", string); |
68 | wprintf (L"\n"); | |
69 | ||
70 | wprintf (L"%20Ls", L"__wprintf_chk: "); | |
5bbbd5ae | 71 | __wprintf_chk (1, format, ld, d); |
329037ce GG |
72 | wprintf (L"\n"); |
73 | } | |
74 | ||
75 | static void | |
76 | do_test_call (void) | |
77 | { | |
78 | long double ld = -1; | |
5bbbd5ae | 79 | double d = -1; |
329037ce GG |
80 | |
81 | /* Print in decimal notation. */ | |
5bbbd5ae GG |
82 | do_test_call_rarg (stdout, L"%.10Lf, %.10f", ld, d); |
83 | do_test_call_varg (stdout, L"%.10Lf, %.10f", ld, d); | |
329037ce GG |
84 | |
85 | /* Print in hexadecimal notation. */ | |
5bbbd5ae GG |
86 | do_test_call_rarg (stdout, L"%.10La, %.10a", ld, d); |
87 | do_test_call_varg (stdout, L"%.10La, %.10a", ld, d); | |
c2f959ed GG |
88 | |
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); | |
329037ce GG |
92 | } |
93 | ||
94 | static int | |
95 | do_test (void) | |
96 | { | |
97 | struct support_capture_subprocess result; | |
98 | result = support_capture_subprocess ((void *) &do_test_call, NULL); | |
99 | ||
100 | /* Compare against the expected output. */ | |
101 | const char *expected = | |
5bbbd5ae GG |
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" | |
c2f959ed GG |
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"; | |
329037ce GG |
117 | TEST_COMPARE_STRING (expected, result.out.buffer); |
118 | ||
119 | return 0; | |
120 | } | |
121 | ||
122 | #include <support/test-driver.c> |