2 * Copyright 2016 Nikolay Sivov 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"
32 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
34 #define TESTSCRIPT_CLSID "{178fc164-f585-4e24-9c13-4bb7faf80746}"
35 static const GUID CLSID_TestScript
=
36 {0x178fc164,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x07,0x46}};
37 static const WCHAR vbW
[] = {'V','B','S','c','r','i','p','t',0};
41 #define CTXARG_T DWORDLONG
42 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
43 #define IActiveScriptSiteDebug_Release IActiveScriptSiteDebug64_Release
47 #define CTXARG_T DWORD
48 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
49 #define IActiveScriptSiteDebug_Release IActiveScriptSiteDebug32_Release
53 #define DEFINE_EXPECT(func) \
54 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
56 #define SET_EXPECT(func) \
57 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
59 #define CHECK_EXPECT2(func) \
61 ok(expect_ ##func, "unexpected call " #func "\n"); \
62 called_ ## func = TRUE; \
65 #define CHECK_EXPECT(func) \
67 CHECK_EXPECT2(func); \
68 expect_ ## func = FALSE; \
71 #define CHECK_CALLED(func) \
73 ok(called_ ## func, "expected " #func "\n"); \
74 expect_ ## func = called_ ## func = FALSE; \
77 #define CHECK_CALLED_BROKEN(func) \
79 ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
80 expect_ ## func = called_ ## func = FALSE; \
83 #define CHECK_NOT_CALLED(func) \
85 ok(!called_ ## func, "unexpected " #func "\n"); \
86 expect_ ## func = called_ ## func = FALSE; \
89 #define CLEAR_CALLED(func) \
90 expect_ ## func = called_ ## func = FALSE
92 DEFINE_EXPECT(CreateInstance
);
93 DEFINE_EXPECT(SetInterfaceSafetyOptions
);
94 DEFINE_EXPECT(InitNew
);
96 DEFINE_EXPECT(QI_IDispatchEx
);
97 DEFINE_EXPECT(GetIDsOfNames
);
98 DEFINE_EXPECT(Invoke
);
99 DEFINE_EXPECT(InvokeEx
);
100 DEFINE_EXPECT(SetScriptSite
);
101 DEFINE_EXPECT(QI_IActiveScriptParse
);
102 DEFINE_EXPECT(SetScriptState_INITIALIZED
);
103 DEFINE_EXPECT(SetScriptState_STARTED
);
104 DEFINE_EXPECT(ParseScriptText
);
105 DEFINE_EXPECT(AddNamedItem
);
106 DEFINE_EXPECT(GetScriptDispatch
);
108 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
109 static void _expect_ref(IUnknown
* obj
, ULONG ref
, int line
)
112 IUnknown_AddRef(obj
);
113 rc
= IUnknown_Release(obj
);
114 ok_(__FILE__
,line
)(rc
== ref
, "expected refcount %d, got %d\n", ref
, rc
);
117 static IActiveScriptSite
*site
;
118 static SCRIPTSTATE state
;
120 static HRESULT WINAPI
ActiveScriptParse_QueryInterface(IActiveScriptParse
*iface
, REFIID riid
, void **ppv
)
123 ok(0, "unexpected call\n");
124 return E_NOINTERFACE
;
127 static ULONG WINAPI
ActiveScriptParse_AddRef(IActiveScriptParse
*iface
)
132 static ULONG WINAPI
ActiveScriptParse_Release(IActiveScriptParse
*iface
)
137 static HRESULT WINAPI
ActiveScriptParse_InitNew(IActiveScriptParse
*iface
)
139 CHECK_EXPECT(InitNew
);
143 static HRESULT WINAPI
ActiveScriptParse_AddScriptlet(IActiveScriptParse
*iface
,
144 LPCOLESTR pstrDefaultName
, LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
,
145 LPCOLESTR pstrSubItemName
, LPCOLESTR pstrEventName
, LPCOLESTR pstrDelimiter
,
146 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
,
147 BSTR
*pbstrName
, EXCEPINFO
*pexcepinfo
)
149 ok(0, "unexpected call\n");
153 static DWORD parse_flags
= 0;
155 static HRESULT WINAPI
ActiveScriptParse_ParseScriptText(IActiveScriptParse
*iface
,
156 LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
, IUnknown
*punkContext
,
157 LPCOLESTR pstrDelimiter
, CTXARG_T dwSourceContextCookie
, ULONG ulStartingLine
,
158 DWORD dwFlags
, VARIANT
*pvarResult
, EXCEPINFO
*pexcepinfo
)
160 ok(!!pstrCode
, "got wrong pointer: %p.\n", pstrCode
);
161 ok(!pstrItemName
, "got wrong pointer: %p.\n", pstrItemName
);
162 ok(!punkContext
, "got wrong pointer: %p.\n", punkContext
);
163 ok(!pstrDelimiter
, "got wrong pointer: %p.\n", pstrDelimiter
);
164 ok(!dwSourceContextCookie
, "got wrong value: %s.\n", wine_dbgstr_longlong(dwSourceContextCookie
));
165 ok(ulStartingLine
== 1, "got wrong value: %d.\n", ulStartingLine
);
166 ok(!!pexcepinfo
, "got wrong pointer: %p.\n", pexcepinfo
);
167 ok(dwFlags
== parse_flags
, "got wrong flags: %x.\n", dwFlags
);
168 if (parse_flags
== SCRIPTTEXT_ISEXPRESSION
)
169 ok(!!pvarResult
, "got wrong pointer: %p.\n", pvarResult
);
171 ok(!pvarResult
, "got wrong pointer: %p.\n", pvarResult
);
173 CHECK_EXPECT(ParseScriptText
);
177 static const IActiveScriptParseVtbl ActiveScriptParseVtbl
= {
178 ActiveScriptParse_QueryInterface
,
179 ActiveScriptParse_AddRef
,
180 ActiveScriptParse_Release
,
181 ActiveScriptParse_InitNew
,
182 ActiveScriptParse_AddScriptlet
,
183 ActiveScriptParse_ParseScriptText
186 static IActiveScriptParse ActiveScriptParse
= { &ActiveScriptParseVtbl
};
188 static HRESULT WINAPI
ObjectSafety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
191 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid
));
192 return E_NOINTERFACE
;
195 static ULONG WINAPI
ObjectSafety_AddRef(IObjectSafety
*iface
)
200 static ULONG WINAPI
ObjectSafety_Release(IObjectSafety
*iface
)
205 static HRESULT WINAPI
ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
206 DWORD
*pdwSupportedOptions
, DWORD
*pdwEnabledOptions
)
208 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid
));
212 static HRESULT WINAPI
ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
213 DWORD mask
, DWORD options
)
215 CHECK_EXPECT(SetInterfaceSafetyOptions
);
217 ok(IsEqualGUID(&IID_IActiveScriptParse
, riid
), "unexpected riid %s\n", wine_dbgstr_guid(riid
));
219 ok(mask
== INTERFACESAFE_FOR_UNTRUSTED_DATA
, "option mask = %x\n", mask
);
220 ok(options
== 0, "options = %x\n", options
);
225 static const IObjectSafetyVtbl ObjectSafetyVtbl
= {
226 ObjectSafety_QueryInterface
,
228 ObjectSafety_Release
,
229 ObjectSafety_GetInterfaceSafetyOptions
,
230 ObjectSafety_SetInterfaceSafetyOptions
233 static IObjectSafety ObjectSafety
= { &ObjectSafetyVtbl
};
235 static BOOL DispatchEx_available
= FALSE
;
236 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
240 if (IsEqualGUID(&IID_IDispatchEx
, riid
))
242 CHECK_EXPECT(QI_IDispatchEx
);
243 if (DispatchEx_available
)
248 return E_NOINTERFACE
;
251 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid
));
252 return E_NOINTERFACE
;
255 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
260 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
265 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
267 ok(0, "unexpected call\n");
271 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
273 ok(0, "unexpected call\n");
277 static BSTR Dispatch_expected_name
;
278 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
279 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
281 CHECK_EXPECT(GetIDsOfNames
);
282 ok(IsEqualGUID(&IID_NULL
, riid
), "unexpected riid %s\n", wine_dbgstr_guid(riid
));
283 ok(lcid
== LOCALE_USER_DEFAULT
, "unexpected lcid %u\n", lcid
);
284 ok(cNames
== 1, "unexpected cNames %u\n", cNames
);
285 ok(Dispatch_expected_name
&& !lstrcmpW(rgszNames
[0], Dispatch_expected_name
),
286 "unexpected name %s (expected %s).\n", wine_dbgstr_w(rgszNames
[0]), wine_dbgstr_w(Dispatch_expected_name
));
288 *rgDispId
= 0xdeadbeef;
292 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
, REFIID riid
, LCID lcid
,
293 WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
295 CHECK_EXPECT(Invoke
);
296 ok(IsEqualGUID(&IID_NULL
, riid
), "unexpected riid %s.\n", wine_dbgstr_guid(riid
));
297 ok(lcid
== LOCALE_USER_DEFAULT
, "unexpected lcid %u.\n", lcid
);
298 ok(wFlags
== DISPATCH_METHOD
, "unexpected wFlags %u.\n", wFlags
);
299 ok(dispIdMember
== 0xdeadbeef, "unexpected dispIdMember %d.\n", dispIdMember
);
300 ok(pDispParams
->cNamedArgs
== 0, "unexpected number of named args %u.\n", pDispParams
->cNamedArgs
);
301 ok(!pDispParams
->rgdispidNamedArgs
, "unexpected named args array %p\n", pDispParams
->rgdispidNamedArgs
);
302 ok(pDispParams
->cArgs
== 2, "unexpected number of args %u.\n", pDispParams
->cArgs
);
303 ok(!!pDispParams
->rgvarg
, "unexpected NULL rgvarg.\n");
304 if (pDispParams
->rgvarg
&& pDispParams
->cArgs
>= 2)
306 ok(V_VT(pDispParams
->rgvarg
+ 1) == VT_I4
&& V_I4(pDispParams
->rgvarg
+ 1) == 10,
307 "unexpected first parameter V_VT = %d, V_I4 = %d.\n",
308 V_VT(pDispParams
->rgvarg
+ 1), V_I4(pDispParams
->rgvarg
+ 1));
309 ok(V_VT(pDispParams
->rgvarg
) == VT_I4
&& V_I4(pDispParams
->rgvarg
) == 3,
310 "unexpected second parameter V_VT = %d, V_I4 = %d.\n",
311 V_VT(pDispParams
->rgvarg
), V_I4(pDispParams
->rgvarg
));
314 V_VT(pVarResult
) = VT_R8
;
315 V_R8(pVarResult
) = 4.2;
319 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
321 ok(0, "unexpected call\n");
325 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
,
326 DISPPARAMS
*pdp
, VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
328 CHECK_EXPECT(InvokeEx
);
329 ok(lcid
== LOCALE_USER_DEFAULT
, "unexpected lcid %u.\n", lcid
);
330 ok(wFlags
== DISPATCH_METHOD
, "unexpected wFlags %u.\n", wFlags
);
331 ok(id
== 0xdeadbeef, "unexpected id %d.\n", id
);
332 ok(pdp
->cNamedArgs
== 0, "unexpected number of named args %u.\n", pdp
->cNamedArgs
);
333 ok(!pdp
->rgdispidNamedArgs
, "unexpected named args array %p.\n", pdp
->rgdispidNamedArgs
);
334 ok(pdp
->cArgs
== 2, "unexpected number of args %u.\n", pdp
->cArgs
);
335 ok(!!pdp
->rgvarg
, "unexpected NULL rgvarg.\n");
336 if (pdp
->rgvarg
&& pdp
->cArgs
>= 2)
338 ok(V_VT(pdp
->rgvarg
+ 1) == VT_I4
&& V_I4(pdp
->rgvarg
+ 1) == 10,
339 "unexpected first parameter V_VT = %d, V_I4 = %d.\n",
340 V_VT(pdp
->rgvarg
+ 1), V_I4(pdp
->rgvarg
+ 1));
341 ok(V_VT(pdp
->rgvarg
) == VT_I4
&& V_I4(pdp
->rgvarg
) == 3,
342 "unexpected second parameter V_VT = %d, V_I4 = %d.\n",
343 V_VT(pdp
->rgvarg
), V_I4(pdp
->rgvarg
));
346 V_VT(pvarRes
) = VT_I2
;
351 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
353 ok(0, "unexpected call\n");
357 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
359 ok(0, "unexpected call\n");
363 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
,
366 ok(0, "unexpected call\n");
370 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
372 ok(0, "unexpected call\n");
376 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
378 ok(0, "unexpected call\n");
382 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
384 ok(0, "unexpected call\n");
388 static const IDispatchExVtbl DispatchExVtbl
= {
389 DispatchEx_QueryInterface
,
392 DispatchEx_GetTypeInfoCount
,
393 DispatchEx_GetTypeInfo
,
394 DispatchEx_GetIDsOfNames
,
396 DispatchEx_GetDispID
,
398 DispatchEx_DeleteMemberByName
,
399 DispatchEx_DeleteMemberByDispID
,
400 DispatchEx_GetMemberProperties
,
401 DispatchEx_GetMemberName
,
402 DispatchEx_GetNextDispID
,
403 DispatchEx_GetNameSpaceParent
406 static IDispatchEx DispatchEx
= { &DispatchExVtbl
};
408 static HRESULT WINAPI
ActiveScript_QueryInterface(IActiveScript
*iface
, REFIID riid
, void **ppv
)
412 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IActiveScript
, riid
)) {
417 if(IsEqualGUID(&IID_IObjectSafety
, riid
)) {
418 *ppv
= &ObjectSafety
;
422 if(IsEqualGUID(&IID_IActiveScriptParse
, riid
)) {
423 CHECK_EXPECT(QI_IActiveScriptParse
);
424 *ppv
= &ActiveScriptParse
;
428 if(IsEqualGUID(&IID_IActiveScriptGarbageCollector
, riid
))
429 return E_NOINTERFACE
;
431 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid
));
432 return E_NOINTERFACE
;
435 static ULONG WINAPI
ActiveScript_AddRef(IActiveScript
*iface
)
440 static ULONG WINAPI
ActiveScript_Release(IActiveScript
*iface
)
445 static HRESULT WINAPI
ActiveScript_SetScriptSite(IActiveScript
*iface
, IActiveScriptSite
*pass
)
447 IActiveScriptSiteInterruptPoll
*poll
;
448 IActiveScriptSiteWindow
*window
;
449 IActiveScriptSiteDebug
*debug
;
450 IServiceProvider
*service
;
451 ICanHandleException
*canexception
;
455 CHECK_EXPECT(SetScriptSite
);
457 ok(pass
!= NULL
, "pass == NULL\n");
459 hres
= IActiveScriptSite_QueryInterface(pass
, &IID_IActiveScriptSiteInterruptPoll
, (void**)&poll
);
460 ok(hres
== E_NOINTERFACE
, "Got IActiveScriptSiteInterruptPoll interface: %08x\n", hres
);
462 hres
= IActiveScriptSite_GetLCID(pass
, &lcid
);
463 ok(hres
== S_OK
, "GetLCID failed: %08x\n", hres
);
465 hres
= IActiveScriptSite_OnStateChange(pass
, (state
= SCRIPTSTATE_INITIALIZED
));
466 ok(hres
== E_NOTIMPL
, "OnStateChange failed: %08x\n", hres
);
468 hres
= IActiveScriptSite_QueryInterface(pass
, &IID_IActiveScriptSiteDebug
, (void**)&debug
);
469 ok(hres
== E_NOINTERFACE
, "Got IActiveScriptSiteDebug interface: %08x\n", hres
);
471 hres
= IActiveScriptSite_QueryInterface(pass
, &IID_ICanHandleException
, (void**)&canexception
);
472 ok(hres
== E_NOINTERFACE
, "Got IID_ICanHandleException interface: %08x\n", hres
);
474 hres
= IActiveScriptSite_QueryInterface(pass
, &IID_IServiceProvider
, (void**)&service
);
475 ok(hres
== S_OK
, "Could not get IServiceProvider interface: %08x\n", hres
);
476 IServiceProvider_Release(service
);
478 hres
= IActiveScriptSite_QueryInterface(pass
, &IID_IActiveScriptSiteWindow
, (void**)&window
);
479 ok(hres
== S_OK
, "Could not get IActiveScriptSiteWindow interface: %08x\n", hres
);
480 IActiveScriptSiteWindow_Release(window
);
483 IActiveScriptSite_Release(site
);
485 IActiveScriptSite_AddRef(site
);
490 static HRESULT WINAPI
ActiveScript_GetScriptSite(IActiveScript
*iface
, REFIID riid
,
493 ok(0, "unexpected call\n");
497 static HRESULT WINAPI
ActiveScript_SetScriptState(IActiveScript
*iface
, SCRIPTSTATE ss
)
499 if (ss
== SCRIPTSTATE_INITIALIZED
) {
500 CHECK_EXPECT(SetScriptState_INITIALIZED
);
503 else if (ss
== SCRIPTSTATE_STARTED
) {
504 CHECK_EXPECT(SetScriptState_STARTED
);
508 ok(0, "unexpected call, state %u\n", ss
);
513 static HRESULT WINAPI
ActiveScript_GetScriptState(IActiveScript
*iface
, SCRIPTSTATE
*pssState
)
515 ok(0, "unexpected call\n");
519 static HRESULT WINAPI
ActiveScript_Close(IActiveScript
*iface
)
525 static HRESULT WINAPI
ActiveScript_AddNamedItem(IActiveScript
*iface
, LPCOLESTR name
, DWORD flags
)
527 static const WCHAR oW
[] = {'o',0};
528 CHECK_EXPECT(AddNamedItem
);
529 ok(!lstrcmpW(name
, oW
), "got name %s\n", wine_dbgstr_w(name
));
530 ok(flags
== (SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|SCRIPTITEM_GLOBALMEMBERS
), "got flags %#x\n", flags
);
534 static HRESULT WINAPI
ActiveScript_AddTypeLib(IActiveScript
*iface
, REFGUID rguidTypeLib
,
535 DWORD dwMajor
, DWORD dwMinor
, DWORD dwFlags
)
537 ok(0, "unexpected call\n");
541 static HRESULT WINAPI
ActiveScript_GetScriptDispatch(IActiveScript
*iface
, LPCOLESTR pstrItemName
,
544 CHECK_EXPECT(GetScriptDispatch
);
545 ok(!pstrItemName
, "pstrItemName not NULL, got %s.\n", wine_dbgstr_w(pstrItemName
));
547 *ppdisp
= (IDispatch
*)&DispatchEx
;
552 static HRESULT WINAPI
ActiveScript_GetCurrentScriptThreadID(IActiveScript
*iface
,
553 SCRIPTTHREADID
*pstridThread
)
555 ok(0, "unexpected call\n");
559 static HRESULT WINAPI
ActiveScript_GetScriptThreadID(IActiveScript
*iface
,
560 DWORD dwWin32ThreadId
, SCRIPTTHREADID
*pstidThread
)
562 ok(0, "unexpected call\n");
566 static HRESULT WINAPI
ActiveScript_GetScriptThreadState(IActiveScript
*iface
,
567 SCRIPTTHREADID stidThread
, SCRIPTTHREADSTATE
*pstsState
)
569 ok(0, "unexpected call\n");
573 static HRESULT WINAPI
ActiveScript_InterruptScriptThread(IActiveScript
*iface
,
574 SCRIPTTHREADID stidThread
, const EXCEPINFO
*pexcepinfo
, DWORD dwFlags
)
576 ok(0, "unexpected call\n");
580 static HRESULT WINAPI
ActiveScript_Clone(IActiveScript
*iface
, IActiveScript
**ppscript
)
582 ok(0, "unexpected call\n");
586 static const IActiveScriptVtbl ActiveScriptVtbl
= {
587 ActiveScript_QueryInterface
,
589 ActiveScript_Release
,
590 ActiveScript_SetScriptSite
,
591 ActiveScript_GetScriptSite
,
592 ActiveScript_SetScriptState
,
593 ActiveScript_GetScriptState
,
595 ActiveScript_AddNamedItem
,
596 ActiveScript_AddTypeLib
,
597 ActiveScript_GetScriptDispatch
,
598 ActiveScript_GetCurrentScriptThreadID
,
599 ActiveScript_GetScriptThreadID
,
600 ActiveScript_GetScriptThreadState
,
601 ActiveScript_InterruptScriptThread
,
605 static IActiveScript ActiveScript
= { &ActiveScriptVtbl
};
607 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
611 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IClassFactory
, riid
)) {
616 if(IsEqualGUID(&IID_IMarshal
, riid
))
617 return E_NOINTERFACE
;
619 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid
));
620 return E_NOINTERFACE
;
623 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
628 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
633 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **ppv
)
635 CHECK_EXPECT(CreateInstance
);
637 ok(!outer
, "outer = %p\n", outer
);
638 ok(IsEqualGUID(&IID_IActiveScript
, riid
), "unexpected riid %s\n", wine_dbgstr_guid(riid
));
639 *ppv
= &ActiveScript
;
644 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
646 ok(0, "unexpected call\n");
650 static const IClassFactoryVtbl ClassFactoryVtbl
= {
651 ClassFactory_QueryInterface
,
653 ClassFactory_Release
,
654 ClassFactory_CreateInstance
,
655 ClassFactory_LockServer
658 static IClassFactory script_cf
= { &ClassFactoryVtbl
};
660 static BOOL
init_key(const char *key_name
, const char *def_value
, BOOL init
)
666 RegDeleteKeyA(HKEY_CLASSES_ROOT
, key_name
);
670 res
= RegCreateKeyA(HKEY_CLASSES_ROOT
, key_name
, &hkey
);
671 if(res
!= ERROR_SUCCESS
)
675 res
= RegSetValueA(hkey
, NULL
, REG_SZ
, def_value
, strlen(def_value
));
679 return res
== ERROR_SUCCESS
;
682 static BOOL
init_registry(BOOL init
)
684 return init_key("TestScript\\CLSID", TESTSCRIPT_CLSID
, init
)
685 && init_key("CLSID\\"TESTSCRIPT_CLSID
"\\Implemented Categories\\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}",
687 && init_key("CLSID\\"TESTSCRIPT_CLSID
"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
691 static BOOL
register_script_engine(void)
696 if(!init_registry(TRUE
)) {
697 init_registry(FALSE
);
701 hres
= CoRegisterClassObject(&CLSID_TestScript
, (IUnknown
*)&script_cf
,
702 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, ®id
);
703 ok(hres
== S_OK
, "Could not register script engine: %08x\n", hres
);
708 static BOOL have_custom_engine
;
710 static HRESULT WINAPI
OleClientSite_QueryInterface(IOleClientSite
*iface
, REFIID riid
, void **obj
)
712 if (IsEqualIID(riid
, &IID_IOleClientSite
) || IsEqualIID(riid
, &IID_IUnknown
))
715 IOleClientSite_AddRef(iface
);
720 return E_NOINTERFACE
;
723 static ULONG WINAPI
OleClientSite_AddRef(IOleClientSite
*iface
)
728 static ULONG WINAPI
OleClientSite_Release(IOleClientSite
*iface
)
733 static HRESULT WINAPI
OleClientSite_SaveObject(IOleClientSite
*iface
)
738 static HRESULT WINAPI
OleClientSite_GetMoniker(IOleClientSite
*iface
, DWORD assign
,
739 DWORD which
, IMoniker
**moniker
)
744 static HRESULT WINAPI
OleClientSite_GetContainer(IOleClientSite
*iface
, IOleContainer
**container
)
749 static HRESULT WINAPI
OleClientSite_ShowObject(IOleClientSite
*iface
)
754 static HRESULT WINAPI
OleClientSite_OnShowWindow(IOleClientSite
*iface
, BOOL show
)
759 static HRESULT WINAPI
OleClientSite_RequestNewObjectLayout(IOleClientSite
*iface
)
764 static const IOleClientSiteVtbl OleClientSiteVtbl
= {
765 OleClientSite_QueryInterface
,
766 OleClientSite_AddRef
,
767 OleClientSite_Release
,
768 OleClientSite_SaveObject
,
769 OleClientSite_GetMoniker
,
770 OleClientSite_GetContainer
,
771 OleClientSite_ShowObject
,
772 OleClientSite_OnShowWindow
,
773 OleClientSite_RequestNewObjectLayout
776 static IOleClientSite testclientsite
= { &OleClientSiteVtbl
};
778 static void test_oleobject(void)
780 DWORD status
, dpi_x
, dpi_y
;
781 IOleClientSite
*site
;
787 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
788 &IID_IOleObject
, (void**)&obj
);
789 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
791 if (0) /* crashes on w2k3 */
792 hr
= IOleObject_GetMiscStatus(obj
, DVASPECT_CONTENT
, NULL
);
795 hr
= IOleObject_GetMiscStatus(obj
, DVASPECT_CONTENT
, &status
);
796 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
797 ok(status
!= 0, "got 0x%08x\n", status
);
799 hr
= IOleObject_SetClientSite(obj
, &testclientsite
);
800 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
802 if (0) /* crashes on w2k3 */
803 hr
= IOleObject_GetClientSite(obj
, NULL
);
805 hr
= IOleObject_GetClientSite(obj
, &site
);
806 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
807 ok(site
== &testclientsite
, "got %p, %p\n", site
, &testclientsite
);
808 IOleClientSite_Release(site
);
810 hr
= IOleObject_SetClientSite(obj
, NULL
);
811 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
813 hr
= IOleObject_GetClientSite(obj
, &site
);
814 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
815 ok(site
== NULL
, "got %p\n", site
);
819 dpi_x
= GetDeviceCaps(hdc
, LOGPIXELSX
);
820 dpi_y
= GetDeviceCaps(hdc
, LOGPIXELSY
);
823 memset(&extent
, 0, sizeof(extent
));
824 hr
= IOleObject_GetExtent(obj
, DVASPECT_CONTENT
, &extent
);
825 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
826 ok(extent
.cx
== MulDiv(38, 2540, dpi_x
), "got %d\n", extent
.cx
);
827 ok(extent
.cy
== MulDiv(38, 2540, dpi_y
), "got %d\n", extent
.cy
);
829 extent
.cx
= extent
.cy
= 0xdeadbeef;
830 hr
= IOleObject_GetExtent(obj
, DVASPECT_THUMBNAIL
, &extent
);
831 ok(hr
== DV_E_DVASPECT
, "got 0x%08x\n", hr
);
832 ok(extent
.cx
== 0xdeadbeef, "got %d\n", extent
.cx
);
833 ok(extent
.cy
== 0xdeadbeef, "got %d\n", extent
.cy
);
835 extent
.cx
= extent
.cy
= 0xdeadbeef;
836 hr
= IOleObject_GetExtent(obj
, DVASPECT_ICON
, &extent
);
837 ok(hr
== DV_E_DVASPECT
, "got 0x%08x\n", hr
);
838 ok(extent
.cx
== 0xdeadbeef, "got %d\n", extent
.cx
);
839 ok(extent
.cy
== 0xdeadbeef, "got %d\n", extent
.cy
);
841 extent
.cx
= extent
.cy
= 0xdeadbeef;
842 hr
= IOleObject_GetExtent(obj
, DVASPECT_DOCPRINT
, &extent
);
843 ok(hr
== DV_E_DVASPECT
, "got 0x%08x\n", hr
);
844 ok(extent
.cx
== 0xdeadbeef, "got %d\n", extent
.cx
);
845 ok(extent
.cy
== 0xdeadbeef, "got %d\n", extent
.cy
);
847 IOleObject_Release(obj
);
850 static void test_persiststreaminit(void)
852 IPersistStreamInit
*init
;
855 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
856 &IID_IPersistStreamInit
, (void**)&init
);
857 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
859 IPersistStreamInit_Release(init
);
862 static void test_olecontrol(void)
864 IOleControl
*olecontrol
;
868 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
869 &IID_IOleControl
, (void**)&olecontrol
);
870 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
872 memset(&info
, 0xab, sizeof(info
));
873 info
.cb
= sizeof(info
);
874 hr
= IOleControl_GetControlInfo(olecontrol
, &info
);
875 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
876 ok(info
.hAccel
== NULL
, "got %p\n", info
.hAccel
);
877 ok(info
.cAccel
== 0, "got %d\n", info
.cAccel
);
878 ok(info
.dwFlags
== 0xabababab, "got %x\n", info
.dwFlags
);
880 memset(&info
, 0xab, sizeof(info
));
881 info
.cb
= sizeof(info
) - 1;
882 hr
= IOleControl_GetControlInfo(olecontrol
, &info
);
883 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
884 ok(info
.hAccel
== NULL
, "got %p\n", info
.hAccel
);
885 ok(info
.cAccel
== 0, "got %d\n", info
.cAccel
);
886 ok(info
.dwFlags
== 0xabababab, "got %x\n", info
.dwFlags
);
888 if (0) /* crashes on win2k3 */
890 hr
= IOleControl_GetControlInfo(olecontrol
, NULL
);
891 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
894 IOleControl_Release(olecontrol
);
897 static void test_Language(void)
899 static const WCHAR jsW
[] = {'J','S','c','r','i','p','t',0};
900 static const WCHAR vb2W
[] = {'v','B','s','c','r','i','p','t',0};
901 static const WCHAR dummyW
[] = {'d','u','m','m','y',0};
906 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
907 &IID_IScriptControl
, (void**)&sc
);
908 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
910 hr
= IScriptControl_get_Language(sc
, NULL
);
911 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
913 str
= (BSTR
)0xdeadbeef;
914 hr
= IScriptControl_get_Language(sc
, &str
);
915 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
916 ok(str
== NULL
, "got %s\n", wine_dbgstr_w(str
));
918 str
= SysAllocString(vbW
);
919 hr
= IScriptControl_put_Language(sc
, str
);
920 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
923 str
= SysAllocString(vb2W
);
924 hr
= IScriptControl_put_Language(sc
, str
);
925 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
928 hr
= IScriptControl_get_Language(sc
, &str
);
929 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
930 ok(!lstrcmpW(str
, vbW
), "got %s\n", wine_dbgstr_w(str
));
933 str
= SysAllocString(dummyW
);
934 hr
= IScriptControl_put_Language(sc
, str
);
935 ok(hr
== CTL_E_INVALIDPROPERTYVALUE
, "got 0x%08x\n", hr
);
938 hr
= IScriptControl_get_Language(sc
, &str
);
939 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
940 ok(!lstrcmpW(str
, vbW
), "got %s\n", wine_dbgstr_w(str
));
943 str
= SysAllocString(jsW
);
944 hr
= IScriptControl_put_Language(sc
, str
);
945 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
948 hr
= IScriptControl_get_Language(sc
, &str
);
949 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
950 ok(!lstrcmpW(str
, jsW
), "got %s\n", wine_dbgstr_w(str
));
953 hr
= IScriptControl_put_Language(sc
, NULL
);
954 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
956 hr
= IScriptControl_get_Language(sc
, &str
);
957 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
958 ok(str
== NULL
, "got %s\n", wine_dbgstr_w(str
));
960 IScriptControl_Release(sc
);
962 /* custom script engine */
963 if (have_custom_engine
) {
964 static const WCHAR testscriptW
[] = {'t','e','s','t','s','c','r','i','p','t',0};
966 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
967 &IID_IScriptControl
, (void**)&sc
);
968 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
970 SET_EXPECT(CreateInstance
);
971 SET_EXPECT(SetInterfaceSafetyOptions
);
972 SET_EXPECT(SetScriptSite
);
973 SET_EXPECT(QI_IActiveScriptParse
);
976 str
= SysAllocString(testscriptW
);
977 hr
= IScriptControl_put_Language(sc
, str
);
978 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
981 CHECK_CALLED(CreateInstance
);
982 CHECK_CALLED(SetInterfaceSafetyOptions
);
983 CHECK_CALLED(SetScriptSite
);
984 CHECK_CALLED(QI_IActiveScriptParse
);
985 CHECK_CALLED(InitNew
);
986 hr
= IScriptControl_get_Language(sc
, &str
);
988 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
990 ok(!lstrcmpW(testscriptW
, str
), "%s\n", wine_dbgstr_w(str
));
993 IActiveScriptSite_Release(site
);
997 IScriptControl_Release(sc
);
1003 static void test_connectionpoints(void)
1005 IConnectionPointContainer
*container
, *container2
;
1006 IConnectionPoint
*cp
;
1011 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1012 &IID_IScriptControl
, (void**)&sc
);
1013 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1016 hr
= IScriptControl_QueryInterface(sc
, &IID_IConnectionPointContainer
, (void**)&container
);
1017 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1019 EXPECT_REF(container
, 2);
1021 hr
= IConnectionPointContainer_FindConnectionPoint(container
, &IID_IPropertyNotifySink
, &cp
);
1022 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1024 if (0) /* crashes on win2k3 */
1026 hr
= IConnectionPoint_GetConnectionPointContainer(cp
, NULL
);
1027 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
1030 hr
= IConnectionPoint_GetConnectionInterface(cp
, &iid
);
1031 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1032 ok(IsEqualIID(&iid
, &IID_IPropertyNotifySink
), "got %s\n", wine_dbgstr_guid(&iid
));
1034 hr
= IConnectionPoint_GetConnectionPointContainer(cp
, &container2
);
1035 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1036 ok(container2
== container
, "got %p, expected %p\n", container2
, container
);
1037 IConnectionPointContainer_Release(container2
);
1039 IConnectionPoint_Release(cp
);
1041 hr
= IConnectionPointContainer_FindConnectionPoint(container
, &DIID_DScriptControlSource
, &cp
);
1042 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1044 if (0) /* crashes on win2k3 */
1046 hr
= IConnectionPoint_GetConnectionPointContainer(cp
, NULL
);
1047 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
1050 hr
= IConnectionPoint_GetConnectionInterface(cp
, &iid
);
1051 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1052 ok(IsEqualIID(&iid
, &DIID_DScriptControlSource
), "got %s\n", wine_dbgstr_guid(&iid
));
1054 hr
= IConnectionPoint_GetConnectionPointContainer(cp
, &container2
);
1055 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1056 ok(container2
== container
, "got %p, expected %p\n", container2
, container
);
1057 IConnectionPointContainer_Release(container2
);
1059 IConnectionPoint_Release(cp
);
1061 IConnectionPointContainer_Release(container
);
1062 IScriptControl_Release(sc
);
1065 static void test_quickactivate(void)
1071 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1072 &IID_IScriptControl
, (void**)&sc
);
1073 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1075 hr
= IScriptControl_QueryInterface(sc
, &IID_IQuickActivate
, (void**)&qa
);
1076 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1078 IQuickActivate_Release(qa
);
1079 IScriptControl_Release(sc
);
1082 static void test_viewobject(void)
1084 DWORD status
, aspect
, flags
;
1085 IViewObjectEx
*viewex
;
1091 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1092 &IID_IScriptControl
, (void**)&sc
);
1093 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1095 hr
= IScriptControl_QueryInterface(sc
, &IID_IViewObject
, (void**)&view
);
1096 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1097 IViewObject_Release(view
);
1099 hr
= IScriptControl_QueryInterface(sc
, &IID_IViewObject2
, (void**)&view
);
1100 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1102 sink
= (IAdviseSink
*)0xdeadbeef;
1103 hr
= IViewObject_GetAdvise(view
, &aspect
, &flags
, &sink
);
1104 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1105 ok(aspect
== DVASPECT_CONTENT
, "got %u\n", aspect
);
1106 ok(flags
== 0, "got %#x\n", flags
);
1107 ok(sink
== NULL
, "got %p\n", sink
);
1109 hr
= IViewObject_SetAdvise(view
, DVASPECT_CONTENT
, 0, NULL
);
1110 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1112 hr
= IViewObject_SetAdvise(view
, DVASPECT_THUMBNAIL
, 0, NULL
);
1113 ok(hr
== DV_E_DVASPECT
, "got 0x%08x\n", hr
);
1115 hr
= IViewObject_SetAdvise(view
, DVASPECT_ICON
, 0, NULL
);
1116 ok(hr
== DV_E_DVASPECT
, "got 0x%08x\n", hr
);
1118 hr
= IViewObject_SetAdvise(view
, DVASPECT_DOCPRINT
, 0, NULL
);
1119 ok(hr
== DV_E_DVASPECT
, "got 0x%08x\n", hr
);
1121 sink
= (IAdviseSink
*)0xdeadbeef;
1122 hr
= IViewObject_GetAdvise(view
, &aspect
, &flags
, &sink
);
1123 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1124 ok(aspect
== DVASPECT_CONTENT
, "got %u\n", aspect
);
1125 ok(flags
== 0, "got %#x\n", flags
);
1126 ok(sink
== NULL
, "got %p\n", sink
);
1128 IViewObject_Release(view
);
1130 hr
= IScriptControl_QueryInterface(sc
, &IID_IViewObjectEx
, (void**)&viewex
);
1131 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1133 if (0) /* crashes */
1134 hr
= IViewObjectEx_GetViewStatus(viewex
, NULL
);
1137 hr
= IViewObjectEx_GetViewStatus(viewex
, &status
);
1138 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1139 ok(status
== VIEWSTATUS_OPAQUE
, "got %#x\n", status
);
1141 IViewObjectEx_Release(viewex
);
1143 IScriptControl_Release(sc
);
1146 static void test_pointerinactive(void)
1148 IPointerInactive
*pi
;
1153 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1154 &IID_IScriptControl
, (void**)&sc
);
1155 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1157 hr
= IScriptControl_QueryInterface(sc
, &IID_IPointerInactive
, (void**)&pi
);
1158 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1160 if (0) /* crashes w2k3 */
1161 hr
= IPointerInactive_GetActivationPolicy(pi
, NULL
);
1164 hr
= IPointerInactive_GetActivationPolicy(pi
, &policy
);
1165 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1166 ok(policy
== 0, "got %#x\n", policy
);
1168 IPointerInactive_Release(pi
);
1169 IScriptControl_Release(sc
);
1172 static void test_timeout(void)
1179 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1180 &IID_IScriptControl
, (void**)&sc
);
1181 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1183 hr
= IScriptControl_get_Timeout(sc
, NULL
);
1184 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
1187 hr
= IScriptControl_get_Timeout(sc
, &val
);
1188 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1189 ok(val
== 10000, "got %d\n", val
);
1191 hr
= IScriptControl_put_Timeout(sc
, -1);
1192 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1195 hr
= IScriptControl_get_Timeout(sc
, &val
);
1196 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1197 ok(val
== -1, "got %d\n", val
);
1199 hr
= IScriptControl_put_Timeout(sc
, -2);
1200 ok(hr
== CTL_E_INVALIDPROPERTYVALUE
, "got 0x%08x\n", hr
);
1203 hr
= IScriptControl_get_Timeout(sc
, &val
);
1204 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1205 ok(val
== -1, "got %d\n", val
);
1207 hr
= IScriptControl_put_Timeout(sc
, 0);
1208 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1211 hr
= IScriptControl_get_Timeout(sc
, &val
);
1212 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1213 ok(val
== 0, "got %d\n", val
);
1215 str
= SysAllocString(vbW
);
1216 hr
= IScriptControl_put_Language(sc
, str
);
1217 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1221 hr
= IScriptControl_get_Timeout(sc
, &val
);
1222 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1223 ok(val
== 0, "got %d\n", val
);
1225 hr
= IScriptControl_put_Timeout(sc
, 10000);
1226 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1228 IScriptControl_Release(sc
);
1231 static void test_Reset(void)
1237 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1238 &IID_IScriptControl
, (void**)&sc
);
1239 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1241 hr
= IScriptControl_Reset(sc
);
1242 ok(hr
== E_FAIL
, "got 0x%08x\n", hr
);
1244 str
= SysAllocString(vbW
);
1245 hr
= IScriptControl_put_Language(sc
, str
);
1246 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1249 hr
= IScriptControl_Reset(sc
);
1250 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1252 hr
= IScriptControl_get_Language(sc
, &str
);
1253 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1254 ok(!lstrcmpW(str
, vbW
), "got %s\n", wine_dbgstr_w(str
));
1257 IScriptControl_Release(sc
);
1259 /* custom script engine */
1260 if (have_custom_engine
) {
1261 static const WCHAR testscriptW
[] = {'t','e','s','t','s','c','r','i','p','t',0};
1263 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1264 &IID_IScriptControl
, (void**)&sc
);
1265 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1267 SET_EXPECT(CreateInstance
);
1268 SET_EXPECT(SetInterfaceSafetyOptions
);
1269 SET_EXPECT(SetScriptSite
);
1270 SET_EXPECT(QI_IActiveScriptParse
);
1271 SET_EXPECT(InitNew
);
1273 str
= SysAllocString(testscriptW
);
1274 hr
= IScriptControl_put_Language(sc
, str
);
1275 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1278 SET_EXPECT(SetScriptState_INITIALIZED
);
1279 hr
= IScriptControl_Reset(sc
);
1280 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1281 CHECK_CALLED(SetScriptState_INITIALIZED
);
1283 SET_EXPECT(SetScriptState_INITIALIZED
);
1284 hr
= IScriptControl_Reset(sc
);
1285 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1286 CHECK_CALLED(SetScriptState_INITIALIZED
);
1288 CHECK_CALLED(SetScriptSite
);
1289 IActiveScriptSite_Release(site
);
1293 IScriptControl_Release(sc
);
1295 CHECK_CALLED(Close
);
1299 static HRESULT WINAPI
disp_QI(IDispatch
*iface
, REFIID riid
, void **obj
)
1301 if (IsEqualIID(riid
, &IID_IDispatch
) || IsEqualIID(riid
, &IID_IUnknown
)) {
1303 IDispatch_AddRef(iface
);
1308 return E_NOINTERFACE
;
1311 static ULONG WINAPI
disp_AddRef(IDispatch
*iface
)
1316 static ULONG WINAPI
disp_Release(IDispatch
*iface
)
1321 static HRESULT WINAPI
disp_GetTypeInfoCount(IDispatch
*iface
, UINT
*count
)
1323 ok(0, "unexpected call\n");
1327 static HRESULT WINAPI
disp_GetTypeInfo(IDispatch
*iface
, UINT index
, LCID lcid
, ITypeInfo
**ti
)
1329 ok(0, "unexpected call\n");
1333 static HRESULT WINAPI
disp_GetIDsOfNames(IDispatch
*iface
, REFIID riid
, LPOLESTR
*names
,
1334 UINT cnames
, LCID lcid
, DISPID
*dispid
)
1336 ok(0, "unexpected call\n");
1340 static HRESULT WINAPI
disp_Invoke(IDispatch
*iface
, DISPID dispid
, REFIID riid
, LCID lcid
,
1341 WORD flags
, DISPPARAMS
*dispparams
, VARIANT
*result
, EXCEPINFO
*ei
, UINT
*arg_err
)
1343 ok(0, "unexpected call\n");
1347 static const IDispatchVtbl dispvtbl
= {
1351 disp_GetTypeInfoCount
,
1357 static IDispatch testdisp
= { &dispvtbl
};
1359 static void test_AddObject(void)
1361 static const WCHAR oW
[] = {'o',0};
1366 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1367 &IID_IScriptControl
, (void**)&sc
);
1368 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1370 objname
= SysAllocString(oW
);
1371 hr
= IScriptControl_AddObject(sc
, objname
, NULL
, VARIANT_FALSE
);
1372 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1374 hr
= IScriptControl_AddObject(sc
, objname
, &testdisp
, VARIANT_FALSE
);
1375 ok(hr
== E_FAIL
, "got 0x%08x\n", hr
);
1377 str
= SysAllocString(vbW
);
1378 hr
= IScriptControl_put_Language(sc
, str
);
1379 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1382 hr
= IScriptControl_AddObject(sc
, objname
, &testdisp
, VARIANT_TRUE
);
1383 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1385 hr
= IScriptControl_Reset(sc
);
1386 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1388 hr
= IScriptControl_AddObject(sc
, objname
, &testdisp
, VARIANT_TRUE
);
1389 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1391 IScriptControl_Release(sc
);
1393 /* custom script engine */
1394 if (have_custom_engine
) {
1395 static const WCHAR testscriptW
[] = {'t','e','s','t','s','c','r','i','p','t',0};
1397 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1398 &IID_IScriptControl
, (void**)&sc
);
1399 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1401 SET_EXPECT(CreateInstance
);
1402 SET_EXPECT(SetInterfaceSafetyOptions
);
1403 SET_EXPECT(SetScriptSite
);
1404 SET_EXPECT(QI_IActiveScriptParse
);
1405 SET_EXPECT(InitNew
);
1407 str
= SysAllocString(testscriptW
);
1408 hr
= IScriptControl_put_Language(sc
, str
);
1409 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1412 hr
= IScriptControl_AddObject(sc
, objname
, NULL
, VARIANT_FALSE
);
1413 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1415 SET_EXPECT(AddNamedItem
);
1416 hr
= IScriptControl_AddObject(sc
, objname
, &testdisp
, VARIANT_TRUE
);
1417 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1418 CHECK_CALLED(AddNamedItem
);
1420 hr
= IScriptControl_AddObject(sc
, objname
, &testdisp
, VARIANT_TRUE
);
1421 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1423 CHECK_CALLED(SetScriptSite
);
1424 IActiveScriptSite_Release(site
);
1428 IScriptControl_Release(sc
);
1430 CHECK_CALLED(Close
);
1433 SysFreeString(objname
);
1436 static void test_AllowUI(void)
1442 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1443 &IID_IScriptControl
, (void**)&sc
);
1444 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1446 hr
= IScriptControl_get_AllowUI(sc
, NULL
);
1447 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
1449 hr
= IScriptControl_get_AllowUI(sc
, &allow
);
1450 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1451 ok(allow
== VARIANT_TRUE
, "got %d\n", allow
);
1453 hr
= IScriptControl_put_AllowUI(sc
, VARIANT_FALSE
);
1454 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1456 hr
= IScriptControl_get_AllowUI(sc
, &allow
);
1457 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1458 ok(allow
== VARIANT_FALSE
, "got %d\n", allow
);
1460 IScriptControl_Release(sc
);
1463 static void test_UseSafeSubset(void)
1466 VARIANT_BOOL use_safe_subset
;
1470 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1471 &IID_IScriptControl
, (void**)&sc
);
1472 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1474 hr
= IScriptControl_get_UseSafeSubset(sc
, NULL
);
1475 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
1477 hr
= IScriptControl_get_UseSafeSubset(sc
, &use_safe_subset
);
1478 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1479 ok(use_safe_subset
== VARIANT_FALSE
, "got %d\n", use_safe_subset
);
1481 hr
= IScriptControl_put_UseSafeSubset(sc
, VARIANT_TRUE
);
1482 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1484 hr
= IScriptControl_get_UseSafeSubset(sc
, &use_safe_subset
);
1485 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1486 ok(use_safe_subset
== VARIANT_TRUE
, "got %d\n", use_safe_subset
);
1488 str
= SysAllocString(vbW
);
1489 hr
= IScriptControl_put_Language(sc
, str
);
1490 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1493 hr
= IScriptControl_get_UseSafeSubset(sc
, &use_safe_subset
);
1494 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1495 ok(use_safe_subset
== VARIANT_TRUE
, "got %d\n", use_safe_subset
);
1497 IScriptControl_Release(sc
);
1500 static void test_State(void)
1503 ScriptControlStates state
;
1507 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1508 &IID_IScriptControl
, (void**)&sc
);
1509 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1511 hr
= IScriptControl_get_State(sc
, NULL
);
1512 ok(hr
== E_POINTER
, "got 0x%08x\n", hr
);
1514 hr
= IScriptControl_get_State(sc
, &state
);
1515 ok(hr
== E_FAIL
, "got 0x%08x\n", hr
);
1517 hr
= IScriptControl_put_State(sc
, Connected
);
1518 ok(hr
== E_FAIL
, "got 0x%08x\n", hr
);
1520 str
= SysAllocString(vbW
);
1521 hr
= IScriptControl_put_Language(sc
, str
);
1522 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1525 hr
= IScriptControl_get_State(sc
, &state
);
1526 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1527 ok(state
== Initialized
, "got %d\n", state
);
1529 hr
= IScriptControl_put_State(sc
, Connected
);
1530 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1532 hr
= IScriptControl_get_State(sc
, &state
);
1533 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1534 ok(state
== Connected
, "got %d\n", state
);
1536 hr
= IScriptControl_put_State(sc
, 2);
1537 ok(hr
== CTL_E_INVALIDPROPERTYVALUE
, "got 0x%08x\n", hr
);
1539 hr
= IScriptControl_get_State(sc
, &state
);
1540 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1541 ok(state
== Connected
, "got %d\n", state
);
1543 hr
= IScriptControl_put_State(sc
, -1);
1544 ok(hr
== CTL_E_INVALIDPROPERTYVALUE
, "got 0x%08x\n", hr
);
1546 hr
= IScriptControl_get_State(sc
, &state
);
1547 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1548 ok(state
== Connected
, "got %d\n", state
);
1550 IScriptControl_Release(sc
);
1553 #define CHECK_ERROR(sc,exp_num) _check_error(sc, exp_num, __LINE__)
1554 static void _check_error(IScriptControl
*sc
, LONG exp_num
, int line
)
1556 IScriptError
*script_err
;
1560 hr
= IScriptControl_get_Error(sc
, &script_err
);
1561 ok_(__FILE__
,line
)(hr
== S_OK
, "IScriptControl_get_Error failed: 0x%08x.\n", hr
);
1564 error_num
= 0xdeadbeef;
1565 hr
= IScriptError_get_Number(script_err
, &error_num
);
1566 ok_(__FILE__
,line
)(hr
== S_OK
, "IScriptError_get_Number failed: 0x%08x.\n", hr
);
1567 ok_(__FILE__
,line
)(error_num
== exp_num
, "got wrong error number: %d, expected %d.\n",
1568 error_num
, exp_num
);
1569 IScriptError_Release(script_err
);
1573 static void test_IScriptControl_Eval(void)
1577 BSTR script_str
, language
, expected_string
;
1579 ScriptControlStates state
;
1581 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
,
1582 &IID_IScriptControl
, (void **)&sc
);
1583 ok(hr
== S_OK
, "Failed to create IScriptControl interface: 0x%08x.\n", hr
);
1585 hr
= IScriptControl_Eval(sc
, NULL
, NULL
);
1586 ok(hr
== E_POINTER
, "IScriptControl_Eval returned: 0x%08x.\n", hr
);
1588 script_str
= SysAllocString(L
"1 + 1");
1589 hr
= IScriptControl_Eval(sc
, script_str
, NULL
);
1590 ok(hr
== E_POINTER
, "IScriptControl_Eval returned: 0x%08x.\n", hr
);
1591 SysFreeString(script_str
);
1593 V_VT(&var
) = VT_NULL
;
1594 V_I4(&var
) = 0xdeadbeef;
1595 hr
= IScriptControl_Eval(sc
, NULL
, &var
);
1596 ok(hr
== E_FAIL
, "IScriptControl_Eval returned: 0x%08x.\n", hr
);
1597 ok((V_VT(&var
) == VT_EMPTY
) && (V_I4(&var
) == 0xdeadbeef), "V_VT(var) = %d, V_I4(var) = %d.\n",
1598 V_VT(&var
), V_I4(&var
));
1599 todo_wine
CHECK_ERROR(sc
, 0);
1601 script_str
= SysAllocString(L
"1 + 1");
1602 V_VT(&var
) = VT_NULL
;
1603 V_I4(&var
) = 0xdeadbeef;
1604 hr
= IScriptControl_Eval(sc
, script_str
, &var
);
1605 ok(hr
== E_FAIL
, "IScriptControl_Eval returned: 0x%08x.\n", hr
);
1606 ok((V_VT(&var
) == VT_EMPTY
) && (V_I4(&var
) == 0xdeadbeef), "V_VT(var) = %d, V_I4(var) = %d.\n",
1607 V_VT(&var
), V_I4(&var
));
1608 SysFreeString(script_str
);
1610 language
= SysAllocString(L
"jscript");
1611 hr
= IScriptControl_put_Language(sc
, language
);
1612 ok(hr
== S_OK
, "IScriptControl_put_Language failed: 0x%08x.\n", hr
);
1613 hr
= IScriptControl_get_State(sc
, &state
);
1614 ok(hr
== S_OK
, "IScriptControl_get_State failed: 0x%08x.\n", hr
);
1615 ok(state
== Initialized
, "got wrong state: %d\n", state
);
1616 SysFreeString(language
);
1617 script_str
= SysAllocString(L
"var1 = 1 + 1");
1618 V_VT(&var
) = VT_NULL
;
1619 V_I4(&var
) = 0xdeadbeef;
1620 hr
= IScriptControl_Eval(sc
, script_str
, &var
);
1621 ok(hr
== S_OK
, "IScriptControl_Eval failed: 0x%08x.\n", hr
);
1622 ok((V_VT(&var
) == VT_I4
) && (V_I4(&var
) == 2), "V_VT(var) = %d, V_I4(var) = %d.\n",
1623 V_VT(&var
), V_I4(&var
));
1624 hr
= IScriptControl_get_State(sc
, &state
);
1625 ok(hr
== S_OK
, "IScriptControl_get_State failed: 0x%08x.\n", hr
);
1626 ok(state
== Initialized
, "got wrong state: %d\n", state
);
1627 SysFreeString(script_str
);
1629 script_str
= SysAllocString(L
"var2 = 10 + var1");
1630 V_VT(&var
) = VT_NULL
;
1631 V_I4(&var
) = 0xdeadbeef;
1632 hr
= IScriptControl_Eval(sc
, script_str
, &var
);
1633 ok(hr
== S_OK
, "IScriptControl_Eval failed: 0x%08x.\n", hr
);
1634 ok((V_VT(&var
) == VT_I4
) && (V_I4(&var
) == 12), "V_VT(var) = %d, V_I4(var) = %d.\n",
1635 V_VT(&var
), V_I4(&var
));
1636 SysFreeString(script_str
);
1638 script_str
= SysAllocString(L
"invalid syntax");
1639 V_VT(&var
) = VT_NULL
;
1640 V_I4(&var
) = 0xdeadbeef;
1641 hr
= IScriptControl_Eval(sc
, script_str
, &var
);
1642 todo_wine
ok(hr
== 0x800a03ec, "IScriptControl_Eval failed: 0x%08x.\n", hr
);
1643 ok(V_VT(&var
) == VT_EMPTY
, "V_VT(var) = %d\n", V_VT(&var
));
1644 ok(V_I4(&var
) == 0xdeadbeef || broken(V_I4(&var
) == 0) /* after Win8 */,
1645 "V_I4(var) = %d.\n", V_I4(&var
));
1646 SysFreeString(script_str
);
1647 todo_wine
CHECK_ERROR(sc
, 1004);
1649 script_str
= SysAllocString(L
"var2 = var1 + var2");
1650 V_VT(&var
) = VT_NULL
;
1651 V_I4(&var
) = 0xdeadbeef;
1652 hr
= IScriptControl_Eval(sc
, script_str
, &var
);
1653 ok(hr
== S_OK
, "IScriptControl_Eval failed: 0x%08x.\n", hr
);
1654 ok((V_VT(&var
) == VT_I4
) && (V_I4(&var
) == 14), "V_VT(var) = %d, V_I4(var) = %d.\n",
1655 V_VT(&var
), V_I4(&var
));
1656 SysFreeString(script_str
);
1658 script_str
= SysAllocString(L
"\"Hello\"");
1659 V_VT(&var
) = VT_NULL
;
1660 V_I4(&var
) = 0xdeadbeef;
1661 hr
= IScriptControl_Eval(sc
, script_str
, &var
);
1662 ok(hr
== S_OK
, "IScriptControl_Eval failed: 0x%08x.\n", hr
);
1663 expected_string
= SysAllocString(L
"Hello");
1664 ok((V_VT(&var
) == VT_BSTR
) && (!lstrcmpW(V_BSTR(&var
), expected_string
)),
1665 "V_VT(var) = %d, V_BSTR(var) = %s.\n", V_VT(&var
), wine_dbgstr_w(V_BSTR(&var
)));
1666 SysFreeString(expected_string
);
1667 SysFreeString(script_str
);
1669 IScriptControl_Release(sc
);
1671 if (have_custom_engine
)
1673 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
,
1674 &IID_IScriptControl
, (void **)&sc
);
1675 ok(hr
== S_OK
, "Failed to create IScriptControl interface: 0x%08x.\n", hr
);
1677 SET_EXPECT(CreateInstance
);
1678 SET_EXPECT(SetInterfaceSafetyOptions
);
1679 SET_EXPECT(SetScriptSite
);
1680 SET_EXPECT(QI_IActiveScriptParse
);
1681 SET_EXPECT(InitNew
);
1683 language
= SysAllocString(L
"testscript");
1684 hr
= IScriptControl_put_Language(sc
, language
);
1685 ok(hr
== S_OK
, "IScriptControl_put_Language failed: 0x%08x.\n", hr
);
1686 SysFreeString(language
);
1688 CHECK_CALLED(CreateInstance
);
1689 CHECK_CALLED(SetInterfaceSafetyOptions
);
1690 CHECK_CALLED(SetScriptSite
);
1691 CHECK_CALLED(QI_IActiveScriptParse
);
1692 CHECK_CALLED(InitNew
);
1694 SET_EXPECT(SetScriptState_STARTED
);
1695 SET_EXPECT(ParseScriptText
);
1696 parse_flags
= SCRIPTTEXT_ISEXPRESSION
;
1697 script_str
= SysAllocString(L
"var1 = 1 + 1");
1698 V_VT(&var
) = VT_NULL
;
1699 hr
= IScriptControl_Eval(sc
, script_str
, &var
);
1700 ok(hr
== S_OK
, "IScriptControl_Eval failed: 0x%08x.\n", hr
);
1701 ok(V_VT(&var
) == VT_EMPTY
, "V_VT(var) = %d.\n", V_VT(&var
));
1702 SysFreeString(script_str
);
1703 CHECK_CALLED(SetScriptState_STARTED
);
1704 CHECK_CALLED(ParseScriptText
);
1706 SET_EXPECT(ParseScriptText
);
1707 script_str
= SysAllocString(L
"var2 = 10 + var1");
1708 V_VT(&var
) = VT_NULL
;
1709 V_I4(&var
) = 0xdeadbeef;
1710 hr
= IScriptControl_Eval(sc
, script_str
, &var
);
1711 ok(hr
== S_OK
, "IScriptControl_Eval failed: 0x%08x.\n", hr
);
1712 ok((V_VT(&var
) == VT_EMPTY
) && (V_I4(&var
) == 0xdeadbeef), "V_VT(var) = %d, V_I4(var) = %d.\n",
1713 V_VT(&var
), V_I4(&var
));
1714 SysFreeString(script_str
);
1715 CHECK_CALLED(ParseScriptText
);
1717 SET_EXPECT(SetScriptState_INITIALIZED
);
1718 hr
= IScriptControl_Reset(sc
);
1719 ok(hr
== S_OK
, "IScriptControl_Reset failed: 0x%08x.\n", hr
);
1720 CHECK_CALLED(SetScriptState_INITIALIZED
);
1722 SET_EXPECT(SetScriptState_STARTED
);
1723 SET_EXPECT(ParseScriptText
);
1724 script_str
= SysAllocString(L
"var2 = 10 + var1");
1725 V_VT(&var
) = VT_NULL
;
1726 V_I4(&var
) = 0xdeadbeef;
1727 hr
= IScriptControl_Eval(sc
, script_str
, &var
);
1728 ok(hr
== S_OK
, "IScriptControl_Eval failed: 0x%08x.\n", hr
);
1729 ok((V_VT(&var
) == VT_EMPTY
) && (V_I4(&var
) == 0xdeadbeef), "V_VT(var) = %d, V_I4(var) = %d.\n",
1730 V_VT(&var
), V_I4(&var
));
1731 SysFreeString(script_str
);
1732 CHECK_CALLED(SetScriptState_STARTED
);
1733 CHECK_CALLED(ParseScriptText
);
1735 IActiveScriptSite_Release(site
);
1739 IScriptControl_Release(sc
);
1741 CHECK_CALLED(Close
);
1745 static void test_IScriptControl_AddCode(void)
1747 BSTR code_str
, language
;
1752 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
,
1753 &IID_IScriptControl
, (void **)&sc
);
1754 ok(hr
== S_OK
, "Failed to create IScriptControl interface: 0x%08x.\n", hr
);
1756 code_str
= SysAllocString(L
"1 + 1");
1757 hr
= IScriptControl_AddCode(sc
, code_str
);
1758 ok(hr
== E_FAIL
, "IScriptControl_AddCode returned: 0x%08x.\n", hr
);
1759 SysFreeString(code_str
);
1761 hr
= IScriptControl_AddCode(sc
, NULL
);
1762 ok(hr
== E_FAIL
, "IScriptControl_AddCode returned: 0x%08x.\n", hr
);
1764 language
= SysAllocString(L
"jscript");
1765 hr
= IScriptControl_put_Language(sc
, language
);
1766 ok(hr
== S_OK
, "IScriptControl_put_Language failed: 0x%08x.\n", hr
);
1767 SysFreeString(language
);
1769 code_str
= SysAllocString(L
"1 + 1");
1770 hr
= IScriptControl_AddCode(sc
, code_str
);
1771 ok(hr
== S_OK
, "IScriptControl_AddCode failed: 0x%08x.\n", hr
);
1772 SysFreeString(code_str
);
1773 todo_wine
CHECK_ERROR(sc
, 0);
1775 code_str
= SysAllocString(L
"invalid syntax");
1776 hr
= IScriptControl_AddCode(sc
, code_str
);
1777 todo_wine
ok(hr
== 0x800a03ec, "IScriptControl_AddCode returned: 0x%08x.\n", hr
);
1778 SysFreeString(code_str
);
1779 todo_wine
CHECK_ERROR(sc
, 1004);
1781 IScriptControl_Release(sc
);
1783 /* custom script engine */
1784 if (have_custom_engine
)
1786 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
,
1787 &IID_IScriptControl
, (void **)&sc
);
1788 ok(hr
== S_OK
, "Failed to create IScriptControl interface: 0x%08x.\n", hr
);
1790 SET_EXPECT(CreateInstance
);
1791 SET_EXPECT(SetInterfaceSafetyOptions
);
1792 SET_EXPECT(SetScriptSite
);
1793 SET_EXPECT(QI_IActiveScriptParse
);
1794 SET_EXPECT(InitNew
);
1796 language
= SysAllocString(L
"testscript");
1797 hr
= IScriptControl_put_Language(sc
, language
);
1798 ok(hr
== S_OK
, "IScriptControl_put_Language failed: 0x%08x.\n", hr
);
1799 SysFreeString(language
);
1801 CHECK_CALLED(CreateInstance
);
1802 CHECK_CALLED(SetInterfaceSafetyOptions
);
1803 CHECK_CALLED(SetScriptSite
);
1804 CHECK_CALLED(QI_IActiveScriptParse
);
1805 CHECK_CALLED(InitNew
);
1807 SET_EXPECT(SetScriptState_STARTED
);
1808 SET_EXPECT(ParseScriptText
);
1809 parse_flags
= SCRIPTTEXT_ISVISIBLE
;
1810 code_str
= SysAllocString(L
"1 + 1");
1811 hr
= IScriptControl_AddCode(sc
, code_str
);
1812 ok(hr
== S_OK
, "IScriptControl_AddCode failed: 0x%08x.\n", hr
);
1813 SysFreeString(code_str
);
1814 CHECK_CALLED(SetScriptState_STARTED
);
1815 CHECK_CALLED(ParseScriptText
);
1817 SET_EXPECT(ParseScriptText
);
1818 code_str
= SysAllocString(L
"0x100");
1819 hr
= IScriptControl_AddCode(sc
, code_str
);
1820 ok(hr
== S_OK
, "IScriptControl_AddCode failed: 0x%08x.\n", hr
);
1821 SysFreeString(code_str
);
1822 CHECK_CALLED(ParseScriptText
);
1824 /* Call Eval() after AddCode() for checking if it will call SetScriptState() again. */
1825 SET_EXPECT(ParseScriptText
);
1826 parse_flags
= SCRIPTTEXT_ISEXPRESSION
;
1827 code_str
= SysAllocString(L
"var2 = 10 + var1");
1828 V_VT(&var
) = VT_NULL
;
1829 hr
= IScriptControl_Eval(sc
, code_str
, &var
);
1830 ok(hr
== S_OK
, "IScriptControl_Eval failed: 0x%08x.\n", hr
);
1831 ok(V_VT(&var
) == VT_EMPTY
, "V_VT(var) = %d.\n", V_VT(&var
));
1832 SysFreeString(code_str
);
1833 CHECK_CALLED(ParseScriptText
);
1835 IActiveScriptSite_Release(site
);
1839 IScriptControl_Release(sc
);
1841 CHECK_CALLED(Close
);
1845 static void test_IScriptControl_ExecuteStatement(void)
1851 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
,
1852 &IID_IScriptControl
, (void**)&sc
);
1853 ok(hr
== S_OK
, "Failed to create IScriptControl interface: 0x%08x.\n", hr
);
1855 str
= SysAllocString(L
"1 + 1");
1856 hr
= IScriptControl_ExecuteStatement(sc
, str
);
1857 ok(hr
== E_FAIL
, "IScriptControl_ExecuteStatement returned: 0x%08x.\n", hr
);
1860 hr
= IScriptControl_ExecuteStatement(sc
, NULL
);
1861 ok(hr
== E_FAIL
, "IScriptControl_ExecuteStatement returned: 0x%08x.\n", hr
);
1863 str
= SysAllocString(L
"jscript");
1864 hr
= IScriptControl_put_Language(sc
, str
);
1865 ok(hr
== S_OK
, "IScriptControl_put_Language failed: 0x%08x.\n", hr
);
1868 str
= SysAllocString(L
"1 + 1");
1869 hr
= IScriptControl_ExecuteStatement(sc
, str
);
1870 ok(hr
== S_OK
, "IScriptControl_ExecuteStatement failed: 0x%08x.\n", hr
);
1872 todo_wine
CHECK_ERROR(sc
, 0);
1874 str
= SysAllocString(L
"invalid syntax");
1875 hr
= IScriptControl_ExecuteStatement(sc
, str
);
1876 todo_wine
ok(hr
== 0x800a03ec, "IScriptControl_ExecuteStatement returned: 0x%08x.\n", hr
);
1878 todo_wine
CHECK_ERROR(sc
, 1004);
1880 IScriptControl_Release(sc
);
1882 /* custom script engine */
1883 if (have_custom_engine
)
1885 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
,
1886 &IID_IScriptControl
, (void**)&sc
);
1887 ok(hr
== S_OK
, "Failed to create IScriptControl interface: 0x%08x.\n", hr
);
1889 SET_EXPECT(CreateInstance
);
1890 SET_EXPECT(SetInterfaceSafetyOptions
);
1891 SET_EXPECT(SetScriptSite
);
1892 SET_EXPECT(QI_IActiveScriptParse
);
1893 SET_EXPECT(InitNew
);
1895 str
= SysAllocString(L
"testscript");
1896 hr
= IScriptControl_put_Language(sc
, str
);
1897 ok(hr
== S_OK
, "IScriptControl_put_Language failed: 0x%08x.\n", hr
);
1900 CHECK_CALLED(CreateInstance
);
1901 CHECK_CALLED(SetInterfaceSafetyOptions
);
1902 CHECK_CALLED(SetScriptSite
);
1903 CHECK_CALLED(QI_IActiveScriptParse
);
1904 CHECK_CALLED(InitNew
);
1906 SET_EXPECT(SetScriptState_STARTED
);
1907 SET_EXPECT(ParseScriptText
);
1909 str
= SysAllocString(L
"1 + 1");
1910 hr
= IScriptControl_ExecuteStatement(sc
, str
);
1911 ok(hr
== S_OK
, "IScriptControl_ExecuteStatement failed: 0x%08x.\n", hr
);
1913 CHECK_CALLED(SetScriptState_STARTED
);
1914 CHECK_CALLED(ParseScriptText
);
1916 SET_EXPECT(ParseScriptText
);
1917 str
= SysAllocString(L
"0x100");
1918 hr
= IScriptControl_ExecuteStatement(sc
, str
);
1919 ok(hr
== S_OK
, "IScriptControl_ExecuteStatement failed: 0x%08x.\n", hr
);
1921 CHECK_CALLED(ParseScriptText
);
1923 IActiveScriptSite_Release(site
);
1926 IScriptControl_Release(sc
);
1927 CHECK_CALLED(Close
);
1931 static void test_IScriptControl_Run(void)
1933 SAFEARRAYBOUND bnd
[] = { { 2, 0 }, { 2, 0 } };
1934 LONG idx0_0
[] = { 0, 0 };
1935 LONG idx0_1
[] = { 1, 0 };
1936 LONG idx1_0
[] = { 0, 1 };
1937 LONG idx1_1
[] = { 1, 1 };
1944 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
,
1945 &IID_IScriptControl
, (void**)&sc
);
1946 ok(hr
== S_OK
, "Failed to create IScriptControl interface: 0x%08x.\n", hr
);
1949 str
= SysAllocString(L
"identifier");
1950 hr
= IScriptControl_Run(sc
, str
, ¶ms
, &var
);
1951 ok(hr
== E_POINTER
, "IScriptControl_Run returned: 0x%08x.\n", hr
);
1953 params
= SafeArrayCreate(VT_VARIANT
, 1, bnd
);
1954 ok(params
!= NULL
, "Failed to create SafeArray.\n");
1958 SafeArrayPutElement(params
, idx0_0
, &var
);
1960 SafeArrayPutElement(params
, idx0_1
, &var
);
1962 hr
= IScriptControl_Run(sc
, str
, ¶ms
, &var
);
1963 ok(hr
== E_FAIL
, "IScriptControl_Run returned: 0x%08x.\n", hr
);
1965 hr
= IScriptControl_Run(sc
, str
, NULL
, &var
);
1966 ok(hr
== E_POINTER
, "IScriptControl_Run returned: 0x%08x.\n", hr
);
1968 hr
= IScriptControl_Run(sc
, str
, ¶ms
, NULL
);
1969 ok(hr
== E_POINTER
, "IScriptControl_Run returned: 0x%08x.\n", hr
);
1972 hr
= IScriptControl_Run(sc
, NULL
, ¶ms
, &var
);
1973 ok(hr
== E_FAIL
, "IScriptControl_Run returned: 0x%08x.\n", hr
);
1975 str
= SysAllocString(L
"jscript");
1976 hr
= IScriptControl_put_Language(sc
, str
);
1977 ok(hr
== S_OK
, "IScriptControl_put_Language failed: 0x%08x.\n", hr
);
1980 str
= SysAllocString(L
"foobar");
1981 hr
= IScriptControl_Run(sc
, str
, ¶ms
, &var
);
1982 ok(hr
== DISP_E_UNKNOWNNAME
, "IScriptControl_Run failed: 0x%08x.\n", hr
);
1983 todo_wine
CHECK_ERROR(sc
, 0);
1986 str
= SysAllocString(L
"function subtract(a, b) { return a - b; }\n");
1987 hr
= IScriptControl_AddCode(sc
, str
);
1988 ok(hr
== S_OK
, "IScriptControl_AddCode failed: 0x%08x.\n", hr
);
1989 todo_wine
CHECK_ERROR(sc
, 0);
1992 str
= SysAllocString(L
"Subtract");
1993 hr
= IScriptControl_Run(sc
, str
, ¶ms
, &var
);
1994 ok(hr
== DISP_E_UNKNOWNNAME
, "IScriptControl_Run failed: 0x%08x.\n", hr
);
1997 str
= SysAllocString(L
"subtract");
1998 hr
= IScriptControl_Run(sc
, str
, ¶ms
, NULL
);
1999 ok(hr
== E_POINTER
, "IScriptControl_Run failed: 0x%08x.\n", hr
);
2000 todo_wine
CHECK_ERROR(sc
, 0);
2002 hr
= IScriptControl_Run(sc
, str
, ¶ms
, &var
);
2003 ok(hr
== S_OK
, "IScriptControl_Run failed: 0x%08x.\n", hr
);
2004 ok((V_VT(&var
) == VT_I4
) && (V_I4(&var
) == 7), "V_VT(var) = %d, V_I4(var) = %d.\n", V_VT(&var
), V_I4(&var
));
2005 todo_wine
CHECK_ERROR(sc
, 0);
2006 SafeArrayDestroy(params
);
2008 /* The array's other dimensions are ignored */
2009 params
= SafeArrayCreate(VT_VARIANT
, 2, bnd
);
2010 ok(params
!= NULL
, "Failed to create SafeArray.\n");
2014 SafeArrayPutElement(params
, idx0_0
, &var
);
2016 SafeArrayPutElement(params
, idx0_1
, &var
);
2018 SafeArrayPutElement(params
, idx1_0
, &var
);
2020 SafeArrayPutElement(params
, idx1_1
, &var
);
2022 hr
= IScriptControl_Run(sc
, str
, ¶ms
, &var
);
2023 ok(hr
== S_OK
, "IScriptControl_Run failed: 0x%08x.\n", hr
);
2024 ok((V_VT(&var
) == VT_I4
) && (V_I4(&var
) == 7), "V_VT(var) = %d, V_I4(var) = %d.\n", V_VT(&var
), V_I4(&var
));
2026 /* Hack the array's dimensions to 0 */
2028 hr
= IScriptControl_Run(sc
, str
, ¶ms
, &var
);
2029 ok(hr
== DISP_E_BADINDEX
, "IScriptControl_Run returned: 0x%08x.\n", hr
);
2030 ok(V_VT(&var
) == VT_EMPTY
, "V_VT(var) = %d.\n", V_VT(&var
));
2033 IScriptControl_Release(sc
);
2035 /* custom script engine */
2036 if (have_custom_engine
)
2038 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
,
2039 &IID_IScriptControl
, (void**)&sc
);
2040 ok(hr
== S_OK
, "Failed to create IScriptControl interface: 0x%08x.\n", hr
);
2042 SET_EXPECT(CreateInstance
);
2043 SET_EXPECT(SetInterfaceSafetyOptions
);
2044 SET_EXPECT(SetScriptSite
);
2045 SET_EXPECT(QI_IActiveScriptParse
);
2046 SET_EXPECT(InitNew
);
2047 str
= SysAllocString(L
"testscript");
2048 hr
= IScriptControl_put_Language(sc
, str
);
2049 ok(hr
== S_OK
, "IScriptControl_put_Language failed: 0x%08x.\n", hr
);
2051 CHECK_CALLED(CreateInstance
);
2052 CHECK_CALLED(SetInterfaceSafetyOptions
);
2053 CHECK_CALLED(SetScriptSite
);
2054 CHECK_CALLED(QI_IActiveScriptParse
);
2055 CHECK_CALLED(InitNew
);
2057 SET_EXPECT(SetScriptState_STARTED
);
2058 SET_EXPECT(GetScriptDispatch
);
2059 SET_EXPECT(QI_IDispatchEx
);
2060 SET_EXPECT(GetIDsOfNames
);
2062 Dispatch_expected_name
= SysAllocString(L
"function");
2063 hr
= IScriptControl_Run(sc
, Dispatch_expected_name
, ¶ms
, &var
);
2064 ok(hr
== S_OK
, "IScriptControl_Run failed: 0x%08x.\n", hr
);
2065 ok((V_VT(&var
) == VT_R8
) && (V_R8(&var
) == 4.2), "V_VT(var) = %d, V_R8(var) = %lf.\n", V_VT(&var
), V_R8(&var
));
2066 SysFreeString(Dispatch_expected_name
);
2067 CHECK_CALLED(SetScriptState_STARTED
);
2068 CHECK_CALLED(GetScriptDispatch
);
2069 CHECK_CALLED(QI_IDispatchEx
);
2070 CHECK_CALLED(GetIDsOfNames
);
2071 CHECK_CALLED(Invoke
);
2073 /* GetScriptDispatch is cached and not called again */
2074 CLEAR_CALLED(GetScriptDispatch
);
2075 SET_EXPECT(QI_IDispatchEx
);
2076 SET_EXPECT(GetIDsOfNames
);
2078 Dispatch_expected_name
= SysAllocString(L
"BarFoo");
2079 hr
= IScriptControl_Run(sc
, Dispatch_expected_name
, ¶ms
, &var
);
2080 ok(hr
== S_OK
, "IScriptControl_Run failed: 0x%08x.\n", hr
);
2081 SysFreeString(Dispatch_expected_name
);
2082 CHECK_NOT_CALLED(GetScriptDispatch
);
2083 CHECK_CALLED(QI_IDispatchEx
);
2084 CHECK_CALLED(GetIDsOfNames
);
2085 CHECK_CALLED(Invoke
);
2087 /* Make DispatchEx available */
2088 DispatchEx_available
= TRUE
;
2089 CLEAR_CALLED(GetScriptDispatch
);
2090 SET_EXPECT(QI_IDispatchEx
);
2091 SET_EXPECT(GetIDsOfNames
);
2092 SET_EXPECT(InvokeEx
);
2093 Dispatch_expected_name
= SysAllocString(L
"FooBar");
2094 hr
= IScriptControl_Run(sc
, Dispatch_expected_name
, ¶ms
, &var
);
2095 ok(hr
== S_OK
, "IScriptControl_Run failed: 0x%08x.\n", hr
);
2096 ok((V_VT(&var
) == VT_I2
) && (V_I2(&var
) == 42), "V_VT(var) = %d, V_I2(var) = %d.\n", V_VT(&var
), V_I2(&var
));
2097 SysFreeString(Dispatch_expected_name
);
2098 CHECK_NOT_CALLED(GetScriptDispatch
);
2099 CHECK_CALLED(QI_IDispatchEx
);
2100 CHECK_CALLED(GetIDsOfNames
);
2101 CHECK_CALLED(InvokeEx
);
2103 /* QueryInterface for IDispatchEx is always called and not cached */
2104 CLEAR_CALLED(GetScriptDispatch
);
2105 SET_EXPECT(QI_IDispatchEx
);
2106 SET_EXPECT(GetIDsOfNames
);
2107 SET_EXPECT(InvokeEx
);
2108 Dispatch_expected_name
= SysAllocString(L
"1");
2109 hr
= IScriptControl_Run(sc
, Dispatch_expected_name
, ¶ms
, &var
);
2110 ok(hr
== S_OK
, "IScriptControl_Run failed: 0x%08x.\n", hr
);
2111 SysFreeString(Dispatch_expected_name
);
2112 CHECK_NOT_CALLED(GetScriptDispatch
);
2113 CHECK_CALLED(QI_IDispatchEx
);
2114 CHECK_CALLED(GetIDsOfNames
);
2115 CHECK_CALLED(InvokeEx
);
2116 DispatchEx_available
= FALSE
;
2118 IActiveScriptSite_Release(site
);
2121 IScriptControl_Release(sc
);
2122 CHECK_CALLED(Close
);
2125 SafeArrayDestroy(params
);
2128 START_TEST(msscript
)
2135 hr
= CoCreateInstance(&CLSID_ScriptControl
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
2136 &IID_IUnknown
, (void**)&unk
);
2138 win_skip("Could not create ScriptControl object: %08x\n", hr
);
2141 IUnknown_Release(unk
);
2143 have_custom_engine
= register_script_engine();
2144 if (!have_custom_engine
)
2145 skip("Could not register TestScript engine.\n");
2148 test_persiststreaminit();
2151 test_connectionpoints();
2152 test_quickactivate();
2154 test_pointerinactive();
2159 test_UseSafeSubset();
2161 test_IScriptControl_Eval();
2162 test_IScriptControl_AddCode();
2163 test_IScriptControl_ExecuteStatement();
2164 test_IScriptControl_Run();
2166 init_registry(FALSE
);