From d8135b8243e72a6a1d5db3aac742fe20996baf1c Mon Sep 17 00:00:00 2001 From: Shuai Meng Date: Fri, 13 Jun 2014 22:30:29 +0800 Subject: [PATCH] vbscript: Implemented CSng. --- dlls/vbscript/global.c | 19 ++++++++++++++++-- dlls/vbscript/tests/api.vbs | 48 +++++++++++++++++++++++++++++++++++++++++++++ dlls/vbscript/tests/run.c | 2 ++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 294004b0722..5160374c98f 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -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) diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index 2aad761ffc5..2cf9bb7c7cc 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -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() diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c index 0188c12c757..56361bff611 100644 --- a/dlls/vbscript/tests/run.c +++ b/dlls/vbscript/tests/run.c @@ -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: -- 2.11.4.GIT