2 * Conformance tests for *scanf functions.
4 * Copyright 2002 Uwe Bonnes
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/test.h"
30 static int WINAPIV
vsscanf_wrapper(unsigned __int64 options
, const char *str
, size_t len
, const char *format
, ...)
34 __ms_va_start(valist
, format
);
35 ret
= __stdio_common_vsscanf(options
, str
, len
, format
, NULL
, valist
);
40 static void test_sscanf(void)
42 static const float float1
= -82.6267f
, float2
= 27.76f
;
43 char buffer
[100], buffer1
[100];
44 int result
, ret
, hour
, min
, count
;
48 float ret_float1
, ret_float2
;
52 static const unsigned int tests
[] =
55 _CRT_INTERNAL_SCANF_LEGACY_WIDE_SPECIFIERS
,
56 _CRT_INTERNAL_SCANF_LEGACY_MSVCRT_COMPATIBILITY
,
59 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
61 ret
= vsscanf_wrapper(tests
[i
], "", -1, "%d", &result
);
62 ok(ret
== EOF
, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
64 ret
= vsscanf_wrapper(tests
[i
], "000000000046F170", -1, "%p", &ptr
);
65 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
66 ok(ptr
== (void *)0x46f170, "sscanf reads %p for flags %#x\n", ptr
, tests
[i
]);
68 ret
= vsscanf_wrapper(tests
[i
], "0046F171", -1, "%p", &ptr
);
69 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
70 ok(ptr
== (void *)0x46f171, "sscanf reads %p for flags %#x\n", ptr
, tests
[i
]);
72 ret
= vsscanf_wrapper(tests
[i
], "46F172", -1, "%p", &ptr
);
73 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
74 ok(ptr
== (void *)0x46f172, "sscanf reads %p for flags %#x\n", ptr
, tests
[i
]);
76 ret
= vsscanf_wrapper(tests
[i
], "0x46F173", -1, "%p", &ptr
);
77 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
78 todo_wine
ok(ptr
== (void *)0x46f173, "sscanf reads %p for flags %#x\n", ptr
, tests
[i
]);
80 ret
= vsscanf_wrapper(tests
[i
], "-46F174", -1, "%p", &ptr
);
81 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
82 ok(ptr
== (void *)(ULONG_PTR
)-0x46f174, "sscanf reads %p for flags %#x\n", ptr
, tests
[i
]);
84 ret
= vsscanf_wrapper(tests
[i
], "+46F175", -1, "%p", &ptr
);
85 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
86 ok(ptr
== (void *)0x46f175, "sscanf reads %p for flags %#x\n", ptr
, tests
[i
]);
88 ret
= vsscanf_wrapper(tests
[i
], "1233", -1, "%p", &ptr
);
89 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
90 ok(ptr
== (void *)0x1233, "sscanf reads %p for flags %#x\n", ptr
, tests
[i
]);
92 ret
= vsscanf_wrapper(tests
[i
], "1234", -1, "%P", &ptr
);
93 todo_wine
ok(ret
== 0, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
95 ret
= vsscanf_wrapper(tests
[i
], "0x519", -1, "%x", &result
);
96 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
97 ok(result
== 0x519, "sscanf reads %#x for flags %#x\n", result
, tests
[i
]);
99 ret
= vsscanf_wrapper(tests
[i
], "0x51a", -1, "%x", &result
);
100 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
101 ok(result
== 0x51a, "sscanf reads %#x for flags %#x\n", result
, tests
[i
]);
103 ret
= vsscanf_wrapper(tests
[i
], "0x51g", -1, "%x", &result
);
104 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
105 ok(result
== 0x51, "sscanf reads %#x for flags %#x\n", result
, tests
[i
]);
108 ret
= vsscanf_wrapper(tests
[i
], "-1", -1, "%x", &result
);
109 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
110 ok(result
== -1, "sscanf reads %#x for flags %#x\n", result
, tests
[i
]);
112 ret
= vsscanf_wrapper(tests
[i
], "\"%12@", -1, "%\"%%%d%@", &result
);
113 todo_wine
ok(ret
== 0, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
115 sprintf(buffer
, "%f %f", float1
, float2
);
116 ret
= vsscanf_wrapper(tests
[i
], buffer
, -1, "%f%f", &ret_float1
, &ret_float2
);
117 ok(ret
== 2, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
118 ok(ret_float1
== float1
, "got wrong float %.8e for flags %#x\n", ret_float1
, tests
[i
]);
119 ok(ret_float2
== float2
, "got wrong float %.8e for flags %#x\n", ret_float2
, tests
[i
]);
121 sprintf(buffer
, "%lf", 32.715);
122 ret
= vsscanf_wrapper(tests
[i
], buffer
, -1, "%lf", &double_res
);
123 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
124 ok(double_res
== 32.715, "got wrong double %.16e for flags %#x\n", double_res
, tests
[i
]);
125 ret
= vsscanf_wrapper(tests
[i
], buffer
, -1, "%Lf", &double_res
);
126 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
127 ok(double_res
== 32.715, "got wrong double %.16e for flags %#x\n", double_res
, tests
[i
]);
129 ret
= vsscanf_wrapper(tests
[i
], "1.1e-30", -1, "%lf", &double_res
);
130 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
131 ok(double_res
== 1.1e-30, "got wrong double %.16e for flags %#x\n", double_res
, tests
[i
]);
133 ret
= vsscanf_wrapper(tests
[i
], " Waverly", -1, "%*c%[^\n]", buffer
);
134 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
135 ok(!strcmp(buffer
, " Waverly"), "got string '%s' for flags %#x\n", buffer
, tests
[i
]);
137 ret
= vsscanf_wrapper(tests
[i
], "abcefgdh", -1, "%*[a-cg-e]%c", &buffer
[0]);
138 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
139 ok(buffer
[0] == 'd', "got char '%c' for flags %#x\n", buffer
[0], tests
[i
]);
141 ret
= vsscanf_wrapper(tests
[i
], "abcefgdh", -1, "%*[a-cd-dg-e]%c", &buffer
[0]);
142 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
143 ok(buffer
[0] == 'h', "got char '%c' for flags %#x\n", buffer
[0], tests
[i
]);
145 strcpy(buffer
, "foo");
146 strcpy(buffer1
, "bar");
147 ret
= vsscanf_wrapper(tests
[i
], "a", -1, "%s%s", buffer
, buffer1
);
148 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
149 ok(!strcmp(buffer
, "a"), "got string '%s' for flags %#x\n", buffer
, tests
[i
]);
150 ok(!strcmp(buffer1
, "bar"), "got string '%s' for flags %#x\n", buffer1
, tests
[i
]);
152 ret
= vsscanf_wrapper(tests
[i
], "21:59:20", -1, "%d%n", &result
, &count
);
153 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
154 ok(result
== 21, "got wrong number %d for flags %#x\n", result
, tests
[i
]);
155 ok(count
== 2, "got wrong count %d for flags %#x\n", count
, tests
[i
]);
157 ret
= vsscanf_wrapper(tests
[i
], ":59:20", -1, "%*c%n", &count
);
158 ok(ret
== 0, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
159 ok(count
== 1, "got wrong count %d for flags %#x\n", count
, tests
[i
]);
162 ret
= vsscanf_wrapper(tests
[i
], "12345678", -1, "%hd", &result
);
163 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
164 ok(result
== 0xdead614e, "got wrong number %#x for flags %#x\n", result
, tests
[i
]);
167 ret
= vsscanf_wrapper(tests
[i
], "12345678", -1, "%hhd", &result
);
168 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
169 ok(result
== 0xdeadbe4e, "got wrong number %#x for flags %#x\n", result
, tests
[i
]);
171 ret
= vsscanf_wrapper(tests
[i
], "12345678901234", -1, "%lld", &result64
);
172 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
173 ok(result64
== 12345678901234, "got wrong number 0x%s for flags %#x\n",
174 wine_dbgstr_longlong(result64
), tests
[i
]);
176 ret
= vsscanf_wrapper(tests
[i
], "123", -1, "%i", &result
);
177 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
178 ok(result
== 123, "got wrong number %d for flags %#x\n", result
, tests
[i
]);
180 ret
= vsscanf_wrapper(tests
[i
], "-1", -1, "%i", &result
);
181 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
182 ok(result
== -1, "got wrong number %d for flags %#x\n", result
, tests
[i
]);
184 ret
= vsscanf_wrapper(tests
[i
], "123", -1, "%d", &result
);
185 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
186 ok(result
== 123, "got wrong number %d for flags %#x\n", result
, tests
[i
]);
188 ret
= vsscanf_wrapper(tests
[i
], "-1", -1, "%d", &result
);
189 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
190 ok(result
== -1, "got wrong number %d for flags %#x\n", result
, tests
[i
]);
192 ret
= vsscanf_wrapper(tests
[i
], "017", -1, "%i", &result
);
193 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
194 ok(result
== 15, "got wrong number %d for flags %#x\n", result
, tests
[i
]);
196 ret
= vsscanf_wrapper(tests
[i
], "0x17", -1, "%i", &result
);
197 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
198 ok(result
== 23, "got wrong number %d for flags %#x\n", result
, tests
[i
]);
200 ret
= vsscanf_wrapper(tests
[i
], "-1", -1, "%o", &result
);
201 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
202 ok(result
== -1, "got wrong number %d for flags %#x\n", result
, tests
[i
]);
205 ret
= vsscanf_wrapper(tests
[i
], "-1", -1, "%u", &result
);
206 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
207 ok(result
== -1, "got wrong number %d for flags %#x\n", result
, tests
[i
]);
210 ret
= vsscanf_wrapper(tests
[i
], "a", -1, "%c", &c
);
211 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
212 ok(c
== 'a', "got wrong char '%c' for flags %#x\n", c
, tests
[i
]);
215 ret
= vsscanf_wrapper(tests
[i
], " a", -1, "%c", &c
);
216 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
217 ok(c
== ' ', "got wrong char '%c' for flags %#x\n", c
, tests
[i
]);
220 ret
= vsscanf_wrapper(tests
[i
], "18:59", -1, "%d:%d%c", &hour
, &min
, &c
);
221 ok(ret
== 2, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
222 ok(hour
== 18, "got wrong char '%c' for flags %#x\n", hour
, tests
[i
]);
223 ok(min
== 59, "got wrong char '%c' for flags %#x\n", min
, tests
[i
]);
224 ok(c
== 0x55, "got wrong char '%c' for flags %#x\n", c
, tests
[i
]);
226 strcpy(buffer
, "foo");
227 strcpy(buffer1
, "bar");
228 ret
= vsscanf_wrapper(tests
[i
], "abc def", -1, "%s %n%s", buffer
, &count
, buffer1
);
229 ok(ret
== 2, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
230 ok(!strcmp(buffer
, "abc"), "got wrong string '%s' for flags %#x\n", buffer
, tests
[i
]);
231 ok(count
== 6, "got wrong count %d for flags %#x\n", count
, tests
[i
]);
232 ok(!strcmp(buffer1
, "def"), "got wrong string '%s' for flags %#x\n", buffer1
, tests
[i
]);
234 ret
= vsscanf_wrapper(tests
[i
], "3:45", -1, "%d:%d%n", &hour
, &min
, &count
);
235 ok(ret
== 2, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
236 ok(hour
== 3, "got wrong char '%c' for flags %#x\n", hour
, tests
[i
]);
237 ok(min
== 45, "got wrong char '%c' for flags %#x\n", min
, tests
[i
]);
238 ok(count
== 4, "got wrong count %d for flags %#x\n", count
, tests
[i
]);
240 strcpy(buffer
, "foo");
241 strcpy(buffer1
, "bar");
242 ret
= vsscanf_wrapper(tests
[i
], "test=value\xda", -1, "%[^=] = %[^;]", buffer
, buffer1
);
243 ok(ret
== 2, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
244 ok(!strcmp(buffer
, "test"), "got wrong string '%s' for flags %#x\n", buffer
, tests
[i
]);
245 ok(!strcmp(buffer1
, "value\xda"), "got wrong string '%s' for flags %#x\n", buffer1
, tests
[i
]);
247 ret
= vsscanf_wrapper(tests
[i
], "0.1", 3, "%lf%n", &double_res
, &count
);
248 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
249 ok(double_res
== 0.1, "got wrong double %.16e for flags %#x\n", double_res
, tests
[i
]);
250 ok(count
== 3, "got wrong count %d for flags %#x\n", count
, tests
[i
]);
252 ret
= vsscanf_wrapper(tests
[i
], "a", -1, "%lf%n", &double_res
, &count
);
253 ok(ret
== 0, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
255 ret
= vsscanf_wrapper(tests
[i
], "aa", -1, "%c%lf%n", &c
, &double_res
, &count
);
256 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
258 ret
= vsscanf_wrapper(tests
[i
], "a0e", -1, "%c%lf%n", &c
, &double_res
, &count
);
259 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
261 ret
= vsscanf_wrapper(tests
[i
], "0.", -1, "%lf%n", &double_res
, &count
);
262 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
263 ok(double_res
== 0, "got wrong double %.16e for flags %#x\n", double_res
, tests
[i
]);
264 ok(count
== 2, "got wrong count %d for flags %#x\n", count
, tests
[i
]);
266 ret
= vsscanf_wrapper(tests
[i
], "0.", 2, "%lf%n", &double_res
, &count
);
267 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
268 ok(double_res
== 0, "got wrong double %.16e for flags %#x\n", double_res
, tests
[i
]);
269 ok(count
== 2, "got wrong count %d for flags %#x\n", count
, tests
[i
]);
271 ret
= vsscanf_wrapper(tests
[i
], "1e", -1, "%lf%n", &double_res
, &count
);
272 ok(ret
== -1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
274 ret
= vsscanf_wrapper(tests
[i
], "1e ", 2, "%lf%n", &double_res
, &count
);
275 ok(ret
== -1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
277 ret
= vsscanf_wrapper(tests
[i
], "1e+", -1, "%lf%n", &double_res
, &count
);
278 ok(ret
== -1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
280 ret
= vsscanf_wrapper(tests
[i
], "inf", -1, "%lf%n", &double_res
, &count
);
281 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
282 ok(double_res
== INFINITY
, "got wrong double %.16e for flags %#x\n", double_res
, tests
[i
]);
283 ok(count
== 3, "got wrong count %d for flags %#x\n", count
, tests
[i
]);
285 ret
= vsscanf_wrapper(tests
[i
], "infa", -1, "%lf%n", &double_res
, &count
);
286 ok(ret
== 1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);
287 ok(double_res
== INFINITY
, "got wrong double %.16e for flags %#x\n", double_res
, tests
[i
]);
288 ok(count
== 3, "got wrong count %d for flags %#x\n", count
, tests
[i
]);
290 ret
= vsscanf_wrapper(tests
[i
], "infi", -1, "%lf%n", &double_res
, &count
);
291 ok(ret
== -1, "sscanf returned %d for flags %#x\n", ret
, tests
[i
]);