[07/10] msvcirt: Implement ostream::write
Iván Matellanes
matellanesivan at gmail.com
Mon Jun 6 06:52:55 CDT 2016
Signed-off-by: Iván Matellanes <matellanes.ivan at gmail.com>
---
dlls/msvcirt/msvcirt.c | 16 +++++++++++-----
dlls/msvcirt/tests/msvcirt.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index fdf4914..05738b1 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -2492,7 +2492,15 @@ streampos __thiscall ostream_tellp(ostream *this)
DEFINE_THISCALL_WRAPPER(ostream_write_char, 12)
ostream* __thiscall ostream_write_char(ostream *this, const char *str, int count)
{
- FIXME("(%p %s %d) stub\n", this, str, count);
+ ios *base = ostream_get_ios(this);
+
+ TRACE("(%p %p %d)\n", this, str, count);
+
+ if (ostream_opfx(this)) {
+ if (streambuf_sputn(base->sb, str, count) != count)
+ ios_clear(base, IOSTATE_badbit | IOSTATE_failbit);
+ ostream_osfx(this);
+ }
return this;
}
@@ -2501,8 +2509,7 @@ ostream* __thiscall ostream_write_char(ostream *this, const char *str, int count
DEFINE_THISCALL_WRAPPER(ostream_write_signed_char, 12)
ostream* __thiscall ostream_write_signed_char(ostream *this, const signed char *str, int count)
{
- FIXME("(%p %s %d) stub\n", this, str, count);
- return this;
+ return ostream_write_char(this, (const char*) str, count);
}
/* ?write at ostream@@QAEAAV1 at PBEH@Z */
@@ -2510,8 +2517,7 @@ ostream* __thiscall ostream_write_signed_char(ostream *this, const signed char *
DEFINE_THISCALL_WRAPPER(ostream_write_unsigned_char, 12)
ostream* __thiscall ostream_write_unsigned_char(ostream *this, const unsigned char *str, int count)
{
- FIXME("(%p %s %d) stub\n", this, str, count);
- return this;
+ return ostream_write_char(this, (const char*) str, count);
}
/* ?writepad at ostream@@AAEAAV1 at PBD0@Z */
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index 59a78d1..e8a4ceb 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -265,6 +265,7 @@ 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);
+static ostream* (*__thiscall p_ostream_write_char)(ostream*, const char*, int);
/* Emulate a __thiscall */
#ifdef __i386__
@@ -434,6 +435,7 @@ static BOOL init(void)
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");
+ SET(p_ostream_write_char, "?write at ostream@@QEAAAEAV1 at PEBDH@Z");
} else {
p_operator_new = (void*)GetProcAddress(msvcrt, "??2 at YAPAXI@Z");
p_operator_delete = (void*)GetProcAddress(msvcrt, "??3 at YAXPAX@Z");
@@ -533,6 +535,7 @@ static BOOL init(void)
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_ostream_write_char, "?write at ostream@@QAEAAV1 at PBDH@Z");
}
SET(p_ios_static_lock, "?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A");
SET(p_ios_lockc, "?lockc at ios@@KAXXZ");
@@ -2751,6 +2754,38 @@ if (0) /* crashes on native */
ok(fb1.base.pptr == NULL, "wrong put pointer, expected %p got %p\n", NULL, fb1.base.pptr);
fb1.fd = fd;
+ /* write */
+ pos = (ostream*) call_func3(p_ostream_write_char, &os1, "Your", 4);
+ 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(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);
+ os1.base_ios.state = IOSTATE_goodbit;
+ os1.base_ios.width = 1;
+ pos = (ostream*) call_func3(p_ostream_write_char, &os1, "heart's", 7);
+ 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 == fb1.base.base, "wrong put base, expected %p got %p\n", fb1.base.base, fb1.base.pbase);
+ ok(fb1.base.pptr == fb1.base.base + 7, "wrong put pointer, expected %p got %p\n", fb1.base.base + 7, fb1.base.pptr);
+ os1.base_ios.sb = NULL;
+if (0) /* crashes on native */
+ pos = (ostream*) call_func3(p_ostream_write_char, &os1, "been", 4);
+ 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_func3(p_ostream_write_char, &os1, "aching,", 7);
+ 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