static void test_GetObject(void) { IActiveScriptParse *parser; HRESULT hres; /* Never allowed with security manager */ parser = create_script(TRUE); hres = parse_script_ae(parser, "Call GetObject(\"clsid:" TESTOBJINST_CLSID "\").reportSuccess()"); ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres); IActiveScriptParse_Release(parser); parser = create_script(FALSE); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(SetSite); SET_EXPECT(reportSuccess); hres = parse_script_ae(parser, "Call GetObject(\"clsid:" TESTOBJINST_CLSID "\").reportSuccess()"); if(hres == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND)) { /* Workaround for broken win2k */ win_skip("got unexpected error %08x\n", hres); CLEAR_CALLED(QI_IObjectWithSite); CLEAR_CALLED(SetSite); CLEAR_CALLED(reportSuccess); IActiveScriptParse_Release(parser); return; } ok(hres == S_OK, "hres = %08x\n", hres); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(SetSite); CHECK_CALLED(reportSuccess); SetSite_hres = E_FAIL; SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(SetSite); hres = parse_script_ae(parser, "Call GetObject(\"clsid:" TESTOBJINST_CLSID "\").reportSuccess()"); ok(hres == E_FAIL, "hres = %08x\n", hres); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(SetSite); QI_IObjectWithSite_hres = E_NOINTERFACE; SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(reportSuccess); parse_script_a(parser, "Call GetObject(\"clsid:" TESTOBJINST_CLSID "\").reportSuccess()"); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(reportSuccess); IActiveScriptParse_Release(parser); /* Invalid moniker */ parser = create_script(FALSE); hres = parse_script_ae(parser, "Call GetObject(\"nonexistent:test\").reportSuccess()"); ok(hres == MK_E_SYNTAX, "hres = %08x\n", hres); IActiveScriptParse_Release(parser); }
static void test_jscript2(void) { IActiveScriptParse *parse; IActiveScript *script; ULONG ref; HRESULT hres; script = create_jscript(); hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse); ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); test_state(script, SCRIPTSTATE_UNINITIALIZED); SET_EXPECT(GetLCID); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); test_state(script, SCRIPTSTATE_UNINITIALIZED); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScriptParse_InitNew(parse); ok(hres == S_OK, "InitNew failed: %08x\n", hres); CHECK_CALLED(OnStateChange_INITIALIZED); hres = IActiveScriptParse_InitNew(parse); ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres); SET_EXPECT(OnStateChange_CONNECTED); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CONNECTED); test_state(script, SCRIPTSTATE_CONNECTED); SET_EXPECT(OnStateChange_DISCONNECTED); SET_EXPECT(OnStateChange_INITIALIZED); SET_EXPECT(OnStateChange_CLOSED); hres = IActiveScript_Close(script); ok(hres == S_OK, "Close failed: %08x\n", hres); CHECK_CALLED(OnStateChange_DISCONNECTED); CHECK_CALLED(OnStateChange_INITIALIZED); CHECK_CALLED(OnStateChange_CLOSED); test_state(script, SCRIPTSTATE_CLOSED); test_no_script_dispatch(script); IActiveScriptParse_Release(parse); ref = IActiveScript_Release(script); ok(!ref, "ref = %d\n", ref); }
static void test_vbscript_release(void) { IActiveScriptParse *parser; IActiveScript *vbscript; ULONG ref; HRESULT hres; vbscript = create_vbscript(); hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParse, (void**)&parser); ok(hres == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hres); test_state(vbscript, SCRIPTSTATE_UNINITIALIZED); test_safety(vbscript); SET_EXPECT(GetLCID); hres = IActiveScript_SetScriptSite(vbscript, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); test_state(vbscript, SCRIPTSTATE_UNINITIALIZED); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScriptParse_InitNew(parser); ok(hres == S_OK, "InitNew failed: %08x\n", hres); CHECK_CALLED(OnStateChange_INITIALIZED); test_state(vbscript, SCRIPTSTATE_INITIALIZED); SET_EXPECT(OnStateChange_CONNECTED); hres = IActiveScript_SetScriptState(vbscript, SCRIPTSTATE_CONNECTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CONNECTED); test_state(vbscript, SCRIPTSTATE_CONNECTED); IActiveScriptParse_Release(parser); SET_EXPECT(OnStateChange_DISCONNECTED); SET_EXPECT(OnStateChange_INITIALIZED); SET_EXPECT(OnStateChange_CLOSED); ref = IActiveScript_Release(vbscript); ok(!ref, "ref = %d\n", ref); CHECK_CALLED(OnStateChange_DISCONNECTED); CHECK_CALLED(OnStateChange_INITIALIZED); CHECK_CALLED(OnStateChange_CLOSED); }
static BOOL check_jscript(void) { IActiveScriptProperty *script_prop; IActiveScriptParse *parser; BSTR str; HRESULT hres; parser = create_script(TRUE, TRUE); if(!parser) return FALSE; str = a2bstr("if(!('localeCompare' in String.prototype)) throw 1;"); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); SysFreeString(str); if(hres == S_OK) hres = IActiveScriptParse_QueryInterface(parser, &IID_IActiveScriptProperty, (void**)&script_prop); IActiveScriptParse_Release(parser); if(hres == S_OK) IActiveScriptProperty_Release(script_prop); return hres == S_OK; }
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow) { const WCHAR *ext, *filename = NULL; IActiveScriptParse *parser; IActiveScript *script; WCHAR **argv; CLSID clsid; int argc, i; DWORD res; WINE_TRACE("(%p %p %s %x)\n", hInst, hPrevInst, wine_dbgstr_w(cmdline), cmdshow); argv = CommandLineToArgvW(cmdline, &argc); if(!argv) return 1; for(i=0; i<argc; i++) { if(*argv[i] == '/' || *argv[i] == '-') { if(!set_host_properties(argv[i])) return 1; }else { filename = argv[i]; argums = argv+i+1; numOfArgs = argc-i-1; break; } } if(!filename) { WINE_FIXME("No file name specified\n"); return 1; } res = GetFullPathNameW(filename, sizeof(scriptFullName)/sizeof(WCHAR), scriptFullName, NULL); if(!res || res > sizeof(scriptFullName)/sizeof(WCHAR)) return 1; ext = strchrW(filename, '.'); if(!ext) ext = filename; if(!get_engine_clsid(ext, &clsid)) { WINE_FIXME("Could not find engine for %s\n", wine_dbgstr_w(ext)); return 1; } CoInitialize(NULL); if(!create_engine(&clsid, &script, &parser)) { WINE_FIXME("Could not create script engine\n"); CoUninitialize(); return 1; } if(init_engine(script, parser)) { run_script(filename, script, parser); IActiveScript_Close(script); ITypeInfo_Release(host_ti); }else { WINE_FIXME("Script initialization failed\n"); } IActiveScript_Release(script); IActiveScriptParse_Release(parser); CoUninitialize(); return 0; }
static void test_vbscript_uninitializing(void) { IActiveScriptParse *parse; IActiveScript *script; IDispatchEx *dispex; ULONG ref; HRESULT hres; static const WCHAR script_textW[] = {'F','u','n','c','t','i','o','n',' ','f','\n','E','n','d',' ','F','u','n','c','t','i','o','n','\n',0}; script = create_vbscript(); hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse); ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); test_state(script, SCRIPTSTATE_UNINITIALIZED); hres = IActiveScriptParse_InitNew(parse); ok(hres == S_OK, "InitNew failed: %08x\n", hres); SET_EXPECT(GetLCID); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); CHECK_CALLED(OnStateChange_INITIALIZED); test_state(script, SCRIPTSTATE_INITIALIZED); hres = IActiveScriptParse_ParseScriptText(parse, script_textW, NULL, NULL, NULL, 0, 1, 0x42, NULL, NULL); ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres); SET_EXPECT(OnStateChange_UNINITIALIZED); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_UNINITIALIZED); test_state(script, SCRIPTSTATE_UNINITIALIZED); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres); SET_EXPECT(GetLCID); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); CHECK_CALLED(OnStateChange_INITIALIZED); SET_EXPECT(OnStateChange_CONNECTED); SET_EXPECT(OnEnterScript); SET_EXPECT(OnLeaveScript); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CONNECTED); CHECK_CALLED(OnEnterScript); CHECK_CALLED(OnLeaveScript); test_state(script, SCRIPTSTATE_CONNECTED); dispex = get_script_dispatch(script); ok(dispex != NULL, "dispex == NULL\n"); if(dispex) IDispatchEx_Release(dispex); SET_EXPECT(OnStateChange_DISCONNECTED); SET_EXPECT(OnStateChange_INITIALIZED); SET_EXPECT(OnStateChange_UNINITIALIZED); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_DISCONNECTED); CHECK_CALLED(OnStateChange_INITIALIZED); CHECK_CALLED(OnStateChange_UNINITIALIZED); test_state(script, SCRIPTSTATE_UNINITIALIZED); hres = IActiveScript_Close(script); ok(hres == S_OK, "Close failed: %08x\n", hres); test_state(script, SCRIPTSTATE_CLOSED); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED); ok(hres == E_UNEXPECTED, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x, expected E_UNEXPECTED\n", hres); test_state(script, SCRIPTSTATE_CLOSED); SET_EXPECT(GetLCID); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); CHECK_CALLED(OnStateChange_INITIALIZED); test_state(script, SCRIPTSTATE_INITIALIZED); SET_EXPECT(OnStateChange_CLOSED); hres = IActiveScript_Close(script); ok(hres == S_OK, "Close failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CLOSED); test_state(script, SCRIPTSTATE_CLOSED); IActiveScriptParse_Release(parse); ref = IActiveScript_Release(script); ok(!ref, "ref = %d\n", ref); }
static void test_vbscript(void) { IActiveScriptParseProcedure2 *parse_proc; IActiveScriptParse *parser; IActiveScript *vbscript; ULONG ref; HRESULT hres; vbscript = create_vbscript(); hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParse, (void**)&parser); ok(hres == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hres); test_state(vbscript, SCRIPTSTATE_UNINITIALIZED); test_safety(vbscript); SET_EXPECT(GetLCID); hres = IActiveScript_SetScriptSite(vbscript, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); test_state(vbscript, SCRIPTSTATE_UNINITIALIZED); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScriptParse_InitNew(parser); ok(hres == S_OK, "InitNew failed: %08x\n", hres); CHECK_CALLED(OnStateChange_INITIALIZED); test_state(vbscript, SCRIPTSTATE_INITIALIZED); hres = IActiveScriptParse_InitNew(parser); ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres); SET_EXPECT(OnStateChange_CONNECTED); hres = IActiveScript_SetScriptState(vbscript, SCRIPTSTATE_CONNECTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CONNECTED); test_state(vbscript, SCRIPTSTATE_CONNECTED); SET_EXPECT(OnStateChange_DISCONNECTED); SET_EXPECT(OnStateChange_INITIALIZED); SET_EXPECT(OnStateChange_CLOSED); hres = IActiveScript_Close(vbscript); ok(hres == S_OK, "Close failed: %08x\n", hres); CHECK_CALLED(OnStateChange_DISCONNECTED); CHECK_CALLED(OnStateChange_INITIALIZED); CHECK_CALLED(OnStateChange_CLOSED); test_state(vbscript, SCRIPTSTATE_CLOSED); test_no_script_dispatch(vbscript); IActiveScriptParse_Release(parser); hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParseProcedure, (void**)&parse_proc); ok(hres == E_NOINTERFACE, "Got IActiveScriptParseProcedure interface, expected E_NOTIMPL\n"); hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc); ok(hres == S_OK, "Could not get IActiveScriptParseProcedure2 interface\n"); IActiveScriptParseProcedure2_Release(parse_proc); ref = IActiveScript_Release(vbscript); ok(!ref, "ref = %d\n", ref); }
static void test_scriptdisp(void) { IActiveScriptParse *parser; IDispatchEx *script_disp; IActiveScript *vbscript; DISPID id, id2; DISPPARAMS dp; EXCEPINFO ei; VARIANT v; ULONG ref; HRESULT hres; vbscript = create_vbscript(); hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParse, (void**)&parser); ok(hres == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hres); test_state(vbscript, SCRIPTSTATE_UNINITIALIZED); test_safety(vbscript); SET_EXPECT(GetLCID); hres = IActiveScript_SetScriptSite(vbscript, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); test_state(vbscript, SCRIPTSTATE_UNINITIALIZED); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScriptParse_InitNew(parser); ok(hres == S_OK, "InitNew failed: %08x\n", hres); CHECK_CALLED(OnStateChange_INITIALIZED); test_state(vbscript, SCRIPTSTATE_INITIALIZED); SET_EXPECT(OnStateChange_CONNECTED); hres = IActiveScript_SetScriptState(vbscript, SCRIPTSTATE_CONNECTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CONNECTED); test_state(vbscript, SCRIPTSTATE_CONNECTED); script_disp = get_script_dispatch(vbscript); id = 100; get_disp_id(script_disp, "LCase", DISP_E_UNKNOWNNAME, &id); ok(id == -1, "id = %d, expected -1\n", id); get_disp_id(script_disp, "globalVariable", DISP_E_UNKNOWNNAME, &id); parse_script(parser, "dim globalVariable\nglobalVariable = 3"); get_disp_id(script_disp, "globalVariable", S_OK, &id); memset(&dp, 0, sizeof(dp)); memset(&ei, 0, sizeof(ei)); V_VT(&v) = VT_EMPTY; hres = IDispatchEx_InvokeEx(script_disp, id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL); ok(hres == S_OK, "InvokeEx failed: %08x\n", hres); ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v)); ok(V_I2(&v) == 3, "V_I2(v) = %d\n", V_I2(&v)); get_disp_id(script_disp, "globalVariable2", DISP_E_UNKNOWNNAME, &id); parse_script(parser, "globalVariable2 = 4"); get_disp_id(script_disp, "globalVariable2", S_OK, &id); get_disp_id(script_disp, "globalFunction", DISP_E_UNKNOWNNAME, &id); parse_script(parser, "function globalFunction()\nglobalFunction=5\nend function"); get_disp_id(script_disp, "globalFunction", S_OK, &id); SET_EXPECT(OnEnterScript); SET_EXPECT(OnLeaveScript); memset(&dp, 0, sizeof(dp)); memset(&ei, 0, sizeof(ei)); V_VT(&v) = VT_EMPTY; hres = IDispatchEx_InvokeEx(script_disp, id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL); ok(hres == S_OK, "InvokeEx failed: %08x\n", hres); ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v)); ok(V_I2(&v) == 5, "V_I2(v) = %d\n", V_I2(&v)); CHECK_CALLED(OnEnterScript); CHECK_CALLED(OnLeaveScript); SET_EXPECT(OnEnterScript); SET_EXPECT(OnLeaveScript); memset(&dp, 0, sizeof(dp)); memset(&ei, 0, sizeof(ei)); V_VT(&v) = VT_EMPTY; hres = IDispatchEx_Invoke(script_disp, id, &IID_NULL, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL); ok(hres == S_OK, "InvokeEx failed: %08x\n", hres); ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v)); ok(V_I2(&v) == 5, "V_I2(v) = %d\n", V_I2(&v)); CHECK_CALLED(OnEnterScript); CHECK_CALLED(OnLeaveScript); get_disp_id(script_disp, "globalSub", DISP_E_UNKNOWNNAME, &id); parse_script(parser, "sub globalSub()\nend sub"); get_disp_id(script_disp, "globalSub", S_OK, &id); get_disp_id(script_disp, "globalSub", S_OK, &id2); ok(id == id2, "id != id2\n"); get_disp_id(script_disp, "constVariable", DISP_E_UNKNOWNNAME, &id); parse_script(parser, "const constVariable = 6"); get_disp_id(script_disp, "ConstVariable", S_OK, &id); get_disp_id(script_disp, "Constvariable", S_OK, &id2); ok(id == id2, "id != id2\n"); IDispatchEx_Release(script_disp); IActiveScriptParse_Release(parser); SET_EXPECT(OnStateChange_DISCONNECTED); SET_EXPECT(OnStateChange_INITIALIZED); SET_EXPECT(OnStateChange_CLOSED); hres = IActiveScript_Close(vbscript); ok(hres == S_OK, "Close failed: %08x\n", hres); CHECK_CALLED(OnStateChange_DISCONNECTED); CHECK_CALLED(OnStateChange_INITIALIZED); CHECK_CALLED(OnStateChange_CLOSED); ref = IActiveScript_Release(vbscript); ok(!ref, "ref = %d\n", ref); }
static void test_ActiveXObject(void) { IActiveScriptParse *parser; IDispatchEx *proc; parser = create_script(FALSE, TRUE); SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(reportSuccess); parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();"); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(reportSuccess); proc = parse_procedure_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();"); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(reportSuccess); call_procedure(proc, NULL); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(reportSuccess); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(reportSuccess); call_procedure(proc, &caller_sp); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(reportSuccess); IDispatchEx_Release(proc); IActiveScriptParse_Release(parser); parser = create_script(FALSE, TRUE); proc = parse_procedure_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();"); SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(reportSuccess); call_procedure(proc, &caller_sp); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(reportSuccess); parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.TestABC'); }, 'Error', -2146827859);"); IDispatchEx_Release(proc); IActiveScriptParse_Release(parser); parser = create_script(FALSE, TRUE); QS_SecMgr_hres = E_NOINTERFACE; SET_EXPECT(Host_QS_SecMgr); parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);"); CHECK_CALLED(Host_QS_SecMgr); IActiveScriptParse_Release(parser); parser = create_script(FALSE, TRUE); ProcessUrlAction_hres = E_FAIL; SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);"); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); IActiveScriptParse_Release(parser); parser = create_script(FALSE, TRUE); ProcessUrlAction_policy = URLPOLICY_DISALLOW; SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);"); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); IActiveScriptParse_Release(parser); parser = create_script(FALSE, TRUE); CreateInstance_hres = E_FAIL; SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);"); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); IActiveScriptParse_Release(parser); parser = create_script(FALSE, TRUE); QueryCustomPolicy_hres = E_FAIL; SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);"); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); IActiveScriptParse_Release(parser); parser = create_script(FALSE, TRUE); QueryCustomPolicy_psize = 6; SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(reportSuccess); parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();"); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(reportSuccess); IActiveScriptParse_Release(parser); parser = create_script(FALSE, TRUE); QueryCustomPolicy_policy = URLPOLICY_DISALLOW; SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);"); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); QueryCustomPolicy_psize = 6; SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);"); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); QueryCustomPolicy_policy = URLPOLICY_ALLOW; QueryCustomPolicy_psize = 3; SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);"); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); IActiveScriptParse_Release(parser); parser = create_script(FALSE, FALSE); SET_EXPECT(CreateInstance); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(reportSuccess); parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();"); CHECK_CALLED(CreateInstance); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(reportSuccess); IActiveScriptParse_Release(parser); parser = create_script(FALSE, TRUE); object_with_site = &ObjectWithSite; SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(SetSite); SET_EXPECT(reportSuccess); parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();"); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(SetSite); CHECK_CALLED(reportSuccess); SetSite_hres = E_FAIL; SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(SetSite); parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);"); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(SetSite); IActiveScriptParse_Release(parser); /* No IServiceProvider Interface */ parser = create_script(FALSE, FALSE); object_with_site = &ObjectWithSite; AllowIServiceProvider = FALSE; SET_EXPECT(CreateInstance); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(reportSuccess); SET_EXPECT(SetSite); parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();"); CHECK_CALLED(CreateInstance); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(reportSuccess); CHECK_CALLED(SetSite); IActiveScriptParse_Release(parser); parser = create_script(FALSE, TRUE); object_with_site = &ObjectWithSite; AllowIServiceProvider = FALSE; parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);"); IActiveScriptParse_Release(parser); }
static void test_jscript(void) { IActiveScriptParse *parse; IActiveScript *script; IDispatchEx *dispex; ULONG ref; HRESULT hres; script = create_jscript(); hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse); ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres); test_state(script, SCRIPTSTATE_UNINITIALIZED); test_safety((IUnknown*)script); test_invoke_versioning(script); hres = IActiveScriptParse_InitNew(parse); ok(hres == S_OK, "InitNew failed: %08x\n", hres); hres = IActiveScriptParse_InitNew(parse); ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres); hres = IActiveScript_SetScriptSite(script, NULL); ok(hres == E_POINTER, "SetScriptSite failed: %08x, expected E_POINTER\n", hres); test_state(script, SCRIPTSTATE_UNINITIALIZED); test_no_script_dispatch(script); SET_EXPECT(GetLCID); SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); CHECK_CALLED(OnStateChange_INITIALIZED); test_state(script, SCRIPTSTATE_INITIALIZED); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres); dispex = get_script_dispatch(script); test_script_dispatch(dispex); SET_EXPECT(OnStateChange_STARTED); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_STARTED); test_state(script, SCRIPTSTATE_STARTED); SET_EXPECT(OnStateChange_CLOSED); hres = IActiveScript_Close(script); ok(hres == S_OK, "Close failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CLOSED); test_state(script, SCRIPTSTATE_CLOSED); test_no_script_dispatch(script); test_script_dispatch(dispex); IDispatchEx_Release(dispex); IActiveScriptParse_Release(parse); ref = IActiveScript_Release(script); ok(!ref, "ref = %d\n", ref); }
static void test_CreateObject(void) { IActiveScriptParse *parser; HRESULT hres; parser = create_script(TRUE); SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(reportSuccess); parse_script_a(parser, "Call CreateObject(\"Wine.Test\").reportSuccess()"); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(reportSuccess); IActiveScriptParse_Release(parser); parser = create_script(TRUE); hres = parse_script_ae(parser, "Call CreateObject(\"Wine.TestABC\")"); ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres); IActiveScriptParse_Release(parser); parser = create_script(TRUE); QS_SecMgr_hres = E_NOINTERFACE; SET_EXPECT(Host_QS_SecMgr); hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")"); ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres); CHECK_CALLED(Host_QS_SecMgr); IActiveScriptParse_Release(parser); parser = create_script(TRUE); ProcessUrlAction_hres = E_FAIL; SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")"); ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); IActiveScriptParse_Release(parser); parser = create_script(TRUE); ProcessUrlAction_policy = URLPOLICY_DISALLOW; SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")"); ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); IActiveScriptParse_Release(parser); parser = create_script(TRUE); CreateInstance_hres = E_FAIL; SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")"); ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); IActiveScriptParse_Release(parser); parser = create_script(TRUE); QueryCustomPolicy_hres = E_FAIL; SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")"); ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); IActiveScriptParse_Release(parser); parser = create_script(TRUE); QueryCustomPolicy_psize = 6; SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(reportSuccess); parse_script_a(parser, "Call CreateObject(\"Wine.Test\").reportSuccess()"); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(reportSuccess); IActiveScriptParse_Release(parser); parser = create_script(TRUE); QueryCustomPolicy_policy = URLPOLICY_DISALLOW; SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")"); ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); QueryCustomPolicy_psize = 6; SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")"); ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); QueryCustomPolicy_policy = URLPOLICY_ALLOW; QueryCustomPolicy_psize = 3; SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")"); ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); IActiveScriptParse_Release(parser); parser = create_script(FALSE); SET_EXPECT(CreateInstance); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(reportSuccess); parse_script_a(parser, "Call CreateObject(\"Wine.Test\").reportSuccess()"); CHECK_CALLED(CreateInstance); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(reportSuccess); IActiveScriptParse_Release(parser); parser = create_script(TRUE); object_with_site = &ObjectWithSite; SET_EXPECT(Host_QS_SecMgr); SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(SetSite); SET_EXPECT(reportSuccess); parse_script_a(parser, "Call CreateObject(\"Wine.Test\").reportSuccess()"); CHECK_CALLED(Host_QS_SecMgr); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(SetSite); CHECK_CALLED(reportSuccess); SetSite_hres = E_FAIL; SET_EXPECT(ProcessUrlAction); SET_EXPECT(CreateInstance); SET_EXPECT(QueryCustomPolicy); SET_EXPECT(QI_IObjectWithSite); SET_EXPECT(SetSite); hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")"); ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres); CHECK_CALLED(ProcessUrlAction); CHECK_CALLED(CreateInstance); CHECK_CALLED(QueryCustomPolicy); CHECK_CALLED(QI_IObjectWithSite); CHECK_CALLED(SetSite); IActiveScriptParse_Release(parser); }
/* * Call a script. */ DWORD call_script(MSIHANDLE hPackage, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action) { HRESULT hr; IActiveScript *pActiveScript = NULL; IActiveScriptParse *pActiveScriptParse = NULL; MsiActiveScriptSite *scriptsite; IDispatch *pDispatch = NULL; DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}; DISPID dispid; CLSID clsid; VARIANT var; DWORD ret = ERROR_INSTALL_FAILURE; CoInitialize(NULL); /* Create MsiActiveScriptSite object */ hr = create_activescriptsite(&scriptsite); if (hr != S_OK) goto done; /* Create an installer object */ hr = create_msiserver(NULL, (void**)&scriptsite->installer); if (hr != S_OK) goto done; /* Create a session object */ hr = create_session(hPackage, scriptsite->installer, &scriptsite->session); if (hr != S_OK) goto done; /* Create the scripting engine */ type &= msidbCustomActionTypeJScript|msidbCustomActionTypeVBScript; if (type == msidbCustomActionTypeJScript) hr = CLSIDFromProgID(szJScript, &clsid); else if (type == msidbCustomActionTypeVBScript) hr = CLSIDFromProgID(szVBScript, &clsid); else { ERR("Unknown script type %d\n", type); goto done; } if (FAILED(hr)) { ERR("Could not find CLSID for Windows Script\n"); goto done; } hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IActiveScript, (void **)&pActiveScript); if (FAILED(hr)) { ERR("Could not instantiate class for Windows Script\n"); goto done; } hr = IActiveScript_QueryInterface(pActiveScript, &IID_IActiveScriptParse, (void **)&pActiveScriptParse); if (FAILED(hr)) goto done; hr = IActiveScript_SetScriptSite(pActiveScript, &scriptsite->IActiveScriptSite_iface); if (FAILED(hr)) goto done; hr = IActiveScriptParse_InitNew(pActiveScriptParse); if (FAILED(hr)) goto done; hr = IActiveScript_AddNamedItem(pActiveScript, szSession, SCRIPTITEM_GLOBALMEMBERS|SCRIPTITEM_ISVISIBLE); if (FAILED(hr)) goto done; hr = IActiveScriptParse_ParseScriptText(pActiveScriptParse, script, NULL, NULL, NULL, 0, 0, 0L, NULL, NULL); if (FAILED(hr)) goto done; hr = IActiveScript_SetScriptState(pActiveScript, SCRIPTSTATE_CONNECTED); if (FAILED(hr)) goto done; /* Call a function if necessary through the IDispatch interface */ if (function && function[0]) { TRACE("Calling function %s\n", debugstr_w(function)); hr = IActiveScript_GetScriptDispatch(pActiveScript, NULL, &pDispatch); if (FAILED(hr)) goto done; hr = IDispatch_GetIDsOfNames(pDispatch, &IID_NULL, (WCHAR **)&function, 1,LOCALE_USER_DEFAULT, &dispid); if (FAILED(hr)) goto done; hr = IDispatch_Invoke(pDispatch, dispid, &IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparamsNoArgs, &var, NULL, NULL); if (FAILED(hr)) goto done; hr = VariantChangeType(&var, &var, 0, VT_I4); if (FAILED(hr)) goto done; ret = map_return_value(V_I4(&var)); VariantClear(&var); } else { /* If no function to be called, MSI behavior is to succeed */ ret = ERROR_SUCCESS; } done: if (pDispatch) IDispatch_Release(pDispatch); if (pActiveScript) IActiveScript_Release(pActiveScript); if (pActiveScriptParse) IActiveScriptParse_Release(pActiveScriptParse); if (scriptsite) { if (scriptsite->session) IDispatch_Release(scriptsite->session); if (scriptsite->installer) IDispatch_Release(scriptsite->installer); IActiveScriptSite_Release(&scriptsite->IActiveScriptSite_iface); } CoUninitialize(); /* must call even if CoInitialize failed */ return ret; }