[07/13] msvcirt: Implement ios status-testing functions

Iván Matellanes matellanesivan at gmail.com
Fri Jul 17 09:36:55 CDT 2015


---
 dlls/msvcirt/msvcirt.c       | 25 ++++++++++++----------
 dlls/msvcirt/tests/msvcirt.c | 50 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 11 deletions(-)

diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 5bae2c8..1397ccd 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -843,8 +843,8 @@ ios* __thiscall ios_scalar_dtor(ios *this, unsigned int flags)
 DEFINE_THISCALL_WRAPPER(ios_bad, 4)
 int __thiscall ios_bad(const ios *this)
 {
-    FIXME("(%p) stub\n", this);
-    return 0;
+    TRACE("(%p)\n", this);
+    return (this->state & IOSTATE_badbit);
 }
 
 /* ?bitalloc at ios@@SAJXZ */
@@ -859,7 +859,10 @@ LONG __cdecl ios_bitalloc(void)
 DEFINE_THISCALL_WRAPPER(ios_clear, 8)
 void __thiscall ios_clear(ios *this, int state)
 {
-    FIXME("(%p %d) stub\n", this, state);
+    TRACE("(%p %d)\n", this, state);
+    ios_lock(this);
+    this->state = state;
+    ios_unlock(this);
 }
 
 /* ?clrlock at ios@@QAAXXZ */
@@ -904,8 +907,8 @@ ios* __cdecl ios_dec(ios *this)
 DEFINE_THISCALL_WRAPPER(ios_eof, 4)
 int __thiscall ios_eof(const ios *this)
 {
-    FIXME("(%p) stub\n", this);
-    return 0;
+    TRACE("(%p)\n", this);
+    return (this->state & IOSTATE_eofbit);
 }
 
 /* ?fail at ios@@QBEHXZ */
@@ -913,8 +916,8 @@ int __thiscall ios_eof(const ios *this)
 DEFINE_THISCALL_WRAPPER(ios_fail, 4)
 int __thiscall ios_fail(const ios *this)
 {
-    FIXME("(%p) stub\n", this);
-    return 0;
+    TRACE("(%p)\n", this);
+    return (this->state & (IOSTATE_failbit|IOSTATE_badbit));
 }
 
 /* ?fill at ios@@QAEDD at Z */
@@ -966,8 +969,8 @@ LONG __thiscall ios_flags_get(const ios *this)
 DEFINE_THISCALL_WRAPPER(ios_good, 4)
 int __thiscall ios_good(const ios *this)
 {
-    FIXME("(%p) stub\n", this);
-    return 0;
+    TRACE("(%p)\n", this);
+    return this->state == IOSTATE_goodbit;
 }
 
 /* ?hex@@YAAAVios@@AAV1@@Z */
@@ -1088,8 +1091,8 @@ streambuf* __thiscall ios_rdbuf(const ios *this)
 DEFINE_THISCALL_WRAPPER(ios_rdstate, 4)
 int __thiscall ios_rdstate(const ios *this)
 {
-    FIXME("(%p) stub\n", this);
-    return 0;
+    TRACE("(%p)\n", this);
+    return this->state;
 }
 
 /* ?setf at ios@@QAEJJ at Z */
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index 1b730b9..c65d419 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -142,6 +142,11 @@ static LONG (*__thiscall p_ios_flags_get)(const ios*);
 static LONG (*__thiscall p_ios_setf)(ios*, LONG);
 static LONG (*__thiscall p_ios_setf_mask)(ios*, LONG, LONG);
 static LONG (*__thiscall p_ios_unsetf)(ios*, LONG);
+static int (*__thiscall p_ios_good)(const ios*);
+static int (*__thiscall p_ios_bad)(const ios*);
+static int (*__thiscall p_ios_eof)(const ios*);
+static int (*__thiscall p_ios_fail)(const ios*);
+static void (*__thiscall p_ios_clear)(ios*, int);
 
 /* Emulate a __thiscall */
 #ifdef __i386__
@@ -255,6 +260,11 @@ static BOOL init(void)
         SET(p_ios_setf, "?setf at ios@@QEAAJJ at Z");
         SET(p_ios_setf_mask, "?setf at ios@@QEAAJJJ at Z");
         SET(p_ios_unsetf, "?unsetf at ios@@QEAAJJ at Z");
+        SET(p_ios_good, "?good at ios@@QEBAHXZ");
+        SET(p_ios_bad, "?bad at ios@@QEBAHXZ");
+        SET(p_ios_eof, "?eof at ios@@QEBAHXZ");
+        SET(p_ios_fail, "?fail at ios@@QEBAHXZ");
+        SET(p_ios_clear, "?clear at ios@@QEAAXH at Z");
     } else {
         p_operator_new = (void*)GetProcAddress(msvcrt, "??2 at YAPAXI@Z");
 
@@ -298,6 +308,11 @@ static BOOL init(void)
         SET(p_ios_setf, "?setf at ios@@QAEJJ at Z");
         SET(p_ios_setf_mask, "?setf at ios@@QAEJJJ at Z");
         SET(p_ios_unsetf, "?unsetf at ios@@QAEJJ at Z");
+        SET(p_ios_good, "?good at ios@@QBEHXZ");
+        SET(p_ios_bad, "?bad at ios@@QBEHXZ");
+        SET(p_ios_eof, "?eof at ios@@QBEHXZ");
+        SET(p_ios_fail, "?fail at ios@@QBEHXZ");
+        SET(p_ios_clear, "?clear at ios@@QAEXH at Z");
     }
     SET(p_ios_static_lock, "?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A");
     SET(p_ios_lockc, "?lockc at ios@@KAXXZ");
@@ -1033,6 +1048,41 @@ static void test_ios(void)
     ok(ios_obj.flags == 0x440, "expected %x got %x\n", 0x440, ios_obj.flags);
     ios_obj.do_lock = -1;
 
+    /* state */
+    ios_obj.state = 0x8;
+    ret = (LONG) call_func1(p_ios_good, &ios_obj);
+    ok(ret == 0, "expected 0 got %d\n", ret);
+    ios_obj.state = IOSTATE_goodbit;
+    ret = (LONG) call_func1(p_ios_good, &ios_obj);
+    ok(ret == 1, "expected 1 got %d\n", ret);
+    ret = (LONG) call_func1(p_ios_bad, &ios_obj);
+    ok(ret == 0, "expected 0 got %d\n", ret);
+    ios_obj.state = (IOSTATE_eofbit|IOSTATE_badbit);
+    ret = (LONG) call_func1(p_ios_bad, &ios_obj);
+    ok(ret == IOSTATE_badbit, "expected 4 got %d\n", ret);
+    ret = (LONG) call_func1(p_ios_eof, &ios_obj);
+    ok(ret == IOSTATE_eofbit, "expected 1 got %d\n", ret);
+    ios_obj.state = 0x8;
+    ret = (LONG) call_func1(p_ios_eof, &ios_obj);
+    ok(ret == 0, "expected 0 got %d\n", ret);
+    ret = (LONG) call_func1(p_ios_fail, &ios_obj);
+    ok(ret == 0, "expected 0 got %d\n", ret);
+    ios_obj.state = IOSTATE_badbit;
+    ret = (LONG) call_func1(p_ios_fail, &ios_obj);
+    ok(ret == IOSTATE_badbit, "expected 4 got %d\n", ret);
+    ios_obj.state = (IOSTATE_eofbit|IOSTATE_failbit);
+    ret = (LONG) call_func1(p_ios_fail, &ios_obj);
+    ok(ret == IOSTATE_failbit, "expected 2 got %d\n", ret);
+    ios_obj.state = (IOSTATE_eofbit|IOSTATE_failbit|IOSTATE_badbit);
+    ret = (LONG) call_func1(p_ios_fail, &ios_obj);
+    ok(ret == (IOSTATE_failbit|IOSTATE_badbit), "expected 6 got %d\n", ret);
+    ios_obj.do_lock = 0;
+    call_func2(p_ios_clear, &ios_obj, 0);
+    ok(ios_obj.state == IOSTATE_goodbit, "expected 0 got %d\n", ios_obj.state);
+    call_func2(p_ios_clear, &ios_obj, 0x8|IOSTATE_eofbit);
+    ok(ios_obj.state == (0x8|IOSTATE_eofbit), "expected 9 got %d\n", ios_obj.state);
+    ios_obj.do_lock = -1;
+
     SetEvent(lock_arg.release[0]);
     SetEvent(lock_arg.release[1]);
     SetEvent(lock_arg.release[2]);
-- 
2.1.4




More information about the wine-patches mailing list