From 14f68a988bda797917f778a748ee8920531b734a Mon Sep 17 00:00:00 2001 From: Shuai Meng Date: Tue, 20 May 2014 09:05:07 +0800 Subject: [PATCH] vbscript: Implemented CCur. --- dlls/vbscript/global.c | 21 +++++++++++++++-- dlls/vbscript/tests/api.vbs | 47 +++++++++++++++++++++++++++++++++++++ dlls/vbscript/tests/run.c | 2 ++ 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 7c446611af7..f8c875d24f4 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -375,8 +375,25 @@ static HRESULT show_msgbox(script_ctx_t *ctx, BSTR prompt, VARIANT *res) static HRESULT Global_CCur(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_CY); + if(FAILED(hres)) + return hres; + + if(!res) { + VariantClear(&v); + return DISP_E_BADVARTYPE; + } + + *res = v; + return S_OK; } static HRESULT Global_CInt(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 d7af8e99df4..46c80d457e1 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -587,4 +587,51 @@ MyObject.myval = 0 Call ok(CByte(MyObject) = 0, "CByte(MyObject) = " & CByte(MyObject)) Call ok(getVT(CByte(MyObject)) = "VT_UI1", "getVT(CByte(MyObject)) = " & getVT(CByte(MyObject))) +Sub testCCurError(strings, error_num1, error_num2) + on error resume next + Dim x + + Call Err.clear() + x = CCur(strings) + Call ok(Err.number = error_num1, "Err.number = " & Err.number) + + Call Err.clear() + Call CCur(strings) + Call ok(Err.number = error_num2, "Err.number = " & Err.number) +End Sub + +Call ok(CCur(Empty) = 0, "CCur(Empty) = " & CCur(Empty)) +Call ok(getVT(CCur(Empty)) = "VT_CY", "getVT(CCur(Empty)) = " & getVT(CCur(Empty))) +Call ok(CCur(-32768) = -32768, "CCur(-32768) = " & CCur(-32768)) +Call ok(getVT(CCur(-32768)) = "VT_CY", "getVT(CCur(-32768)) = " & getVT(CCur(-32768))) +Call ok(CCur(32768) = 32768, "CCur(32768) = " & CCur(32768)) +Call ok(getVT(CCur(32768)) = "VT_CY", "getVT(CCur(32768)) = " & getVT(CCur(32768))) +Call ok(CCur(0.000149) = 0.0001, "CCur(0.000149) = " & CCur(0.000149)) +Call ok(getVT(CCur(0.000149)) = "VT_CY", "getVT(CCur(0.000149)) = " & getVT(CCur(0.000149))) +Call ok(CCur(2147483647.99) = 2147483647.99, "CCur(2147483647.99) = " & CCur(2147483647.99)) +Call ok(getVT(CCur(2147483647.99)) = "VT_CY", "getVT(CCur(2147483647.99)) = " & getVT(CCur(2147483647.99))) +Call ok(CCur("-1") = -1, "CCur(""-1"") = " & CCur("-1")) +Call ok(getVT(CCur("-1")) = "VT_CY", "getVT(CCur(""-1"")) = " & getVT(CCur("-1"))) +If isEnglishLang Then + Call ok(CCur("-0.5") = -0.5, "CCur(""-0.5"") = " & CCur("-0.5")) + Call ok(getVT(CCur("-0.5")) = "VT_CY", "getVT(CCur(""-0.5"")) = " & getVT(CCur("-0.5"))) +End If +Call testCCurError("", 13, 13) +Call testCCurError("-1", 0, 458) +Call testCCurError("TRUE", 13, 13) +Call testCCurError("FALSE", 13, 13) +Call testCCurError("#TRue#", 13, 13) +Call testCCurError("#fAlSE#", 13, 13) +Call testCCurError(1, 0, 458) +Call ok(CCur(True) = -1, "CCur(True) = " & CCur(True)) +Call ok(getVT(CCur(True)) = "VT_CY", "getVT(CCur(True)) = " & getVT(CCur(True))) +Call ok(CCur(False) = 0, "CCur(False) = " & CCur(False)) +Call ok(getVT(CCur(False)) = "VT_CY", "getVT(CCur(False)) = " & getVT(CCur(False))) +MyObject.myval = 0.1 +Call ok(CCur(MyObject) = 0.1, "CCur(MyObject) = " & CCur(MyObject)) +Call ok(getVT(CCur(MyObject)) = "VT_CY", "getVT(CCur(MyObject)) = " & getVT(CCur(MyObject))) +MyObject.myval = 0 +Call ok(CCur(MyObject) = 0, "CCur(MyObject) = " & CCur(MyObject)) +Call ok(getVT(CCur(MyObject)) = "VT_CY", "getVT(CCur(MyObject)) = " & getVT(CCur(MyObject))) + Call reportSuccess() diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c index 96203980f10..0188c12c757 100644 --- a/dlls/vbscript/tests/run.c +++ b/dlls/vbscript/tests/run.c @@ -169,6 +169,8 @@ static const char *vt2a(VARIANT *v) return "VT_I4"; case VT_R8: return "VT_R8"; + case VT_CY: + return "VT_CY"; case VT_DATE: return "VT_DATE"; case VT_BSTR: