Fix a warning in last patch.
[gnulib.git] / tests / test-printf-posix.h
1 /* Test of POSIX compatible vsprintf() and sprintf() functions.
2    Copyright (C) 2007 Free Software Foundation, Inc.
3
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)
7    any later version.
8
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.
13
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.  */
17
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
19
20 /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0.  */
21 #ifdef __DECC
22 static double
23 NaN ()
24 {
25   static double zero = 0.0;
26   return zero / zero;
27 }
28 #else
29 # define NaN() (0.0 / 0.0)
30 #endif
31
32 static void
33 test_function (int (*my_printf) (const char *, ...))
34 {
35   /* Here we don't test output that may be platform dependent.
36      The bulk of the tests is done as part of the 'vasnprintf-posix' module.  */
37
38   /* Test support of size specifiers as in C99.  */
39
40   my_printf ("%ju %d\n", (uintmax_t) 12345671, 33, 44, 55);
41
42   my_printf ("%zu %d\n", (size_t) 12345672, 33, 44, 55);
43
44   my_printf ("%tu %d\n", (ptrdiff_t) 12345673, 33, 44, 55);
45
46   /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
47      output of floating-point numbers.  */
48
49   /* Positive zero.  */
50   my_printf ("%a %d\n", 0.0, 33, 44, 55);
51
52   /* Negative zero.  */
53   my_printf ("%a %d\n", -0.0, 33, 44, 55);
54
55   /* Positive infinity.  */
56   my_printf ("%a %d\n", 1.0 / 0.0, 33, 44, 55);
57
58   /* Negative infinity.  */
59   my_printf ("%a %d\n", -1.0 / 0.0, 33, 44, 55);
60
61   /* NaN.  */
62   my_printf ("%a %d\n", NaN (), 33, 44, 55);
63
64   /* FLAG_ZERO with infinite number.  */
65   /* "0000000inf 33" is not a valid result; see
66      <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
67   my_printf ("%010a %d\n", 1.0 / 0.0, 33, 44, 55);
68
69   /* FLAG_ZERO with NaN.  */
70   /* "0000000nan 33" is not a valid result; see
71      <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
72   my_printf ("%010a %d\n", NaN (), 33, 44, 55);
73
74   /* Test the support of the %f format directive.  */
75
76   /* A positive number.  */
77   my_printf ("%f %d\n", 12.75, 33, 44, 55);
78
79   /* A larger positive number.  */
80   my_printf ("%f %d\n", 1234567.0, 33, 44, 55);
81
82   /* A negative number.  */
83   my_printf ("%f %d\n", -0.03125, 33, 44, 55);
84
85   /* Positive zero.  */
86   my_printf ("%f %d\n", 0.0, 33, 44, 55);
87
88   /* Negative zero.  */
89   my_printf ("%f %d\n", -0.0, 33, 44, 55);
90
91   /* NaN.  */
92   my_printf ("%f %d\n", NaN (), 33, 44, 55);
93
94   /* FLAG_ZERO.  */
95   my_printf ("%015f %d\n", 1234.0, 33, 44, 55);
96
97   /* Precision.  */
98   my_printf ("%.f %d\n", 1234.0, 33, 44, 55);
99
100   /* A positive number.  */
101   my_printf ("%Lf %d\n", 12.75L, 33, 44, 55);
102
103   /* A larger positive number.  */
104   my_printf ("%Lf %d\n", 1234567.0L, 33, 44, 55);
105
106   /* A negative number.  */
107   my_printf ("%Lf %d\n", -0.03125L, 33, 44, 55);
108
109   /* Positive zero.  */
110   my_printf ("%Lf %d\n", 0.0L, 33, 44, 55);
111
112   /* Negative zero.  */
113   my_printf ("%Lf %d\n", -0.0L, 33, 44, 55);
114
115   { /* NaN.  */
116     static long double zero = 0.0L;
117     my_printf ("%Lf %d\n", zero / zero, 33, 44, 55);
118   }
119
120   /* FLAG_ZERO.  */
121   my_printf ("%015Lf %d\n", 1234.0L, 33, 44, 55);
122
123   /* Precision.  */
124   my_printf ("%.Lf %d\n", 1234.0L, 33, 44, 55);
125
126   /* Test the support of the %F format directive.  */
127
128   /* A positive number.  */
129   my_printf ("%F %d\n", 12.75, 33, 44, 55);
130
131   /* A larger positive number.  */
132   my_printf ("%F %d\n", 1234567.0, 33, 44, 55);
133
134   /* A negative number.  */
135   my_printf ("%F %d\n", -0.03125, 33, 44, 55);
136
137   /* Positive zero.  */
138   my_printf ("%F %d\n", 0.0, 33, 44, 55);
139
140   /* Negative zero.  */
141   my_printf ("%F %d\n", -0.0, 33, 44, 55);
142
143   /* NaN.  */
144   my_printf ("%F %d\n", NaN (), 33, 44, 55);
145
146   /* FLAG_ZERO.  */
147   my_printf ("%015F %d\n", 1234.0, 33, 44, 55);
148
149   /* Precision.  */
150   my_printf ("%.F %d\n", 1234.0, 33, 44, 55);
151
152   /* A positive number.  */
153   my_printf ("%LF %d\n", 12.75L, 33, 44, 55);
154
155   /* A larger positive number.  */
156   my_printf ("%LF %d\n", 1234567.0L, 33, 44, 55);
157
158   /* A negative number.  */
159   my_printf ("%LF %d\n", -0.03125L, 33, 44, 55);
160
161   /* Positive zero.  */
162   my_printf ("%LF %d\n", 0.0L, 33, 44, 55);
163
164   /* Negative zero.  */
165   my_printf ("%LF %d\n", -0.0L, 33, 44, 55);
166
167   { /* NaN.  */
168     static long double zero = 0.0L;
169     my_printf ("%LF %d\n", zero / zero, 33, 44, 55);
170   }
171
172   /* FLAG_ZERO.  */
173   my_printf ("%015LF %d\n", 1234.0L, 33, 44, 55);
174
175   /* Precision.  */
176   my_printf ("%.LF %d\n", 1234.0L, 33, 44, 55);
177
178   /* Test the support of the POSIX/XSI format strings with positions.  */
179
180   my_printf ("%2$d %1$d\n", 33, 55);
181 }