1 /* Test of POSIX compatible vsprintf() and sprintf() functions.
2 Copyright (C) 2007 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 2, or (at your option)
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, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
21 test_function (int (*my_printf) (const char *, ...))
23 /* Here we don't test output that may be platform dependent.
24 The bulk of the tests is done as part of the 'vasnprintf-posix' module. */
26 /* Test support of size specifiers as in C99. */
28 my_printf ("%ju %d\n", (uintmax_t) 12345671, 33, 44, 55);
30 my_printf ("%zu %d\n", (size_t) 12345672, 33, 44, 55);
32 my_printf ("%tu %d\n", (ptrdiff_t) 12345673, 33, 44, 55);
34 /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
35 output of floating-point numbers. */
38 my_printf ("%a %d\n", 0.0, 33, 44, 55);
40 /* Positive infinity. */
41 my_printf ("%a %d\n", 1.0 / 0.0, 33, 44, 55);
43 /* Negative infinity. */
44 my_printf ("%a %d\n", -1.0 / 0.0, 33, 44, 55);
46 /* FLAG_ZERO with infinite number. */
47 /* "0000000inf 33" is not a valid result; see
48 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
49 my_printf ("%010a %d\n", 1.0 / 0.0, 33, 44, 55);
51 /* Test the support of the %f format directive. */
53 /* A positive number. */
54 my_printf ("%f %d\n", 12.75, 33, 44, 55);
56 /* A larger positive number. */
57 my_printf ("%f %d\n", 1234567.0, 33, 44, 55);
59 /* A negative number. */
60 my_printf ("%f %d\n", -0.03125, 33, 44, 55);
63 my_printf ("%f %d\n", 0.0, 33, 44, 55);
66 my_printf ("%015f %d\n", 1234.0, 33, 44, 55);
69 my_printf ("%.f %d\n", 1234.0, 33, 44, 55);
71 /* A positive number. */
72 my_printf ("%Lf %d\n", 12.75L, 33, 44, 55);
74 /* A larger positive number. */
75 my_printf ("%Lf %d\n", 1234567.0L, 33, 44, 55);
77 /* A negative number. */
78 my_printf ("%Lf %d\n", -0.03125L, 33, 44, 55);
81 my_printf ("%Lf %d\n", 0.0L, 33, 44, 55);
84 my_printf ("%015Lf %d\n", 1234.0L, 33, 44, 55);
87 my_printf ("%.Lf %d\n", 1234.0L, 33, 44, 55);
89 /* Test the support of the %F format directive. */
91 /* A positive number. */
92 my_printf ("%F %d\n", 12.75, 33, 44, 55);
94 /* A larger positive number. */
95 my_printf ("%F %d\n", 1234567.0, 33, 44, 55);
97 /* A negative number. */
98 my_printf ("%F %d\n", -0.03125, 33, 44, 55);
101 my_printf ("%F %d\n", 0.0, 33, 44, 55);
104 my_printf ("%015F %d\n", 1234.0, 33, 44, 55);
107 my_printf ("%.F %d\n", 1234.0, 33, 44, 55);
109 /* A positive number. */
110 my_printf ("%LF %d\n", 12.75L, 33, 44, 55);
112 /* A larger positive number. */
113 my_printf ("%LF %d\n", 1234567.0L, 33, 44, 55);
115 /* A negative number. */
116 my_printf ("%LF %d\n", -0.03125L, 33, 44, 55);
119 my_printf ("%LF %d\n", 0.0L, 33, 44, 55);
122 my_printf ("%015LF %d\n", 1234.0L, 33, 44, 55);
125 my_printf ("%.LF %d\n", 1234.0L, 33, 44, 55);
127 /* Test the support of the POSIX/XSI format strings with positions. */
129 my_printf ("%2$d %1$d\n", 33, 55);