msvcp90: Set state at end of istream<>::ignore.
[wine/testsucceed.git] / dlls / msvcp90 / tests / ios.c
blobb85662f7120abd3eab2ea3ff6993b72a0bb7370d
1 /*
2 * Copyright 2010 Piotr Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdio.h>
20 #include <locale.h>
21 #include <sys/stat.h>
23 #include <windef.h>
24 #include <winbase.h>
25 #include <share.h>
26 #include "wine/test.h"
28 static void* (__cdecl *p_set_invalid_parameter_handler)(void*);
29 static void (__cdecl *p_free)(void*);
31 #undef __thiscall
32 #ifdef __i386__
33 #define __thiscall __stdcall
34 #else
35 #define __thiscall __cdecl
36 #endif
38 typedef unsigned char MSVCP_bool;
39 typedef SIZE_T MSVCP_size_t;
40 typedef SSIZE_T streamoff;
41 typedef SSIZE_T streamsize;
43 typedef void (*vtable_ptr)(void);
45 /* class mutex */
46 typedef struct {
47 void *mutex;
48 } mutex;
50 /* class locale */
51 typedef struct
53 struct _locale__Locimp *ptr;
54 } locale;
56 /* class locale::facet */
57 typedef struct {
58 const vtable_ptr *vtable;
59 MSVCP_size_t refs;
60 } locale_facet;
62 /* class codecvt_base */
63 typedef struct {
64 locale_facet facet;
65 } codecvt_base;
67 /* class codecvt<char> */
68 typedef struct {
69 codecvt_base base;
70 } codecvt_char;
72 typedef enum {
73 FMTFLAG_skipws = 0x0001,
74 FMTFLAG_unitbuf = 0x0002,
75 FMTFLAG_uppercase = 0x0004,
76 FMTFLAG_showbase = 0x0008,
77 FMTFLAG_showpoint = 0x0010,
78 FMTFLAG_showpos = 0x0020,
79 FMTFLAG_left = 0x0040,
80 FMTFLAG_right = 0x0080,
81 FMTFLAG_internal = 0x0100,
82 FMTFLAG_dec = 0x0200,
83 FMTFLAG_oct = 0x0400,
84 FMTFLAG_hex = 0x0800,
85 FMTFLAG_scientific = 0x1000,
86 FMTFLAG_fixed = 0x2000,
87 FMTFLAG_hexfloat = 0x3000,
88 FMTFLAG_boolalpha = 0x4000,
89 FMTFLAG_stdio = 0x8000,
90 FMTFLAG_adjustfield = FMTFLAG_left|FMTFLAG_right|FMTFLAG_internal,
91 FMTFLAG_basefield = FMTFLAG_dec|FMTFLAG_oct|FMTFLAG_hex,
92 FMTFLAG_floatfield = FMTFLAG_scientific|FMTFLAG_fixed,
93 FMTFLAG_mask = 0xffff
94 } IOSB_fmtflags;
96 typedef enum {
97 OPENMODE_in = 0x01,
98 OPENMODE_out = 0x02,
99 OPENMODE_ate = 0x04,
100 OPENMODE_app = 0x08,
101 OPENMODE_trunc = 0x10,
102 OPENMODE__Nocreate = 0x40,
103 OPENMODE__Noreplace = 0x80,
104 OPENMODE_binary = 0x20,
105 OPENMODE_mask = 0xff
106 } IOSB_openmode;
108 typedef enum {
109 SEEKDIR_beg = 0x0,
110 SEEKDIR_cur = 0x1,
111 SEEKDIR_end = 0x2,
112 SEEKDIR_mask = 0x3
113 } IOSB_seekdir;
115 typedef enum {
116 IOSTATE_goodbit = 0x00,
117 IOSTATE_eofbit = 0x01,
118 IOSTATE_failbit = 0x02,
119 IOSTATE_badbit = 0x04,
120 IOSTATE__Hardfail = 0x10,
121 IOSTATE_mask = 0x17
122 } IOSB_iostate;
124 typedef struct _iosarray {
125 struct _iosarray *next;
126 int index;
127 int long_val;
128 void *ptr_val;
129 } IOS_BASE_iosarray;
131 typedef enum {
132 EVENT_erase_event,
133 EVENT_imbue_event,
134 EVENT_copyfmt_event
135 } IOS_BASE_event;
137 struct _ios_base;
138 typedef void (CDECL *IOS_BASE_event_callback)(IOS_BASE_event, struct _ios_base*, int);
139 typedef struct _fnarray {
140 struct _fnarray *next;
141 int index;
142 IOS_BASE_event_callback event_handler;
143 } IOS_BASE_fnarray;
145 /* class ios_base */
146 typedef struct _ios_base {
147 const vtable_ptr *vtable;
148 MSVCP_size_t stdstr;
149 IOSB_iostate state;
150 IOSB_iostate except;
151 IOSB_fmtflags fmtfl;
152 streamsize prec;
153 streamsize wide;
154 IOS_BASE_iosarray *arr;
155 IOS_BASE_fnarray *calls;
156 locale *loc;
157 } ios_base;
159 /* class basic_streambuf<char> */
160 typedef struct {
161 const vtable_ptr *vtable;
162 mutex lock;
163 char *rbuf;
164 char *wbuf;
165 char **prbuf;
166 char **pwbuf;
167 char *rpos;
168 char *wpos;
169 char **prpos;
170 char **pwpos;
171 int rsize;
172 int wsize;
173 int *prsize;
174 int *pwsize;
175 locale *loc;
176 } basic_streambuf_char;
178 /* class basic_streambuf<wchar> */
179 typedef struct {
180 const vtable_ptr *vtable;
181 mutex lock;
182 wchar_t *rbuf;
183 wchar_t *wbuf;
184 wchar_t **prbuf;
185 wchar_t **pwbuf;
186 wchar_t *rpos;
187 wchar_t *wpos;
188 wchar_t **prpos;
189 wchar_t **pwpos;
190 int rsize;
191 int wsize;
192 int *prsize;
193 int *pwsize;
194 locale *loc;
195 } basic_streambuf_wchar;
197 typedef struct {
198 basic_streambuf_char base;
199 char *seekhigh;
200 int state;
201 char allocator; /* empty struct */
202 } basic_stringbuf_char;
204 typedef struct {
205 basic_streambuf_wchar base;
206 wchar_t *seekhigh;
207 int state;
208 char allocator; /* empty struct */
209 } basic_stringbuf_wchar;
211 typedef struct {
212 ios_base base;
213 basic_streambuf_char *strbuf;
214 struct _basic_ostream_char *stream;
215 char fillch;
216 } basic_ios_char;
218 typedef struct {
219 ios_base base;
220 basic_streambuf_wchar *strbuf;
221 struct _basic_ostream_wchar *stream;
222 wchar_t fillch;
223 } basic_ios_wchar;
225 typedef struct _basic_ostream_char {
226 const int *vbtable;
227 /* virtual inheritance
228 * basic_ios_char basic_ios;
230 } basic_ostream_char;
232 typedef struct _basic_ostream_wchar {
233 const int *vbtable;
234 /* virtual inheritance
235 * basic_ios_wchar basic_ios;
237 } basic_ostream_wchar;
239 typedef struct {
240 const int *vbtable;
241 streamsize count;
242 /* virtual inheritance
243 * basic_ios_char basic_ios;
245 } basic_istream_char;
247 typedef struct {
248 const int *vbtable;
249 streamsize count;
250 /* virtual inheritance
251 * basic_ios_wchar basic_ios;
253 } basic_istream_wchar;
255 typedef struct {
256 basic_istream_char base1;
257 basic_ostream_char base2;
258 /* virtual inheritance
259 * basic_ios_char basic_ios;
261 } basic_iostream_char;
263 typedef struct {
264 basic_istream_wchar base1;
265 basic_ostream_wchar base2;
266 /* virtual inheritance
267 * basic_ios_wchar basic_ios;
269 } basic_iostream_wchar;
271 typedef struct {
272 basic_ostream_char base;
273 basic_stringbuf_char strbuf;
274 /* virtual inheritance
275 * basic_ios_char basic_ios;
277 } basic_ostringstream_char;
279 typedef struct {
280 basic_ostream_wchar base;
281 basic_stringbuf_wchar strbuf;
282 /* virtual inheritance
283 * basic_ios_wchar basic_ios;
285 } basic_ostringstream_wchar;
287 typedef struct {
288 basic_istream_char base;
289 basic_stringbuf_char strbuf;
290 /* virtual inheritance
291 * basic_ios_char basic_ios;
293 } basic_istringstream_char;
295 typedef struct {
296 basic_istream_wchar base;
297 basic_stringbuf_wchar strbuf;
298 /* virtual inheritance
299 * basic_ios_wchar basic_ios;
301 } basic_istringstream_wchar;
303 typedef struct {
304 basic_iostream_char base;
305 basic_stringbuf_char strbuf;
306 /* virtual inheritance */
307 basic_ios_char basic_ios; /* here to reserve correct stack size */
308 } basic_stringstream_char;
310 typedef struct {
311 basic_iostream_wchar base;
312 basic_stringbuf_wchar strbuf;
313 /* virtual inheritance */
314 basic_ios_wchar basic_ios; /* here to reserve correct stack size */
315 } basic_stringstream_wchar;
317 /* basic_string<char, char_traits<char>, allocator<char>> */
318 #define BUF_SIZE_CHAR 16
319 typedef struct _basic_string_char
321 void *allocator;
322 union {
323 char buf[BUF_SIZE_CHAR];
324 char *ptr;
325 } data;
326 size_t size;
327 size_t res;
328 } basic_string_char;
330 #define BUF_SIZE_WCHAR 8
331 typedef struct
333 void *allocator;
334 union {
335 wchar_t buf[BUF_SIZE_WCHAR];
336 wchar_t *ptr;
337 } data;
338 MSVCP_size_t size;
339 MSVCP_size_t res;
340 } basic_string_wchar;
342 /* stringstream */
343 static basic_stringstream_char* (*__thiscall p_basic_stringstream_char_ctor)(basic_stringstream_char*, MSVCP_bool);
344 static basic_stringstream_char* (*__thiscall p_basic_stringstream_char_ctor_str)(basic_stringstream_char*, const basic_string_char*, int, MSVCP_bool);
345 static basic_string_char* (*__thiscall p_basic_stringstream_char_str_get)(const basic_stringstream_char*, basic_string_char*);
346 static void (*__thiscall p_basic_stringstream_char_vbase_dtor)(basic_stringstream_char*);
348 static basic_stringstream_wchar* (*__thiscall p_basic_stringstream_wchar_ctor)(basic_stringstream_wchar*, MSVCP_bool);
349 static basic_stringstream_wchar* (*__thiscall p_basic_stringstream_wchar_ctor_str)(basic_stringstream_wchar*, const basic_string_wchar*, int, MSVCP_bool);
350 static basic_string_wchar* (*__thiscall p_basic_stringstream_wchar_str_get)(const basic_stringstream_wchar*, basic_string_wchar*);
351 static void (*__thiscall p_basic_stringstream_wchar_vbase_dtor)(basic_stringstream_wchar*);
353 /* istream */
354 static basic_istream_char* (*__thiscall p_basic_istream_char_read_uint64)(basic_istream_char*, unsigned __int64*);
355 static basic_istream_char* (*__thiscall p_basic_istream_char_read_double)(basic_istream_char*, double*);
356 static int (*__thiscall p_basic_istream_char_get)(basic_istream_char*);
357 static MSVCP_bool (*__thiscall p_basic_istream_char_ipfx)(basic_istream_char*, MSVCP_bool);
358 static basic_istream_char* (*__thiscall p_basic_istream_char_ignore)(basic_istream_char*, streamsize, int);
360 static basic_istream_wchar* (*__thiscall p_basic_istream_wchar_read_uint64)(basic_istream_wchar*, unsigned __int64*);
361 static basic_istream_wchar* (*__thiscall p_basic_istream_wchar_read_double)(basic_istream_wchar*, double *);
362 static int (*__thiscall p_basic_istream_wchar_get)(basic_istream_wchar*);
363 static MSVCP_bool (*__thiscall p_basic_istream_wchar_ipfx)(basic_istream_wchar*, MSVCP_bool);
364 static basic_istream_wchar* (*__thiscall p_basic_istream_wchar_ignore)(basic_istream_wchar*, streamsize, unsigned short);
366 /* ostream */
367 static basic_ostream_char* (*__thiscall p_basic_ostream_char_print_double)(basic_ostream_char*, double);
369 static basic_ostream_wchar* (*__thiscall p_basic_ostream_wchar_print_double)(basic_ostream_wchar*, double);
371 /* basic_ios */
372 static locale* (*__thiscall p_basic_ios_char_imbue)(basic_ios_char*, locale*, const locale*);
374 static locale* (*__thiscall p_basic_ios_wchar_imbue)(basic_ios_wchar*, locale*, const locale*);
376 /* ios_base */
377 static IOSB_iostate (*__thiscall p_ios_base_rdstate)(const ios_base*);
378 static IOSB_fmtflags (*__thiscall p_ios_base_setf_mask)(ios_base*, IOSB_fmtflags, IOSB_fmtflags);
379 static void (*__thiscall p_ios_base_unsetf)(ios_base*, IOSB_fmtflags);
380 static streamsize (*__thiscall p_ios_base_precision_set)(ios_base*, streamsize);
382 /* locale */
383 static locale* (*__thiscall p_locale_ctor_cstr)(locale*, const char*, int /* FIXME: category */);
384 static void (*__thiscall p_locale_dtor)(locale *this);
386 /* basic_string */
387 static basic_string_char* (__thiscall *p_basic_string_char_ctor_cstr)(basic_string_char*, const char*);
388 static const char* (__thiscall *p_basic_string_char_cstr)(basic_string_char*);
389 static void (__thiscall *p_basic_string_char_dtor)(basic_string_char*);
391 static basic_string_wchar* (__thiscall *p_basic_string_wchar_ctor_cstr)(basic_string_wchar*, const wchar_t*);
392 static const wchar_t* (__thiscall *p_basic_string_wchar_cstr)(basic_string_wchar*);
393 static void (__thiscall *p_basic_string_wchar_dtor)(basic_string_wchar*);
395 static int invalid_parameter = 0;
396 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
397 const wchar_t *function, const wchar_t *file,
398 unsigned line, uintptr_t arg)
400 ok(expression == NULL, "expression is not NULL\n");
401 ok(function == NULL, "function is not NULL\n");
402 ok(file == NULL, "file is not NULL\n");
403 ok(line == 0, "line = %u\n", line);
404 ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
405 invalid_parameter++;
408 /* Emulate a __thiscall */
409 #ifdef __i386__
411 #include "pshpack1.h"
412 struct thiscall_thunk
414 BYTE pop_eax; /* popl %eax (ret addr) */
415 BYTE pop_edx; /* popl %edx (func) */
416 BYTE pop_ecx; /* popl %ecx (this) */
417 BYTE push_eax; /* pushl %eax */
418 WORD jmp_edx; /* jmp *%edx */
420 #include "poppack.h"
422 static void * (WINAPI *call_thiscall_func1)( void *func, void *this );
423 static void * (WINAPI *call_thiscall_func2)( void *func, void *this, const void *a );
424 static void * (WINAPI *call_thiscall_func3)( void *func, void *this, const void *a, const void *b );
425 static void * (WINAPI *call_thiscall_func4)( void *func, void *this, const void *a, const void *b,
426 const void *c );
427 static void * (WINAPI *call_thiscall_func5)( void *func, void *this, const void *a, const void *b,
428 const void *c, const void *d );
430 /* to silence compiler error about converting double to pointer */
431 static void * (WINAPI *call_thiscall_func2_ptr_dbl)( void *func, void *this, double a );
433 struct thiscall_thunk_retptr *thunk_retptr;
435 static void init_thiscall_thunk(void)
437 struct thiscall_thunk *thunk = VirtualAlloc( NULL, sizeof(*thunk),
438 MEM_COMMIT, PAGE_EXECUTE_READWRITE );
439 thunk->pop_eax = 0x58; /* popl %eax */
440 thunk->pop_edx = 0x5a; /* popl %edx */
441 thunk->pop_ecx = 0x59; /* popl %ecx */
442 thunk->push_eax = 0x50; /* pushl %eax */
443 thunk->jmp_edx = 0xe2ff; /* jmp *%edx */
444 call_thiscall_func1 = (void *)thunk;
445 call_thiscall_func2 = (void *)thunk;
446 call_thiscall_func3 = (void *)thunk;
447 call_thiscall_func4 = (void *)thunk;
448 call_thiscall_func5 = (void *)thunk;
450 call_thiscall_func2_ptr_dbl = (void *)thunk;
453 #define call_func1(func,_this) call_thiscall_func1(func,_this)
454 #define call_func2(func,_this,a) call_thiscall_func2(func,_this,(const void*)(a))
455 #define call_func3(func,_this,a,b) call_thiscall_func3(func,_this,(const void*)(a),(const void*)(b))
456 #define call_func4(func,_this,a,b,c) call_thiscall_func4(func,_this,(const void*)(a),(const void*)(b), \
457 (const void*)(c))
458 #define call_func5(func,_this,a,b,c,d) call_thiscall_func5(func,_this,(const void*)(a),(const void*)(b), \
459 (const void*)(c), (const void *)(d))
461 #define call_func2_ptr_dbl(func,_this,a) call_thiscall_func2_ptr_dbl(func,_this,a)
463 #else
465 #define init_thiscall_thunk()
466 #define call_func1(func,_this) func(_this)
467 #define call_func2(func,_this,a) func(_this,a)
468 #define call_func3(func,_this,a,b) func(_this,a,b)
469 #define call_func4(func,_this,a,b,c) func(_this,a,b,c)
470 #define call_func5(func,_this,a,b,c,d) func(_this,a,b,c,d)
472 #define call_func2_ptr_dbl call_func2
474 #endif /* __i386__ */
476 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
477 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
478 static BOOL init(void)
480 HMODULE msvcr = LoadLibraryA("msvcr90.dll");
481 HMODULE msvcp = LoadLibraryA("msvcp90.dll");
482 if(!msvcr || !msvcp) {
483 win_skip("msvcp90.dll or msvcrt90.dll not installed\n");
484 return FALSE;
487 p_set_invalid_parameter_handler = (void*)GetProcAddress(msvcr, "_set_invalid_parameter_handler");
488 p_free = (void*)GetProcAddress(msvcr, "free");
489 if(!p_set_invalid_parameter_handler || !p_free) {
490 win_skip("Error setting tests environment\n");
491 return FALSE;
494 p_set_invalid_parameter_handler(test_invalid_parameter_handler);
496 if(sizeof(void*) == 8) { /* 64-bit initialization */
497 SET(p_basic_stringstream_char_ctor,
498 "??_F?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXXZ");
499 SET(p_basic_stringstream_char_ctor_str,
500 "??0?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@H@Z");
501 SET(p_basic_stringstream_char_str_get,
502 "?str@?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
503 SET(p_basic_stringstream_char_vbase_dtor,
504 "??_D?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXXZ");
506 SET(p_basic_stringstream_wchar_ctor,
507 "??_F?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAXXZ");
508 SET(p_basic_stringstream_wchar_ctor_str,
509 "??0?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@AEBV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@1@H@Z");
510 SET(p_basic_stringstream_wchar_str_get,
511 "?str@?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@2@XZ");
512 SET(p_basic_stringstream_wchar_vbase_dtor,
513 "??_D?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAXXZ");
515 SET(p_basic_istream_char_read_uint64,
516 "??5?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@AEA_K@Z");
517 SET(p_basic_istream_char_read_double,
518 "??5?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@AEAN@Z");
519 SET(p_basic_istream_char_get,
520 "?get@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAHXZ");
521 SET(p_basic_istream_char_ipfx,
522 "?ipfx@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAA_N_N@Z");
523 SET(p_basic_istream_char_ignore,
524 "?ignore@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@_JH@Z");
526 SET(p_basic_istream_wchar_read_uint64,
527 "??5?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV01@AEA_K@Z");
528 SET(p_basic_istream_wchar_read_double,
529 "??5?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV01@AEAN@Z");
530 SET(p_basic_istream_wchar_get,
531 "?get@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAGXZ");
532 SET(p_basic_istream_wchar_ipfx,
533 "?ipfx@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAA_N_N@Z");
534 SET(p_basic_istream_wchar_ignore,
535 "?ignore@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV12@_JG@Z");
537 SET(p_basic_ostream_char_print_double,
538 "??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@N@Z");
540 SET(p_basic_ostream_wchar_print_double,
541 "??6?$basic_ostream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV01@N@Z");
543 SET(p_ios_base_rdstate,
544 "?rdstate@ios_base@std@@QEBAHXZ");
545 SET(p_ios_base_setf_mask,
546 "?setf@ios_base@std@@QEAAHHH@Z");
547 SET(p_ios_base_unsetf,
548 "?unsetf@ios_base@std@@QEAAXH@Z");
549 SET(p_ios_base_precision_set,
550 "?precision@ios_base@std@@QEAA_J_J@Z");
552 SET(p_basic_ios_char_imbue,
553 "?imbue@?$basic_ios@DU?$char_traits@D@std@@@std@@QEAA?AVlocale@2@AEBV32@@Z");
555 SET(p_basic_ios_wchar_imbue,
556 "?imbue@?$basic_ios@_WU?$char_traits@_W@std@@@std@@QEAA?AVlocale@2@AEBV32@@Z");
558 SET(p_locale_ctor_cstr,
559 "??0locale@std@@QEAA@PEBDH@Z");
560 SET(p_locale_dtor,
561 "??1locale@std@@QEAA@XZ");
563 SET(p_basic_string_char_ctor_cstr,
564 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@PEBD@Z");
565 SET(p_basic_string_char_cstr,
566 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
567 SET(p_basic_string_char_dtor,
568 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
570 SET(p_basic_string_wchar_ctor_cstr,
571 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@PEB_W@Z");
572 SET(p_basic_string_wchar_cstr,
573 "?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAPEB_WXZ");
574 SET(p_basic_string_wchar_dtor,
575 "??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@XZ");
576 } else {
577 SET(p_basic_stringstream_char_ctor,
578 "??_F?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ");
579 SET(p_basic_stringstream_char_ctor_str,
580 "??0?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@H@Z");
581 SET(p_basic_stringstream_char_str_get,
582 "?str@?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
583 SET(p_basic_stringstream_char_vbase_dtor,
584 "??_D?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ");
586 SET(p_basic_stringstream_wchar_ctor,
587 "??_F?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEXXZ");
588 SET(p_basic_stringstream_wchar_ctor_str,
589 "??0?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@ABV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@1@H@Z");
590 SET(p_basic_stringstream_wchar_str_get,
591 "?str@?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBE?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@2@XZ");
592 SET(p_basic_stringstream_wchar_vbase_dtor,
593 "??_D?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEXXZ");
595 SET(p_basic_istream_char_read_uint64,
596 "??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AA_K@Z");
597 SET(p_basic_istream_char_read_double,
598 "??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAN@Z");
599 SET(p_basic_istream_char_get,
600 "?get@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEHXZ");
601 SET(p_basic_istream_char_ipfx,
602 "?ipfx@?$basic_istream@DU?$char_traits@D@std@@@std@@QAE_N_N@Z");
603 SET(p_basic_istream_char_ignore,
604 "?ignore@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV12@HH@Z");
606 SET(p_basic_istream_wchar_read_uint64,
607 "??5?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV01@AA_K@Z");
608 SET(p_basic_istream_wchar_read_double,
609 "??5?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV01@AAN@Z");
610 SET(p_basic_istream_wchar_get,
611 "?get@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEGXZ");
612 SET(p_basic_istream_wchar_ipfx,
613 "?ipfx@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAE_N_N@Z");
614 SET(p_basic_istream_wchar_ignore,
615 "?ignore@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV12@HG@Z");
617 SET(p_basic_ostream_char_print_double,
618 "??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@N@Z");
620 SET(p_basic_ostream_wchar_print_double,
621 "??6?$basic_ostream@_WU?$char_traits@_W@std@@@std@@QAEAAV01@N@Z");
623 SET(p_ios_base_rdstate,
624 "?rdstate@ios_base@std@@QBEHXZ");
625 SET(p_ios_base_setf_mask,
626 "?setf@ios_base@std@@QAEHHH@Z");
627 SET(p_ios_base_unsetf,
628 "?unsetf@ios_base@std@@QAEXH@Z");
629 SET(p_ios_base_precision_set,
630 "?precision@ios_base@std@@QAEHH@Z");
632 SET(p_basic_ios_char_imbue,
633 "?imbue@?$basic_ios@DU?$char_traits@D@std@@@std@@QAE?AVlocale@2@ABV32@@Z");
635 SET(p_basic_ios_wchar_imbue,
636 "?imbue@?$basic_ios@_WU?$char_traits@_W@std@@@std@@QAE?AVlocale@2@ABV32@@Z");
638 SET(p_locale_ctor_cstr,
639 "??0locale@std@@QAE@PBDH@Z");
640 SET(p_locale_dtor,
641 "??1locale@std@@QAE@XZ");
643 SET(p_basic_string_char_ctor_cstr,
644 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z");
645 SET(p_basic_string_char_cstr,
646 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
647 SET(p_basic_string_char_dtor,
648 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
650 SET(p_basic_string_wchar_ctor_cstr,
651 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@PB_W@Z");
652 SET(p_basic_string_wchar_cstr,
653 "?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEPB_WXZ");
654 SET(p_basic_string_wchar_dtor,
655 "??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@XZ");
658 init_thiscall_thunk();
659 return TRUE;
662 /* convert a dll name A->W without depending on the current codepage */
663 static wchar_t *AtoW( wchar_t *nameW, const char *nameA, unsigned int len )
665 unsigned int i;
667 for (i = 0; i < len; i++) nameW[i] = nameA[i];
668 nameW[i] = 0;
669 return nameW;
672 static void test_num_get_get_uint64(void)
674 unsigned short testus, nextus;
675 basic_stringstream_wchar wss;
676 basic_stringstream_char ss;
677 basic_string_wchar wstr;
678 basic_string_char str;
679 IOSB_iostate state;
680 locale lcl, retlcl;
681 wchar_t wide[64];
682 ULONGLONG val;
683 int i, next;
685 /* makes tables narrower */
686 const IOSB_iostate IOSTATE_faileof = IOSTATE_failbit|IOSTATE_eofbit;
688 struct _test_num_get {
689 const char *str;
690 const char *lcl;
691 IOSB_fmtflags fmtfl;
692 IOSB_iostate state;
693 ULONGLONG val;
694 int next;
695 } tests[] = {
696 /* simple cases */
697 { "0", NULL, FMTFLAG_dec, IOSTATE_eofbit, 0, EOF },
698 { "1234567", NULL, FMTFLAG_dec, IOSTATE_eofbit, 1234567, EOF },
699 { "+1234567", NULL, FMTFLAG_dec, IOSTATE_eofbit, 1234567, EOF },
700 { "-1234567", NULL, FMTFLAG_dec, IOSTATE_eofbit, -1234567, EOF },
701 { "", NULL, FMTFLAG_dec, IOSTATE_faileof, 42, EOF },
703 /* different bases */
704 /* (with and without zero are both tested, since 0 can signal a prefix check) */
705 { "0x1000", NULL, FMTFLAG_hex, IOSTATE_eofbit, 4096, EOF }, /* lowercase x */
706 { "0X1000", NULL, FMTFLAG_hex, IOSTATE_eofbit, 4096, EOF }, /* uppercase X */
707 { "010", NULL, FMTFLAG_hex, IOSTATE_eofbit, 16, EOF },
708 { "010", NULL, FMTFLAG_dec, IOSTATE_eofbit, 10, EOF },
709 { "010", NULL, FMTFLAG_oct, IOSTATE_eofbit, 8, EOF },
710 { "10", NULL, FMTFLAG_hex, IOSTATE_eofbit, 16, EOF },
711 { "10", NULL, FMTFLAG_dec, IOSTATE_eofbit, 10, EOF },
712 { "10", NULL, FMTFLAG_oct, IOSTATE_eofbit, 8, EOF },
713 { "10", NULL, 0, IOSTATE_eofbit, 10, EOF }, /* discover dec */
714 { "010", NULL, 0, IOSTATE_eofbit, 8, EOF }, /* discover oct */
715 { "0xD", NULL, 0, IOSTATE_eofbit, 13, EOF }, /* discover hex (upper) */
716 { "0xd", NULL, 0, IOSTATE_eofbit, 13, EOF }, /* discover hex (lower) */
718 /* test grouping - default/"C" has no grouping, named English/German locales do */
719 { "0.", NULL, FMTFLAG_dec, IOSTATE_goodbit, 0, '.' },
720 { "0,", NULL, FMTFLAG_dec, IOSTATE_goodbit, 0, ',' },
721 { "0,", "English", FMTFLAG_dec, IOSTATE_faileof, 42, EOF }, /* trailing group with , */
722 { "0.", "German", FMTFLAG_dec, IOSTATE_faileof, 42, EOF }, /* trailing group with . */
723 { "0,", "German", FMTFLAG_dec, IOSTATE_goodbit, 0, ',' },
724 { ",0", "English", FMTFLAG_dec, IOSTATE_failbit, 42, EOF }, /* empty group at start */
726 { "1,234,567", NULL, FMTFLAG_dec, IOSTATE_goodbit, 1, ',' }, /* no grouping */
727 { "1,234,567", "English", FMTFLAG_dec, IOSTATE_eofbit, 1234567, EOF }, /* grouping with , */
728 { "1.234.567", "German", FMTFLAG_dec, IOSTATE_eofbit, 1234567, EOF }, /* grouping with . */
729 { "1,,234", NULL, FMTFLAG_dec, IOSTATE_goodbit, 1, ',' }, /* empty group */
730 { "1,,234", "English", FMTFLAG_dec, IOSTATE_failbit, 42, EOF }, /* empty group */
731 { "0x1,000,000", "English", FMTFLAG_hex, IOSTATE_eofbit, 16777216, EOF }, /* yeah, hex can group */
732 { "1,23,34", "English", FMTFLAG_dec, IOSTATE_faileof, 42, EOF }, /* invalid size group */
733 { "0,123", "English", FMTFLAG_dec, IOSTATE_eofbit, 123, EOF }, /* 0 solo in group */
735 { "18446744073709551615", NULL, FMTFLAG_dec, IOSTATE_eofbit, ~0, EOF }, /* max value */
736 { "99999999999999999999", NULL, FMTFLAG_dec, IOSTATE_faileof, 42, EOF }, /* invalid value */
738 /* test invalid formats */
739 { "0000x10", NULL, FMTFLAG_hex, IOSTATE_goodbit, 0, 'x' },
740 { "x10", NULL, FMTFLAG_hex, IOSTATE_failbit, 42, EOF },
741 { "0xx10", NULL, FMTFLAG_hex, IOSTATE_failbit, 42, EOF },
744 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
745 /* char version */
746 call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
747 call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
749 if(tests[i].lcl) {
750 call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
751 call_func3(p_basic_ios_char_imbue, &ss.basic_ios, &retlcl, &lcl);
754 val = 42;
755 call_func3(p_ios_base_setf_mask, &ss.basic_ios.base, tests[i].fmtfl, FMTFLAG_basefield);
756 call_func2(p_basic_istream_char_read_uint64, &ss.base.base1, &val);
757 state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
758 next = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
760 ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
761 ok(tests[i].val == val, "wrong val, expected = %llu found %llu\n", (unsigned long long)tests[i].val, (unsigned long long)val);
762 ok(tests[i].next == next, "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
764 if(tests[i].lcl)
765 call_func1(p_locale_dtor, &lcl);
767 call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
768 call_func1(p_basic_string_char_dtor, &str);
770 /* wchar_t version */
771 AtoW(wide, tests[i].str, strlen(tests[i].str));
772 call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
773 call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
775 if(tests[i].lcl) {
776 call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
777 call_func3(p_basic_ios_wchar_imbue, &wss.basic_ios, &retlcl, &lcl);
780 val = 42;
781 call_func3(p_ios_base_setf_mask, &wss.basic_ios.base, tests[i].fmtfl, FMTFLAG_basefield);
782 call_func2(p_basic_istream_wchar_read_uint64, &wss.base.base1, &val);
783 state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
784 nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
786 ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
787 ok(tests[i].val == val, "wrong val, expected = %llu found %llu\n", (unsigned long long)tests[i].val, (unsigned long long)val);
788 testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
789 ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
791 if(tests[i].lcl)
792 call_func1(p_locale_dtor, &lcl);
794 call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
795 call_func1(p_basic_string_wchar_dtor, &wstr);
800 static void test_num_get_get_double(void)
802 unsigned short testus, nextus;
803 basic_stringstream_wchar wss;
804 basic_stringstream_char ss;
805 basic_string_wchar wstr;
806 basic_string_char str;
807 IOSB_iostate state;
808 locale lcl, retlcl;
809 wchar_t wide[64];
810 int i, next;
811 double val;
813 /* makes tables narrower */
814 const IOSB_iostate IOSTATE_faileof = IOSTATE_failbit|IOSTATE_eofbit;
816 struct _test_num_get {
817 const char *str;
818 const char *lcl;
819 IOSB_iostate state;
820 double val;
821 int next;
822 } tests[] = {
823 /* simple cases */
824 { "0", NULL, IOSTATE_eofbit, 0.0, EOF },
825 { "10", NULL, IOSTATE_eofbit, 10.0, EOF },
826 { "+10", NULL, IOSTATE_eofbit, 10.0, EOF },
827 { "-10", NULL, IOSTATE_eofbit, -10.0, EOF },
828 { "+010", NULL, IOSTATE_eofbit, 10.0, EOF }, /* leading zero */
830 /* test grouping - default/"C" has no grouping, named English/German locales do */
831 { "1,000", NULL, IOSTATE_goodbit, 1.0, ',' }, /* with comma */
832 { "1,000", "English", IOSTATE_eofbit, 1000.0, EOF },
833 { "1,000", "German", IOSTATE_eofbit, 1.0, EOF },
835 { "1.000", NULL, IOSTATE_eofbit, 1.0, EOF }, /* with period */
836 { "1.000", "English", IOSTATE_eofbit, 1.0, EOF },
837 { "1.000", "German", IOSTATE_eofbit, 1000.0, EOF },
839 { "1,234.", NULL, IOSTATE_goodbit, 1.0, ',' },
840 { "1,234.", "English", IOSTATE_eofbit, 1234.0, EOF }, /* trailing decimal */
841 { "1,234.", "German", IOSTATE_goodbit, 1.234, '.' },
842 { "1,234.5", "English", IOSTATE_eofbit, 1234.5, EOF }, /* group + decimal */
843 { "1,234.5", "German", IOSTATE_goodbit, 1.234, '.' },
845 { "1,234,567,890", NULL, IOSTATE_goodbit, 1.0, ',' }, /* more groups */
846 { "1,234,567,890", "English", IOSTATE_eofbit, 1234567890.0, EOF },
847 { "1,234,567,890", "German", IOSTATE_goodbit, 1.234, ',' },
848 { "1.234.567.890", "German", IOSTATE_eofbit, 1234567890.0, EOF },
850 /* extra digits and stuff */
851 { "00000.123456", NULL, IOSTATE_eofbit, 0.123456, EOF },
852 { "0.1234560000", NULL, IOSTATE_eofbit, 0.123456, EOF },
853 { "100aaaa", NULL, IOSTATE_goodbit, 100.0, 'a' },
855 /* exponent */
856 { "10e10", NULL, IOSTATE_eofbit, 10e10, EOF }, /* lowercase e */
857 { "10E10", NULL, IOSTATE_eofbit, 10E10, EOF }, /* uppercase E */
858 { "10e+10", NULL, IOSTATE_eofbit, 10e10, EOF }, /* sign */
859 { "10e-10", NULL, IOSTATE_eofbit, 10e-10, EOF },
860 { "10.e10", NULL, IOSTATE_eofbit, 10e10, EOF }, /* trailing decimal before exponent */
861 { "-10.e-10", NULL, IOSTATE_eofbit, -10e-10, EOF },
862 { "-12.345e-10", NULL, IOSTATE_eofbit, -12.345e-10, EOF },
863 { "1,234e10", NULL, IOSTATE_goodbit, 1.0, ',' },
864 { "1,234e10", "English", IOSTATE_eofbit, 1234.0e10, EOF },
865 { "1,234e10", "German", IOSTATE_eofbit, 1.234e10, EOF },
866 { "1.0e999", NULL, IOSTATE_faileof, 42.0, EOF }, /* too big */
867 { "1.0e-999", NULL, IOSTATE_faileof, 42.0, EOF }, /* too small */
869 /* bad form */
870 { "1,000,", NULL, IOSTATE_goodbit, 1.0, ',' }, /* trailing group */
871 { "1,000,", "English", IOSTATE_faileof, 42.0, EOF },
872 { "1.000.", "German", IOSTATE_faileof, 42.0, EOF },
874 { "1,,000", NULL, IOSTATE_goodbit, 1.0, ',' }, /* empty group */
875 { "1,,000", "English", IOSTATE_failbit, 42.0, EOF },
876 { "1..000", "German", IOSTATE_failbit, 42.0, EOF },
878 { "1.0,00", "English", IOSTATE_goodbit, 1.0, ',' },
879 { "1.0,00", "German", IOSTATE_faileof, 42.0, EOF },
881 { "1.0ee10", NULL, IOSTATE_failbit, 42.0, EOF }, /* dup exp */
882 { "1.0e1.0", NULL, IOSTATE_goodbit, 10.0, '.' }, /* decimal in exponent */
883 { "1.0e1,0", NULL, IOSTATE_goodbit, 10.0, ',' }, /* group in exponent */
886 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
887 /* char version */
888 call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
889 call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
891 if(tests[i].lcl) {
892 call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
893 call_func3(p_basic_ios_char_imbue, &ss.basic_ios, &retlcl, &lcl);
896 val = 42.0;
897 call_func2(p_basic_istream_char_read_double, &ss.base.base1, &val);
898 state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
899 next = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
901 ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
902 ok(tests[i].val == val, "wrong val, expected = %g found %g\n", tests[i].val, val);
903 ok(tests[i].next == next, "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
905 if(tests[i].lcl)
906 call_func1(p_locale_dtor, &lcl);
908 call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
909 call_func1(p_basic_string_char_dtor, &str);
911 /* wchar_t version */
912 AtoW(wide, tests[i].str, strlen(tests[i].str));
913 call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
914 call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
916 if(tests[i].lcl) {
917 call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
918 call_func3(p_basic_ios_wchar_imbue, &wss.basic_ios, &retlcl, &lcl);
921 val = 42.0;
922 call_func2(p_basic_istream_wchar_read_double, &wss.base.base1, &val);
923 state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
924 nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
926 ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
927 ok(tests[i].val == val, "wrong val, expected = %g found %g\n", tests[i].val, val);
928 testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
929 ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
931 if(tests[i].lcl)
932 call_func1(p_locale_dtor, &lcl);
934 call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
935 call_func1(p_basic_string_wchar_dtor, &wstr);
940 static void test_num_put_put_double(void)
942 basic_stringstream_wchar wss;
943 basic_stringstream_char ss;
944 basic_string_wchar pwstr;
945 basic_string_char pstr;
946 locale lcl, retlcl;
947 const wchar_t *wstr;
948 const char *str;
949 wchar_t wide[64];
950 int i;
952 struct _test_num_get {
953 double val;
954 const char *lcl;
955 streamsize prec; /* set to -1 for default */
956 IOSB_fmtflags fmtfl; /* FMTFLAG_scientific, FMTFLAG_fixed */
957 const char *str;
958 } tests[] = {
959 { 0.0, NULL, -1, 0, "0" },
961 /* simple cases */
962 { 0.123, NULL, -1, 0, "0.123" },
963 { 0.123, NULL, 6, 0, "0.123" },
964 { 0.123, NULL, 0, 0, "0.123" },
966 /* fixed format */
967 { 0.123, NULL, -1, FMTFLAG_fixed, "0.123000" },
968 { 0.123, NULL, 6, FMTFLAG_fixed, "0.123000" },
969 { 0.123, NULL, 0, FMTFLAG_fixed, "0" },
971 /* scientific format */
972 { 123456.789, NULL, -1, FMTFLAG_scientific, "1.234568e+005" },
973 { 123456.789, NULL, 0, FMTFLAG_scientific, "1.234568e+005" },
974 { 123456.789, NULL, 9, FMTFLAG_scientific, "1.234567890e+005" },
975 { 123456.789, "German", 9, FMTFLAG_scientific, "1,234567890e+005" },
977 /* different locales */
978 { 0.123, "C", -1, 0, "0.123" },
979 { 0.123, "English", -1, 0, "0.123" },
980 { 0.123, "German", -1, 0, "0,123" },
982 { 123456.789, "C", -1, 0, "123457" },
983 { 123456.789, "English", -1, 0, "123,457" },
984 { 123456.789, "German", -1, 0, "123.457" },
986 /* signs and exponents */
987 { 1.0e-9, NULL, -1, 0, "1e-009" },
988 { 1.0e-9, NULL, 9, 0, "1e-009" },
989 { -1.0e9, NULL, -1, 0, "-1e+009" },
990 { -1.0e9, NULL, 9, 0, "-1e+009" },
992 { 1.0e-9, NULL, 0, FMTFLAG_fixed, "0" },
993 { 1.0e-9, NULL, 6, FMTFLAG_fixed, "0.000000" },
994 { 1.0e-9, NULL, 9, FMTFLAG_fixed, "0.000000001" },
995 { -1.0e9, NULL, 0, FMTFLAG_fixed, "-1000000000" },
996 { -1.0e9, NULL, 6, FMTFLAG_fixed, "-1000000000.000000" },
998 { -1.23456789e9, NULL, 0, 0, "-1.23457e+009" },
999 { -1.23456789e9, NULL, 0, FMTFLAG_fixed, "-1234567890" },
1000 { -1.23456789e9, NULL, 6, FMTFLAG_fixed, "-1234567890.000000" },
1001 { -1.23456789e-9, NULL, 6, FMTFLAG_fixed, "-0.000000" },
1002 { -1.23456789e-9, NULL, 9, FMTFLAG_fixed, "-0.000000001" }
1005 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1006 /* char version */
1007 call_func2(p_basic_stringstream_char_ctor, &ss, TRUE);
1009 if(tests[i].lcl) {
1010 call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
1011 call_func3(p_basic_ios_char_imbue, &ss.basic_ios, &retlcl, &lcl);
1014 /* set format and precision only if specified, so we can try defaults */
1015 if(tests[i].fmtfl)
1016 call_func3(p_ios_base_setf_mask, &ss.basic_ios.base, tests[i].fmtfl, FMTFLAG_floatfield);
1017 if(tests[i].prec != -1)
1018 call_func2(p_ios_base_precision_set, &ss.basic_ios.base, tests[i].prec);
1019 call_func2_ptr_dbl(p_basic_ostream_char_print_double, &ss.base.base2, tests[i].val);
1021 call_func2(p_basic_stringstream_char_str_get, &ss, &pstr);
1022 str = call_func1(p_basic_string_char_cstr, &pstr);
1024 ok(!strcmp(tests[i].str, str), "wrong output, expected = %s found = %s\n", tests[i].str, str);
1026 if(tests[i].lcl)
1027 call_func1(p_locale_dtor, &lcl);
1029 call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1031 /* wchar_t version */
1032 call_func2(p_basic_stringstream_wchar_ctor, &wss, TRUE);
1034 if(tests[i].lcl) {
1035 call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
1036 call_func3(p_basic_ios_wchar_imbue, &wss.basic_ios, &retlcl, &lcl);
1039 /* set format and precision only if specified, so we can try defaults */
1040 if(tests[i].fmtfl)
1041 call_func3(p_ios_base_setf_mask, &wss.basic_ios.base, tests[i].fmtfl, FMTFLAG_floatfield);
1042 if(tests[i].prec != -1)
1043 call_func2(p_ios_base_precision_set, &wss.basic_ios.base, tests[i].prec);
1044 call_func2_ptr_dbl(p_basic_ostream_wchar_print_double, &wss.base.base2, tests[i].val);
1046 call_func2(p_basic_stringstream_wchar_str_get, &wss, &pwstr);
1047 wstr = call_func1(p_basic_string_wchar_cstr, &pwstr);
1049 AtoW(wide, tests[i].str, strlen(tests[i].str));
1050 ok(!lstrcmpW(wide, wstr), "wrong output, expected = %s found = %s\n", tests[i].str, str);
1052 if(tests[i].lcl)
1053 call_func1(p_locale_dtor, &lcl);
1055 call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1060 static void test_istream_ipfx(void)
1062 unsigned short testus, nextus;
1063 basic_stringstream_wchar wss;
1064 basic_stringstream_char ss;
1065 basic_string_wchar wstr;
1066 basic_string_char str;
1067 IOSB_iostate state;
1068 wchar_t wide[64];
1069 int i, ret, next;
1071 /* makes tables narrower */
1072 const IOSB_iostate IOSTATE_faileof = IOSTATE_failbit|IOSTATE_eofbit;
1074 struct _test_istream_ipfx {
1075 const char *str;
1076 int unset_skipws;
1077 int noskip;
1078 int ret;
1079 IOSB_iostate state;
1080 int next;
1081 } tests[] = {
1082 /* string unset noskip return state next char */
1083 { "", FALSE, FALSE, FALSE, IOSTATE_faileof, EOF }, /* empty string */
1084 { " ", FALSE, FALSE, FALSE, IOSTATE_faileof, EOF }, /* just ws */
1085 { "\t \n \f ", FALSE, FALSE, FALSE, IOSTATE_faileof, EOF }, /* different ws */
1086 { "simple", FALSE, FALSE, TRUE, IOSTATE_goodbit, 's' },
1087 { " simple", FALSE, FALSE, TRUE, IOSTATE_goodbit, 's' },
1088 { " simple", TRUE, FALSE, TRUE, IOSTATE_goodbit, ' ' }, /* unset skipws */
1089 { " simple", FALSE, TRUE, TRUE, IOSTATE_goodbit, ' ' }, /* ipfx(true) */
1090 { " simple", TRUE, TRUE, TRUE, IOSTATE_goodbit, ' ' }, /* both */
1091 { "\n\t ws", FALSE, FALSE, TRUE, IOSTATE_goodbit, 'w' },
1092 { "\n\t ws", TRUE, FALSE, TRUE, IOSTATE_goodbit, '\n' },
1095 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1096 /* char version */
1097 call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1098 call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1100 /* set format and precision only if specified, so we can try defaults */
1101 if(tests[i].unset_skipws)
1102 call_func2(p_ios_base_unsetf, &ss.basic_ios.base, TRUE);
1104 ret = (int)call_func2(p_basic_istream_char_ipfx, &ss.base.base1, tests[i].noskip);
1105 state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1106 next = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
1108 ok(tests[i].ret == ret, "wrong return, expected = %i found = %i\n", tests[i].ret, ret);
1109 ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1110 ok(tests[i].next == next, "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
1112 call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1114 /* wchar_t version */
1115 AtoW(wide, tests[i].str, strlen(tests[i].str));
1116 call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1117 call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1119 /* set format and precision only if specified, so we can try defaults */
1120 if(tests[i].unset_skipws)
1121 call_func2(p_ios_base_unsetf, &wss.basic_ios.base, TRUE);
1123 ret = (int)call_func2(p_basic_istream_wchar_ipfx, &wss.base.base1, tests[i].noskip);
1124 state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1125 nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
1127 ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1128 ok(tests[i].ret == ret, "wrong return, expected = %i found = %i\n", tests[i].ret, ret);
1129 testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
1130 ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
1132 call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1137 static void test_istream_ignore(void)
1139 unsigned short testus, nextus;
1140 basic_stringstream_wchar wss;
1141 basic_stringstream_char ss;
1142 basic_string_wchar wstr;
1143 basic_string_char str;
1144 IOSB_iostate state;
1145 wchar_t wide[64];
1146 int i, next;
1148 struct _test_istream_ignore {
1149 const char *str;
1150 streamsize count;
1151 int delim;
1152 IOSB_iostate state;
1153 int next;
1154 } tests[] = {
1155 /* string count delim state next */
1156 { "", 0, '\n', IOSTATE_goodbit, EOF }, /* empty string */
1158 /* different counts */
1159 { "ABCDEF", 2, '\n', IOSTATE_goodbit, 'C' }, /* easy case */
1160 { "ABCDEF", 42, '\n', IOSTATE_eofbit, EOF }, /* ignore too much */
1161 { "ABCDEF", -2, '\n', IOSTATE_goodbit, 'A' }, /* negative count */
1162 { "ABCDEF", 6, '\n', IOSTATE_goodbit, EOF }, /* is eof not set at end */
1163 { "ABCDEF", 7, '\n', IOSTATE_eofbit, EOF }, /* eof is set just after end */
1165 /* different delimiters */
1166 { "ABCDEF", 42, '\0', IOSTATE_eofbit, EOF }, /* null as delim */
1167 { "ABC DEF GHI", 0, ' ', IOSTATE_goodbit, 'A' },
1168 { "ABC DEF GHI", 42, ' ', IOSTATE_goodbit, 'D' },
1169 { "ABC DEF\tGHI", 42, '\t', IOSTATE_goodbit, 'G' },
1170 { "ABC ", 42, ' ', IOSTATE_goodbit, EOF }, /* delim at end */
1173 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1174 /* char version */
1175 call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1176 call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1178 call_func3(p_basic_istream_char_ignore, &ss.base.base1, tests[i].count, tests[i].delim);
1179 state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1180 next = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
1182 ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1183 ok(tests[i].next == next, "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
1185 call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1187 /* wchar_t version */
1188 AtoW(wide, tests[i].str, strlen(tests[i].str));
1189 call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1190 call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1192 call_func3(p_basic_istream_wchar_ignore, &wss.base.base1, tests[i].count, tests[i].delim);
1193 state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1194 nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
1196 ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1197 testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
1198 ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
1200 call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1205 START_TEST(ios)
1207 if(!init())
1208 return;
1210 test_num_get_get_uint64();
1211 test_num_get_get_double();
1212 test_num_put_put_double();
1213 test_istream_ipfx();
1214 test_istream_ignore();
1216 ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");