367dba9abf36c0907124eb30daf2a702ea15425e
[pspp] / 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 static void
21 test_function (int (*my_printf) (const char *, ...))
22 {
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.  */
25
26   /* Test support of size specifiers as in C99.  */
27
28   my_printf ("%ju %d\n", (uintmax_t) 12345671, 33, 44, 55);
29
30   my_printf ("%zu %d\n", (size_t) 12345672, 33, 44, 55);
31
32   my_printf ("%tu %d\n", (ptrdiff_t) 12345673, 33, 44, 55);
33
34   /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
35      output of floating-point numbers.  */
36
37   /* Positive zero.  */
38   my_printf ("%a %d\n", 0.0, 33, 44, 55);
39
40   /* Negative zero.  */
41   my_printf ("%a %d\n", -0.0, 33, 44, 55);
42
43   /* Positive infinity.  */
44   my_printf ("%a %d\n", 1.0 / 0.0, 33, 44, 55);
45
46   /* Negative infinity.  */
47   my_printf ("%a %d\n", -1.0 / 0.0, 33, 44, 55);
48
49   /* FLAG_ZERO with infinite number.  */
50   /* "0000000inf 33" is not a valid result; see
51      <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
52   my_printf ("%010a %d\n", 1.0 / 0.0, 33, 44, 55);
53
54   /* Test the support of the %f format directive.  */
55
56   /* A positive number.  */
57   my_printf ("%f %d\n", 12.75, 33, 44, 55);
58
59   /* A larger positive number.  */
60   my_printf ("%f %d\n", 1234567.0, 33, 44, 55);
61
62   /* A negative number.  */
63   my_printf ("%f %d\n", -0.03125, 33, 44, 55);
64
65   /* Positive zero.  */
66   my_printf ("%f %d\n", 0.0, 33, 44, 55);
67
68   /* Negative zero.  */
69   my_printf ("%f %d\n", -0.0, 33, 44, 55);
70
71   /* FLAG_ZERO.  */
72   my_printf ("%015f %d\n", 1234.0, 33, 44, 55);
73
74   /* Precision.  */
75   my_printf ("%.f %d\n", 1234.0, 33, 44, 55);
76
77   /* A positive number.  */
78   my_printf ("%Lf %d\n", 12.75L, 33, 44, 55);
79
80   /* A larger positive number.  */
81   my_printf ("%Lf %d\n", 1234567.0L, 33, 44, 55);
82
83   /* A negative number.  */
84   my_printf ("%Lf %d\n", -0.03125L, 33, 44, 55);
85
86   /* Positive zero.  */
87   my_printf ("%Lf %d\n", 0.0L, 33, 44, 55);
88
89   /* Negative zero.  */
90   my_printf ("%Lf %d\n", -0.0L, 33, 44, 55);
91
92   /* FLAG_ZERO.  */
93   my_printf ("%015Lf %d\n", 1234.0L, 33, 44, 55);
94
95   /* Precision.  */
96   my_printf ("%.Lf %d\n", 1234.0L, 33, 44, 55);
97
98   /* Test the support of the %F format directive.  */
99
100   /* A positive number.  */
101   my_printf ("%F %d\n", 12.75, 33, 44, 55);
102
103   /* A larger positive number.  */
104   my_printf ("%F %d\n", 1234567.0, 33, 44, 55);
105
106   /* A negative number.  */
107   my_printf ("%F %d\n", -0.03125, 33, 44, 55);
108
109   /* Positive zero.  */
110   my_printf ("%F %d\n", 0.0, 33, 44, 55);
111
112   /* Negative zero.  */
113   my_printf ("%F %d\n", -0.0, 33, 44, 55);
114
115   /* FLAG_ZERO.  */
116   my_printf ("%015F %d\n", 1234.0, 33, 44, 55);
117
118   /* Precision.  */
119   my_printf ("%.F %d\n", 1234.0, 33, 44, 55);
120
121   /* A positive number.  */
122   my_printf ("%LF %d\n", 12.75L, 33, 44, 55);
123
124   /* A larger positive number.  */
125   my_printf ("%LF %d\n", 1234567.0L, 33, 44, 55);
126
127   /* A negative number.  */
128   my_printf ("%LF %d\n", -0.03125L, 33, 44, 55);
129
130   /* Positive zero.  */
131   my_printf ("%LF %d\n", 0.0L, 33, 44, 55);
132
133   /* Negative zero.  */
134   my_printf ("%LF %d\n", -0.0L, 33, 44, 55);
135
136   /* FLAG_ZERO.  */
137   my_printf ("%015LF %d\n", 1234.0L, 33, 44, 55);
138
139   /* Precision.  */
140   my_printf ("%.LF %d\n", 1234.0L, 33, 44, 55);
141
142   /* Test the support of the POSIX/XSI format strings with positions.  */
143
144   my_printf ("%2$d %1$d\n", 33, 55);
145 }