msscript.ocx: Implement parse_script_text on top of modules.
[wine.git] / dlls / msscript.ocx / tests / msscript.c
blob807f82eee3c27ff4d852b562167f6a7a0522d6ad
1 /*
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
19 #define COBJMACROS
20 #define CONST_VTABLE
22 #include <initguid.h>
23 #include <ole2.h>
24 #include <olectl.h>
25 #include "dispex.h"
26 #include "activscp.h"
27 #include "activdbg.h"
28 #include "objsafe.h"
30 #include "msscript.h"
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};
39 #ifdef _WIN64
41 #define CTXARG_T DWORDLONG
42 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
43 #define IActiveScriptSiteDebug_Release IActiveScriptSiteDebug64_Release
45 #else
47 #define CTXARG_T DWORD
48 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
49 #define IActiveScriptSiteDebug_Release IActiveScriptSiteDebug32_Release
51 #endif
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) \
60 do { \
61 ok(expect_ ##func, "unexpected call " #func "\n"); \
62 called_ ## func = TRUE; \
63 }while(0)
65 #define CHECK_EXPECT(func) \
66 do { \
67 CHECK_EXPECT2(func); \
68 expect_ ## func = FALSE; \
69 }while(0)
71 #define CHECK_CALLED(func) \
72 do { \
73 ok(called_ ## func, "expected " #func "\n"); \
74 expect_ ## func = called_ ## func = FALSE; \
75 }while(0)
77 #define CHECK_CALLED_BROKEN(func) \
78 do { \
79 ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
80 expect_ ## func = called_ ## func = FALSE; \
81 }while(0)
83 #define CHECK_NOT_CALLED(func) \
84 do { \
85 ok(!called_ ## func, "unexpected " #func "\n"); \
86 expect_ ## func = called_ ## func = FALSE; \
87 }while(0)
89 #define CLEAR_CALLED(func) \
90 expect_ ## func = called_ ## func = FALSE
92 DEFINE_EXPECT(CreateInstance);
93 DEFINE_EXPECT(SetInterfaceSafetyOptions);
94 DEFINE_EXPECT(InitNew);
95 DEFINE_EXPECT(Close);
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(GetScriptState);
103 DEFINE_EXPECT(SetScriptState_INITIALIZED);
104 DEFINE_EXPECT(SetScriptState_STARTED);
105 DEFINE_EXPECT(SetScriptState_CONNECTED);
106 DEFINE_EXPECT(ParseScriptText);
107 DEFINE_EXPECT(AddNamedItem);
108 DEFINE_EXPECT(GetScriptDispatch);
110 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
111 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
113 ULONG rc;
114 IUnknown_AddRef(obj);
115 rc = IUnknown_Release(obj);
116 ok_(__FILE__,line)(rc == ref, "expected refcount %d, got %d\n", ref, rc);
119 static IActiveScriptSite *site;
120 static SCRIPTSTATE state;
122 static HRESULT WINAPI ActiveScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
124 *ppv = NULL;
125 ok(0, "unexpected call\n");
126 return E_NOINTERFACE;
129 static ULONG WINAPI ActiveScriptParse_AddRef(IActiveScriptParse *iface)
131 return 2;
134 static ULONG WINAPI ActiveScriptParse_Release(IActiveScriptParse *iface)
136 return 1;
139 static HRESULT WINAPI ActiveScriptParse_InitNew(IActiveScriptParse *iface)
141 CHECK_EXPECT(InitNew);
142 return S_OK;
145 static HRESULT WINAPI ActiveScriptParse_AddScriptlet(IActiveScriptParse *iface,
146 LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
147 LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
148 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
149 BSTR *pbstrName, EXCEPINFO *pexcepinfo)
151 ok(0, "unexpected call\n");
152 return E_NOTIMPL;
155 static const WCHAR *parse_item_name;
156 static DWORD parse_flags = 0;
158 static HRESULT WINAPI ActiveScriptParse_ParseScriptText(IActiveScriptParse *iface,
159 LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
160 LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
161 DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
163 ok(!!pstrCode, "got wrong pointer: %p.\n", pstrCode);
164 ok(!lstrcmpW(pstrItemName, parse_item_name), "got wrong item name: %s (expected %s).\n",
165 wine_dbgstr_w(pstrItemName), wine_dbgstr_w(parse_item_name));
166 ok(!punkContext, "got wrong pointer: %p.\n", punkContext);
167 ok(!pstrDelimiter, "got wrong pointer: %p.\n", pstrDelimiter);
168 ok(!dwSourceContextCookie, "got wrong value: %s.\n", wine_dbgstr_longlong(dwSourceContextCookie));
169 ok(ulStartingLine == 1, "got wrong value: %d.\n", ulStartingLine);
170 ok(!!pexcepinfo, "got wrong pointer: %p.\n", pexcepinfo);
171 ok(dwFlags == parse_flags, "got wrong flags: %x.\n", dwFlags);
172 if (parse_flags == SCRIPTTEXT_ISEXPRESSION)
173 ok(!!pvarResult, "got wrong pointer: %p.\n", pvarResult);
174 else
175 ok(!pvarResult, "got wrong pointer: %p.\n", pvarResult);
177 CHECK_EXPECT(ParseScriptText);
178 return S_OK;
181 static const IActiveScriptParseVtbl ActiveScriptParseVtbl = {
182 ActiveScriptParse_QueryInterface,
183 ActiveScriptParse_AddRef,
184 ActiveScriptParse_Release,
185 ActiveScriptParse_InitNew,
186 ActiveScriptParse_AddScriptlet,
187 ActiveScriptParse_ParseScriptText
190 static IActiveScriptParse ActiveScriptParse = { &ActiveScriptParseVtbl };
192 static HRESULT WINAPI ObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
194 *ppv = NULL;
195 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid));
196 return E_NOINTERFACE;
199 static ULONG WINAPI ObjectSafety_AddRef(IObjectSafety *iface)
201 return 2;
204 static ULONG WINAPI ObjectSafety_Release(IObjectSafety *iface)
206 return 1;
209 static HRESULT WINAPI ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
210 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
212 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
213 return E_NOTIMPL;
216 static HRESULT WINAPI ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
217 DWORD mask, DWORD options)
219 CHECK_EXPECT(SetInterfaceSafetyOptions);
221 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
223 ok(mask == INTERFACESAFE_FOR_UNTRUSTED_DATA, "option mask = %x\n", mask);
224 ok(options == 0, "options = %x\n", options);
226 return S_OK;
229 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
230 ObjectSafety_QueryInterface,
231 ObjectSafety_AddRef,
232 ObjectSafety_Release,
233 ObjectSafety_GetInterfaceSafetyOptions,
234 ObjectSafety_SetInterfaceSafetyOptions
237 static IObjectSafety ObjectSafety = { &ObjectSafetyVtbl };
239 static BOOL DispatchEx_available = FALSE;
240 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
242 *ppv = NULL;
244 if (IsEqualGUID(&IID_IDispatchEx, riid))
246 CHECK_EXPECT(QI_IDispatchEx);
247 if (DispatchEx_available)
249 *ppv = iface;
250 return S_OK;
252 return E_NOINTERFACE;
255 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
256 return E_NOINTERFACE;
259 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
261 return 2;
264 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
266 return 1;
269 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
271 ok(0, "unexpected call\n");
272 return E_NOTIMPL;
275 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
277 ok(0, "unexpected call\n");
278 return E_NOTIMPL;
281 static BSTR Dispatch_expected_name;
282 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid, LPOLESTR *rgszNames,
283 UINT cNames, LCID lcid, DISPID *rgDispId)
285 CHECK_EXPECT(GetIDsOfNames);
286 ok(IsEqualGUID(&IID_NULL, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
287 ok(lcid == LOCALE_USER_DEFAULT, "unexpected lcid %u\n", lcid);
288 ok(cNames == 1, "unexpected cNames %u\n", cNames);
289 ok(Dispatch_expected_name && !lstrcmpW(rgszNames[0], Dispatch_expected_name),
290 "unexpected name %s (expected %s).\n", wine_dbgstr_w(rgszNames[0]), wine_dbgstr_w(Dispatch_expected_name));
292 *rgDispId = 0xdeadbeef;
293 return S_OK;
296 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
297 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
299 CHECK_EXPECT(Invoke);
300 ok(IsEqualGUID(&IID_NULL, riid), "unexpected riid %s.\n", wine_dbgstr_guid(riid));
301 ok(lcid == LOCALE_USER_DEFAULT, "unexpected lcid %u.\n", lcid);
302 ok(wFlags == DISPATCH_METHOD, "unexpected wFlags %u.\n", wFlags);
303 ok(dispIdMember == 0xdeadbeef, "unexpected dispIdMember %d.\n", dispIdMember);
304 ok(pDispParams->cNamedArgs == 0, "unexpected number of named args %u.\n", pDispParams->cNamedArgs);
305 ok(!pDispParams->rgdispidNamedArgs, "unexpected named args array %p\n", pDispParams->rgdispidNamedArgs);
306 ok(pDispParams->cArgs == 2, "unexpected number of args %u.\n", pDispParams->cArgs);
307 ok(!!pDispParams->rgvarg, "unexpected NULL rgvarg.\n");
308 if (pDispParams->rgvarg && pDispParams->cArgs >= 2)
310 ok(V_VT(pDispParams->rgvarg + 1) == VT_I4 && V_I4(pDispParams->rgvarg + 1) == 10,
311 "unexpected first parameter V_VT = %d, V_I4 = %d.\n",
312 V_VT(pDispParams->rgvarg + 1), V_I4(pDispParams->rgvarg + 1));
313 ok(V_VT(pDispParams->rgvarg) == VT_I4 && V_I4(pDispParams->rgvarg) == 3,
314 "unexpected second parameter V_VT = %d, V_I4 = %d.\n",
315 V_VT(pDispParams->rgvarg), V_I4(pDispParams->rgvarg));
318 V_VT(pVarResult) = VT_R8;
319 V_R8(pVarResult) = 4.2;
320 return S_OK;
323 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
325 ok(0, "unexpected call\n");
326 return E_NOTIMPL;
329 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags,
330 DISPPARAMS *pdp, VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
332 CHECK_EXPECT(InvokeEx);
333 ok(lcid == LOCALE_USER_DEFAULT, "unexpected lcid %u.\n", lcid);
334 ok(wFlags == DISPATCH_METHOD, "unexpected wFlags %u.\n", wFlags);
335 ok(id == 0xdeadbeef, "unexpected id %d.\n", id);
336 ok(pdp->cNamedArgs == 0, "unexpected number of named args %u.\n", pdp->cNamedArgs);
337 ok(!pdp->rgdispidNamedArgs, "unexpected named args array %p.\n", pdp->rgdispidNamedArgs);
338 ok(pdp->cArgs == 2, "unexpected number of args %u.\n", pdp->cArgs);
339 ok(!!pdp->rgvarg, "unexpected NULL rgvarg.\n");
340 if (pdp->rgvarg && pdp->cArgs >= 2)
342 ok(V_VT(pdp->rgvarg + 1) == VT_I4 && V_I4(pdp->rgvarg + 1) == 10,
343 "unexpected first parameter V_VT = %d, V_I4 = %d.\n",
344 V_VT(pdp->rgvarg + 1), V_I4(pdp->rgvarg + 1));
345 ok(V_VT(pdp->rgvarg) == VT_I4 && V_I4(pdp->rgvarg) == 3,
346 "unexpected second parameter V_VT = %d, V_I4 = %d.\n",
347 V_VT(pdp->rgvarg), V_I4(pdp->rgvarg));
350 V_VT(pvarRes) = VT_I2;
351 V_I2(pvarRes) = 42;
352 return S_OK;
355 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
357 ok(0, "unexpected call\n");
358 return E_NOTIMPL;
361 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
363 ok(0, "unexpected call\n");
364 return E_NOTIMPL;
367 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch,
368 DWORD *pgrfdex)
370 ok(0, "unexpected call\n");
371 return E_NOTIMPL;
374 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
376 ok(0, "unexpected call\n");
377 return E_NOTIMPL;
380 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
382 ok(0, "unexpected call\n");
383 return E_NOTIMPL;
386 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
388 ok(0, "unexpected call\n");
389 return E_NOTIMPL;
392 static const IDispatchExVtbl DispatchExVtbl = {
393 DispatchEx_QueryInterface,
394 DispatchEx_AddRef,
395 DispatchEx_Release,
396 DispatchEx_GetTypeInfoCount,
397 DispatchEx_GetTypeInfo,
398 DispatchEx_GetIDsOfNames,
399 DispatchEx_Invoke,
400 DispatchEx_GetDispID,
401 DispatchEx_InvokeEx,
402 DispatchEx_DeleteMemberByName,
403 DispatchEx_DeleteMemberByDispID,
404 DispatchEx_GetMemberProperties,
405 DispatchEx_GetMemberName,
406 DispatchEx_GetNextDispID,
407 DispatchEx_GetNameSpaceParent
410 static IDispatchEx DispatchEx = { &DispatchExVtbl };
412 static HRESULT WINAPI ActiveScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
414 *ppv = NULL;
416 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IActiveScript, riid)) {
417 *ppv = iface;
418 return S_OK;
421 if(IsEqualGUID(&IID_IObjectSafety, riid)) {
422 *ppv = &ObjectSafety;
423 return S_OK;
426 if(IsEqualGUID(&IID_IActiveScriptParse, riid)) {
427 CHECK_EXPECT(QI_IActiveScriptParse);
428 *ppv = &ActiveScriptParse;
429 return S_OK;
432 if(IsEqualGUID(&IID_IActiveScriptGarbageCollector, riid))
433 return E_NOINTERFACE;
435 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
436 return E_NOINTERFACE;
439 static ULONG WINAPI ActiveScript_AddRef(IActiveScript *iface)
441 return 2;
444 static ULONG WINAPI ActiveScript_Release(IActiveScript *iface)
446 return 1;
449 static HRESULT WINAPI ActiveScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
451 IActiveScriptSiteInterruptPoll *poll;
452 IActiveScriptSiteWindow *window;
453 IActiveScriptSiteDebug *debug;
454 IServiceProvider *service;
455 ICanHandleException *canexception;
456 LCID lcid;
457 HRESULT hres;
459 CHECK_EXPECT(SetScriptSite);
461 ok(pass != NULL, "pass == NULL\n");
463 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteInterruptPoll, (void**)&poll);
464 ok(hres == E_NOINTERFACE, "Got IActiveScriptSiteInterruptPoll interface: %08x\n", hres);
466 hres = IActiveScriptSite_GetLCID(pass, &lcid);
467 ok(hres == S_OK, "GetLCID failed: %08x\n", hres);
469 hres = IActiveScriptSite_OnStateChange(pass, (state = SCRIPTSTATE_INITIALIZED));
470 ok(hres == E_NOTIMPL, "OnStateChange failed: %08x\n", hres);
472 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteDebug, (void**)&debug);
473 ok(hres == E_NOINTERFACE, "Got IActiveScriptSiteDebug interface: %08x\n", hres);
475 hres = IActiveScriptSite_QueryInterface(pass, &IID_ICanHandleException, (void**)&canexception);
476 ok(hres == E_NOINTERFACE, "Got IID_ICanHandleException interface: %08x\n", hres);
478 hres = IActiveScriptSite_QueryInterface(pass, &IID_IServiceProvider, (void**)&service);
479 ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
480 IServiceProvider_Release(service);
482 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteWindow, (void**)&window);
483 ok(hres == S_OK, "Could not get IActiveScriptSiteWindow interface: %08x\n", hres);
484 IActiveScriptSiteWindow_Release(window);
486 if (site)
487 IActiveScriptSite_Release(site);
488 site = pass;
489 IActiveScriptSite_AddRef(site);
491 return S_OK;
494 static HRESULT WINAPI ActiveScript_GetScriptSite(IActiveScript *iface, REFIID riid,
495 void **ppvObject)
497 ok(0, "unexpected call\n");
498 return E_NOTIMPL;
501 static HRESULT WINAPI ActiveScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
503 switch(ss)
505 case SCRIPTSTATE_INITIALIZED:
506 CHECK_EXPECT(SetScriptState_INITIALIZED);
507 return S_OK;
508 case SCRIPTSTATE_STARTED:
509 CHECK_EXPECT(SetScriptState_STARTED);
510 return S_OK;
511 case SCRIPTSTATE_CONNECTED:
512 CHECK_EXPECT(SetScriptState_CONNECTED);
513 return S_OK;
514 default:
515 ok(0, "unexpected call, state %u\n", ss);
516 return E_NOTIMPL;
520 static SCRIPTSTATE emulated_script_state;
522 static HRESULT WINAPI ActiveScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
524 CHECK_EXPECT(GetScriptState);
525 *pssState = emulated_script_state;
526 return S_OK;
529 static HRESULT WINAPI ActiveScript_Close(IActiveScript *iface)
531 CHECK_EXPECT(Close);
532 return E_NOTIMPL;
535 static const WCHAR *AddNamedItem_expected_name;
536 static DWORD AddNamedItem_expected_flags;
537 static HRESULT WINAPI ActiveScript_AddNamedItem(IActiveScript *iface, LPCOLESTR name, DWORD flags)
539 CHECK_EXPECT(AddNamedItem);
540 ok(!lstrcmpW(name, AddNamedItem_expected_name), "got name %s\n", wine_dbgstr_w(name));
541 ok(flags == AddNamedItem_expected_flags, "got flags %#x\n", flags);
542 return S_OK;
545 static HRESULT WINAPI ActiveScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
546 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
548 ok(0, "unexpected call\n");
549 return E_NOTIMPL;
552 static HRESULT WINAPI ActiveScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
553 IDispatch **ppdisp)
555 CHECK_EXPECT(GetScriptDispatch);
556 ok(!pstrItemName, "pstrItemName not NULL, got %s.\n", wine_dbgstr_w(pstrItemName));
558 *ppdisp = (IDispatch*)&DispatchEx;
560 return S_OK;
563 static HRESULT WINAPI ActiveScript_GetCurrentScriptThreadID(IActiveScript *iface,
564 SCRIPTTHREADID *pstridThread)
566 ok(0, "unexpected call\n");
567 return E_NOTIMPL;
570 static HRESULT WINAPI ActiveScript_GetScriptThreadID(IActiveScript *iface,
571 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
573 ok(0, "unexpected call\n");
574 return E_NOTIMPL;
577 static HRESULT WINAPI ActiveScript_GetScriptThreadState(IActiveScript *iface,
578 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
580 ok(0, "unexpected call\n");
581 return E_NOTIMPL;
584 static HRESULT WINAPI ActiveScript_InterruptScriptThread(IActiveScript *iface,
585 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
587 ok(0, "unexpected call\n");
588 return E_NOTIMPL;
591 static HRESULT WINAPI ActiveScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
593 ok(0, "unexpected call\n");
594 return E_NOTIMPL;
597 static const IActiveScriptVtbl ActiveScriptVtbl = {
598 ActiveScript_QueryInterface,
599 ActiveScript_AddRef,
600 ActiveScript_Release,
601 ActiveScript_SetScriptSite,
602 ActiveScript_GetScriptSite,
603 ActiveScript_SetScriptState,
604 ActiveScript_GetScriptState,
605 ActiveScript_Close,
606 ActiveScript_AddNamedItem,
607 ActiveScript_AddTypeLib,
608 ActiveScript_GetScriptDispatch,
609 ActiveScript_GetCurrentScriptThreadID,
610 ActiveScript_GetScriptThreadID,
611 ActiveScript_GetScriptThreadState,
612 ActiveScript_InterruptScriptThread,
613 ActiveScript_Clone
616 static IActiveScript ActiveScript = { &ActiveScriptVtbl };
618 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
620 *ppv = NULL;
622 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
623 *ppv = iface;
624 return S_OK;
627 if(IsEqualGUID(&IID_IMarshal, riid))
628 return E_NOINTERFACE;
630 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
631 return E_NOINTERFACE;
634 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
636 return 2;
639 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
641 return 1;
644 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
646 CHECK_EXPECT(CreateInstance);
648 ok(!outer, "outer = %p\n", outer);
649 ok(IsEqualGUID(&IID_IActiveScript, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
650 *ppv = &ActiveScript;
651 site = NULL;
652 return S_OK;
655 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
657 ok(0, "unexpected call\n");
658 return S_OK;
661 static const IClassFactoryVtbl ClassFactoryVtbl = {
662 ClassFactory_QueryInterface,
663 ClassFactory_AddRef,
664 ClassFactory_Release,
665 ClassFactory_CreateInstance,
666 ClassFactory_LockServer
669 static IClassFactory script_cf = { &ClassFactoryVtbl };
671 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
673 HKEY hkey;
674 DWORD res;
676 if(!init) {
677 RegDeleteKeyA(HKEY_CLASSES_ROOT, key_name);
678 return TRUE;
681 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
682 if(res != ERROR_SUCCESS)
683 return FALSE;
685 if(def_value)
686 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
688 RegCloseKey(hkey);
690 return res == ERROR_SUCCESS;
693 static BOOL init_registry(BOOL init)
695 return init_key("TestScript\\CLSID", TESTSCRIPT_CLSID, init)
696 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}",
697 NULL, init)
698 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
699 NULL, init);
702 static BOOL register_script_engine(void)
704 DWORD regid;
705 HRESULT hres;
707 if(!init_registry(TRUE)) {
708 init_registry(FALSE);
709 return FALSE;
712 hres = CoRegisterClassObject(&CLSID_TestScript, (IUnknown *)&script_cf,
713 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
714 ok(hres == S_OK, "Could not register script engine: %08x\n", hres);
716 return TRUE;
719 static BOOL have_custom_engine;
721 static HRESULT WINAPI OleClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **obj)
723 if (IsEqualIID(riid, &IID_IOleClientSite) || IsEqualIID(riid, &IID_IUnknown))
725 *obj = iface;
726 IOleClientSite_AddRef(iface);
727 return S_OK;
730 *obj = NULL;
731 return E_NOINTERFACE;
734 static ULONG WINAPI OleClientSite_AddRef(IOleClientSite *iface)
736 return 2;
739 static ULONG WINAPI OleClientSite_Release(IOleClientSite *iface)
741 return 1;
744 static HRESULT WINAPI OleClientSite_SaveObject(IOleClientSite *iface)
746 return E_NOTIMPL;
749 static HRESULT WINAPI OleClientSite_GetMoniker(IOleClientSite *iface, DWORD assign,
750 DWORD which, IMoniker **moniker)
752 return E_NOTIMPL;
755 static HRESULT WINAPI OleClientSite_GetContainer(IOleClientSite *iface, IOleContainer **container)
757 return E_NOTIMPL;
760 static HRESULT WINAPI OleClientSite_ShowObject(IOleClientSite *iface)
762 return E_NOTIMPL;
765 static HRESULT WINAPI OleClientSite_OnShowWindow(IOleClientSite *iface, BOOL show)
767 return E_NOTIMPL;
770 static HRESULT WINAPI OleClientSite_RequestNewObjectLayout(IOleClientSite *iface)
772 return E_NOTIMPL;
775 static const IOleClientSiteVtbl OleClientSiteVtbl = {
776 OleClientSite_QueryInterface,
777 OleClientSite_AddRef,
778 OleClientSite_Release,
779 OleClientSite_SaveObject,
780 OleClientSite_GetMoniker,
781 OleClientSite_GetContainer,
782 OleClientSite_ShowObject,
783 OleClientSite_OnShowWindow,
784 OleClientSite_RequestNewObjectLayout
787 static IOleClientSite testclientsite = { &OleClientSiteVtbl };
789 static void test_oleobject(void)
791 DWORD status, dpi_x, dpi_y;
792 IOleClientSite *site;
793 IOleObject *obj;
794 SIZEL extent;
795 HRESULT hr;
796 HDC hdc;
798 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
799 &IID_IOleObject, (void**)&obj);
800 ok(hr == S_OK, "got 0x%08x\n", hr);
802 if (0) /* crashes on w2k3 */
803 hr = IOleObject_GetMiscStatus(obj, DVASPECT_CONTENT, NULL);
805 status = 0;
806 hr = IOleObject_GetMiscStatus(obj, DVASPECT_CONTENT, &status);
807 ok(hr == S_OK, "got 0x%08x\n", hr);
808 ok(status != 0, "got 0x%08x\n", status);
810 hr = IOleObject_SetClientSite(obj, &testclientsite);
811 ok(hr == S_OK, "got 0x%08x\n", hr);
813 if (0) /* crashes on w2k3 */
814 hr = IOleObject_GetClientSite(obj, NULL);
816 hr = IOleObject_GetClientSite(obj, &site);
817 ok(hr == S_OK, "got 0x%08x\n", hr);
818 ok(site == &testclientsite, "got %p, %p\n", site, &testclientsite);
819 IOleClientSite_Release(site);
821 hr = IOleObject_SetClientSite(obj, NULL);
822 ok(hr == S_OK, "got 0x%08x\n", hr);
824 hr = IOleObject_GetClientSite(obj, &site);
825 ok(hr == S_OK, "got 0x%08x\n", hr);
826 ok(site == NULL, "got %p\n", site);
828 /* extents */
829 hdc = GetDC(0);
830 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
831 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
832 ReleaseDC(0, hdc);
834 memset(&extent, 0, sizeof(extent));
835 hr = IOleObject_GetExtent(obj, DVASPECT_CONTENT, &extent);
836 ok(hr == S_OK, "got 0x%08x\n", hr);
837 ok(extent.cx == MulDiv(38, 2540, dpi_x), "got %d\n", extent.cx);
838 ok(extent.cy == MulDiv(38, 2540, dpi_y), "got %d\n", extent.cy);
840 extent.cx = extent.cy = 0xdeadbeef;
841 hr = IOleObject_GetExtent(obj, DVASPECT_THUMBNAIL, &extent);
842 ok(hr == DV_E_DVASPECT, "got 0x%08x\n", hr);
843 ok(extent.cx == 0xdeadbeef, "got %d\n", extent.cx);
844 ok(extent.cy == 0xdeadbeef, "got %d\n", extent.cy);
846 extent.cx = extent.cy = 0xdeadbeef;
847 hr = IOleObject_GetExtent(obj, DVASPECT_ICON, &extent);
848 ok(hr == DV_E_DVASPECT, "got 0x%08x\n", hr);
849 ok(extent.cx == 0xdeadbeef, "got %d\n", extent.cx);
850 ok(extent.cy == 0xdeadbeef, "got %d\n", extent.cy);
852 extent.cx = extent.cy = 0xdeadbeef;
853 hr = IOleObject_GetExtent(obj, DVASPECT_DOCPRINT, &extent);
854 ok(hr == DV_E_DVASPECT, "got 0x%08x\n", hr);
855 ok(extent.cx == 0xdeadbeef, "got %d\n", extent.cx);
856 ok(extent.cy == 0xdeadbeef, "got %d\n", extent.cy);
858 IOleObject_Release(obj);
861 static void test_persiststreaminit(void)
863 IPersistStreamInit *init;
864 HRESULT hr;
866 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
867 &IID_IPersistStreamInit, (void**)&init);
868 ok(hr == S_OK, "got 0x%08x\n", hr);
870 IPersistStreamInit_Release(init);
873 static void test_olecontrol(void)
875 IOleControl *olecontrol;
876 CONTROLINFO info;
877 HRESULT hr;
879 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
880 &IID_IOleControl, (void**)&olecontrol);
881 ok(hr == S_OK, "got 0x%08x\n", hr);
883 memset(&info, 0xab, sizeof(info));
884 info.cb = sizeof(info);
885 hr = IOleControl_GetControlInfo(olecontrol, &info);
886 ok(hr == S_OK, "got 0x%08x\n", hr);
887 ok(info.hAccel == NULL, "got %p\n", info.hAccel);
888 ok(info.cAccel == 0, "got %d\n", info.cAccel);
889 ok(info.dwFlags == 0xabababab, "got %x\n", info.dwFlags);
891 memset(&info, 0xab, sizeof(info));
892 info.cb = sizeof(info) - 1;
893 hr = IOleControl_GetControlInfo(olecontrol, &info);
894 ok(hr == S_OK, "got 0x%08x\n", hr);
895 ok(info.hAccel == NULL, "got %p\n", info.hAccel);
896 ok(info.cAccel == 0, "got %d\n", info.cAccel);
897 ok(info.dwFlags == 0xabababab, "got %x\n", info.dwFlags);
899 if (0) /* crashes on win2k3 */
901 hr = IOleControl_GetControlInfo(olecontrol, NULL);
902 ok(hr == E_POINTER, "got 0x%08x\n", hr);
905 IOleControl_Release(olecontrol);
908 static void test_Language(void)
910 static const WCHAR jsW[] = {'J','S','c','r','i','p','t',0};
911 static const WCHAR vb2W[] = {'v','B','s','c','r','i','p','t',0};
912 static const WCHAR dummyW[] = {'d','u','m','m','y',0};
913 IScriptControl *sc;
914 HRESULT hr;
915 BSTR str;
917 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
918 &IID_IScriptControl, (void**)&sc);
919 ok(hr == S_OK, "got 0x%08x\n", hr);
921 hr = IScriptControl_get_Language(sc, NULL);
922 ok(hr == E_POINTER, "got 0x%08x\n", hr);
924 str = (BSTR)0xdeadbeef;
925 hr = IScriptControl_get_Language(sc, &str);
926 ok(hr == S_OK, "got 0x%08x\n", hr);
927 ok(str == NULL, "got %s\n", wine_dbgstr_w(str));
929 str = SysAllocString(vbW);
930 hr = IScriptControl_put_Language(sc, str);
931 ok(hr == S_OK, "got 0x%08x\n", hr);
932 SysFreeString(str);
934 str = SysAllocString(vb2W);
935 hr = IScriptControl_put_Language(sc, str);
936 ok(hr == S_OK, "got 0x%08x\n", hr);
937 SysFreeString(str);
939 hr = IScriptControl_get_Language(sc, &str);
940 ok(hr == S_OK, "got 0x%08x\n", hr);
941 ok(!lstrcmpW(str, vbW), "got %s\n", wine_dbgstr_w(str));
942 SysFreeString(str);
944 str = SysAllocString(dummyW);
945 hr = IScriptControl_put_Language(sc, str);
946 ok(hr == CTL_E_INVALIDPROPERTYVALUE, "got 0x%08x\n", hr);
947 SysFreeString(str);
949 hr = IScriptControl_get_Language(sc, &str);
950 ok(hr == S_OK, "got 0x%08x\n", hr);
951 ok(!lstrcmpW(str, vbW), "got %s\n", wine_dbgstr_w(str));
952 SysFreeString(str);
954 str = SysAllocString(jsW);
955 hr = IScriptControl_put_Language(sc, str);
956 ok(hr == S_OK, "got 0x%08x\n", hr);
957 SysFreeString(str);
959 hr = IScriptControl_get_Language(sc, &str);
960 ok(hr == S_OK, "got 0x%08x\n", hr);
961 ok(!lstrcmpW(str, jsW), "got %s\n", wine_dbgstr_w(str));
962 SysFreeString(str);
964 hr = IScriptControl_put_Language(sc, NULL);
965 ok(hr == S_OK, "got 0x%08x\n", hr);
967 hr = IScriptControl_get_Language(sc, &str);
968 ok(hr == S_OK, "got 0x%08x\n", hr);
969 ok(str == NULL, "got %s\n", wine_dbgstr_w(str));
971 IScriptControl_Release(sc);
973 /* custom script engine */
974 if (have_custom_engine) {
975 static const WCHAR testscriptW[] = {'t','e','s','t','s','c','r','i','p','t',0};
977 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
978 &IID_IScriptControl, (void**)&sc);
979 ok(hr == S_OK, "got 0x%08x\n", hr);
981 SET_EXPECT(CreateInstance);
982 SET_EXPECT(SetInterfaceSafetyOptions);
983 SET_EXPECT(SetScriptSite);
984 SET_EXPECT(QI_IActiveScriptParse);
985 SET_EXPECT(InitNew);
987 str = SysAllocString(testscriptW);
988 hr = IScriptControl_put_Language(sc, str);
989 ok(hr == S_OK, "got 0x%08x\n", hr);
990 SysFreeString(str);
992 CHECK_CALLED(CreateInstance);
993 CHECK_CALLED(SetInterfaceSafetyOptions);
994 CHECK_CALLED(SetScriptSite);
995 CHECK_CALLED(QI_IActiveScriptParse);
996 CHECK_CALLED(InitNew);
997 hr = IScriptControl_get_Language(sc, &str);
998 todo_wine
999 ok(hr == S_OK, "got 0x%08x\n", hr);
1000 if (hr == S_OK)
1001 ok(!lstrcmpW(testscriptW, str), "%s\n", wine_dbgstr_w(str));
1002 SysFreeString(str);
1004 IActiveScriptSite_Release(site);
1006 SET_EXPECT(Close);
1008 IScriptControl_Release(sc);
1010 CHECK_CALLED(Close);
1014 static void test_connectionpoints(void)
1016 IConnectionPointContainer *container, *container2;
1017 IConnectionPoint *cp;
1018 IScriptControl *sc;
1019 HRESULT hr;
1020 IID iid;
1022 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1023 &IID_IScriptControl, (void**)&sc);
1024 ok(hr == S_OK, "got 0x%08x\n", hr);
1026 EXPECT_REF(sc, 1);
1027 hr = IScriptControl_QueryInterface(sc, &IID_IConnectionPointContainer, (void**)&container);
1028 ok(hr == S_OK, "got 0x%08x\n", hr);
1029 EXPECT_REF(sc, 2);
1030 EXPECT_REF(container, 2);
1032 hr = IConnectionPointContainer_FindConnectionPoint(container, &IID_IPropertyNotifySink, &cp);
1033 ok(hr == S_OK, "got 0x%08x\n", hr);
1035 if (0) /* crashes on win2k3 */
1037 hr = IConnectionPoint_GetConnectionPointContainer(cp, NULL);
1038 ok(hr == E_POINTER, "got 0x%08x\n", hr);
1041 hr = IConnectionPoint_GetConnectionInterface(cp, &iid);
1042 ok(hr == S_OK, "got 0x%08x\n", hr);
1043 ok(IsEqualIID(&iid, &IID_IPropertyNotifySink), "got %s\n", wine_dbgstr_guid(&iid));
1045 hr = IConnectionPoint_GetConnectionPointContainer(cp, &container2);
1046 ok(hr == S_OK, "got 0x%08x\n", hr);
1047 ok(container2 == container, "got %p, expected %p\n", container2, container);
1048 IConnectionPointContainer_Release(container2);
1050 IConnectionPoint_Release(cp);
1052 hr = IConnectionPointContainer_FindConnectionPoint(container, &DIID_DScriptControlSource, &cp);
1053 ok(hr == S_OK, "got 0x%08x\n", hr);
1055 if (0) /* crashes on win2k3 */
1057 hr = IConnectionPoint_GetConnectionPointContainer(cp, NULL);
1058 ok(hr == E_POINTER, "got 0x%08x\n", hr);
1061 hr = IConnectionPoint_GetConnectionInterface(cp, &iid);
1062 ok(hr == S_OK, "got 0x%08x\n", hr);
1063 ok(IsEqualIID(&iid, &DIID_DScriptControlSource), "got %s\n", wine_dbgstr_guid(&iid));
1065 hr = IConnectionPoint_GetConnectionPointContainer(cp, &container2);
1066 ok(hr == S_OK, "got 0x%08x\n", hr);
1067 ok(container2 == container, "got %p, expected %p\n", container2, container);
1068 IConnectionPointContainer_Release(container2);
1070 IConnectionPoint_Release(cp);
1072 IConnectionPointContainer_Release(container);
1073 IScriptControl_Release(sc);
1076 static void test_quickactivate(void)
1078 IScriptControl *sc;
1079 IQuickActivate *qa;
1080 HRESULT hr;
1082 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1083 &IID_IScriptControl, (void**)&sc);
1084 ok(hr == S_OK, "got 0x%08x\n", hr);
1086 hr = IScriptControl_QueryInterface(sc, &IID_IQuickActivate, (void**)&qa);
1087 ok(hr == S_OK, "got 0x%08x\n", hr);
1089 IQuickActivate_Release(qa);
1090 IScriptControl_Release(sc);
1093 static void test_viewobject(void)
1095 DWORD status, aspect, flags;
1096 IViewObjectEx *viewex;
1097 IScriptControl *sc;
1098 IViewObject *view;
1099 IAdviseSink *sink;
1100 HRESULT hr;
1102 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1103 &IID_IScriptControl, (void**)&sc);
1104 ok(hr == S_OK, "got 0x%08x\n", hr);
1106 hr = IScriptControl_QueryInterface(sc, &IID_IViewObject, (void**)&view);
1107 ok(hr == S_OK, "got 0x%08x\n", hr);
1108 IViewObject_Release(view);
1110 hr = IScriptControl_QueryInterface(sc, &IID_IViewObject2, (void**)&view);
1111 ok(hr == S_OK, "got 0x%08x\n", hr);
1113 sink = (IAdviseSink*)0xdeadbeef;
1114 hr = IViewObject_GetAdvise(view, &aspect, &flags, &sink);
1115 ok(hr == S_OK, "got 0x%08x\n", hr);
1116 ok(aspect == DVASPECT_CONTENT, "got %u\n", aspect);
1117 ok(flags == 0, "got %#x\n", flags);
1118 ok(sink == NULL, "got %p\n", sink);
1120 hr = IViewObject_SetAdvise(view, DVASPECT_CONTENT, 0, NULL);
1121 ok(hr == S_OK, "got 0x%08x\n", hr);
1123 hr = IViewObject_SetAdvise(view, DVASPECT_THUMBNAIL, 0, NULL);
1124 ok(hr == DV_E_DVASPECT, "got 0x%08x\n", hr);
1126 hr = IViewObject_SetAdvise(view, DVASPECT_ICON, 0, NULL);
1127 ok(hr == DV_E_DVASPECT, "got 0x%08x\n", hr);
1129 hr = IViewObject_SetAdvise(view, DVASPECT_DOCPRINT, 0, NULL);
1130 ok(hr == DV_E_DVASPECT, "got 0x%08x\n", hr);
1132 sink = (IAdviseSink*)0xdeadbeef;
1133 hr = IViewObject_GetAdvise(view, &aspect, &flags, &sink);
1134 ok(hr == S_OK, "got 0x%08x\n", hr);
1135 ok(aspect == DVASPECT_CONTENT, "got %u\n", aspect);
1136 ok(flags == 0, "got %#x\n", flags);
1137 ok(sink == NULL, "got %p\n", sink);
1139 IViewObject_Release(view);
1141 hr = IScriptControl_QueryInterface(sc, &IID_IViewObjectEx, (void**)&viewex);
1142 ok(hr == S_OK, "got 0x%08x\n", hr);
1144 if (0) /* crashes */
1145 hr = IViewObjectEx_GetViewStatus(viewex, NULL);
1147 status = 0;
1148 hr = IViewObjectEx_GetViewStatus(viewex, &status);
1149 ok(hr == S_OK, "got 0x%08x\n", hr);
1150 ok(status == VIEWSTATUS_OPAQUE, "got %#x\n", status);
1152 IViewObjectEx_Release(viewex);
1154 IScriptControl_Release(sc);
1157 static void test_pointerinactive(void)
1159 IPointerInactive *pi;
1160 IScriptControl *sc;
1161 DWORD policy;
1162 HRESULT hr;
1164 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1165 &IID_IScriptControl, (void**)&sc);
1166 ok(hr == S_OK, "got 0x%08x\n", hr);
1168 hr = IScriptControl_QueryInterface(sc, &IID_IPointerInactive, (void**)&pi);
1169 ok(hr == S_OK, "got 0x%08x\n", hr);
1171 if (0) /* crashes w2k3 */
1172 hr = IPointerInactive_GetActivationPolicy(pi, NULL);
1174 policy = 123;
1175 hr = IPointerInactive_GetActivationPolicy(pi, &policy);
1176 ok(hr == S_OK, "got 0x%08x\n", hr);
1177 ok(policy == 0, "got %#x\n", policy);
1179 IPointerInactive_Release(pi);
1180 IScriptControl_Release(sc);
1183 static void test_timeout(void)
1185 IScriptControl *sc;
1186 HRESULT hr;
1187 LONG val;
1188 BSTR str;
1190 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1191 &IID_IScriptControl, (void**)&sc);
1192 ok(hr == S_OK, "got 0x%08x\n", hr);
1194 hr = IScriptControl_get_Timeout(sc, NULL);
1195 ok(hr == E_POINTER, "got 0x%08x\n", hr);
1197 val = 0;
1198 hr = IScriptControl_get_Timeout(sc, &val);
1199 ok(hr == S_OK, "got 0x%08x\n", hr);
1200 ok(val == 10000, "got %d\n", val);
1202 hr = IScriptControl_put_Timeout(sc, -1);
1203 ok(hr == S_OK, "got 0x%08x\n", hr);
1205 val = 0;
1206 hr = IScriptControl_get_Timeout(sc, &val);
1207 ok(hr == S_OK, "got 0x%08x\n", hr);
1208 ok(val == -1, "got %d\n", val);
1210 hr = IScriptControl_put_Timeout(sc, -2);
1211 ok(hr == CTL_E_INVALIDPROPERTYVALUE, "got 0x%08x\n", hr);
1213 val = 0;
1214 hr = IScriptControl_get_Timeout(sc, &val);
1215 ok(hr == S_OK, "got 0x%08x\n", hr);
1216 ok(val == -1, "got %d\n", val);
1218 hr = IScriptControl_put_Timeout(sc, 0);
1219 ok(hr == S_OK, "got 0x%08x\n", hr);
1221 val = 1;
1222 hr = IScriptControl_get_Timeout(sc, &val);
1223 ok(hr == S_OK, "got 0x%08x\n", hr);
1224 ok(val == 0, "got %d\n", val);
1226 str = SysAllocString(vbW);
1227 hr = IScriptControl_put_Language(sc, str);
1228 ok(hr == S_OK, "got 0x%08x\n", hr);
1229 SysFreeString(str);
1231 val = 1;
1232 hr = IScriptControl_get_Timeout(sc, &val);
1233 ok(hr == S_OK, "got 0x%08x\n", hr);
1234 ok(val == 0, "got %d\n", val);
1236 hr = IScriptControl_put_Timeout(sc, 10000);
1237 ok(hr == S_OK, "got 0x%08x\n", hr);
1239 IScriptControl_Release(sc);
1242 static void test_Reset(void)
1244 IScriptControl *sc;
1245 HRESULT hr;
1246 BSTR str;
1248 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1249 &IID_IScriptControl, (void**)&sc);
1250 ok(hr == S_OK, "got 0x%08x\n", hr);
1252 hr = IScriptControl_Reset(sc);
1253 ok(hr == E_FAIL, "got 0x%08x\n", hr);
1255 str = SysAllocString(vbW);
1256 hr = IScriptControl_put_Language(sc, str);
1257 ok(hr == S_OK, "got 0x%08x\n", hr);
1258 SysFreeString(str);
1260 hr = IScriptControl_Reset(sc);
1261 ok(hr == S_OK, "got 0x%08x\n", hr);
1263 hr = IScriptControl_get_Language(sc, &str);
1264 ok(hr == S_OK, "got 0x%08x\n", hr);
1265 ok(!lstrcmpW(str, vbW), "got %s\n", wine_dbgstr_w(str));
1266 SysFreeString(str);
1268 IScriptControl_Release(sc);
1270 /* custom script engine */
1271 if (have_custom_engine) {
1272 static const WCHAR testscriptW[] = {'t','e','s','t','s','c','r','i','p','t',0};
1274 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1275 &IID_IScriptControl, (void**)&sc);
1276 ok(hr == S_OK, "got 0x%08x\n", hr);
1278 SET_EXPECT(CreateInstance);
1279 SET_EXPECT(SetInterfaceSafetyOptions);
1280 SET_EXPECT(SetScriptSite);
1281 SET_EXPECT(QI_IActiveScriptParse);
1282 SET_EXPECT(InitNew);
1284 str = SysAllocString(testscriptW);
1285 hr = IScriptControl_put_Language(sc, str);
1286 ok(hr == S_OK, "got 0x%08x\n", hr);
1287 SysFreeString(str);
1289 SET_EXPECT(SetScriptState_INITIALIZED);
1290 hr = IScriptControl_Reset(sc);
1291 ok(hr == S_OK, "got 0x%08x\n", hr);
1292 CHECK_CALLED(SetScriptState_INITIALIZED);
1294 SET_EXPECT(SetScriptState_INITIALIZED);
1295 hr = IScriptControl_Reset(sc);
1296 ok(hr == S_OK, "got 0x%08x\n", hr);
1297 CHECK_CALLED(SetScriptState_INITIALIZED);
1299 CHECK_CALLED(SetScriptSite);
1300 IActiveScriptSite_Release(site);
1302 SET_EXPECT(Close);
1304 IScriptControl_Release(sc);
1306 CHECK_CALLED(Close);
1310 static HRESULT WINAPI disp_QI(IDispatch *iface, REFIID riid, void **obj)
1312 if (IsEqualIID(riid, &IID_IDispatch) || IsEqualIID(riid, &IID_IUnknown)) {
1313 *obj = iface;
1314 IDispatch_AddRef(iface);
1315 return S_OK;
1318 *obj = NULL;
1319 return E_NOINTERFACE;
1322 static ULONG WINAPI disp_AddRef(IDispatch *iface)
1324 return 2;
1327 static ULONG WINAPI disp_Release(IDispatch *iface)
1329 return 1;
1332 static HRESULT WINAPI disp_GetTypeInfoCount(IDispatch *iface, UINT *count)
1334 ok(0, "unexpected call\n");
1335 return E_NOTIMPL;
1338 static HRESULT WINAPI disp_GetTypeInfo(IDispatch *iface, UINT index, LCID lcid, ITypeInfo **ti)
1340 ok(0, "unexpected call\n");
1341 return E_NOTIMPL;
1344 static HRESULT WINAPI disp_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *names,
1345 UINT cnames, LCID lcid, DISPID *dispid)
1347 ok(0, "unexpected call\n");
1348 return E_NOTIMPL;
1351 static HRESULT WINAPI disp_Invoke(IDispatch *iface, DISPID dispid, REFIID riid, LCID lcid,
1352 WORD flags, DISPPARAMS *dispparams, VARIANT *result, EXCEPINFO *ei, UINT *arg_err)
1354 ok(0, "unexpected call\n");
1355 return E_NOTIMPL;
1358 static const IDispatchVtbl dispvtbl = {
1359 disp_QI,
1360 disp_AddRef,
1361 disp_Release,
1362 disp_GetTypeInfoCount,
1363 disp_GetTypeInfo,
1364 disp_GetIDsOfNames,
1365 disp_Invoke
1368 static IDispatch testdisp = { &dispvtbl };
1370 static void test_AddObject(void)
1372 static const WCHAR oW[] = {'o',0};
1373 IScriptControl *sc;
1374 BSTR str, objname;
1375 HRESULT hr;
1377 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1378 &IID_IScriptControl, (void**)&sc);
1379 ok(hr == S_OK, "got 0x%08x\n", hr);
1381 objname = SysAllocString(oW);
1382 hr = IScriptControl_AddObject(sc, objname, NULL, VARIANT_FALSE);
1383 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1385 hr = IScriptControl_AddObject(sc, objname, &testdisp, VARIANT_FALSE);
1386 ok(hr == E_FAIL, "got 0x%08x\n", hr);
1388 str = SysAllocString(vbW);
1389 hr = IScriptControl_put_Language(sc, str);
1390 ok(hr == S_OK, "got 0x%08x\n", hr);
1391 SysFreeString(str);
1393 hr = IScriptControl_AddObject(sc, objname, &testdisp, VARIANT_TRUE);
1394 ok(hr == S_OK, "got 0x%08x\n", hr);
1396 hr = IScriptControl_Reset(sc);
1397 ok(hr == S_OK, "got 0x%08x\n", hr);
1399 hr = IScriptControl_AddObject(sc, objname, &testdisp, VARIANT_TRUE);
1400 ok(hr == S_OK, "got 0x%08x\n", hr);
1402 IScriptControl_Release(sc);
1404 /* custom script engine */
1405 if (have_custom_engine) {
1406 static const WCHAR testscriptW[] = {'t','e','s','t','s','c','r','i','p','t',0};
1408 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1409 &IID_IScriptControl, (void**)&sc);
1410 ok(hr == S_OK, "got 0x%08x\n", hr);
1412 SET_EXPECT(CreateInstance);
1413 SET_EXPECT(SetInterfaceSafetyOptions);
1414 SET_EXPECT(SetScriptSite);
1415 SET_EXPECT(QI_IActiveScriptParse);
1416 SET_EXPECT(InitNew);
1418 str = SysAllocString(testscriptW);
1419 hr = IScriptControl_put_Language(sc, str);
1420 ok(hr == S_OK, "got 0x%08x\n", hr);
1421 SysFreeString(str);
1423 hr = IScriptControl_AddObject(sc, objname, NULL, VARIANT_FALSE);
1424 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1426 SET_EXPECT(AddNamedItem);
1427 AddNamedItem_expected_name = objname;
1428 AddNamedItem_expected_flags = SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS;
1429 hr = IScriptControl_AddObject(sc, objname, &testdisp, VARIANT_TRUE);
1430 ok(hr == S_OK, "got 0x%08x\n", hr);
1431 CHECK_CALLED(AddNamedItem);
1433 hr = IScriptControl_AddObject(sc, objname, &testdisp, VARIANT_TRUE);
1434 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1436 CHECK_CALLED(SetScriptSite);
1437 IActiveScriptSite_Release(site);
1439 SET_EXPECT(Close);
1441 IScriptControl_Release(sc);
1443 CHECK_CALLED(Close);
1446 SysFreeString(objname);
1449 static void test_AllowUI(void)
1451 IScriptControl *sc;
1452 VARIANT_BOOL allow;
1453 HRESULT hr;
1455 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1456 &IID_IScriptControl, (void**)&sc);
1457 ok(hr == S_OK, "got 0x%08x\n", hr);
1459 hr = IScriptControl_get_AllowUI(sc, NULL);
1460 ok(hr == E_POINTER, "got 0x%08x\n", hr);
1462 hr = IScriptControl_get_AllowUI(sc, &allow);
1463 ok(hr == S_OK, "got 0x%08x\n", hr);
1464 ok(allow == VARIANT_TRUE, "got %d\n", allow);
1466 hr = IScriptControl_put_AllowUI(sc, VARIANT_FALSE);
1467 ok(hr == S_OK, "got 0x%08x\n", hr);
1469 hr = IScriptControl_get_AllowUI(sc, &allow);
1470 ok(hr == S_OK, "got 0x%08x\n", hr);
1471 ok(allow == VARIANT_FALSE, "got %d\n", allow);
1473 IScriptControl_Release(sc);
1476 static void test_UseSafeSubset(void)
1478 IScriptControl *sc;
1479 VARIANT_BOOL use_safe_subset;
1480 HRESULT hr;
1481 BSTR str;
1483 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1484 &IID_IScriptControl, (void**)&sc);
1485 ok(hr == S_OK, "got 0x%08x\n", hr);
1487 hr = IScriptControl_get_UseSafeSubset(sc, NULL);
1488 ok(hr == E_POINTER, "got 0x%08x\n", hr);
1490 hr = IScriptControl_get_UseSafeSubset(sc, &use_safe_subset);
1491 ok(hr == S_OK, "got 0x%08x\n", hr);
1492 ok(use_safe_subset == VARIANT_FALSE, "got %d\n", use_safe_subset);
1494 hr = IScriptControl_put_UseSafeSubset(sc, VARIANT_TRUE);
1495 ok(hr == S_OK, "got 0x%08x\n", hr);
1497 hr = IScriptControl_get_UseSafeSubset(sc, &use_safe_subset);
1498 ok(hr == S_OK, "got 0x%08x\n", hr);
1499 ok(use_safe_subset == VARIANT_TRUE, "got %d\n", use_safe_subset);
1501 str = SysAllocString(vbW);
1502 hr = IScriptControl_put_Language(sc, str);
1503 ok(hr == S_OK, "got 0x%08x\n", hr);
1504 SysFreeString(str);
1506 hr = IScriptControl_get_UseSafeSubset(sc, &use_safe_subset);
1507 ok(hr == S_OK, "got 0x%08x\n", hr);
1508 ok(use_safe_subset == VARIANT_TRUE, "got %d\n", use_safe_subset);
1510 IScriptControl_Release(sc);
1513 static void test_State(void)
1515 IScriptControl *sc;
1516 ScriptControlStates state;
1517 HRESULT hr;
1518 BSTR str;
1520 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1521 &IID_IScriptControl, (void**)&sc);
1522 ok(hr == S_OK, "got 0x%08x\n", hr);
1524 hr = IScriptControl_get_State(sc, NULL);
1525 ok(hr == E_POINTER, "got 0x%08x\n", hr);
1527 hr = IScriptControl_get_State(sc, &state);
1528 ok(hr == E_FAIL, "got 0x%08x\n", hr);
1530 hr = IScriptControl_put_State(sc, Connected);
1531 ok(hr == E_FAIL, "got 0x%08x\n", hr);
1533 str = SysAllocString(vbW);
1534 hr = IScriptControl_put_Language(sc, str);
1535 ok(hr == S_OK, "got 0x%08x\n", hr);
1536 SysFreeString(str);
1538 hr = IScriptControl_get_State(sc, &state);
1539 ok(hr == S_OK, "got 0x%08x\n", hr);
1540 ok(state == Initialized, "got %d\n", state);
1542 hr = IScriptControl_put_State(sc, Connected);
1543 ok(hr == S_OK, "got 0x%08x\n", hr);
1545 hr = IScriptControl_get_State(sc, &state);
1546 ok(hr == S_OK, "got 0x%08x\n", hr);
1547 ok(state == Connected, "got %d\n", state);
1549 hr = IScriptControl_put_State(sc, 2);
1550 ok(hr == CTL_E_INVALIDPROPERTYVALUE, "got 0x%08x\n", hr);
1552 hr = IScriptControl_get_State(sc, &state);
1553 ok(hr == S_OK, "got 0x%08x\n", hr);
1554 ok(state == Connected, "got %d\n", state);
1556 hr = IScriptControl_put_State(sc, -1);
1557 ok(hr == CTL_E_INVALIDPROPERTYVALUE, "got 0x%08x\n", hr);
1559 hr = IScriptControl_get_State(sc, &state);
1560 ok(hr == S_OK, "got 0x%08x\n", hr);
1561 ok(state == Connected, "got %d\n", state);
1563 IScriptControl_Release(sc);
1565 /* custom script engine */
1566 if (have_custom_engine)
1568 BSTR language, code_str;
1570 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
1571 &IID_IScriptControl, (void **)&sc);
1572 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
1574 SET_EXPECT(CreateInstance);
1575 SET_EXPECT(SetInterfaceSafetyOptions);
1576 SET_EXPECT(SetScriptSite);
1577 SET_EXPECT(QI_IActiveScriptParse);
1578 SET_EXPECT(InitNew);
1580 language = SysAllocString(L"testscript");
1581 hr = IScriptControl_put_Language(sc, language);
1582 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
1583 SysFreeString(language);
1585 CHECK_CALLED(CreateInstance);
1586 CHECK_CALLED(SetInterfaceSafetyOptions);
1587 CHECK_CALLED(SetScriptSite);
1588 CHECK_CALLED(QI_IActiveScriptParse);
1589 CHECK_CALLED(InitNew);
1591 SET_EXPECT(SetScriptState_STARTED);
1592 hr = IScriptControl_put_State(sc, Initialized);
1593 ok(hr == S_OK, "got 0x%08x\n", hr);
1594 CHECK_CALLED(SetScriptState_STARTED);
1596 SET_EXPECT(SetScriptState_STARTED);
1597 hr = IScriptControl_put_State(sc, Initialized);
1598 ok(hr == S_OK, "got 0x%08x\n", hr);
1599 CHECK_CALLED(SetScriptState_STARTED);
1601 SET_EXPECT(SetScriptState_CONNECTED);
1602 hr = IScriptControl_put_State(sc, Connected);
1603 ok(hr == S_OK, "got 0x%08x\n", hr);
1604 CHECK_CALLED(SetScriptState_CONNECTED);
1606 SET_EXPECT(SetScriptState_STARTED);
1607 hr = IScriptControl_put_State(sc, Initialized);
1608 ok(hr == S_OK, "got 0x%08x\n", hr);
1609 CHECK_CALLED(SetScriptState_STARTED);
1611 SET_EXPECT(SetScriptState_STARTED);
1612 SET_EXPECT(ParseScriptText);
1613 parse_item_name = NULL;
1614 parse_flags = SCRIPTTEXT_ISVISIBLE;
1615 code_str = SysAllocString(L"1 + 1");
1616 hr = IScriptControl_AddCode(sc, code_str);
1617 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
1618 SysFreeString(code_str);
1619 CHECK_CALLED(SetScriptState_STARTED);
1620 CHECK_CALLED(ParseScriptText);
1622 emulated_script_state = SCRIPTSTATE_INITIALIZED;
1623 SET_EXPECT(GetScriptState);
1624 hr = IScriptControl_get_State(sc, &state);
1625 ok(hr == S_OK, "got 0x%08x\n", hr);
1626 ok(state == Initialized, "got %d\n", state);
1627 CHECK_CALLED(GetScriptState);
1629 emulated_script_state = SCRIPTSTATE_STARTED;
1630 SET_EXPECT(GetScriptState);
1631 hr = IScriptControl_get_State(sc, &state);
1632 ok(hr == S_OK, "got 0x%08x\n", hr);
1633 ok(state == Initialized, "got %d\n", state);
1634 CHECK_CALLED(GetScriptState);
1636 emulated_script_state = SCRIPTSTATE_CONNECTED;
1637 SET_EXPECT(GetScriptState);
1638 hr = IScriptControl_get_State(sc, &state);
1639 ok(hr == S_OK, "got 0x%08x\n", hr);
1640 ok(state == Connected, "got %d\n", state);
1641 CHECK_CALLED(GetScriptState);
1643 emulated_script_state = SCRIPTSTATE_UNINITIALIZED;
1644 SET_EXPECT(GetScriptState);
1645 hr = IScriptControl_get_State(sc, &state);
1646 ok(hr == E_FAIL, "got 0x%08x\n", hr);
1647 CHECK_CALLED(GetScriptState);
1649 SET_EXPECT(ParseScriptText);
1650 code_str = SysAllocString(L"0x100");
1651 hr = IScriptControl_AddCode(sc, code_str);
1652 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
1653 SysFreeString(code_str);
1654 CHECK_CALLED(ParseScriptText);
1656 IActiveScriptSite_Release(site);
1658 SET_EXPECT(Close);
1659 IScriptControl_Release(sc);
1660 CHECK_CALLED(Close);
1662 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
1663 &IID_IScriptControl, (void **)&sc);
1664 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
1666 SET_EXPECT(CreateInstance);
1667 SET_EXPECT(SetInterfaceSafetyOptions);
1668 SET_EXPECT(SetScriptSite);
1669 SET_EXPECT(QI_IActiveScriptParse);
1670 SET_EXPECT(InitNew);
1672 language = SysAllocString(L"testscript");
1673 hr = IScriptControl_put_Language(sc, language);
1674 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
1675 SysFreeString(language);
1677 CHECK_CALLED(CreateInstance);
1678 CHECK_CALLED(SetInterfaceSafetyOptions);
1679 CHECK_CALLED(SetScriptSite);
1680 CHECK_CALLED(QI_IActiveScriptParse);
1681 CHECK_CALLED(InitNew);
1683 SET_EXPECT(SetScriptState_STARTED);
1684 hr = IScriptControl_put_State(sc, Initialized);
1685 ok(hr == S_OK, "got 0x%08x\n", hr);
1686 CHECK_CALLED(SetScriptState_STARTED);
1688 SET_EXPECT(SetScriptState_STARTED);
1689 hr = IScriptControl_put_State(sc, Initialized);
1690 ok(hr == S_OK, "got 0x%08x\n", hr);
1691 CHECK_CALLED(SetScriptState_STARTED);
1693 SET_EXPECT(SetScriptState_CONNECTED);
1694 hr = IScriptControl_put_State(sc, Connected);
1695 ok(hr == S_OK, "got 0x%08x\n", hr);
1696 CHECK_CALLED(SetScriptState_CONNECTED);
1698 SET_EXPECT(SetScriptState_STARTED);
1699 SET_EXPECT(ParseScriptText);
1700 parse_item_name = NULL;
1701 parse_flags = SCRIPTTEXT_ISVISIBLE;
1702 code_str = SysAllocString(L"1 + 1");
1703 hr = IScriptControl_AddCode(sc, code_str);
1704 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
1705 SysFreeString(code_str);
1706 CHECK_CALLED(SetScriptState_STARTED);
1707 CHECK_CALLED(ParseScriptText);
1709 SET_EXPECT(SetScriptState_CONNECTED);
1710 hr = IScriptControl_put_State(sc, Connected);
1711 ok(hr == S_OK, "got 0x%08x\n", hr);
1712 CHECK_CALLED(SetScriptState_CONNECTED);
1714 SET_EXPECT(ParseScriptText);
1715 code_str = SysAllocString(L"0x100");
1716 hr = IScriptControl_AddCode(sc, code_str);
1717 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
1718 SysFreeString(code_str);
1719 CHECK_CALLED(ParseScriptText);
1721 IActiveScriptSite_Release(site);
1723 SET_EXPECT(Close);
1724 IScriptControl_Release(sc);
1725 CHECK_CALLED(Close);
1729 #define CHECK_ERROR(sc,exp_num) _check_error(sc, exp_num, __LINE__)
1730 static void _check_error(IScriptControl *sc, LONG exp_num, int line)
1732 IScriptError *script_err;
1733 LONG error_num;
1734 HRESULT hr;
1736 hr = IScriptControl_get_Error(sc, &script_err);
1737 ok_(__FILE__,line)(hr == S_OK, "IScriptControl_get_Error failed: 0x%08x.\n", hr);
1738 if (SUCCEEDED(hr))
1740 error_num = 0xdeadbeef;
1741 hr = IScriptError_get_Number(script_err, &error_num);
1742 ok_(__FILE__,line)(hr == S_OK, "IScriptError_get_Number failed: 0x%08x.\n", hr);
1743 ok_(__FILE__,line)(error_num == exp_num, "got wrong error number: %d, expected %d.\n",
1744 error_num, exp_num);
1745 IScriptError_Release(script_err);
1749 static void test_IScriptControl_Eval(void)
1751 IScriptControl *sc;
1752 HRESULT hr;
1753 BSTR script_str, language, expected_string;
1754 VARIANT var;
1755 ScriptControlStates state;
1757 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
1758 &IID_IScriptControl, (void **)&sc);
1759 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
1761 hr = IScriptControl_Eval(sc, NULL, NULL);
1762 ok(hr == E_POINTER, "IScriptControl_Eval returned: 0x%08x.\n", hr);
1764 script_str = SysAllocString(L"1 + 1");
1765 hr = IScriptControl_Eval(sc, script_str, NULL);
1766 ok(hr == E_POINTER, "IScriptControl_Eval returned: 0x%08x.\n", hr);
1767 SysFreeString(script_str);
1769 V_VT(&var) = VT_NULL;
1770 V_I4(&var) = 0xdeadbeef;
1771 hr = IScriptControl_Eval(sc, NULL, &var);
1772 ok(hr == E_FAIL, "IScriptControl_Eval returned: 0x%08x.\n", hr);
1773 ok((V_VT(&var) == VT_EMPTY) && (V_I4(&var) == 0xdeadbeef), "V_VT(var) = %d, V_I4(var) = %d.\n",
1774 V_VT(&var), V_I4(&var));
1775 todo_wine CHECK_ERROR(sc, 0);
1777 script_str = SysAllocString(L"1 + 1");
1778 V_VT(&var) = VT_NULL;
1779 V_I4(&var) = 0xdeadbeef;
1780 hr = IScriptControl_Eval(sc, script_str, &var);
1781 ok(hr == E_FAIL, "IScriptControl_Eval returned: 0x%08x.\n", hr);
1782 ok((V_VT(&var) == VT_EMPTY) && (V_I4(&var) == 0xdeadbeef), "V_VT(var) = %d, V_I4(var) = %d.\n",
1783 V_VT(&var), V_I4(&var));
1784 SysFreeString(script_str);
1786 language = SysAllocString(L"jscript");
1787 hr = IScriptControl_put_Language(sc, language);
1788 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
1789 hr = IScriptControl_get_State(sc, &state);
1790 ok(hr == S_OK, "IScriptControl_get_State failed: 0x%08x.\n", hr);
1791 ok(state == Initialized, "got wrong state: %d\n", state);
1792 SysFreeString(language);
1793 script_str = SysAllocString(L"var1 = 1 + 1");
1794 V_VT(&var) = VT_NULL;
1795 V_I4(&var) = 0xdeadbeef;
1796 hr = IScriptControl_Eval(sc, script_str, &var);
1797 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
1798 ok((V_VT(&var) == VT_I4) && (V_I4(&var) == 2), "V_VT(var) = %d, V_I4(var) = %d.\n",
1799 V_VT(&var), V_I4(&var));
1800 hr = IScriptControl_get_State(sc, &state);
1801 ok(hr == S_OK, "IScriptControl_get_State failed: 0x%08x.\n", hr);
1802 ok(state == Initialized, "got wrong state: %d\n", state);
1803 SysFreeString(script_str);
1805 script_str = SysAllocString(L"var2 = 10 + var1");
1806 V_VT(&var) = VT_NULL;
1807 V_I4(&var) = 0xdeadbeef;
1808 hr = IScriptControl_Eval(sc, script_str, &var);
1809 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
1810 ok((V_VT(&var) == VT_I4) && (V_I4(&var) == 12), "V_VT(var) = %d, V_I4(var) = %d.\n",
1811 V_VT(&var), V_I4(&var));
1812 SysFreeString(script_str);
1814 script_str = SysAllocString(L"invalid syntax");
1815 V_VT(&var) = VT_NULL;
1816 V_I4(&var) = 0xdeadbeef;
1817 hr = IScriptControl_Eval(sc, script_str, &var);
1818 todo_wine ok(hr == 0x800a03ec, "IScriptControl_Eval failed: 0x%08x.\n", hr);
1819 ok(V_VT(&var) == VT_EMPTY, "V_VT(var) = %d\n", V_VT(&var));
1820 ok(V_I4(&var) == 0xdeadbeef || broken(V_I4(&var) == 0) /* after Win8 */,
1821 "V_I4(var) = %d.\n", V_I4(&var));
1822 SysFreeString(script_str);
1823 todo_wine CHECK_ERROR(sc, 1004);
1825 script_str = SysAllocString(L"var2 = var1 + var2");
1826 V_VT(&var) = VT_NULL;
1827 V_I4(&var) = 0xdeadbeef;
1828 hr = IScriptControl_Eval(sc, script_str, &var);
1829 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
1830 ok((V_VT(&var) == VT_I4) && (V_I4(&var) == 14), "V_VT(var) = %d, V_I4(var) = %d.\n",
1831 V_VT(&var), V_I4(&var));
1832 SysFreeString(script_str);
1834 script_str = SysAllocString(L"\"Hello\"");
1835 V_VT(&var) = VT_NULL;
1836 V_I4(&var) = 0xdeadbeef;
1837 hr = IScriptControl_Eval(sc, script_str, &var);
1838 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
1839 expected_string = SysAllocString(L"Hello");
1840 ok((V_VT(&var) == VT_BSTR) && (!lstrcmpW(V_BSTR(&var), expected_string)),
1841 "V_VT(var) = %d, V_BSTR(var) = %s.\n", V_VT(&var), wine_dbgstr_w(V_BSTR(&var)));
1842 SysFreeString(expected_string);
1843 SysFreeString(script_str);
1845 IScriptControl_Release(sc);
1847 if (have_custom_engine)
1849 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
1850 &IID_IScriptControl, (void **)&sc);
1851 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
1853 SET_EXPECT(CreateInstance);
1854 SET_EXPECT(SetInterfaceSafetyOptions);
1855 SET_EXPECT(SetScriptSite);
1856 SET_EXPECT(QI_IActiveScriptParse);
1857 SET_EXPECT(InitNew);
1859 language= SysAllocString(L"testscript");
1860 hr = IScriptControl_put_Language(sc, language);
1861 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
1862 SysFreeString(language);
1864 CHECK_CALLED(CreateInstance);
1865 CHECK_CALLED(SetInterfaceSafetyOptions);
1866 CHECK_CALLED(SetScriptSite);
1867 CHECK_CALLED(QI_IActiveScriptParse);
1868 CHECK_CALLED(InitNew);
1870 SET_EXPECT(SetScriptState_STARTED);
1871 SET_EXPECT(ParseScriptText);
1872 parse_item_name = NULL;
1873 parse_flags = SCRIPTTEXT_ISEXPRESSION;
1874 script_str = SysAllocString(L"var1 = 1 + 1");
1875 V_VT(&var) = VT_NULL;
1876 hr = IScriptControl_Eval(sc, script_str, &var);
1877 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
1878 ok(V_VT(&var) == VT_EMPTY, "V_VT(var) = %d.\n", V_VT(&var));
1879 SysFreeString(script_str);
1880 CHECK_CALLED(SetScriptState_STARTED);
1881 CHECK_CALLED(ParseScriptText);
1883 SET_EXPECT(ParseScriptText);
1884 script_str = SysAllocString(L"var2 = 10 + var1");
1885 V_VT(&var) = VT_NULL;
1886 V_I4(&var) = 0xdeadbeef;
1887 hr = IScriptControl_Eval(sc, script_str, &var);
1888 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
1889 ok((V_VT(&var) == VT_EMPTY) && (V_I4(&var) == 0xdeadbeef), "V_VT(var) = %d, V_I4(var) = %d.\n",
1890 V_VT(&var), V_I4(&var));
1891 SysFreeString(script_str);
1892 CHECK_CALLED(ParseScriptText);
1894 SET_EXPECT(SetScriptState_INITIALIZED);
1895 hr = IScriptControl_Reset(sc);
1896 ok(hr == S_OK, "IScriptControl_Reset failed: 0x%08x.\n", hr);
1897 CHECK_CALLED(SetScriptState_INITIALIZED);
1899 SET_EXPECT(SetScriptState_STARTED);
1900 SET_EXPECT(ParseScriptText);
1901 script_str = SysAllocString(L"var2 = 10 + var1");
1902 V_VT(&var) = VT_NULL;
1903 V_I4(&var) = 0xdeadbeef;
1904 hr = IScriptControl_Eval(sc, script_str, &var);
1905 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
1906 ok((V_VT(&var) == VT_EMPTY) && (V_I4(&var) == 0xdeadbeef), "V_VT(var) = %d, V_I4(var) = %d.\n",
1907 V_VT(&var), V_I4(&var));
1908 SysFreeString(script_str);
1909 CHECK_CALLED(SetScriptState_STARTED);
1910 CHECK_CALLED(ParseScriptText);
1912 IActiveScriptSite_Release(site);
1914 SET_EXPECT(Close);
1916 IScriptControl_Release(sc);
1918 CHECK_CALLED(Close);
1922 static void test_IScriptControl_AddCode(void)
1924 BSTR code_str, language;
1925 IScriptControl *sc;
1926 VARIANT var;
1927 HRESULT hr;
1929 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
1930 &IID_IScriptControl, (void **)&sc);
1931 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
1933 code_str = SysAllocString(L"1 + 1");
1934 hr = IScriptControl_AddCode(sc, code_str);
1935 ok(hr == E_FAIL, "IScriptControl_AddCode returned: 0x%08x.\n", hr);
1936 SysFreeString(code_str);
1938 hr = IScriptControl_AddCode(sc, NULL);
1939 ok(hr == E_FAIL, "IScriptControl_AddCode returned: 0x%08x.\n", hr);
1941 language = SysAllocString(L"jscript");
1942 hr = IScriptControl_put_Language(sc, language);
1943 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
1944 SysFreeString(language);
1946 code_str = SysAllocString(L"1 + 1");
1947 hr = IScriptControl_AddCode(sc, code_str);
1948 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
1949 SysFreeString(code_str);
1950 todo_wine CHECK_ERROR(sc, 0);
1952 code_str = SysAllocString(L"invalid syntax");
1953 hr = IScriptControl_AddCode(sc, code_str);
1954 todo_wine ok(hr == 0x800a03ec, "IScriptControl_AddCode returned: 0x%08x.\n", hr);
1955 SysFreeString(code_str);
1956 todo_wine CHECK_ERROR(sc, 1004);
1958 IScriptControl_Release(sc);
1960 /* custom script engine */
1961 if (have_custom_engine)
1963 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
1964 &IID_IScriptControl, (void **)&sc);
1965 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
1967 SET_EXPECT(CreateInstance);
1968 SET_EXPECT(SetInterfaceSafetyOptions);
1969 SET_EXPECT(SetScriptSite);
1970 SET_EXPECT(QI_IActiveScriptParse);
1971 SET_EXPECT(InitNew);
1973 language = SysAllocString(L"testscript");
1974 hr = IScriptControl_put_Language(sc, language);
1975 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
1976 SysFreeString(language);
1978 CHECK_CALLED(CreateInstance);
1979 CHECK_CALLED(SetInterfaceSafetyOptions);
1980 CHECK_CALLED(SetScriptSite);
1981 CHECK_CALLED(QI_IActiveScriptParse);
1982 CHECK_CALLED(InitNew);
1984 SET_EXPECT(SetScriptState_STARTED);
1985 SET_EXPECT(ParseScriptText);
1986 parse_item_name = NULL;
1987 parse_flags = SCRIPTTEXT_ISVISIBLE;
1988 code_str = SysAllocString(L"1 + 1");
1989 hr = IScriptControl_AddCode(sc, code_str);
1990 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
1991 SysFreeString(code_str);
1992 CHECK_CALLED(SetScriptState_STARTED);
1993 CHECK_CALLED(ParseScriptText);
1995 SET_EXPECT(ParseScriptText);
1996 code_str = SysAllocString(L"0x100");
1997 hr = IScriptControl_AddCode(sc, code_str);
1998 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
1999 SysFreeString(code_str);
2000 CHECK_CALLED(ParseScriptText);
2002 /* Call Eval() after AddCode() for checking if it will call SetScriptState() again. */
2003 SET_EXPECT(ParseScriptText);
2004 parse_item_name = NULL;
2005 parse_flags = SCRIPTTEXT_ISEXPRESSION;
2006 code_str = SysAllocString(L"var2 = 10 + var1");
2007 V_VT(&var) = VT_NULL;
2008 hr = IScriptControl_Eval(sc, code_str, &var);
2009 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
2010 ok(V_VT(&var) == VT_EMPTY, "V_VT(var) = %d.\n", V_VT(&var));
2011 SysFreeString(code_str);
2012 CHECK_CALLED(ParseScriptText);
2014 IActiveScriptSite_Release(site);
2016 SET_EXPECT(Close);
2018 IScriptControl_Release(sc);
2020 CHECK_CALLED(Close);
2024 static void test_IScriptControl_ExecuteStatement(void)
2026 IScriptControl *sc;
2027 HRESULT hr;
2028 BSTR str;
2030 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2031 &IID_IScriptControl, (void**)&sc);
2032 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2034 str = SysAllocString(L"1 + 1");
2035 hr = IScriptControl_ExecuteStatement(sc, str);
2036 ok(hr == E_FAIL, "IScriptControl_ExecuteStatement returned: 0x%08x.\n", hr);
2037 SysFreeString(str);
2039 hr = IScriptControl_ExecuteStatement(sc, NULL);
2040 ok(hr == E_FAIL, "IScriptControl_ExecuteStatement returned: 0x%08x.\n", hr);
2042 str = SysAllocString(L"jscript");
2043 hr = IScriptControl_put_Language(sc, str);
2044 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2045 SysFreeString(str);
2047 str = SysAllocString(L"1 + 1");
2048 hr = IScriptControl_ExecuteStatement(sc, str);
2049 ok(hr == S_OK, "IScriptControl_ExecuteStatement failed: 0x%08x.\n", hr);
2050 SysFreeString(str);
2051 todo_wine CHECK_ERROR(sc, 0);
2053 str = SysAllocString(L"invalid syntax");
2054 hr = IScriptControl_ExecuteStatement(sc, str);
2055 todo_wine ok(hr == 0x800a03ec, "IScriptControl_ExecuteStatement returned: 0x%08x.\n", hr);
2056 SysFreeString(str);
2057 todo_wine CHECK_ERROR(sc, 1004);
2059 IScriptControl_Release(sc);
2061 /* custom script engine */
2062 if (have_custom_engine)
2064 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2065 &IID_IScriptControl, (void**)&sc);
2066 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2068 SET_EXPECT(CreateInstance);
2069 SET_EXPECT(SetInterfaceSafetyOptions);
2070 SET_EXPECT(SetScriptSite);
2071 SET_EXPECT(QI_IActiveScriptParse);
2072 SET_EXPECT(InitNew);
2074 str = SysAllocString(L"testscript");
2075 hr = IScriptControl_put_Language(sc, str);
2076 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2077 SysFreeString(str);
2079 CHECK_CALLED(CreateInstance);
2080 CHECK_CALLED(SetInterfaceSafetyOptions);
2081 CHECK_CALLED(SetScriptSite);
2082 CHECK_CALLED(QI_IActiveScriptParse);
2083 CHECK_CALLED(InitNew);
2085 SET_EXPECT(SetScriptState_STARTED);
2086 SET_EXPECT(ParseScriptText);
2087 parse_item_name = NULL;
2088 parse_flags = 0;
2089 str = SysAllocString(L"1 + 1");
2090 hr = IScriptControl_ExecuteStatement(sc, str);
2091 ok(hr == S_OK, "IScriptControl_ExecuteStatement failed: 0x%08x.\n", hr);
2092 SysFreeString(str);
2093 CHECK_CALLED(SetScriptState_STARTED);
2094 CHECK_CALLED(ParseScriptText);
2096 SET_EXPECT(ParseScriptText);
2097 str = SysAllocString(L"0x100");
2098 hr = IScriptControl_ExecuteStatement(sc, str);
2099 ok(hr == S_OK, "IScriptControl_ExecuteStatement failed: 0x%08x.\n", hr);
2100 SysFreeString(str);
2101 CHECK_CALLED(ParseScriptText);
2103 IActiveScriptSite_Release(site);
2105 SET_EXPECT(Close);
2106 IScriptControl_Release(sc);
2107 CHECK_CALLED(Close);
2111 static void test_IScriptControl_Run(void)
2113 SAFEARRAYBOUND bnd[] = { { 2, 0 }, { 2, 0 } };
2114 LONG idx0_0[] = { 0, 0 };
2115 LONG idx0_1[] = { 1, 0 };
2116 LONG idx1_0[] = { 0, 1 };
2117 LONG idx1_1[] = { 1, 1 };
2118 IScriptControl *sc;
2119 SAFEARRAY *params;
2120 VARIANT var;
2121 HRESULT hr;
2122 BSTR str;
2124 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2125 &IID_IScriptControl, (void**)&sc);
2126 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2128 params = NULL;
2129 str = SysAllocString(L"identifier");
2130 hr = IScriptControl_Run(sc, str, &params, &var);
2131 ok(hr == E_POINTER, "IScriptControl_Run returned: 0x%08x.\n", hr);
2133 params = SafeArrayCreate(VT_VARIANT, 1, bnd);
2134 ok(params != NULL, "Failed to create SafeArray.\n");
2136 V_VT(&var) = VT_I4;
2137 V_I4(&var) = 10;
2138 SafeArrayPutElement(params, idx0_0, &var);
2139 V_I4(&var) = 3;
2140 SafeArrayPutElement(params, idx0_1, &var);
2142 hr = IScriptControl_Run(sc, str, &params, &var);
2143 ok(hr == E_FAIL, "IScriptControl_Run returned: 0x%08x.\n", hr);
2145 hr = IScriptControl_Run(sc, str, NULL, &var);
2146 ok(hr == E_POINTER, "IScriptControl_Run returned: 0x%08x.\n", hr);
2148 hr = IScriptControl_Run(sc, str, &params, NULL);
2149 ok(hr == E_POINTER, "IScriptControl_Run returned: 0x%08x.\n", hr);
2150 SysFreeString(str);
2152 hr = IScriptControl_Run(sc, NULL, &params, &var);
2153 ok(hr == E_FAIL, "IScriptControl_Run returned: 0x%08x.\n", hr);
2155 str = SysAllocString(L"jscript");
2156 hr = IScriptControl_put_Language(sc, str);
2157 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2158 SysFreeString(str);
2160 str = SysAllocString(L"foobar");
2161 hr = IScriptControl_Run(sc, str, &params, &var);
2162 ok(hr == DISP_E_UNKNOWNNAME, "IScriptControl_Run failed: 0x%08x.\n", hr);
2163 todo_wine CHECK_ERROR(sc, 0);
2164 SysFreeString(str);
2166 str = SysAllocString(L"function subtract(a, b) { return a - b; }\n");
2167 hr = IScriptControl_AddCode(sc, str);
2168 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
2169 todo_wine CHECK_ERROR(sc, 0);
2170 SysFreeString(str);
2172 str = SysAllocString(L"Subtract");
2173 hr = IScriptControl_Run(sc, str, &params, &var);
2174 ok(hr == DISP_E_UNKNOWNNAME, "IScriptControl_Run failed: 0x%08x.\n", hr);
2175 SysFreeString(str);
2177 str = SysAllocString(L"subtract");
2178 hr = IScriptControl_Run(sc, str, &params, NULL);
2179 ok(hr == E_POINTER, "IScriptControl_Run failed: 0x%08x.\n", hr);
2180 todo_wine CHECK_ERROR(sc, 0);
2182 hr = IScriptControl_Run(sc, str, &params, &var);
2183 ok(hr == S_OK, "IScriptControl_Run failed: 0x%08x.\n", hr);
2184 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));
2185 todo_wine CHECK_ERROR(sc, 0);
2186 SafeArrayDestroy(params);
2188 /* The array's other dimensions are ignored */
2189 params = SafeArrayCreate(VT_VARIANT, 2, bnd);
2190 ok(params != NULL, "Failed to create SafeArray.\n");
2192 V_VT(&var) = VT_I4;
2193 V_I4(&var) = 10;
2194 SafeArrayPutElement(params, idx0_0, &var);
2195 V_I4(&var) = 3;
2196 SafeArrayPutElement(params, idx0_1, &var);
2197 V_I4(&var) = 90;
2198 SafeArrayPutElement(params, idx1_0, &var);
2199 V_I4(&var) = 80;
2200 SafeArrayPutElement(params, idx1_1, &var);
2202 hr = IScriptControl_Run(sc, str, &params, &var);
2203 ok(hr == S_OK, "IScriptControl_Run failed: 0x%08x.\n", hr);
2204 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));
2206 /* Hack the array's dimensions to 0 */
2207 params->cDims = 0;
2208 hr = IScriptControl_Run(sc, str, &params, &var);
2209 ok(hr == DISP_E_BADINDEX, "IScriptControl_Run returned: 0x%08x.\n", hr);
2210 ok(V_VT(&var) == VT_EMPTY, "V_VT(var) = %d.\n", V_VT(&var));
2211 params->cDims = 2;
2212 SysFreeString(str);
2213 IScriptControl_Release(sc);
2215 /* custom script engine */
2216 if (have_custom_engine)
2218 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2219 &IID_IScriptControl, (void**)&sc);
2220 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2222 SET_EXPECT(CreateInstance);
2223 SET_EXPECT(SetInterfaceSafetyOptions);
2224 SET_EXPECT(SetScriptSite);
2225 SET_EXPECT(QI_IActiveScriptParse);
2226 SET_EXPECT(InitNew);
2227 str = SysAllocString(L"testscript");
2228 hr = IScriptControl_put_Language(sc, str);
2229 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2230 SysFreeString(str);
2231 CHECK_CALLED(CreateInstance);
2232 CHECK_CALLED(SetInterfaceSafetyOptions);
2233 CHECK_CALLED(SetScriptSite);
2234 CHECK_CALLED(QI_IActiveScriptParse);
2235 CHECK_CALLED(InitNew);
2237 SET_EXPECT(SetScriptState_STARTED);
2238 SET_EXPECT(GetScriptDispatch);
2239 SET_EXPECT(QI_IDispatchEx);
2240 SET_EXPECT(GetIDsOfNames);
2241 SET_EXPECT(Invoke);
2242 Dispatch_expected_name = SysAllocString(L"function");
2243 hr = IScriptControl_Run(sc, Dispatch_expected_name, &params, &var);
2244 ok(hr == S_OK, "IScriptControl_Run failed: 0x%08x.\n", hr);
2245 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));
2246 SysFreeString(Dispatch_expected_name);
2247 CHECK_CALLED(SetScriptState_STARTED);
2248 CHECK_CALLED(GetScriptDispatch);
2249 CHECK_CALLED(QI_IDispatchEx);
2250 CHECK_CALLED(GetIDsOfNames);
2251 CHECK_CALLED(Invoke);
2253 /* GetScriptDispatch is cached and not called again */
2254 CLEAR_CALLED(GetScriptDispatch);
2255 SET_EXPECT(QI_IDispatchEx);
2256 SET_EXPECT(GetIDsOfNames);
2257 SET_EXPECT(Invoke);
2258 Dispatch_expected_name = SysAllocString(L"BarFoo");
2259 hr = IScriptControl_Run(sc, Dispatch_expected_name, &params, &var);
2260 ok(hr == S_OK, "IScriptControl_Run failed: 0x%08x.\n", hr);
2261 SysFreeString(Dispatch_expected_name);
2262 CHECK_NOT_CALLED(GetScriptDispatch);
2263 CHECK_CALLED(QI_IDispatchEx);
2264 CHECK_CALLED(GetIDsOfNames);
2265 CHECK_CALLED(Invoke);
2267 /* Make DispatchEx available */
2268 DispatchEx_available = TRUE;
2269 CLEAR_CALLED(GetScriptDispatch);
2270 SET_EXPECT(QI_IDispatchEx);
2271 SET_EXPECT(GetIDsOfNames);
2272 SET_EXPECT(InvokeEx);
2273 Dispatch_expected_name = SysAllocString(L"FooBar");
2274 hr = IScriptControl_Run(sc, Dispatch_expected_name, &params, &var);
2275 ok(hr == S_OK, "IScriptControl_Run failed: 0x%08x.\n", hr);
2276 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));
2277 SysFreeString(Dispatch_expected_name);
2278 CHECK_NOT_CALLED(GetScriptDispatch);
2279 CHECK_CALLED(QI_IDispatchEx);
2280 CHECK_CALLED(GetIDsOfNames);
2281 CHECK_CALLED(InvokeEx);
2283 /* QueryInterface for IDispatchEx is always called and not cached */
2284 CLEAR_CALLED(GetScriptDispatch);
2285 SET_EXPECT(QI_IDispatchEx);
2286 SET_EXPECT(GetIDsOfNames);
2287 SET_EXPECT(InvokeEx);
2288 Dispatch_expected_name = SysAllocString(L"1");
2289 hr = IScriptControl_Run(sc, Dispatch_expected_name, &params, &var);
2290 ok(hr == S_OK, "IScriptControl_Run failed: 0x%08x.\n", hr);
2291 SysFreeString(Dispatch_expected_name);
2292 CHECK_NOT_CALLED(GetScriptDispatch);
2293 CHECK_CALLED(QI_IDispatchEx);
2294 CHECK_CALLED(GetIDsOfNames);
2295 CHECK_CALLED(InvokeEx);
2296 DispatchEx_available = FALSE;
2298 IActiveScriptSite_Release(site);
2300 SET_EXPECT(Close);
2301 IScriptControl_Release(sc);
2302 CHECK_CALLED(Close);
2305 SafeArrayDestroy(params);
2308 static void test_IScriptControl_get_Modules(void)
2310 IScriptModuleCollection *mods;
2311 IScriptModule *mod;
2312 IScriptControl *sc;
2313 IUnknown *unknown;
2314 VARIANT var;
2315 LONG count;
2316 HRESULT hr;
2317 BSTR str;
2319 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2320 &IID_IScriptControl, (void**)&sc);
2321 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2323 hr = IScriptControl_get_Modules(sc, &mods);
2324 ok(hr == E_FAIL, "IScriptControl_get_Modules returned: 0x%08x.\n", hr);
2326 str = SysAllocString(L"jscript");
2327 hr = IScriptControl_put_Language(sc, str);
2328 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2329 SysFreeString(str);
2331 hr = IScriptControl_get_Modules(sc, &mods);
2332 ok(hr == S_OK, "IScriptControl_get_Modules failed: 0x%08x.\n", hr);
2334 hr = IScriptModuleCollection_get_Count(mods, NULL);
2335 ok(hr == E_POINTER, "IScriptModuleCollection_get_Count returned: 0x%08x.\n", hr);
2336 count = 0;
2337 hr = IScriptModuleCollection_get_Count(mods, &count);
2338 ok(hr == S_OK, "IScriptModuleCollection_get_Count failed: 0x%08x.\n", hr);
2339 ok(count == 1, "count is not 1, got %d.\n", count);
2341 V_VT(&var) = VT_I4;
2342 V_I4(&var) = -1;
2343 hr = IScriptModuleCollection_get_Item(mods, var, NULL);
2344 ok(hr == E_POINTER, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
2345 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
2346 ok(hr == 0x800a0009, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
2348 V_VT(&var) = VT_EMPTY;
2349 str = SysAllocString(L"foobar");
2350 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
2351 ok(hr == E_INVALIDARG, "IScriptModuleCollection_Add returned: 0x%08x.\n", hr);
2352 hr = IScriptModuleCollection_Add(mods, str, &var, NULL);
2353 ok(hr == E_POINTER, "IScriptModuleCollection_Add returned: 0x%08x.\n", hr);
2354 V_VT(&var) = VT_DISPATCH;
2355 V_DISPATCH(&var) = NULL;
2356 hr = IScriptModuleCollection_Add(mods, NULL, &var, &mod);
2357 ok(hr == E_INVALIDARG, "IScriptModuleCollection_Add returned: 0x%08x.\n", hr);
2358 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
2359 ok(hr == S_OK, "IScriptModuleCollection_Add failed: 0x%08x.\n", hr);
2360 IScriptModule_Release(mod);
2361 SysFreeString(str);
2363 str = SysAllocString(L"some other Module");
2364 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
2365 ok(hr == S_OK, "IScriptModuleCollection_Add failed: 0x%08x.\n", hr);
2366 IScriptModule_Release(mod);
2367 SysFreeString(str);
2369 /* Adding a module with the same name is invalid (case insensitive) */
2370 str = SysAllocString(L"FooBar");
2371 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
2372 ok(hr == E_INVALIDARG, "IScriptModuleCollection_Add failed: 0x%08x.\n", hr);
2373 SysFreeString(str);
2375 hr = IScriptModuleCollection_get_Count(mods, &count);
2376 ok(hr == S_OK, "IScriptModuleCollection_get_Count failed: 0x%08x.\n", hr);
2377 ok(count == 3, "count is not 3, got %d.\n", count);
2378 V_VT(&var) = VT_I4;
2379 V_I4(&var) = count + 1;
2380 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
2381 ok(hr == 0x800a0009, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
2382 V_VT(&var) = VT_BSTR;
2383 V_BSTR(&var) = SysAllocString(L"non-existent module");
2384 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
2385 ok(hr == CTL_E_ILLEGALFUNCTIONCALL, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
2386 ok(V_VT(&var) == VT_BSTR, "var type not BSTR, got %d.\n", V_VT(&var));
2387 VariantClear(&var);
2389 V_VT(&var) = VT_I4;
2390 V_I4(&var) = 1;
2391 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
2392 ok(hr == S_OK, "IScriptModuleCollection_get_Item failed: 0x%08x.\n", hr);
2393 hr = IScriptModule_get_Name(mod, NULL);
2394 ok(hr == E_POINTER, "IScriptModule_get_Name returned: 0x%08x.\n", hr);
2395 hr = IScriptModule_get_Name(mod, &str);
2396 ok(hr == S_OK, "IScriptModule_get_Name failed: 0x%08x.\n", hr);
2397 ok(!lstrcmpW(str, L"Global"), "got %s.\n", wine_dbgstr_w(str));
2398 SysFreeString(str);
2399 str = SysAllocString(L"function add(a, b) { return a + b; }\n");
2400 hr = IScriptModule_AddCode(mod, str);
2401 ok(hr == S_OK, "IScriptModule_AddCode failed: 0x%08x.\n", hr);
2402 IScriptModule_Release(mod);
2403 SysFreeString(str);
2405 V_VT(&var) = VT_BSTR;
2406 V_BSTR(&var) = SysAllocString(L"some other module");
2407 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
2408 ok(hr == S_OK, "IScriptModuleCollection_get_Item failed: 0x%08x.\n", hr);
2409 ok(V_VT(&var) == VT_BSTR, "var type not BSTR, got %d.\n", V_VT(&var));
2410 VariantClear(&var);
2411 hr = IScriptModule_get_Name(mod, &str);
2412 ok(hr == S_OK, "IScriptModule_get_Name failed: 0x%08x.\n", hr);
2413 ok(!lstrcmpW(str, L"some other Module"), "got %s.\n", wine_dbgstr_w(str));
2414 IScriptModule_Release(mod);
2415 SysFreeString(str);
2417 V_VT(&var) = VT_R8;
2418 V_R8(&var) = 2.0;
2419 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
2420 ok(hr == S_OK, "IScriptModuleCollection_get_Item failed: 0x%08x.\n", hr);
2421 hr = IScriptModule_get_Name(mod, &str);
2422 ok(hr == S_OK, "IScriptModule_get_Name failed: 0x%08x.\n", hr);
2423 ok(!lstrcmpW(str, L"foobar"), "got %s.\n", wine_dbgstr_w(str));
2424 SysFreeString(str);
2425 str = SysAllocString(L"function sub(a, b) { return a - b; }\n");
2426 hr = IScriptModule_AddCode(mod, str);
2427 ok(hr == S_OK, "IScriptModule_AddCode failed: 0x%08x.\n", hr);
2428 IScriptModule_Release(mod);
2429 SysFreeString(str);
2431 /* The 'Global' module is the same as the script control */
2432 str = SysAllocString(L"add(10, 5)");
2433 hr = IScriptControl_Eval(sc, str, &var);
2434 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
2435 ok(V_VT(&var) == VT_I4 && V_I4(&var) == 15, "V_VT(var) = %d, V_I4(var) = %d.\n", V_VT(&var), V_I4(&var));
2436 SysFreeString(str);
2437 str = SysAllocString(L"sub(10, 5)");
2438 hr = IScriptControl_Eval(sc, str, &var);
2439 ok(FAILED(hr), "IScriptControl_Eval succeeded: 0x%08x.\n", hr);
2440 SysFreeString(str);
2442 /* Grab a module ref and change the language to something valid */
2443 V_VT(&var) = VT_I2;
2444 V_I2(&var) = 3;
2445 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
2446 ok(hr == S_OK, "IScriptModuleCollection_get_Item failed: 0x%08x.\n", hr);
2447 str = SysAllocString(L"vbscript");
2448 hr = IScriptControl_put_Language(sc, str);
2449 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2450 SysFreeString(str);
2452 /* The module collection changes and module ref is invalid */
2453 hr = IScriptModuleCollection_get_Count(mods, &count);
2454 ok(hr == S_OK, "IScriptModuleCollection_get_Count failed: 0x%08x.\n", hr);
2455 ok(count == 1, "count is not 1, got %d.\n", count);
2456 hr = IScriptModule_get_Name(mod, &str);
2457 ok(hr == E_FAIL, "IScriptModule_get_Name returned: 0x%08x.\n", hr);
2458 str = SysAllocString(L"function closed() { }\n");
2459 hr = IScriptModule_AddCode(mod, str);
2460 ok(hr == E_FAIL, "IScriptModule_AddCode failed: 0x%08x.\n", hr);
2461 SysFreeString(str);
2462 str = SysAllocString(L"sub closed\nend sub");
2463 hr = IScriptModule_AddCode(mod, str);
2464 ok(hr == E_FAIL, "IScriptModule_AddCode failed: 0x%08x.\n", hr);
2465 IScriptModule_Release(mod);
2466 SysFreeString(str);
2468 hr = IScriptControl_put_Language(sc, NULL);
2469 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2471 hr = IScriptModuleCollection_get_Count(mods, &count);
2472 ok(hr == E_FAIL, "IScriptModuleCollection_get_Count returned: 0x%08x.\n", hr);
2473 V_VT(&var) = VT_I4;
2474 V_I4(&var) = 1;
2475 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
2476 ok(hr == E_FAIL, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
2477 V_VT(&var) = VT_DISPATCH;
2478 V_DISPATCH(&var) = NULL;
2479 str = SysAllocString(L"module_name");
2480 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
2481 ok(hr == E_FAIL, "IScriptModuleCollection_Add returned: 0x%08x.\n", hr);
2482 SysFreeString(str);
2484 IScriptModuleCollection_Release(mods);
2485 hr = IScriptControl_get_Modules(sc, &mods);
2486 ok(hr == E_FAIL, "IScriptControl_get_Modules returned: 0x%08x.\n", hr);
2488 IScriptControl_Release(sc);
2490 /* custom script engine */
2491 if (have_custom_engine)
2493 BSTR code_str;
2495 /* A module collection ref keeps the control alive */
2496 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2497 &IID_IScriptControl, (void**)&sc);
2498 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2500 SET_EXPECT(CreateInstance);
2501 SET_EXPECT(SetInterfaceSafetyOptions);
2502 SET_EXPECT(SetScriptSite);
2503 SET_EXPECT(QI_IActiveScriptParse);
2504 SET_EXPECT(InitNew);
2505 str = SysAllocString(L"testscript");
2506 hr = IScriptControl_put_Language(sc, str);
2507 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2508 SysFreeString(str);
2509 CHECK_CALLED(CreateInstance);
2510 CHECK_CALLED(SetInterfaceSafetyOptions);
2511 CHECK_CALLED(SetScriptSite);
2512 CHECK_CALLED(QI_IActiveScriptParse);
2513 CHECK_CALLED(InitNew);
2515 hr = IScriptControl_get_Modules(sc, &mods);
2516 ok(hr == S_OK, "IScriptControl_get_Modules failed: 0x%08x.\n", hr);
2518 IActiveScriptSite_Release(site);
2519 IScriptControl_Release(sc);
2521 SET_EXPECT(Close);
2522 IScriptModuleCollection_Release(mods);
2523 CHECK_CALLED(Close);
2525 /* Add a module with a non-null object and add some code to it */
2526 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2527 &IID_IScriptControl, (void**)&sc);
2528 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2530 SET_EXPECT(CreateInstance);
2531 SET_EXPECT(SetInterfaceSafetyOptions);
2532 SET_EXPECT(SetScriptSite);
2533 SET_EXPECT(QI_IActiveScriptParse);
2534 SET_EXPECT(InitNew);
2535 str = SysAllocString(L"testscript");
2536 hr = IScriptControl_put_Language(sc, str);
2537 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2538 SysFreeString(str);
2539 CHECK_CALLED(CreateInstance);
2540 CHECK_CALLED(SetInterfaceSafetyOptions);
2541 CHECK_CALLED(SetScriptSite);
2542 CHECK_CALLED(QI_IActiveScriptParse);
2543 CHECK_CALLED(InitNew);
2545 hr = IScriptControl_get_Modules(sc, &mods);
2546 ok(hr == S_OK, "IScriptControl_get_Modules failed: 0x%08x.\n", hr);
2548 SET_EXPECT(AddNamedItem);
2549 str = SysAllocString(L"modname");
2550 AddNamedItem_expected_name = str;
2551 AddNamedItem_expected_flags = 0;
2552 V_VT(&var) = VT_DISPATCH;
2553 V_DISPATCH(&var) = &testdisp;
2554 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
2555 ok(hr == S_OK, "IScriptModuleCollection_Add failed: 0x%08x.\n", hr);
2556 VariantClear(&var);
2557 CHECK_CALLED(AddNamedItem);
2559 unknown = (IUnknown*)0xdeadbeef;
2560 hr = IActiveScriptSite_GetItemInfo(site, str, SCRIPTINFO_IUNKNOWN, &unknown, NULL);
2561 ok(hr == S_OK, "IActiveScriptSite_GetItemInfo failed: 0x%08x.\n", hr);
2562 ok(unknown == (IUnknown*)&testdisp, "Unexpected IUnknown for the item: %p.\n", unknown);
2563 IUnknown_Release(unknown);
2565 SET_EXPECT(SetScriptState_STARTED);
2566 SET_EXPECT(ParseScriptText);
2567 parse_item_name = str;
2568 parse_flags = SCRIPTTEXT_ISVISIBLE;
2569 code_str = SysAllocString(L"some code");
2570 hr = IScriptModule_AddCode(mod, code_str);
2571 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
2572 CHECK_CALLED(SetScriptState_STARTED);
2573 CHECK_CALLED(ParseScriptText);
2574 SysFreeString(code_str);
2575 SysFreeString(str);
2577 /* Keep the module ref before changing the language */
2578 SET_EXPECT(Close);
2579 hr = IScriptControl_put_Language(sc, NULL);
2580 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2581 CHECK_CALLED(Close);
2582 IScriptModuleCollection_Release(mods);
2583 IActiveScriptSite_Release(site);
2584 IScriptControl_Release(sc);
2585 IScriptModule_Release(mod);
2587 /* Now try holding a module ref while closing the script */
2588 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2589 &IID_IScriptControl, (void**)&sc);
2590 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2592 SET_EXPECT(CreateInstance);
2593 SET_EXPECT(SetInterfaceSafetyOptions);
2594 SET_EXPECT(SetScriptSite);
2595 SET_EXPECT(QI_IActiveScriptParse);
2596 SET_EXPECT(InitNew);
2597 str = SysAllocString(L"testscript");
2598 hr = IScriptControl_put_Language(sc, str);
2599 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2600 SysFreeString(str);
2601 CHECK_CALLED(CreateInstance);
2602 CHECK_CALLED(SetInterfaceSafetyOptions);
2603 CHECK_CALLED(SetScriptSite);
2604 CHECK_CALLED(QI_IActiveScriptParse);
2605 CHECK_CALLED(InitNew);
2607 hr = IScriptControl_get_Modules(sc, &mods);
2608 ok(hr == S_OK, "IScriptControl_get_Modules failed: 0x%08x.\n", hr);
2610 SET_EXPECT(AddNamedItem);
2611 str = SysAllocString(L"foo");
2612 AddNamedItem_expected_name = str;
2613 AddNamedItem_expected_flags = SCRIPTITEM_CODEONLY;
2614 V_VT(&var) = VT_DISPATCH;
2615 V_DISPATCH(&var) = NULL;
2616 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
2617 ok(hr == S_OK, "IScriptModuleCollection_Add failed: 0x%08x.\n", hr);
2618 VariantClear(&var);
2619 CHECK_CALLED(AddNamedItem);
2621 unknown = (IUnknown*)0xdeadbeef;
2622 hr = IActiveScriptSite_GetItemInfo(site, str, SCRIPTINFO_IUNKNOWN, &unknown, NULL);
2623 ok(hr == TYPE_E_ELEMENTNOTFOUND, "IActiveScriptSite_GetItemInfo returned: 0x%08x.\n", hr);
2624 IScriptModuleCollection_Release(mods);
2625 IActiveScriptSite_Release(site);
2626 IScriptControl_Release(sc);
2628 SET_EXPECT(SetScriptState_STARTED);
2629 SET_EXPECT(ParseScriptText);
2630 parse_item_name = str;
2631 parse_flags = SCRIPTTEXT_ISVISIBLE;
2632 code_str = SysAllocString(L"code after close");
2633 hr = IScriptModule_AddCode(mod, code_str);
2634 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
2635 CHECK_CALLED(SetScriptState_STARTED);
2636 CHECK_CALLED(ParseScriptText);
2637 SysFreeString(code_str);
2638 SysFreeString(str);
2640 SET_EXPECT(Close);
2641 IScriptModule_Release(mod);
2642 CHECK_CALLED(Close);
2646 START_TEST(msscript)
2648 IUnknown *unk;
2649 HRESULT hr;
2651 CoInitialize(NULL);
2653 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2654 &IID_IUnknown, (void**)&unk);
2655 if (FAILED(hr)) {
2656 win_skip("Could not create ScriptControl object: %08x\n", hr);
2657 return;
2659 IUnknown_Release(unk);
2661 have_custom_engine = register_script_engine();
2662 if (!have_custom_engine)
2663 skip("Could not register TestScript engine.\n");
2665 test_oleobject();
2666 test_persiststreaminit();
2667 test_olecontrol();
2668 test_Language();
2669 test_connectionpoints();
2670 test_quickactivate();
2671 test_viewobject();
2672 test_pointerinactive();
2673 test_timeout();
2674 test_Reset();
2675 test_AddObject();
2676 test_AllowUI();
2677 test_UseSafeSubset();
2678 test_State();
2679 test_IScriptControl_Eval();
2680 test_IScriptControl_AddCode();
2681 test_IScriptControl_ExecuteStatement();
2682 test_IScriptControl_Run();
2683 test_IScriptControl_get_Modules();
2685 init_registry(FALSE);
2687 CoUninitialize();