msvcrt: Added _set_fmode and _get_fmode implementation.
[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 struct thiscall_thunk_retptr *thunk_retptr;
548
549 static void init_thiscall_thunk(void)
550 {
551     struct thiscall_thunk *thunk = VirtualAlloc( NULL, sizeof(*thunk),
552                                                  MEM_COMMIT, PAGE_EXECUTE_READWRITE );
553     thunk->pop_eax  = 0x58;   /* popl  %eax */
554     thunk->pop_edx  = 0x5a;   /* popl  %edx */
555     thunk->pop_ecx  = 0x59;   /* popl  %ecx */
556     thunk->push_eax = 0x50;   /* pushl %eax */
557     thunk->jmp_edx  = 0xe2ff; /* jmp  *%edx */
558     call_thiscall_func1 = (void *)thunk;
559     call_thiscall_func2 = (void *)thunk;
560     call_thiscall_func3 = (void *)thunk;
561     call_thiscall_func4 = (void *)thunk;
562     call_thiscall_func5 = (void *)thunk;
563
564     call_thiscall_func2_ptr_dbl  = (void *)thunk;
565     call_thiscall_func2_ptr_fpos = (void *)thunk;
566 }
567
568 #define call_func1(func,_this) call_thiscall_func1(func,_this)
569 #define call_func2(func,_this,a) call_thiscall_func2(func,_this,(const void*)(a))
570 #define call_func3(func,_this,a,b) call_thiscall_func3(func,_this,(const void*)(a),(const void*)(b))
571 #define call_func4(func,_this,a,b,c) call_thiscall_func4(func,_this,(const void*)(a),(const void*)(b), \
572         (const void*)(c))
573 #define call_func5(func,_this,a,b,c,d) call_thiscall_func5(func,_this,(const void*)(a),(const void*)(b), \
574         (const void*)(c), (const void *)(d))
575
576 #define call_func2_ptr_dbl(func,_this,a)  call_thiscall_func2_ptr_dbl(func,_this,a)
577 #define call_func2_ptr_fpos(func,_this,a) call_thiscall_func2_ptr_fpos(func,_this,a)
578
579 #else
580
581 #define init_thiscall_thunk()
582 #define call_func1(func,_this) func(_this)
583 #define call_func2(func,_this,a) func(_this,a)
584 #define call_func3(func,_this,a,b) func(_this,a,b)
585 #define call_func4(func,_this,a,b,c) func(_this,a,b,c)
586 #define call_func5(func,_this,a,b,c,d) func(_this,a,b,c,d)
587
588 #define call_func2_ptr_dbl   call_func2
589 #define call_func2_ptr_fpos  call_func2
590
591 #endif /* __i386__ */
592
593 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
594 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
595 static BOOL init(void)
596 {
597     HMODULE msvcr = LoadLibraryA("msvcr90.dll");
598     HMODULE msvcp = LoadLibraryA("msvcp90.dll");
599     if(!msvcr || !msvcp) {
600         win_skip("msvcp90.dll or msvcrt90.dll not installed\n");
601         return FALSE;
602     }
603
604     p_set_invalid_parameter_handler = (void*)GetProcAddress(msvcr, "_set_invalid_parameter_handler");
605     p_free = (void*)GetProcAddress(msvcr, "free");
606     if(!p_set_invalid_parameter_handler || !p_free) {
607         win_skip("Error setting tests environment\n");
608         return FALSE;
609     }
610
611     p_set_invalid_parameter_handler(test_invalid_parameter_handler);
612
613     if(sizeof(void*) == 8) { /* 64-bit initialization */
614         SET(p_basic_stringstream_char_ctor,
615             "??_F?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXXZ");
616         SET(p_basic_stringstream_char_ctor_str,
617             "??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");
618         SET(p_basic_stringstream_char_str_get,
619             "?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");
620         SET(p_basic_stringstream_char_vbase_dtor,
621             "??_D?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXXZ");
622
623         SET(p_basic_stringstream_wchar_ctor,
624             "??_F?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAXXZ");
625         SET(p_basic_stringstream_wchar_ctor_str,
626             "??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");
627         SET(p_basic_stringstream_wchar_str_get,
628             "?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");
629         SET(p_basic_stringstream_wchar_vbase_dtor,
630             "??_D?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAXXZ");
631
632         SET(p_basic_fstream_char_ctor_name,
633             "??0?$basic_fstream@DU?$char_traits@D@std@@@std@@QEAA@PEBDHH@Z");
634         SET(p_basic_fstream_char_vbase_dtor,
635             "??_D?$basic_fstream@DU?$char_traits@D@std@@@std@@QEAAXXZ");
636
637         SET(p_basic_fstream_wchar_ctor_name,
638             "??0?$basic_fstream@_WU?$char_traits@_W@std@@@std@@QEAA@PEBDHH@Z");
639         SET(p_basic_fstream_wchar_vbase_dtor,
640             "??_D?$basic_fstream@_WU?$char_traits@_W@std@@@std@@QEAAXXZ");
641
642         SET(p_basic_istream_char_read_uint64,
643             "??5?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@AEA_K@Z");
644         SET(p_basic_istream_char_read_double,
645             "??5?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@AEAN@Z");
646         SET(p_basic_istream_char_get,
647             "?get@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAHXZ");
648         SET(p_basic_istream_char_ipfx,
649             "?ipfx@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAA_N_N@Z");
650         SET(p_basic_istream_char_ignore,
651             "?ignore@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@_JH@Z");
652         SET(p_basic_istream_char_seekg,
653             "?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@_JH@Z");
654         SET(p_basic_istream_char_seekg_fpos,
655             "?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@V?$fpos@H@2@@Z");
656         SET(p_basic_istream_char_peek,
657             "?peek@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAHXZ");
658         SET(p_basic_istream_char_tellg,
659             "?tellg@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAA?AV?$fpos@H@2@XZ");
660         SET(p_basic_istream_char_getline_bstr_delim,
661             "??$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");
662
663         SET(p_basic_istream_wchar_read_uint64,
664             "??5?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV01@AEA_K@Z");
665         SET(p_basic_istream_wchar_read_double,
666             "??5?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV01@AEAN@Z");
667         SET(p_basic_istream_wchar_get,
668             "?get@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAGXZ");
669         SET(p_basic_istream_wchar_ipfx,
670             "?ipfx@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAA_N_N@Z");
671         SET(p_basic_istream_wchar_ignore,
672             "?ignore@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV12@_JG@Z");
673         SET(p_basic_istream_wchar_seekg,
674             "?seekg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV12@_JH@Z");
675         SET(p_basic_istream_wchar_seekg_fpos,
676             "?seekg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV12@V?$fpos@H@2@@Z");
677         SET(p_basic_istream_wchar_peek,
678             "?peek@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAAGXZ");
679         SET(p_basic_istream_wchar_tellg,
680             "?tellg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QEAA?AV?$fpos@H@2@XZ");
681         SET(p_basic_istream_wchar_getline_bstr_delim,
682             "??$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");
683
684         SET(p_basic_ostream_char_print_double,
685             "??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@N@Z");
686
687         SET(p_basic_ostream_wchar_print_double,
688             "??6?$basic_ostream@_WU?$char_traits@_W@std@@@std@@QEAAAEAV01@N@Z");
689
690         SET(p_ios_base_rdstate,
691             "?rdstate@ios_base@std@@QEBAHXZ");
692         SET(p_ios_base_setf_mask,
693             "?setf@ios_base@std@@QEAAHHH@Z");
694         SET(p_ios_base_unsetf,
695             "?unsetf@ios_base@std@@QEAAXH@Z");
696         SET(p_ios_base_precision_set,
697             "?precision@ios_base@std@@QEAA_J_J@Z");
698
699         SET(p_basic_ios_char_imbue,
700             "?imbue@?$basic_ios@DU?$char_traits@D@std@@@std@@QEAA?AVlocale@2@AEBV32@@Z");
701
702         SET(p_basic_ios_wchar_imbue,
703             "?imbue@?$basic_ios@_WU?$char_traits@_W@std@@@std@@QEAA?AVlocale@2@AEBV32@@Z");
704
705         SET(p_locale_ctor_cstr,
706             "??0locale@std@@QEAA@PEBDH@Z");
707         SET(p_locale_dtor,
708             "??1locale@std@@QEAA@XZ");
709
710         SET(p_basic_string_char_ctor_cstr,
711                 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@PEBD@Z");
712         SET(p_basic_string_char_cstr,
713                 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
714         SET(p_basic_string_char_dtor,
715                 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
716
717         SET(p_basic_string_wchar_ctor_cstr,
718                 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@PEB_W@Z");
719         SET(p_basic_string_wchar_cstr,
720                 "?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAPEB_WXZ");
721         SET(p_basic_string_wchar_dtor,
722                 "??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@XZ");
723     } else {
724         SET(p_basic_stringstream_char_ctor,
725             "??_F?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ");
726         SET(p_basic_stringstream_char_ctor_str,
727             "??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");
728         SET(p_basic_stringstream_char_str_get,
729             "?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");
730         SET(p_basic_stringstream_char_vbase_dtor,
731             "??_D?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ");
732
733         SET(p_basic_stringstream_wchar_ctor,
734             "??_F?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEXXZ");
735         SET(p_basic_stringstream_wchar_ctor_str,
736             "??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");
737         SET(p_basic_stringstream_wchar_str_get,
738             "?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");
739         SET(p_basic_stringstream_wchar_vbase_dtor,
740             "??_D?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEXXZ");
741
742         SET(p_basic_fstream_char_ctor_name,
743             "??0?$basic_fstream@DU?$char_traits@D@std@@@std@@QAE@PBDHH@Z");
744         SET(p_basic_fstream_char_vbase_dtor,
745             "??_D?$basic_fstream@DU?$char_traits@D@std@@@std@@QAEXXZ");
746
747         SET(p_basic_fstream_wchar_ctor_name,
748             "??0?$basic_fstream@_WU?$char_traits@_W@std@@@std@@QAE@PBDHH@Z");
749         SET(p_basic_fstream_wchar_vbase_dtor,
750             "??_D?$basic_fstream@_WU?$char_traits@_W@std@@@std@@QAEXXZ");
751
752         SET(p_basic_istream_char_read_uint64,
753             "??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AA_K@Z");
754         SET(p_basic_istream_char_read_double,
755             "??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAN@Z");
756         SET(p_basic_istream_char_get,
757             "?get@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEHXZ");
758         SET(p_basic_istream_char_ipfx,
759             "?ipfx@?$basic_istream@DU?$char_traits@D@std@@@std@@QAE_N_N@Z");
760         SET(p_basic_istream_char_ignore,
761             "?ignore@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV12@HH@Z");
762         SET(p_basic_istream_char_seekg,
763             "?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV12@JH@Z");
764         SET(p_basic_istream_char_seekg_fpos,
765             "?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV12@V?$fpos@H@2@@Z");
766         SET(p_basic_istream_char_peek,
767             "?peek@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEHXZ");
768         SET(p_basic_istream_char_tellg,
769             "?tellg@?$basic_istream@DU?$char_traits@D@std@@@std@@QAE?AV?$fpos@H@2@XZ");
770         SET(p_basic_istream_char_getline_bstr_delim,
771             "??$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");
772
773         SET(p_basic_istream_wchar_read_uint64,
774             "??5?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV01@AA_K@Z");
775         SET(p_basic_istream_wchar_read_double,
776             "??5?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV01@AAN@Z");
777         SET(p_basic_istream_wchar_get,
778             "?get@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEGXZ");
779         SET(p_basic_istream_wchar_ipfx,
780             "?ipfx@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAE_N_N@Z");
781         SET(p_basic_istream_wchar_ignore,
782             "?ignore@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV12@HG@Z");
783         SET(p_basic_istream_wchar_seekg,
784             "?seekg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV12@JH@Z");
785         SET(p_basic_istream_wchar_seekg_fpos,
786             "?seekg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV12@V?$fpos@H@2@@Z");
787         SET(p_basic_istream_wchar_peek,
788             "?peek@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEGXZ");
789         SET(p_basic_istream_wchar_tellg,
790             "?tellg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAE?AV?$fpos@H@2@XZ");
791         SET(p_basic_istream_wchar_getline_bstr_delim,
792             "??$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");
793
794         SET(p_basic_ostream_char_print_double,
795             "??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@N@Z");
796
797         SET(p_basic_ostream_wchar_print_double,
798             "??6?$basic_ostream@_WU?$char_traits@_W@std@@@std@@QAEAAV01@N@Z");
799
800         SET(p_ios_base_rdstate,
801             "?rdstate@ios_base@std@@QBEHXZ");
802         SET(p_ios_base_setf_mask,
803             "?setf@ios_base@std@@QAEHHH@Z");
804         SET(p_ios_base_unsetf,
805             "?unsetf@ios_base@std@@QAEXH@Z");
806         SET(p_ios_base_precision_set,
807             "?precision@ios_base@std@@QAEHH@Z");
808
809         SET(p_basic_ios_char_imbue,
810             "?imbue@?$basic_ios@DU?$char_traits@D@std@@@std@@QAE?AVlocale@2@ABV32@@Z");
811
812         SET(p_basic_ios_wchar_imbue,
813             "?imbue@?$basic_ios@_WU?$char_traits@_W@std@@@std@@QAE?AVlocale@2@ABV32@@Z");
814
815         SET(p_locale_ctor_cstr,
816             "??0locale@std@@QAE@PBDH@Z");
817         SET(p_locale_dtor,
818             "??1locale@std@@QAE@XZ");
819
820         SET(p_basic_string_char_ctor_cstr,
821                 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z");
822         SET(p_basic_string_char_cstr,
823                 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
824         SET(p_basic_string_char_dtor,
825                 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
826
827         SET(p_basic_string_wchar_ctor_cstr,
828                 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@PB_W@Z");
829         SET(p_basic_string_wchar_cstr,
830                 "?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEPB_WXZ");
831         SET(p_basic_string_wchar_dtor,
832                 "??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@XZ");
833     }
834
835     init_thiscall_thunk();
836     return TRUE;
837 }
838
839 /* convert a dll name A->W without depending on the current codepage */
840 static wchar_t *AtoW( wchar_t *nameW, const char *nameA, unsigned int len )
841 {
842     unsigned int i;
843
844     for (i = 0; i < len; i++) nameW[i] = nameA[i];
845     nameW[i] = 0;
846     return nameW;
847 }
848
849 static void test_num_get_get_uint64(void)
850 {
851     unsigned short testus, nextus;
852     basic_stringstream_wchar wss;
853     basic_stringstream_char ss;
854     basic_string_wchar wstr;
855     basic_string_char str;
856     IOSB_iostate state;
857     locale lcl, retlcl;
858     wchar_t wide[64];
859     ULONGLONG val;
860     int i, next;
861
862     /* makes tables narrower */
863     const IOSB_iostate IOSTATE_faileof = IOSTATE_failbit|IOSTATE_eofbit;
864
865     struct _test_num_get {
866         const char    *str;
867         const char    *lcl;
868         IOSB_fmtflags fmtfl;
869         IOSB_iostate  state;
870         ULONGLONG     val;
871         int           next;
872     } tests[] = {
873         /* simple cases */
874         { "0",        NULL, FMTFLAG_dec, IOSTATE_eofbit,  0,       EOF },
875         { "1234567",  NULL, FMTFLAG_dec, IOSTATE_eofbit,  1234567, EOF },
876         { "+1234567", NULL, FMTFLAG_dec, IOSTATE_eofbit,  1234567, EOF },
877         { "-1234567", NULL, FMTFLAG_dec, IOSTATE_eofbit, -1234567, EOF },
878         { "",         NULL, FMTFLAG_dec, IOSTATE_faileof, 42,      EOF },
879
880         /* different bases */
881         /* (with and without zero are both tested, since 0 can signal a prefix check) */
882         { "0x1000",   NULL, FMTFLAG_hex, IOSTATE_eofbit, 4096, EOF }, /* lowercase x */
883         { "0X1000",   NULL, FMTFLAG_hex, IOSTATE_eofbit, 4096, EOF }, /* uppercase X */
884         { "010",      NULL, FMTFLAG_hex, IOSTATE_eofbit, 16,   EOF },
885         { "010",      NULL, FMTFLAG_dec, IOSTATE_eofbit, 10,   EOF },
886         { "010",      NULL, FMTFLAG_oct, IOSTATE_eofbit, 8,    EOF },
887         { "10",       NULL, FMTFLAG_hex, IOSTATE_eofbit, 16,   EOF },
888         { "10",       NULL, FMTFLAG_dec, IOSTATE_eofbit, 10,   EOF },
889         { "10",       NULL, FMTFLAG_oct, IOSTATE_eofbit, 8,    EOF },
890         { "10",       NULL, 0,           IOSTATE_eofbit, 10,   EOF }, /* discover dec */
891         { "010",      NULL, 0,           IOSTATE_eofbit, 8,    EOF }, /* discover oct */
892         { "0xD",      NULL, 0,           IOSTATE_eofbit, 13,   EOF }, /* discover hex (upper) */
893         { "0xd",      NULL, 0,           IOSTATE_eofbit, 13,   EOF }, /* discover hex (lower) */
894
895         /* test grouping - default/"C" has no grouping, named English/German locales do */
896         { "0.", NULL,       FMTFLAG_dec, IOSTATE_goodbit, 0,  '.' },
897         { "0,", NULL,       FMTFLAG_dec, IOSTATE_goodbit, 0,  ',' },
898         { "0,", "English",  FMTFLAG_dec, IOSTATE_faileof, 42, EOF }, /* trailing group with , */
899         { "0.", "German",   FMTFLAG_dec, IOSTATE_faileof, 42, EOF }, /* trailing group with . */
900         { "0,", "German",   FMTFLAG_dec, IOSTATE_goodbit, 0,  ',' },
901         { ",0", "English",  FMTFLAG_dec, IOSTATE_failbit, 42, EOF }, /* empty group at start */
902
903         { "1,234,567",   NULL,      FMTFLAG_dec, IOSTATE_goodbit, 1,        ',' }, /* no grouping */
904         { "1,234,567",   "English", FMTFLAG_dec, IOSTATE_eofbit,  1234567,  EOF }, /* grouping with , */
905         { "1.234.567",   "German",  FMTFLAG_dec, IOSTATE_eofbit,  1234567,  EOF }, /* grouping with . */
906         { "1,,234",      NULL,      FMTFLAG_dec, IOSTATE_goodbit, 1,        ',' }, /* empty group */
907         { "1,,234",      "English", FMTFLAG_dec, IOSTATE_failbit, 42,       EOF }, /* empty group */
908         { "0x1,000,000", "English", FMTFLAG_hex, IOSTATE_eofbit,  16777216, EOF }, /* yeah, hex can group */
909         { "1,23,34",     "English", FMTFLAG_dec, IOSTATE_faileof, 42,       EOF }, /* invalid size group */
910         { "0,123",       "English", FMTFLAG_dec, IOSTATE_eofbit,  123,      EOF }, /* 0 solo in group */
911
912         { "18446744073709551615", NULL, FMTFLAG_dec, IOSTATE_eofbit,  ~0, EOF }, /* max value */
913         { "99999999999999999999", NULL, FMTFLAG_dec, IOSTATE_faileof, 42, EOF }, /* invalid value */
914
915         /* test invalid formats */
916         { "0000x10", NULL, FMTFLAG_hex, IOSTATE_goodbit, 0,  'x' },
917         { "x10",     NULL, FMTFLAG_hex, IOSTATE_failbit, 42, EOF },
918         { "0xx10",   NULL, FMTFLAG_hex, IOSTATE_failbit, 42, EOF },
919     };
920
921     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
922         /* char version */
923         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
924         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
925
926         if(tests[i].lcl) {
927             call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
928             call_func3(p_basic_ios_char_imbue, &ss.basic_ios, &retlcl, &lcl);
929         }
930
931         val = 42;
932         call_func3(p_ios_base_setf_mask, &ss.basic_ios.base, tests[i].fmtfl, FMTFLAG_basefield);
933         call_func2(p_basic_istream_char_read_uint64, &ss.base.base1, &val);
934         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
935         next  = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
936
937         if(state==IOSTATE_faileof && tests[i].val==~0) {
938             /* Maximal uint64 test is broken on 9.0.21022.8 */
939             skip("basic_istream_char_read_uint64(MAX_UINT64) is broken\n");
940             continue;
941         }
942
943         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
944         ok(tests[i].val   == val,   "wrong val, expected = %lx%08lx found %lx%08lx\n", (unsigned long)(tests[i].val >> 32),
945                 (unsigned long)tests[i].val, (unsigned long)(val >> 32), (unsigned long)val);
946         ok(tests[i].next  == next,  "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
947
948         if(tests[i].lcl)
949             call_func1(p_locale_dtor, &lcl);
950
951         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
952         call_func1(p_basic_string_char_dtor, &str);
953
954         /* wchar_t version */
955         AtoW(wide, tests[i].str, strlen(tests[i].str));
956         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
957         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
958
959         if(tests[i].lcl) {
960             call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
961             call_func3(p_basic_ios_wchar_imbue, &wss.basic_ios, &retlcl, &lcl);
962         }
963
964         val = 42;
965         call_func3(p_ios_base_setf_mask, &wss.basic_ios.base, tests[i].fmtfl, FMTFLAG_basefield);
966         call_func2(p_basic_istream_wchar_read_uint64, &wss.base.base1, &val);
967         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
968         nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
969
970         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
971         ok(tests[i].val == val, "wrong val, expected = %lx%08lx found %lx%08lx\n", (unsigned long)(tests[i].val >> 32),
972                 (unsigned long)tests[i].val, (unsigned long)(val >> 32), (unsigned long)val);
973         testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
974         ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
975
976         if(tests[i].lcl)
977             call_func1(p_locale_dtor, &lcl);
978
979         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
980         call_func1(p_basic_string_wchar_dtor, &wstr);
981     }
982 }
983
984
985 static void test_num_get_get_double(void)
986 {
987     unsigned short testus, nextus;
988     basic_stringstream_wchar wss;
989     basic_stringstream_char ss;
990     basic_string_wchar wstr;
991     basic_string_char str;
992     IOSB_iostate state;
993     locale lcl, retlcl;
994     wchar_t wide[64];
995     int i, next;
996     double val;
997
998     /* makes tables narrower */
999     const IOSB_iostate IOSTATE_faileof = IOSTATE_failbit|IOSTATE_eofbit;
1000
1001     struct _test_num_get {
1002         const char    *str;
1003         const char    *lcl;
1004         IOSB_iostate  state;
1005         double        val;
1006         int           next;
1007     } tests[] = {
1008         /* simple cases */
1009         { "0",     NULL, IOSTATE_eofbit,  0.0,  EOF },
1010         { "10",    NULL, IOSTATE_eofbit,  10.0, EOF },
1011         { "+10",   NULL, IOSTATE_eofbit,  10.0, EOF },
1012         { "-10",   NULL, IOSTATE_eofbit, -10.0, EOF },
1013         { "+010",  NULL, IOSTATE_eofbit,  10.0, EOF }, /* leading zero */
1014
1015         /* test grouping - default/"C" has no grouping, named English/German locales do */
1016         { "1,000", NULL,         IOSTATE_goodbit,  1.0,      ',' }, /* with comma */
1017         { "1,000", "English",    IOSTATE_eofbit,   1000.0,   EOF },
1018         { "1,000", "German",     IOSTATE_eofbit,   1.0,      EOF },
1019
1020         { "1.000", NULL,         IOSTATE_eofbit,   1.0,      EOF }, /* with period */
1021         { "1.000", "English",    IOSTATE_eofbit,   1.0,      EOF },
1022         { "1.000", "German",     IOSTATE_eofbit,   1000.0,   EOF },
1023
1024         { "1,234.",  NULL,       IOSTATE_goodbit,  1.0,      ',' },
1025         { "1,234.",  "English",  IOSTATE_eofbit,   1234.0,   EOF }, /* trailing decimal */
1026         { "1,234.",  "German",   IOSTATE_goodbit,  1.234,    '.' },
1027         { "1,234.5", "English",  IOSTATE_eofbit,   1234.5,   EOF }, /* group + decimal */
1028         { "1,234.5", "German",   IOSTATE_goodbit,  1.234,    '.' },
1029
1030         { "1,234,567,890", NULL,      IOSTATE_goodbit, 1.0,          ',' }, /* more groups */
1031         { "1,234,567,890", "English", IOSTATE_eofbit,  1234567890.0, EOF },
1032         { "1,234,567,890", "German",  IOSTATE_goodbit, 1.234,        ',' },
1033         { "1.234.567.890", "German",  IOSTATE_eofbit,  1234567890.0, EOF },
1034
1035         /* extra digits and stuff */
1036         { "00000.123456", NULL,  IOSTATE_eofbit,  0.123456, EOF },
1037         { "0.1234560000", NULL,  IOSTATE_eofbit,  0.123456, EOF },
1038         { "100aaaa",      NULL,  IOSTATE_goodbit, 100.0,    'a' },
1039
1040         /* exponent */
1041         { "10e10",       NULL,      IOSTATE_eofbit,    10e10,      EOF }, /* lowercase e */
1042         { "10E10",       NULL,      IOSTATE_eofbit,    10E10,      EOF }, /* uppercase E */
1043         { "10e+10",      NULL,      IOSTATE_eofbit,    10e10,      EOF }, /* sign */
1044         { "10e-10",      NULL,      IOSTATE_eofbit,    10e-10,     EOF },
1045         { "10.e10",      NULL,      IOSTATE_eofbit,    10e10,      EOF }, /* trailing decimal before exponent */
1046         { "-10.e-10",    NULL,      IOSTATE_eofbit,   -10e-10,     EOF },
1047         { "-12.345e-10", NULL,      IOSTATE_eofbit,   -12.345e-10, EOF },
1048         { "1,234e10",    NULL,      IOSTATE_goodbit,   1.0,        ',' },
1049         { "1,234e10",    "English", IOSTATE_eofbit,    1234.0e10,  EOF },
1050         { "1,234e10",    "German",  IOSTATE_eofbit,    1.234e10,   EOF },
1051         { "1.0e999",     NULL,      IOSTATE_faileof,   42.0,       EOF }, /* too big   */
1052         { "1.0e-999",    NULL,      IOSTATE_faileof,   42.0,       EOF }, /* too small */
1053
1054         /* bad form */
1055         { "1,000,", NULL,       IOSTATE_goodbit, 1.0,   ',' }, /* trailing group */
1056         { "1,000,", "English",  IOSTATE_faileof, 42.0,  EOF },
1057         { "1.000.", "German",   IOSTATE_faileof, 42.0,  EOF },
1058
1059         { "1,,000", NULL,       IOSTATE_goodbit, 1.0,   ',' }, /* empty group */
1060         { "1,,000", "English",  IOSTATE_failbit, 42.0,  EOF },
1061         { "1..000", "German",   IOSTATE_failbit, 42.0,  EOF },
1062
1063         { "1.0,00", "English",  IOSTATE_goodbit, 1.0,   ',' },
1064         { "1.0,00", "German",   IOSTATE_faileof, 42.0,  EOF },
1065
1066         { "1.0ee10", NULL,      IOSTATE_failbit, 42.0,  EOF }, /* dup exp */
1067         { "1.0e1.0", NULL,      IOSTATE_goodbit, 10.0,  '.' }, /* decimal in exponent */
1068         { "1.0e1,0", NULL,      IOSTATE_goodbit, 10.0,  ',' }, /* group in exponent */
1069     };
1070
1071     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1072         /* char version */
1073         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1074         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1075
1076         if(tests[i].lcl) {
1077             call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
1078             call_func3(p_basic_ios_char_imbue, &ss.basic_ios, &retlcl, &lcl);
1079         }
1080
1081         val = 42.0;
1082         call_func2(p_basic_istream_char_read_double, &ss.base.base1, &val);
1083         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1084         next  = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
1085
1086         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1087         ok(tests[i].val   == val,   "wrong val, expected = %g found %g\n", tests[i].val, val);
1088         ok(tests[i].next  == next,  "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
1089
1090         if(tests[i].lcl)
1091             call_func1(p_locale_dtor, &lcl);
1092
1093         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1094         call_func1(p_basic_string_char_dtor, &str);
1095
1096         /* wchar_t version */
1097         AtoW(wide, tests[i].str, strlen(tests[i].str));
1098         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1099         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1100
1101         if(tests[i].lcl) {
1102             call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
1103             call_func3(p_basic_ios_wchar_imbue, &wss.basic_ios, &retlcl, &lcl);
1104         }
1105
1106         val = 42.0;
1107         call_func2(p_basic_istream_wchar_read_double, &wss.base.base1, &val);
1108         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1109         nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
1110
1111         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1112         ok(tests[i].val == val, "wrong val, expected = %g found %g\n", tests[i].val, val);
1113         testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
1114         ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
1115
1116         if(tests[i].lcl)
1117             call_func1(p_locale_dtor, &lcl);
1118
1119         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1120         call_func1(p_basic_string_wchar_dtor, &wstr);
1121     }
1122 }
1123
1124
1125 static void test_num_put_put_double(void)
1126 {
1127     basic_stringstream_wchar wss;
1128     basic_stringstream_char ss;
1129     basic_string_wchar pwstr;
1130     basic_string_char pstr;
1131     locale lcl, retlcl;
1132     const wchar_t *wstr;
1133     const char *str;
1134     wchar_t wide[64];
1135     int i;
1136
1137     struct _test_num_get {
1138         double        val;
1139         const char    *lcl;
1140         streamsize    prec;  /* set to -1 for default */
1141         IOSB_fmtflags fmtfl; /* FMTFLAG_scientific, FMTFLAG_fixed */
1142         const char    *str;
1143     } tests[] = {
1144         { 0.0, NULL, -1, 0, "0" },
1145
1146         /* simple cases */
1147         { 0.123, NULL, -1, 0, "0.123" },
1148         { 0.123, NULL,  6, 0, "0.123" },
1149         { 0.123, NULL,  0, 0, "0.123" },
1150
1151         /* fixed format */
1152         { 0.123, NULL, -1, FMTFLAG_fixed, "0.123000" },
1153         { 0.123, NULL,  6, FMTFLAG_fixed, "0.123000" },
1154         { 0.123, NULL,  0, FMTFLAG_fixed, "0" },
1155
1156         /* scientific format */
1157         { 123456.789, NULL,    -1, FMTFLAG_scientific, "1.234568e+005"    },
1158         { 123456.789, NULL,     0, FMTFLAG_scientific, "1.234568e+005"    },
1159         { 123456.789, NULL,     9, FMTFLAG_scientific, "1.234567890e+005" },
1160         { 123456.789, "German", 9, FMTFLAG_scientific, "1,234567890e+005" },
1161
1162         /* different locales */
1163         { 0.123, "C",       -1, 0, "0.123" },
1164         { 0.123, "English", -1, 0, "0.123" },
1165         { 0.123, "German",  -1, 0, "0,123" },
1166
1167         { 123456.789, "C",       -1, 0, "123457"  },
1168         { 123456.789, "English", -1, 0, "123,457" },
1169         { 123456.789, "German",  -1, 0, "123.457" },
1170
1171         /* signs and exponents */
1172         {  1.0e-9, NULL, -1, 0, "1e-009"  },
1173         {  1.0e-9, NULL,  9, 0, "1e-009"  },
1174         { -1.0e9,  NULL, -1, 0, "-1e+009" },
1175         { -1.0e9,  NULL,  9, 0, "-1e+009" },
1176
1177         {  1.0e-9, NULL, 0, FMTFLAG_fixed, "0"                  },
1178         {  1.0e-9, NULL, 6, FMTFLAG_fixed, "0.000000"           },
1179         {  1.0e-9, NULL, 9, FMTFLAG_fixed, "0.000000001"        },
1180         { -1.0e9,  NULL, 0, FMTFLAG_fixed, "-1000000000"        },
1181         { -1.0e9,  NULL, 6, FMTFLAG_fixed, "-1000000000.000000" },
1182
1183         { -1.23456789e9,  NULL, 0, 0,             "-1.23457e+009"      },
1184         { -1.23456789e9,  NULL, 0, FMTFLAG_fixed, "-1234567890"        },
1185         { -1.23456789e9,  NULL, 6, FMTFLAG_fixed, "-1234567890.000000" },
1186         { -1.23456789e-9, NULL, 6, FMTFLAG_fixed, "-0.000000"          },
1187         { -1.23456789e-9, NULL, 9, FMTFLAG_fixed, "-0.000000001"       }
1188     };
1189
1190     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1191         /* char version */
1192         call_func2(p_basic_stringstream_char_ctor, &ss, TRUE);
1193
1194         if(tests[i].lcl) {
1195             call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
1196             call_func3(p_basic_ios_char_imbue, &ss.basic_ios, &retlcl, &lcl);
1197         }
1198
1199         /* set format and precision only if specified, so we can try defaults */
1200         if(tests[i].fmtfl)
1201             call_func3(p_ios_base_setf_mask, &ss.basic_ios.base, tests[i].fmtfl, FMTFLAG_floatfield);
1202         if(tests[i].prec != -1)
1203             call_func2(p_ios_base_precision_set, &ss.basic_ios.base, tests[i].prec);
1204         call_func2_ptr_dbl(p_basic_ostream_char_print_double, &ss.base.base2, tests[i].val);
1205
1206         call_func2(p_basic_stringstream_char_str_get, &ss, &pstr);
1207         str = call_func1(p_basic_string_char_cstr, &pstr);
1208
1209         ok(!strcmp(tests[i].str, str), "wrong output, expected = %s found = %s\n", tests[i].str, str);
1210         call_func1(p_basic_string_char_dtor, &pstr);
1211
1212         if(tests[i].lcl)
1213             call_func1(p_locale_dtor, &lcl);
1214
1215         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1216
1217         /* wchar_t version */
1218         call_func2(p_basic_stringstream_wchar_ctor, &wss, TRUE);
1219
1220         if(tests[i].lcl) {
1221             call_func3(p_locale_ctor_cstr, &lcl, tests[i].lcl, 0x3f /* FIXME: support categories */);
1222             call_func3(p_basic_ios_wchar_imbue, &wss.basic_ios, &retlcl, &lcl);
1223         }
1224
1225         /* set format and precision only if specified, so we can try defaults */
1226         if(tests[i].fmtfl)
1227             call_func3(p_ios_base_setf_mask, &wss.basic_ios.base, tests[i].fmtfl, FMTFLAG_floatfield);
1228         if(tests[i].prec != -1)
1229             call_func2(p_ios_base_precision_set, &wss.basic_ios.base, tests[i].prec);
1230         call_func2_ptr_dbl(p_basic_ostream_wchar_print_double, &wss.base.base2, tests[i].val);
1231
1232         call_func2(p_basic_stringstream_wchar_str_get, &wss, &pwstr);
1233         wstr = call_func1(p_basic_string_wchar_cstr, &pwstr);
1234
1235         AtoW(wide, tests[i].str, strlen(tests[i].str));
1236         ok(!lstrcmpW(wide, wstr), "wrong output, expected = %s found = %s\n", tests[i].str, wine_dbgstr_w(wstr));
1237         call_func1(p_basic_string_wchar_dtor, &pwstr);
1238
1239         if(tests[i].lcl)
1240             call_func1(p_locale_dtor, &lcl);
1241
1242         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1243     }
1244 }
1245
1246
1247 static void test_istream_ipfx(void)
1248 {
1249     unsigned short testus, nextus;
1250     basic_stringstream_wchar wss;
1251     basic_stringstream_char ss;
1252     basic_string_wchar wstr;
1253     basic_string_char str;
1254     IOSB_iostate state;
1255     wchar_t wide[64];
1256     int i, ret, next;
1257
1258     /* makes tables narrower */
1259     const IOSB_iostate IOSTATE_faileof = IOSTATE_failbit|IOSTATE_eofbit;
1260
1261     struct _test_istream_ipfx {
1262         const char  *str;
1263         int          unset_skipws;
1264         int          noskip;
1265         int          ret;
1266         IOSB_iostate state;
1267         int          next;
1268     } tests[] = {
1269         /* string       unset  noskip return state            next char */
1270         { "",           FALSE, FALSE, FALSE, IOSTATE_faileof, EOF  }, /* empty string */
1271         { "   ",        FALSE, FALSE, FALSE, IOSTATE_faileof, EOF  }, /* just ws */
1272         { "\t \n \f ",  FALSE, FALSE, FALSE, IOSTATE_faileof, EOF  }, /* different ws */
1273         { "simple",     FALSE, FALSE, TRUE,  IOSTATE_goodbit, 's'  },
1274         { "  simple",   FALSE, FALSE, TRUE,  IOSTATE_goodbit, 's'  },
1275         { "  simple",   TRUE,  FALSE, TRUE,  IOSTATE_goodbit, ' '  }, /* unset skipws */
1276         { "  simple",   FALSE, TRUE,  TRUE,  IOSTATE_goodbit, ' '  }, /* ipfx(true) */
1277         { "  simple",   TRUE,  TRUE,  TRUE,  IOSTATE_goodbit, ' '  }, /* both */
1278         { "\n\t ws",    FALSE, FALSE, TRUE,  IOSTATE_goodbit, 'w'  },
1279         { "\n\t ws",    TRUE,  FALSE, TRUE,  IOSTATE_goodbit, '\n' },
1280     };
1281
1282     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1283         /* char version */
1284         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1285         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1286
1287         /* set format and precision only if specified, so we can try defaults */
1288         if(tests[i].unset_skipws)
1289             call_func2(p_ios_base_unsetf, &ss.basic_ios.base, TRUE);
1290
1291         ret   = (int)call_func2(p_basic_istream_char_ipfx, &ss.base.base1, tests[i].noskip);
1292         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1293         next  = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
1294
1295         ok(tests[i].ret   == ret,   "wrong return, expected = %i found = %i\n", tests[i].ret, ret);
1296         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1297         ok(tests[i].next  == next,  "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
1298
1299         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1300         call_func1(p_basic_string_char_dtor, &str);
1301
1302         /* wchar_t version */
1303         AtoW(wide, tests[i].str, strlen(tests[i].str));
1304         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1305         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1306
1307         /* set format and precision only if specified, so we can try defaults */
1308         if(tests[i].unset_skipws)
1309             call_func2(p_ios_base_unsetf, &wss.basic_ios.base, TRUE);
1310
1311         ret    = (int)call_func2(p_basic_istream_wchar_ipfx, &wss.base.base1, tests[i].noskip);
1312         state  = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1313         nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
1314
1315         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1316         ok(tests[i].ret == ret, "wrong return, expected = %i found = %i\n", tests[i].ret, ret);
1317         testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
1318         ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
1319
1320         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1321         call_func1(p_basic_string_wchar_dtor, &wstr);
1322     }
1323 }
1324
1325
1326 static void test_istream_ignore(void)
1327 {
1328     unsigned short testus, nextus;
1329     basic_stringstream_wchar wss;
1330     basic_stringstream_char ss;
1331     basic_string_wchar wstr;
1332     basic_string_char str;
1333     IOSB_iostate state;
1334     wchar_t wide[64];
1335     int i, next;
1336
1337     struct _test_istream_ignore {
1338         const char  *str;
1339         streamsize   count;
1340         int          delim;
1341         IOSB_iostate state;
1342         int          next;
1343     } tests[] = {
1344         /* string       count delim state            next */
1345         { "",           0,    '\n', IOSTATE_goodbit, EOF }, /* empty string */
1346
1347         /* different counts */
1348         { "ABCDEF",     2,    '\n', IOSTATE_goodbit, 'C' }, /* easy case */
1349         { "ABCDEF",     42,   '\n', IOSTATE_eofbit,  EOF }, /* ignore too much */
1350         { "ABCDEF",    -2,    '\n', IOSTATE_goodbit, 'A' }, /* negative count */
1351         { "ABCDEF",     6,    '\n', IOSTATE_goodbit, EOF }, /* is eof not set at end */
1352         { "ABCDEF",     7,    '\n', IOSTATE_eofbit,  EOF }, /* eof is set just after end */
1353
1354         /* different delimiters */
1355         { "ABCDEF",       42, '\0', IOSTATE_eofbit,  EOF }, /* null as delim */
1356         { "ABC DEF GHI",  0,  ' ',  IOSTATE_goodbit, 'A' },
1357         { "ABC DEF GHI",  42, ' ',  IOSTATE_goodbit, 'D' },
1358         { "ABC DEF\tGHI", 42, '\t', IOSTATE_goodbit, 'G' },
1359         { "ABC ",         42, ' ',  IOSTATE_goodbit, EOF }, /* delim at end */
1360     };
1361
1362     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1363         /* char version */
1364         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1365         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1366
1367         call_func3(p_basic_istream_char_ignore, &ss.base.base1, tests[i].count, tests[i].delim);
1368         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1369         next  = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
1370
1371         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1372         ok(tests[i].next  == next,  "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
1373
1374         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1375         call_func1(p_basic_string_char_dtor, &str);
1376
1377         /* wchar_t version */
1378         AtoW(wide, tests[i].str, strlen(tests[i].str));
1379         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1380         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1381
1382         call_func3(p_basic_istream_wchar_ignore, &wss.base.base1, tests[i].count, tests[i].delim);
1383         state  = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1384         nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
1385
1386         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1387         testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
1388         ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
1389
1390         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1391         call_func1(p_basic_string_wchar_dtor, &wstr);
1392     }
1393 }
1394
1395
1396 static void test_istream_seekg(void)
1397 {
1398     unsigned short testus, nextus;
1399     basic_stringstream_wchar wss;
1400     basic_stringstream_char ss;
1401     basic_string_wchar wstr;
1402     basic_string_char str;
1403     IOSB_iostate state;
1404     wchar_t wide[64];
1405     int i, next;
1406
1407     struct _test_istream_seekg {
1408         const char  *str;
1409         streamoff    off;
1410         IOSB_seekdir dir;
1411         IOSB_iostate state;
1412         int          next;
1413     } tests[] = {
1414         { "ABCDEFGHIJ",  0, SEEKDIR_beg, IOSTATE_goodbit, 'A' },
1415         { "ABCDEFGHIJ",  1, SEEKDIR_beg, IOSTATE_goodbit, 'B' },
1416         { "ABCDEFGHIJ",  5, SEEKDIR_cur, IOSTATE_goodbit, 'F' },
1417         { "ABCDEFGHIJ", -3, SEEKDIR_end, IOSTATE_goodbit, 'H' },
1418
1419         /* bad offsets */
1420         { "ABCDEFGHIJ", -1, SEEKDIR_beg, IOSTATE_failbit, EOF },
1421         { "ABCDEFGHIJ", 42, SEEKDIR_cur, IOSTATE_failbit, EOF },
1422         { "ABCDEFGHIJ", 42, SEEKDIR_end, IOSTATE_failbit, EOF },
1423         { "",            0, SEEKDIR_beg, IOSTATE_failbit, EOF },
1424     };
1425
1426     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1427         /* char version */
1428         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1429         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1430
1431         call_func3(p_basic_istream_char_seekg, &ss.base.base1, tests[i].off, tests[i].dir);
1432         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1433         next  = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
1434
1435         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1436         ok(tests[i].next  == next,  "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
1437
1438         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1439         call_func1(p_basic_string_char_dtor, &str);
1440
1441         /* wchar_t version */
1442         AtoW(wide, tests[i].str, strlen(tests[i].str));
1443         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1444         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1445
1446         call_func3(p_basic_istream_wchar_seekg, &wss.base.base1, tests[i].off, tests[i].dir);
1447         state  = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1448         nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
1449
1450         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1451         testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
1452         ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
1453
1454         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1455         call_func1(p_basic_string_wchar_dtor, &wstr);
1456     }
1457 }
1458
1459
1460 static void test_istream_seekg_fpos(void)
1461 {
1462     unsigned short testus, nextus;
1463     basic_stringstream_wchar wss;
1464     basic_stringstream_char ss;
1465     basic_string_wchar wstr;
1466     basic_string_char str;
1467     IOSB_iostate state;
1468     wchar_t wide[64];
1469     fpos_int pos;
1470     int i, next;
1471
1472     struct _test_istream_seekg_fpos {
1473         const char  *str;
1474         streamoff    off;
1475         IOSB_iostate state;
1476         int          next;
1477     } tests[] = {
1478         { "ABCDEFGHIJ", 0,  IOSTATE_goodbit, 'A' },
1479         { "ABCDEFGHIJ", 9,  IOSTATE_goodbit, 'J' },
1480         { "ABCDEFGHIJ", 10, IOSTATE_goodbit, EOF }, /* beyond end, but still good */
1481         { "ABCDEFGHIJ", -1, IOSTATE_failbit, EOF },
1482         { "",           0,  IOSTATE_failbit, EOF },
1483     };
1484
1485     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1486         /* char version */
1487         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1488         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1489
1490         pos.off   = tests[i].off;
1491         pos.pos   = 0; /* FIXME: a later patch will test this with filebuf */
1492         pos.state = 0;
1493         call_func2_ptr_fpos(p_basic_istream_char_seekg_fpos, &ss.base.base1, pos);
1494         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1495         next  = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
1496
1497         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1498         ok(tests[i].next  == next,  "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
1499
1500         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1501         call_func1(p_basic_string_char_dtor, &str);
1502
1503         /* wchar_t version */
1504         AtoW(wide, tests[i].str, strlen(tests[i].str));
1505         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1506         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1507
1508         pos.off   = tests[i].off;
1509         pos.pos   = 0; /* FIXME: a later patch will test this with filebuf */
1510         pos.state = 0;
1511         call_func2_ptr_fpos(p_basic_istream_wchar_seekg_fpos, &wss.base.base1, pos);
1512         state  = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1513         nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
1514
1515         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1516         testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
1517         ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
1518
1519         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1520         call_func1(p_basic_string_wchar_dtor, &wstr);
1521     }
1522 }
1523
1524
1525 static void test_istream_peek(void)
1526 {
1527     unsigned short testus, nextus, peekus;
1528     basic_stringstream_wchar wss;
1529     basic_stringstream_char ss;
1530     basic_string_wchar wstr;
1531     basic_string_char str;
1532     IOSB_iostate state;
1533     int i, next, peek;
1534     wchar_t wide[64];
1535
1536     struct _test_istream_peek {
1537         const char  *str;
1538         int          peek;
1539         int          next;
1540         IOSB_iostate state;
1541     } tests[] = {
1542         { "",       EOF, EOF, IOSTATE_eofbit  },
1543         { "ABCDEF", 'A', 'A', IOSTATE_goodbit },
1544     };
1545
1546     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1547         /* char version */
1548         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1549         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1550
1551         peek  = (int)call_func1(p_basic_istream_char_peek, &ss.base.base1);
1552         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1553         next  = (int)call_func1(p_basic_istream_char_get, &ss.base.base1);
1554
1555         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1556         ok(tests[i].next  == next,  "wrong next, expected = %c (%i) found = %c (%i)\n", tests[i].next, tests[i].next, next, next);
1557         ok(peek == next, "wrong peek, expected %c (%i) found = %c (%i)\n", peek, peek, next, next);
1558
1559         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1560         call_func1(p_basic_string_char_dtor, &str);
1561
1562         /* wchar_t version */
1563         AtoW(wide, tests[i].str, strlen(tests[i].str));
1564         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1565         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1566
1567         peekus = (unsigned short)(int)call_func1(p_basic_istream_wchar_peek, &wss.base.base1);
1568         state  = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1569         nextus = (unsigned short)(int)call_func1(p_basic_istream_wchar_get, &wss.base.base1);
1570
1571         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1572         testus = tests[i].next == EOF ? WEOF : (unsigned short)tests[i].next;
1573         ok(testus == nextus, "wrong next, expected = %c (%i) found = %c (%i)\n", testus, testus, nextus, nextus);
1574         ok(peekus == nextus, "wrong peek, expected %c (%i) found = %c (%i)\n", peekus, peekus, nextus, nextus);
1575
1576         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1577         call_func1(p_basic_string_wchar_dtor, &wstr);
1578     }
1579 }
1580
1581
1582 static void test_istream_tellg(void)
1583 {
1584     basic_stringstream_wchar wss;
1585     basic_stringstream_char ss;
1586     basic_fstream_wchar wfs;
1587     basic_fstream_char fs;
1588     basic_string_wchar wstr;
1589     basic_string_char str;
1590     fpos_int spos, tpos, *rpos;
1591     wchar_t wide[64];
1592     FILE *file;
1593     int i;
1594
1595     const char *testfile = "file.txt";
1596
1597     struct _test_istream_tellg_fpos {
1598         const char  *str;
1599         streamoff    seekoff;
1600         streamoff    telloff_ss; /* offset for stringstream */
1601         streamoff    telloff_fs; /* offset for fstream */
1602         __int64      tellpos;
1603     } tests[] = {
1604         /* empty strings */
1605         { "", -1, -1,  0,  0 }, /* tellg on defaults */
1606         { "",  0, -1,  0,  0 }, /* tellg after seek 0 */
1607         { "", 42, -1,  0, 42 }, /* tellg after seek beyond end */
1608         { "", -6, -1, -1,  0 }, /* tellg after seek beyond beg */
1609
1610         /* non-empty strings */
1611         { "ABCDEFGHIJ", -1,  0,  0,  0 },
1612         { "ABCDEFGHIJ",  3,  3,  0,  3 },
1613         { "ABCDEFGHIJ", 42, -1,  0, 42 },
1614         { "ABCDEFGHIJ", -6, -1, -1,  0 }
1615     };
1616
1617     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1618         /* stringstream<char> version */
1619         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1620         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1621
1622         spos.off   = tests[i].seekoff;
1623         spos.pos   = 0;
1624         spos.state = 0;
1625
1626         tpos.off   = 0xdeadbeef;
1627         tpos.pos   = 0xdeadbeef;
1628         tpos.state = 0xdeadbeef;
1629
1630         if (tests[i].seekoff != -1) /* to test without seek */
1631             call_func2_ptr_fpos(p_basic_istream_char_seekg_fpos, &ss.base.base1, spos);
1632         rpos = (fpos_int *)call_func2(p_basic_istream_char_tellg, &ss.base.base1, &tpos);
1633
1634         ok(tests[i].telloff_ss == tpos.off, "wrong offset, expected = %ld found = %ld\n", tests[i].telloff_ss, tpos.off);
1635         if (tests[i].telloff_ss != -1 && spos.off != -1) /* check if tell == seek but only if not hit EOF */
1636             ok(spos.off == tpos.off, "tell doesn't match seek, seek = %ld tell = %ld\n", spos.off, tpos.off);
1637         ok(rpos == &tpos, "wrong return fpos, expected = %p found = %p\n", rpos, &tpos);
1638         ok(tpos.pos == 0, "wrong position, expected = 0 found = %s\n", debugstr_longlong(tpos.pos));
1639         ok(tpos.state == 0, "wrong state, expected = 0 found = %d\n", tpos.state);
1640
1641         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1642         call_func1(p_basic_string_char_dtor, &str);
1643
1644         /* stringstream<wchar_t> version */
1645         AtoW(wide, tests[i].str, strlen(tests[i].str));
1646         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1647         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1648
1649         spos.off   = tests[i].seekoff;
1650         spos.pos   = 0; /* FIXME: a later patch will test this with filebuf */
1651         spos.state = 0;
1652
1653         tpos.off   = 0xdeadbeef;
1654         tpos.pos   = 0xdeadbeef;
1655         tpos.state = 0xdeadbeef;
1656
1657         if (tests[i].seekoff != -1) /* to test without seek */
1658             call_func2_ptr_fpos(p_basic_istream_wchar_seekg_fpos, &wss.base.base1, spos);
1659         rpos = (fpos_int *)call_func2(p_basic_istream_wchar_tellg, &wss.base.base1, &tpos);
1660
1661         ok(tests[i].telloff_ss == tpos.off, "wrong offset, expected = %ld found = %ld\n", tests[i].telloff_ss, tpos.off);
1662         if (tests[i].telloff_ss != -1 && spos.off != -1) /* check if tell == seek but only if not hit EOF */
1663             ok(spos.off == tpos.off, "tell doesn't match seek, seek = %ld tell = %ld\n", spos.off, tpos.off);
1664         ok(rpos == &tpos, "wrong return fpos, expected = %p found = %p\n", rpos, &tpos);
1665         ok(tpos.pos == 0, "wrong position, expected = 0 found = %s\n", debugstr_longlong(tpos.pos));
1666         ok(tpos.state == 0, "wrong state, expected = 0 found = %d\n", tpos.state);
1667
1668         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1669         call_func1(p_basic_string_wchar_dtor, &wstr);
1670
1671         /* filebuf */
1672         file = fopen(testfile, "wt");
1673         fprintf(file, tests[i].str);
1674         fclose(file);
1675
1676         /* fstream<char> version */
1677         call_func5(p_basic_fstream_char_ctor_name, &fs, testfile, OPENMODE_out|OPENMODE_in, SH_DENYNO, TRUE);
1678
1679         spos.off   = tests[i].seekoff;
1680         spos.pos   = 0;
1681         spos.state = 0;
1682
1683         tpos.off   = 0xdeadbeef;
1684         tpos.pos   = 0xdeadbeef;
1685         tpos.state = 0xdeadbeef;
1686
1687         if (tests[i].seekoff != -1) /* to test without seek */
1688             call_func2_ptr_fpos(p_basic_istream_char_seekg_fpos, &fs.base.base1, spos);
1689         rpos = (fpos_int *)call_func2(p_basic_istream_char_tellg, &fs.base.base1, &tpos);
1690
1691         ok(tests[i].tellpos == tpos.pos, "wrong filepos, expected = %s found = %s\n",
1692             debugstr_longlong(tests[i].tellpos), debugstr_longlong(tpos.pos));
1693         ok(rpos == &tpos, "wrong return fpos, expected = %p found = %p\n", rpos, &tpos);
1694         ok(tpos.off == tests[i].telloff_fs, "wrong offset, expected %ld found %ld\n", tests[i].telloff_fs, tpos.off);
1695         ok(tpos.state == 0, "wrong state, expected = 0 found = %d\n", tpos.state);
1696
1697         call_func1(p_basic_fstream_char_vbase_dtor, &fs);
1698
1699         /* fstream<wchar_t> version */
1700         call_func5(p_basic_fstream_wchar_ctor_name, &wfs, testfile, OPENMODE_out|OPENMODE_in, SH_DENYNO, TRUE);
1701
1702         spos.off   = tests[i].seekoff;
1703         spos.pos   = 0;
1704         spos.state = 0;
1705
1706         tpos.off   = 0xdeadbeef;
1707         tpos.pos   = 0xdeadbeef;
1708         tpos.state = 0xdeadbeef;
1709
1710         if (tests[i].seekoff != -1) /* to test without seek */
1711             call_func2_ptr_fpos(p_basic_istream_wchar_seekg_fpos, &wfs.base.base1, spos);
1712         rpos = (fpos_int *)call_func2(p_basic_istream_wchar_tellg, &wfs.base.base1, &tpos);
1713
1714         ok(tests[i].tellpos == tpos.pos, "wrong filepos, expected = %s found = %s\n",
1715             debugstr_longlong(tests[i].tellpos), debugstr_longlong(tpos.pos));
1716         ok(rpos == &tpos, "wrong return fpos, expected = %p found = %p\n", rpos, &tpos);
1717         ok(tpos.off == tests[i].telloff_fs, "wrong offset, expected %ld found %ld\n", tests[i].telloff_fs, tpos.off);
1718         ok(tpos.state == 0, "wrong state, expected = 0 found = %d\n", tpos.state);
1719
1720         call_func1(p_basic_fstream_wchar_vbase_dtor, &wfs);
1721
1722         unlink(testfile);
1723     }
1724 }
1725
1726
1727 static void test_istream_getline(void)
1728 {
1729     basic_stringstream_wchar wss;
1730     basic_stringstream_char ss;
1731     basic_string_wchar wstr;
1732     basic_string_char str;
1733     IOSB_iostate state;
1734     wchar_t wide[64];
1735     int i;
1736     const char *cstr;
1737     const wchar_t *wcstr;
1738
1739     /* makes tables narrower */
1740     const IOSB_iostate IOSTATE_faileof = IOSTATE_failbit|IOSTATE_eofbit;
1741
1742     struct _test_istream_getline {
1743         const char  *str;
1744         const char  *line;
1745         int          delim;
1746         IOSB_iostate state;
1747         const char  *nextline;
1748         int          nextdelim;
1749         IOSB_iostate nextstate;
1750     } tests[] = {
1751         { "", "", '\n', IOSTATE_faileof, "", '\n', IOSTATE_faileof },
1752
1753         { "this\n",                 "this", '\n', IOSTATE_goodbit, "",   '\n', IOSTATE_faileof },
1754         { "this\nis\nsome\ntext\n", "this", '\n', IOSTATE_goodbit, "is", '\n', IOSTATE_goodbit },
1755
1756         { "this is some text\n", "this", ' ',  IOSTATE_goodbit, "is",           ' ',  IOSTATE_goodbit },
1757         { "this is some text\n", "this", ' ',  IOSTATE_goodbit, "is some text", '\n', IOSTATE_goodbit },
1758
1759         { "this is some text\n", "this is some text",   '\n', IOSTATE_goodbit, "",                    '\n', IOSTATE_faileof },
1760         { "this is some text\n", "this is some text\n", '\0', IOSTATE_eofbit,  "this is some text\n", '\n', IOSTATE_faileof },
1761     };
1762
1763     for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
1764         /* char version */
1765         call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
1766         call_func4(p_basic_stringstream_char_ctor_str, &ss, &str, OPENMODE_out|OPENMODE_in, TRUE);
1767
1768         p_basic_istream_char_getline_bstr_delim(&ss.base.base1, &str, tests[i].delim);
1769         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1770         cstr  = call_func1(p_basic_string_char_cstr, &str);
1771
1772         ok(!strcmp(tests[i].line, cstr), "wrong line, expected = %s found = %s\n", tests[i].line, cstr);
1773         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1774
1775         /* next line */
1776         p_basic_istream_char_getline_bstr_delim(&ss.base.base1, &str, tests[i].nextdelim);
1777         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &ss.basic_ios.base);
1778         cstr  = call_func1(p_basic_string_char_cstr, &str);
1779
1780         ok(!strcmp(tests[i].nextline, cstr), "wrong next line, expected = %s found = %s\n", tests[i].nextline, cstr);
1781         ok(tests[i].nextstate == state, "wrong next state, expected = %x found = %x\n", tests[i].nextstate, state);
1782
1783         call_func1(p_basic_stringstream_char_vbase_dtor, &ss);
1784         call_func1(p_basic_string_char_dtor, &str);
1785
1786         /* wchar_t version */
1787         AtoW(wide, tests[i].str, strlen(tests[i].str));
1788         call_func2(p_basic_string_wchar_ctor_cstr, &wstr, wide);
1789         call_func4(p_basic_stringstream_wchar_ctor_str, &wss, &wstr, OPENMODE_out|OPENMODE_in, TRUE);
1790
1791         p_basic_istream_wchar_getline_bstr_delim(&wss.base.base1, &wstr, tests[i].delim);
1792         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1793         wcstr = call_func1(p_basic_string_wchar_cstr, &wstr);
1794
1795         AtoW(wide, tests[i].line, strlen(tests[i].line));
1796         ok(!lstrcmpW(wide, wcstr), "wrong line, expected = %s found = %s\n", tests[i].line, wine_dbgstr_w(wcstr));
1797         ok(tests[i].state == state, "wrong state, expected = %x found = %x\n", tests[i].state, state);
1798
1799         /* next line */
1800         p_basic_istream_wchar_getline_bstr_delim(&wss.base.base1, &wstr, tests[i].nextdelim);
1801         state = (IOSB_iostate)call_func1(p_ios_base_rdstate, &wss.basic_ios.base);
1802         wcstr = call_func1(p_basic_string_wchar_cstr, &wstr);
1803
1804         AtoW(wide, tests[i].nextline, strlen(tests[i].nextline));
1805         ok(!lstrcmpW(wide, wcstr), "wrong line, expected = %s found = %s\n", tests[i].nextline, wine_dbgstr_w(wcstr));
1806         ok(tests[i].nextstate == state, "wrong state, expected = %x found = %x\n", tests[i].nextstate, state);
1807
1808         call_func1(p_basic_stringstream_wchar_vbase_dtor, &wss);
1809         call_func1(p_basic_string_wchar_dtor, &wstr);
1810     }
1811 }
1812
1813
1814 START_TEST(ios)
1815 {
1816     if(!init())
1817         return;
1818
1819     test_num_get_get_uint64();
1820     test_num_get_get_double();
1821     test_num_put_put_double();
1822     test_istream_ipfx();
1823     test_istream_ignore();
1824     test_istream_seekg();
1825     test_istream_seekg_fpos();
1826     test_istream_peek();
1827     test_istream_tellg();
1828     test_istream_getline();
1829
1830     ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");
1831 }