Fix missing backslash in last change.
[glibc.git] / stdio-common / tstdiomisc.c
blob452a21f9cb5bc3362ef271aff575b37b3f4ae59a
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 static int
50 F (void)
52 char buf[20];
53 wchar_t wbuf[10];
54 int result;
56 snprintf (buf, sizeof buf, "%f %F", DBL_MAX * DBL_MAX - DBL_MAX * DBL_MAX,
57 DBL_MAX * DBL_MAX - DBL_MAX * DBL_MAX);
58 result = strcmp (buf, "nan NAN") != 0;
59 printf ("expected \"nan NAN\", got \"%s\"\n", buf);
61 snprintf (buf, sizeof buf, "%f %F", DBL_MAX * DBL_MAX, DBL_MAX * DBL_MAX);
62 result |= strcmp (buf, "inf INF") != 0;
63 printf ("expected \"inf INF\", got \"%s\"\n", buf);
65 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%f %F",
66 DBL_MAX * DBL_MAX - DBL_MAX * DBL_MAX,
67 DBL_MAX * DBL_MAX - DBL_MAX * DBL_MAX);
68 result |= wcscmp (wbuf, L"nan NAN") != 0;
69 printf ("expected L\"nan NAN\", got L\"%S\"\n", wbuf);
71 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%f %F",
72 DBL_MAX * DBL_MAX, DBL_MAX * DBL_MAX);
73 result |= wcscmp (wbuf, L"inf INF") != 0;
74 printf ("expected L\"inf INF\", got L\"%S\"\n", wbuf);
76 return result;
79 int
80 main (int argc, char *argv[])
82 int result = 0;
84 result |= t1 ();
85 result |= t2 ();
86 result |= F ();
88 result |= fflush (stdout) == EOF;
90 return result;