wineps: Fix a couple of typos in the path painting function.
[wine/testsucceed.git] / dlls / vbscript / tests / createobj.c
blobb869d075f82712ff19644a23bd8d2b82e47071cf
1 /*
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
19 #include <stdio.h>
21 #define COBJMACROS
22 #define CONST_VTABLE
24 #include <ole2.h>
25 #include <dispex.h>
26 #include <activscp.h>
27 #include <objsafe.h>
28 #include <urlmon.h>
29 #include <mshtmhst.h>
31 #include "wine/test.h"
33 extern const CLSID CLSID_VBScript;
35 #define DEFINE_EXPECT(func) \
36 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
38 #define SET_EXPECT(func) \
39 expect_ ## func = TRUE
41 #define SET_CALLED(func) \
42 called_ ## func = TRUE
44 #define CHECK_EXPECT2(func) \
45 do { \
46 ok(expect_ ##func, "unexpected call " #func "\n"); \
47 called_ ## func = TRUE; \
48 }while(0)
50 #define CHECK_EXPECT(func) \
51 do { \
52 CHECK_EXPECT2(func); \
53 expect_ ## func = FALSE; \
54 }while(0)
56 #define CHECK_CALLED(func) \
57 do { \
58 ok(called_ ## func, "expected " #func "\n"); \
59 expect_ ## func = called_ ## func = FALSE; \
60 }while(0)
62 DEFINE_EXPECT(CreateInstance);
63 DEFINE_EXPECT(ProcessUrlAction);
64 DEFINE_EXPECT(QueryCustomPolicy);
65 DEFINE_EXPECT(reportSuccess);
66 DEFINE_EXPECT(Host_QS_SecMgr);
67 DEFINE_EXPECT(Caller_QS_SecMgr);
68 DEFINE_EXPECT(QI_IObjectWithSite);
69 DEFINE_EXPECT(SetSite);
71 static const WCHAR testW[] = {'t','e','s','t',0};
73 static HRESULT QS_SecMgr_hres;
74 static HRESULT ProcessUrlAction_hres;
75 static DWORD ProcessUrlAction_policy;
76 static HRESULT CreateInstance_hres;
77 static HRESULT QueryCustomPolicy_hres;
78 static DWORD QueryCustomPolicy_psize;
79 static DWORD QueryCustomPolicy_policy;
80 static HRESULT QI_IDispatch_hres;
81 static HRESULT SetSite_hres;
83 #define TESTOBJ_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}"
85 static const GUID CLSID_TestObj =
86 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
88 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
89 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
90 {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
92 #define DISPID_TEST_REPORTSUCCESS 0x1000
94 #define DISPID_GLOBAL_OK 0x2000
96 #define VB_E_CANNOT_CREATE_OBJ 0x800a01ad
98 static const char *debugstr_guid(REFIID riid)
100 static char buf[50];
102 sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
103 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
104 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
105 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
107 return buf;
110 static BSTR a2bstr(const char *str)
112 BSTR ret;
113 int len;
115 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
116 ret = SysAllocStringLen(NULL, len-1);
117 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
119 return ret;
122 static int strcmp_wa(LPCWSTR strw, const char *stra)
124 CHAR buf[512];
125 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
126 return lstrcmpA(buf, stra);
129 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID riid, void **ppv)
131 ok(0, "unexpected call\n");
132 return E_NOTIMPL;
135 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
137 return 2;
140 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
142 return 1;
145 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
147 IServiceProvider *sp;
148 HRESULT hres;
151 CHECK_EXPECT(SetSite);
152 ok(pUnkSite != NULL, "pUnkSite == NULL\n");
154 hres = IUnknown_QueryInterface(pUnkSite, &IID_IServiceProvider, (void**)&sp);
155 ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
156 IServiceProvider_Release(sp);
158 return SetSite_hres;
161 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, void **ppvSite)
163 ok(0, "unexpected call\n");
164 return E_NOTIMPL;
167 static const IObjectWithSiteVtbl ObjectWithSiteVtbl = {
168 ObjectWithSite_QueryInterface,
169 ObjectWithSite_AddRef,
170 ObjectWithSite_Release,
171 ObjectWithSite_SetSite,
172 ObjectWithSite_GetSite
175 static IObjectWithSite ObjectWithSite = { &ObjectWithSiteVtbl };
177 static IObjectWithSite *object_with_site;
179 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
181 *ppv = NULL;
183 if(IsEqualGUID(riid, &IID_IUnknown)) {
184 *ppv = iface;
185 }else if(IsEqualGUID(riid, &IID_IDispatch) || IsEqualGUID(riid, &IID_IDispatchEx)) {
186 if(FAILED(QI_IDispatch_hres))
187 return QI_IDispatch_hres;
188 *ppv = iface;
189 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
190 CHECK_EXPECT(QI_IObjectWithSite);
191 *ppv = object_with_site;
192 }else if(IsEqualGUID(&IID_IObjectSafety, riid)) {
193 ok(0, "Unexpected IID_IObjectSafety query\n");
196 return *ppv ? S_OK : E_NOINTERFACE;
199 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
201 return 2;
204 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
206 return 1;
209 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
211 ok(0, "unexpected call\n");
212 return E_NOTIMPL;
215 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
216 LCID lcid, ITypeInfo **ppTInfo)
218 ok(0, "unexpected call\n");
219 return E_NOTIMPL;
222 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
223 LPOLESTR *rgszNames, UINT cNames,
224 LCID lcid, DISPID *rgDispId)
226 ok(0, "unexpected call\n");
227 return E_NOTIMPL;
230 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
231 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
232 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
234 ok(0, "unexpected call\n");
235 return E_NOTIMPL;
238 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
240 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
241 return E_NOTIMPL;
244 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
246 ok(0, "unexpected call\n");
247 return E_NOTIMPL;
250 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
252 ok(0, "unexpected call\n");
253 return E_NOTIMPL;
256 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
258 ok(0, "unexpected call\n");
259 return E_NOTIMPL;
262 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
264 ok(0, "unexpected call\n");
265 return E_NOTIMPL;
268 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
270 ok(0, "unexpected call\n");
271 return E_NOTIMPL;
274 static HRESULT WINAPI Test_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
276 if(!strcmp_wa(bstrName, "reportSuccess")) {
277 ok(grfdex == fdexNameCaseInsensitive, "grfdex = %x\n", grfdex);
278 *pid = DISPID_TEST_REPORTSUCCESS;
279 return S_OK;
282 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
283 return E_NOTIMPL;
286 static HRESULT WINAPI Test_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
287 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
289 switch(id) {
290 case DISPID_TEST_REPORTSUCCESS:
291 CHECK_EXPECT(reportSuccess);
293 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
294 ok(pdp != NULL, "pdp == NULL\n");
295 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
296 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
297 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
298 ok(!pvarRes, "pvarRes != NULL\n");
299 ok(pei != NULL, "pei == NULL\n");
300 break;
302 default:
303 ok(0, "unexpected call\n");
304 return E_NOTIMPL;
307 return S_OK;
310 static IDispatchExVtbl testObjVtbl = {
311 DispatchEx_QueryInterface,
312 DispatchEx_AddRef,
313 DispatchEx_Release,
314 DispatchEx_GetTypeInfoCount,
315 DispatchEx_GetTypeInfo,
316 DispatchEx_GetIDsOfNames,
317 DispatchEx_Invoke,
318 Test_GetDispID,
319 Test_InvokeEx,
320 DispatchEx_DeleteMemberByName,
321 DispatchEx_DeleteMemberByDispID,
322 DispatchEx_GetMemberProperties,
323 DispatchEx_GetMemberName,
324 DispatchEx_GetNextDispID,
325 DispatchEx_GetNameSpaceParent
328 static IDispatchEx testObj = { &testObjVtbl };
330 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
332 if(!strcmp_wa(bstrName, "ok")) {
333 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
334 *pid = DISPID_GLOBAL_OK;
335 return S_OK;
338 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
339 return E_NOTIMPL;
342 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
343 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
345 switch(id) {
346 case DISPID_GLOBAL_OK:
347 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
348 ok(pdp != NULL, "pdp == NULL\n");
349 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
350 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
351 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
352 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
353 ok(pei != NULL, "pei == NULL\n");
355 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
356 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
357 ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
358 break;
360 default:
361 ok(0, "unexpected call\n");
362 return E_NOTIMPL;
365 return S_OK;
368 static IDispatchExVtbl globalObjVtbl = {
369 DispatchEx_QueryInterface,
370 DispatchEx_AddRef,
371 DispatchEx_Release,
372 DispatchEx_GetTypeInfoCount,
373 DispatchEx_GetTypeInfo,
374 DispatchEx_GetIDsOfNames,
375 DispatchEx_Invoke,
376 Global_GetDispID,
377 Global_InvokeEx,
378 DispatchEx_DeleteMemberByName,
379 DispatchEx_DeleteMemberByDispID,
380 DispatchEx_GetMemberProperties,
381 DispatchEx_GetMemberName,
382 DispatchEx_GetNextDispID,
383 DispatchEx_GetNameSpaceParent
386 static IDispatchEx globalObj = { &globalObjVtbl };
388 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
390 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
391 *ppv = iface;
392 return S_OK;
395 /* TODO: IClassFactoryEx */
396 *ppv = NULL;
397 return E_NOINTERFACE;
400 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
402 return 2;
405 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
407 return 1;
410 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
412 CHECK_EXPECT(CreateInstance);
414 ok(!outer, "outer = %p\n", outer);
415 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
417 if(SUCCEEDED(CreateInstance_hres))
418 *ppv = &testObj;
419 return CreateInstance_hres;
422 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
424 ok(0, "unexpected call\n");
425 return S_OK;
428 static const IClassFactoryVtbl ClassFactoryVtbl = {
429 ClassFactory_QueryInterface,
430 ClassFactory_AddRef,
431 ClassFactory_Release,
432 ClassFactory_CreateInstance,
433 ClassFactory_LockServer
436 static IClassFactory activex_cf = { &ClassFactoryVtbl };
438 static HRESULT WINAPI InternetHostSecurityManager_QueryInterface(IInternetHostSecurityManager *iface, REFIID riid, void **ppv)
440 ok(0, "unexpected call\n");
441 return E_NOINTERFACE;
444 static ULONG WINAPI InternetHostSecurityManager_AddRef(IInternetHostSecurityManager *iface)
446 return 2;
449 static ULONG WINAPI InternetHostSecurityManager_Release(IInternetHostSecurityManager *iface)
451 return 1;
454 static HRESULT WINAPI InternetHostSecurityManager_GetSecurityId(IInternetHostSecurityManager *iface, BYTE *pbSecurityId,
455 DWORD *pcbSecurityId, DWORD_PTR dwReserved)
457 ok(0, "unexpected call\n");
458 return E_NOTIMPL;
461 static HRESULT WINAPI InternetHostSecurityManager_ProcessUrlAction(IInternetHostSecurityManager *iface, DWORD dwAction,
462 BYTE *pPolicy, DWORD cbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved)
464 CHECK_EXPECT(ProcessUrlAction);
466 ok(dwAction == URLACTION_ACTIVEX_RUN, "dwAction = %x\n", dwAction);
467 ok(pPolicy != NULL, "pPolicy == NULL\n");
468 ok(cbPolicy == sizeof(DWORD), "cbPolicy = %d\n", cbPolicy);
469 ok(pContext != NULL, "pContext == NULL\n");
470 ok(cbContext == sizeof(GUID), "cbContext = %d\n", cbContext);
471 ok(IsEqualGUID(pContext, &CLSID_TestObj), "pContext = %s\n", debugstr_guid((const IID*)pContext));
472 ok(!dwFlags, "dwFlags = %x\n", dwFlags);
473 ok(!dwReserved, "dwReserved = %x\n", dwReserved);
475 if(SUCCEEDED(ProcessUrlAction_hres))
476 *(DWORD*)pPolicy = ProcessUrlAction_policy;
477 return ProcessUrlAction_hres;
480 static HRESULT WINAPI InternetHostSecurityManager_QueryCustomPolicy(IInternetHostSecurityManager *iface, REFGUID guidKey,
481 BYTE **ppPolicy, DWORD *pcbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwReserved)
483 const struct CONFIRMSAFETY *cs = (const struct CONFIRMSAFETY*)pContext;
484 DWORD *ret;
486 CHECK_EXPECT(QueryCustomPolicy);
488 ok(IsEqualGUID(&GUID_CUSTOM_CONFIRMOBJECTSAFETY, guidKey), "guidKey = %s\n", debugstr_guid(guidKey));
490 ok(ppPolicy != NULL, "ppPolicy == NULL\n");
491 ok(pcbPolicy != NULL, "pcbPolicy == NULL\n");
492 ok(pContext != NULL, "pContext == NULL\n");
493 ok(cbContext == sizeof(struct CONFIRMSAFETY), "cbContext = %d\n", cbContext);
494 ok(!dwReserved, "dwReserved = %x\n", dwReserved);
496 /* TODO: CLSID */
497 ok(cs->pUnk != NULL, "cs->pUnk == NULL\n");
498 ok(!cs->dwFlags, "dwFlags = %x\n", cs->dwFlags);
500 if(FAILED(QueryCustomPolicy_hres))
501 return QueryCustomPolicy_hres;
503 ret = CoTaskMemAlloc(QueryCustomPolicy_psize);
504 *ppPolicy = (BYTE*)ret;
505 *pcbPolicy = QueryCustomPolicy_psize;
506 memset(ret, 0, QueryCustomPolicy_psize);
507 if(QueryCustomPolicy_psize >= sizeof(DWORD))
508 *ret = QueryCustomPolicy_policy;
510 return QueryCustomPolicy_hres;
513 static const IInternetHostSecurityManagerVtbl InternetHostSecurityManagerVtbl = {
514 InternetHostSecurityManager_QueryInterface,
515 InternetHostSecurityManager_AddRef,
516 InternetHostSecurityManager_Release,
517 InternetHostSecurityManager_GetSecurityId,
518 InternetHostSecurityManager_ProcessUrlAction,
519 InternetHostSecurityManager_QueryCustomPolicy
522 static IInternetHostSecurityManager InternetHostSecurityManager = { &InternetHostSecurityManagerVtbl };
524 static IServiceProvider ServiceProvider;
526 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
528 ok(0, "unexpected call\n");
529 return E_NOINTERFACE;
532 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
534 return 2;
537 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
539 return 1;
542 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
543 REFGUID guidService, REFIID riid, void **ppv)
545 if(IsEqualGUID(&SID_GetCaller, guidService))
546 return E_NOINTERFACE;
548 if(IsEqualGUID(&SID_SInternetHostSecurityManager, guidService)) {
549 if(iface == &ServiceProvider)
550 CHECK_EXPECT(Host_QS_SecMgr);
551 else
552 CHECK_EXPECT(Caller_QS_SecMgr);
553 ok(IsEqualGUID(&IID_IInternetHostSecurityManager, riid), "unexpected riid %s\n", debugstr_guid(riid));
554 if(SUCCEEDED(QS_SecMgr_hres))
555 *ppv = &InternetHostSecurityManager;
556 return QS_SecMgr_hres;
559 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
560 return E_NOINTERFACE;
563 static IServiceProviderVtbl ServiceProviderVtbl = {
564 ServiceProvider_QueryInterface,
565 ServiceProvider_AddRef,
566 ServiceProvider_Release,
567 ServiceProvider_QueryService
570 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
572 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
574 if(IsEqualGUID(&IID_IUnknown, riid)) {
575 *ppv = iface;
576 }else if(IsEqualGUID(&IID_IActiveScriptSite, riid)) {
577 *ppv = iface;
578 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
579 *ppv = &ServiceProvider;
580 }else {
581 *ppv = NULL;
582 return E_NOINTERFACE;
585 IUnknown_AddRef((IUnknown*)*ppv);
586 return S_OK;
589 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
591 return 2;
594 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
596 return 1;
599 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
601 *plcid = GetUserDefaultLCID();
602 return S_OK;
605 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
606 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
608 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
609 ok(!ppti, "ppti != NULL\n");
610 ok(!strcmp_wa(pstrName, "test"), "pstrName = %s\n", wine_dbgstr_w(pstrName));
612 *ppiunkItem = (IUnknown*)&globalObj;
613 return S_OK;
616 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
618 return E_NOTIMPL;
621 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
622 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
624 return E_NOTIMPL;
627 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
629 return E_NOTIMPL;
632 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
634 return E_NOTIMPL;
637 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
639 return E_NOTIMPL;
642 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
644 return E_NOTIMPL;
647 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
648 ActiveScriptSite_QueryInterface,
649 ActiveScriptSite_AddRef,
650 ActiveScriptSite_Release,
651 ActiveScriptSite_GetLCID,
652 ActiveScriptSite_GetItemInfo,
653 ActiveScriptSite_GetDocVersionString,
654 ActiveScriptSite_OnScriptTerminate,
655 ActiveScriptSite_OnStateChange,
656 ActiveScriptSite_OnScriptError,
657 ActiveScriptSite_OnEnterScript,
658 ActiveScriptSite_OnLeaveScript
661 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
663 static void set_safety_options(IUnknown *unk, BOOL use_sec_mgr)
665 IObjectSafety *safety;
666 DWORD supported, enabled, options_all, options_set;
667 HRESULT hres;
669 hres = IUnknown_QueryInterface(unk, &IID_IObjectSafety, (void**)&safety);
670 ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
671 if(FAILED(hres))
672 return;
674 options_all = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
675 if(use_sec_mgr)
676 options_set = options_all;
677 else
678 options_set = INTERFACE_USES_DISPEX;
680 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, options_all, options_set);
681 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
683 supported = enabled = 0xdeadbeef;
684 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
685 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
686 ok(supported == options_all, "supported=%x, expected %x\n", supported, options_all);
687 ok(enabled == options_set, "enabled=%x, expected %x\n", enabled, options_set);
689 IObjectSafety_Release(safety);
692 #define parse_script_a(p,s) _parse_script_a(__LINE__,p,s)
693 static void _parse_script_a(unsigned line, IActiveScriptParse *parser, const char *script)
695 BSTR str;
696 HRESULT hres;
698 str = a2bstr(script);
699 hres = IActiveScriptParse64_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
700 SysFreeString(str);
701 ok_(__FILE__,line)(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
704 static HRESULT parse_script_ae(IActiveScriptParse *parser, const char *script)
706 BSTR str;
707 HRESULT hres;
709 str = a2bstr(script);
710 hres = IActiveScriptParse64_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
711 SysFreeString(str);
713 return hres;
716 static IActiveScriptParse *create_script(BOOL use_sec_mgr)
718 IActiveScriptParse *parser;
719 IActiveScript *script;
720 HRESULT hres;
722 QS_SecMgr_hres = S_OK;
723 ProcessUrlAction_hres = S_OK;
724 ProcessUrlAction_policy = URLPOLICY_ALLOW;
725 CreateInstance_hres = S_OK;
726 QueryCustomPolicy_hres = S_OK;
727 QueryCustomPolicy_psize = sizeof(DWORD);
728 QueryCustomPolicy_policy = URLPOLICY_ALLOW;
729 QI_IDispatch_hres = S_OK;
730 SetSite_hres = S_OK;
732 hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
733 &IID_IActiveScript, (void**)&script);
734 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
735 if(FAILED(hres))
736 return NULL;
738 set_safety_options((IUnknown*)script, use_sec_mgr);
740 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser);
741 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
743 hres = IActiveScriptParse64_InitNew(parser);
744 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
746 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
747 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
749 hres = IActiveScript_AddNamedItem(script, testW,
750 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
751 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
753 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED);
754 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
756 IActiveScript_Release(script);
758 return parser;
761 static void test_CreateObject(void)
763 IActiveScriptParse *parser;
764 HRESULT hres;
766 parser = create_script(TRUE);
768 SET_EXPECT(Host_QS_SecMgr);
769 SET_EXPECT(ProcessUrlAction);
770 SET_EXPECT(CreateInstance);
771 SET_EXPECT(QueryCustomPolicy);
772 SET_EXPECT(QI_IObjectWithSite);
773 SET_EXPECT(reportSuccess);
774 parse_script_a(parser, "Call CreateObject(\"Wine.Test\").reportSuccess()");
775 CHECK_CALLED(Host_QS_SecMgr);
776 CHECK_CALLED(ProcessUrlAction);
777 CHECK_CALLED(CreateInstance);
778 CHECK_CALLED(QueryCustomPolicy);
779 CHECK_CALLED(QI_IObjectWithSite);
780 CHECK_CALLED(reportSuccess);
782 IUnknown_Release(parser);
784 parser = create_script(TRUE);
786 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.TestABC\")");
787 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
789 IUnknown_Release(parser);
791 parser = create_script(TRUE);
792 QS_SecMgr_hres = E_NOINTERFACE;
794 SET_EXPECT(Host_QS_SecMgr);
795 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
796 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
797 CHECK_CALLED(Host_QS_SecMgr);
799 IUnknown_Release(parser);
801 parser = create_script(TRUE);
802 ProcessUrlAction_hres = E_FAIL;
804 SET_EXPECT(Host_QS_SecMgr);
805 SET_EXPECT(ProcessUrlAction);
806 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
807 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
808 CHECK_CALLED(Host_QS_SecMgr);
809 CHECK_CALLED(ProcessUrlAction);
811 IUnknown_Release(parser);
813 parser = create_script(TRUE);
814 ProcessUrlAction_policy = URLPOLICY_DISALLOW;
816 SET_EXPECT(Host_QS_SecMgr);
817 SET_EXPECT(ProcessUrlAction);
818 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
819 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
820 CHECK_CALLED(Host_QS_SecMgr);
821 CHECK_CALLED(ProcessUrlAction);
823 IUnknown_Release(parser);
825 parser = create_script(TRUE);
826 CreateInstance_hres = E_FAIL;
828 SET_EXPECT(Host_QS_SecMgr);
829 SET_EXPECT(ProcessUrlAction);
830 SET_EXPECT(CreateInstance);
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);
835 CHECK_CALLED(CreateInstance);
837 IUnknown_Release(parser);
839 parser = create_script(TRUE);
840 QueryCustomPolicy_hres = E_FAIL;
842 SET_EXPECT(Host_QS_SecMgr);
843 SET_EXPECT(ProcessUrlAction);
844 SET_EXPECT(CreateInstance);
845 SET_EXPECT(QueryCustomPolicy);
846 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
847 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
848 CHECK_CALLED(Host_QS_SecMgr);
849 CHECK_CALLED(ProcessUrlAction);
850 CHECK_CALLED(CreateInstance);
851 CHECK_CALLED(QueryCustomPolicy);
853 IUnknown_Release(parser);
855 parser = create_script(TRUE);
856 QueryCustomPolicy_psize = 6;
858 SET_EXPECT(Host_QS_SecMgr);
859 SET_EXPECT(ProcessUrlAction);
860 SET_EXPECT(CreateInstance);
861 SET_EXPECT(QueryCustomPolicy);
862 SET_EXPECT(QI_IObjectWithSite);
863 SET_EXPECT(reportSuccess);
864 parse_script_a(parser, "Call CreateObject(\"Wine.Test\").reportSuccess()");
865 CHECK_CALLED(Host_QS_SecMgr);
866 CHECK_CALLED(ProcessUrlAction);
867 CHECK_CALLED(CreateInstance);
868 CHECK_CALLED(QueryCustomPolicy);
869 CHECK_CALLED(QI_IObjectWithSite);
870 CHECK_CALLED(reportSuccess);
872 IUnknown_Release(parser);
874 parser = create_script(TRUE);
875 QueryCustomPolicy_policy = URLPOLICY_DISALLOW;
877 SET_EXPECT(Host_QS_SecMgr);
878 SET_EXPECT(ProcessUrlAction);
879 SET_EXPECT(CreateInstance);
880 SET_EXPECT(QueryCustomPolicy);
881 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
882 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
883 CHECK_CALLED(Host_QS_SecMgr);
884 CHECK_CALLED(ProcessUrlAction);
885 CHECK_CALLED(CreateInstance);
886 CHECK_CALLED(QueryCustomPolicy);
888 QueryCustomPolicy_psize = 6;
890 SET_EXPECT(ProcessUrlAction);
891 SET_EXPECT(CreateInstance);
892 SET_EXPECT(QueryCustomPolicy);
893 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
894 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
895 CHECK_CALLED(ProcessUrlAction);
896 CHECK_CALLED(CreateInstance);
897 CHECK_CALLED(QueryCustomPolicy);
899 QueryCustomPolicy_policy = URLPOLICY_ALLOW;
900 QueryCustomPolicy_psize = 3;
902 SET_EXPECT(ProcessUrlAction);
903 SET_EXPECT(CreateInstance);
904 SET_EXPECT(QueryCustomPolicy);
905 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
906 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
907 CHECK_CALLED(ProcessUrlAction);
908 CHECK_CALLED(CreateInstance);
909 CHECK_CALLED(QueryCustomPolicy);
911 IUnknown_Release(parser);
913 parser = create_script(FALSE);
915 SET_EXPECT(CreateInstance);
916 SET_EXPECT(QI_IObjectWithSite);
917 SET_EXPECT(reportSuccess);
918 parse_script_a(parser, "Call CreateObject(\"Wine.Test\").reportSuccess()");
919 CHECK_CALLED(CreateInstance);
920 CHECK_CALLED(QI_IObjectWithSite);
921 CHECK_CALLED(reportSuccess);
923 IUnknown_Release(parser);
925 parser = create_script(TRUE);
926 object_with_site = &ObjectWithSite;
928 SET_EXPECT(Host_QS_SecMgr);
929 SET_EXPECT(ProcessUrlAction);
930 SET_EXPECT(CreateInstance);
931 SET_EXPECT(QueryCustomPolicy);
932 SET_EXPECT(QI_IObjectWithSite);
933 SET_EXPECT(SetSite);
934 SET_EXPECT(reportSuccess);
935 parse_script_a(parser, "Call CreateObject(\"Wine.Test\").reportSuccess()");
936 CHECK_CALLED(Host_QS_SecMgr);
937 CHECK_CALLED(ProcessUrlAction);
938 CHECK_CALLED(CreateInstance);
939 CHECK_CALLED(QueryCustomPolicy);
940 CHECK_CALLED(QI_IObjectWithSite);
941 CHECK_CALLED(SetSite);
942 CHECK_CALLED(reportSuccess);
944 SetSite_hres = E_FAIL;
945 SET_EXPECT(ProcessUrlAction);
946 SET_EXPECT(CreateInstance);
947 SET_EXPECT(QueryCustomPolicy);
948 SET_EXPECT(QI_IObjectWithSite);
949 SET_EXPECT(SetSite);
950 hres = parse_script_ae(parser, "Call CreateObject(\"Wine.Test\")");
951 ok(hres == VB_E_CANNOT_CREATE_OBJ, "hres = %08x\n", hres);
952 CHECK_CALLED(ProcessUrlAction);
953 CHECK_CALLED(CreateInstance);
954 CHECK_CALLED(QueryCustomPolicy);
955 CHECK_CALLED(QI_IObjectWithSite);
956 CHECK_CALLED(SetSite);
958 IUnknown_Release(parser);
961 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
963 HKEY hkey;
964 DWORD res;
966 if(!init) {
967 RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
968 return TRUE;
971 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
972 if(res != ERROR_SUCCESS)
973 return FALSE;
975 if(def_value)
976 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
978 RegCloseKey(hkey);
980 return res == ERROR_SUCCESS;
983 static BOOL init_registry(BOOL init)
985 return init_key("Wine.Test\\CLSID", TESTOBJ_CLSID, init);
988 static BOOL register_activex(void)
990 DWORD regid;
991 HRESULT hres;
993 if(!init_registry(TRUE)) {
994 init_registry(FALSE);
995 return FALSE;
998 hres = CoRegisterClassObject(&CLSID_TestObj, (IUnknown *)&activex_cf,
999 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
1000 ok(hres == S_OK, "Could not register script engine: %08x\n", hres);
1002 return TRUE;
1005 START_TEST(createobj)
1007 CoInitialize(NULL);
1009 register_activex();
1011 test_CreateObject();
1013 init_registry(FALSE);
1015 CoUninitialize();