added missing dependencies to fix failing unistr/ tests
[gnulib.git] / tests / test-printf-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_printf) (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_printf ("%ju %d\n", (uintmax_t) 12345671, 33, 44, 55);
28
29   my_printf ("%zu %d\n", (size_t) 12345672, 33, 44, 55);
30
31   my_printf ("%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_printf ("%a %d\n", 0.0, 33, 44, 55);
38
39   /* Positive infinity.  */
40   my_printf ("%a %d\n", 1.0 / 0.0, 33, 44, 55);
41
42   /* Negative infinity.  */
43   my_printf ("%a %d\n", -1.0 / 0.0, 33, 44, 55);
44
45   /* FLAG_ZERO with infinite number.  */
46   /* "0000000inf 33" is not a valid result; see
47      <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
48   my_printf ("%010a %d\n", 1.0 / 0.0, 33, 44, 55);
49
50   /* Test the support of the %f format directive.  */
51
52   /* A positive number.  */
53   my_printf ("%f %d\n", 12.75, 33, 44, 55);
54
55   /* A larger positive number.  */
56   my_printf ("%f %d\n", 1234567.0, 33, 44, 55);
57
58   /* A negative number.  */
59   my_printf ("%f %d\n", -0.03125, 33, 44, 55);
60
61   /* Positive zero.  */
62   my_printf ("%f %d\n", 0.0, 33, 44, 55);
63
64   /* FLAG_ZERO.  */
65   my_printf ("%015f %d\n", 1234.0, 33, 44, 55);
66
67   /* Precision.  */
68   my_printf ("%.f %d\n", 1234.0, 33, 44, 55);
69
70   /* Precision with no rounding.  */
71   my_printf ("%.2f %d\n", 999.95, 33, 44, 55);
72
73   /* Precision with rounding.  */
74   my_printf ("%.2f %d\n", 999.996, 33, 44, 55);
75
76   /* A positive number.  */
77   my_printf ("%Lf %d\n", 12.75L, 33, 44, 55);
78
79   /* A larger positive number.  */
80   my_printf ("%Lf %d\n", 1234567.0L, 33, 44, 55);
81
82   /* A negative number.  */
83   my_printf ("%Lf %d\n", -0.03125L, 33, 44, 55);
84
85   /* Positive zero.  */
86   my_printf ("%Lf %d\n", 0.0L, 33, 44, 55);
87
88   /* FLAG_ZERO.  */
89   my_printf ("%015Lf %d\n", 1234.0L, 33, 44, 55);
90
91   /* Precision.  */
92   my_printf ("%.Lf %d\n", 1234.0L, 33, 44, 55);
93
94   /* Precision with no rounding.  */
95   my_printf ("%.2Lf %d\n", 999.95L, 33, 44, 55);
96
97   /* Precision with rounding.  */
98   my_printf ("%.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_printf ("%F %d\n", 12.75, 33, 44, 55);
104
105   /* A larger positive number.  */
106   my_printf ("%F %d\n", 1234567.0, 33, 44, 55);
107
108   /* A negative number.  */
109   my_printf ("%F %d\n", -0.03125, 33, 44, 55);
110
111   /* Positive zero.  */
112   my_printf ("%F %d\n", 0.0, 33, 44, 55);
113
114   /* FLAG_ZERO.  */
115   my_printf ("%015F %d\n", 1234.0, 33, 44, 55);
116
117   /* Precision.  */
118   my_printf ("%.F %d\n", 1234.0, 33, 44, 55);
119
120   /* Precision with no rounding.  */
121   my_printf ("%.2F %d\n", 999.95, 33, 44, 55);
122
123   /* Precision with rounding.  */
124   my_printf ("%.2F %d\n", 999.996, 33, 44, 55);
125
126   /* A positive number.  */
127   my_printf ("%LF %d\n", 12.75L, 33, 44, 55);
128
129   /* A larger positive number.  */
130   my_printf ("%LF %d\n", 1234567.0L, 33, 44, 55);
131
132   /* A negative number.  */
133   my_printf ("%LF %d\n", -0.03125L, 33, 44, 55);
134
135   /* Positive zero.  */
136   my_printf ("%LF %d\n", 0.0L, 33, 44, 55);
137
138   /* FLAG_ZERO.  */
139   my_printf ("%015LF %d\n", 1234.0L, 33, 44, 55);
140
141   /* Precision.  */
142   my_printf ("%.LF %d\n", 1234.0L, 33, 44, 55);
143
144   /* Precision with no rounding.  */
145   my_printf ("%.2LF %d\n", 999.95L, 33, 44, 55);
146
147   /* Precision with rounding.  */
148   my_printf ("%.2LF %d\n", 999.996L, 33, 44, 55);
149
150   /* Test the support of the POSIX/XSI format strings with positions.  */
151
152   my_printf ("%2$d %1$d\n", 33, 55);
153 }