2 * Copyright 2009,2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/test.h"
35 #define IActiveScriptParse_QueryInterface IActiveScriptParse64_QueryInterface
36 #define IActiveScriptParse_Release IActiveScriptParse64_Release
37 #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
38 #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
42 #define IActiveScriptParse_QueryInterface IActiveScriptParse32_QueryInterface
43 #define IActiveScriptParse_Release IActiveScriptParse32_Release
44 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
45 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
49 extern const CLSID CLSID_VBScript;
51 #define DEFINE_EXPECT(func) \
52 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
54 #define SET_EXPECT(func) \
55 expect_ ## func = TRUE
57 #define CHECK_EXPECT2(func) \
59 ok(expect_ ##func, "unexpected call " #func "\n"); \
60 called_ ## func = TRUE; \
63 #define CHECK_EXPECT(func) \
65 CHECK_EXPECT2(func); \
66 expect_ ## func = FALSE; \
69 #define CHECK_CALLED(func) \
71 ok(called_ ## func, "expected " #func "\n"); \
72 expect_ ## func = called_ ## func = FALSE; \
75 DEFINE_EXPECT(CreateInstance);
76 DEFINE_EXPECT(ProcessUrlAction);
77 DEFINE_EXPECT(QueryCustomPolicy);
78 DEFINE_EXPECT(reportSuccess);
79 DEFINE_EXPECT(Host_QS_SecMgr);
80 DEFINE_EXPECT(Caller_QS_SecMgr);
81 DEFINE_EXPECT(QI_IObjectWithSite);
82 DEFINE_EXPECT(SetSite);
84 static const WCHAR testW[] = {'t','e','s','t',0};
86 static HRESULT QS_SecMgr_hres;
87 static HRESULT ProcessUrlAction_hres;
88 static DWORD ProcessUrlAction_policy;
89 static HRESULT CreateInstance_hres;
90 static HRESULT QueryCustomPolicy_hres;
91 static DWORD QueryCustomPolicy_psize;
92 static DWORD QueryCustomPolicy_policy;
93 static HRESULT QI_IDispatch_hres;
94 static HRESULT SetSite_hres;
96 #define TESTOBJ_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}"
98 static const GUID CLSID_TestObj =
99 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
101 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
102 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
103 {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
105 #define DISPID_TEST_REPORTSUCCESS 0x1000
107 #define DISPID_GLOBAL_OK 0x2000
109 #define VB_E_CANNOT_CREATE_OBJ 0x800a01ad
111 static const char *debugstr_guid(REFIID riid)
115 sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
116 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
117 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
118 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
123 static BSTR a2bstr(const char *str)
128 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
129 ret = SysAllocStringLen(NULL, len-1);
130 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
135 static int strcmp_wa(LPCWSTR strw, const char *stra)
138 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
139 return lstrcmpA(buf, stra);
142 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID riid, void **ppv)
144 ok(0, "unexpected call\n");
148 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
153 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
158 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
160 IServiceProvider *sp;
164 CHECK_EXPECT(SetSite);
165 ok(pUnkSite != NULL, "pUnkSite == NULL\n");
167 hres = IUnknown_QueryInterface(pUnkSite, &IID_IServiceProvider, (void**)&sp);
168 ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
169 IServiceProvider_Release(sp);
174 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, void **ppvSite)
176 ok(0, "unexpected call\n");
180 static const IObjectWithSiteVtbl ObjectWithSiteVtbl = {
181 ObjectWithSite_QueryInterface,
182 ObjectWithSite_AddRef,
183 ObjectWithSite_Release,
184 ObjectWithSite_SetSite,
185 ObjectWithSite_GetSite
188 static IObjectWithSite ObjectWithSite = { &ObjectWithSiteVtbl };
190 static IObjectWithSite *object_with_site;
192 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
196 if(IsEqualGUID(riid, &IID_IUnknown)) {
198 }else if(IsEqualGUID(riid, &IID_IDispatch) || IsEqualGUID(riid, &IID_IDispatchEx)) {
199 if(FAILED(QI_IDispatch_hres))
200 return QI_IDispatch_hres;
202 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
203 CHECK_EXPECT(QI_IObjectWithSite);
204 *ppv = object_with_site;
205 }else if(IsEqualGUID(&IID_IObjectSafety, riid)) {
206 ok(0, "Unexpected IID_IObjectSafety query\n");
209 return *ppv ? S_OK : E_NOINTERFACE;
212 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
217 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
222 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
224 ok(0, "unexpected call\n");
228 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
229 LCID lcid, ITypeInfo **ppTInfo)
231 ok(0, "unexpected call\n");
235 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
236 LPOLESTR *rgszNames, UINT cNames,
237 LCID lcid, DISPID *rgDispId)
239 ok(0, "unexpected call\n");
243 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
244 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
245 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
247 ok(0, "unexpected call\n");
251 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
253 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
257 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
259 ok(0, "unexpected call\n");
263 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
265 ok(0, "unexpected call\n");
269 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
271 ok(0, "unexpected call\n");
275 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
277 ok(0, "unexpected call\n");
281 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
283 ok(0, "unexpected call\n");
287 static HRESULT WINAPI Test_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
289 if(!strcmp_wa(bstrName, "reportSuccess")) {
290 ok(grfdex == fdexNameCaseInsensitive, "grfdex = %x\n", grfdex);
291 *pid = DISPID_TEST_REPORTSUCCESS;
295 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
299 static HRESULT WINAPI Test_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
300 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
303 case DISPID_TEST_REPORTSUCCESS:
304 CHECK_EXPECT(reportSuccess);
306 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
307 ok(pdp != NULL, "pdp == NULL\n");
308 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
309 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
310 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
311 ok(!pvarRes, "pvarRes != NULL\n");
312 ok(pei != NULL, "pei == NULL\n");
316 ok(0, "unexpected call\n");
323 static IDispatchExVtbl testObjVtbl = {
324 DispatchEx_QueryInterface,
327 DispatchEx_GetTypeInfoCount,
328 DispatchEx_GetTypeInfo,
329 DispatchEx_GetIDsOfNames,
333 DispatchEx_DeleteMemberByName,
334 DispatchEx_DeleteMemberByDispID,
335 DispatchEx_GetMemberProperties,
336 DispatchEx_GetMemberName,
337 DispatchEx_GetNextDispID,
338 DispatchEx_GetNameSpaceParent
341 static IDispatchEx testObj = { &testObjVtbl };
343 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
345 if(!strcmp_wa(bstrName, "ok")) {
346 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
347 *pid = DISPID_GLOBAL_OK;
351 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
355 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
356 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
359 case DISPID_GLOBAL_OK:
360 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
361 ok(pdp != NULL, "pdp == NULL\n");
362 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
363 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
364 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
365 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
366 ok(pei != NULL, "pei == NULL\n");
368 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
369 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
370 ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
374 ok(0, "unexpected call\n");
381 static IDispatchExVtbl globalObjVtbl = {
382 DispatchEx_QueryInterface,
385 DispatchEx_GetTypeInfoCount,
386 DispatchEx_GetTypeInfo,
387 DispatchEx_GetIDsOfNames,
391 DispatchEx_DeleteMemberByName,
392 DispatchEx_DeleteMemberByDispID,
393 DispatchEx_GetMemberProperties,
394 DispatchEx_GetMemberName,
395 DispatchEx_GetNextDispID,
396 DispatchEx_GetNameSpaceParent
399 static IDispatchEx globalObj = { &globalObjVtbl };
401 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
403 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
408 /* TODO: IClassFactoryEx */
410 return E_NOINTERFACE;
413 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
418 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
423 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
425 CHECK_EXPECT(CreateInstance);
427 ok(!outer, "outer = %p\n", outer);
428 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
430 if(SUCCEEDED(CreateInstance_hres))
432 return CreateInstance_hres;
435 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
437 ok(0, "unexpected call\n");
441 static const IClassFactoryVtbl ClassFactoryVtbl = {
442 ClassFactory_QueryInterface,
444 ClassFactory_Release,
445 ClassFactory_CreateInstance,
446 ClassFactory_LockServer
449 static IClassFactory activex_cf = { &ClassFactoryVtbl };
451 static HRESULT WINAPI InternetHostSecurityManager_QueryInterface(IInternetHostSecurityManager *iface, REFIID riid, void **ppv)
453 ok(0, "unexpected call\n");
454 return E_NOINTERFACE;
457 static ULONG WINAPI InternetHostSecurityManager_AddRef(IInternetHostSecurityManager *iface)
462 static ULONG WINAPI InternetHostSecurityManager_Release(IInternetHostSecurityManager *iface)
467 static HRESULT WINAPI InternetHostSecurityManager_GetSecurityId(IInternetHostSecurityManager *iface, BYTE *pbSecurityId,
468 DWORD *pcbSecurityId, DWORD_PTR dwReserved)
470 ok(0, "unexpected call\n");
474 static HRESULT WINAPI InternetHostSecurityManager_ProcessUrlAction(IInternetHostSecurityManager *iface, DWORD dwAction,
475 BYTE *pPolicy, DWORD cbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved)
477 CHECK_EXPECT(ProcessUrlAction);
479 ok(dwAction == URLACTION_ACTIVEX_RUN, "dwAction = %x\n", dwAction);
480 ok(pPolicy != NULL, "pPolicy == NULL\n");
481 ok(cbPolicy == sizeof(DWORD), "cbPolicy = %d\n", cbPolicy);
482 ok(pContext != NULL, "pContext == NULL\n");
483 ok(cbContext == sizeof(GUID), "cbContext = %d\n", cbContext);
484 ok(IsEqualGUID(pContext, &CLSID_TestObj), "pContext = %s\n", debugstr_guid((const IID*)pContext));
485 ok(!dwFlags, "dwFlags = %x\n", dwFlags);
486 ok(!dwReserved, "dwReserved = %x\n", dwReserved);
488 if(SUCCEEDED(ProcessUrlAction_hres))
489 *(DWORD*)pPolicy = ProcessUrlAction_policy;
490 return ProcessUrlAction_hres;
493 static HRESULT WINAPI InternetHostSecurityManager_QueryCustomPolicy(IInternetHostSecurityManager *iface, REFGUID guidKey,
494 BYTE **ppPolicy, DWORD *pcbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwReserved)
496 const struct CONFIRMSAFETY *cs = (const struct CONFIRMSAFETY*)pContext;
499 CHECK_EXPECT(QueryCustomPolicy);
501 ok(IsEqualGUID(&GUID_CUSTOM_CONFIRMOBJECTSAFETY, guidKey), "guidKey = %s\n", debugstr_guid(guidKey));
503 ok(ppPolicy != NULL, "ppPolicy == NULL\n");
504 ok(pcbPolicy != NULL, "pcbPolicy == NULL\n");
505 ok(pContext != NULL, "pContext == NULL\n");
506 ok(cbContext == sizeof(struct CONFIRMSAFETY), "cbContext = %d\n", cbContext);
507 ok(!dwReserved, "dwReserved = %x\n", dwReserved);
510 ok(cs->pUnk != NULL, "cs->pUnk == NULL\n");
511 ok(!cs->dwFlags, "dwFlags = %x\n", cs->dwFlags);
513 if(FAILED(QueryCustomPolicy_hres))
514 return QueryCustomPolicy_hres;
516 ret = CoTaskMemAlloc(QueryCustomPolicy_psize);
517 *ppPolicy = (BYTE*)ret;
518 *pcbPolicy = QueryCustomPolicy_psize;
519 memset(ret, 0, QueryCustomPolicy_psize);
520 if(QueryCustomPolicy_psize >= sizeof(DWORD))
521 *ret = QueryCustomPolicy_policy;
523 return QueryCustomPolicy_hres;
526 static const IInternetHostSecurityManagerVtbl InternetHostSecurityManagerVtbl = {
527 InternetHostSecurityManager_QueryInterface,
528 InternetHostSecurityManager_AddRef,
529 InternetHostSecurityManager_Release,
530 InternetHostSecurityManager_GetSecurityId,
531 InternetHostSecurityManager_ProcessUrlAction,
532 InternetHostSecurityManager_QueryCustomPolicy
535 static IInternetHostSecurityManager InternetHostSecurityManager = { &InternetHostSecurityManagerVtbl };
537 static IServiceProvider ServiceProvider;
539 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
541 ok(0, "unexpected call\n");
542 return E_NOINTERFACE;
545 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
550 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
555 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
556 REFGUID guidService, REFIID riid, void **ppv)
558 if(IsEqualGUID(&SID_GetCaller, guidService))
559 return E_NOINTERFACE;
561 if(IsEqualGUID(&SID_SInternetHostSecurityManager, guidService)) {
562 if(iface == &ServiceProvider)
563 CHECK_EXPECT(Host_QS_SecMgr);
565 CHECK_EXPECT(Caller_QS_SecMgr);
566 ok(IsEqualGUID(&IID_IInternetHostSecurityManager, riid), "unexpected riid %s\n", debugstr_guid(riid));
567 if(SUCCEEDED(QS_SecMgr_hres))
568 *ppv = &InternetHostSecurityManager;
569 return QS_SecMgr_hres;
572 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
573 return E_NOINTERFACE;
576 static IServiceProviderVtbl ServiceProviderVtbl = {
577 ServiceProvider_QueryInterface,
578 ServiceProvider_AddRef,
579 ServiceProvider_Release,
580 ServiceProvider_QueryService
583 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
585 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
587 if(IsEqualGUID(&IID_IUnknown, riid)) {
589 }else if(IsEqualGUID(&IID_IActiveScriptSite, riid)) {
591 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
592 *ppv = &ServiceProvider;
595 return E_NOINTERFACE;
598 IUnknown_AddRef((IUnknown*)*ppv);
602 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
607 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
612 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
614 *plcid = GetUserDefaultLCID();
618 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
619 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
621 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
622 ok(!ppti, "ppti != NULL\n");
623 ok(!strcmp_wa(pstrName, "test"), "pstrName = %s\n", wine_dbgstr_w(pstrName));
625 *ppiunkItem = (IUnknown*)&globalObj;
629 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
634 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
635 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
640 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
645 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
650 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
655 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
660 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
661 ActiveScriptSite_QueryInterface,
662 ActiveScriptSite_AddRef,
663 ActiveScriptSite_Release,
664 ActiveScriptSite_GetLCID,
665 ActiveScriptSite_GetItemInfo,
666 ActiveScriptSite_GetDocVersionString,
667 ActiveScriptSite_OnScriptTerminate,
668 ActiveScriptSite_OnStateChange,
669 ActiveScriptSite_OnScriptError,
670 ActiveScriptSite_OnEnterScript,
671 ActiveScriptSite_OnLeaveScript
674 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
676 static void set_safety_options(IUnknown *unk, BOOL use_sec_mgr)
678 IObjectSafety *safety;
679 DWORD supported, enabled, options_all, options_set;
682 hres = IUnknown_QueryInterface(unk, &IID_IObjectSafety, (void**)&safety);
683 ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
687 options_all = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
689 options_set = options_all;
691 options_set = INTERFACE_USES_DISPEX;
693 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, options_all, options_set);
694 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
696 supported = enabled = 0xdeadbeef;
697 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
698 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
699 ok(supported == options_all, "supported=%x, expected %x\n", supported, options_all);
700 ok(enabled == options_set, "enabled=%x, expected %x\n", enabled, options_set);
702 IObjectSafety_Release(safety);
705 #define parse_script_a(p,s) _parse_script_a(__LINE__,p,s)
706 static void _parse_script_a(unsigned line, IActiveScriptParse *parser, const char *script)
711 str = a2bstr(script);
712 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
714 ok_(__FILE__,line)(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
717 static HRESULT parse_script_ae(IActiveScriptParse *parser, const char *script)
722 str = a2bstr(script);
723 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
729 static IActiveScriptParse *create_script(BOOL use_sec_mgr)
731 IActiveScriptParse *parser;
732 IActiveScript *script;
735 QS_SecMgr_hres = S_OK;
736 ProcessUrlAction_hres = S_OK;
737 ProcessUrlAction_policy = URLPOLICY_ALLOW;
738 CreateInstance_hres = S_OK;
739 QueryCustomPolicy_hres = S_OK;
740 QueryCustomPolicy_psize = sizeof(DWORD);
741 QueryCustomPolicy_policy = URLPOLICY_ALLOW;
742 QI_IDispatch_hres = S_OK;
745 hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
746 &IID_IActiveScript, (void**)&script);
747 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
751 set_safety_options((IUnknown*)script, use_sec_mgr);
753 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser);
754 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
756 hres = IActiveScriptParse_InitNew(parser);
757 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
759 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
760 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
762 hres = IActiveScript_AddNamedItem(script, testW,
763 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
764 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
766 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED);
767 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
769 IActiveScript_Release(script);
774 static void test_CreateObject(void)
776 IActiveScriptParse *parser;
779 parser = create_script(TRUE);
781 SET_EXPECT(Host_QS_SecMgr);
782 SET_EXPECT(ProcessUrlAction);
783 SET_EXPECT(CreateInstance);
784 SET_EXPECT(QueryCustomPolicy);
785 SET_EXPECT(QI_IObjectWithSite);
786 SET_EXPECT(reportSuccess);
787 parse_script_a(parser, "Call CreateObject(\"Wine.Test\").reportSuccess()");
788 CHECK_CALLED(Host_QS_SecMgr);
789 CHECK_CALLED(ProcessUrlAction);
790 CHECK_CALLED(CreateInstance);
791 CHECK_CALLED(QueryCustomPolicy);
792 CHECK_CALLED(QI_IObjectWithSite);
793 CHECK_CALLED(reportSuccess);
795 IActiveScriptParse_Release(parser);
797 parser = create_script(TRUE);
799 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.TestABC\")");
800 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
802 IActiveScriptParse_Release(parser);
804 parser = create_script(TRUE);
805 QS_SecMgr_hres = E_NOINTERFACE;
807 SET_EXPECT(Host_QS_SecMgr);
808 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
809 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
810 CHECK_CALLED(Host_QS_SecMgr);
812 IActiveScriptParse_Release(parser);
814 parser = create_script(TRUE);
815 ProcessUrlAction_hres = E_FAIL;
817 SET_EXPECT(Host_QS_SecMgr);
818 SET_EXPECT(ProcessUrlAction);
819 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
820 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
821 CHECK_CALLED(Host_QS_SecMgr);
822 CHECK_CALLED(ProcessUrlAction);
824 IActiveScriptParse_Release(parser);
826 parser = create_script(TRUE);
827 ProcessUrlAction_policy = URLPOLICY_DISALLOW;
829 SET_EXPECT(Host_QS_SecMgr);
830 SET_EXPECT(ProcessUrlAction);
831 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
832 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
833 CHECK_CALLED(Host_QS_SecMgr);
834 CHECK_CALLED(ProcessUrlAction);
836 IActiveScriptParse_Release(parser);
838 parser = create_script(TRUE);
839 CreateInstance_hres = E_FAIL;
841 SET_EXPECT(Host_QS_SecMgr);
842 SET_EXPECT(ProcessUrlAction);
843 SET_EXPECT(CreateInstance);
844 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
845 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
846 CHECK_CALLED(Host_QS_SecMgr);
847 CHECK_CALLED(ProcessUrlAction);
848 CHECK_CALLED(CreateInstance);
850 IActiveScriptParse_Release(parser);
852 parser = create_script(TRUE);
853 QueryCustomPolicy_hres = E_FAIL;
855 SET_EXPECT(Host_QS_SecMgr);
856 SET_EXPECT(ProcessUrlAction);
857 SET_EXPECT(CreateInstance);
858 SET_EXPECT(QueryCustomPolicy);
859 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
860 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
861 CHECK_CALLED(Host_QS_SecMgr);
862 CHECK_CALLED(ProcessUrlAction);
863 CHECK_CALLED(CreateInstance);
864 CHECK_CALLED(QueryCustomPolicy);
866 IActiveScriptParse_Release(parser);
868 parser = create_script(TRUE);
869 QueryCustomPolicy_psize = 6;
871 SET_EXPECT(Host_QS_SecMgr);
872 SET_EXPECT(ProcessUrlAction);
873 SET_EXPECT(CreateInstance);
874 SET_EXPECT(QueryCustomPolicy);
875 SET_EXPECT(QI_IObjectWithSite);
876 SET_EXPECT(reportSuccess);
877 parse_script_a(parser, "Call CreateObject(\"Wine.Test\").reportSuccess()");
878 CHECK_CALLED(Host_QS_SecMgr);
879 CHECK_CALLED(ProcessUrlAction);
880 CHECK_CALLED(CreateInstance);
881 CHECK_CALLED(QueryCustomPolicy);
882 CHECK_CALLED(QI_IObjectWithSite);
883 CHECK_CALLED(reportSuccess);
885 IActiveScriptParse_Release(parser);
887 parser = create_script(TRUE);
888 QueryCustomPolicy_policy = URLPOLICY_DISALLOW;
890 SET_EXPECT(Host_QS_SecMgr);
891 SET_EXPECT(ProcessUrlAction);
892 SET_EXPECT(CreateInstance);
893 SET_EXPECT(QueryCustomPolicy);
894 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
895 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
896 CHECK_CALLED(Host_QS_SecMgr);
897 CHECK_CALLED(ProcessUrlAction);
898 CHECK_CALLED(CreateInstance);
899 CHECK_CALLED(QueryCustomPolicy);
901 QueryCustomPolicy_psize = 6;
903 SET_EXPECT(ProcessUrlAction);
904 SET_EXPECT(CreateInstance);
905 SET_EXPECT(QueryCustomPolicy);
906 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
907 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
908 CHECK_CALLED(ProcessUrlAction);
909 CHECK_CALLED(CreateInstance);
910 CHECK_CALLED(QueryCustomPolicy);
912 QueryCustomPolicy_policy = URLPOLICY_ALLOW;
913 QueryCustomPolicy_psize = 3;
915 SET_EXPECT(ProcessUrlAction);
916 SET_EXPECT(CreateInstance);
917 SET_EXPECT(QueryCustomPolicy);
918 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
919 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
920 CHECK_CALLED(ProcessUrlAction);
921 CHECK_CALLED(CreateInstance);
922 CHECK_CALLED(QueryCustomPolicy);
924 IActiveScriptParse_Release(parser);
926 parser = create_script(FALSE);
928 SET_EXPECT(CreateInstance);
929 SET_EXPECT(QI_IObjectWithSite);
930 SET_EXPECT(reportSuccess);
931 parse_script_a(parser, "Call CreateObject(\"Wine.Test\").reportSuccess()");
932 CHECK_CALLED(CreateInstance);
933 CHECK_CALLED(QI_IObjectWithSite);
934 CHECK_CALLED(reportSuccess);
936 IActiveScriptParse_Release(parser);
938 parser = create_script(TRUE);
939 object_with_site = &ObjectWithSite;
941 SET_EXPECT(Host_QS_SecMgr);
942 SET_EXPECT(ProcessUrlAction);
943 SET_EXPECT(CreateInstance);
944 SET_EXPECT(QueryCustomPolicy);
945 SET_EXPECT(QI_IObjectWithSite);
947 SET_EXPECT(reportSuccess);
948 parse_script_a(parser, "Call CreateObject(\"Wine.Test\").reportSuccess()");
949 CHECK_CALLED(Host_QS_SecMgr);
950 CHECK_CALLED(ProcessUrlAction);
951 CHECK_CALLED(CreateInstance);
952 CHECK_CALLED(QueryCustomPolicy);
953 CHECK_CALLED(QI_IObjectWithSite);
954 CHECK_CALLED(SetSite);
955 CHECK_CALLED(reportSuccess);
957 SetSite_hres = E_FAIL;
958 SET_EXPECT(ProcessUrlAction);
959 SET_EXPECT(CreateInstance);
960 SET_EXPECT(QueryCustomPolicy);
961 SET_EXPECT(QI_IObjectWithSite);
963 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
964 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
965 CHECK_CALLED(ProcessUrlAction);
966 CHECK_CALLED(CreateInstance);
967 CHECK_CALLED(QueryCustomPolicy);
968 CHECK_CALLED(QI_IObjectWithSite);
969 CHECK_CALLED(SetSite);
971 IActiveScriptParse_Release(parser);
974 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
980 RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
984 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
985 if(res != ERROR_SUCCESS)
989 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
993 return res == ERROR_SUCCESS;
996 static BOOL init_registry(BOOL init)
998 return init_key("Wine.Test\\CLSID", TESTOBJ_CLSID, init);
1001 static BOOL register_activex(void)
1006 if(!init_registry(TRUE)) {
1007 init_registry(FALSE);
1011 hres = CoRegisterClassObject(&CLSID_TestObj, (IUnknown *)&activex_cf,
1012 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
1013 ok(hres == S_OK, "Could not register script engine: %08x\n", hres);
1018 START_TEST(createobj)
1024 test_CreateObject();
1026 init_registry(FALSE);