[06/10] msvcirt: Implement ostream::put

Iván Matellanes matellanesivan at gmail.com
Mon Jun 6 06:52:54 CDT 2016


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

diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 75cf128..fdf4914 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -2432,7 +2432,15 @@ void __thiscall ostream_osfx(ostream *this)
 DEFINE_THISCALL_WRAPPER(ostream_put_char, 8)
 ostream* __thiscall ostream_put_char(ostream *this, char c)
 {
-    FIXME("(%p %c) stub\n", this, c);
+    ios *base = ostream_get_ios(this);
+
+    TRACE("(%p %c)\n", this, c);
+
+    if (ostream_opfx(this)) {
+        if (streambuf_sputc(base->sb, c) == EOF)
+            ios_clear(base, IOSTATE_badbit | IOSTATE_failbit);
+        ostream_osfx(this);
+    }
     return this;
 }
 
@@ -2441,8 +2449,7 @@ ostream* __thiscall ostream_put_char(ostream *this, char c)
 DEFINE_THISCALL_WRAPPER(ostream_put_signed_char, 8)
 ostream* __thiscall ostream_put_signed_char(ostream *this, signed char c)
 {
-    FIXME("(%p %c) stub\n", this, c);
-    return this;
+    return ostream_put_char(this, (char) c);
 }
 
 /* ?put at ostream@@QAEAAV1 at E@Z */
@@ -2450,8 +2457,7 @@ ostream* __thiscall ostream_put_signed_char(ostream *this, signed char c)
 DEFINE_THISCALL_WRAPPER(ostream_put_unsigned_char, 8)
 ostream* __thiscall ostream_put_unsigned_char(ostream *this, unsigned char c)
 {
-    FIXME("(%p %c) stub\n", this, c);
-    return this;
+    return ostream_put_char(this, (char) c);
 }
 
 /* ?seekp at ostream@@QAEAAV1 at J@Z */
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index 86996f6..59a78d1 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -264,6 +264,7 @@ static void (*__thiscall p_ostream_vbase_dtor)(ostream*);
 static ostream* (*__thiscall p_ostream_flush)(ostream*);
 static int (*__thiscall p_ostream_opfx)(ostream*);
 static void (*__thiscall p_ostream_osfx)(ostream*);
+static ostream* (*__thiscall p_ostream_put_char)(ostream*, char);
 
 /* Emulate a __thiscall */
 #ifdef __i386__
@@ -432,6 +433,7 @@ static BOOL init(void)
         SET(p_ostream_flush, "?flush at ostream@@QEAAAEAV1 at XZ");
         SET(p_ostream_opfx, "?opfx at ostream@@QEAAHXZ");
         SET(p_ostream_osfx, "?osfx at ostream@@QEAAXXZ");
+        SET(p_ostream_put_char, "?put at ostream@@QEAAAEAV1 at D@Z");
     } else {
         p_operator_new = (void*)GetProcAddress(msvcrt, "??2 at YAPAXI@Z");
         p_operator_delete = (void*)GetProcAddress(msvcrt, "??3 at YAXPAX@Z");
@@ -530,6 +532,7 @@ static BOOL init(void)
         SET(p_ostream_flush, "?flush at ostream@@QAEAAV1 at XZ");
         SET(p_ostream_opfx, "?opfx at ostream@@QAEHXZ");
         SET(p_ostream_osfx, "?osfx at ostream@@QAEXXZ");
+        SET(p_ostream_put_char, "?put at ostream@@QAEAAV1 at D@Z");
     }
     SET(p_ios_static_lock, "?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A");
     SET(p_ios_lockc, "?lockc at ios@@KAXXZ");
@@ -2520,7 +2523,7 @@ static void test_ostream(void) {
     filebuf fb1, fb2, *pfb;
     const char filename1[] = "test1";
     const char filename2[] = "test2";
-    int ret;
+    int fd, ret;
 
     memset(&os1, 0xab, sizeof(ostream));
     memset(&os2, 0xab, sizeof(ostream));
@@ -2705,6 +2708,49 @@ if (0) /* crashes on native */
     ok(fb1.base.pbase == NULL, "wrong put base, expected %p got %p\n", NULL, fb1.base.pbase);
     ok(fb1.base.pptr == NULL, "wrong put pointer, expected %p got %p\n", NULL, fb1.base.pptr);
 
+    /* put */
+    os1.base_ios.width = 2;
+    pos = (ostream*) call_func2(p_ostream_put_char, &os1, 'a');
+    ok(pos == &os1, "wrong return, expected %p got %p\n", &os1, pos);
+    ok(os1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit), "expected %d got %d\n",
+        IOSTATE_badbit|IOSTATE_failbit, os1.base_ios.state);
+    ok(os1.base_ios.width == 2, "expected 2 got %d\n", os1.base_ios.width);
+    ok(fb1.base.pbase == NULL, "wrong put base, expected %p got %p\n", NULL, fb1.base.pbase);
+    ok(fb1.base.pptr == NULL, "wrong put pointer, expected %p got %p\n", NULL, fb1.base.pptr);
+    ok(fb2.base.pbase == fb2.base.base, "wrong put base, expected %p got %p\n", fb2.base.base, fb2.base.pbase);
+    ok(fb2.base.pptr == fb2.base.base + 11, "wrong put pointer, expected %p got %p\n", fb2.base.base + 11, fb2.base.pptr);
+    os1.base_ios.state = IOSTATE_goodbit;
+    pos = (ostream*) call_func2(p_ostream_put_char, &os1, 'a');
+    ok(pos == &os1, "wrong return, expected %p got %p\n", &os1, pos);
+    ok(os1.base_ios.state == IOSTATE_goodbit, "expected %d got %d\n", IOSTATE_goodbit, os1.base_ios.state);
+    ok(os1.base_ios.width == 0, "expected 0 got %d\n", os1.base_ios.width);
+    ok(fb1.base.pbase == NULL, "wrong put base, expected %p got %p\n", NULL, fb1.base.pbase);
+    ok(fb1.base.pptr == NULL, "wrong put pointer, expected %p got %p\n", NULL, fb1.base.pptr);
+    ok(fb2.base.pbase == NULL, "wrong put base, expected %p got %p\n", NULL, fb2.base.pbase);
+    ok(fb2.base.pptr == NULL, "wrong put pointer, expected %p got %p\n", NULL, fb2.base.pptr);
+    os1.base_ios.flags = 0;
+    pos = (ostream*) call_func2(p_ostream_put_char, &os1, 'b');
+    ok(pos == &os1, "wrong return, expected %p got %p\n", &os1, pos);
+    ok(os1.base_ios.state == IOSTATE_goodbit, "expected %d got %d\n", IOSTATE_goodbit, os1.base_ios.state);
+    ok(fb1.base.pbase == fb1.base.base, "wrong put base, expected %p got %p\n", fb1.base.base, fb1.base.pbase);
+    ok(fb1.base.pptr == fb1.base.base + 1, "wrong put pointer, expected %p got %p\n", fb1.base.base + 1, fb1.base.pptr);
+    os1.base_ios.sb = NULL;
+if (0) /* crashes on native */
+    pos = (ostream*) call_func2(p_ostream_put_char, &os1, 'c');
+    os1.base_ios.sb = (streambuf*) &fb1;
+    os1.base_ios.width = 5;
+    call_func1(p_filebuf_sync, &fb1);
+    fd = fb1.fd;
+    fb1.fd = -1;
+    pos = (ostream*) call_func2(p_ostream_put_char, &os1, 'c');
+    ok(pos == &os1, "wrong return, expected %p got %p\n", &os1, pos);
+    ok(os1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit), "expected %d got %d\n",
+        IOSTATE_badbit|IOSTATE_failbit, os1.base_ios.state);
+    ok(os1.base_ios.width == 0, "expected 0 got %d\n", os1.base_ios.width);
+    ok(fb1.base.pbase == NULL, "wrong put base, expected %p got %p\n", NULL, fb1.base.pbase);
+    ok(fb1.base.pptr == NULL, "wrong put pointer, expected %p got %p\n", NULL, fb1.base.pptr);
+    fb1.fd = fd;
+
     call_func1(p_ostream_vbase_dtor, &os1);
     call_func1(p_ostream_vbase_dtor, &os2);
     call_func1(p_filebuf_dtor, &fb1);
-- 
2.7.4




More information about the wine-patches mailing list