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