Fix misspelled yesexpr/day/abday/mon/abmon/date_fmt fields in sc_IT
[glibc.git] / stdio-common / tstdiomisc.c
blob89009e05490afd5815da97911a377db028ee2f97
1 #include <float.h>
2 #include <math.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <wchar.h>
6 #include <libc-diag.h>
8 static int
9 t1 (void)
11 int n = -1;
12 sscanf ("abc ", "abc %n", &n);
13 printf ("t1: count=%d\n", n);
15 return n != 5;
18 static int
19 t2 (void)
21 int result = 0;
22 int n;
23 long N;
24 int retval;
25 #define SCAN(INPUT, FORMAT, VAR, EXP_RES, EXP_VAL) \
26 VAR = -1; \
27 retval = sscanf (INPUT, FORMAT, &VAR); \
28 printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \
29 INPUT, FORMAT, retval, (long int) VAR); \
30 result |= retval != EXP_RES || VAR != EXP_VAL
32 /* This function is testing corner cases of the scanf format string,
33 so they do not all conform to -Wformat's expectations. */
34 DIAG_PUSH_NEEDS_COMMENT;
35 DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
36 DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat-extra-args");
38 SCAN ("12345", "%ld", N, 1, 12345);
39 SCAN ("12345", "%llllld", N, 0, -1);
40 SCAN ("12345", "%LLLLLd", N, 0, -1);
41 SCAN ("test ", "%*s%n", n, 0, 4);
42 SCAN ("test ", "%2*s%n", n, 0, -1);
43 SCAN ("12 ", "%l2d", n, 0, -1);
44 SCAN ("12 ", "%2ld", N, 1, 12);
46 n = -1;
47 N = -1;
48 retval = sscanf ("1 1", "%d %Z", &n, &N);
49 printf ("sscanf (\"1 1\", \"%%d %%Z\", &n, &N) => %d, n = %d, N = %ld\n", \
50 retval, n, N); \
51 result |= retval != 1 || n != 1 || N != -1;
53 DIAG_POP_NEEDS_COMMENT;
55 return result;
58 static int
59 t3 (void)
61 char buf[80];
62 wchar_t wbuf[80];
63 int result = 0;
64 int retval;
66 retval = sprintf (buf, "%p", (char *) NULL);
67 result |= retval != 5 || strcmp (buf, "(nil)") != 0;
69 retval = swprintf (wbuf, sizeof (wbuf) / sizeof (wbuf[0]),
70 L"%p", (char *) NULL);
71 result |= retval != 5 || wcscmp (wbuf, L"(nil)") != 0;
73 return result;
76 volatile double qnanval;
77 volatile long double lqnanval;
78 /* A sNaN is only guaranteed to be representable in variables with static (or
79 thread-local) storage duration. */
80 static volatile double snanval = __builtin_nans ("");
81 static volatile double msnanval = -__builtin_nans ("");
82 static volatile long double lsnanval = __builtin_nansl ("");
83 static volatile long double lmsnanval = -__builtin_nansl ("");
84 volatile double infval;
85 volatile long double linfval;
88 static int
89 F (void)
91 char buf[80];
92 wchar_t wbuf[40];
93 int result = 0;
95 qnanval = NAN;
97 /* The %f and %F arguments are in fact constants, but GCC is
98 prevented from seeing this (volatile is used) so it cannot tell
99 that the output is not truncated. */
100 DIAG_PUSH_NEEDS_COMMENT;
101 #if __GNUC_PREREQ (7, 0)
102 DIAG_IGNORE_NEEDS_COMMENT (7.0, "-Wformat-truncation");
103 #endif
105 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
106 qnanval, qnanval, qnanval, qnanval,
107 qnanval, qnanval, qnanval, qnanval);
108 result |= strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0;
109 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf);
111 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
112 -qnanval, -qnanval, -qnanval, -qnanval,
113 -qnanval, -qnanval, -qnanval, -qnanval);
114 result |= strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
115 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
116 buf);
118 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
119 snanval, snanval, snanval, snanval,
120 snanval, snanval, snanval, snanval);
121 result |= strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0;
122 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf);
124 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
125 msnanval, msnanval, msnanval, msnanval,
126 msnanval, msnanval, msnanval, msnanval);
127 result |= strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
128 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
129 buf);
131 infval = DBL_MAX * DBL_MAX;
133 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
134 infval, infval, infval, infval, infval, infval, infval, infval);
135 result |= strcmp (buf, "inf INF inf INF inf INF inf INF") != 0;
136 printf ("expected \"inf INF inf INF inf INF inf INF\", got \"%s\"\n", buf);
138 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
139 -infval, -infval, -infval, -infval,
140 -infval, -infval, -infval, -infval);
141 result |= strcmp (buf, "-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
142 printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n",
143 buf);
145 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
146 qnanval, qnanval, qnanval, qnanval,
147 qnanval, qnanval, qnanval, qnanval);
148 result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
149 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
151 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
152 -qnanval, -qnanval, -qnanval, -qnanval,
153 -qnanval, -qnanval, -qnanval, -qnanval);
154 result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
155 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
156 wbuf);
158 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
159 snanval, snanval, snanval, snanval,
160 snanval, snanval, snanval, snanval);
161 result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
162 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
164 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
165 msnanval, msnanval, msnanval, msnanval,
166 msnanval, msnanval, msnanval, msnanval);
167 result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
168 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
169 wbuf);
171 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
172 infval, infval, infval, infval, infval, infval, infval, infval);
173 result |= wcscmp (wbuf, L"inf INF inf INF inf INF inf INF") != 0;
174 printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf);
176 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
177 -infval, -infval, -infval, -infval,
178 -infval, -infval, -infval, -infval);
179 result |= wcscmp (wbuf, L"-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
180 printf ("expected L\"-inf -INF -inf -INF -inf -INF -inf -INF\", got L\"%S\"\n",
181 wbuf);
183 lqnanval = NAN;
185 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
186 lqnanval, lqnanval, lqnanval, lqnanval,
187 lqnanval, lqnanval, lqnanval, lqnanval);
188 result |= strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0;
189 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf);
191 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
192 -lqnanval, -lqnanval, -lqnanval, -lqnanval,
193 -lqnanval, -lqnanval, -lqnanval, -lqnanval);
194 result |= strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
195 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
196 buf);
198 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
199 lsnanval, lsnanval, lsnanval, lsnanval,
200 lsnanval, lsnanval, lsnanval, lsnanval);
201 result |= strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0;
202 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf);
204 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
205 lmsnanval, lmsnanval, lmsnanval, lmsnanval,
206 lmsnanval, lmsnanval, lmsnanval, lmsnanval);
207 result |= strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
208 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
209 buf);
211 linfval = LDBL_MAX * LDBL_MAX;
213 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
214 linfval, linfval, linfval, linfval,
215 linfval, linfval, linfval, linfval);
216 result |= strcmp (buf, "inf INF inf INF inf INF inf INF") != 0;
217 printf ("expected \"inf INF inf INF inf INF inf INF\", got \"%s\"\n", buf);
219 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
220 -linfval, -linfval, -linfval, -linfval,
221 -linfval, -linfval, -linfval, -linfval);
222 result |= strcmp (buf, "-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
223 printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n",
224 buf);
226 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
227 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
228 lqnanval, lqnanval, lqnanval, lqnanval,
229 lqnanval, lqnanval, lqnanval, lqnanval);
230 result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
231 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
233 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
234 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
235 -lqnanval, -lqnanval, -lqnanval, -lqnanval,
236 -lqnanval, -lqnanval, -lqnanval, -lqnanval);
237 result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
238 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
239 wbuf);
241 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
242 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
243 lsnanval, lsnanval, lsnanval, lsnanval,
244 lsnanval, lsnanval, lsnanval, lsnanval);
245 result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
246 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
248 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
249 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
250 lmsnanval, lmsnanval, lmsnanval, lmsnanval,
251 lmsnanval, lmsnanval, lmsnanval, lmsnanval);
252 result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
253 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
254 wbuf);
256 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
257 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
258 linfval, linfval, linfval, linfval,
259 linfval, linfval, linfval, linfval);
260 result |= wcscmp (wbuf, L"inf INF inf INF inf INF inf INF") != 0;
261 printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf);
263 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
264 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
265 -linfval, -linfval, -linfval, -linfval,
266 -linfval, -linfval, -linfval, -linfval);
267 result |= wcscmp (wbuf, L"-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
268 printf ("expected L\"-inf -INF -inf -INF -inf -INF -inf -INF\", got L\"%S\"\n",
269 wbuf);
271 DIAG_POP_NEEDS_COMMENT;
273 return result;
277 main (int argc, char *argv[])
279 int result = 0;
281 result |= t1 ();
282 result |= t2 ();
283 result |= t3 ();
284 result |= F ();
286 result |= fflush (stdout) == EOF;
288 return result;