msscript.ocx: Implement ScriptProcedureCollection::get_Count.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Gabriel Ivăncescu 2020-08-12 17:13:38 +03:00 committed by Alexandre Julliard
parent 697a44a795
commit c8e4ceb461
2 changed files with 66 additions and 21 deletions

View file

@ -83,6 +83,7 @@ typedef struct {
BSTR name;
ScriptHost *host;
IDispatch *script_dispatch;
ITypeInfo *script_typeinfo;
ScriptProcedureCollection *procedures;
} ScriptModule;
@ -91,6 +92,7 @@ struct ScriptProcedureCollection {
IScriptProcedureCollection IScriptProcedureCollection_iface;
LONG ref;
LONG count;
ScriptModule *module;
};
@ -258,6 +260,23 @@ static HRESULT get_script_dispatch(ScriptModule *module, IDispatch **disp)
return S_OK;
}
static HRESULT get_script_typeinfo(ScriptModule *module, ITypeInfo **typeinfo)
{
IDispatch *disp;
HRESULT hr;
if (!module->script_typeinfo)
{
hr = get_script_dispatch(module, &disp);
if (FAILED(hr)) return hr;
hr = IDispatch_GetTypeInfo(disp, 0, LOCALE_USER_DEFAULT, &module->script_typeinfo);
if (FAILED(hr)) return hr;
}
*typeinfo = module->script_typeinfo;
return S_OK;
}
static HRESULT set_script_state(ScriptHost *host, SCRIPTSTATE state)
{
HRESULT hr;
@ -820,10 +839,32 @@ static HRESULT WINAPI ScriptProcedureCollection_get_Item(IScriptProcedureCollect
static HRESULT WINAPI ScriptProcedureCollection_get_Count(IScriptProcedureCollection *iface, LONG *plCount)
{
ScriptProcedureCollection *This = impl_from_IScriptProcedureCollection(iface);
TYPEATTR *attr;
ITypeInfo *ti;
HRESULT hr;
FIXME("(%p)->(%p)\n", This, plCount);
TRACE("(%p)->(%p)\n", This, plCount);
return E_NOTIMPL;
if (!plCount) return E_POINTER;
if (!This->module->host) return E_FAIL;
hr = start_script(This->module->host);
if (FAILED(hr)) return hr;
if (This->count == -1)
{
hr = get_script_typeinfo(This->module, &ti);
if (FAILED(hr)) return hr;
hr = ITypeInfo_GetTypeAttr(ti, &attr);
if (FAILED(hr)) return hr;
This->count = attr->cFuncs;
ITypeInfo_ReleaseTypeAttr(ti, attr);
}
*plCount = This->count;
return S_OK;
}
static const IScriptProcedureCollectionVtbl ScriptProcedureCollectionVtbl = {
@ -910,6 +951,8 @@ static ULONG WINAPI ScriptModule_Release(IScriptModule *iface)
SysFreeString(This->name);
if (This->script_dispatch)
IDispatch_Release(This->script_dispatch);
if (This->script_typeinfo)
ITypeInfo_Release(This->script_typeinfo);
heap_free(This);
}
@ -1029,6 +1072,7 @@ static HRESULT WINAPI ScriptModule_get_Procedures(IScriptModule *iface, IScriptP
procs->IScriptProcedureCollection_iface.lpVtbl = &ScriptProcedureCollectionVtbl;
procs->ref = 1;
procs->count = -1;
procs->module = This;
This->procedures = procs;
IScriptModule_AddRef(&This->IScriptModule_iface);

View file

@ -3317,9 +3317,10 @@ static void test_IScriptControl_get_Procedures(void)
ok(hr == S_OK, "IScriptControl_get_Procedures failed: 0x%08x.\n", hr);
hr = IScriptProcedureCollection_get_Count(procs, NULL);
todo_wine ok(hr == E_POINTER, "IScriptProcedureCollection_get_Count returned: 0x%08x.\n", hr);
ok(hr == E_POINTER, "IScriptProcedureCollection_get_Count returned: 0x%08x.\n", hr);
hr = IScriptProcedureCollection_get_Count(procs, &count);
todo_wine ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
ok(count == 0, "count is not 0, got %d.\n", count);
V_VT(&var) = VT_I4;
V_I4(&var) = -1;
@ -3339,7 +3340,8 @@ static void test_IScriptControl_get_Procedures(void)
SysFreeString(str);
hr = IScriptProcedureCollection_get_Count(procs, &count);
todo_wine ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
todo_wine ok(count == 3, "count is not 3, got %d.\n", count);
V_VT(&var) = VT_I4;
V_I4(&var) = 1;
@ -3407,17 +3409,18 @@ static void test_IScriptControl_get_Procedures(void)
SET_EXPECT(ReleaseTypeAttr);
TypeInfo_GetTypeAttr_cFuncs = 1337;
hr = IScriptProcedureCollection_get_Count(procs, &count);
todo_wine ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
todo_wine CHECK_CALLED(SetScriptState_STARTED);
todo_wine CHECK_CALLED(GetScriptDispatch);
todo_wine CHECK_CALLED(GetTypeInfo);
todo_wine CHECK_CALLED(GetTypeAttr);
todo_wine CHECK_CALLED(ReleaseTypeAttr);
ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
ok(count == 1337, "count is not 1337, got %d.\n", count);
CHECK_CALLED(SetScriptState_STARTED);
CHECK_CALLED(GetScriptDispatch);
CHECK_CALLED(GetTypeInfo);
CHECK_CALLED(GetTypeAttr);
CHECK_CALLED(ReleaseTypeAttr);
TypeInfo_GetTypeAttr_cFuncs = ARRAY_SIZE(custom_engine_funcs);
count = 0;
hr = IScriptProcedureCollection_get_Count(procs, &count);
todo_wine ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
todo_wine ok(count == 1337, "count is not 1337, got %d.\n", count);
ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
ok(count == 1337, "count is not 1337, got %d.\n", count);
/* Reload the collection to update the cached function count */
IScriptProcedureCollection_Release(procs);
@ -3427,13 +3430,12 @@ static void test_IScriptControl_get_Procedures(void)
SET_EXPECT(GetTypeAttr);
SET_EXPECT(ReleaseTypeAttr);
hr = IScriptProcedureCollection_get_Count(procs, &count);
todo_wine ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
todo_wine ok(count == ARRAY_SIZE(custom_engine_funcs), "count is not %u, got %d.\n", TypeInfo_GetTypeAttr_cFuncs, count);
todo_wine CHECK_CALLED(GetTypeAttr);
todo_wine CHECK_CALLED(ReleaseTypeAttr);
ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
ok(count == ARRAY_SIZE(custom_engine_funcs), "count is not %u, got %d.\n", TypeInfo_GetTypeAttr_cFuncs, count);
CHECK_CALLED(GetTypeAttr);
CHECK_CALLED(ReleaseTypeAttr);
/* Adding code reloads the typeinfo the next time */
SET_EXPECT(SetScriptState_STARTED);
SET_EXPECT(ParseScriptText);
parse_item_name = NULL;
parse_flags = SCRIPTTEXT_ISVISIBLE;
@ -3442,7 +3444,6 @@ static void test_IScriptControl_get_Procedures(void)
ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
SysFreeString(str);
todo_wine CHECK_ERROR(sc, 0);
todo_wine CHECK_NOT_CALLED(SetScriptState_STARTED);
CHECK_CALLED(ParseScriptText);
GetScriptDispatch_expected_name = NULL;
@ -3451,8 +3452,8 @@ static void test_IScriptControl_get_Procedures(void)
SET_EXPECT(GetTypeAttr);
SET_EXPECT(ReleaseTypeAttr);
hr = IScriptProcedureCollection_get_Count(procs, &count);
todo_wine ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
todo_wine ok(count == ARRAY_SIZE(custom_engine_funcs), "count is not %u, got %d.\n", TypeInfo_GetTypeAttr_cFuncs, count);
ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
ok(count == ARRAY_SIZE(custom_engine_funcs), "count is not %u, got %d.\n", TypeInfo_GetTypeAttr_cFuncs, count);
todo_wine CHECK_CALLED(GetScriptDispatch);
todo_wine CHECK_CALLED(GetTypeInfo);
todo_wine CHECK_CALLED(GetTypeAttr);