[2/5] msvcirt: Implement istream::sync
Iván Matellanes
matellanesivan at gmail.com
Wed Jul 20 04:56:06 CDT 2016
Signed-off-by: Iván Matellanes <matellanes.ivan at gmail.com>
---
dlls/msvcirt/msvcirt.c | 12 ++++++++++--
dlls/msvcirt/tests/msvcirt.c | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 1715f80..12a4809 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -3378,8 +3378,16 @@ istream* __thiscall istream_seekg_offset(istream *this, streamoff off, ios_seek_
DEFINE_THISCALL_WRAPPER(istream_sync, 4)
int __thiscall istream_sync(istream *this)
{
- FIXME("(%p) stub\n", this);
- return 0;
+ ios *base = istream_get_ios(this);
+ int ret;
+
+ TRACE("(%p)\n", this);
+
+ ios_lockbuf(base);
+ if ((ret = call_streambuf_sync(base->sb)) == EOF)
+ ios_clear(base, base->state | IOSTATE_badbit | IOSTATE_failbit);
+ ios_unlockbuf(base);
+ return ret;
}
/* ?tellg at istream@@QAEJXZ */
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index 0bb3e98..af8a235 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -323,6 +323,7 @@ static istream* (*__thiscall p_istream_putback)(istream*, char);
static istream* (*__thiscall p_istream_read)(istream*, char*, int);
static istream* (*__thiscall p_istream_seekg)(istream*, streampos);
static istream* (*__thiscall p_istream_seekg_offset)(istream*, streamoff, ios_seek_dir);
+static int (*__thiscall p_istream_sync)(istream*);
/* Emulate a __thiscall */
#ifdef __i386__
@@ -534,6 +535,7 @@ static BOOL init(void)
SET(p_istream_read, "?read at istream@@QEAAAEAV1 at PEADH@Z");
SET(p_istream_seekg, "?seekg at istream@@QEAAAEAV1 at J@Z");
SET(p_istream_seekg_offset, "?seekg at istream@@QEAAAEAV1 at JW4seek_dir@ios@@@Z");
+ SET(p_istream_sync, "?sync at istream@@QEAAHXZ");
} else {
p_operator_new = (void*)GetProcAddress(msvcrt, "??2 at YAPAXI@Z");
p_operator_delete = (void*)GetProcAddress(msvcrt, "??3 at YAXPAX@Z");
@@ -667,6 +669,7 @@ static BOOL init(void)
SET(p_istream_read, "?read at istream@@QAEAAV1 at PADH@Z");
SET(p_istream_seekg, "?seekg at istream@@QAEAAV1 at J@Z");
SET(p_istream_seekg_offset, "?seekg at istream@@QAEAAV1 at JW4seek_dir@ios@@@Z");
+ SET(p_istream_sync, "?sync at istream@@QAEHXZ");
}
SET(p_ios_static_lock, "?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A");
SET(p_ios_lockc, "?lockc at ios@@KAXXZ");
@@ -4549,6 +4552,42 @@ if (0) /* crashes on native */
ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
ok(_tell(fb1.fd) == 24, "expected 24 got %d\n", _tell(fb1.fd));
+ /* sync */
+ ret = (int) call_func1(p_istream_sync, &is1);
+ ok(ret == 0, "expected 0 got %d\n", ret);
+ ok(is1.base_ios.state == IOSTATE_failbit, "expected %d got %d\n", IOSTATE_failbit, is1.base_ios.state);
+ is1.base_ios.state = IOSTATE_badbit;
+ ret = (int) call_func1(p_istream_sync, &is1);
+ ok(ret == 0, "expected 0 got %d\n", ret);
+ ok(is1.base_ios.state == IOSTATE_badbit, "expected %d got %d\n", IOSTATE_badbit, is1.base_ios.state);
+ is1.base_ios.state = IOSTATE_goodbit;
+ ret = (int) call_func1(p_istream_sync, &is1);
+ ok(ret == 0, "expected 0 got %d\n", ret);
+ ok(is1.base_ios.state == IOSTATE_goodbit, "expected %d got %d\n", IOSTATE_goodbit, is1.base_ios.state);
+if (0) /* crashes on native */
+ is1.base_ios.sb = NULL;
+ fb1.base.eback = fb1.base.gptr = fb1.base.base;
+ fb1.base.egptr = fb1.base.base + 30;
+ ret = (int) call_func1(p_istream_sync, &is1);
+ ok(ret == EOF, "expected -1 got %d\n", ret);
+ ok(is1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit), "expected %d got %d\n",
+ IOSTATE_badbit|IOSTATE_failbit, 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);
+ fb1.base.gptr = fb1.base.egptr;
+ ret = (int) call_func1(p_istream_sync, &is1);
+ ok(ret == 0, "expected 0 got %d\n", ret);
+ ok(is1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit), "expected %d got %d\n",
+ IOSTATE_badbit|IOSTATE_failbit, is1.base_ios.state);
+ ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
+ is1.base_ios.state = IOSTATE_eofbit;
+ fd = fb1.fd;
+ fb1.fd = -1;
+ ret = (int) call_func1(p_istream_sync, &is1);
+ ok(ret == EOF, "expected -1 got %d\n", ret);
+ ok(is1.base_ios.state == (IOSTATE_badbit|IOSTATE_failbit|IOSTATE_eofbit), "expected %d got %d\n",
+ IOSTATE_badbit|IOSTATE_failbit|IOSTATE_eofbit, is1.base_ios.state);
+ fb1.fd = fd;
+
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