From: Shuai Meng Subject: [PATCH] vbscript: Implemented IsNumeric(try 2) Message-Id: <53CD34A2.2080807@gmail.com> Date: Mon, 21 Jul 2014 23:41:22 +0800 Thanks Piotr Jacek and Dmitry~ Change log: used to_double instead of switch(arg); added return_bool for simplification. testbot: https://testbot.winehq.org/JobDetails.pl?Key=8045 --- dlls/vbscript/global.c | 21 +++++++++++++++++++-- dlls/vbscript/tests/api.vbs | 26 +++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index af7a27d..e41a7dd 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -91,6 +91,15 @@ static HRESULT return_bstr(VARIANT *res, BSTR str) return S_OK; } +static HRESULT return_bool(VARIANT *res, BOOL val) +{ + if(res) { + V_VT(res) = VT_BOOL; + V_BOOL(res) = val ? VARIANT_TRUE : VARIANT_FALSE; + } + return S_OK; +} + static HRESULT return_short(VARIANT *res, short val) { if(res) { @@ -628,8 +637,16 @@ static HRESULT Global_IsNull(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VA static HRESULT Global_IsNumeric(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) { - FIXME("\n"); - return E_NOTIMPL; + HRESULT hres; + double d; + + TRACE("(%s)\n", debugstr_variant(arg)); + + assert(args_cnt == 1); + + hres = to_double(arg, &d); + + return return_bool(res, SUCCEEDED(hres)); } static HRESULT Global_IsArray(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 813f5e8..2ace288 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -1,4 +1,3 @@ -' ' Copyright 2011 Jacek Caban for CodeWeavers ' ' This library is free software; you can redistribute it and/or @@ -194,6 +193,31 @@ Call ok(not isNull(4), "isNull(4) is true?") Call ok(not isNull("x"), "isNull(""x"") is true?") Call ok(isNull(Null), "isNull(Null) is not true?") +Call ok(isNumeric(Empty), "isNumeric(empty) is not true?") +Call ok(not isNumeric(Null), "isNumeric(Null) is not true?") +Call ok(isNumeric(32767), "isNumeric(32767) is true?") +Call ok(isNumeric(32768), "isNumeric(32768) is true?") +Call ok(isNumeric(CSng(3242.4)), "isNumeric(CSng(3242.4)) is true?") +Call ok(isNumeric(32768.4), "isNumeric(32768.4) is true?") +Call ok(isNumeric(CCur(32768.4)), "isNumeric(CCur(32768.4)) is true?") +Call ok(isNumeric("44"), "isNumeric(""44"") is true?") +Call ok(not isNumeric("rwrf"), "isNumeric(""rwrf"") is not true?") +Call ok(not isNumeric(Nothing), "isNumeric(Nothing) is not true?") +Call ok(not isNumeric(New EmptyClass), "isNumeric(New EmptyClass) is not true?") +Call ok(isNumeric(true), "isNumeric(true) is true?") +Call ok(isNumeric(CByte(32)), "isNumeric(CByte(32)) is true?") +Dim arr(2) +arr(0) = 2 +arr(1) = 3 +Call ok(not isNumeric(arr), "isNumeric(arr) is not true?") + +Dim newObject +Set newObject = New ValClass +newObject.myval = 1 +Call ok(isNumeric(newObject), "isNumeric(newObject) is true?") +newObject.myval = "test" +Call ok(not isNumeric(newObject), "isNumeric(newObject) is not true?") + Call ok(getVT(err) = "VT_DISPATCH", "getVT(err) = " & getVT(err)) Sub TestHex(x, ex)