[3/5] msvcirt: Implement istream::peek
Iván Matellanes
matellanesivan at gmail.com
Mon Jul 18 10:00:18 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 a025aab..88b6a62 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -3284,8 +3284,16 @@ istream* __thiscall istream_ignore(istream *this, int count, int delim)
DEFINE_THISCALL_WRAPPER(istream_peek, 4)
int __thiscall istream_peek(istream *this)
{
- FIXME("(%p) stub\n", this);
- return 0;
+ ios *base = istream_get_ios(this);
+ int ret = EOF;
+
+ TRACE("(%p)\n", this);
+
+ if (istream_ipfx(this, 1)) {
+ ret = streambuf_sgetc(base->sb);
+ istream_isfx(this);
+ }
+ return ret;
}
/* ?putback at istream@@QAEAAV1 at D@Z */
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index fdc1e36..f55ad86 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -318,6 +318,7 @@ static istream* (*__thiscall p_istream_get_char)(istream*, char*);
static istream* (*__thiscall p_istream_get_sb)(istream*, streambuf*, char);
static istream* (*__thiscall p_istream_getline)(istream*, char*, int, char);
static istream* (*__thiscall p_istream_ignore)(istream*, int, int);
+static int (*__thiscall p_istream_peek)(istream*);
/* Emulate a __thiscall */
#ifdef __i386__
@@ -524,6 +525,7 @@ static BOOL init(void)
SET(p_istream_get_sb, "?get at istream@@QEAAAEAV1 at AEAVstreambuf@@D at Z");
SET(p_istream_getline, "?getline at istream@@QEAAAEAV1 at PEADHD@Z");
SET(p_istream_ignore, "?ignore at istream@@QEAAAEAV1 at HH@Z");
+ SET(p_istream_peek, "?peek at istream@@QEAAHXZ");
} else {
p_operator_new = (void*)GetProcAddress(msvcrt, "??2 at YAPAXI@Z");
p_operator_delete = (void*)GetProcAddress(msvcrt, "??3 at YAXPAX@Z");
@@ -652,6 +654,7 @@ static BOOL init(void)
SET(p_istream_get_sb, "?get at istream@@QAEAAV1 at AAVstreambuf@@D at Z");
SET(p_istream_getline, "?getline at istream@@QAEAAV1 at PADHD@Z");
SET(p_istream_ignore, "?ignore at istream@@QAEAAV1 at HH@Z");
+ SET(p_istream_peek, "?peek 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");
@@ -4346,6 +4349,42 @@ if (0) /* crashes on native */
ok(is1.base_ios.state == IOSTATE_eofbit, "expected %d got %d\n", IOSTATE_eofbit, is1.base_ios.state);
ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
+ /* peek */
+ is1.count = 0xabababab;
+ ret = (int) call_func1(p_istream_peek, &is1);
+ ok(ret == EOF, "expected -1 got %d\n", ret);
+ ok(is1.count == 0, "expected 0 got %d\n", is1.count);
+ ok(is1.base_ios.state == (IOSTATE_eofbit|IOSTATE_failbit), "expected %d got %d\n",
+ IOSTATE_eofbit|IOSTATE_failbit, is1.base_ios.state);
+ is1.count = 0xabababab;
+ is1.base_ios.state = IOSTATE_goodbit;
+ ret = (int) call_func1(p_istream_peek, &is1);
+ ok(ret == EOF, "expected -1 got %d\n", ret);
+ ok(is1.count == 0, "expected 0 got %d\n", is1.count);
+ ok(is1.base_ios.state == IOSTATE_goodbit, "expected %d got %d\n", IOSTATE_goodbit, is1.base_ios.state);
+ ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
+ fb1.base.eback = fb1.base.gptr = fb1.base.base;
+ fb1.base.egptr = fb1.base.base + 30;
+ ret = (int) call_func1(p_istream_peek, &is1);
+ ok(ret == ' ', "expected ' ' got %d\n", ret);
+ ok(is1.count == 0, "expected 0 got %d\n", is1.count);
+ ok(is1.base_ios.state == IOSTATE_goodbit, "expected %d got %d\n", IOSTATE_goodbit, 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);
+if (0) /* crashes on native */
+ is1.base_ios.sb = NULL;
+ fb1.base.gptr = fb1.base.base + 14;
+ ret = (int) call_func1(p_istream_peek, &is1);
+ ok(ret == 206, "expected 206 got %d\n", ret);
+ ok(is1.count == 0, "expected 0 got %d\n", is1.count);
+ ok(is1.base_ios.state == IOSTATE_goodbit, "expected %d got %d\n", IOSTATE_goodbit, is1.base_ios.state);
+ ok(fb1.base.gptr == fb1.base.base + 14, "wrong get pointer, expected %p got %p\n", fb1.base.base + 14, fb1.base.gptr);
+ fb1.base.gptr = fb1.base.base + 30;
+ ret = (int) call_func1(p_istream_peek, &is1);
+ ok(ret == EOF, "expected -1 got %d\n", ret);
+ ok(is1.count == 0, "expected 0 got %d\n", is1.count);
+ ok(is1.base_ios.state == IOSTATE_goodbit, "expected %d got %d\n", IOSTATE_goodbit, is1.base_ios.state);
+ ok(fb1.base.gptr == NULL, "wrong get pointer, expected %p got %p\n", NULL, fb1.base.gptr);
+
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