Commit b8aecb92 authored by Shuai Meng's avatar Shuai Meng Committed by Alexandre Julliard

vbscript: Fixed CBool handling.

parent 43241934
...@@ -114,16 +114,6 @@ static HRESULT return_int(VARIANT *res, int val) ...@@ -114,16 +114,6 @@ static HRESULT return_int(VARIANT *res, int val)
return S_OK; 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) static inline HRESULT return_double(VARIANT *res, double val)
{ {
if(res) { if(res) {
...@@ -413,30 +403,23 @@ static HRESULT Global_CLng(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARI ...@@ -413,30 +403,23 @@ 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) static HRESULT Global_CBool(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
{ {
int val; VARIANT v;
HRESULT hres;
TRACE("%s\n", debugstr_variant(arg)); TRACE("%s\n", debugstr_variant(arg));
assert(args_cnt == 1); assert(args_cnt == 1);
switch(V_VT(arg)) { V_VT(&v) = VT_EMPTY;
case VT_I2: hres = VariantChangeType(&v, arg, VARIANT_LOCALBOOL, VT_BOOL);
val = V_I2(arg); if(FAILED(hres))
break; return hres;
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;
}
return return_bool(res, val); if(res)
*res = v;
else
VariantClear(&v);
return S_OK;
} }
static HRESULT Global_CByte(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) static HRESULT Global_CByte(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
......
...@@ -478,4 +478,59 @@ Call ok(getVT(CBool(0)) = "VT_BOOL", "getVT(CBool(0)) = " & getVT(CBool(0))) ...@@ -478,4 +478,59 @@ Call ok(getVT(CBool(0)) = "VT_BOOL", "getVT(CBool(0)) = " & getVT(CBool(0)))
Call ok(CBool(-5) = true, "CBool(-5) = " & CBool(-5)) Call ok(CBool(-5) = true, "CBool(-5) = " & CBool(-5))
Call ok(getVT(CBool(-5)) = "VT_BOOL", "getVT(CBool(-5)) = " & getVT(CBool(-5))) Call ok(getVT(CBool(-5)) = "VT_BOOL", "getVT(CBool(-5)) = " & getVT(CBool(-5)))
Sub testCBoolError(strings, error_num)
on error resume next
Call Err.clear()
Call CBool(strings)
Call ok(Err.number = error_num, "Err.number = " & Err.number)
End Sub
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 testCBoolError("", 13)
Call ok(CBool("0") = False, "CBool(""0"") = " & CBool("0"))
Call ok(getVT(CBool("0")) = "VT_BOOL", "getVT(CBool(""0"")) = " & getVT(CBool("0")))
If isEnglishLang Then
Call ok(CBool("0.1") = True, "CBool(""0.1"") = " & CBool("0.1"))
Call ok(getVT(CBool("0.1")) = "VT_BOOL", "getVT(CBool(""0.1"")) = " & getVT(CBool("0.1")))
End If
Call ok(CBool("true") = True, "CBool(""true"") = " & CBool("true"))
Call ok(getVT(CBool("true")) = "VT_BOOL", "getVT(CBool(""true"")) = " & getVT(CBool("true")))
Call ok(CBool("false") = False, "CBool(""false"") = " & CBool("false"))
Call ok(getVT(CBool("false")) = "VT_BOOL", "getVT(CBool(""false"")) = " & getVT(CBool("false")))
Call ok(CBool("TRUE") = True, "CBool(""TRUE"") = " & CBool("TRUE"))
Call ok(getVT(CBool("TRUE")) = "VT_BOOL", "getVT(CBool(""TRUE"")) = " & getVT(CBool("TRUE")))
Call ok(CBool("FALSE") = False, "CBool(""FALSE"") = " & CBool("FALSE"))
Call ok(getVT(CBool("FALSE")) = "VT_BOOL", "getVT(CBool(""FALSE"")) = " & getVT(CBool("FALSE")))
Call ok(CBool("#TRUE#") = True, "CBool(""#TRUE#"") = " & CBool("#TRUE#"))
Call ok(getVT(CBool("#TRUE#")) = "VT_BOOL", "getVT(CBool(""#TRUE#"")) = " & getVT(CBool("#TRUE#")))
Call ok(CBool("#FALSE#") = False, "CBool(""#FALSE#"") = " & CBool("#FALSE#"))
Call ok(getVT(CBool("#FALSE#")) = "VT_BOOL", "getVT(CBool(""#FALSE#"")) = " & getVT(CBool("#FALSE#")))
Call ok(CBool(MyObject) = False, "CBool(MyObject) = " & CBool(MyObject))
Call ok(getVT(CBool(MyObject)) = "VT_BOOL", "getVT(CBool(MyObject)) = " & getVT(CBool(MyObject)))
MyObject.myval = 1
Call ok(CBool(MyObject) = True, "CBool(MyObject) = " & CBool(MyObject))
Call ok(getVT(CBool(MyObject)) = "VT_BOOL", "getVT(CBool(MyObject)) = " & getVT(CBool(MyObject)))
MyObject.myval = 0
Call ok(CBool(MyObject) = False, "CBool(MyObject) = " & CBool(MyObject))
Call ok(getVT(CBool(MyObject)) = "VT_BOOL", "getVT(CBool(MyObject)) = " & getVT(CBool(MyObject)))
Call reportSuccess() Call reportSuccess()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment