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

vbscript: Implemented CSng.

parent 05f65a93
......@@ -514,8 +514,23 @@ static HRESULT Global_CDbl(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARI
static HRESULT Global_CSng(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
{
FIXME("\n");
return E_NOTIMPL;
VARIANT v;
HRESULT hres;
TRACE("%s\n", debugstr_variant(arg));
assert(args_cnt == 1);
V_VT(&v) = VT_EMPTY;
hres = VariantChangeType(&v, arg, 0, VT_R4);
if(FAILED(hres))
return hres;
if(!res)
return DISP_E_BADVARTYPE;
*res = v;
return S_OK;
}
static HRESULT Global_CStr(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
......
......@@ -797,4 +797,52 @@ MyObject.myval = 1.5
Call ok(CInt(MyObject) = 2, "CInt(MyObject) = " & CInt(MyObject))
Call ok(getVT(CInt(MyObject)) = "VT_I2", "getVT(CInt(MyObject)) = " & getVT(CInt(MyObject)))
Sub testCSngError(strings, error_num1, error_num2)
on error resume next
Dim x
Call Err.clear()
x = CSng(strings)
Call ok(Err.number = error_num1, "Err.number = " & Err.number)
Call Err.clear()
Call CSng(strings)
Call ok(Err.number = error_num2, "Err.number = " & Err.number)
End Sub
Call ok(CSng(Empty) = 0, "CSng(Empty) = " & CSng(Empty))
Call ok(getVT(CSng(Empty)) = "VT_R4", "getVT(CSng(Empty)) = " & getVT(CSng(Empty)))
Call ok(CSng(CByte(0)) = 0, "CSng(CByte(0)) = " & CSng(CByte(0)))
Call ok(getVT(CSng(CCur(0))) = "VT_R4", "getVT(CSng(CCur(0))) = " & getVT(CSng(CCur(0))))
Call ok(CSng(CCur(0)) = 0, "CSng(CCur(0)) = " & CSng(CCur(0)))
Call ok(getVT(CSng(CCur(0))) = "VT_R4", "getVT(CSng(CCur(0))) = " & getVT(CSng(CCur(0))))
Call ok(CSng(0) = 0, "CSng(0) = " & CSng(0))
Call ok(getVT(CSng(0)) = "VT_R4", "getVT(CSng(0)) = " & getVT(CSng(0)))
Call ok(CSng(32768) = 32768, "CSng(32768) = " & CSng(32768))
Call ok(getVT(CSng(32768)) = "VT_R4", "getVT(CSng(32768)) = " & getVT(CSng(32768)))
Call ok(CSng(0.001 * 0.001) = 0.000001, "CSng(0.001 * 0.001) = " & CSng(0.001 * 0.001))
Call ok(getVT(CSng(0.001 * 0.001)) = "VT_R4", "getVT(CSng(0.001 * 0.001)) = " & getVT(CSng(0.001 * 0.001)))
Call ok(CSng("-1") = -1, "CSng(""-1"") = " & CSng("-1"))
Call ok(getVT(CSng("-1")) = "VT_R4", "getVT(CSng(""-1"")) = " & getVT(CSng("-1")))
If isEnglishLang Then
Call ok(CSng("-0.5") = -0.5, "CSng(""-0.5"") = " & CSng("-0.5"))
Call ok(getVT(CSng("-0.5")) = "VT_R4", "getVT(CSng(""-0.5"")) = " & getVT(CSng("-0.5")))
End If
Call testCSngError("", 13, 13)
Call testCSngError("TRUE", 13, 13)
Call testCSngError("FALSE", 13, 13)
Call testCSngError("#TRue#", 13, 13)
Call testCSngError("#fAlSE#", 13, 13)
Call testCSngError(1, 0, 458)
Call ok(CSng(True) = -1, "CSng(True) = " & CSng(True))
Call ok(getVT(CSng(True)) = "VT_R4", "getVT(CSng(True)) = " & getVT(CSng(True)))
Call ok(CSng(False) = 0, "CSng(False) = " & CSng(False))
Call ok(getVT(CSng(False)) = "VT_R4", "getVT(CSng(False)) = " & getVT(CSng(False)))
MyObject.myval = 0.1
Call ok(CSng(MyObject) = 0.1, "CSng(MyObject) = " & CSng(MyObject))
Call ok(getVT(CSng(MyObject)) = "VT_R4", "getVT(CSng(MyObject)) = " & getVT(CSng(MyObject)))
MyObject.myval = 0
Call ok(CSng(MyObject) = 0, "CSng(MyObject) = " & CSng(MyObject))
Call ok(getVT(CSng(MyObject)) = "VT_R4", "getVT(CSng(MyObject)) = " & getVT(CSng(MyObject)))
Call reportSuccess()
......@@ -167,6 +167,8 @@ static const char *vt2a(VARIANT *v)
return "VT_I2";
case VT_I4:
return "VT_I4";
case VT_R4:
return "VT_R4";
case VT_R8:
return "VT_R8";
case VT_CY:
......
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