msvcirt: Implement istream::read.

Signed-off-by: Iván Matellanes <matellanes.ivan@gmail.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Iván Matellanes 2016-07-18 16:00:20 +01:00 committed by Alexandre Julliard
parent 25a02cc4a9
commit e6be6283b6
2 changed files with 79 additions and 3 deletions

View File

@ -3321,7 +3321,15 @@ istream* __thiscall istream_putback(istream *this, char ch)
DEFINE_THISCALL_WRAPPER(istream_read, 12) DEFINE_THISCALL_WRAPPER(istream_read, 12)
istream* __thiscall istream_read(istream *this, char *str, int count) istream* __thiscall istream_read(istream *this, char *str, int count)
{ {
FIXME("(%p %p %d) stub\n", this, str, count); ios *base = istream_get_ios(this);
TRACE("(%p %p %d)\n", this, str, count);
if (istream_ipfx(this, 1)) {
if ((this->count = streambuf_sgetn(base->sb, str, count)) != count)
base->state = IOSTATE_eofbit | IOSTATE_failbit;
istream_isfx(this);
}
return this; return this;
} }
@ -3330,8 +3338,7 @@ istream* __thiscall istream_read(istream *this, char *str, int count)
DEFINE_THISCALL_WRAPPER(istream_read_unsigned, 12) DEFINE_THISCALL_WRAPPER(istream_read_unsigned, 12)
istream* __thiscall istream_read_unsigned(istream *this, unsigned char *str, int count) istream* __thiscall istream_read_unsigned(istream *this, unsigned char *str, int count)
{ {
FIXME("(%p %p %d) stub\n", this, str, count); return istream_read(this, (char*) str, count);
return this;
} }
/* ?seekg@istream@@QAEAAV1@J@Z */ /* ?seekg@istream@@QAEAAV1@J@Z */

View File

@ -320,6 +320,7 @@ static istream* (*__thiscall p_istream_getline)(istream*, char*, int, char);
static istream* (*__thiscall p_istream_ignore)(istream*, int, int); static istream* (*__thiscall p_istream_ignore)(istream*, int, int);
static int (*__thiscall p_istream_peek)(istream*); static int (*__thiscall p_istream_peek)(istream*);
static istream* (*__thiscall p_istream_putback)(istream*, char); static istream* (*__thiscall p_istream_putback)(istream*, char);
static istream* (*__thiscall p_istream_read)(istream*, char*, int);
/* Emulate a __thiscall */ /* Emulate a __thiscall */
#ifdef __i386__ #ifdef __i386__
@ -528,6 +529,7 @@ static BOOL init(void)
SET(p_istream_ignore, "?ignore@istream@@QEAAAEAV1@HH@Z"); SET(p_istream_ignore, "?ignore@istream@@QEAAAEAV1@HH@Z");
SET(p_istream_peek, "?peek@istream@@QEAAHXZ"); SET(p_istream_peek, "?peek@istream@@QEAAHXZ");
SET(p_istream_putback, "?putback@istream@@QEAAAEAV1@D@Z"); SET(p_istream_putback, "?putback@istream@@QEAAAEAV1@D@Z");
SET(p_istream_read, "?read@istream@@QEAAAEAV1@PEADH@Z");
} else { } else {
p_operator_new = (void*)GetProcAddress(msvcrt, "??2@YAPAXI@Z"); p_operator_new = (void*)GetProcAddress(msvcrt, "??2@YAPAXI@Z");
p_operator_delete = (void*)GetProcAddress(msvcrt, "??3@YAXPAX@Z"); p_operator_delete = (void*)GetProcAddress(msvcrt, "??3@YAXPAX@Z");
@ -658,6 +660,7 @@ static BOOL init(void)
SET(p_istream_ignore, "?ignore@istream@@QAEAAV1@HH@Z"); SET(p_istream_ignore, "?ignore@istream@@QAEAAV1@HH@Z");
SET(p_istream_peek, "?peek@istream@@QAEHXZ"); SET(p_istream_peek, "?peek@istream@@QAEHXZ");
SET(p_istream_putback, "?putback@istream@@QAEAAV1@D@Z"); SET(p_istream_putback, "?putback@istream@@QAEAAV1@D@Z");
SET(p_istream_read, "?read@istream@@QAEAAV1@PADH@Z");
} }
SET(p_ios_static_lock, "?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A"); SET(p_ios_static_lock, "?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A");
SET(p_ios_lockc, "?lockc@ios@@KAXXZ"); SET(p_ios_lockc, "?lockc@ios@@KAXXZ");
@ -4426,6 +4429,72 @@ if (0) /* crashes on native */
ok(fb1.base.gptr == fb1.base.base + 14, "wrong get pointer, expected %p got %p\n", fb1.base.base + 14, fb1.base.gptr); ok(fb1.base.gptr == fb1.base.base + 14, "wrong get pointer, expected %p got %p\n", fb1.base.base + 14, fb1.base.gptr);
ok(*fb1.base.gptr == -40, "expected -40 got %d\n", *fb1.base.gptr); ok(*fb1.base.gptr == -40, "expected -40 got %d\n", *fb1.base.gptr);
/* read */
is1.extract_delim = is1.count = 0xabababab;
is1.base_ios.state = IOSTATE_badbit;
memset(buffer, 'A', sizeof(buffer));
pis = call_func3(p_istream_read, &is1, buffer, 10);
ok(pis == &is1, "wrong return, expected %p got %p\n", &is1, pis);
ok(is1.count == 0, "expected 0 got %d\n", is1.count);
ok(is1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit), "expected %d got %d\n",
IOSTATE_badbit|IOSTATE_failbit, is1.base_ios.state);
ok(buffer[0] == 'A', "expected 'A' got %d\n", buffer[0]);
is1.base_ios.state = IOSTATE_goodbit;
fb1.base.gptr = fb1.base.base;
memset(buffer, 'A', sizeof(buffer));
pis = call_func3(p_istream_read, &is1, buffer, 10);
ok(pis == &is1, "wrong return, expected %p got %p\n", &is1, pis);
ok(is1.count == 10, "expected 10 got %d\n", is1.count);
ok(is1.base_ios.state == IOSTATE_goodbit, "expected %d got %d\n", IOSTATE_goodbit, is1.base_ios.state);
ok(fb1.base.gptr == fb1.base.base + 10, "wrong get pointer, expected %p got %p\n", fb1.base.base + 10, fb1.base.gptr);
ok(!strncmp(buffer, fb1.base.base, 10), "unexpected buffer content, got '%s'\n", buffer);
ok(buffer[10] == 'A', "expected 'A' got %d\n", buffer[10]);
memset(buffer, 'A', sizeof(buffer));
pis = call_func3(p_istream_read, &is1, buffer, 20);
ok(pis == &is1, "wrong return, expected %p got %p\n", &is1, pis);
ok(is1.count == 20, "expected 20 got %d\n", is1.count);
ok(is1.base_ios.state == IOSTATE_goodbit, "expected %d got %d\n", IOSTATE_goodbit, is1.base_ios.state);
ok(fb1.base.gptr == fb1.base.base + 30, "wrong get pointer, expected %p got %p\n", fb1.base.base + 30, fb1.base.gptr);
ok(!strncmp(buffer, fb1.base.base + 10, 20), "unexpected buffer content, got '%s'\n", buffer);
ok(buffer[4] == -40, "expected -40 got %d\n", buffer[4]);
ok(buffer[20] == 'A', "expected 'A' got %d\n", buffer[20]);
memset(buffer, 'A', sizeof(buffer));
pis = call_func3(p_istream_read, &is1, buffer, 5);
ok(pis == &is1, "wrong return, expected %p got %p\n", &is1, pis);
ok(is1.count == 1, "expected 1 got %d\n", is1.count);
ok(is1.base_ios.state == (IOSTATE_eofbit|IOSTATE_failbit), "expected %d got %d\n",
IOSTATE_eofbit|IOSTATE_failbit, is1.base_ios.state);
ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
ok(buffer[0] == 'e', "expected 'e' got %d\n", buffer[0]);
ok(buffer[1] == 'A', "expected 'A' got %d\n", buffer[1]);
is1.base_ios.state = IOSTATE_goodbit;
fb1.base.eback = fb1.base.gptr = fb1.base.base;
fb1.base.egptr = fb1.base.base + 30;
memset(buffer, 'A', sizeof(buffer));
pis = call_func3(p_istream_read, &is1, buffer, 35);
ok(pis == &is1, "wrong return, expected %p got %p\n", &is1, pis);
ok(is1.count == 30, "expected 30 got %d\n", is1.count);
ok(is1.base_ios.state == (IOSTATE_eofbit|IOSTATE_failbit), "expected %d got %d\n",
IOSTATE_eofbit|IOSTATE_failbit, is1.base_ios.state);
ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
ok(!strncmp(buffer, fb1.base.base, 30), "unexpected buffer content, got '%s'\n", buffer);
ok(buffer[30] == 'A', "expected 'A' got %d\n", buffer[30]);
if (0) /* crashes on native */
is1.base_ios.sb = NULL;
is1.base_ios.state = IOSTATE_goodbit;
fb1.base.eback = fb1.base.gptr = fb1.base.base;
fb1.base.egptr = fb1.base.base + 30;
memset(buffer, 'A', sizeof(buffer));
if (0) /* crashes on native */
pis = call_func3(p_istream_read, &is1, buffer, -1);
pis = call_func3(p_istream_read, &is1, buffer, 0);
ok(pis == &is1, "wrong return, expected %p got %p\n", &is1, pis);
ok(is1.count == 0, "expected 0 got %d\n", is1.count);
ok(is1.base_ios.state == IOSTATE_goodbit, "expected %d got %d\n", IOSTATE_goodbit, is1.base_ios.state);
ok(fb1.base.gptr == fb1.base.base, "wrong get pointer, expected %p got %p\n", fb1.base.base, fb1.base.gptr);
ok(buffer[0] == 'A', "expected 'A' got %d\n", buffer[0]);
fb1.base.gptr = fb1.base.egptr;
call_func1(p_istream_vbase_dtor, &is1); call_func1(p_istream_vbase_dtor, &is1);
call_func1(p_istream_vbase_dtor, &is2); call_func1(p_istream_vbase_dtor, &is2);
call_func1(p_ostream_vbase_dtor, &os); call_func1(p_ostream_vbase_dtor, &os);