Add test case from a recent glibc bug.
[gnulib.git] / tests / test-printf-posix.h
blobc12118543583fc68b31a7f850224409aa6189b90
1 /* Test of POSIX compatible vsprintf() and sprintf() functions.
2 Copyright (C) 2007-2018 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
19 #include "infinity.h"
21 static void
22 test_function (int (*my_printf) (const char *, ...))
24 /* Here we don't test output that may be platform dependent.
25 The bulk of the tests is done as part of the 'vasnprintf-posix' module. */
27 /* Test support of size specifiers as in C99. */
29 my_printf ("%ju %d\n", (uintmax_t) 12345671, 33, 44, 55);
31 my_printf ("%zu %d\n", (size_t) 12345672, 33, 44, 55);
33 my_printf ("%tu %d\n", (ptrdiff_t) 12345673, 33, 44, 55);
35 /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
36 output of floating-point numbers. */
38 /* Positive zero. */
39 my_printf ("%a %d\n", 0.0, 33, 44, 55);
41 /* Positive infinity. */
42 my_printf ("%a %d\n", Infinityd (), 33, 44, 55);
44 /* Negative infinity. */
45 my_printf ("%a %d\n", - Infinityd (), 33, 44, 55);
47 /* FLAG_ZERO with infinite number. */
48 /* "0000000inf 33" is not a valid result; see
49 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
50 my_printf ("%010a %d\n", Infinityd (), 33, 44, 55);
52 /* Test the support of the %f format directive. */
54 /* A positive number. */
55 my_printf ("%f %d\n", 12.75, 33, 44, 55);
57 /* A larger positive number. */
58 my_printf ("%f %d\n", 1234567.0, 33, 44, 55);
60 /* A negative number. */
61 my_printf ("%f %d\n", -0.03125, 33, 44, 55);
63 /* Positive zero. */
64 my_printf ("%f %d\n", 0.0, 33, 44, 55);
66 /* FLAG_ZERO. */
67 my_printf ("%015f %d\n", 1234.0, 33, 44, 55);
69 /* Precision. */
70 my_printf ("%.f %d\n", 1234.0, 33, 44, 55);
72 /* Precision with no rounding. */
73 my_printf ("%.2f %d\n", 999.95, 33, 44, 55);
75 /* Precision with rounding. */
76 my_printf ("%.2f %d\n", 999.996, 33, 44, 55);
78 /* A positive number. */
79 my_printf ("%Lf %d\n", 12.75L, 33, 44, 55);
81 /* A larger positive number. */
82 my_printf ("%Lf %d\n", 1234567.0L, 33, 44, 55);
84 /* A negative number. */
85 my_printf ("%Lf %d\n", -0.03125L, 33, 44, 55);
87 /* Positive zero. */
88 my_printf ("%Lf %d\n", 0.0L, 33, 44, 55);
90 /* FLAG_ZERO. */
91 my_printf ("%015Lf %d\n", 1234.0L, 33, 44, 55);
93 /* Precision. */
94 my_printf ("%.Lf %d\n", 1234.0L, 33, 44, 55);
96 /* Precision with no rounding. */
97 my_printf ("%.2Lf %d\n", 999.95L, 33, 44, 55);
99 /* Precision with rounding. */
100 my_printf ("%.2Lf %d\n", 999.996L, 33, 44, 55);
102 /* Test the support of the %F format directive. */
104 /* A positive number. */
105 my_printf ("%F %d\n", 12.75, 33, 44, 55);
107 /* A larger positive number. */
108 my_printf ("%F %d\n", 1234567.0, 33, 44, 55);
110 /* A negative number. */
111 my_printf ("%F %d\n", -0.03125, 33, 44, 55);
113 /* Positive zero. */
114 my_printf ("%F %d\n", 0.0, 33, 44, 55);
116 /* FLAG_ZERO. */
117 my_printf ("%015F %d\n", 1234.0, 33, 44, 55);
119 /* Precision. */
120 my_printf ("%.F %d\n", 1234.0, 33, 44, 55);
122 /* Precision with no rounding. */
123 my_printf ("%.2F %d\n", 999.95, 33, 44, 55);
125 /* Precision with rounding. */
126 my_printf ("%.2F %d\n", 999.996, 33, 44, 55);
128 /* A positive number. */
129 my_printf ("%LF %d\n", 12.75L, 33, 44, 55);
131 /* A larger positive number. */
132 my_printf ("%LF %d\n", 1234567.0L, 33, 44, 55);
134 /* A negative number. */
135 my_printf ("%LF %d\n", -0.03125L, 33, 44, 55);
137 /* Positive zero. */
138 my_printf ("%LF %d\n", 0.0L, 33, 44, 55);
140 /* FLAG_ZERO. */
141 my_printf ("%015LF %d\n", 1234.0L, 33, 44, 55);
143 /* Precision. */
144 my_printf ("%.LF %d\n", 1234.0L, 33, 44, 55);
146 /* Precision with no rounding. */
147 my_printf ("%.2LF %d\n", 999.95L, 33, 44, 55);
149 /* Precision with rounding. */
150 my_printf ("%.2LF %d\n", 999.996L, 33, 44, 55);
152 /* Test the support of the POSIX/XSI format strings with positions. */
154 my_printf ("%2$d %1$d\n", 33, 55);