Module: wine Branch: master Commit: 327cada0f1b81a3fd55f1a9047317ded2c6b149c URL: http://source.winehq.org/git/wine.git/?a=commit;h=327cada0f1b81a3fd55f1a9047... Author: Iván Matellanes <matellanesivan(a)gmail.com> Date: Tue Jun 14 15:40:18 2016 +0100 msvcirt: Implement ostream::opfx. Signed-off-by: Iván Matellanes <matellanes.ivan(a)gmail.com> Signed-off-by: Piotr Caban <piotr(a)codeweavers.com> Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- dlls/msvcirt/msvcirt.c | 15 +++++++++++++-- dlls/msvcirt/tests/msvcirt.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c index 2d9c235..54012c0 100644 --- a/dlls/msvcirt/msvcirt.c +++ b/dlls/msvcirt/msvcirt.c @@ -2406,8 +2406,19 @@ ostream* __thiscall ostream_flush(ostream *this) DEFINE_THISCALL_WRAPPER(ostream_opfx, 4) int __thiscall ostream_opfx(ostream *this) { - FIXME("(%p) stub\n", this); - return 0; + ios *base = ostream_get_ios(this); + + TRACE("(%p)\n", this); + + if (!ios_good(base)) { + ios_clear(base, base->state | IOSTATE_failbit); + return 0; + } + ios_lock(base); + ios_lockbuf(base); + if (base->tie) + ostream_flush(base->tie); + return 1; } /* ?osfx(a)ostream@@QAEXXZ */ diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c index 045c224..7197126 100644 --- a/dlls/msvcirt/tests/msvcirt.c +++ b/dlls/msvcirt/tests/msvcirt.c @@ -262,6 +262,7 @@ static ostream* (*__thiscall p_ostream_assign)(ostream*, const ostream*); static ostream* (*__thiscall p_ostream_assign_sb)(ostream*, streambuf*); static void (*__thiscall p_ostream_vbase_dtor)(ostream*); static ostream* (*__thiscall p_ostream_flush)(ostream*); +static int (*__thiscall p_ostream_opfx)(ostream*); /* Emulate a __thiscall */ #ifdef __i386__ @@ -428,6 +429,7 @@ static BOOL init(void) SET(p_ostream_assign_sb, "??4ostream@@IEAAAEAV0(a)PEAVstreambuf@@@Z"); SET(p_ostream_vbase_dtor, "??_Dostream@@QEAAXXZ"); SET(p_ostream_flush, "?flush(a)ostream@@QEAAAEAV1(a)XZ"); + SET(p_ostream_opfx, "?opfx(a)ostream@@QEAAHXZ"); } else { p_operator_new = (void*)GetProcAddress(msvcrt, "??2(a)YAPAXI@Z"); p_operator_delete = (void*)GetProcAddress(msvcrt, "??3(a)YAXPAX@Z"); @@ -524,6 +526,7 @@ static BOOL init(void) SET(p_ostream_assign_sb, "??4ostream@@IAEAAV0(a)PAVstreambuf@@@Z"); SET(p_ostream_vbase_dtor, "??_Dostream@@QAEXXZ"); SET(p_ostream_flush, "?flush(a)ostream@@QAEAAV1(a)XZ"); + SET(p_ostream_opfx, "?opfx(a)ostream@@QAEHXZ"); } SET(p_ios_static_lock, "?x_lockc(a)ios@@0U_CRT_CRITICAL_SECTION@@A"); SET(p_ios_lockc, "?lockc(a)ios@@KAXXZ"); @@ -2666,6 +2669,44 @@ if (0) /* crashes on native */ 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 + 12, "wrong put pointer, expected %p got %p\n", fb2.base.base + 12, fb2.base.pptr); + /* opfx */ + ret = (int) call_func1(p_ostream_opfx, &os1); + ok(ret == 0, "expected 0 got %d\n", ret); + ok(os1.base_ios.state == (IOSTATE_eofbit|IOSTATE_failbit), "expected %d got %d\n", + IOSTATE_eofbit|IOSTATE_failbit, os1.base_ios.state); + os1.base_ios.state = IOSTATE_badbit; + ret = (int) call_func1(p_ostream_opfx, &os1); + ok(ret == 0, "expected 0 got %d\n", ret); + ok(os1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit), "expected %d got %d\n", + IOSTATE_badbit|IOSTATE_failbit, os1.base_ios.state); + os1.base_ios.sb = (streambuf*) &fb1; + os1.base_ios.state = IOSTATE_badbit; + ret = (int) call_func1(p_ostream_opfx, &os1); + ok(ret == 0, "expected 0 got %d\n", ret); + ok(os1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit), "expected %d got %d\n", + IOSTATE_badbit|IOSTATE_failbit, os1.base_ios.state); + os1.base_ios.state = IOSTATE_failbit; + ret = (int) call_func1(p_ostream_opfx, &os1); + ok(ret == 0, "expected 0 got %d\n", ret); + ok(os1.base_ios.state == IOSTATE_failbit, "expected %d got %d\n", IOSTATE_failbit, os1.base_ios.state); + os1.base_ios.state = IOSTATE_goodbit; + os1.base_ios.tie = &os2; + os2.base_ios.sb = NULL; +if (0) /* crashes on native */ + ret = (int) call_func1(p_ostream_opfx, &os1); + os2.base_ios.sb = (streambuf*) &fb2; + os2.base_ios.state = IOSTATE_badbit; + ret = (int) call_func3(p_streambuf_xsputn, &fb1.base, "We've known each other", 22); + ok(ret == 22, "expected 22 got %d\n", ret); + ret = (int) call_func1(p_ostream_opfx, &os1); + ok(ret == 1, "expected 1 got %d\n", ret); + ok(os1.base_ios.state == IOSTATE_goodbit, "expected %d got %d\n", IOSTATE_goodbit, os1.base_ios.state); + ok(os2.base_ios.state == IOSTATE_badbit, "expected %d got %d\n", IOSTATE_badbit, os2.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 + 22, "wrong put pointer, expected %p got %p\n", fb1.base.base + 22, 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); + call_func1(p_ostream_vbase_dtor, &os1); call_func1(p_ostream_vbase_dtor, &os2); call_func1(p_filebuf_dtor, &fb1);