Release 1.5.29.
[wine] / dlls / msvcp90 / tests / ios.c
1 /*
2  * Copyright 2010 Piotr Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdio.h>
20 #include <locale.h>
21 #include <sys/stat.h>
22
23 #include <windef.h>
24 #include <winbase.h>
25 #include <share.h>
26 #include "wine/test.h"
27
28 static void* (__cdecl *p_set_invalid_parameter_handler)(void*);
29 static void  (__cdecl *p_free)(void*);
30
31 #undef __thiscall
32 #ifdef __i386__
33 #define __thiscall __stdcall
34 #else
35 #define __thiscall __cdecl
36 #endif
37
38 typedef unsigned char MSVCP_bool;
39 typedef SIZE_T MSVCP_size_t;
40 typedef SSIZE_T streamoff;
41 typedef SSIZE_T streamsize;
42
43 typedef void (*vtable_ptr)(void);
44
45 /* class mutex */
46 typedef struct {
47         void *mutex;
48 } mutex;
49
50 /* class locale */
51 typedef struct
52 {
53     struct _locale__Locimp *ptr;
54 } locale;
55
56 /* class locale::facet */
57 typedef struct {
58     const vtable_ptr *vtable;
59     MSVCP_size_t refs;
60 } locale_facet;
61
62 /* class codecvt_base */
63 typedef struct {
64     locale_facet facet;
65 } codecvt_base;
66
67 /* class codecvt<char> */
68 typedef struct {
69     codecvt_base base;
70 } codecvt_char;
71
72 typedef struct {
73     LCID handle;
74     unsigned page;
75 } _Cvtvec;
76
77 /* class codecvt<wchar> */
78 typedef struct {
79     codecvt_base base;
80     _Cvtvec cvt;
81 } codecvt_wchar;
82
83 typedef enum {
84     FMTFLAG_skipws      = 0x0001,
85     FMTFLAG_unitbuf     = 0x0002,
86     FMTFLAG_uppercase   = 0x0004,
87     FMTFLAG_showbase    = 0x0008,
88     FMTFLAG_showpoint   = 0x0010,
89     FMTFLAG_showpos     = 0x0020,
90     FMTFLAG_left        = 0x0040,
91     FMTFLAG_right       = 0x0080,
92     FMTFLAG_internal    = 0x0100,
93     FMTFLAG_dec         = 0x0200,
94     FMTFLAG_oct         = 0x0400,
95     FMTFLAG_hex         = 0x0800,
96     FMTFLAG_scientific  = 0x1000,
97     FMTFLAG_fixed       = 0x2000,
98     FMTFLAG_hexfloat    = 0x3000,
99     FMTFLAG_boolalpha   = 0x4000,
100     FMTFLAG_stdio       = 0x8000,
101     FMTFLAG_adjustfield = FMTFLAG_left|FMTFLAG_right|FMTFLAG_internal,
102     FMTFLAG_basefield   = FMTFLAG_dec|FMTFLAG_oct|FMTFLAG_hex,
103     FMTFLAG_floatfield  = FMTFLAG_scientific|FMTFLAG_fixed,
104     FMTFLAG_mask        = 0xffff
105 } IOSB_fmtflags;
106
107 typedef enum {
108     OPENMODE_in         = 0x01,
109     OPENMODE_out        = 0x02,
110     OPENMODE_ate        = 0x04,
111     OPENMODE_app        = 0x08,
112     OPENMODE_trunc      = 0x10,
113     OPENMODE__Nocreate  = 0x40,
114     OPENMODE__Noreplace = 0x80,
115     OPENMODE_binary     = 0x20,
116     OPENMODE_mask       = 0xff
117 } IOSB_openmode;
118
119 typedef enum {
120     SEEKDIR_beg  = 0x0,
121     SEEKDIR_cur  = 0x1,
122     SEEKDIR_end  = 0x2,
123     SEEKDIR_mask = 0x3
124 } IOSB_seekdir;
125
126 typedef enum {
127     IOSTATE_goodbit   = 0x00,
128     IOSTATE_eofbit    = 0x01,
129     IOSTATE_failbit   = 0x02,
130     IOSTATE_badbit    = 0x04,
131     IOSTATE__Hardfail = 0x10,
132     IOSTATE_mask      = 0x17
133 } IOSB_iostate;
134
135 typedef struct _iosarray {
136     struct _iosarray *next;
137     int index;
138     int long_val;
139     void *ptr_val;
140 } IOS_BASE_iosarray;
141
142 typedef enum {
143     EVENT_erase_event,
144     EVENT_imbue_event,
145     EVENT_copyfmt_event
146 } IOS_BASE_event;
147
148 struct _ios_base;
149 typedef void (CDECL *IOS_BASE_event_callback)(IOS_BASE_event, struct _ios_base*, int);
150 typedef struct _fnarray {
151     struct _fnarray *next;
152     int index;
153     IOS_BASE_event_callback event_handler;
154 } IOS_BASE_fnarray;
155
156 /* class ios_base */
157 typedef struct _ios_base {
158     const vtable_ptr *vtable;
159     MSVCP_size_t stdstr;
160     IOSB_iostate state;
161     IOSB_iostate except;
162     IOSB_fmtflags fmtfl;
163     streamsize prec;
164     streamsize wide;
165     IOS_BASE_iosarray *arr;
166     IOS_BASE_fnarray *calls;
167     locale *loc;
168 } ios_base;
169
170 /* class basic_streambuf<char> */
171 typedef struct {
172     const vtable_ptr *vtable;
173     mutex lock;
174     char *rbuf;
175     char *wbuf;
176     char **prbuf;
177     char **pwbuf;
178     char *rpos;
179     char *wpos;
180     char **prpos;
181     char **pwpos;
182     int rsize;
183     int wsize;
184     int *prsize;
185     int *pwsize;
186     locale *loc;
187 } basic_streambuf_char;
188
189 /* class basic_streambuf<wchar> */
190 typedef struct {
191     const vtable_ptr *vtable;
192     mutex lock;
193     wchar_t *rbuf;
194     wchar_t *wbuf;
195     wchar_t **prbuf;
196     wchar_t **pwbuf;
197     wchar_t *rpos;
198     wchar_t *wpos;
199     wchar_t **prpos;
200     wchar_t **pwpos;
201     int rsize;
202     int wsize;
203     int *prsize;
204     int *pwsize;
205     locale *loc;
206 } basic_streambuf_wchar;
207
208 typedef struct {
209     basic_streambuf_char base;
210     codecvt_char *cvt;
211     char putback;
212     MSVCP_bool wrotesome;
213     int state;
214     MSVCP_bool close;
215     FILE *file;
216 } basic_filebuf_char;
217
218 typedef struct {
219     basic_streambuf_wchar base;
220     codecvt_wchar *cvt;
221     wchar_t putback;
222     MSVCP_bool wrotesome;
223     int state;
224     MSVCP_bool close;
225     FILE *file;
226 } basic_filebuf_wchar;
227
228 typedef struct {
229     basic_streambuf_char base;
230     char *seekhigh;
231     int state;
232     char allocator; /* empty struct */
233 } basic_stringbuf_char;
234
235 typedef struct {
236     basic_streambuf_wchar base;
237     wchar_t *seekhigh;
238     int state;
239     char allocator; /* empty struct */
240 } basic_stringbuf_wchar;
241
242 typedef struct {
243     ios_base base;
244     basic_streambuf_char *strbuf;
245     struct _basic_ostream_char *stream;
246     char fillch;
247 } basic_ios_char;
248
249 typedef struct {
250     ios_base base;
251     basic_streambuf_wchar *strbuf;
252     struct _basic_ostream_wchar *stream;
253     wchar_t fillch;
254 } basic_ios_wchar;
255
256 typedef struct _basic_ostream_char {
257     const int *vbtable;
258     /* virtual inheritance
259      * basic_ios_char basic_ios;
260      */
261 } basic_ostream_char;
262
263 typedef struct _basic_ostream_wchar {
264     const int *vbtable;
265     /* virtual inheritance
266      * basic_ios_wchar basic_ios;
267      */
268 } basic_ostream_wchar;
269
270 typedef struct {
271     const int *vbtable;
272     streamsize count;
273     /* virtual inheritance
274      * basic_ios_char basic_ios;
275      */
276 } basic_istream_char;
277
278 typedef struct {
279     const int *vbtable;
280     streamsize count;
281     /* virtual inheritance
282      * basic_ios_wchar basic_ios;
283      */
284 } basic_istream_wchar;
285
286 typedef struct {
287     basic_istream_char base1;
288     basic_ostream_char base2;
289     /* virtual inheritance
290      * basic_ios_char basic_ios;
291      */
292 } basic_iostream_char;
293
294 typedef struct {
295     basic_istream_wchar base1;
296     basic_ostream_wchar base2;
297     /* virtual inheritance
298      * basic_ios_wchar basic_ios;
299      */
300 } basic_iostream_wchar;
301
302 typedef struct {
303     basic_ostream_char base;
304     basic_filebuf_char filebuf;
305     /* virtual inheritance
306      * basic_ios_char basic_ios;
307      */
308 } basic_ofstream_char;
309
310 typedef struct {
311     basic_ostream_wchar base;
312     basic_filebuf_wchar filebuf;
313     /* virtual inheritance
314      * basic_ios_wchar basic_ios;
315      */
316 } basic_ofstream_wchar;
317
318 typedef struct {
319     basic_istream_char base;
320     basic_filebuf_char filebuf;
321     /* virtual inheritance
322      * basic_ios_char basic_ios;
323      */
324 } basic_ifstream_char;
325
326 typedef struct {
327     basic_istream_wchar base;
328     basic_filebuf_wchar filebuf;
329     /* virtual inheritance
330      * basic_ios_wchar basic_ios;
331      */
332 } basic_ifstream_wchar;
333
334 typedef struct {
335     basic_iostream_char base;
336     basic_filebuf_char filebuf;
337     /* virtual inheritance */
338     basic_ios_char basic_ios; /* here to reserve correct stack size */
339 } basic_fstream_char;
340
341 typedef struct {
342     basic_iostream_wchar base;
343     basic_filebuf_wchar filebuf;
344     /* virtual inheritance */
345     basic_ios_wchar basic_ios; /* here to reserve correct stack size */
346 } basic_fstream_wchar;
347
348 typedef struct {
349     basic_ostream_char base;
350     basic_stringbuf_char strbuf;
351     /* virtual inheritance
352      * basic_ios_char basic_ios;
353      */
354 } basic_ostringstream_char;
355
356 typedef struct {
357     basic_ostream_wchar base;
358     basic_stringbuf_wchar strbuf;
359     /* virtual inheritance
360      * basic_ios_wchar basic_ios;
361      */
362 } basic_ostringstream_wchar;
363
364 typedef struct {
365     basic_istream_char base;
366     basic_stringbuf_char strbuf;
367     /* virtual inheritance
368      * basic_ios_char basic_ios;
369      */
370 } basic_istringstream_char;
371
372 typedef struct {
373     basic_istream_wchar base;
374     basic_stringbuf_wchar strbuf;
375     /* virtual inheritance
376      * basic_ios_wchar basic_ios;
377      */
378 } basic_istringstream_wchar;
379
380 typedef struct {
381     basic_iostream_char base;
382     basic_stringbuf_char strbuf;
383     /* virtual inheritance */
384     basic_ios_char basic_ios; /* here to reserve correct stack size */
385 } basic_stringstream_char;
386
387 typedef struct {
388     basic_iostream_wchar base;
389     basic_stringbuf_wchar strbuf;
390     /* virtual inheritance */
391     basic_ios_wchar basic_ios; /* here to reserve correct stack size */
392 } basic_stringstream_wchar;
393
394 /* basic_string<char, char_traits<char>, allocator<char>> */
395 #define BUF_SIZE_CHAR 16
396 typedef struct _basic_string_char
397 {
398     void *allocator;
399     union {
400         char buf[BUF_SIZE_CHAR];
401         char *ptr;
402     } data;
403     size_t size;
404     size_t res;
405 } basic_string_char;
406
407 #define BUF_SIZE_WCHAR 8
408 typedef struct
409 {
410     void *allocator;
411     union {
412         wchar_t buf[BUF_SIZE_WCHAR];
413         wchar_t *ptr;
414     } data;
415     MSVCP_size_t size;
416     MSVCP_size_t res;
417 } basic_string_wchar;
418
419 typedef struct {
420     streamoff off;
421     __int64 DECLSPEC_ALIGN(8) pos;
422     int state;
423 } fpos_int;
424
425 /* stringstream */
426 static basic_stringstream_char* (*__thiscall p_basic_stringstream_char_ctor)(basic_stringstream_char*, MSVCP_bool);
427 static basic_stringstream_char* (*__thiscall p_basic_stringstream_char_ctor_str)(basic_stringstream_char*, const basic_string_char*, int, MSVCP_bool);
428 static basic_string_char* (*__thiscall p_basic_stringstream_char_str_get)(const basic_stringstream_char*, basic_string_char*);
429 static void (*__thiscall p_basic_stringstream_char_vbase_dtor)(basic_stringstream_char*);
430
431 static basic_stringstream_wchar* (*__thiscall p_basic_stringstream_wchar_ctor)(basic_stringstream_wchar*, MSVCP_bool);
432 static basic_stringstream_wchar* (*__thiscall p_basic_stringstream_wchar_ctor_str)(basic_stringstream_wchar*, const basic_string_wchar*, int, MSVCP_bool);
433 static basic_string_wchar* (*__thiscall p_basic_stringstream_wchar_str_get)(const basic_stringstream_wchar*, basic_string_wchar*);
434 static void (*__thiscall p_basic_stringstream_wchar_vbase_dtor)(basic_stringstream_wchar*);
435
436 /* fstream */
437 static basic_fstream_char* (*__thiscall p_basic_fstream_char_ctor_name)(basic_fstream_char*, const char*, int, int, MSVCP_bool);
438 static void (*__thiscall p_basic_fstream_char_vbase_dtor)(basic_fstream_char*);
439
440 static basic_fstream_wchar* (*__thiscall p_basic_fstream_wchar_ctor_name)(basic_fstream_wchar*, const char*, int, int, MSVCP_bool);
441 static void (*__thiscall p_basic_fstream_wchar_vbase_dtor)(basic_fstream_wchar*);
442
443 /* istream */
444 static basic_istream_char* (*__thiscall p_basic_istream_char_read_uint64)(basic_istream_char*, unsigned __int64*);
445 static basic_istream_char* (*__thiscall p_basic_istream_char_read_double)(basic_istream_char*, double*);
446 static int                 (*__thiscall p_basic_istream_char_get)(basic_istream_char*);
447 static MSVCP_bool          (*__thiscall p_basic_istream_char_ipfx)(basic_istream_char*, MSVCP_bool);
448 static basic_istream_char* (*__thiscall p_basic_istream_char_ignore)(basic_istream_char*, streamsize, int);
449 static basic_istream_char* (*__thiscall p_basic_istream_char_seekg)(basic_istream_char*, streamoff, int);
450 static basic_istream_char* (*__thiscall p_basic_istream_char_seekg_fpos)(basic_istream_char*, fpos_int);
451 static int                 (*__thiscall p_basic_istream_char_peek)(basic_istream_char*);
452 static fpos_int*           (*__thiscall p_basic_istream_char_tellg)(basic_istream_char*, fpos_int*);
453 static basic_istream_char* (*__cdecl    p_basic_istream_char_getline_bstr_delim)(basic_istream_char*, basic_string_char*, char);
454
455 static basic_istream_wchar* (*__thiscall p_basic_istream_wchar_read_uint64)(basic_istream_wchar*, unsigned __int64*);
456 static basic_istream_wchar* (*__thiscall p_basic_istream_wchar_read_double)(basic_istream_wchar*, double *);
457 static int                  (*__thiscall p_basic_istream_wchar_get)(basic_istream_wchar*);
458 static MSVCP_bool           (*__thiscall p_basic_istream_wchar_ipfx)(basic_istream_wchar*, MSVCP_bool);
459 static basic_istream_wchar* (*__thiscall p_basic_istream_wchar_ignore)(basic_istream_wchar*, streamsize, unsigned short);
460 static basic_istream_wchar* (*__thiscall p_basic_istream_wchar_seekg)(basic_istream_wchar*, streamoff, int);
461 static basic_istream_wchar* (*__thiscall p_basic_istream_wchar_seekg_fpos)(basic_istream_wchar*, fpos_int);
462 static unsigned short       (*__thiscall p_basic_istream_wchar_peek)(basic_istream_wchar*);
463 static fpos_int*            (*__thiscall p_basic_istream_wchar_tellg)(basic_istream_wchar*, fpos_int*);
464 static basic_istream_wchar* (*__cdecl    p_basic_istream_wchar_getline_bstr_delim)(basic_istream_wchar*, basic_string_wchar*, wchar_t);
465
466 /* ostream */
467 static basic_ostream_char* (*__thiscall p_basic_ostream_char_print_double)(basic_ostream_char*, double);
468
469 static basic_ostream_wchar* (*__thiscall p_basic_ostream_wchar_print_double)(basic_ostream_wchar*, double);
470
471 /* basic_ios */
472 static locale*  (*__thiscall p_basic_ios_char_imbue)(basic_ios_char*, locale*, const locale*);
473
474 static locale*  (*__thiscall p_basic_ios_wchar_imbue)(basic_ios_wchar*, locale*, const locale*);
475
476 /* ios_base */
477 static IOSB_iostate  (*__thiscall p_ios_base_rdstate)(const ios_base*);
478 static IOSB_fmtflags (*__thiscall p_ios_base_setf_mask)(ios_base*, IOSB_fmtflags, IOSB_fmtflags);
479 static void          (*__thiscall p_ios_base_unsetf)(ios_base*, IOSB_fmtflags);
480 static streamsize    (*__thiscall p_ios_base_precision_set)(ios_base*, streamsize);
481
482 /* locale */
483 static locale*  (*__thiscall p_locale_ctor_cstr)(locale*, const char*, int /* FIXME: category */);
484 static void     (*__thiscall p_locale_dtor)(locale *this);
485
486 /* basic_string */
487 static basic_string_char* (__thiscall *p_basic_string_char_ctor_cstr)(basic_string_char*, const char*);
488 static const char* (__thiscall *p_basic_string_char_cstr)(basic_string_char*);
489 static void (__thiscall *p_basic_string_char_dtor)(basic_string_char*);
490
491 static basic_string_wchar* (__thiscall *p_basic_string_wchar_ctor_cstr)(basic_string_wchar*, const wchar_t*);
492 static const wchar_t* (__thiscall *p_basic_string_wchar_cstr)(basic_string_wchar*);
493 static void (__thiscall *p_basic_string_wchar_dtor)(basic_string_wchar*);
494
495 static int invalid_parameter = 0;
496 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
497         const wchar_t *function, const wchar_t *file,
498         unsigned line, uintptr_t arg)
499 {
500     ok(expression == NULL, "expression is not NULL\n");
501     ok(function == NULL, "function is not NULL\n");
502     ok(file == NULL, "file is not NULL\n");
503     ok(line == 0, "line = %u\n", line);
504     ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
505     invalid_parameter++;
506 }
507
508 static inline const char* debugstr_longlong(ULONGLONG ll)
509 {
510     /* return a different string if called up to 4 times in the same ok() */
511     static char string[4][17];
512     static int which;
513
514     if (sizeof(ll) > sizeof(unsigned long) && ll >> 32)
515         sprintf(string[which & 3], "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll);
516     else
517         sprintf(string[which & 3], "%lx", (unsigned long)ll);
518     return string[which++ & 3];
519 }
520
521 /* Emulate a __thiscall */
522 #ifdef __i386__
523
524 #include "pshpack1.h"
525 struct thiscall_thunk
526 {
527     BYTE pop_eax;    /* popl  %eax (ret addr) */
528     BYTE pop_edx;    /* popl  %edx (func) */
529     BYTE pop_ecx;    /* popl  %ecx (this) */
530     BYTE push_eax;   /* pushl %eax */
531     WORD jmp_edx;    /* jmp  *%edx */
532 };
533 #include "poppack.h"
534
535 static void * (WINAPI *call_thiscall_func1)( void *func, void *this );
536 static void * (WINAPI *call_thiscall_func2)( void *func, void *this, const void *a );
537 static void * (WINAPI *call_thiscall_func3)( void *func, void *this, const void *a, const void *b );
538 static void * (WINAPI *call_thiscall_func4)( void *func, void *this, const void *a, const void *b,
539         const void *c );
540 static void * (WINAPI *call_thiscall_func5)( void *func, void *this, const void *a, const void *b,
541         const void *c, const void *d );
542
543 /* to silence compiler errors */
544 static void * (WINAPI *call_thiscall_func2_ptr_dbl)( void *func, void *this, double a );
545 static void * (WINAPI *call_thiscall_func2_ptr_fpos)( void *func, void *this, fpos_int a );
546
547 static void init_thiscall_thunk(void)
548 {
549     struct thiscall_thunk *thunk = VirtualAlloc( NULL, sizeof(*thunk),
550                                                  MEM_COMMIT, PAGE_EXECUTE_READWRITE );
551     thunk->pop_eax  = 0x58;   /* popl  %eax */
552     thunk->pop_edx  = 0x5a;   /* popl  %edx */
553     thunk->pop_ecx  = 0x59;   /* popl  %ecx */
554     thunk->push_eax = 0x50;   /* pushl %eax */
555     thunk->jmp_edx  = 0xe2ff; /* jmp  *%edx */
556     call_thiscall_func1 = (void *)thunk;
557     call_thiscall_func2 = (void *)thunk;
558     call_thiscall_func3 = (void *)thunk;
559     call_thiscall_func4 = (void *)thunk;
560     call_thiscall_func5 = (void *)thunk;
561
562     call_thiscall_func2_ptr_dbl  = (void *)thunk;
563     call_thiscall_func2_ptr_fpos = (void *)thunk;
564 }
565
566 #define call_func1(func,_this) call_thiscall_func1(func,_this)
567 #define call_func2(func,_this,a) call_thiscall_func2(func,_this,(const void*)(a))
568 #define call_func3(func,_this,a,b) call_thiscall_func3(func,_this,(const void*)(a),(const void*)(b))
569 #define call_func4(func,_this,a,b,c) call_thiscall_func4(func,_this,(const void*)(a),(const void*)(b), \
570         (const void*)(c))
571 #define call_func5(func,_this,a,b,c,d) call_thiscall_func5(func,_this,(const void*)(a),(const void*)(b), \
572         (const void*)(c), (const void *)(d))
573
574 #define call_func2_ptr_dbl(func,_this,a)  call_thiscall_func2_ptr_dbl(func,_this,a)
575 #define call_func2_ptr_fpos(func,_this,a) call_thiscall_func2_ptr_fpos(func,_this,a)
576
577 #else
578
579 #define init_thiscall_thunk()
580 #define call_func1(func,_this) func(_this)
581 #define call_func2(func,_this,a) func(_this,a)
582 #define call_func3(func,_this,a,b) func(_this,a,b)
583 #define call_func4(func,_this,a,b,c) func(_this,a,b,c)
584 #define call_func5(func,_this,a,b,c,d) func(_this,a,b,c,d)
585
586 #define call_func2_ptr_dbl   call_func2
587 #define call_func2_ptr_fpos  call_func2
588
589 #endif /* __i386__ */
590
591 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
592 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
593 static BOOL init(void)
594 {
595     HMODULE msvcr = LoadLibraryA("msvcr90.dll");
596     HMODULE msvcp = LoadLibraryA("msvcp90.dll");
597     if(!msvcr || !msvcp) {
598         win_skip("msvcp90.dll or msvcrt90.dll not installed\n");
599         return FALSE;
600     }
601
602     p_set_invalid_parameter_handler = (void*)GetProcAddress(msvcr, "_set_invalid_parameter_handler");
603     p_free = (void*)GetProcAddress(msvcr, "free");
604     if(!p_set_invalid_parameter_handler || !p_free) {
605         win_skip("Error setting tests environment\n");
606         return FALSE;
607     }
608
609     p_set_invalid_parameter_handler(test_invalid_parameter_handler);
610
611     if(sizeof(void*) == 8) { /* 64-bit initialization */
612         SET(p_basic_stringstream_char_ctor,
613             "??_F?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXXZ");
614         SET(p_basic_stringstream_char_ctor_str,
615             "??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");
616         SET(p_basic_stringstream_char_str_get,
617             "?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");
618         SET(p_basic_stringstream_char_vbase_dtor,
619             "??_D?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXXZ");
620
621         SET(p_basic_stringstream_wchar_ctor,
622             "??_F?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAXXZ");
623         SET(p_basic_stringstream_wchar_ctor_str,
624             "??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");
625         SET(p_basic_stringstream_wchar_str_get,
626             "?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");
627         SET(p_basic_stringstream_wchar_vbase_dtor,
628             "??_D?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAXXZ");
629
630         SET(p_basic_fstream_char_ctor_name,
631             "??0?$basic_fstream@DU?$char_traits@D@std@@@std@@QEAA@PEBDHH@Z");
632         SET(p_basic_fstream_char_vbase_dtor,
633             "??_D?$basic_fstream@DU?$char_traits@D@std@@@std@@QEAAXXZ");
634
635         SET(p_basic_fstream_wchar_ctor_name,
636             "??0?$basic_fstream@_WU?$char_traits@_W@std@@@std@@QEAA@PEBDHH@Z");
637         SET(p_basic_fstream_wchar_vbase_dtor,
638             "??_D?$basic_fstream@_WU?$char_traits@_W@std@@@std@@QEAAXXZ");
639
640         SET(p_basic_istream_char_read_uint64,
641             "??5?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@AEA_K@Z");
642         SET(p_basic_istream_char_read_double,
643             "??5?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@AEAN@Z");
644         SET(p_basic_istream_char_get,
645             "?get@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAHXZ");
646         SET(p_basic_istream_char_ipfx,
647             "?ipfx@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAA_N_N@Z");
648         SET(p_basic_istream_char_ignore,
649             "?ignore@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@_JH@Z");
650         SET(p_basic_istream_char_seekg,
651             "?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@_JH@Z");
652         SET(p_basic_istream_char_seekg_fpos,
653             "?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@V?$fpos@H@2@@Z");
654         SET(p_basic_istream_char_peek,
655             "?peek@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAHXZ");
656         SET(p_basic_istream_char_tellg,
657             "?tellg@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAA?AV?$fpos@H@2@XZ");
658         SET(p_basic_istream_char_getline_bstr_delim,
659             "??$getline@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@YAAEAV?$basic_istream@DU?$char_traits@D@std@@@0@AEAV10@AEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@D@Z");
660
661         SET(p_basic_istream_wchar_read_uint64,
662             "??5?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV01@AEA_K@Z");
663         SET(p_basic_istream_wchar_read_double,
664             "??5?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV01@AEAN@Z");
665         SET(p_basic_istream_wchar_get,
666             "?get@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAGXZ");
667         SET(p_basic_istream_wchar_ipfx,
668             "?ipfx@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAA_N_N@Z");
669         SET(p_basic_istream_wchar_ignore,
670             "?ignore@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV12@_JG@Z");
671         SET(p_basic_istream_wchar_seekg,
672             "?seekg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV12@_JH@Z");
673         SET(p_basic_istream_wchar_seekg_fpos,
674             "?seekg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV12@V?$fpos@H@2@@Z");
675         SET(p_basic_istream_wchar_peek,
676             "?peek@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAGXZ");
677         SET(p_basic_istream_wchar_tellg,
678             "?tellg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAA?AV?$fpos@H@2@XZ");
679         SET(p_basic_istream_wchar_getline_bstr_delim,
680             "??$getline@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@YAAEAV?$basic_istream@_WU?$char_traits@_W@std@@@0@AEAV10@AEAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@0@_W@Z");
681
682         SET(p_basic_ostream_char_print_double,
683             "??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@N@Z");
684
685         SET(p_basic_ostream_wchar_print_double,
686             "??6?$basic_ostream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV01@N@Z");
687
688         SET(p_ios_base_rdstate,
689             "?rdstate@ios_base@std@@QEBAHXZ");
690         SET(p_ios_base_setf_mask,
691             "?setf@ios_base@std@@QEAAHHH@Z");
692         SET(p_ios_base_unsetf,
693             "?unsetf@ios_base@std@@QEAAXH@Z");
694         SET(p_ios_base_precision_set,
695             "?precision@ios_base@std@@QEAA_J_J@Z");
696
697         SET(p_basic_ios_char_imbue,
698             "?imbue@?$basic_ios@DU?$char_traits@D@std@@@std@@QEAA?AVlocale@2@AEBV32@@Z");
699
700         SET(p_basic_ios_wchar_imbue,
701             "?imbue@?$basic_ios@_WU?$char_traits@_W@std@@@std@@QEAA?AVlocale@2@AEBV32@@Z");
702
703         SET(p_locale_ctor_cstr,
704             "??0locale@std@@QEAA@PEBDH@Z");
705         SET(p_locale_dtor,
706             "??1locale@std@@QEAA@XZ");
707
708         SET(p_basic_string_char_ctor_cstr,
709                 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@PEBD@Z");
710         SET(p_basic_string_char_cstr,
711                 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
712         SET(p_basic_string_char_dtor,
713                 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
714
715         SET(p_basic_string_wchar_ctor_cstr,
716                 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@PEB_W@Z");
717         SET(p_basic_string_wchar_cstr,
718                 "?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAPEB_WXZ");
719         SET(p_basic_string_wchar_dtor,
720                 "??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@XZ");
721     } else {
722         SET(p_basic_stringstream_char_ctor,
723             "??_F?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ");
724         SET(p_basic_stringstream_char_ctor_str,
725             "??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");
726         SET(p_basic_stringstream_char_str_get,
727             "?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");
728         SET(p_basic_stringstream_char_vbase_dtor,
729             "??_D?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ");
730
731         SET(p_basic_stringstream_wchar_ctor,
732             "??_F?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEXXZ");
733         SET(p_basic_stringstream_wchar_ctor_str,
734             "??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");
735         SET(p_basic_stringstream_wchar_str_get,
736             "?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");
737         SET(p_basic_stringstream_wchar_vbase_dtor,
738             "??_D?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEXXZ");
739
740         SET(p_basic_fstream_char_ctor_name,
741             "??0?$basic_fstream@DU?$char_traits@D@std@@@std@@QAE@PBDHH@Z");
742         SET(p_basic_fstream_char_vbase_dtor,
743             "??_D?$basic_fstream@DU?$char_traits@D@std@@@std@@QAEXXZ");
744
745         SET(p_basic_fstream_wchar_ctor_name,
746             "??0?$basic_fstream@_WU?$char_traits@_W@std@@@std@@QAE@PBDHH@Z");
747         SET(p_basic_fstream_wchar_vbase_dtor,
748             "??_D?$basic_fstream@_WU?$char_traits@_W@std@@@std@@QAEXXZ");
749
750         SET(p_basic_istream_char_read_uint64,
751             "??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AA_K@Z");
752         SET(p_basic_istream_char_read_double,
753             "??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAN@Z");
754         SET(p_basic_istream_char_get,
755             "?get@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEHXZ");
756         SET(p_basic_istream_char_ipfx,
757             "?ipfx@?$basic_istream@DU?$char_traits@D@std@@@std@@QAE_N_N@Z");
758         SET(p_basic_istream_char_ignore,
759             "?ignore@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV12@HH@Z");
760         SET(p_basic_istream_char_seekg,
761             "?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV12@JH@Z");
762         SET(p_basic_istream_char_seekg_fpos,
763             "?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV12@V?$fpos@H@2@@Z");
764         SET(p_basic_istream_char_peek,
765             "?peek@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEHXZ");
766         SET(p_basic_istream_char_tellg,
767             "?tellg@?$basic_istream@DU?$char_traits@D@std@@@std@@QAE?AV?$fpos@H@2@XZ");
768         SET(p_basic_istream_char_getline_bstr_delim,
769             "??$getline@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@YAAAV?$basic_istream@DU?$char_traits@D@std@@@0@AAV10@AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@D@Z");
770
771         SET(p_basic_istream_wchar_read_uint64,
772             "??5?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV01@AA_K@Z");
773         SET(p_basic_istream_wchar_read_double,
774             "??5?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV01@AAN@Z");
775         SET(p_basic_istream_wchar_get,
776             "?get@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEGXZ");
777         SET(p_basic_istream_wchar_ipfx,
778             "?ipfx@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAE_N_N@Z");
779         SET(p_basic_istream_wchar_ignore,
780             "?ignore@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV12@HG@Z");
781         SET(p_basic_istream_wchar_seekg,
782             "?seekg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV12@JH@Z");
783         SET(p_basic_istream_wchar_seekg_fpos,
784             "?seekg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV12@V?$fpos@H@2@@Z");
785         SET(p_basic_istream_wchar_peek,
786             "?peek@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEGXZ");
787         SET(p_basic_istream_wchar_tellg,
788             "?tellg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAE?AV?$fpos@H@2@XZ");
789         SET(p_basic_istream_wchar_getline_bstr_delim,
790             "??$getline@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@YAAAV?$basic_istream@_WU?$char_traits@_W@std@@@0@AAV10@AAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@0@_W@Z");
791
792         SET(p_basic_ostream_char_print_double,
793             "??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@N@Z");
794
795         SET(p_basic_ostream_wchar_print_double,
796             "??6?$basic_ostream@_WU?$char_traits@_W@std@@@std@@QAEAAV01@N@Z");
797
798         SET(p_ios_base_rdstate,
799             "?rdstate@ios_base@std@@QBEHXZ");
800         SET(p_ios_base_setf_mask,
801             "?setf@ios_base@std@@QAEHHH@Z");
802         SET(p_ios_base_unsetf,
803             "?unsetf@ios_base@std@@QAEXH@Z");
804         SET(p_ios_base_precision_set,
805             "?precision@ios_base@std@@QAEHH@Z");
806
807         SET(p_basic_ios_char_imbue,
808             "?imbue@?$basic_ios@DU?$char_traits@D@std@@@std@@QAE?AVlocale@2@ABV32@@Z");
809
810         SET(p_basic_ios_wchar_imbue,
811             "?imbue@?$basic_ios@_WU?$char_traits@_W@std@@@std@@QAE?AVlocale@2@ABV32@@Z");
812
813         SET(p_locale_ctor_cstr,
814             "??0locale@std@@QAE@PBDH@Z");
815         SET(p_locale_dtor,
816             "??1locale@std@@QAE@XZ");
817
818         SET(p_basic_string_char_ctor_cstr,
819                 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z");
820         SET(p_basic_string_char_cstr,
821                 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
822         SET(p_basic_string_char_dtor,
823                 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
824
825         SET(p_basic_string_wchar_ctor_cstr,
826                 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@PB_W@Z");
827         SET(p_basic_string_wchar_cstr,
828                 "?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEPB_WXZ");
829         SET(p_basic_string_wchar_dtor,
830                 "??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@XZ");
831     }
832
833     init_thiscall_thunk();
834     return TRUE;
835 }
836
837 /* convert a dll name A->W without depending on the current codepage */
838 static wchar_t *AtoW( wchar_t *nameW, const char *nameA, unsigned int len )
839 {
840     unsigned int i;
841
842     for (i = 0; i < len; i++) nameW[i] = nameA[i];
843     nameW[i] = 0;
844     return nameW;
845 }
846
847 static void test_num_get_get_uint64(void)
848 {
849     unsigned short testus, nextus;
850     basic_stringstream_wchar wss;
851     basic_stringstream_char ss;
852     basic_string_wchar wstr;
853     basic_string_char str;
854     IOSB_iostate state;
855     locale lcl, retlcl;
856     wchar_t wide[64];
857     ULONGLONG val;
858     int i, next;
859
860     /* makes tables narrower */
861     const IOSB_iostate IOSTATE_faileof = IOSTATE_failbit|IOSTATE_eofbit;
862
863     struct _test_num_get {
864         const char    *str;
865         const char    *lcl;
866         IOSB_fmtflags fmtfl;
867         IOSB_iostate  state;
868         ULONGLONG     val;
869         int           next;
870     } tests[] = {
871         /* simple cases */
872         { "0",        NULL, FMTFLAG_dec, IOSTATE_eofbit,  0,       EOF },
873         { "1234567",  NULL, FMTFLAG_dec, IOSTATE_eofbit,  1234567, EOF },
874         { "+1234567", NULL, FMTFLAG_dec, IOSTATE_eofbit,  1234567, EOF },
875         { "-1234567", NULL, FMTFLAG_dec, IOSTATE_eofbit, -1234567, EOF },
876         { "",         NULL, FMTFLAG_dec, IOSTATE_faileof, 42,      EOF },
877
878         /* different bases */
879         /* (with and without zero are both tested, since 0 can signal a prefix check) */
880         { "0x1000",   NULL, FMTFLAG_hex, IOSTATE_eofbit, 4096, EOF }, /* lowercase x */
881         { "0X1000",   NULL, FMTFLAG_hex, IOSTATE_eofbit, 4096, EOF }, /* uppercase X */
882         { "010",      NULL, FMTFLAG_hex, IOSTATE_eofbit, 16,   EOF },
883         { "010",      NULL, FMTFLAG_dec, IOSTATE_eofbit, 10,   EOF },
884         { "010",      NULL, FMTFLAG_oct, IOSTATE_eofbit, 8,    EOF },
885         { "10",       NULL, FMTFLAG_hex, IOSTATE_eofbit, 16,   EOF },
886         { "10",       NULL, FMTFLAG_dec, IOSTATE_eofbit, 10,   EOF },
887         { "10",       NULL, FMTFLAG_oct, IOSTATE_eofbit, 8,    EOF },
888         { "10",       NULL, 0,           IOSTATE_eofbit, 10,   EOF }, /* discover dec */
889         { "010",      NULL, 0,           IOSTATE_eofbit, 8,    EOF }, /* discover oct */
890         { "0xD",      NULL, 0,           IOSTATE_eofbit, 13,   EOF }, /* discover hex (upper) */
891         { "0xd",      NULL, 0,           IOSTATE_eofbit, 13,   EOF }, /* discover hex (lower) */
892
893         /* test grouping - default/"C" has no grouping, named English/German locales do */
894         { "0.", NULL,       FMTFLAG_dec, IOSTATE_goodbit, 0,  '.' },
895         { "0,", NULL,       FMTFLAG_dec, IOSTATE_goodbit, 0,  ',' },
896         { "0,", "English",  FMTFLAG_dec, IOSTATE_faileof, 42, EOF }, /* trailing group with , */
897         { "0.", "German",   FMTFLAG_dec, IOSTATE_faileof, 42, EOF }, /* trailing group with . */
898         { "0,", "German",   FMTFLAG_dec, IOSTATE_goodbit, 0,  ',' },
899         { ",0", "English",  FMTFLAG_dec, IOSTATE_failbit, 42, EOF }, /* empty group at start */
900
901         { "1,234,567",   NULL,      FMTFLAG_dec, IOSTATE_goodbit, 1,        ',' }, /* no grouping */
902         { "1,234,567",   "English", FMTFLAG_dec, IOSTATE_eofbit,  1234567,  EOF }, /* grouping with , */
903         { "1.234.567",   "German",  FMTFLAG_dec, IOSTATE_eofbit,  1234567,  EOF }, /* grouping with . */
904         { "1,,234",      NULL,      FMTFLAG_dec, IOSTATE_goodbit, 1,        ',' }, /* empty group */
905         { "1,,234",      "English", FMTFLAG_dec, IOSTATE_failbit, 42,       EOF }, /* empty group */
906         { "0x1,000,000", "English", FMTFLAG_hex, IOSTATE_eofbit,  16777216, EOF }, /* yeah, hex can group */
907         { "1,23,34",     "English", FMTFLAG_dec, IOSTATE_faileof, 42,       EOF }, /* invalid size group */
908         { "0,123",       "English", FMTFLAG_dec, IOSTATE_eofbit,  123,      EOF }, /* 0 solo in group */
909
910         { "18446744073709551615", NULL, FMTFLAG_dec, IOSTATE_eofbit,  ~0, EOF }, /* max value */
911         { "99999999999999999999", NULL, FMTFLAG_dec, IOSTATE_faileof, 42, EOF }, /* invalid value */
912
913         /* test invalid formats */
914         { "0000x10", NULL, FMTFLAG_hex, IOSTATE_goodbit, 0,  'x' },
915         { "x10",     NULL, FMTFLAG_hex, IOSTATE_failbit, 42, EOF },
916         { "0xx10",   NULL, FMTFLAG_hex, IOSTATE_failbit, 42, EOF },
917     };
918
919     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
920         /* char version */
921         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
922         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
923
924         if(tests[i].lcl) {
925             call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
926             call_func3(p_basic_ios_char_imbue, &ss.basic_ios, &retlcl, &lcl);
927         }
928
929         val = 42;
930         call_func3(p_ios_base_setf_mask, &ss.basic_ios.base, tests[i].fmtfl, FMTFLAG_basefield);
931         call_func2(p_basic_istream_char_read_uint64, &ss.base.base1, &val);
932         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
933         next  = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
934
935         if(state==IOSTATE_faileof && tests[i].val==~0) {
936             /* Maximal uint64 test is broken on 9.0.21022.8 */
937             skip("basic_istream_char_read_uint64(MAX_UINT64) is broken\n");
938             continue;
939         }
940
941         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
942         ok(tests[i].val   == val,   "wrong val, expected = %lx%08lx found %lx%08lx\n", (unsigned long)(tests[i].val >> 32),
943                 (unsigned long)tests[i].val, (unsigned long)(val >> 32), (unsigned long)val);
944         ok(tests[i].next  == next,  "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
945
946         if(tests[i].lcl)
947             call_func1(p_locale_dtor, &lcl);
948
949         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
950         call_func1(p_basic_string_char_dtor, &str);
951
952         /* wchar_t version */
953         AtoW(wide, tests[i].str, strlen(tests[i].str));
954         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
955         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
956
957         if(tests[i].lcl) {
958             call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
959             call_func3(p_basic_ios_wchar_imbue, &wss.basic_ios, &retlcl, &lcl);
960         }
961
962         val = 42;
963         call_func3(p_ios_base_setf_mask, &wss.basic_ios.base, tests[i].fmtfl, FMTFLAG_basefield);
964         call_func2(p_basic_istream_wchar_read_uint64, &wss.base.base1, &val);
965         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
966         nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
967
968         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
969         ok(tests[i].val == val, "wrong val, expected = %lx%08lx found %lx%08lx\n", (unsigned long)(tests[i].val >> 32),
970                 (unsigned long)tests[i].val, (unsigned long)(val >> 32), (unsigned long)val);
971         testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
972         ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
973
974         if(tests[i].lcl)
975             call_func1(p_locale_dtor, &lcl);
976
977         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
978         call_func1(p_basic_string_wchar_dtor, &wstr);
979     }
980 }
981
982
983 static void test_num_get_get_double(void)
984 {
985     unsigned short testus, nextus;
986     basic_stringstream_wchar wss;
987     basic_stringstream_char ss;
988     basic_string_wchar wstr;
989     basic_string_char str;
990     IOSB_iostate state;
991     locale lcl, retlcl;
992     wchar_t wide[64];
993     int i, next;
994     double val;
995
996     /* makes tables narrower */
997     const IOSB_iostate IOSTATE_faileof = IOSTATE_failbit|IOSTATE_eofbit;
998
999     struct _test_num_get {
1000         const char    *str;
1001         const char    *lcl;
1002         IOSB_iostate  state;
1003         double        val;
1004         int           next;
1005     } tests[] = {
1006         /* simple cases */
1007         { "0",     NULL, IOSTATE_eofbit,  0.0,  EOF },
1008         { "10",    NULL, IOSTATE_eofbit,  10.0, EOF },
1009         { "+10",   NULL, IOSTATE_eofbit,  10.0, EOF },
1010         { "-10",   NULL, IOSTATE_eofbit, -10.0, EOF },
1011         { "+010",  NULL, IOSTATE_eofbit,  10.0, EOF }, /* leading zero */
1012
1013         /* test grouping - default/"C" has no grouping, named English/German locales do */
1014         { "1,000", NULL,         IOSTATE_goodbit,  1.0,      ',' }, /* with comma */
1015         { "1,000", "English",    IOSTATE_eofbit,   1000.0,   EOF },
1016         { "1,000", "German",     IOSTATE_eofbit,   1.0,      EOF },
1017
1018         { "1.000", NULL,         IOSTATE_eofbit,   1.0,      EOF }, /* with period */
1019         { "1.000", "English",    IOSTATE_eofbit,   1.0,      EOF },
1020         { "1.000", "German",     IOSTATE_eofbit,   1000.0,   EOF },
1021
1022         { "1,234.",  NULL,       IOSTATE_goodbit,  1.0,      ',' },
1023         { "1,234.",  "English",  IOSTATE_eofbit,   1234.0,   EOF }, /* trailing decimal */
1024         { "1,234.",  "German",   IOSTATE_goodbit,  1.234,    '.' },
1025         { "1,234.5", "English",  IOSTATE_eofbit,   1234.5,   EOF }, /* group + decimal */
1026         { "1,234.5", "German",   IOSTATE_goodbit,  1.234,    '.' },
1027
1028         { "1,234,567,890", NULL,      IOSTATE_goodbit, 1.0,          ',' }, /* more groups */
1029         { "1,234,567,890", "English", IOSTATE_eofbit,  1234567890.0, EOF },
1030         { "1,234,567,890", "German",  IOSTATE_goodbit, 1.234,        ',' },
1031         { "1.234.567.890", "German",  IOSTATE_eofbit,  1234567890.0, EOF },
1032
1033         /* extra digits and stuff */
1034         { "00000.123456", NULL,  IOSTATE_eofbit,  0.123456, EOF },
1035         { "0.1234560000", NULL,  IOSTATE_eofbit,  0.123456, EOF },
1036         { "100aaaa",      NULL,  IOSTATE_goodbit, 100.0,    'a' },
1037
1038         /* exponent */
1039         { "10e10",       NULL,      IOSTATE_eofbit,    10e10,      EOF }, /* lowercase e */
1040         { "10E10",       NULL,      IOSTATE_eofbit,    10E10,      EOF }, /* uppercase E */
1041         { "10e+10",      NULL,      IOSTATE_eofbit,    10e10,      EOF }, /* sign */
1042         { "10e-10",      NULL,      IOSTATE_eofbit,    10e-10,     EOF },
1043         { "10.e10",      NULL,      IOSTATE_eofbit,    10e10,      EOF }, /* trailing decimal before exponent */
1044         { "-10.e-10",    NULL,      IOSTATE_eofbit,   -10e-10,     EOF },
1045         { "-12.345e-10", NULL,      IOSTATE_eofbit,   -12.345e-10, EOF },
1046         { "1,234e10",    NULL,      IOSTATE_goodbit,   1.0,        ',' },
1047         { "1,234e10",    "English", IOSTATE_eofbit,    1234.0e10,  EOF },
1048         { "1,234e10",    "German",  IOSTATE_eofbit,    1.234e10,   EOF },
1049         { "1.0e999",     NULL,      IOSTATE_faileof,   42.0,       EOF }, /* too big   */
1050         { "1.0e-999",    NULL,      IOSTATE_faileof,   42.0,       EOF }, /* too small */
1051
1052         /* bad form */
1053         { "1,000,", NULL,       IOSTATE_goodbit, 1.0,   ',' }, /* trailing group */
1054         { "1,000,", "English",  IOSTATE_faileof, 42.0,  EOF },
1055         { "1.000.", "German",   IOSTATE_faileof, 42.0,  EOF },
1056
1057         { "1,,000", NULL,       IOSTATE_goodbit, 1.0,   ',' }, /* empty group */
1058         { "1,,000", "English",  IOSTATE_failbit, 42.0,  EOF },
1059         { "1..000", "German",   IOSTATE_failbit, 42.0,  EOF },
1060
1061         { "1.0,00", "English",  IOSTATE_goodbit, 1.0,   ',' },
1062         { "1.0,00", "German",   IOSTATE_faileof, 42.0,  EOF },
1063
1064         { "1.0ee10", NULL,      IOSTATE_failbit, 42.0,  EOF }, /* dup exp */
1065         { "1.0e1.0", NULL,      IOSTATE_goodbit, 10.0,  '.' }, /* decimal in exponent */
1066         { "1.0e1,0", NULL,      IOSTATE_goodbit, 10.0,  ',' }, /* group in exponent */
1067     };
1068
1069     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1070         /* char version */
1071         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1072         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1073
1074         if(tests[i].lcl) {
1075             call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
1076             call_func3(p_basic_ios_char_imbue, &ss.basic_ios, &retlcl, &lcl);
1077         }
1078
1079         val = 42.0;
1080         call_func2(p_basic_istream_char_read_double, &ss.base.base1, &val);
1081         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1082         next  = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
1083
1084         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1085         ok(tests[i].val   == val,   "wrong val, expected = %g found %g\n", tests[i].val, val);
1086         ok(tests[i].next  == next,  "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
1087
1088         if(tests[i].lcl)
1089             call_func1(p_locale_dtor, &lcl);
1090
1091         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1092         call_func1(p_basic_string_char_dtor, &str);
1093
1094         /* wchar_t version */
1095         AtoW(wide, tests[i].str, strlen(tests[i].str));
1096         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1097         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1098
1099         if(tests[i].lcl) {
1100             call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
1101             call_func3(p_basic_ios_wchar_imbue, &wss.basic_ios, &retlcl, &lcl);
1102         }
1103
1104         val = 42.0;
1105         call_func2(p_basic_istream_wchar_read_double, &wss.base.base1, &val);
1106         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1107         nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
1108
1109         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1110         ok(tests[i].val == val, "wrong val, expected = %g found %g\n", tests[i].val, val);
1111         testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
1112         ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
1113
1114         if(tests[i].lcl)
1115             call_func1(p_locale_dtor, &lcl);
1116
1117         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1118         call_func1(p_basic_string_wchar_dtor, &wstr);
1119     }
1120 }
1121
1122
1123 static void test_num_put_put_double(void)
1124 {
1125     basic_stringstream_wchar wss;
1126     basic_stringstream_char ss;
1127     basic_string_wchar pwstr;
1128     basic_string_char pstr;
1129     locale lcl, retlcl;
1130     const wchar_t *wstr;
1131     const char *str;
1132     wchar_t wide[64];
1133     int i;
1134
1135     struct _test_num_get {
1136         double        val;
1137         const char    *lcl;
1138         streamsize    prec;  /* set to -1 for default */
1139         IOSB_fmtflags fmtfl; /* FMTFLAG_scientific, FMTFLAG_fixed */
1140         const char    *str;
1141     } tests[] = {
1142         { 0.0, NULL, -1, 0, "0" },
1143
1144         /* simple cases */
1145         { 0.123, NULL, -1, 0, "0.123" },
1146         { 0.123, NULL,  6, 0, "0.123" },
1147         { 0.123, NULL,  0, 0, "0.123" },
1148
1149         /* fixed format */
1150         { 0.123, NULL, -1, FMTFLAG_fixed, "0.123000" },
1151         { 0.123, NULL,  6, FMTFLAG_fixed, "0.123000" },
1152         { 0.123, NULL,  0, FMTFLAG_fixed, "0" },
1153
1154         /* scientific format */
1155         { 123456.789, NULL,    -1, FMTFLAG_scientific, "1.234568e+005"    },
1156         { 123456.789, NULL,     0, FMTFLAG_scientific, "1.234568e+005"    },
1157         { 123456.789, NULL,     9, FMTFLAG_scientific, "1.234567890e+005" },
1158         { 123456.789, "German", 9, FMTFLAG_scientific, "1,234567890e+005" },
1159
1160         /* different locales */
1161         { 0.123, "C",       -1, 0, "0.123" },
1162         { 0.123, "English", -1, 0, "0.123" },
1163         { 0.123, "German",  -1, 0, "0,123" },
1164
1165         { 123456.789, "C",       -1, 0, "123457"  },
1166         { 123456.789, "English", -1, 0, "123,457" },
1167         { 123456.789, "German",  -1, 0, "123.457" },
1168
1169         /* signs and exponents */
1170         {  1.0e-9, NULL, -1, 0, "1e-009"  },
1171         {  1.0e-9, NULL,  9, 0, "1e-009"  },
1172         { -1.0e9,  NULL, -1, 0, "-1e+009" },
1173         { -1.0e9,  NULL,  9, 0, "-1e+009" },
1174
1175         {  1.0e-9, NULL, 0, FMTFLAG_fixed, "0"                  },
1176         {  1.0e-9, NULL, 6, FMTFLAG_fixed, "0.000000"           },
1177         {  1.0e-9, NULL, 9, FMTFLAG_fixed, "0.000000001"        },
1178         { -1.0e9,  NULL, 0, FMTFLAG_fixed, "-1000000000"        },
1179         { -1.0e9,  NULL, 6, FMTFLAG_fixed, "-1000000000.000000" },
1180
1181         { -1.23456789e9,  NULL, 0, 0,             "-1.23457e+009"      },
1182         { -1.23456789e9,  NULL, 0, FMTFLAG_fixed, "-1234567890"        },
1183         { -1.23456789e9,  NULL, 6, FMTFLAG_fixed, "-1234567890.000000" },
1184         { -1.23456789e-9, NULL, 6, FMTFLAG_fixed, "-0.000000"          },
1185         { -1.23456789e-9, NULL, 9, FMTFLAG_fixed, "-0.000000001"       }
1186     };
1187
1188     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1189         /* char version */
1190         call_func2(p_basic_stringstream_char_ctor, &ss, TRUE);
1191
1192         if(tests[i].lcl) {
1193             call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
1194             call_func3(p_basic_ios_char_imbue, &ss.basic_ios, &retlcl, &lcl);
1195         }
1196
1197         /* set format and precision only if specified, so we can try defaults */
1198         if(tests[i].fmtfl)
1199             call_func3(p_ios_base_setf_mask, &ss.basic_ios.base, tests[i].fmtfl, FMTFLAG_floatfield);
1200         if(tests[i].prec != -1)
1201             call_func2(p_ios_base_precision_set, &ss.basic_ios.base, tests[i].prec);
1202         call_func2_ptr_dbl(p_basic_ostream_char_print_double, &ss.base.base2, tests[i].val);
1203
1204         call_func2(p_basic_stringstream_char_str_get, &ss, &pstr);
1205         str = call_func1(p_basic_string_char_cstr, &pstr);
1206
1207         ok(!strcmp(tests[i].str, str), "wrong output, expected = %s found = %s\n", tests[i].str, str);
1208         call_func1(p_basic_string_char_dtor, &pstr);
1209
1210         if(tests[i].lcl)
1211             call_func1(p_locale_dtor, &lcl);
1212
1213         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1214
1215         /* wchar_t version */
1216         call_func2(p_basic_stringstream_wchar_ctor, &wss, TRUE);
1217
1218         if(tests[i].lcl) {
1219             call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
1220             call_func3(p_basic_ios_wchar_imbue, &wss.basic_ios, &retlcl, &lcl);
1221         }
1222
1223         /* set format and precision only if specified, so we can try defaults */
1224         if(tests[i].fmtfl)
1225             call_func3(p_ios_base_setf_mask, &wss.basic_ios.base, tests[i].fmtfl, FMTFLAG_floatfield);
1226         if(tests[i].prec != -1)
1227             call_func2(p_ios_base_precision_set, &wss.basic_ios.base, tests[i].prec);
1228         call_func2_ptr_dbl(p_basic_ostream_wchar_print_double, &wss.base.base2, tests[i].val);
1229
1230         call_func2(p_basic_stringstream_wchar_str_get, &wss, &pwstr);
1231         wstr = call_func1(p_basic_string_wchar_cstr, &pwstr);
1232
1233         AtoW(wide, tests[i].str, strlen(tests[i].str));
1234         ok(!lstrcmpW(wide, wstr), "wrong output, expected = %s found = %s\n", tests[i].str, wine_dbgstr_w(wstr));
1235         call_func1(p_basic_string_wchar_dtor, &pwstr);
1236
1237         if(tests[i].lcl)
1238             call_func1(p_locale_dtor, &lcl);
1239
1240         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1241     }
1242 }
1243
1244
1245 static void test_istream_ipfx(void)
1246 {
1247     unsigned short testus, nextus;
1248     basic_stringstream_wchar wss;
1249     basic_stringstream_char ss;
1250     basic_string_wchar wstr;
1251     basic_string_char str;
1252     IOSB_iostate state;
1253     wchar_t wide[64];
1254     int i, ret, next;
1255
1256     /* makes tables narrower */
1257     const IOSB_iostate IOSTATE_faileof = IOSTATE_failbit|IOSTATE_eofbit;
1258
1259     struct _test_istream_ipfx {
1260         const char  *str;
1261         int          unset_skipws;
1262         int          noskip;
1263         int          ret;
1264         IOSB_iostate state;
1265         int          next;
1266     } tests[] = {
1267         /* string       unset  noskip return state            next char */
1268         { "",           FALSE, FALSE, FALSE, IOSTATE_faileof, EOF  }, /* empty string */
1269         { "   ",        FALSE, FALSE, FALSE, IOSTATE_faileof, EOF  }, /* just ws */
1270         { "\t \n \f ",  FALSE, FALSE, FALSE, IOSTATE_faileof, EOF  }, /* different ws */
1271         { "simple",     FALSE, FALSE, TRUE,  IOSTATE_goodbit, 's'  },
1272         { "  simple",   FALSE, FALSE, TRUE,  IOSTATE_goodbit, 's'  },
1273         { "  simple",   TRUE,  FALSE, TRUE,  IOSTATE_goodbit, ' '  }, /* unset skipws */
1274         { "  simple",   FALSE, TRUE,  TRUE,  IOSTATE_goodbit, ' '  }, /* ipfx(true) */
1275         { "  simple",   TRUE,  TRUE,  TRUE,  IOSTATE_goodbit, ' '  }, /* both */
1276         { "\n\t ws",    FALSE, FALSE, TRUE,  IOSTATE_goodbit, 'w'  },
1277         { "\n\t ws",    TRUE,  FALSE, TRUE,  IOSTATE_goodbit, '\n' },
1278     };
1279
1280     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1281         /* char version */
1282         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1283         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1284
1285         /* set format and precision only if specified, so we can try defaults */
1286         if(tests[i].unset_skipws)
1287             call_func2(p_ios_base_unsetf, &ss.basic_ios.base, TRUE);
1288
1289         ret   = (int)call_func2(p_basic_istream_char_ipfx, &ss.base.base1, tests[i].noskip);
1290         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1291         next  = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
1292
1293         ok(tests[i].ret   == ret,   "wrong return, expected = %i found = %i\n", tests[i].ret, ret);
1294         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1295         ok(tests[i].next  == next,  "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
1296
1297         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1298         call_func1(p_basic_string_char_dtor, &str);
1299
1300         /* wchar_t version */
1301         AtoW(wide, tests[i].str, strlen(tests[i].str));
1302         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1303         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1304
1305         /* set format and precision only if specified, so we can try defaults */
1306         if(tests[i].unset_skipws)
1307             call_func2(p_ios_base_unsetf, &wss.basic_ios.base, TRUE);
1308
1309         ret    = (int)call_func2(p_basic_istream_wchar_ipfx, &wss.base.base1, tests[i].noskip);
1310         state  = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1311         nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
1312
1313         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1314         ok(tests[i].ret == ret, "wrong return, expected = %i found = %i\n", tests[i].ret, ret);
1315         testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
1316         ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
1317
1318         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1319         call_func1(p_basic_string_wchar_dtor, &wstr);
1320     }
1321 }
1322
1323
1324 static void test_istream_ignore(void)
1325 {
1326     unsigned short testus, nextus;
1327     basic_stringstream_wchar wss;
1328     basic_stringstream_char ss;
1329     basic_string_wchar wstr;
1330     basic_string_char str;
1331     IOSB_iostate state;
1332     wchar_t wide[64];
1333     int i, next;
1334
1335     struct _test_istream_ignore {
1336         const char  *str;
1337         streamsize   count;
1338         int          delim;
1339         IOSB_iostate state;
1340         int          next;
1341     } tests[] = {
1342         /* string       count delim state            next */
1343         { "",           0,    '\n', IOSTATE_goodbit, EOF }, /* empty string */
1344
1345         /* different counts */
1346         { "ABCDEF",     2,    '\n', IOSTATE_goodbit, 'C' }, /* easy case */
1347         { "ABCDEF",     42,   '\n', IOSTATE_eofbit,  EOF }, /* ignore too much */
1348         { "ABCDEF",    -2,    '\n', IOSTATE_goodbit, 'A' }, /* negative count */
1349         { "ABCDEF",     6,    '\n', IOSTATE_goodbit, EOF }, /* is eof not set at end */
1350         { "ABCDEF",     7,    '\n', IOSTATE_eofbit,  EOF }, /* eof is set just after end */
1351
1352         /* different delimiters */
1353         { "ABCDEF",       42, '\0', IOSTATE_eofbit,  EOF }, /* null as delim */
1354         { "ABC DEF GHI",  0,  ' ',  IOSTATE_goodbit, 'A' },
1355         { "ABC DEF GHI",  42, ' ',  IOSTATE_goodbit, 'D' },
1356         { "ABC DEF\tGHI", 42, '\t', IOSTATE_goodbit, 'G' },
1357         { "ABC ",         42, ' ',  IOSTATE_goodbit, EOF }, /* delim at end */
1358     };
1359
1360     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1361         /* char version */
1362         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1363         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1364
1365         call_func3(p_basic_istream_char_ignore, &ss.base.base1, tests[i].count, tests[i].delim);
1366         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1367         next  = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
1368
1369         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1370         ok(tests[i].next  == next,  "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
1371
1372         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1373         call_func1(p_basic_string_char_dtor, &str);
1374
1375         /* wchar_t version */
1376         AtoW(wide, tests[i].str, strlen(tests[i].str));
1377         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1378         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1379
1380         call_func3(p_basic_istream_wchar_ignore, &wss.base.base1, tests[i].count, tests[i].delim);
1381         state  = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1382         nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
1383
1384         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1385         testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
1386         ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
1387
1388         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1389         call_func1(p_basic_string_wchar_dtor, &wstr);
1390     }
1391 }
1392
1393
1394 static void test_istream_seekg(void)
1395 {
1396     unsigned short testus, nextus;
1397     basic_stringstream_wchar wss;
1398     basic_stringstream_char ss;
1399     basic_string_wchar wstr;
1400     basic_string_char str;
1401     IOSB_iostate state;
1402     wchar_t wide[64];
1403     int i, next;
1404
1405     struct _test_istream_seekg {
1406         const char  *str;
1407         streamoff    off;
1408         IOSB_seekdir dir;
1409         IOSB_iostate state;
1410         int          next;
1411     } tests[] = {
1412         { "ABCDEFGHIJ",  0, SEEKDIR_beg, IOSTATE_goodbit, 'A' },
1413         { "ABCDEFGHIJ",  1, SEEKDIR_beg, IOSTATE_goodbit, 'B' },
1414         { "ABCDEFGHIJ",  5, SEEKDIR_cur, IOSTATE_goodbit, 'F' },
1415         { "ABCDEFGHIJ", -3, SEEKDIR_end, IOSTATE_goodbit, 'H' },
1416
1417         /* bad offsets */
1418         { "ABCDEFGHIJ", -1, SEEKDIR_beg, IOSTATE_failbit, EOF },
1419         { "ABCDEFGHIJ", 42, SEEKDIR_cur, IOSTATE_failbit, EOF },
1420         { "ABCDEFGHIJ", 42, SEEKDIR_end, IOSTATE_failbit, EOF },
1421         { "",            0, SEEKDIR_beg, IOSTATE_failbit, EOF },
1422     };
1423
1424     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1425         /* char version */
1426         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1427         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1428
1429         call_func3(p_basic_istream_char_seekg, &ss.base.base1, tests[i].off, tests[i].dir);
1430         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1431         next  = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
1432
1433         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1434         ok(tests[i].next  == next,  "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
1435
1436         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1437         call_func1(p_basic_string_char_dtor, &str);
1438
1439         /* wchar_t version */
1440         AtoW(wide, tests[i].str, strlen(tests[i].str));
1441         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1442         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1443
1444         call_func3(p_basic_istream_wchar_seekg, &wss.base.base1, tests[i].off, tests[i].dir);
1445         state  = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1446         nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
1447
1448         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1449         testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
1450         ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
1451
1452         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1453         call_func1(p_basic_string_wchar_dtor, &wstr);
1454     }
1455 }
1456
1457
1458 static void test_istream_seekg_fpos(void)
1459 {
1460     unsigned short testus, nextus;
1461     basic_stringstream_wchar wss;
1462     basic_stringstream_char ss;
1463     basic_string_wchar wstr;
1464     basic_string_char str;
1465     IOSB_iostate state;
1466     wchar_t wide[64];
1467     fpos_int pos;
1468     int i, next;
1469
1470     struct _test_istream_seekg_fpos {
1471         const char  *str;
1472         streamoff    off;
1473         IOSB_iostate state;
1474         int          next;
1475     } tests[] = {
1476         { "ABCDEFGHIJ", 0,  IOSTATE_goodbit, 'A' },
1477         { "ABCDEFGHIJ", 9,  IOSTATE_goodbit, 'J' },
1478         { "ABCDEFGHIJ", 10, IOSTATE_goodbit, EOF }, /* beyond end, but still good */
1479         { "ABCDEFGHIJ", -1, IOSTATE_failbit, EOF },
1480         { "",           0,  IOSTATE_failbit, EOF },
1481     };
1482
1483     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1484         /* char version */
1485         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1486         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1487
1488         pos.off   = tests[i].off;
1489         pos.pos   = 0; /* FIXME: a later patch will test this with filebuf */
1490         pos.state = 0;
1491         call_func2_ptr_fpos(p_basic_istream_char_seekg_fpos, &ss.base.base1, pos);
1492         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1493         next  = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
1494
1495         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1496         ok(tests[i].next  == next,  "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
1497
1498         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1499         call_func1(p_basic_string_char_dtor, &str);
1500
1501         /* wchar_t version */
1502         AtoW(wide, tests[i].str, strlen(tests[i].str));
1503         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1504         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1505
1506         pos.off   = tests[i].off;
1507         pos.pos   = 0; /* FIXME: a later patch will test this with filebuf */
1508         pos.state = 0;
1509         call_func2_ptr_fpos(p_basic_istream_wchar_seekg_fpos, &wss.base.base1, pos);
1510         state  = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1511         nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
1512
1513         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1514         testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
1515         ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
1516
1517         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1518         call_func1(p_basic_string_wchar_dtor, &wstr);
1519     }
1520 }
1521
1522
1523 static void test_istream_peek(void)
1524 {
1525     unsigned short testus, nextus, peekus;
1526     basic_stringstream_wchar wss;
1527     basic_stringstream_char ss;
1528     basic_string_wchar wstr;
1529     basic_string_char str;
1530     IOSB_iostate state;
1531     int i, next, peek;
1532     wchar_t wide[64];
1533
1534     struct _test_istream_peek {
1535         const char  *str;
1536         int          peek;
1537         int          next;
1538         IOSB_iostate state;
1539     } tests[] = {
1540         { "",       EOF, EOF, IOSTATE_eofbit  },
1541         { "ABCDEF", 'A', 'A', IOSTATE_goodbit },
1542     };
1543
1544     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1545         /* char version */
1546         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1547         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1548
1549         peek  = (int)call_func1(p_basic_istream_char_peek, &ss.base.base1);
1550         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1551         next  = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
1552
1553         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1554         ok(tests[i].next  == next,  "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
1555         ok(peek == next, "wrong peek, expected %c (%i) found = %c (%i)\n", peek, peek, next, next);
1556
1557         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1558         call_func1(p_basic_string_char_dtor, &str);
1559
1560         /* wchar_t version */
1561         AtoW(wide, tests[i].str, strlen(tests[i].str));
1562         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1563         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1564
1565         peekus = (unsigned short)(int)call_func1(p_basic_istream_wchar_peek, &wss.base.base1);
1566         state  = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1567         nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
1568
1569         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1570         testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
1571         ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
1572         ok(peekus == nextus, "wrong peek, expected %c (%i) found = %c (%i)\n", peekus, peekus, nextus, nextus);
1573
1574         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1575         call_func1(p_basic_string_wchar_dtor, &wstr);
1576     }
1577 }
1578
1579
1580 static void test_istream_tellg(void)
1581 {
1582     basic_stringstream_wchar wss;
1583     basic_stringstream_char ss;
1584     basic_fstream_wchar wfs;
1585     basic_fstream_char fs;
1586     basic_string_wchar wstr;
1587     basic_string_char str;
1588     fpos_int spos, tpos, *rpos;
1589     wchar_t wide[64];
1590     FILE *file;
1591     int i;
1592
1593     const char *testfile = "file.txt";
1594
1595     struct _test_istream_tellg_fpos {
1596         const char  *str;
1597         streamoff    seekoff;
1598         streamoff    telloff_ss; /* offset for stringstream */
1599         streamoff    telloff_fs; /* offset for fstream */
1600         __int64      tellpos;
1601     } tests[] = {
1602         /* empty strings */
1603         { "", -1, -1,  0,  0 }, /* tellg on defaults */
1604         { "",  0, -1,  0,  0 }, /* tellg after seek 0 */
1605         { "", 42, -1,  0, 42 }, /* tellg after seek beyond end */
1606         { "", -6, -1, -1,  0 }, /* tellg after seek beyond beg */
1607
1608         /* non-empty strings */
1609         { "ABCDEFGHIJ", -1,  0,  0,  0 },
1610         { "ABCDEFGHIJ",  3,  3,  0,  3 },
1611         { "ABCDEFGHIJ", 42, -1,  0, 42 },
1612         { "ABCDEFGHIJ", -6, -1, -1,  0 }
1613     };
1614
1615     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1616         /* stringstream<char> version */
1617         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1618         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1619
1620         spos.off   = tests[i].seekoff;
1621         spos.pos   = 0;
1622         spos.state = 0;
1623
1624         tpos.off   = 0xdeadbeef;
1625         tpos.pos   = 0xdeadbeef;
1626         tpos.state = 0xdeadbeef;
1627
1628         if (tests[i].seekoff != -1) /* to test without seek */
1629             call_func2_ptr_fpos(p_basic_istream_char_seekg_fpos, &ss.base.base1, spos);
1630         rpos = (fpos_int *)call_func2(p_basic_istream_char_tellg, &ss.base.base1, &tpos);
1631
1632         ok(tests[i].telloff_ss == tpos.off, "wrong offset, expected = %ld found = %ld\n", tests[i].telloff_ss, tpos.off);
1633         if (tests[i].telloff_ss != -1 && spos.off != -1) /* check if tell == seek but only if not hit EOF */
1634             ok(spos.off == tpos.off, "tell doesn't match seek, seek = %ld tell = %ld\n", spos.off, tpos.off);
1635         ok(rpos == &tpos, "wrong return fpos, expected = %p found = %p\n", rpos, &tpos);
1636         ok(tpos.pos == 0, "wrong position, expected = 0 found = %s\n", debugstr_longlong(tpos.pos));
1637         ok(tpos.state == 0, "wrong state, expected = 0 found = %d\n", tpos.state);
1638
1639         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1640         call_func1(p_basic_string_char_dtor, &str);
1641
1642         /* stringstream<wchar_t> version */
1643         AtoW(wide, tests[i].str, strlen(tests[i].str));
1644         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1645         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1646
1647         spos.off   = tests[i].seekoff;
1648         spos.pos   = 0; /* FIXME: a later patch will test this with filebuf */
1649         spos.state = 0;
1650
1651         tpos.off   = 0xdeadbeef;
1652         tpos.pos   = 0xdeadbeef;
1653         tpos.state = 0xdeadbeef;
1654
1655         if (tests[i].seekoff != -1) /* to test without seek */
1656             call_func2_ptr_fpos(p_basic_istream_wchar_seekg_fpos, &wss.base.base1, spos);
1657         rpos = (fpos_int *)call_func2(p_basic_istream_wchar_tellg, &wss.base.base1, &tpos);
1658
1659         ok(tests[i].telloff_ss == tpos.off, "wrong offset, expected = %ld found = %ld\n", tests[i].telloff_ss, tpos.off);
1660         if (tests[i].telloff_ss != -1 && spos.off != -1) /* check if tell == seek but only if not hit EOF */
1661             ok(spos.off == tpos.off, "tell doesn't match seek, seek = %ld tell = %ld\n", spos.off, tpos.off);
1662         ok(rpos == &tpos, "wrong return fpos, expected = %p found = %p\n", rpos, &tpos);
1663         ok(tpos.pos == 0, "wrong position, expected = 0 found = %s\n", debugstr_longlong(tpos.pos));
1664         ok(tpos.state == 0, "wrong state, expected = 0 found = %d\n", tpos.state);
1665
1666         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1667         call_func1(p_basic_string_wchar_dtor, &wstr);
1668
1669         /* filebuf */
1670         file = fopen(testfile, "wt");
1671         fprintf(file, tests[i].str);
1672         fclose(file);
1673
1674         /* fstream<char> version */
1675         call_func5(p_basic_fstream_char_ctor_name, &fs, testfile, OPENMODE_out|OPENMODE_in, SH_DENYNO, TRUE);
1676
1677         spos.off   = tests[i].seekoff;
1678         spos.pos   = 0;
1679         spos.state = 0;
1680
1681         tpos.off   = 0xdeadbeef;
1682         tpos.pos   = 0xdeadbeef;
1683         tpos.state = 0xdeadbeef;
1684
1685         if (tests[i].seekoff != -1) /* to test without seek */
1686             call_func2_ptr_fpos(p_basic_istream_char_seekg_fpos, &fs.base.base1, spos);
1687         rpos = (fpos_int *)call_func2(p_basic_istream_char_tellg, &fs.base.base1, &tpos);
1688
1689         ok(tests[i].tellpos == tpos.pos, "wrong filepos, expected = %s found = %s\n",
1690             debugstr_longlong(tests[i].tellpos), debugstr_longlong(tpos.pos));
1691         ok(rpos == &tpos, "wrong return fpos, expected = %p found = %p\n", rpos, &tpos);
1692         ok(tpos.off == tests[i].telloff_fs, "wrong offset, expected %ld found %ld\n", tests[i].telloff_fs, tpos.off);
1693         ok(tpos.state == 0, "wrong state, expected = 0 found = %d\n", tpos.state);
1694
1695         call_func1(p_basic_fstream_char_vbase_dtor, &fs);
1696
1697         /* fstream<wchar_t> version */
1698         call_func5(p_basic_fstream_wchar_ctor_name, &wfs, testfile, OPENMODE_out|OPENMODE_in, SH_DENYNO, TRUE);
1699
1700         spos.off   = tests[i].seekoff;
1701         spos.pos   = 0;
1702         spos.state = 0;
1703
1704         tpos.off   = 0xdeadbeef;
1705         tpos.pos   = 0xdeadbeef;
1706         tpos.state = 0xdeadbeef;
1707
1708         if (tests[i].seekoff != -1) /* to test without seek */
1709             call_func2_ptr_fpos(p_basic_istream_wchar_seekg_fpos, &wfs.base.base1, spos);
1710         rpos = (fpos_int *)call_func2(p_basic_istream_wchar_tellg, &wfs.base.base1, &tpos);
1711
1712         ok(tests[i].tellpos == tpos.pos, "wrong filepos, expected = %s found = %s\n",
1713             debugstr_longlong(tests[i].tellpos), debugstr_longlong(tpos.pos));
1714         ok(rpos == &tpos, "wrong return fpos, expected = %p found = %p\n", rpos, &tpos);
1715         ok(tpos.off == tests[i].telloff_fs, "wrong offset, expected %ld found %ld\n", tests[i].telloff_fs, tpos.off);
1716         ok(tpos.state == 0, "wrong state, expected = 0 found = %d\n", tpos.state);
1717
1718         call_func1(p_basic_fstream_wchar_vbase_dtor, &wfs);
1719
1720         unlink(testfile);
1721     }
1722 }
1723
1724
1725 static void test_istream_getline(void)
1726 {
1727     basic_stringstream_wchar wss;
1728     basic_stringstream_char ss;
1729     basic_string_wchar wstr;
1730     basic_string_char str;
1731     IOSB_iostate state;
1732     wchar_t wide[64];
1733     int i;
1734     const char *cstr;
1735     const wchar_t *wcstr;
1736
1737     /* makes tables narrower */
1738     const IOSB_iostate IOSTATE_faileof = IOSTATE_failbit|IOSTATE_eofbit;
1739
1740     struct _test_istream_getline {
1741         const char  *str;
1742         const char  *line;
1743         int          delim;
1744         IOSB_iostate state;
1745         const char  *nextline;
1746         int          nextdelim;
1747         IOSB_iostate nextstate;
1748     } tests[] = {
1749         { "", "", '\n', IOSTATE_faileof, "", '\n', IOSTATE_faileof },
1750
1751         { "this\n",                 "this", '\n', IOSTATE_goodbit, "",   '\n', IOSTATE_faileof },
1752         { "this\nis\nsome\ntext\n", "this", '\n', IOSTATE_goodbit, "is", '\n', IOSTATE_goodbit },
1753
1754         { "this is some text\n", "this", ' ',  IOSTATE_goodbit, "is",           ' ',  IOSTATE_goodbit },
1755         { "this is some text\n", "this", ' ',  IOSTATE_goodbit, "is some text", '\n', IOSTATE_goodbit },
1756
1757         { "this is some text\n", "this is some text",   '\n', IOSTATE_goodbit, "",                    '\n', IOSTATE_faileof },
1758         { "this is some text\n", "this is some text\n", '\0', IOSTATE_eofbit,  "this is some text\n", '\n', IOSTATE_faileof },
1759     };
1760
1761     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1762         /* char version */
1763         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1764         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1765
1766         p_basic_istream_char_getline_bstr_delim(&ss.base.base1, &str, tests[i].delim);
1767         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1768         cstr  = call_func1(p_basic_string_char_cstr, &str);
1769
1770         ok(!strcmp(tests[i].line, cstr), "wrong line, expected = %s found = %s\n", tests[i].line, cstr);
1771         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1772
1773         /* next line */
1774         p_basic_istream_char_getline_bstr_delim(&ss.base.base1, &str, tests[i].nextdelim);
1775         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1776         cstr  = call_func1(p_basic_string_char_cstr, &str);
1777
1778         ok(!strcmp(tests[i].nextline, cstr), "wrong next line, expected = %s found = %s\n", tests[i].nextline, cstr);
1779         ok(tests[i].nextstate == state, "wrong next state, expected = %x found = %x\n", tests[i].nextstate, state);
1780
1781         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1782         call_func1(p_basic_string_char_dtor, &str);
1783
1784         /* wchar_t version */
1785         AtoW(wide, tests[i].str, strlen(tests[i].str));
1786         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1787         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1788
1789         p_basic_istream_wchar_getline_bstr_delim(&wss.base.base1, &wstr, tests[i].delim);
1790         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1791         wcstr = call_func1(p_basic_string_wchar_cstr, &wstr);
1792
1793         AtoW(wide, tests[i].line, strlen(tests[i].line));
1794         ok(!lstrcmpW(wide, wcstr), "wrong line, expected = %s found = %s\n", tests[i].line, wine_dbgstr_w(wcstr));
1795         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1796
1797         /* next line */
1798         p_basic_istream_wchar_getline_bstr_delim(&wss.base.base1, &wstr, tests[i].nextdelim);
1799         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1800         wcstr = call_func1(p_basic_string_wchar_cstr, &wstr);
1801
1802         AtoW(wide, tests[i].nextline, strlen(tests[i].nextline));
1803         ok(!lstrcmpW(wide, wcstr), "wrong line, expected = %s found = %s\n", tests[i].nextline, wine_dbgstr_w(wcstr));
1804         ok(tests[i].nextstate == state, "wrong state, expected = %x found = %x\n", tests[i].nextstate, state);
1805
1806         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1807         call_func1(p_basic_string_wchar_dtor, &wstr);
1808     }
1809 }
1810
1811
1812 START_TEST(ios)
1813 {
1814     if(!init())
1815         return;
1816
1817     test_num_get_get_uint64();
1818     test_num_get_get_double();
1819     test_num_put_put_double();
1820     test_istream_ipfx();
1821     test_istream_ignore();
1822     test_istream_seekg();
1823     test_istream_seekg_fpos();
1824     test_istream_peek();
1825     test_istream_tellg();
1826     test_istream_getline();
1827
1828     ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");
1829 }