1 /* Test of POSIX compatible vsprintf() and sprintf() functions.
2 Copyright (C) 2007-2010 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 <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
20 test_function (int (*my_printf) (const char *, ...))
22 /* Here we don't test output that may be platform dependent.
23 The bulk of the tests is done as part of the 'vasnprintf-posix' module. */
25 /* Test support of size specifiers as in C99. */
27 my_printf ("%ju %d\n", (uintmax_t) 12345671, 33, 44, 55);
29 my_printf ("%zu %d\n", (size_t) 12345672, 33, 44, 55);
31 my_printf ("%tu %d\n", (ptrdiff_t) 12345673, 33, 44, 55);
33 /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
34 output of floating-point numbers. */
37 my_printf ("%a %d\n", 0.0, 33, 44, 55);
39 /* Positive infinity. */
40 my_printf ("%a %d\n", 1.0 / 0.0, 33, 44, 55);
42 /* Negative infinity. */
43 my_printf ("%a %d\n", -1.0 / 0.0, 33, 44, 55);
45 /* FLAG_ZERO with infinite number. */
46 /* "0000000inf 33" is not a valid result; see
47 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
48 my_printf ("%010a %d\n", 1.0 / 0.0, 33, 44, 55);
50 /* Test the support of the %f format directive. */
52 /* A positive number. */
53 my_printf ("%f %d\n", 12.75, 33, 44, 55);
55 /* A larger positive number. */
56 my_printf ("%f %d\n", 1234567.0, 33, 44, 55);
58 /* A negative number. */
59 my_printf ("%f %d\n", -0.03125, 33, 44, 55);
62 my_printf ("%f %d\n", 0.0, 33, 44, 55);
65 my_printf ("%015f %d\n", 1234.0, 33, 44, 55);
68 my_printf ("%.f %d\n", 1234.0, 33, 44, 55);
70 /* Precision with no rounding. */
71 my_printf ("%.2f %d\n", 999.95, 33, 44, 55);
73 /* Precision with rounding. */
74 my_printf ("%.2f %d\n", 999.996, 33, 44, 55);
76 /* A positive number. */
77 my_printf ("%Lf %d\n", 12.75L, 33, 44, 55);
79 /* A larger positive number. */
80 my_printf ("%Lf %d\n", 1234567.0L, 33, 44, 55);
82 /* A negative number. */
83 my_printf ("%Lf %d\n", -0.03125L, 33, 44, 55);
86 my_printf ("%Lf %d\n", 0.0L, 33, 44, 55);
89 my_printf ("%015Lf %d\n", 1234.0L, 33, 44, 55);
92 my_printf ("%.Lf %d\n", 1234.0L, 33, 44, 55);
94 /* Precision with no rounding. */
95 my_printf ("%.2Lf %d\n", 999.95L, 33, 44, 55);
97 /* Precision with rounding. */
98 my_printf ("%.2Lf %d\n", 999.996L, 33, 44, 55);
100 /* Test the support of the %F format directive. */
102 /* A positive number. */
103 my_printf ("%F %d\n", 12.75, 33, 44, 55);
105 /* A larger positive number. */
106 my_printf ("%F %d\n", 1234567.0, 33, 44, 55);
108 /* A negative number. */
109 my_printf ("%F %d\n", -0.03125, 33, 44, 55);
112 my_printf ("%F %d\n", 0.0, 33, 44, 55);
115 my_printf ("%015F %d\n", 1234.0, 33, 44, 55);
118 my_printf ("%.F %d\n", 1234.0, 33, 44, 55);
120 /* Precision with no rounding. */
121 my_printf ("%.2F %d\n", 999.95, 33, 44, 55);
123 /* Precision with rounding. */
124 my_printf ("%.2F %d\n", 999.996, 33, 44, 55);
126 /* A positive number. */
127 my_printf ("%LF %d\n", 12.75L, 33, 44, 55);
129 /* A larger positive number. */
130 my_printf ("%LF %d\n", 1234567.0L, 33, 44, 55);
132 /* A negative number. */
133 my_printf ("%LF %d\n", -0.03125L, 33, 44, 55);
136 my_printf ("%LF %d\n", 0.0L, 33, 44, 55);
139 my_printf ("%015LF %d\n", 1234.0L, 33, 44, 55);
142 my_printf ("%.LF %d\n", 1234.0L, 33, 44, 55);
144 /* Precision with no rounding. */
145 my_printf ("%.2LF %d\n", 999.95L, 33, 44, 55);
147 /* Precision with rounding. */
148 my_printf ("%.2LF %d\n", 999.996L, 33, 44, 55);
150 /* Test the support of the POSIX/XSI format strings with positions. */
152 my_printf ("%2$d %1$d\n", 33, 55);