usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-fprintf-posix.h
blobd36305b14569c59c8f83f1bc7a28d58832759903
1 /* Test of POSIX compatible vsprintf() and sprintf() functions.
2 Copyright (C) 2007-2024 Free Software Foundation, Inc.
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
19 #include "infinity.h"
21 static void
22 test_function (int (*my_fprintf) (FILE *, const char *, ...))
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. */
27 /* Test support of size specifiers as in C99. */
29 my_fprintf (stdout, "%ju %d\n", (uintmax_t) 12345671, 33, 44, 55);
31 my_fprintf (stdout, "%zu %d\n", (size_t) 12345672, 33, 44, 55);
33 my_fprintf (stdout, "%tu %d\n", (ptrdiff_t) 12345673, 33, 44, 55);
35 /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
36 output of floating-point numbers. */
38 /* Positive zero. */
39 my_fprintf (stdout, "%a %d\n", 0.0, 33, 44, 55);
41 /* Positive infinity. */
42 my_fprintf (stdout, "%a %d\n", Infinityd (), 33, 44, 55);
44 /* Negative infinity. */
45 my_fprintf (stdout, "%a %d\n", - Infinityd (), 33, 44, 55);
47 /* FLAG_ZERO with infinite number. */
48 my_fprintf (stdout, "%010a %d\n", Infinityd (), 33, 44, 55);
50 /* Test the support of the %f format directive. */
52 /* A positive number. */
53 my_fprintf (stdout, "%f %d\n", 12.75, 33, 44, 55);
55 /* A larger positive number. */
56 my_fprintf (stdout, "%f %d\n", 1234567.0, 33, 44, 55);
58 /* A negative number. */
59 my_fprintf (stdout, "%f %d\n", -0.03125, 33, 44, 55);
61 /* Positive zero. */
62 my_fprintf (stdout, "%f %d\n", 0.0, 33, 44, 55);
64 /* FLAG_ZERO. */
65 my_fprintf (stdout, "%015f %d\n", 1234.0, 33, 44, 55);
67 /* Precision. */
68 my_fprintf (stdout, "%.f %d\n", 1234.0, 33, 44, 55);
70 /* Precision with no rounding. */
71 my_fprintf (stdout, "%.2f %d\n", 999.95, 33, 44, 55);
73 /* Precision with rounding. */
74 my_fprintf (stdout, "%.2f %d\n", 999.996, 33, 44, 55);
76 /* A positive number. */
77 my_fprintf (stdout, "%Lf %d\n", 12.75L, 33, 44, 55);
79 /* A larger positive number. */
80 my_fprintf (stdout, "%Lf %d\n", 1234567.0L, 33, 44, 55);
82 /* A negative number. */
83 my_fprintf (stdout, "%Lf %d\n", -0.03125L, 33, 44, 55);
85 /* Positive zero. */
86 my_fprintf (stdout, "%Lf %d\n", 0.0L, 33, 44, 55);
88 /* FLAG_ZERO. */
89 my_fprintf (stdout, "%015Lf %d\n", 1234.0L, 33, 44, 55);
91 /* Precision. */
92 my_fprintf (stdout, "%.Lf %d\n", 1234.0L, 33, 44, 55);
94 /* Precision with no rounding. */
95 my_fprintf (stdout, "%.2Lf %d\n", 999.95L, 33, 44, 55);
97 /* Precision with rounding. */
98 my_fprintf (stdout, "%.2Lf %d\n", 999.996L, 33, 44, 55);
100 /* Test the support of the %F format directive. */
102 /* A positive number. */
103 my_fprintf (stdout, "%F %d\n", 12.75, 33, 44, 55);
105 /* A larger positive number. */
106 my_fprintf (stdout, "%F %d\n", 1234567.0, 33, 44, 55);
108 /* A negative number. */
109 my_fprintf (stdout, "%F %d\n", -0.03125, 33, 44, 55);
111 /* Positive zero. */
112 my_fprintf (stdout, "%F %d\n", 0.0, 33, 44, 55);
114 /* FLAG_ZERO. */
115 my_fprintf (stdout, "%015F %d\n", 1234.0, 33, 44, 55);
117 /* Precision. */
118 my_fprintf (stdout, "%.F %d\n", 1234.0, 33, 44, 55);
120 /* Precision with no rounding. */
121 my_fprintf (stdout, "%.2F %d\n", 999.95, 33, 44, 55);
123 /* Precision with rounding. */
124 my_fprintf (stdout, "%.2F %d\n", 999.996, 33, 44, 55);
126 /* A positive number. */
127 my_fprintf (stdout, "%LF %d\n", 12.75L, 33, 44, 55);
129 /* A larger positive number. */
130 my_fprintf (stdout, "%LF %d\n", 1234567.0L, 33, 44, 55);
132 /* A negative number. */
133 my_fprintf (stdout, "%LF %d\n", -0.03125L, 33, 44, 55);
135 /* Positive zero. */
136 my_fprintf (stdout, "%LF %d\n", 0.0L, 33, 44, 55);
138 /* FLAG_ZERO. */
139 my_fprintf (stdout, "%015LF %d\n", 1234.0L, 33, 44, 55);
141 /* Precision. */
142 my_fprintf (stdout, "%.LF %d\n", 1234.0L, 33, 44, 55);
144 /* Precision with no rounding. */
145 my_fprintf (stdout, "%.2LF %d\n", 999.95L, 33, 44, 55);
147 /* Precision with rounding. */
148 my_fprintf (stdout, "%.2LF %d\n", 999.996L, 33, 44, 55);
150 /* Test the support of the POSIX/XSI format strings with positions. */
152 my_fprintf (stdout, "%2$d %1$d\n", 33, 55);