Document not_eol and remove mention of regex.c.
[gnulib.git] / tests / test-dprintf-posix.c
1 /* Test of POSIX compatible dprintf() function.
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>, 2009.  */
18
19 #include <config.h>
20
21 #include <stdio.h>
22
23 #include "signature.h"
24 SIGNATURE_CHECK (dprintf, int, (int, const char *, ...));
25
26 #include <stddef.h>
27 #include <stdint.h>
28 #include <string.h>
29
30 #include "macros.h"
31
32 static void
33 test_function (int (*my_dprintf) (int, 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_dprintf (fileno (stdout), "%ju %d\n", (uintmax_t) 12345671, 33, 44, 55);
41
42   my_dprintf (fileno (stdout), "%zu %d\n", (size_t) 12345672, 33, 44, 55);
43
44   my_dprintf (fileno (stdout), "%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_dprintf (fileno (stdout), "%a %d\n", 0.0, 33, 44, 55);
51
52   /* Positive infinity.  */
53   my_dprintf (fileno (stdout), "%a %d\n", 1.0 / 0.0, 33, 44, 55);
54
55   /* Negative infinity.  */
56   my_dprintf (fileno (stdout), "%a %d\n", -1.0 / 0.0, 33, 44, 55);
57
58   /* FLAG_ZERO with infinite number.  */
59   my_dprintf (fileno (stdout), "%010a %d\n", 1.0 / 0.0, 33, 44, 55);
60
61   /* Test the support of the %f format directive.  */
62
63   /* A positive number.  */
64   my_dprintf (fileno (stdout), "%f %d\n", 12.75, 33, 44, 55);
65
66   /* A larger positive number.  */
67   my_dprintf (fileno (stdout), "%f %d\n", 1234567.0, 33, 44, 55);
68
69   /* A negative number.  */
70   my_dprintf (fileno (stdout), "%f %d\n", -0.03125, 33, 44, 55);
71
72   /* Positive zero.  */
73   my_dprintf (fileno (stdout), "%f %d\n", 0.0, 33, 44, 55);
74
75   /* FLAG_ZERO.  */
76   my_dprintf (fileno (stdout), "%015f %d\n", 1234.0, 33, 44, 55);
77
78   /* Precision.  */
79   my_dprintf (fileno (stdout), "%.f %d\n", 1234.0, 33, 44, 55);
80
81   /* Precision with no rounding.  */
82   my_dprintf (fileno (stdout), "%.2f %d\n", 999.95, 33, 44, 55);
83
84   /* Precision with rounding.  */
85   my_dprintf (fileno (stdout), "%.2f %d\n", 999.996, 33, 44, 55);
86
87   /* A positive number.  */
88   my_dprintf (fileno (stdout), "%Lf %d\n", 12.75L, 33, 44, 55);
89
90   /* A larger positive number.  */
91   my_dprintf (fileno (stdout), "%Lf %d\n", 1234567.0L, 33, 44, 55);
92
93   /* A negative number.  */
94   my_dprintf (fileno (stdout), "%Lf %d\n", -0.03125L, 33, 44, 55);
95
96   /* Positive zero.  */
97   my_dprintf (fileno (stdout), "%Lf %d\n", 0.0L, 33, 44, 55);
98
99   /* FLAG_ZERO.  */
100   my_dprintf (fileno (stdout), "%015Lf %d\n", 1234.0L, 33, 44, 55);
101
102   /* Precision.  */
103   my_dprintf (fileno (stdout), "%.Lf %d\n", 1234.0L, 33, 44, 55);
104
105   /* Precision with no rounding.  */
106   my_dprintf (fileno (stdout), "%.2Lf %d\n", 999.95L, 33, 44, 55);
107
108   /* Precision with rounding.  */
109   my_dprintf (fileno (stdout), "%.2Lf %d\n", 999.996L, 33, 44, 55);
110
111   /* Test the support of the %F format directive.  */
112
113   /* A positive number.  */
114   my_dprintf (fileno (stdout), "%F %d\n", 12.75, 33, 44, 55);
115
116   /* A larger positive number.  */
117   my_dprintf (fileno (stdout), "%F %d\n", 1234567.0, 33, 44, 55);
118
119   /* A negative number.  */
120   my_dprintf (fileno (stdout), "%F %d\n", -0.03125, 33, 44, 55);
121
122   /* Positive zero.  */
123   my_dprintf (fileno (stdout), "%F %d\n", 0.0, 33, 44, 55);
124
125   /* FLAG_ZERO.  */
126   my_dprintf (fileno (stdout), "%015F %d\n", 1234.0, 33, 44, 55);
127
128   /* Precision.  */
129   my_dprintf (fileno (stdout), "%.F %d\n", 1234.0, 33, 44, 55);
130
131   /* Precision with no rounding.  */
132   my_dprintf (fileno (stdout), "%.2F %d\n", 999.95, 33, 44, 55);
133
134   /* Precision with rounding.  */
135   my_dprintf (fileno (stdout), "%.2F %d\n", 999.996, 33, 44, 55);
136
137   /* A positive number.  */
138   my_dprintf (fileno (stdout), "%LF %d\n", 12.75L, 33, 44, 55);
139
140   /* A larger positive number.  */
141   my_dprintf (fileno (stdout), "%LF %d\n", 1234567.0L, 33, 44, 55);
142
143   /* A negative number.  */
144   my_dprintf (fileno (stdout), "%LF %d\n", -0.03125L, 33, 44, 55);
145
146   /* Positive zero.  */
147   my_dprintf (fileno (stdout), "%LF %d\n", 0.0L, 33, 44, 55);
148
149   /* FLAG_ZERO.  */
150   my_dprintf (fileno (stdout), "%015LF %d\n", 1234.0L, 33, 44, 55);
151
152   /* Precision.  */
153   my_dprintf (fileno (stdout), "%.LF %d\n", 1234.0L, 33, 44, 55);
154
155   /* Precision with no rounding.  */
156   my_dprintf (fileno (stdout), "%.2LF %d\n", 999.95L, 33, 44, 55);
157
158   /* Precision with rounding.  */
159   my_dprintf (fileno (stdout), "%.2LF %d\n", 999.996L, 33, 44, 55);
160
161   /* Test the support of the POSIX/XSI format strings with positions.  */
162
163   my_dprintf (fileno (stdout), "%2$d %1$d\n", 33, 55);
164 }
165
166 int
167 main (int argc, char *argv[])
168 {
169   test_function (dprintf);
170   return 0;
171 }