From 0aa2a29a3103ae5a7cbdb7c8ac50f1551f7db69c Mon Sep 17 00:00:00 2001 From: Shuai Meng Date: Tue, 29 Apr 2014 11:09:49 +0800 Subject: [PATCH] vbscript: Fixed CBool To: wine-patches Reply-To: wine-devel Cc: Shuai Meng --- dlls/vbscript/global.c | 33 ++++----------------------------- dlls/vbscript/tests/api.vbs | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 9983509..8eab9e6 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -114,16 +114,6 @@ static HRESULT return_int(VARIANT *res, int val) return S_OK; } -static HRESULT return_bool(VARIANT *res, int val) -{ - if(res) { - V_VT(res) = VT_BOOL; - V_BOOL(res) = val != 0 ? VARIANT_TRUE : VARIANT_FALSE; - } - - return S_OK; -} - static inline HRESULT return_double(VARIANT *res, double val) { if(res) { @@ -413,30 +403,15 @@ static HRESULT Global_CLng(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARI static HRESULT Global_CBool(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) { - int val; TRACE("%s\n", debugstr_variant(arg)); assert(args_cnt == 1); - switch(V_VT(arg)) { - case VT_I2: - val = V_I2(arg); - break; - case VT_I4: - val = V_I4(arg); - break; - case VT_R4: - val = V_R4(arg) > 0.0 || V_R4(arg) < 0.0; - break; - case VT_R8: - val = V_R8(arg) > 0.0 || V_R8(arg) < 0.0; - break; - default: - ERR("Not a numeric value: %s\n", debugstr_variant(arg)); - return E_FAIL; - } + if(!res) + return S_OK; - return return_bool(res, val); + V_VT(res) = VT_EMPTY; + return VariantChangeType(res, arg, 0, VT_BOOL); } static HRESULT Global_CByte(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index 3c496b1..ea698b0 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -464,4 +464,28 @@ Call ok(getVT(CBool(0)) = "VT_BOOL", "getVT(CBool(0)) = " & getVT(CBool(0))) Call ok(CBool(-5) = true, "CBool(-5) = " & CBool(-5)) Call ok(getVT(CBool(-5)) = "VT_BOOL", "getVT(CBool(-5)) = " & getVT(CBool(-5))) +Class ValClass + Public myval + + Public default Property Get defprop + defprop = myval + End Property +End Class + +Dim MyObject +Set MyObject = New ValClass + +Call ok(CBool(Empty) = False, "CBool(Empty) = " & CBool(Empty)) +Call ok(getVT(CBool(Empty)) = "VT_BOOL", "getVT(CBool(Empty)) = " & getVT(CBool(Empty))) +Call ok(CBool(1) = True, "CBool(1) = " & CBool(1)) +Call ok(getVT(CBool(1)) = "VT_BOOL", "getVT(CBool(1)) = " & getVT(CBool(1))) +Call ok(CBool(0) = False, "CBool(0) = " & CBool(0)) +Call ok(getVT(CBool(0)) = "VT_BOOL", "getVT(CBool(0)) = " & getVT(CBool(0))) +Call ok(CBool(-0.56) = True, "CBool(-0.56) = " & CBool(-0.56)) +Call ok(getVT(CBool(-0.56)) = "VT_BOOL", "getVT(CBool(-0.56)) = " & getVT(CBool(-0.56))) +Call ok(CBool("-1") = True, "CBool(""-1"") = " & CBool("-1")) +Call ok(getVT(CBool("-1")) = "VT_BOOL", "getVT(CBool(""-1"")) = " & getVT(CBool("-1"))) +Call ok(CBool(MyObject) = False, "CBool(MyObject) = " & CBool(MyObject)) +Call ok(getVT(CBool(MyObject)) = "VT_BOOL", "getVT(CBool(MyObject)) = " & getVT(CBool(MyObject))) + Call reportSuccess() -- 1.8.1.2