Commit 15dfae71 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

vbscript: Use VariantChangeType in to_int.

parent 0eed829f
......@@ -142,41 +142,15 @@ static inline HRESULT return_date(VARIANT *res, double date)
HRESULT to_int(VARIANT *v, int *ret)
{
if(V_VT(v) == (VT_BYREF|VT_VARIANT))
v = V_VARIANTREF(v);
switch(V_VT(v)) {
case VT_I2:
*ret = V_I2(v);
break;
case VT_I4:
*ret = V_I4(v);
break;
case VT_R8: {
double n = floor(V_R8(v)+0.5);
INT32 i;
if(!is_int32(n)) {
FIXME("%lf is out of int range\n", n);
return E_FAIL;
}
/* Round half to even */
i = n;
if(i%2 && n-V_R8(v) == 0.5)
i--;
VARIANT r;
HRESULT hres;
*ret = i;
break;
}
case VT_BOOL:
*ret = V_BOOL(v) ? -1 : 0;
break;
default:
FIXME("not supported %s\n", debugstr_variant(v));
return E_NOTIMPL;
}
V_VT(&r) = VT_EMPTY;
hres = VariantChangeType(&r, v, 0, VT_I4);
if(FAILED(hres))
return hres;
*ret = V_I4(&r);
return S_OK;
}
......@@ -400,24 +374,22 @@ static HRESULT Global_CInt(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARI
static HRESULT Global_CLng(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
{
VARIANT v;
int i;
HRESULT hres;
TRACE("%s\n", debugstr_variant(arg));
assert(args_cnt == 1);
V_VT(&v) = VT_EMPTY;
hres = VariantChangeType(&v, arg, 0, VT_I4);
hres = to_int(arg, &i);
if(FAILED(hres))
return hres;
if(!res)
return DISP_E_BADVARTYPE;
else {
*res = v;
V_VT(res) = VT_I4;
V_I4(res) = i;
return S_OK;
}
}
static HRESULT Global_CBool(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
......
......@@ -136,6 +136,7 @@ Call ok(Chr(120) = "x", "Chr(120) = " & Chr(120))
Call ok(Chr(0) <> "", "Chr(0) = """"")
Call ok(Chr(120.5) = "x", "Chr(120.5) = " & Chr(120.5))
Call ok(Chr(119.5) = "x", "Chr(119.5) = " & Chr(119.5))
Call ok(Chr("120") = "x", "Chr(""120"") = " & Chr("120"))
sub testChrError
on error resume next
......@@ -321,6 +322,7 @@ Call ok(Space(5.5) = " ", "Space(5.5) = " & Space(5.5) & """")
Call ok(Space(4.5) = " ", "Space(4.5) = " & Space(4.5) & """")
Call ok(Space(0.5) = "", "Space(0.5) = " & Space(0.5) & """")
Call ok(Space(1.5) = " ", "Space(1.5) = " & Space(1.5) & """")
Call ok(Space("1") = " ", "Space(""1"") = " & Space("1") & """")
Sub TestStrReverse(str, ex)
Call ok(StrReverse(str) = ex, "StrReverse(" & str & ") = " & StrReverse(str))
......@@ -341,6 +343,7 @@ TestLeft "test", 0, ""
TestLeft 123, 2, "12"
TestLeft "123456", 1.5, "12"
TestLeft "123456", 2.5, "12"
TestLeft "test", "2", "te"
if isEnglishLang then TestLeft true, 2, "Tr"
Sub TestRight(str, len, ex)
......
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