msvcirt: Implement stdiobuf constructors and destructor.

Signed-off-by: Iván Matellanes <matellanesivan@gmail.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
This commit is contained in:
Iván Matellanes 2015-10-02 15:03:20 +02:00 committed by Alexandre Julliard
parent 8f5e817d84
commit a9ad6e88d7
2 changed files with 68 additions and 3 deletions

View File

@ -1460,7 +1460,9 @@ int __thiscall strstreambuf_underflow(strstreambuf *this)
DEFINE_THISCALL_WRAPPER(stdiobuf_copy_ctor, 8)
stdiobuf* __thiscall stdiobuf_copy_ctor(stdiobuf *this, const stdiobuf *copy)
{
FIXME("(%p %p) stub\n", this, copy);
TRACE("(%p %p)\n", this, copy);
*this = *copy;
this->base.vtable = &MSVCP_stdiobuf_vtable;
return this;
}
@ -1469,7 +1471,10 @@ stdiobuf* __thiscall stdiobuf_copy_ctor(stdiobuf *this, const stdiobuf *copy)
DEFINE_THISCALL_WRAPPER(stdiobuf_file_ctor, 8)
stdiobuf* __thiscall stdiobuf_file_ctor(stdiobuf *this, FILE *file)
{
FIXME("(%p %p) stub\n", this, file);
TRACE("(%p %p)\n", this, file);
streambuf_reserve_ctor(&this->base, NULL, 0);
this->base.vtable = &MSVCP_stdiobuf_vtable;
this->file = file;
return this;
}
@ -1478,7 +1483,9 @@ stdiobuf* __thiscall stdiobuf_file_ctor(stdiobuf *this, FILE *file)
DEFINE_THISCALL_WRAPPER(stdiobuf_dtor, 4)
void __thiscall stdiobuf_dtor(stdiobuf *this)
{
FIXME("(%p) stub\n", this);
TRACE("(%p)\n", this);
call_streambuf_sync(&this->base);
streambuf_dtor(&this->base);
}
/* ??4stdiobuf@@QAEAAV0@ABV0@@Z */

View File

@ -115,6 +115,12 @@ typedef struct {
freeFunction f_free;
} strstreambuf;
/* class stdiobuf */
typedef struct {
streambuf base;
FILE *file;
} stdiobuf;
/* class ios */
struct _ostream;
typedef struct {
@ -200,6 +206,10 @@ static streampos (*__thiscall p_strstreambuf_seekoff)(strstreambuf*, streamoff,
static streambuf* (*__thiscall p_strstreambuf_setbuf)(strstreambuf*, char*, int);
static int (*__thiscall p_strstreambuf_underflow)(strstreambuf*);
/* stdiobuf */
static stdiobuf* (*__thiscall p_stdiobuf_file_ctor)(stdiobuf*, FILE*);
static void (*__thiscall p_stdiobuf_dtor)(stdiobuf*);
/* ios */
static ios* (*__thiscall p_ios_copy_ctor)(ios*, const ios*);
static ios* (*__thiscall p_ios_ctor)(ios*);
@ -358,6 +368,9 @@ static BOOL init(void)
SET(p_strstreambuf_setbuf, "?setbuf@strstreambuf@@UEAAPEAVstreambuf@@PEADH@Z");
SET(p_strstreambuf_underflow, "?underflow@strstreambuf@@UEAAHXZ");
SET(p_stdiobuf_file_ctor, "??0stdiobuf@@QEAA@PEAU_iobuf@@@Z");
SET(p_stdiobuf_dtor, "??1stdiobuf@@UEAA@XZ");
SET(p_ios_copy_ctor, "??0ios@@IEAA@AEBV0@@Z");
SET(p_ios_ctor, "??0ios@@IEAA@XZ");
SET(p_ios_sb_ctor, "??0ios@@QEAA@PEAVstreambuf@@@Z");
@ -436,6 +449,9 @@ static BOOL init(void)
SET(p_strstreambuf_setbuf, "?setbuf@strstreambuf@@UAEPAVstreambuf@@PADH@Z");
SET(p_strstreambuf_underflow, "?underflow@strstreambuf@@UAEHXZ");
SET(p_stdiobuf_file_ctor, "??0stdiobuf@@QAE@PAU_iobuf@@@Z");
SET(p_stdiobuf_dtor, "??1stdiobuf@@UAE@XZ");
SET(p_ios_copy_ctor, "??0ios@@IAE@ABV0@@Z");
SET(p_ios_ctor, "??0ios@@IAE@XZ");
SET(p_ios_sb_ctor, "??0ios@@QAE@PAVstreambuf@@@Z");
@ -1806,6 +1822,47 @@ static void test_strstreambuf(void)
call_func1(p_strstreambuf_dtor, &ssb2);
}
static void test_stdiobuf(void)
{
stdiobuf stb1, stb2;
FILE *file1, *file2;
const char filename1[] = "stdiobuf_test1";
const char filename2[] = "stdiobuf_test2";
memset(&stb1, 0xab, sizeof(stdiobuf));
memset(&stb2, 0xab, sizeof(stdiobuf));
file1 = fopen(filename1, "w");
fputs("Never gonna give you up, never gonna let you down", file1);
fclose(file1);
file1 = fopen(filename1, "r");
ok(file1 != NULL, "Couldn't open the file named '%s'\n", filename1);
file2 = fopen(filename2, "w+");
ok(file2 != NULL, "Couldn't open the file named '%s'\n", filename2);
/* constructors/destructor */
call_func2(p_stdiobuf_file_ctor, &stb1, NULL);
ok(stb1.base.allocated == 0, "wrong allocate value, expected 0 got %d\n", stb1.base.allocated);
ok(stb1.base.unbuffered == 1, "wrong unbuffered value, expected 1 got %d\n", stb1.base.unbuffered);
ok(stb1.file == NULL, "wrong file pointer, expected %p got %p\n", NULL, stb1.file);
call_func1(p_stdiobuf_dtor, &stb1);
call_func2(p_stdiobuf_file_ctor, &stb1, file1);
ok(stb1.base.allocated == 0, "wrong allocate value, expected 0 got %d\n", stb1.base.allocated);
ok(stb1.base.unbuffered == 1, "wrong unbuffered value, expected 1 got %d\n", stb1.base.unbuffered);
ok(stb1.file == file1, "wrong file pointer, expected %p got %p\n", file1, stb1.file);
call_func2(p_stdiobuf_file_ctor, &stb2, file2);
ok(stb2.base.allocated == 0, "wrong allocate value, expected 0 got %d\n", stb2.base.allocated);
ok(stb2.base.unbuffered == 1, "wrong unbuffered value, expected 1 got %d\n", stb2.base.unbuffered);
ok(stb2.file == file2, "wrong file pointer, expected %p got %p\n", file2, stb2.file);
call_func1(p_stdiobuf_dtor, &stb1);
call_func1(p_stdiobuf_dtor, &stb2);
fclose(file1);
fclose(file2);
ok(_unlink(filename1) == 0, "Couldn't unlink file named '%s'\n", filename1);
ok(_unlink(filename2) == 0, "Couldn't unlink file named '%s'\n", filename2);
}
struct ios_lock_arg
{
ios *ios_obj;
@ -2091,6 +2148,7 @@ START_TEST(msvcirt)
test_streambuf();
test_filebuf();
test_strstreambuf();
test_stdiobuf();
test_ios();
FreeLibrary(msvcrt);