Accept make versions 4.0 and greater
[glibc.git] / stdio-common / tstdiomisc.c
blob5a25ecc9f09e443f3f6e06ddee7132e44d1091bf
1 #include <float.h>
2 #include <math.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <wchar.h>
7 static int
8 t1 (void)
10 int n = -1;
11 sscanf ("abc ", "abc %n", &n);
12 printf ("t1: count=%d\n", n);
14 return n != 5;
17 static int
18 t2 (void)
20 int result = 0;
21 int n;
22 long N;
23 int retval;
24 #define SCAN(INPUT, FORMAT, VAR, EXP_RES, EXP_VAL) \
25 VAR = -1; \
26 retval = sscanf (INPUT, FORMAT, &VAR); \
27 printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \
28 INPUT, FORMAT, retval, (long int) VAR); \
29 result |= retval != EXP_RES || VAR != EXP_VAL
31 SCAN ("12345", "%ld", N, 1, 12345);
32 SCAN ("12345", "%llllld", N, 0, -1);
33 SCAN ("12345", "%LLLLLd", N, 0, -1);
34 SCAN ("test ", "%*s%n", n, 0, 4);
35 SCAN ("test ", "%2*s%n", n, 0, -1);
36 SCAN ("12 ", "%l2d", n, 0, -1);
37 SCAN ("12 ", "%2ld", N, 1, 12);
39 n = -1;
40 N = -1;
41 retval = sscanf ("1 1", "%d %Z", &n, &N);
42 printf ("sscanf (\"1 1\", \"%%d %%Z\", &n, &N) => %d, n = %d, N = %ld\n", \
43 retval, n, N); \
44 result |= retval != 1 || n != 1 || N != -1;
46 return result;
49 volatile double qnanval;
50 volatile long double lqnanval;
51 /* A sNaN is only guaranteed to be representable in variables with static (or
52 thread-local) storage duration. */
53 static volatile double snanval = __builtin_nans ("");
54 static volatile double msnanval = -__builtin_nans ("");
55 static volatile long double lsnanval = __builtin_nansl ("");
56 static volatile long double lmsnanval = -__builtin_nansl ("");
57 volatile double infval;
58 volatile long double linfval;
61 static int
62 F (void)
64 char buf[80];
65 wchar_t wbuf[40];
66 int result = 0;
68 qnanval = NAN;
70 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
71 qnanval, qnanval, qnanval, qnanval,
72 qnanval, qnanval, qnanval, qnanval);
73 result |= strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0;
74 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf);
76 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
77 -qnanval, -qnanval, -qnanval, -qnanval,
78 -qnanval, -qnanval, -qnanval, -qnanval);
79 result |= strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
80 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
81 buf);
83 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
84 snanval, snanval, snanval, snanval,
85 snanval, snanval, snanval, snanval);
86 result |= strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0;
87 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf);
89 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
90 msnanval, msnanval, msnanval, msnanval,
91 msnanval, msnanval, msnanval, msnanval);
92 result |= strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
93 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
94 buf);
96 infval = DBL_MAX * DBL_MAX;
98 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
99 infval, infval, infval, infval, infval, infval, infval, infval);
100 result |= strcmp (buf, "inf INF inf INF inf INF inf INF") != 0;
101 printf ("expected \"inf INF inf INF inf INF inf INF\", got \"%s\"\n", buf);
103 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
104 -infval, -infval, -infval, -infval,
105 -infval, -infval, -infval, -infval);
106 result |= strcmp (buf, "-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
107 printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n",
108 buf);
110 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
111 qnanval, qnanval, qnanval, qnanval,
112 qnanval, qnanval, qnanval, qnanval);
113 result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
114 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
116 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
117 -qnanval, -qnanval, -qnanval, -qnanval,
118 -qnanval, -qnanval, -qnanval, -qnanval);
119 result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
120 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
121 wbuf);
123 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
124 snanval, snanval, snanval, snanval,
125 snanval, snanval, snanval, snanval);
126 result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
127 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
129 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
130 msnanval, msnanval, msnanval, msnanval,
131 msnanval, msnanval, msnanval, msnanval);
132 result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
133 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
134 wbuf);
136 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
137 infval, infval, infval, infval, infval, infval, infval, infval);
138 result |= wcscmp (wbuf, L"inf INF inf INF inf INF inf INF") != 0;
139 printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf);
141 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
142 -infval, -infval, -infval, -infval,
143 -infval, -infval, -infval, -infval);
144 result |= wcscmp (wbuf, L"-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
145 printf ("expected L\"-inf -INF -inf -INF -inf -INF -inf -INF\", got L\"%S\"\n",
146 wbuf);
148 lqnanval = NAN;
150 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
151 lqnanval, lqnanval, lqnanval, lqnanval,
152 lqnanval, lqnanval, lqnanval, lqnanval);
153 result |= strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0;
154 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf);
156 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
157 -lqnanval, -lqnanval, -lqnanval, -lqnanval,
158 -lqnanval, -lqnanval, -lqnanval, -lqnanval);
159 result |= strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
160 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
161 buf);
163 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
164 lsnanval, lsnanval, lsnanval, lsnanval,
165 lsnanval, lsnanval, lsnanval, lsnanval);
166 result |= strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0;
167 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf);
169 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
170 lmsnanval, lmsnanval, lmsnanval, lmsnanval,
171 lmsnanval, lmsnanval, lmsnanval, lmsnanval);
172 result |= strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
173 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
174 buf);
176 linfval = LDBL_MAX * LDBL_MAX;
178 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
179 linfval, linfval, linfval, linfval,
180 linfval, linfval, linfval, linfval);
181 result |= strcmp (buf, "inf INF inf INF inf INF inf INF") != 0;
182 printf ("expected \"inf INF inf INF inf INF inf INF\", got \"%s\"\n", buf);
184 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
185 -linfval, -linfval, -linfval, -linfval,
186 -linfval, -linfval, -linfval, -linfval);
187 result |= strcmp (buf, "-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
188 printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n",
189 buf);
191 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
192 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
193 lqnanval, lqnanval, lqnanval, lqnanval,
194 lqnanval, lqnanval, lqnanval, lqnanval);
195 result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
196 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
198 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
199 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
200 -lqnanval, -lqnanval, -lqnanval, -lqnanval,
201 -lqnanval, -lqnanval, -lqnanval, -lqnanval);
202 result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
203 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
204 wbuf);
206 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
207 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
208 lsnanval, lsnanval, lsnanval, lsnanval,
209 lsnanval, lsnanval, lsnanval, lsnanval);
210 result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
211 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
213 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
214 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
215 lmsnanval, lmsnanval, lmsnanval, lmsnanval,
216 lmsnanval, lmsnanval, lmsnanval, lmsnanval);
217 result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
218 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
219 wbuf);
221 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
222 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
223 linfval, linfval, linfval, linfval,
224 linfval, linfval, linfval, linfval);
225 result |= wcscmp (wbuf, L"inf INF inf INF inf INF inf INF") != 0;
226 printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf);
228 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
229 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
230 -linfval, -linfval, -linfval, -linfval,
231 -linfval, -linfval, -linfval, -linfval);
232 result |= wcscmp (wbuf, L"-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
233 printf ("expected L\"-inf -INF -inf -INF -inf -INF -inf -INF\", got L\"%S\"\n",
234 wbuf);
236 return result;
240 main (int argc, char *argv[])
242 int result = 0;
244 result |= t1 ();
245 result |= t2 ();
246 result |= F ();
248 result |= fflush (stdout) == EOF;
250 return result;