Module: wine Branch: master Commit: e95492bc83c65b1d84c4976338be909a3d05bf64 URL: http://source.winehq.org/git/wine.git/?a=commit;h=e95492bc83c65b1d84c4976338...
Author: Piotr Caban piotr@codeweavers.com Date: Mon Nov 6 16:53:08 2017 +0100
vbscript: Add UBound implementation.
Signed-off-by: Piotr Caban piotr@codeweavers.com Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/vbscript/global.c | 38 +++++++++++++++++++++++++++++++++++--- dlls/vbscript/tests/api.vbs | 10 ++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index f523820..a5df54a 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -822,8 +822,40 @@ static HRESULT Global_LBound(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VA
static HRESULT Global_UBound(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) { - FIXME("\n"); - return E_NOTIMPL; + SAFEARRAY *sa; + HRESULT hres; + LONG ubound; + int dim; + + assert(args_cnt == 1 || args_cnt == 2); + + TRACE("%s %s\n", debugstr_variant(arg), args_cnt == 2 ? debugstr_variant(arg + 1) : "1"); + + switch(V_VT(arg)) { + case VT_VARIANT|VT_ARRAY: + sa = V_ARRAY(arg); + break; + case VT_VARIANT|VT_ARRAY|VT_BYREF: + sa = *V_ARRAYREF(arg); + break; + default: + FIXME("arg %s not supported\n", debugstr_variant(arg)); + return E_NOTIMPL; + } + + if(args_cnt == 2) { + hres = to_int(arg + 1, &dim); + if(FAILED(hres)) + return hres; + }else { + dim = 1; + } + + hres = SafeArrayGetUBound(sa, dim, &ubound); + if(FAILED(hres)) + return hres; + + return return_int(res, ubound); }
static HRESULT Global_RGB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) @@ -2256,7 +2288,7 @@ static const builtin_prop_t global_props[] = { {DISPID_GLOBAL_RND, Global_Rnd, 0, 1}, {DISPID_GLOBAL_TIMER, Global_Timer, 0, 0}, {DISPID_GLOBAL_LBOUND, Global_LBound, 0, 1}, - {DISPID_GLOBAL_UBOUND, Global_UBound, 0, 1}, + {DISPID_GLOBAL_UBOUND, Global_UBound, 0, 1, 2}, {DISPID_GLOBAL_RGB, Global_RGB, 0, 3}, {DISPID_GLOBAL_LEN, Global_Len, 0, 1}, {DISPID_GLOBAL_LENB, Global_LenB, 0, 1}, diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index baa0553..8ebbfb6 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -227,6 +227,16 @@ new_array = x x(0) = "new value" Call ok(new_array(0) = "a1", "new_array(0) = " & new_array(0))
+Call ok(getVT(UBound(x)) = "VT_I4", "getVT(UBound(x)) = " & getVT(UBound(x))) +Call ok(UBound(x) = 2, "UBound(x) = " & UBound(x)) +Call ok(getVT(UBound(x, 1)) = "VT_I4", "getVT(UBound(x, 1)) = " & getVT(UBound(x, 1))) +Call ok(UBound(x, 1) = 2, "UBound(x) = " & UBound(x, 1)) + +Dim arr2(2, 4) +Call ok(UBound(arr2) = 2, "UBound(x) = " & UBound(x)) +Call ok(UBound(arr2, 1) = 2, "UBound(x) = " & UBound(x)) +Call ok(UBound(arr2, 2) = 4, "UBound(x) = " & UBound(x)) + Dim newObject Set newObject = New ValClass newObject.myval = 1