Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/vbscript/tests/vbscript.c | 84 ++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 5 deletions(-)
diff --git a/dlls/vbscript/tests/vbscript.c b/dlls/vbscript/tests/vbscript.c index 8653463..7545ca3 100644 --- a/dlls/vbscript/tests/vbscript.c +++ b/dlls/vbscript/tests/vbscript.c @@ -101,6 +101,7 @@ DEFINE_EXPECT(GetItemInfo_global); DEFINE_EXPECT(GetItemInfo_global_code); DEFINE_EXPECT(GetItemInfo_visible); DEFINE_EXPECT(GetItemInfo_visible_code); +DEFINE_EXPECT(GetItemInfo_persistent); DEFINE_EXPECT(testCall);
DEFINE_GUID(CLSID_VBScript, 0xb54f3741, 0x5b07, 0x11cf, 0xa4,0xb0, 0x00,0xaa,0x00,0x4a,0x55,0xe8); @@ -151,7 +152,7 @@ static ULONG WINAPI Dispatch_Release(IDispatch *iface) return 1; }
-static ULONG global_named_item_ref, visible_named_item_ref, visible_code_named_item_ref; +static ULONG global_named_item_ref, visible_named_item_ref, visible_code_named_item_ref, persistent_named_item_ref;
static ULONG WINAPI global_AddRef(IDispatch *iface) { @@ -183,6 +184,16 @@ static ULONG WINAPI visible_code_Release(IDispatch *iface) return --visible_code_named_item_ref; }
+static ULONG WINAPI persistent_AddRef(IDispatch *iface) +{ + return ++persistent_named_item_ref; +} + +static ULONG WINAPI persistent_Release(IDispatch *iface) +{ + return --persistent_named_item_ref; +} + static HRESULT WINAPI Dispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo) { ok(0, "unexpected call\n"); @@ -266,6 +277,18 @@ static const IDispatchVtbl visible_code_named_item_vtbl = {
static IDispatch visible_code_named_item = { &visible_code_named_item_vtbl };
+static const IDispatchVtbl persistent_named_item_vtbl = { + Dispatch_QueryInterface, + persistent_AddRef, + persistent_Release, + Dispatch_GetTypeInfoCount, + Dispatch_GetTypeInfo, + Dispatch_GetIDsOfNames, + Dispatch_Invoke +}; + +static IDispatch persistent_named_item = { &persistent_named_item_vtbl }; + static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv) { *ppv = NULL; @@ -325,6 +348,12 @@ static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPC *item_unk = (IUnknown*)&visible_code_named_item; return S_OK; } + if(!wcscmp(name, L"persistent")) { + CHECK_EXPECT(GetItemInfo_persistent); + IDispatch_AddRef(&persistent_named_item); + *item_unk = (IUnknown*)&persistent_named_item; + return S_OK; + } ok(0, "unexpected call %s\n", wine_dbgstr_w(name)); return E_NOTIMPL; } @@ -1818,6 +1847,8 @@ static void test_named_items(void) ok(hres == E_UNEXPECTED, "AddNamedItem returned: %08x\n", hres); hres = IActiveScript_AddNamedItem(script, L"codeOnlyItem", SCRIPTITEM_CODEONLY); ok(hres == E_UNEXPECTED, "AddNamedItem returned: %08x\n", hres); + hres = IActiveScript_AddNamedItem(script, L"persistent", SCRIPTITEM_ISPERSISTENT | SCRIPTITEM_CODEONLY); + ok(hres == E_UNEXPECTED, "AddNamedItem returned: %08x\n", hres);
SET_EXPECT(GetLCID); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); @@ -1835,10 +1866,13 @@ static void test_named_items(void) ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); hres = IActiveScript_AddNamedItem(script, L"codeOnlyItem", SCRIPTITEM_CODEONLY); ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); + hres = IActiveScript_AddNamedItem(script, L"persistent", SCRIPTITEM_ISPERSISTENT | SCRIPTITEM_CODEONLY); + ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
ok(global_named_item_ref > 0, "global_named_item_ref = %u\n", global_named_item_ref); ok(visible_named_item_ref == 0, "visible_named_item_ref = %u\n", visible_named_item_ref); ok(visible_code_named_item_ref == 0, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref); + ok(persistent_named_item_ref == 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
hres = IActiveScript_GetScriptDispatch(script, L"noContext", &disp); ok(hres == E_INVALIDARG, "GetScriptDispatch returned: %08x\n", hres); @@ -1920,6 +1954,7 @@ static void test_named_items(void) ok(global_named_item_ref > 0, "global_named_item_ref = %u\n", global_named_item_ref); ok(visible_named_item_ref == 1, "visible_named_item_ref = %u\n", visible_named_item_ref); ok(visible_code_named_item_ref == 1, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref); + ok(persistent_named_item_ref == 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
SET_EXPECT(testCall); parse_script(parse, "visibleItem.testCall\n"); @@ -2087,6 +2122,28 @@ static void test_named_items(void) IDispatchEx_Release(script_disp2); IDispatchEx_Release(script_disp);
+ SET_EXPECT(OnEnterScript); + SET_EXPECT(OnLeaveScript); + hres = IActiveScriptParse_ParseScriptText(parse, L"x = 13\n", L"persistent", NULL, NULL, 0, 0, SCRIPTTEXT_ISPERSISTENT, NULL, NULL); + ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); + CHECK_CALLED(OnEnterScript); + CHECK_CALLED(OnLeaveScript); + SET_EXPECT(OnEnterScript); + SET_EXPECT(OnLeaveScript); + hres = IActiveScriptParse_ParseScriptText(parse, L"x = 10\n", L"persistent", NULL, NULL, 0, 0, 0, NULL, NULL); + ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); + CHECK_CALLED(OnEnterScript); + CHECK_CALLED(OnLeaveScript); + SET_EXPECT(OnEnterScript); + SET_EXPECT(OnLeaveScript); + hres = IActiveScriptParse_ParseScriptText(parse, L"x", L"persistent", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); + ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); + ok(V_VT(&var) == VT_I2 && V_I2(&var) == 10, "Unexpected 'x': V_VT = %d, V_I2 = %d\n", V_VT(&var), V_I2(&var)); + CHECK_CALLED(OnEnterScript); + CHECK_CALLED(OnLeaveScript); + + script_disp = get_script_dispatch(script, L"persistent"); + SET_EXPECT(OnStateChange_DISCONNECTED); SET_EXPECT(OnStateChange_INITIALIZED); SET_EXPECT(OnStateChange_UNINITIALIZED); @@ -2100,30 +2157,46 @@ static void test_named_items(void) ok(global_named_item_ref == 0, "global_named_item_ref = %u\n", global_named_item_ref); ok(visible_named_item_ref == 0, "visible_named_item_ref = %u\n", visible_named_item_ref); ok(visible_code_named_item_ref == 0, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref); + ok(persistent_named_item_ref == 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
hres = IActiveScript_GetScriptDispatch(script, L"codeOnlyItem", &disp); ok(hres == E_UNEXPECTED, "hres = %08x, expected E_UNEXPECTED\n", hres);
SET_EXPECT(GetLCID); SET_EXPECT(OnStateChange_INITIALIZED); + SET_EXPECT(GetItemInfo_persistent); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); CHECK_CALLED(OnStateChange_INITIALIZED); + CHECK_CALLED(GetItemInfo_persistent); + ok(persistent_named_item_ref > 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
hres = IActiveScript_AddNamedItem(script, L"codeOnlyItem", SCRIPTITEM_CODEONLY); ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
SET_EXPECT(OnStateChange_CONNECTED); - SET_EXPECT_MULTI(OnEnterScript, 4); - SET_EXPECT_MULTI(OnLeaveScript, 4); + SET_EXPECT_MULTI(OnEnterScript, 5); + SET_EXPECT_MULTI(OnLeaveScript, 5); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CONNECTED); - CHECK_CALLED_MULTI(OnEnterScript, 4); - CHECK_CALLED_MULTI(OnLeaveScript, 4); + CHECK_CALLED_MULTI(OnEnterScript, 5); + CHECK_CALLED_MULTI(OnLeaveScript, 5); test_state(script, SCRIPTSTATE_CONNECTED);
+ script_disp2 = get_script_dispatch(script, L"persistent"); + ok(script_disp != script_disp2, "Same script dispatch returned for "persistent" named item\n"); + IDispatchEx_Release(script_disp2); + IDispatchEx_Release(script_disp); + SET_EXPECT(OnEnterScript); + SET_EXPECT(OnLeaveScript); + hres = IActiveScriptParse_ParseScriptText(parse, L"x", L"persistent", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); + ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); + ok(V_VT(&var) == VT_I2 && V_I2(&var) == 13, "Unexpected 'x': V_VT = %d, V_I2 = %d\n", V_VT(&var), V_I2(&var)); + CHECK_CALLED(OnEnterScript); + CHECK_CALLED(OnLeaveScript); + script_disp = get_script_dispatch(script, NULL); for (i = 0; i < ARRAY_SIZE(global_idents); i++) { @@ -2237,6 +2310,7 @@ static void test_named_items(void) ok(global_named_item_ref == 0, "global_named_item_ref = %u\n", global_named_item_ref); ok(visible_named_item_ref == 0, "visible_named_item_ref = %u\n", visible_named_item_ref); ok(visible_code_named_item_ref == 0, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref); + ok(persistent_named_item_ref == 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
test_state(script, SCRIPTSTATE_CLOSED);