=?UTF-8?Q?Iv=C3=A1n=20Matellanes=20?=: msvcirt: Implement ostream::put.
Alexandre Julliard
julliard at winehq.org
Wed Jun 15 11:39:41 CDT 2016
Module: wine
Branch: master
Commit: e1b3a5290262c19d4e49dfbb30b8c96f300b86af
URL: http://source.winehq.org/git/wine.git/?a=commit;h=e1b3a5290262c19d4e49dfbb30b8c96f300b86af
Author: Iván Matellanes <matellanesivan at gmail.com>
Date: Tue Jun 14 15:40:20 2016 +0100
msvcirt: Implement ostream::put.
Signed-off-by: Iván Matellanes <matellanes.ivan at gmail.com>
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/msvcirt/msvcirt.c | 16 +++++++++-----
dlls/msvcirt/tests/msvcirt.c | 51 +++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 61 insertions(+), 6 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 6872383..75c5a9d 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -2446,7 +2446,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)
+ base->state = IOSTATE_badbit | IOSTATE_failbit;
+ ostream_osfx(this);
+ }
return this;
}
@@ -2455,8 +2463,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 */
@@ -2464,8 +2471,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 f29bafd..f846c9e 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));
@@ -2732,6 +2735,52 @@ 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 */
+ ret = (int) call_func3(p_streambuf_xsputn, &fb2.base, "for so long", 11);
+ ok(ret == 11, "expected 11 got %d\n", ret);
+ os1.base_ios.state = IOSTATE_badbit;
+ 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);
More information about the wine-cvs
mailing list