Oops, fix last commit so that it also works with modf().
[gnulib.git] / tests / test-fprintf-posix.h
1 /* Test of POSIX compatible vsprintf() and sprintf() functions.
2    Copyright (C) 2007-2010 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 3 of the License, or
7    (at your option) 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, see <http://www.gnu.org/licenses/>.  */
16
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
18
19 static void
20 test_function (int (*my_fprintf) (FILE *, const char *, ...))
21 {
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.  */
24
25   /* Test support of size specifiers as in C99.  */
26
27   my_fprintf (stdout, "%ju %d\n", (uintmax_t) 12345671, 33, 44, 55);
28
29   my_fprintf (stdout, "%zu %d\n", (size_t) 12345672, 33, 44, 55);
30
31   my_fprintf (stdout, "%tu %d\n", (ptrdiff_t) 12345673, 33, 44, 55);
32
33   /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
34      output of floating-point numbers.  */
35
36   /* Positive zero.  */
37   my_fprintf (stdout, "%a %d\n", 0.0, 33, 44, 55);
38
39   /* Positive infinity.  */
40   my_fprintf (stdout, "%a %d\n", 1.0 / 0.0, 33, 44, 55);
41
42   /* Negative infinity.  */
43   my_fprintf (stdout, "%a %d\n", -1.0 / 0.0, 33, 44, 55);
44
45   /* FLAG_ZERO with infinite number.  */
46   my_fprintf (stdout, "%010a %d\n", 1.0 / 0.0, 33, 44, 55);
47
48   /* Test the support of the %f format directive.  */
49
50   /* A positive number.  */
51   my_fprintf (stdout, "%f %d\n", 12.75, 33, 44, 55);
52
53   /* A larger positive number.  */
54   my_fprintf (stdout, "%f %d\n", 1234567.0, 33, 44, 55);
55
56   /* A negative number.  */
57   my_fprintf (stdout, "%f %d\n", -0.03125, 33, 44, 55);
58
59   /* Positive zero.  */
60   my_fprintf (stdout, "%f %d\n", 0.0, 33, 44, 55);
61
62   /* FLAG_ZERO.  */
63   my_fprintf (stdout, "%015f %d\n", 1234.0, 33, 44, 55);
64
65   /* Precision.  */
66   my_fprintf (stdout, "%.f %d\n", 1234.0, 33, 44, 55);
67
68   /* Precision with no rounding.  */
69   my_fprintf (stdout, "%.2f %d\n", 999.95, 33, 44, 55);
70
71   /* Precision with rounding.  */
72   my_fprintf (stdout, "%.2f %d\n", 999.996, 33, 44, 55);
73
74   /* A positive number.  */
75   my_fprintf (stdout, "%Lf %d\n", 12.75L, 33, 44, 55);
76
77   /* A larger positive number.  */
78   my_fprintf (stdout, "%Lf %d\n", 1234567.0L, 33, 44, 55);
79
80   /* A negative number.  */
81   my_fprintf (stdout, "%Lf %d\n", -0.03125L, 33, 44, 55);
82
83   /* Positive zero.  */
84   my_fprintf (stdout, "%Lf %d\n", 0.0L, 33, 44, 55);
85
86   /* FLAG_ZERO.  */
87   my_fprintf (stdout, "%015Lf %d\n", 1234.0L, 33, 44, 55);
88
89   /* Precision.  */
90   my_fprintf (stdout, "%.Lf %d\n", 1234.0L, 33, 44, 55);
91
92   /* Precision with no rounding.  */
93   my_fprintf (stdout, "%.2Lf %d\n", 999.95L, 33, 44, 55);
94
95   /* Precision with rounding.  */
96   my_fprintf (stdout, "%.2Lf %d\n", 999.996L, 33, 44, 55);
97
98   /* Test the support of the %F format directive.  */
99
100   /* A positive number.  */
101   my_fprintf (stdout, "%F %d\n", 12.75, 33, 44, 55);
102
103   /* A larger positive number.  */
104   my_fprintf (stdout, "%F %d\n", 1234567.0, 33, 44, 55);
105
106   /* A negative number.  */
107   my_fprintf (stdout, "%F %d\n", -0.03125, 33, 44, 55);
108
109   /* Positive zero.  */
110   my_fprintf (stdout, "%F %d\n", 0.0, 33, 44, 55);
111
112   /* FLAG_ZERO.  */
113   my_fprintf (stdout, "%015F %d\n", 1234.0, 33, 44, 55);
114
115   /* Precision.  */
116   my_fprintf (stdout, "%.F %d\n", 1234.0, 33, 44, 55);
117
118   /* Precision with no rounding.  */
119   my_fprintf (stdout, "%.2F %d\n", 999.95, 33, 44, 55);
120
121   /* Precision with rounding.  */
122   my_fprintf (stdout, "%.2F %d\n", 999.996, 33, 44, 55);
123
124   /* A positive number.  */
125   my_fprintf (stdout, "%LF %d\n", 12.75L, 33, 44, 55);
126
127   /* A larger positive number.  */
128   my_fprintf (stdout, "%LF %d\n", 1234567.0L, 33, 44, 55);
129
130   /* A negative number.  */
131   my_fprintf (stdout, "%LF %d\n", -0.03125L, 33, 44, 55);
132
133   /* Positive zero.  */
134   my_fprintf (stdout, "%LF %d\n", 0.0L, 33, 44, 55);
135
136   /* FLAG_ZERO.  */
137   my_fprintf (stdout, "%015LF %d\n", 1234.0L, 33, 44, 55);
138
139   /* Precision.  */
140   my_fprintf (stdout, "%.LF %d\n", 1234.0L, 33, 44, 55);
141
142   /* Precision with no rounding.  */
143   my_fprintf (stdout, "%.2LF %d\n", 999.95L, 33, 44, 55);
144
145   /* Precision with rounding.  */
146   my_fprintf (stdout, "%.2LF %d\n", 999.996L, 33, 44, 55);
147
148   /* Test the support of the POSIX/XSI format strings with positions.  */
149
150   my_fprintf (stdout, "%2$d %1$d\n", 33, 55);
151 }