[5/5] msvcirt: Implement istream::read

Iván Matellanes matellanesivan at gmail.com
Mon Jul 18 10:00:20 CDT 2016


Signed-off-by: Iván Matellanes <matellanes.ivan at gmail.com>
---
 dlls/msvcirt/msvcirt.c       | 13 +++++++--
 dlls/msvcirt/tests/msvcirt.c | 69 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 2e3a308..f016328 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -3321,7 +3321,15 @@ istream* __thiscall istream_putback(istream *this, char ch)
 DEFINE_THISCALL_WRAPPER(istream_read, 12)
 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;
 }
 
@@ -3330,8 +3338,7 @@ istream* __thiscall istream_read(istream *this, char *str, int count)
 DEFINE_THISCALL_WRAPPER(istream_read_unsigned, 12)
 istream* __thiscall istream_read_unsigned(istream *this, unsigned char *str, int count)
 {
-    FIXME("(%p %p %d) stub\n", this, str, count);
-    return this;
+    return istream_read(this, (char*) str, count);
 }
 
 /* ?seekg at istream@@QAEAAV1 at J@Z */
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index 4c83297..28f5dbf 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -320,6 +320,7 @@ static istream* (*__thiscall p_istream_getline)(istream*, char*, int, char);
 static istream* (*__thiscall p_istream_ignore)(istream*, int, int);
 static int (*__thiscall p_istream_peek)(istream*);
 static istream* (*__thiscall p_istream_putback)(istream*, char);
+static istream* (*__thiscall p_istream_read)(istream*, char*, int);
 
 /* Emulate a __thiscall */
 #ifdef __i386__
@@ -528,6 +529,7 @@ static BOOL init(void)
         SET(p_istream_ignore, "?ignore at istream@@QEAAAEAV1 at HH@Z");
         SET(p_istream_peek, "?peek at istream@@QEAAHXZ");
         SET(p_istream_putback, "?putback at istream@@QEAAAEAV1 at D@Z");
+        SET(p_istream_read, "?read at istream@@QEAAAEAV1 at PEADH@Z");
     } else {
         p_operator_new = (void*)GetProcAddress(msvcrt, "??2 at YAPAXI@Z");
         p_operator_delete = (void*)GetProcAddress(msvcrt, "??3 at YAXPAX@Z");
@@ -658,6 +660,7 @@ static BOOL init(void)
         SET(p_istream_ignore, "?ignore at istream@@QAEAAV1 at HH@Z");
         SET(p_istream_peek, "?peek at istream@@QAEHXZ");
         SET(p_istream_putback, "?putback at istream@@QAEAAV1 at D@Z");
+        SET(p_istream_read, "?read at istream@@QAEAAV1 at PADH@Z");
     }
     SET(p_ios_static_lock, "?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A");
     SET(p_ios_lockc, "?lockc at 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 == -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, &is2);
     call_func1(p_ostream_vbase_dtor, &os);
-- 
2.7.4




More information about the wine-patches mailing list