1 /* Test for the long double variants of *printf functions.
2 Copyright (C) 2019-2023 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/>. */
24 #include <support/capture_subprocess.h>
25 #include <support/check.h>
28 do_test_call_varg (FILE *stream
, const char *format
, ...)
34 printf ("%15s", "vasprintf: ");
35 va_start (args
, format
);
36 vasprintf (&buffer
, format
, args
);
39 printf ("Error using vasprintf\n");
42 printf ("%s", buffer
);
47 printf ("%15s", "vdprintf: ");
48 va_start (args
, format
);
49 vdprintf (fileno (stream
), format
, args
);
53 printf ("%15s", "vfprintf: ");
54 va_start (args
, format
);
55 vfprintf (stream
, format
, args
);
59 printf ("%15s", "vprintf: ");
60 va_start (args
, format
);
61 vprintf (format
, args
);
65 printf ("%15s", "vsnprintf: ");
66 va_start (args
, format
);
67 vsnprintf (string
, 127, format
, args
);
69 printf ("%s", string
);
72 printf ("%15s", "vsprintf: ");
73 va_start (args
, format
);
74 vsprintf (string
, format
, args
);
76 printf ("%s", string
);
81 do_test_call_rarg (FILE *stream
, const char *format
, long double ld
, double d
)
86 printf ("%15s", "asprintf: ");
87 asprintf (&buffer
, format
, ld
, d
);
89 printf ("Error using asprintf\n");
92 printf ("%s", buffer
);
97 printf ("%15s", "dprintf: ");
98 dprintf (fileno (stream
), format
, ld
, d
);
101 printf ("%15s", "fprintf: ");
102 fprintf (stream
, format
, ld
, d
);
105 printf ("%15s", "printf: ");
106 printf (format
, ld
, d
);
109 printf ("%15s", "snprintf: ");
110 snprintf (string
, 127, format
, ld
, d
);
111 printf ("%s", string
);
114 printf ("%15s", "sprintf: ");
115 sprintf (string
, format
, ld
, d
);
116 printf ("%s", string
);
126 /* Print in decimal notation. */
127 do_test_call_rarg (stdout
, "%.10Lf, %.10f", ld
, d
);
128 do_test_call_varg (stdout
, "%.10Lf, %.10f", ld
, d
);
130 /* Print in hexadecimal notation. */
131 do_test_call_rarg (stdout
, "%.10La, %.10a", ld
, d
);
132 do_test_call_varg (stdout
, "%.10La, %.10a", ld
, d
);
134 /* Test positional parameters. */
135 do_test_call_varg (stdout
, "%3$Lf, %2$Lf, %1$f",
136 (double) 1, (long double) 2, (long double) 3);
142 struct support_capture_subprocess result
;
143 result
= support_capture_subprocess ((void *) &do_test_call
, NULL
);
145 /* Compare against the expected output. */
146 const char *expected
=
147 " asprintf: -1.0000000000, -1.0000000000\n"
148 " dprintf: -1.0000000000, -1.0000000000\n"
149 " fprintf: -1.0000000000, -1.0000000000\n"
150 " printf: -1.0000000000, -1.0000000000\n"
151 " snprintf: -1.0000000000, -1.0000000000\n"
152 " sprintf: -1.0000000000, -1.0000000000\n"
153 " vasprintf: -1.0000000000, -1.0000000000\n"
154 " vdprintf: -1.0000000000, -1.0000000000\n"
155 " vfprintf: -1.0000000000, -1.0000000000\n"
156 " vprintf: -1.0000000000, -1.0000000000\n"
157 " vsnprintf: -1.0000000000, -1.0000000000\n"
158 " vsprintf: -1.0000000000, -1.0000000000\n"
159 " asprintf: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
160 " dprintf: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
161 " fprintf: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
162 " printf: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
163 " snprintf: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
164 " sprintf: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
165 " vasprintf: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
166 " vdprintf: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
167 " vfprintf: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
168 " vprintf: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
169 " vsnprintf: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
170 " vsprintf: -0x1.0000000000p+0, -0x1.0000000000p+0\n"
171 " vasprintf: 3.000000, 2.000000, 1.000000\n"
172 " vdprintf: 3.000000, 2.000000, 1.000000\n"
173 " vfprintf: 3.000000, 2.000000, 1.000000\n"
174 " vprintf: 3.000000, 2.000000, 1.000000\n"
175 " vsnprintf: 3.000000, 2.000000, 1.000000\n"
176 " vsprintf: 3.000000, 2.000000, 1.000000\n";
177 TEST_COMPARE_STRING (expected
, result
.out
.buffer
);
182 #include <support/test-driver.c>