1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
/* Test scanf functions with C2X binary integers.
Copyright (C) 2022-2023 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
#include <support/check.h>
#include <support/xstdio.h>
#define CONCAT_(X, Y, Z) X ## Y ## Z
#define CONCAT(X, Y, Z) CONCAT_ (X, Y, Z)
#define FNX(FN1, FN2) CONCAT (FN1, FNW, FN2)
#ifndef STDX
# define STDX ""
#endif
#define INFILE OBJPFX "/tst-" STDX "scanf-binary-" STD "-in"
static int
wrap_vfscanf (FILE *fp, const CHAR *format, ...)
{
va_list ap;
va_start (ap, format);
int ret = FNX (vf, scanf) (fp, format, ap);
va_end (ap);
return ret;
}
static int
wrap_vscanf (const CHAR *format, ...)
{
va_list ap;
va_start (ap, format);
int ret = FNX (v, scanf) (format, ap);
va_end (ap);
return ret;
}
static int
wrap_vsscanf (const CHAR *s, const CHAR *format, ...)
{
va_list ap;
va_start (ap, format);
int ret = FNX (vs, scanf) (s, format, ap);
va_end (ap);
return ret;
}
static void
one_check (const CHAR *s, int expected, char expected_c)
{
int ret;
FILE *fp;
int ret_i;
long int ret_l;
long long int ret_ll;
char ret_c;
fp = xfopen (INFILE, "w");
ret = FNX (fput, s) (s, fp);
TEST_VERIFY_EXIT (0 <= ret);
xfclose (fp);
if (!TEST_C2X)
{
expected = 0;
expected_c = s[0] == L_('-') ? s[2] : s[1];
}
ret = FNX (s, scanf) (s, L_("%i %c"), &ret_i, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_i, expected);
TEST_COMPARE (ret_c, expected_c);
fp = xfopen (INFILE, "r");
ret = FNX (f, scanf) (fp, L_("%i %c"), &ret_i, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_i, expected);
TEST_COMPARE (ret_c, expected_c);
xfclose (fp);
fp = xfreopen (INFILE, "r", stdin);
ret = FNX (, scanf) (L_("%i %c"), &ret_i, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_i, expected);
TEST_COMPARE (ret_c, expected_c);
ret = wrap_vsscanf (s, L_("%i %c"), &ret_i, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_i, expected);
TEST_COMPARE (ret_c, expected_c);
fp = xfopen (INFILE, "r");
ret = wrap_vfscanf (fp, L_("%i %c"), &ret_i, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_i, expected);
TEST_COMPARE (ret_c, expected_c);
xfclose (fp);
fp = xfreopen (INFILE, "r", stdin);
ret = wrap_vscanf (L_("%i %c"), &ret_i, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_i, expected);
TEST_COMPARE (ret_c, expected_c);
ret = FNX (s, scanf) (s, L_("%li %c"), &ret_l, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_l, expected);
TEST_COMPARE (ret_c, expected_c);
fp = xfopen (INFILE, "r");
ret = FNX (f, scanf) (fp, L_("%li %c"), &ret_l, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_l, expected);
TEST_COMPARE (ret_c, expected_c);
xfclose (fp);
fp = xfreopen (INFILE, "r", stdin);
ret = FNX (, scanf) (L_("%li %c"), &ret_l, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_l, expected);
TEST_COMPARE (ret_c, expected_c);
ret = wrap_vsscanf (s, L_("%li %c"), &ret_l, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_l, expected);
TEST_COMPARE (ret_c, expected_c);
fp = xfopen (INFILE, "r");
ret = wrap_vfscanf (fp, L_("%li %c"), &ret_l, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_l, expected);
TEST_COMPARE (ret_c, expected_c);
xfclose (fp);
fp = xfreopen (INFILE, "r", stdin);
ret = wrap_vscanf (L_("%li %c"), &ret_l, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_l, expected);
TEST_COMPARE (ret_c, expected_c);
ret = FNX (s, scanf) (s, L_("%lli %c"), &ret_ll, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_ll, expected);
TEST_COMPARE (ret_c, expected_c);
fp = xfopen (INFILE, "r");
ret = FNX (f, scanf) (fp, L_("%lli %c"), &ret_ll, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_ll, expected);
TEST_COMPARE (ret_c, expected_c);
xfclose (fp);
fp = xfreopen (INFILE, "r", stdin);
ret = FNX (, scanf) (L_("%lli %c"), &ret_ll, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_ll, expected);
TEST_COMPARE (ret_c, expected_c);
ret = wrap_vsscanf (s, L_("%lli %c"), &ret_ll, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_ll, expected);
TEST_COMPARE (ret_c, expected_c);
fp = xfopen (INFILE, "r");
ret = wrap_vfscanf (fp, L_("%lli %c"), &ret_ll, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_ll, expected);
TEST_COMPARE (ret_c, expected_c);
xfclose (fp);
fp = xfreopen (INFILE, "r", stdin);
ret = wrap_vscanf (L_("%lli %c"), &ret_ll, &ret_c);
TEST_COMPARE (ret, 2);
TEST_COMPARE (ret_ll, expected);
TEST_COMPARE (ret_c, expected_c);
}
static int
do_test (void)
{
one_check (L_("0b101 x"), 5, 'x');
one_check (L_("0B101 x"), 5, 'x');
one_check (L_("-0b11111 y"), -31, 'y');
one_check (L_("-0B11111 y"), -31, 'y');
return 0;
}
#include <support/test-driver.c>
|