wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / msscript.ocx / tests / msscript.c
blob756c21d887bb70af84bb3e19fb27437536015cf9
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}};
38 #ifdef _WIN64
40 #define CTXARG_T DWORDLONG
41 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
42 #define IActiveScriptSiteDebug_Release IActiveScriptSiteDebug64_Release
44 #else
46 #define CTXARG_T DWORD
47 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
48 #define IActiveScriptSiteDebug_Release IActiveScriptSiteDebug32_Release
50 #endif
52 #define DEFINE_EXPECT(func) \
53 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
55 #define SET_EXPECT(func) \
56 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
58 #define CHECK_EXPECT2(func) \
59 do { \
60 ok(expect_ ##func, "unexpected call " #func "\n"); \
61 called_ ## func = TRUE; \
62 }while(0)
64 #define CHECK_EXPECT(func) \
65 do { \
66 CHECK_EXPECT2(func); \
67 expect_ ## func = FALSE; \
68 }while(0)
70 #define CHECK_CALLED(func) \
71 do { \
72 ok(called_ ## func, "expected " #func "\n"); \
73 expect_ ## func = called_ ## func = FALSE; \
74 }while(0)
76 #define CHECK_CALLED_BROKEN(func) \
77 do { \
78 ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
79 expect_ ## func = called_ ## func = FALSE; \
80 }while(0)
82 #define CHECK_NOT_CALLED(func) \
83 do { \
84 ok(!called_ ## func, "unexpected " #func "\n"); \
85 expect_ ## func = called_ ## func = FALSE; \
86 }while(0)
88 #define CLEAR_CALLED(func) \
89 expect_ ## func = called_ ## func = FALSE
91 DEFINE_EXPECT(CreateInstance);
92 DEFINE_EXPECT(SetInterfaceSafetyOptions);
93 DEFINE_EXPECT(SetInterfaceSafetyOptions_UseSafeSubset);
94 DEFINE_EXPECT(InitNew);
95 DEFINE_EXPECT(Close);
96 DEFINE_EXPECT(Bind);
97 DEFINE_EXPECT(QI_ITypeComp);
98 DEFINE_EXPECT(GetTypeAttr);
99 DEFINE_EXPECT(GetNames);
100 DEFINE_EXPECT(GetFuncDesc);
101 DEFINE_EXPECT(ReleaseTypeAttr);
102 DEFINE_EXPECT(ReleaseFuncDesc);
103 DEFINE_EXPECT(ReleaseVarDesc);
104 DEFINE_EXPECT(QI_IDispatchEx);
105 DEFINE_EXPECT(GetTypeInfo);
106 DEFINE_EXPECT(GetIDsOfNames);
107 DEFINE_EXPECT(Invoke);
108 DEFINE_EXPECT(InvokeEx);
109 DEFINE_EXPECT(DeferredFillIn);
110 DEFINE_EXPECT(GetExceptionInfo);
111 DEFINE_EXPECT(GetSourcePosition);
112 DEFINE_EXPECT(GetSourceLineText);
113 DEFINE_EXPECT(SetScriptSite);
114 DEFINE_EXPECT(QI_IActiveScriptParse);
115 DEFINE_EXPECT(GetScriptState);
116 DEFINE_EXPECT(SetScriptState_INITIALIZED);
117 DEFINE_EXPECT(SetScriptState_STARTED);
118 DEFINE_EXPECT(SetScriptState_CONNECTED);
119 DEFINE_EXPECT(ParseScriptText);
120 DEFINE_EXPECT(AddNamedItem);
121 DEFINE_EXPECT(GetScriptDispatch);
123 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
124 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
126 ULONG rc;
127 IUnknown_AddRef(obj);
128 rc = IUnknown_Release(obj);
129 ok_(__FILE__,line)(rc == ref, "expected refcount %d, got %d\n", ref, rc);
132 static IActiveScriptSite *site;
133 static SCRIPTSTATE state;
134 static ITypeInfo TypeInfo;
136 static struct
138 const WCHAR *name;
139 SHORT num_args;
140 SHORT num_opt_args;
141 VARTYPE ret_type;
142 FUNCKIND func_kind;
143 INVOKEKIND invoke_kind;
144 WORD flags;
145 } custom_engine_funcs[] =
147 { L"foobar", 3, 0, VT_I4, FUNC_DISPATCH, INVOKE_FUNC, 0 },
148 { L"barfoo", 11, 2, VT_VOID, FUNC_VIRTUAL, INVOKE_FUNC, FUNCFLAG_FRESTRICTED },
149 { L"empty", 0, 0, VT_EMPTY, FUNC_PUREVIRTUAL, INVOKE_PROPERTYGET, FUNCFLAG_FBINDABLE | FUNCFLAG_FDISPLAYBIND },
150 { L"vararg", 4, -1, VT_BSTR, FUNC_NONVIRTUAL, INVOKE_PROPERTYPUT, FUNCFLAG_FREQUESTEDIT },
151 { L"static", 0, 1, VT_PTR, FUNC_STATIC, INVOKE_PROPERTYPUTREF, FUNCFLAG_FHIDDEN },
152 { L"deadbeef", 21, -9, VT_ERROR, 0xdeadbeef, 0xdeadbeef, 0xffff }
155 static int memid_to_func_index(MEMBERID memid)
157 UINT idx = memid - 0xdeadbeef;
158 return idx < ARRAY_SIZE(custom_engine_funcs) ? idx : -1;
161 static MEMBERID func_index_to_memid(UINT idx)
163 return idx + 0xdeadbeef;
166 static FUNCDESC *get_func_desc(UINT i)
168 FUNCDESC *desc;
170 if (!(desc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*desc))))
171 return NULL;
173 desc->memid = func_index_to_memid(i);
174 desc->cParams = custom_engine_funcs[i].num_args;
175 desc->cParamsOpt = custom_engine_funcs[i].num_opt_args;
176 desc->elemdescFunc.tdesc.vt = custom_engine_funcs[i].ret_type;
177 desc->elemdescFunc.paramdesc.wParamFlags = PARAMFLAG_FRETVAL;
178 desc->funckind = custom_engine_funcs[i].func_kind;
179 desc->invkind = custom_engine_funcs[i].invoke_kind;
180 desc->wFuncFlags = custom_engine_funcs[i].flags;
181 return desc;
184 static HRESULT WINAPI ActiveScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
186 *ppv = NULL;
187 ok(0, "unexpected call\n");
188 return E_NOINTERFACE;
191 static ULONG WINAPI ActiveScriptParse_AddRef(IActiveScriptParse *iface)
193 return 2;
196 static ULONG WINAPI ActiveScriptParse_Release(IActiveScriptParse *iface)
198 return 1;
201 static HRESULT WINAPI ActiveScriptParse_InitNew(IActiveScriptParse *iface)
203 CHECK_EXPECT(InitNew);
204 return S_OK;
207 static HRESULT WINAPI ActiveScriptParse_AddScriptlet(IActiveScriptParse *iface,
208 LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
209 LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
210 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
211 BSTR *pbstrName, EXCEPINFO *pexcepinfo)
213 ok(0, "unexpected call\n");
214 return E_NOTIMPL;
217 static const WCHAR *parse_item_name;
218 static DWORD parse_flags = 0;
220 static HRESULT WINAPI ActiveScriptParse_ParseScriptText(IActiveScriptParse *iface,
221 LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
222 LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
223 DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
225 ok(!!pstrCode, "got wrong pointer: %p.\n", pstrCode);
226 ok(!lstrcmpW(pstrItemName, parse_item_name), "got wrong item name: %s (expected %s).\n",
227 wine_dbgstr_w(pstrItemName), wine_dbgstr_w(parse_item_name));
228 ok(!punkContext, "got wrong pointer: %p.\n", punkContext);
229 ok(!pstrDelimiter, "got wrong pointer: %p.\n", pstrDelimiter);
230 ok(!dwSourceContextCookie, "got wrong value: %s.\n", wine_dbgstr_longlong(dwSourceContextCookie));
231 ok(ulStartingLine == 1, "got wrong value: %d.\n", ulStartingLine);
232 ok(!!pexcepinfo, "got wrong pointer: %p.\n", pexcepinfo);
233 ok(dwFlags == parse_flags, "got wrong flags: %x.\n", dwFlags);
234 if (parse_flags == SCRIPTTEXT_ISEXPRESSION)
235 ok(!!pvarResult, "got wrong pointer: %p.\n", pvarResult);
236 else
237 ok(!pvarResult, "got wrong pointer: %p.\n", pvarResult);
239 CHECK_EXPECT(ParseScriptText);
240 return S_OK;
243 static const IActiveScriptParseVtbl ActiveScriptParseVtbl = {
244 ActiveScriptParse_QueryInterface,
245 ActiveScriptParse_AddRef,
246 ActiveScriptParse_Release,
247 ActiveScriptParse_InitNew,
248 ActiveScriptParse_AddScriptlet,
249 ActiveScriptParse_ParseScriptText
252 static IActiveScriptParse ActiveScriptParse = { &ActiveScriptParseVtbl };
254 static HRESULT WINAPI ObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
256 *ppv = NULL;
257 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid));
258 return E_NOINTERFACE;
261 static ULONG WINAPI ObjectSafety_AddRef(IObjectSafety *iface)
263 return 2;
266 static ULONG WINAPI ObjectSafety_Release(IObjectSafety *iface)
268 return 1;
271 static HRESULT WINAPI ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
272 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
274 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
275 return E_NOTIMPL;
278 static HRESULT WINAPI ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
279 DWORD mask, DWORD options)
281 if (options == INTERFACESAFE_FOR_UNTRUSTED_DATA)
282 CHECK_EXPECT(SetInterfaceSafetyOptions_UseSafeSubset);
283 else
284 CHECK_EXPECT(SetInterfaceSafetyOptions);
286 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
287 ok(mask == INTERFACESAFE_FOR_UNTRUSTED_DATA, "option mask = %x\n", mask);
289 return S_OK;
292 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
293 ObjectSafety_QueryInterface,
294 ObjectSafety_AddRef,
295 ObjectSafety_Release,
296 ObjectSafety_GetInterfaceSafetyOptions,
297 ObjectSafety_SetInterfaceSafetyOptions
300 static IObjectSafety ObjectSafety = { &ObjectSafetyVtbl };
302 static HRESULT WINAPI TypeComp_QueryInterface(ITypeComp *iface, REFIID riid, void **ppv)
304 *ppv = NULL;
305 ok(0, "unexpected call\n");
306 return E_NOINTERFACE;
309 static ULONG WINAPI TypeComp_AddRef(ITypeComp *iface)
311 return 2;
314 static ULONG WINAPI TypeComp_Release(ITypeComp *iface)
316 return 1;
319 static HRESULT WINAPI TypeComp_Bind(ITypeComp *iface, LPOLESTR szName, ULONG lHashVal, WORD wFlags,
320 ITypeInfo **ppTInfo, DESCKIND *pDescKind, BINDPTR *pBindPtr)
322 ULONG hash = LHashValOfNameSys(sizeof(void*) == 8 ? SYS_WIN64 : SYS_WIN32, LOCALE_USER_DEFAULT, szName);
323 UINT i;
325 CHECK_EXPECT(Bind);
326 ok(lHashVal == hash, "wrong hash, expected 0x%08x, got 0x%08x.\n", hash, lHashVal);
327 ok(wFlags == INVOKE_FUNC, "wrong flags, got 0x%x.\n", wFlags);
329 *ppTInfo = NULL;
330 *pDescKind = DESCKIND_NONE;
331 pBindPtr->lptcomp = NULL;
333 if (!lstrcmpW(szName, L"type_mismatch"))
334 return TYPE_E_TYPEMISMATCH;
336 if (!lstrcmpW(szName, L"variable"))
338 if (!(pBindPtr->lpvardesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(VARDESC))))
339 return E_OUTOFMEMORY;
340 *ppTInfo = &TypeInfo;
341 *pDescKind = DESCKIND_VARDESC;
342 return S_OK;
345 for (i = 0; i < ARRAY_SIZE(custom_engine_funcs); i++)
347 if (!lstrcmpW(szName, custom_engine_funcs[i].name))
349 *ppTInfo = &TypeInfo;
350 *pDescKind = DESCKIND_FUNCDESC;
351 pBindPtr->lpfuncdesc = get_func_desc(i);
352 return S_OK;
356 return S_OK;
359 static HRESULT WINAPI TypeComp_BindType(ITypeComp *iface, LPOLESTR szName, ULONG lHashVal,
360 ITypeInfo **ppTInfo, ITypeComp **ppTComp)
362 ok(0, "unexpected call\n");
363 return E_NOTIMPL;
366 static const ITypeCompVtbl TypeCompVtbl = {
367 TypeComp_QueryInterface,
368 TypeComp_AddRef,
369 TypeComp_Release,
370 TypeComp_Bind,
371 TypeComp_BindType
374 static ITypeComp TypeComp = { &TypeCompVtbl };
376 static BOOL TypeComp_available = FALSE;
377 static HRESULT WINAPI TypeInfo_QueryInterface(ITypeInfo *iface, REFIID riid, void **ppv)
379 *ppv = NULL;
381 if (IsEqualGUID(&IID_ITypeComp, riid))
383 CHECK_EXPECT(QI_ITypeComp);
384 if (TypeComp_available)
386 *ppv = &TypeComp;
387 return S_OK;
389 return E_NOINTERFACE;
392 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
393 return E_NOINTERFACE;
396 static ULONG WINAPI TypeInfo_AddRef(ITypeInfo *iface)
398 return 2;
401 static ULONG WINAPI TypeInfo_Release(ITypeInfo *iface)
403 return 1;
406 static UINT TypeInfo_GetTypeAttr_cFuncs;
407 static HRESULT WINAPI TypeInfo_GetTypeAttr(ITypeInfo *iface, TYPEATTR **ppTypeAttr)
409 CHECK_EXPECT(GetTypeAttr);
411 if (!(*ppTypeAttr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TYPEATTR))))
412 return E_OUTOFMEMORY;
414 (*ppTypeAttr)->cFuncs = TypeInfo_GetTypeAttr_cFuncs;
415 return S_OK;
418 static HRESULT WINAPI TypeInfo_GetTypeComp(ITypeInfo *iface, ITypeComp **ppTComp)
420 ok(0, "unexpected call\n");
421 return E_NOTIMPL;
424 static HRESULT WINAPI TypeInfo_GetFuncDesc(ITypeInfo *iface, UINT index, FUNCDESC **ppFuncDesc)
426 CHECK_EXPECT(GetFuncDesc);
428 if (index >= ARRAY_SIZE(custom_engine_funcs))
429 return E_INVALIDARG;
431 *ppFuncDesc = get_func_desc(index);
432 return S_OK;
435 static HRESULT WINAPI TypeInfo_GetVarDesc(ITypeInfo *iface, UINT index, VARDESC **ppVarDesc)
437 ok(0, "unexpected call\n");
438 return E_NOTIMPL;
441 static HRESULT WINAPI TypeInfo_GetNames(ITypeInfo *iface, MEMBERID memid, BSTR *rgBstrNames,
442 UINT cMaxNames, UINT *pcNames)
444 int idx;
446 CHECK_EXPECT(GetNames);
447 ok(cMaxNames == 1, "unexpected cMaxNames, got %u.\n", cMaxNames);
448 ok(rgBstrNames != NULL, "rgBstrNames is NULL.\n");
449 ok(pcNames != NULL, "pcNames is NULL.\n");
451 idx = memid_to_func_index(memid);
452 if (idx != -1)
454 *rgBstrNames = SysAllocString(custom_engine_funcs[idx].name);
455 *pcNames = 1;
456 return S_OK;
459 *pcNames = 0;
460 return TYPE_E_ELEMENTNOTFOUND;
463 static HRESULT WINAPI TypeInfo_GetRefTypeOfImplType(ITypeInfo *iface, UINT index, HREFTYPE *pRefType)
465 ok(0, "unexpected call\n");
466 return E_NOTIMPL;
469 static HRESULT WINAPI TypeInfo_GetImplTypeFlags(ITypeInfo *iface, UINT index, INT *pImplTypeFlags)
471 ok(0, "unexpected call\n");
472 return E_NOTIMPL;
475 static HRESULT WINAPI TypeInfo_GetIDsOfNames(ITypeInfo *iface, LPOLESTR *rgszNames, UINT cNames,
476 MEMBERID *pMemId)
478 ok(0, "unexpected call\n");
479 return E_NOTIMPL;
482 static HRESULT WINAPI TypeInfo_Invoke(ITypeInfo *iface, PVOID pvInstance, MEMBERID memid, WORD wFlags,
483 DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
485 ok(0, "unexpected call\n");
486 return E_NOTIMPL;
489 static HRESULT WINAPI TypeInfo_GetDocumentation(ITypeInfo *iface, MEMBERID memid, BSTR *pBstrName,
490 BSTR *pBstrDocString, DWORD *pdwHelpContext, BSTR *pBstrHelpFile)
492 ok(0, "unexpected call\n");
493 return E_NOTIMPL;
496 static HRESULT WINAPI TypeInfo_GetDllEntry(ITypeInfo *iface, MEMBERID memid, INVOKEKIND invKind,
497 BSTR *pBstrDllName, BSTR *pBstrName, WORD *pwOrdinal)
499 ok(0, "unexpected call\n");
500 return E_NOTIMPL;
503 static HRESULT WINAPI TypeInfo_GetRefTypeInfo(ITypeInfo *iface, HREFTYPE hRefType, ITypeInfo **ppTInfo)
505 ok(0, "unexpected call\n");
506 return E_NOTIMPL;
509 static HRESULT WINAPI TypeInfo_AddressOfMember(ITypeInfo *iface, MEMBERID memid, INVOKEKIND invKind, PVOID *ppv)
511 ok(0, "unexpected call\n");
512 return E_NOTIMPL;
515 static HRESULT WINAPI TypeInfo_CreateInstance(ITypeInfo *iface, IUnknown *pUnkOuter, REFIID riid, PVOID *ppvObj)
517 ok(0, "unexpected call\n");
518 return E_NOTIMPL;
521 static HRESULT WINAPI TypeInfo_GetMops(ITypeInfo *iface, MEMBERID memid, BSTR *pBstrMops)
523 ok(0, "unexpected call\n");
524 return E_NOTIMPL;
527 static HRESULT WINAPI TypeInfo_GetContainingTypeLib(ITypeInfo *iface, ITypeLib **ppTLib, UINT *pIndex)
529 ok(0, "unexpected call\n");
530 return E_NOTIMPL;
533 static void WINAPI TypeInfo_ReleaseTypeAttr(ITypeInfo *iface, TYPEATTR *pTypeAttr)
535 CHECK_EXPECT(ReleaseTypeAttr);
536 HeapFree(GetProcessHeap(), 0, pTypeAttr);
539 static void WINAPI TypeInfo_ReleaseFuncDesc(ITypeInfo *iface, FUNCDESC *pFuncDesc)
541 CHECK_EXPECT(ReleaseFuncDesc);
542 HeapFree(GetProcessHeap(), 0, pFuncDesc);
545 static void WINAPI TypeInfo_ReleaseVarDesc(ITypeInfo *iface, VARDESC *pVarDesc)
547 CHECK_EXPECT(ReleaseVarDesc);
548 HeapFree(GetProcessHeap(), 0, pVarDesc);
551 static const ITypeInfoVtbl TypeInfoVtbl = {
552 TypeInfo_QueryInterface,
553 TypeInfo_AddRef,
554 TypeInfo_Release,
555 TypeInfo_GetTypeAttr,
556 TypeInfo_GetTypeComp,
557 TypeInfo_GetFuncDesc,
558 TypeInfo_GetVarDesc,
559 TypeInfo_GetNames,
560 TypeInfo_GetRefTypeOfImplType,
561 TypeInfo_GetImplTypeFlags,
562 TypeInfo_GetIDsOfNames,
563 TypeInfo_Invoke,
564 TypeInfo_GetDocumentation,
565 TypeInfo_GetDllEntry,
566 TypeInfo_GetRefTypeInfo,
567 TypeInfo_AddressOfMember,
568 TypeInfo_CreateInstance,
569 TypeInfo_GetMops,
570 TypeInfo_GetContainingTypeLib,
571 TypeInfo_ReleaseTypeAttr,
572 TypeInfo_ReleaseFuncDesc,
573 TypeInfo_ReleaseVarDesc
576 static ITypeInfo TypeInfo = { &TypeInfoVtbl };
578 static BOOL DispatchEx_available = FALSE;
579 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
581 *ppv = NULL;
583 if (IsEqualGUID(&IID_IDispatchEx, riid))
585 CHECK_EXPECT(QI_IDispatchEx);
586 if (DispatchEx_available)
588 *ppv = iface;
589 return S_OK;
591 return E_NOINTERFACE;
594 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
595 return E_NOINTERFACE;
598 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
600 return 2;
603 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
605 return 1;
608 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
610 ok(0, "unexpected call\n");
611 return E_NOTIMPL;
614 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
616 CHECK_EXPECT(GetTypeInfo);
617 ok(iTInfo == 0, "unexpected iTInfo %u.\n", iTInfo);
618 ok(lcid == LOCALE_USER_DEFAULT, "unexpected lcid %u\n", lcid);
620 *ppTInfo = &TypeInfo;
621 return S_OK;
624 static BSTR Dispatch_expected_name;
625 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid, LPOLESTR *rgszNames,
626 UINT cNames, LCID lcid, DISPID *rgDispId)
628 CHECK_EXPECT(GetIDsOfNames);
629 ok(IsEqualGUID(&IID_NULL, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
630 ok(lcid == LOCALE_USER_DEFAULT, "unexpected lcid %u\n", lcid);
631 ok(cNames == 1, "unexpected cNames %u\n", cNames);
632 ok(Dispatch_expected_name && !lstrcmpW(rgszNames[0], Dispatch_expected_name),
633 "unexpected name %s (expected %s).\n", wine_dbgstr_w(rgszNames[0]), wine_dbgstr_w(Dispatch_expected_name));
635 *rgDispId = 0xdeadbeef;
636 return S_OK;
639 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
640 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
642 CHECK_EXPECT(Invoke);
643 ok(IsEqualGUID(&IID_NULL, riid), "unexpected riid %s.\n", wine_dbgstr_guid(riid));
644 ok(lcid == LOCALE_USER_DEFAULT, "unexpected lcid %u.\n", lcid);
645 ok(wFlags == DISPATCH_METHOD, "unexpected wFlags %u.\n", wFlags);
646 ok(dispIdMember == 0xdeadbeef, "unexpected dispIdMember %d.\n", dispIdMember);
647 ok(pDispParams->cNamedArgs == 0, "unexpected number of named args %u.\n", pDispParams->cNamedArgs);
648 ok(!pDispParams->rgdispidNamedArgs, "unexpected named args array %p\n", pDispParams->rgdispidNamedArgs);
649 ok(pDispParams->cArgs == 2, "unexpected number of args %u.\n", pDispParams->cArgs);
650 ok(!!pDispParams->rgvarg, "unexpected NULL rgvarg.\n");
651 if (pDispParams->rgvarg && pDispParams->cArgs >= 2)
653 ok(V_VT(pDispParams->rgvarg + 1) == VT_I4 && V_I4(pDispParams->rgvarg + 1) == 10,
654 "unexpected first parameter V_VT = %d, V_I4 = %d.\n",
655 V_VT(pDispParams->rgvarg + 1), V_I4(pDispParams->rgvarg + 1));
656 ok(V_VT(pDispParams->rgvarg) == VT_I4 && V_I4(pDispParams->rgvarg) == 3,
657 "unexpected second parameter V_VT = %d, V_I4 = %d.\n",
658 V_VT(pDispParams->rgvarg), V_I4(pDispParams->rgvarg));
661 V_VT(pVarResult) = VT_R8;
662 V_R8(pVarResult) = 4.2;
663 return S_OK;
666 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
668 ok(0, "unexpected call\n");
669 return E_NOTIMPL;
672 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags,
673 DISPPARAMS *pdp, VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
675 IServiceProvider *sp;
676 IUnknown *unk;
677 HRESULT hr;
679 CHECK_EXPECT(InvokeEx);
680 ok(lcid == LOCALE_USER_DEFAULT, "unexpected lcid %u.\n", lcid);
681 ok(wFlags == DISPATCH_METHOD, "unexpected wFlags %u.\n", wFlags);
682 ok(id == 0xdeadbeef, "unexpected id %d.\n", id);
683 ok(pdp->cNamedArgs == 0, "unexpected number of named args %u.\n", pdp->cNamedArgs);
684 ok(!pdp->rgdispidNamedArgs, "unexpected named args array %p.\n", pdp->rgdispidNamedArgs);
685 ok(pdp->cArgs == 2, "unexpected number of args %u.\n", pdp->cArgs);
686 ok(!!pdp->rgvarg, "unexpected NULL rgvarg.\n");
687 if (pdp->rgvarg && pdp->cArgs >= 2)
689 ok(V_VT(pdp->rgvarg + 1) == VT_I4 && V_I4(pdp->rgvarg + 1) == 10,
690 "unexpected first parameter V_VT = %d, V_I4 = %d.\n",
691 V_VT(pdp->rgvarg + 1), V_I4(pdp->rgvarg + 1));
692 ok(V_VT(pdp->rgvarg) == VT_I4 && V_I4(pdp->rgvarg) == 3,
693 "unexpected second parameter V_VT = %d, V_I4 = %d.\n",
694 V_VT(pdp->rgvarg), V_I4(pdp->rgvarg));
696 ok(!!pspCaller, "unexpected NULL pspCaller.\n");
698 hr = IActiveScriptSite_QueryInterface(site, &IID_IServiceProvider, (void**)&sp);
699 ok(hr == S_OK, "Failed to retrieve IID_IServiceProvider from script site: 0x%08x.\n", hr);
700 ok(sp != pspCaller, "Same IServiceProvider objects.\n");
701 IServiceProvider_Release(sp);
703 hr = IServiceProvider_QueryInterface(pspCaller, &IID_IActiveScriptSite, (void**)&unk);
704 ok(hr == E_NOINTERFACE, "QueryInterface IActiveScriptSite returned: 0x%08x.\n", hr);
706 unk = (IUnknown*)0xdeadbeef;
707 hr = IServiceProvider_QueryService(pspCaller, &SID_GetCaller, NULL, (void**)&unk);
708 ok(hr == S_OK, "QueryService failed: 0x%08x.\n", hr);
709 ok(!unk, "unexpected object returned %p.\n", unk);
710 unk = (IUnknown*)0xdeadbeef;
711 hr = IServiceProvider_QueryService(pspCaller, &SID_GetCaller, &IID_IUnknown, (void**)&unk);
712 ok(hr == S_OK, "QueryService failed: 0x%08x.\n", hr);
713 ok(!unk, "unexpected object returned %p.\n", unk);
714 sp = (IServiceProvider*)0xdeadbeef;
715 hr = IServiceProvider_QueryService(pspCaller, &SID_GetCaller, &IID_IServiceProvider, (void**)&sp);
716 ok(hr == S_OK, "QueryService failed: 0x%08x.\n", hr);
717 ok(!sp, "unexpected object returned %p.\n", sp);
718 unk = (IUnknown*)0xdeadbeef;
719 hr = IServiceProvider_QueryService(pspCaller, &SID_VariantConversion, &IID_IVariantChangeType, (void**)&unk);
720 ok(hr == E_NOINTERFACE, "QueryService returned: 0x%08x.\n", hr);
721 ok(!unk, "unexpected object returned %p.\n", unk);
723 V_VT(pvarRes) = VT_I2;
724 V_I2(pvarRes) = 42;
725 return S_OK;
728 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
730 ok(0, "unexpected call\n");
731 return E_NOTIMPL;
734 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
736 ok(0, "unexpected call\n");
737 return E_NOTIMPL;
740 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch,
741 DWORD *pgrfdex)
743 ok(0, "unexpected call\n");
744 return E_NOTIMPL;
747 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
749 ok(0, "unexpected call\n");
750 return E_NOTIMPL;
753 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
755 ok(0, "unexpected call\n");
756 return E_NOTIMPL;
759 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
761 ok(0, "unexpected call\n");
762 return E_NOTIMPL;
765 static const IDispatchExVtbl DispatchExVtbl = {
766 DispatchEx_QueryInterface,
767 DispatchEx_AddRef,
768 DispatchEx_Release,
769 DispatchEx_GetTypeInfoCount,
770 DispatchEx_GetTypeInfo,
771 DispatchEx_GetIDsOfNames,
772 DispatchEx_Invoke,
773 DispatchEx_GetDispID,
774 DispatchEx_InvokeEx,
775 DispatchEx_DeleteMemberByName,
776 DispatchEx_DeleteMemberByDispID,
777 DispatchEx_GetMemberProperties,
778 DispatchEx_GetMemberName,
779 DispatchEx_GetNextDispID,
780 DispatchEx_GetNameSpaceParent
783 static IDispatchEx DispatchEx = { &DispatchExVtbl };
785 static HRESULT WINAPI ActiveScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
787 *ppv = NULL;
789 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IActiveScript, riid)) {
790 *ppv = iface;
791 return S_OK;
794 if(IsEqualGUID(&IID_IObjectSafety, riid)) {
795 *ppv = &ObjectSafety;
796 return S_OK;
799 if(IsEqualGUID(&IID_IActiveScriptParse, riid)) {
800 CHECK_EXPECT(QI_IActiveScriptParse);
801 *ppv = &ActiveScriptParse;
802 return S_OK;
805 if(IsEqualGUID(&IID_IActiveScriptGarbageCollector, riid))
806 return E_NOINTERFACE;
808 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
809 return E_NOINTERFACE;
812 static ULONG WINAPI ActiveScript_AddRef(IActiveScript *iface)
814 return 2;
817 static ULONG WINAPI ActiveScript_Release(IActiveScript *iface)
819 return 1;
822 static HRESULT WINAPI ActiveScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
824 IActiveScriptSiteInterruptPoll *poll;
825 IActiveScriptSiteWindow *window;
826 IActiveScriptSiteDebug *debug;
827 IServiceProvider *service;
828 ICanHandleException *canexception;
829 LCID lcid;
830 HRESULT hres;
832 CHECK_EXPECT(SetScriptSite);
834 ok(pass != NULL, "pass == NULL\n");
836 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteInterruptPoll, (void**)&poll);
837 ok(hres == E_NOINTERFACE, "Got IActiveScriptSiteInterruptPoll interface: %08x\n", hres);
839 hres = IActiveScriptSite_GetLCID(pass, &lcid);
840 ok(hres == S_OK, "GetLCID failed: %08x\n", hres);
842 hres = IActiveScriptSite_OnStateChange(pass, (state = SCRIPTSTATE_INITIALIZED));
843 ok(hres == E_NOTIMPL, "OnStateChange failed: %08x\n", hres);
845 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteDebug, (void**)&debug);
846 ok(hres == E_NOINTERFACE, "Got IActiveScriptSiteDebug interface: %08x\n", hres);
848 hres = IActiveScriptSite_QueryInterface(pass, &IID_ICanHandleException, (void**)&canexception);
849 ok(hres == E_NOINTERFACE, "Got IID_ICanHandleException interface: %08x\n", hres);
851 hres = IActiveScriptSite_QueryInterface(pass, &IID_IServiceProvider, (void**)&service);
852 ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
853 IServiceProvider_Release(service);
855 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteWindow, (void**)&window);
856 ok(hres == S_OK, "Could not get IActiveScriptSiteWindow interface: %08x\n", hres);
857 IActiveScriptSiteWindow_Release(window);
859 if (site)
860 IActiveScriptSite_Release(site);
861 site = pass;
862 IActiveScriptSite_AddRef(site);
864 return S_OK;
867 static HRESULT WINAPI ActiveScript_GetScriptSite(IActiveScript *iface, REFIID riid,
868 void **ppvObject)
870 ok(0, "unexpected call\n");
871 return E_NOTIMPL;
874 static HRESULT WINAPI ActiveScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
876 switch(ss)
878 case SCRIPTSTATE_INITIALIZED:
879 CHECK_EXPECT(SetScriptState_INITIALIZED);
880 return S_OK;
881 case SCRIPTSTATE_STARTED:
882 CHECK_EXPECT(SetScriptState_STARTED);
883 return S_OK;
884 case SCRIPTSTATE_CONNECTED:
885 CHECK_EXPECT(SetScriptState_CONNECTED);
886 return S_OK;
887 default:
888 ok(0, "unexpected call, state %u\n", ss);
889 return E_NOTIMPL;
893 static SCRIPTSTATE emulated_script_state;
895 static HRESULT WINAPI ActiveScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
897 CHECK_EXPECT(GetScriptState);
898 *pssState = emulated_script_state;
899 return S_OK;
902 static HRESULT WINAPI ActiveScript_Close(IActiveScript *iface)
904 CHECK_EXPECT(Close);
905 return E_NOTIMPL;
908 static const WCHAR *AddNamedItem_expected_name;
909 static DWORD AddNamedItem_expected_flags;
910 static HRESULT WINAPI ActiveScript_AddNamedItem(IActiveScript *iface, LPCOLESTR name, DWORD flags)
912 CHECK_EXPECT(AddNamedItem);
913 ok(!lstrcmpW(name, AddNamedItem_expected_name), "got name %s\n", wine_dbgstr_w(name));
914 ok(flags == AddNamedItem_expected_flags, "got flags %#x\n", flags);
915 return S_OK;
918 static HRESULT WINAPI ActiveScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
919 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
921 ok(0, "unexpected call\n");
922 return E_NOTIMPL;
925 static const WCHAR *GetScriptDispatch_expected_name;
926 static HRESULT WINAPI ActiveScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
927 IDispatch **ppdisp)
929 CHECK_EXPECT(GetScriptDispatch);
930 ok(GetScriptDispatch_expected_name ? (pstrItemName && !lstrcmpW(pstrItemName, GetScriptDispatch_expected_name)) : !pstrItemName,
931 "pstrItemName not %s, got %s.\n", wine_dbgstr_w(GetScriptDispatch_expected_name), wine_dbgstr_w(pstrItemName));
933 *ppdisp = (IDispatch*)&DispatchEx;
935 return S_OK;
938 static HRESULT WINAPI ActiveScript_GetCurrentScriptThreadID(IActiveScript *iface,
939 SCRIPTTHREADID *pstridThread)
941 ok(0, "unexpected call\n");
942 return E_NOTIMPL;
945 static HRESULT WINAPI ActiveScript_GetScriptThreadID(IActiveScript *iface,
946 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
948 ok(0, "unexpected call\n");
949 return E_NOTIMPL;
952 static HRESULT WINAPI ActiveScript_GetScriptThreadState(IActiveScript *iface,
953 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
955 ok(0, "unexpected call\n");
956 return E_NOTIMPL;
959 static HRESULT WINAPI ActiveScript_InterruptScriptThread(IActiveScript *iface,
960 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
962 ok(0, "unexpected call\n");
963 return E_NOTIMPL;
966 static HRESULT WINAPI ActiveScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
968 ok(0, "unexpected call\n");
969 return E_NOTIMPL;
972 static const IActiveScriptVtbl ActiveScriptVtbl = {
973 ActiveScript_QueryInterface,
974 ActiveScript_AddRef,
975 ActiveScript_Release,
976 ActiveScript_SetScriptSite,
977 ActiveScript_GetScriptSite,
978 ActiveScript_SetScriptState,
979 ActiveScript_GetScriptState,
980 ActiveScript_Close,
981 ActiveScript_AddNamedItem,
982 ActiveScript_AddTypeLib,
983 ActiveScript_GetScriptDispatch,
984 ActiveScript_GetCurrentScriptThreadID,
985 ActiveScript_GetScriptThreadID,
986 ActiveScript_GetScriptThreadState,
987 ActiveScript_InterruptScriptThread,
988 ActiveScript_Clone
991 static IActiveScript ActiveScript = { &ActiveScriptVtbl };
993 static HRESULT WINAPI ActiveScriptError_QueryInterface(IActiveScriptError *iface, REFIID riid, void **ppv)
995 *ppv = NULL;
997 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IActiveScriptError, riid)) {
998 *ppv = iface;
999 return S_OK;
1002 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
1003 return E_NOINTERFACE;
1006 static ULONG WINAPI ActiveScriptError_AddRef(IActiveScriptError *iface)
1008 return 2;
1011 static ULONG WINAPI ActiveScriptError_Release(IActiveScriptError *iface)
1013 return 1;
1016 static unsigned ActiveScriptError_stage = 0;
1018 static HRESULT WINAPI ActiveScriptError_DeferredFillIn(EXCEPINFO *pexcepinfo)
1020 CHECK_EXPECT(DeferredFillIn);
1022 pexcepinfo->bstrSource = SysAllocString(L"foobar");
1023 pexcepinfo->bstrDescription = SysAllocString(L"barfoo");
1025 /* Failure is ignored */
1026 return E_FAIL;
1029 static HRESULT WINAPI ActiveScriptError_GetExceptionInfo(IActiveScriptError *iface, EXCEPINFO *pexcepinfo)
1031 CHECK_EXPECT(GetExceptionInfo);
1033 memset(pexcepinfo, 0, sizeof(*pexcepinfo));
1034 pexcepinfo->wCode = 0xdead;
1035 pexcepinfo->pfnDeferredFillIn = ActiveScriptError_DeferredFillIn;
1037 if (ActiveScriptError_stage == 0) return E_FAIL;
1038 if (ActiveScriptError_stage == 2)
1040 pexcepinfo->wCode = 0;
1041 pexcepinfo->scode = 0xbeef;
1042 pexcepinfo->bstrSource = SysAllocString(L"source");
1043 pexcepinfo->pfnDeferredFillIn = NULL;
1045 return S_OK;
1048 static HRESULT WINAPI ActiveScriptError_GetSourcePosition(IActiveScriptError *iface, DWORD *pdwSourceContext,
1049 ULONG *pulLineNumber, LONG *pichCharPosition)
1051 CHECK_EXPECT(GetSourcePosition);
1053 *pdwSourceContext = 0xdeadbeef;
1054 *pulLineNumber = 42;
1055 *pichCharPosition = 10;
1057 return (ActiveScriptError_stage == 0) ? E_FAIL : S_OK;
1060 static HRESULT WINAPI ActiveScriptError_GetSourceLineText(IActiveScriptError *iface, BSTR *pbstrSourceLine)
1062 CHECK_EXPECT(GetSourceLineText);
1064 *pbstrSourceLine = SysAllocString(L"source line");
1066 /* Failure is ignored */
1067 return E_FAIL;
1070 static const IActiveScriptErrorVtbl ActiveScriptErrorVtbl = {
1071 ActiveScriptError_QueryInterface,
1072 ActiveScriptError_AddRef,
1073 ActiveScriptError_Release,
1074 ActiveScriptError_GetExceptionInfo,
1075 ActiveScriptError_GetSourcePosition,
1076 ActiveScriptError_GetSourceLineText
1079 static IActiveScriptError ActiveScriptError = { &ActiveScriptErrorVtbl };
1081 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1083 *ppv = NULL;
1085 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
1086 *ppv = iface;
1087 return S_OK;
1090 if(IsEqualGUID(&IID_IMarshal, riid))
1091 return E_NOINTERFACE;
1093 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
1094 return E_NOINTERFACE;
1097 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1099 return 2;
1102 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1104 return 1;
1107 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1109 CHECK_EXPECT(CreateInstance);
1111 ok(!outer, "outer = %p\n", outer);
1112 ok(IsEqualGUID(&IID_IActiveScript, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
1113 *ppv = &ActiveScript;
1114 site = NULL;
1115 return S_OK;
1118 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1120 ok(0, "unexpected call\n");
1121 return S_OK;
1124 static const IClassFactoryVtbl ClassFactoryVtbl = {
1125 ClassFactory_QueryInterface,
1126 ClassFactory_AddRef,
1127 ClassFactory_Release,
1128 ClassFactory_CreateInstance,
1129 ClassFactory_LockServer
1132 static IClassFactory script_cf = { &ClassFactoryVtbl };
1134 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
1136 HKEY hkey;
1137 DWORD res;
1139 if(!init) {
1140 RegDeleteKeyA(HKEY_CLASSES_ROOT, key_name);
1141 return TRUE;
1144 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
1145 if(res != ERROR_SUCCESS)
1146 return FALSE;
1148 if(def_value)
1149 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
1151 RegCloseKey(hkey);
1153 return res == ERROR_SUCCESS;
1156 static BOOL init_registry(BOOL init)
1158 return init_key("TestScript\\CLSID", TESTSCRIPT_CLSID, init)
1159 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}",
1160 NULL, init)
1161 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
1162 NULL, init);
1165 static BOOL register_script_engine(void)
1167 DWORD regid;
1168 HRESULT hres;
1170 if(!init_registry(TRUE)) {
1171 init_registry(FALSE);
1172 return FALSE;
1175 hres = CoRegisterClassObject(&CLSID_TestScript, (IUnknown *)&script_cf,
1176 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
1177 ok(hres == S_OK, "Could not register script engine: %08x\n", hres);
1179 return TRUE;
1182 static BOOL have_custom_engine;
1184 static HRESULT WINAPI OleClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **obj)
1186 if (IsEqualIID(riid, &IID_IOleClientSite) || IsEqualIID(riid, &IID_IUnknown))
1188 *obj = iface;
1189 IOleClientSite_AddRef(iface);
1190 return S_OK;
1193 *obj = NULL;
1194 return E_NOINTERFACE;
1197 static ULONG WINAPI OleClientSite_AddRef(IOleClientSite *iface)
1199 return 2;
1202 static ULONG WINAPI OleClientSite_Release(IOleClientSite *iface)
1204 return 1;
1207 static HRESULT WINAPI OleClientSite_SaveObject(IOleClientSite *iface)
1209 return E_NOTIMPL;
1212 static HRESULT WINAPI OleClientSite_GetMoniker(IOleClientSite *iface, DWORD assign,
1213 DWORD which, IMoniker **moniker)
1215 return E_NOTIMPL;
1218 static HRESULT WINAPI OleClientSite_GetContainer(IOleClientSite *iface, IOleContainer **container)
1220 return E_NOTIMPL;
1223 static HRESULT WINAPI OleClientSite_ShowObject(IOleClientSite *iface)
1225 return E_NOTIMPL;
1228 static HRESULT WINAPI OleClientSite_OnShowWindow(IOleClientSite *iface, BOOL show)
1230 return E_NOTIMPL;
1233 static HRESULT WINAPI OleClientSite_RequestNewObjectLayout(IOleClientSite *iface)
1235 return E_NOTIMPL;
1238 static const IOleClientSiteVtbl OleClientSiteVtbl = {
1239 OleClientSite_QueryInterface,
1240 OleClientSite_AddRef,
1241 OleClientSite_Release,
1242 OleClientSite_SaveObject,
1243 OleClientSite_GetMoniker,
1244 OleClientSite_GetContainer,
1245 OleClientSite_ShowObject,
1246 OleClientSite_OnShowWindow,
1247 OleClientSite_RequestNewObjectLayout
1250 static IOleClientSite testclientsite = { &OleClientSiteVtbl };
1252 static void test_oleobject(void)
1254 DWORD status, dpi_x, dpi_y;
1255 IOleClientSite *site;
1256 IOleObject *obj;
1257 SIZEL extent;
1258 HRESULT hr;
1259 HDC hdc;
1261 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1262 &IID_IOleObject, (void**)&obj);
1263 ok(hr == S_OK, "got 0x%08x\n", hr);
1265 if (0) /* crashes on w2k3 */
1266 hr = IOleObject_GetMiscStatus(obj, DVASPECT_CONTENT, NULL);
1268 status = 0;
1269 hr = IOleObject_GetMiscStatus(obj, DVASPECT_CONTENT, &status);
1270 ok(hr == S_OK, "got 0x%08x\n", hr);
1271 ok(status != 0, "got 0x%08x\n", status);
1273 hr = IOleObject_SetClientSite(obj, &testclientsite);
1274 ok(hr == S_OK, "got 0x%08x\n", hr);
1276 if (0) /* crashes on w2k3 */
1277 hr = IOleObject_GetClientSite(obj, NULL);
1279 hr = IOleObject_GetClientSite(obj, &site);
1280 ok(hr == S_OK, "got 0x%08x\n", hr);
1281 ok(site == &testclientsite, "got %p, %p\n", site, &testclientsite);
1282 IOleClientSite_Release(site);
1284 hr = IOleObject_SetClientSite(obj, NULL);
1285 ok(hr == S_OK, "got 0x%08x\n", hr);
1287 hr = IOleObject_GetClientSite(obj, &site);
1288 ok(hr == S_OK, "got 0x%08x\n", hr);
1289 ok(site == NULL, "got %p\n", site);
1291 /* extents */
1292 hdc = GetDC(0);
1293 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
1294 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
1295 ReleaseDC(0, hdc);
1297 memset(&extent, 0, sizeof(extent));
1298 hr = IOleObject_GetExtent(obj, DVASPECT_CONTENT, &extent);
1299 ok(hr == S_OK, "got 0x%08x\n", hr);
1300 ok(extent.cx == MulDiv(38, 2540, dpi_x), "got %d\n", extent.cx);
1301 ok(extent.cy == MulDiv(38, 2540, dpi_y), "got %d\n", extent.cy);
1303 extent.cx = extent.cy = 0xdeadbeef;
1304 hr = IOleObject_GetExtent(obj, DVASPECT_THUMBNAIL, &extent);
1305 ok(hr == DV_E_DVASPECT, "got 0x%08x\n", hr);
1306 ok(extent.cx == 0xdeadbeef, "got %d\n", extent.cx);
1307 ok(extent.cy == 0xdeadbeef, "got %d\n", extent.cy);
1309 extent.cx = extent.cy = 0xdeadbeef;
1310 hr = IOleObject_GetExtent(obj, DVASPECT_ICON, &extent);
1311 ok(hr == DV_E_DVASPECT, "got 0x%08x\n", hr);
1312 ok(extent.cx == 0xdeadbeef, "got %d\n", extent.cx);
1313 ok(extent.cy == 0xdeadbeef, "got %d\n", extent.cy);
1315 extent.cx = extent.cy = 0xdeadbeef;
1316 hr = IOleObject_GetExtent(obj, DVASPECT_DOCPRINT, &extent);
1317 ok(hr == DV_E_DVASPECT, "got 0x%08x\n", hr);
1318 ok(extent.cx == 0xdeadbeef, "got %d\n", extent.cx);
1319 ok(extent.cy == 0xdeadbeef, "got %d\n", extent.cy);
1321 IOleObject_Release(obj);
1324 static void test_persiststreaminit(void)
1326 IPersistStreamInit *init;
1327 HRESULT hr;
1329 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1330 &IID_IPersistStreamInit, (void**)&init);
1331 ok(hr == S_OK, "got 0x%08x\n", hr);
1333 IPersistStreamInit_Release(init);
1336 static void test_olecontrol(void)
1338 IOleControl *olecontrol;
1339 CONTROLINFO info;
1340 HRESULT hr;
1342 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1343 &IID_IOleControl, (void**)&olecontrol);
1344 ok(hr == S_OK, "got 0x%08x\n", hr);
1346 memset(&info, 0xab, sizeof(info));
1347 info.cb = sizeof(info);
1348 hr = IOleControl_GetControlInfo(olecontrol, &info);
1349 ok(hr == S_OK, "got 0x%08x\n", hr);
1350 ok(info.hAccel == NULL, "got %p\n", info.hAccel);
1351 ok(info.cAccel == 0, "got %d\n", info.cAccel);
1352 ok(info.dwFlags == 0xabababab, "got %x\n", info.dwFlags);
1354 memset(&info, 0xab, sizeof(info));
1355 info.cb = sizeof(info) - 1;
1356 hr = IOleControl_GetControlInfo(olecontrol, &info);
1357 ok(hr == S_OK, "got 0x%08x\n", hr);
1358 ok(info.hAccel == NULL, "got %p\n", info.hAccel);
1359 ok(info.cAccel == 0, "got %d\n", info.cAccel);
1360 ok(info.dwFlags == 0xabababab, "got %x\n", info.dwFlags);
1362 if (0) /* crashes on win2k3 */
1364 hr = IOleControl_GetControlInfo(olecontrol, NULL);
1365 ok(hr == E_POINTER, "got 0x%08x\n", hr);
1368 IOleControl_Release(olecontrol);
1371 static void test_Language(void)
1373 IScriptControl *sc;
1374 HRESULT hr;
1375 BSTR str;
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 hr = IScriptControl_get_Language(sc, NULL);
1382 ok(hr == E_POINTER, "got 0x%08x\n", hr);
1384 str = (BSTR)0xdeadbeef;
1385 hr = IScriptControl_get_Language(sc, &str);
1386 ok(hr == S_OK, "got 0x%08x\n", hr);
1387 ok(str == NULL, "got %s\n", wine_dbgstr_w(str));
1389 str = SysAllocString(L"VBScript");
1390 hr = IScriptControl_put_Language(sc, str);
1391 ok(hr == S_OK, "got 0x%08x\n", hr);
1392 SysFreeString(str);
1394 str = SysAllocString(L"vBscript");
1395 hr = IScriptControl_put_Language(sc, str);
1396 ok(hr == S_OK, "got 0x%08x\n", hr);
1397 SysFreeString(str);
1399 hr = IScriptControl_get_Language(sc, &str);
1400 ok(hr == S_OK, "got 0x%08x\n", hr);
1401 ok(!lstrcmpW(str, L"VBScript"), "got %s\n", wine_dbgstr_w(str));
1402 SysFreeString(str);
1404 str = SysAllocString(L"dummy");
1405 hr = IScriptControl_put_Language(sc, str);
1406 ok(hr == CTL_E_INVALIDPROPERTYVALUE, "got 0x%08x\n", hr);
1407 SysFreeString(str);
1409 hr = IScriptControl_get_Language(sc, &str);
1410 ok(hr == S_OK, "got 0x%08x\n", hr);
1411 ok(!lstrcmpW(str, L"VBScript"), "got %s\n", wine_dbgstr_w(str));
1412 SysFreeString(str);
1414 str = SysAllocString(L"JScript");
1415 hr = IScriptControl_put_Language(sc, str);
1416 ok(hr == S_OK, "got 0x%08x\n", hr);
1417 SysFreeString(str);
1419 hr = IScriptControl_get_Language(sc, &str);
1420 ok(hr == S_OK, "got 0x%08x\n", hr);
1421 ok(!lstrcmpW(str, L"JScript"), "got %s\n", wine_dbgstr_w(str));
1422 SysFreeString(str);
1424 hr = IScriptControl_put_Language(sc, NULL);
1425 ok(hr == S_OK, "got 0x%08x\n", hr);
1427 hr = IScriptControl_get_Language(sc, &str);
1428 ok(hr == S_OK, "got 0x%08x\n", hr);
1429 ok(str == NULL, "got %s\n", wine_dbgstr_w(str));
1431 IScriptControl_Release(sc);
1433 /* custom script engine */
1434 if (have_custom_engine) {
1435 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1436 &IID_IScriptControl, (void**)&sc);
1437 ok(hr == S_OK, "got 0x%08x\n", hr);
1439 SET_EXPECT(CreateInstance);
1440 SET_EXPECT(SetInterfaceSafetyOptions);
1441 SET_EXPECT(SetScriptSite);
1442 SET_EXPECT(QI_IActiveScriptParse);
1443 SET_EXPECT(InitNew);
1445 str = SysAllocString(L"testscript");
1446 hr = IScriptControl_put_Language(sc, str);
1447 ok(hr == S_OK, "got 0x%08x\n", hr);
1448 SysFreeString(str);
1450 CHECK_CALLED(CreateInstance);
1451 CHECK_CALLED(SetInterfaceSafetyOptions);
1452 CHECK_CALLED(SetScriptSite);
1453 CHECK_CALLED(QI_IActiveScriptParse);
1454 CHECK_CALLED(InitNew);
1455 hr = IScriptControl_get_Language(sc, &str);
1456 todo_wine
1457 ok(hr == S_OK, "got 0x%08x\n", hr);
1458 if (hr == S_OK)
1459 ok(!lstrcmpW(L"testscript", str), "%s\n", wine_dbgstr_w(str));
1460 SysFreeString(str);
1462 IActiveScriptSite_Release(site);
1464 SET_EXPECT(Close);
1466 IScriptControl_Release(sc);
1468 CHECK_CALLED(Close);
1472 static void test_connectionpoints(void)
1474 IConnectionPointContainer *container, *container2;
1475 IConnectionPoint *cp;
1476 IScriptControl *sc;
1477 HRESULT hr;
1478 IID iid;
1480 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1481 &IID_IScriptControl, (void**)&sc);
1482 ok(hr == S_OK, "got 0x%08x\n", hr);
1484 EXPECT_REF(sc, 1);
1485 hr = IScriptControl_QueryInterface(sc, &IID_IConnectionPointContainer, (void**)&container);
1486 ok(hr == S_OK, "got 0x%08x\n", hr);
1487 EXPECT_REF(sc, 2);
1488 EXPECT_REF(container, 2);
1490 hr = IConnectionPointContainer_FindConnectionPoint(container, &IID_IPropertyNotifySink, &cp);
1491 ok(hr == S_OK, "got 0x%08x\n", hr);
1493 if (0) /* crashes on win2k3 */
1495 hr = IConnectionPoint_GetConnectionPointContainer(cp, NULL);
1496 ok(hr == E_POINTER, "got 0x%08x\n", hr);
1499 hr = IConnectionPoint_GetConnectionInterface(cp, &iid);
1500 ok(hr == S_OK, "got 0x%08x\n", hr);
1501 ok(IsEqualIID(&iid, &IID_IPropertyNotifySink), "got %s\n", wine_dbgstr_guid(&iid));
1503 hr = IConnectionPoint_GetConnectionPointContainer(cp, &container2);
1504 ok(hr == S_OK, "got 0x%08x\n", hr);
1505 ok(container2 == container, "got %p, expected %p\n", container2, container);
1506 IConnectionPointContainer_Release(container2);
1508 IConnectionPoint_Release(cp);
1510 hr = IConnectionPointContainer_FindConnectionPoint(container, &DIID_DScriptControlSource, &cp);
1511 ok(hr == S_OK, "got 0x%08x\n", hr);
1513 if (0) /* crashes on win2k3 */
1515 hr = IConnectionPoint_GetConnectionPointContainer(cp, NULL);
1516 ok(hr == E_POINTER, "got 0x%08x\n", hr);
1519 hr = IConnectionPoint_GetConnectionInterface(cp, &iid);
1520 ok(hr == S_OK, "got 0x%08x\n", hr);
1521 ok(IsEqualIID(&iid, &DIID_DScriptControlSource), "got %s\n", wine_dbgstr_guid(&iid));
1523 hr = IConnectionPoint_GetConnectionPointContainer(cp, &container2);
1524 ok(hr == S_OK, "got 0x%08x\n", hr);
1525 ok(container2 == container, "got %p, expected %p\n", container2, container);
1526 IConnectionPointContainer_Release(container2);
1528 IConnectionPoint_Release(cp);
1530 IConnectionPointContainer_Release(container);
1531 IScriptControl_Release(sc);
1534 static void test_quickactivate(void)
1536 IScriptControl *sc;
1537 IQuickActivate *qa;
1538 HRESULT hr;
1540 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1541 &IID_IScriptControl, (void**)&sc);
1542 ok(hr == S_OK, "got 0x%08x\n", hr);
1544 hr = IScriptControl_QueryInterface(sc, &IID_IQuickActivate, (void**)&qa);
1545 ok(hr == S_OK, "got 0x%08x\n", hr);
1547 IQuickActivate_Release(qa);
1548 IScriptControl_Release(sc);
1551 static void test_viewobject(void)
1553 DWORD status, aspect, flags;
1554 IViewObjectEx *viewex;
1555 IScriptControl *sc;
1556 IViewObject *view;
1557 IAdviseSink *sink;
1558 HRESULT hr;
1560 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1561 &IID_IScriptControl, (void**)&sc);
1562 ok(hr == S_OK, "got 0x%08x\n", hr);
1564 hr = IScriptControl_QueryInterface(sc, &IID_IViewObject, (void**)&view);
1565 ok(hr == S_OK, "got 0x%08x\n", hr);
1566 IViewObject_Release(view);
1568 hr = IScriptControl_QueryInterface(sc, &IID_IViewObject2, (void**)&view);
1569 ok(hr == S_OK, "got 0x%08x\n", hr);
1571 sink = (IAdviseSink*)0xdeadbeef;
1572 hr = IViewObject_GetAdvise(view, &aspect, &flags, &sink);
1573 ok(hr == S_OK, "got 0x%08x\n", hr);
1574 ok(aspect == DVASPECT_CONTENT, "got %u\n", aspect);
1575 ok(flags == 0, "got %#x\n", flags);
1576 ok(sink == NULL, "got %p\n", sink);
1578 hr = IViewObject_SetAdvise(view, DVASPECT_CONTENT, 0, NULL);
1579 ok(hr == S_OK, "got 0x%08x\n", hr);
1581 hr = IViewObject_SetAdvise(view, DVASPECT_THUMBNAIL, 0, NULL);
1582 ok(hr == DV_E_DVASPECT, "got 0x%08x\n", hr);
1584 hr = IViewObject_SetAdvise(view, DVASPECT_ICON, 0, NULL);
1585 ok(hr == DV_E_DVASPECT, "got 0x%08x\n", hr);
1587 hr = IViewObject_SetAdvise(view, DVASPECT_DOCPRINT, 0, NULL);
1588 ok(hr == DV_E_DVASPECT, "got 0x%08x\n", hr);
1590 sink = (IAdviseSink*)0xdeadbeef;
1591 hr = IViewObject_GetAdvise(view, &aspect, &flags, &sink);
1592 ok(hr == S_OK, "got 0x%08x\n", hr);
1593 ok(aspect == DVASPECT_CONTENT, "got %u\n", aspect);
1594 ok(flags == 0, "got %#x\n", flags);
1595 ok(sink == NULL, "got %p\n", sink);
1597 IViewObject_Release(view);
1599 hr = IScriptControl_QueryInterface(sc, &IID_IViewObjectEx, (void**)&viewex);
1600 ok(hr == S_OK, "got 0x%08x\n", hr);
1602 if (0) /* crashes */
1603 hr = IViewObjectEx_GetViewStatus(viewex, NULL);
1605 status = 0;
1606 hr = IViewObjectEx_GetViewStatus(viewex, &status);
1607 ok(hr == S_OK, "got 0x%08x\n", hr);
1608 ok(status == VIEWSTATUS_OPAQUE, "got %#x\n", status);
1610 IViewObjectEx_Release(viewex);
1612 IScriptControl_Release(sc);
1615 static void test_pointerinactive(void)
1617 IPointerInactive *pi;
1618 IScriptControl *sc;
1619 DWORD policy;
1620 HRESULT hr;
1622 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1623 &IID_IScriptControl, (void**)&sc);
1624 ok(hr == S_OK, "got 0x%08x\n", hr);
1626 hr = IScriptControl_QueryInterface(sc, &IID_IPointerInactive, (void**)&pi);
1627 ok(hr == S_OK, "got 0x%08x\n", hr);
1629 if (0) /* crashes w2k3 */
1630 hr = IPointerInactive_GetActivationPolicy(pi, NULL);
1632 policy = 123;
1633 hr = IPointerInactive_GetActivationPolicy(pi, &policy);
1634 ok(hr == S_OK, "got 0x%08x\n", hr);
1635 ok(policy == 0, "got %#x\n", policy);
1637 IPointerInactive_Release(pi);
1638 IScriptControl_Release(sc);
1641 static void test_timeout(void)
1643 IScriptControl *sc;
1644 HRESULT hr;
1645 LONG val;
1646 BSTR str;
1648 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1649 &IID_IScriptControl, (void**)&sc);
1650 ok(hr == S_OK, "got 0x%08x\n", hr);
1652 hr = IScriptControl_get_Timeout(sc, NULL);
1653 ok(hr == E_POINTER, "got 0x%08x\n", hr);
1655 val = 0;
1656 hr = IScriptControl_get_Timeout(sc, &val);
1657 ok(hr == S_OK, "got 0x%08x\n", hr);
1658 ok(val == 10000, "got %d\n", val);
1660 hr = IScriptControl_put_Timeout(sc, -1);
1661 ok(hr == S_OK, "got 0x%08x\n", hr);
1663 val = 0;
1664 hr = IScriptControl_get_Timeout(sc, &val);
1665 ok(hr == S_OK, "got 0x%08x\n", hr);
1666 ok(val == -1, "got %d\n", val);
1668 hr = IScriptControl_put_Timeout(sc, -2);
1669 ok(hr == CTL_E_INVALIDPROPERTYVALUE, "got 0x%08x\n", hr);
1671 val = 0;
1672 hr = IScriptControl_get_Timeout(sc, &val);
1673 ok(hr == S_OK, "got 0x%08x\n", hr);
1674 ok(val == -1, "got %d\n", val);
1676 hr = IScriptControl_put_Timeout(sc, 0);
1677 ok(hr == S_OK, "got 0x%08x\n", hr);
1679 val = 1;
1680 hr = IScriptControl_get_Timeout(sc, &val);
1681 ok(hr == S_OK, "got 0x%08x\n", hr);
1682 ok(val == 0, "got %d\n", val);
1684 str = SysAllocString(L"VBScript");
1685 hr = IScriptControl_put_Language(sc, str);
1686 ok(hr == S_OK, "got 0x%08x\n", hr);
1687 SysFreeString(str);
1689 val = 1;
1690 hr = IScriptControl_get_Timeout(sc, &val);
1691 ok(hr == S_OK, "got 0x%08x\n", hr);
1692 ok(val == 0, "got %d\n", val);
1694 hr = IScriptControl_put_Timeout(sc, 10000);
1695 ok(hr == S_OK, "got 0x%08x\n", hr);
1697 IScriptControl_Release(sc);
1700 static void test_Reset(void)
1702 IScriptControl *sc;
1703 HRESULT hr;
1704 BSTR str;
1706 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1707 &IID_IScriptControl, (void**)&sc);
1708 ok(hr == S_OK, "got 0x%08x\n", hr);
1710 hr = IScriptControl_Reset(sc);
1711 ok(hr == E_FAIL, "got 0x%08x\n", hr);
1713 str = SysAllocString(L"VBScript");
1714 hr = IScriptControl_put_Language(sc, str);
1715 ok(hr == S_OK, "got 0x%08x\n", hr);
1716 SysFreeString(str);
1718 hr = IScriptControl_Reset(sc);
1719 ok(hr == S_OK, "got 0x%08x\n", hr);
1721 hr = IScriptControl_get_Language(sc, &str);
1722 ok(hr == S_OK, "got 0x%08x\n", hr);
1723 ok(!lstrcmpW(str, L"VBScript"), "got %s\n", wine_dbgstr_w(str));
1724 SysFreeString(str);
1726 IScriptControl_Release(sc);
1728 /* custom script engine */
1729 if (have_custom_engine) {
1730 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1731 &IID_IScriptControl, (void**)&sc);
1732 ok(hr == S_OK, "got 0x%08x\n", hr);
1734 SET_EXPECT(CreateInstance);
1735 SET_EXPECT(SetInterfaceSafetyOptions);
1736 SET_EXPECT(SetScriptSite);
1737 SET_EXPECT(QI_IActiveScriptParse);
1738 SET_EXPECT(InitNew);
1740 str = SysAllocString(L"testscript");
1741 hr = IScriptControl_put_Language(sc, str);
1742 ok(hr == S_OK, "got 0x%08x\n", hr);
1743 SysFreeString(str);
1745 SET_EXPECT(SetScriptState_INITIALIZED);
1746 hr = IScriptControl_Reset(sc);
1747 ok(hr == S_OK, "got 0x%08x\n", hr);
1748 CHECK_CALLED(SetScriptState_INITIALIZED);
1750 SET_EXPECT(SetScriptState_INITIALIZED);
1751 hr = IScriptControl_Reset(sc);
1752 ok(hr == S_OK, "got 0x%08x\n", hr);
1753 CHECK_CALLED(SetScriptState_INITIALIZED);
1755 CHECK_CALLED(SetScriptSite);
1756 IActiveScriptSite_Release(site);
1758 SET_EXPECT(Close);
1760 IScriptControl_Release(sc);
1762 CHECK_CALLED(Close);
1766 static HRESULT WINAPI disp_QI(IDispatch *iface, REFIID riid, void **obj)
1768 if (IsEqualIID(riid, &IID_IDispatch) || IsEqualIID(riid, &IID_IUnknown)) {
1769 *obj = iface;
1770 IDispatch_AddRef(iface);
1771 return S_OK;
1774 *obj = NULL;
1775 return E_NOINTERFACE;
1778 static ULONG WINAPI disp_AddRef(IDispatch *iface)
1780 return 2;
1783 static ULONG WINAPI disp_Release(IDispatch *iface)
1785 return 1;
1788 static HRESULT WINAPI disp_GetTypeInfoCount(IDispatch *iface, UINT *count)
1790 ok(0, "unexpected call\n");
1791 return E_NOTIMPL;
1794 static HRESULT WINAPI disp_GetTypeInfo(IDispatch *iface, UINT index, LCID lcid, ITypeInfo **ti)
1796 ok(0, "unexpected call\n");
1797 return E_NOTIMPL;
1800 static HRESULT WINAPI disp_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *names,
1801 UINT cnames, LCID lcid, DISPID *dispid)
1803 ok(0, "unexpected call\n");
1804 return E_NOTIMPL;
1807 static HRESULT WINAPI disp_Invoke(IDispatch *iface, DISPID dispid, REFIID riid, LCID lcid,
1808 WORD flags, DISPPARAMS *dispparams, VARIANT *result, EXCEPINFO *ei, UINT *arg_err)
1810 ok(0, "unexpected call\n");
1811 return E_NOTIMPL;
1814 static const IDispatchVtbl dispvtbl = {
1815 disp_QI,
1816 disp_AddRef,
1817 disp_Release,
1818 disp_GetTypeInfoCount,
1819 disp_GetTypeInfo,
1820 disp_GetIDsOfNames,
1821 disp_Invoke
1824 static IDispatch testdisp = { &dispvtbl };
1826 static void test_AddObject(void)
1828 IScriptControl *sc;
1829 BSTR str, objname;
1830 HRESULT hr;
1832 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1833 &IID_IScriptControl, (void**)&sc);
1834 ok(hr == S_OK, "got 0x%08x\n", hr);
1836 objname = SysAllocString(L"o");
1837 hr = IScriptControl_AddObject(sc, objname, NULL, VARIANT_FALSE);
1838 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1840 hr = IScriptControl_AddObject(sc, objname, &testdisp, VARIANT_FALSE);
1841 ok(hr == E_FAIL, "got 0x%08x\n", hr);
1843 str = SysAllocString(L"VBScript");
1844 hr = IScriptControl_put_Language(sc, str);
1845 ok(hr == S_OK, "got 0x%08x\n", hr);
1846 SysFreeString(str);
1848 hr = IScriptControl_AddObject(sc, objname, &testdisp, VARIANT_TRUE);
1849 ok(hr == S_OK, "got 0x%08x\n", hr);
1851 hr = IScriptControl_Reset(sc);
1852 ok(hr == S_OK, "got 0x%08x\n", hr);
1854 hr = IScriptControl_AddObject(sc, objname, &testdisp, VARIANT_TRUE);
1855 ok(hr == S_OK, "got 0x%08x\n", hr);
1857 IScriptControl_Release(sc);
1859 /* custom script engine */
1860 if (have_custom_engine) {
1861 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1862 &IID_IScriptControl, (void**)&sc);
1863 ok(hr == S_OK, "got 0x%08x\n", hr);
1865 SET_EXPECT(CreateInstance);
1866 SET_EXPECT(SetInterfaceSafetyOptions);
1867 SET_EXPECT(SetScriptSite);
1868 SET_EXPECT(QI_IActiveScriptParse);
1869 SET_EXPECT(InitNew);
1871 str = SysAllocString(L"testscript");
1872 hr = IScriptControl_put_Language(sc, str);
1873 ok(hr == S_OK, "got 0x%08x\n", hr);
1874 SysFreeString(str);
1876 hr = IScriptControl_AddObject(sc, objname, NULL, VARIANT_FALSE);
1877 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1879 SET_EXPECT(AddNamedItem);
1880 AddNamedItem_expected_name = objname;
1881 AddNamedItem_expected_flags = SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS;
1882 hr = IScriptControl_AddObject(sc, objname, &testdisp, VARIANT_TRUE);
1883 ok(hr == S_OK, "got 0x%08x\n", hr);
1884 CHECK_CALLED(AddNamedItem);
1886 hr = IScriptControl_AddObject(sc, objname, &testdisp, VARIANT_TRUE);
1887 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1889 CHECK_CALLED(SetScriptSite);
1890 IActiveScriptSite_Release(site);
1892 SET_EXPECT(Close);
1894 IScriptControl_Release(sc);
1896 CHECK_CALLED(Close);
1899 SysFreeString(objname);
1902 static void test_AllowUI(void)
1904 IScriptControl *sc;
1905 VARIANT_BOOL allow;
1906 HRESULT hr;
1908 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1909 &IID_IScriptControl, (void**)&sc);
1910 ok(hr == S_OK, "got 0x%08x\n", hr);
1912 hr = IScriptControl_get_AllowUI(sc, NULL);
1913 ok(hr == E_POINTER, "got 0x%08x\n", hr);
1915 hr = IScriptControl_get_AllowUI(sc, &allow);
1916 ok(hr == S_OK, "got 0x%08x\n", hr);
1917 ok(allow == VARIANT_TRUE, "got %d\n", allow);
1919 hr = IScriptControl_put_AllowUI(sc, VARIANT_FALSE);
1920 ok(hr == S_OK, "got 0x%08x\n", hr);
1922 hr = IScriptControl_get_AllowUI(sc, &allow);
1923 ok(hr == S_OK, "got 0x%08x\n", hr);
1924 ok(allow == VARIANT_FALSE, "got %d\n", allow);
1926 IScriptControl_Release(sc);
1929 static void test_SitehWnd(void)
1931 IScriptControl *sc;
1932 LONG site_hwnd;
1933 HRESULT hr;
1934 HWND hwnd;
1935 BSTR str;
1937 hwnd = CreateWindowA("static", NULL, WS_OVERLAPPEDWINDOW, 50, 50, 100, 100, NULL, NULL, NULL, NULL);
1938 ok(hwnd != NULL, "failed to create window, error %08x\n", GetLastError());
1940 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1941 &IID_IScriptControl, (void**)&sc);
1942 ok(hr == S_OK, "got 0x%08x\n", hr);
1944 hr = IScriptControl_get_SitehWnd(sc, NULL);
1945 ok(hr == E_POINTER, "got 0x%08x\n", hr);
1947 site_hwnd = 0xdeadbeef;
1948 hr = IScriptControl_get_SitehWnd(sc, &site_hwnd);
1949 ok(hr == S_OK, "got 0x%08x\n", hr);
1950 ok(!site_hwnd, "got %p\n", (HWND)(LONG_PTR)site_hwnd);
1952 hr = IScriptControl_put_SitehWnd(sc, 1);
1953 ok(hr == CTL_E_INVALIDPROPERTYVALUE, "got 0x%08x\n", hr);
1955 site_hwnd = 0xdeadbeef;
1956 hr = IScriptControl_get_SitehWnd(sc, &site_hwnd);
1957 ok(hr == S_OK, "got 0x%08x\n", hr);
1958 ok(!site_hwnd, "got %p\n", (HWND)(LONG_PTR)site_hwnd);
1960 hr = IScriptControl_put_SitehWnd(sc, 0);
1961 ok(hr == S_OK, "got 0x%08x\n", hr);
1963 hr = IScriptControl_put_SitehWnd(sc, (LONG)(LONG_PTR)hwnd);
1964 ok(hr == S_OK, "got 0x%08x\n", hr);
1966 str = SysAllocString(L"vbscript");
1967 hr = IScriptControl_put_Language(sc, str);
1968 ok(hr == S_OK, "got 0x%08x\n", hr);
1969 SysFreeString(str);
1971 site_hwnd = 0;
1972 hr = IScriptControl_get_SitehWnd(sc, &site_hwnd);
1973 ok(hr == S_OK, "got 0x%08x\n", hr);
1974 ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd);
1976 IScriptControl_Release(sc);
1978 /* custom script engine */
1979 if (have_custom_engine)
1981 IActiveScriptSiteWindow *site_window;
1982 HWND window;
1984 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
1985 &IID_IScriptControl, (void **)&sc);
1986 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
1988 hr = IScriptControl_put_SitehWnd(sc, (LONG)(LONG_PTR)hwnd);
1989 ok(hr == S_OK, "got 0x%08x\n", hr);
1991 SET_EXPECT(CreateInstance);
1992 SET_EXPECT(SetInterfaceSafetyOptions);
1993 SET_EXPECT(SetScriptSite);
1994 SET_EXPECT(QI_IActiveScriptParse);
1995 SET_EXPECT(InitNew);
1997 str = SysAllocString(L"testscript");
1998 hr = IScriptControl_put_Language(sc, str);
1999 ok(hr == S_OK, "got 0x%08x\n", hr);
2000 SysFreeString(str);
2002 CHECK_CALLED(CreateInstance);
2003 CHECK_CALLED(SetInterfaceSafetyOptions);
2004 CHECK_CALLED(SetScriptSite);
2005 CHECK_CALLED(QI_IActiveScriptParse);
2006 CHECK_CALLED(InitNew);
2008 hr = IActiveScriptSite_QueryInterface(site, &IID_IActiveScriptSiteWindow, (void**)&site_window);
2009 ok(hr == S_OK, "got 0x%08x\n", hr);
2011 site_hwnd = 0;
2012 hr = IScriptControl_get_SitehWnd(sc, &site_hwnd);
2013 ok(hr == S_OK, "got 0x%08x\n", hr);
2014 ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd);
2016 window = NULL;
2017 hr = IActiveScriptSiteWindow_GetWindow(site_window, NULL);
2018 ok(hr == E_POINTER, "got 0x%08x\n", hr);
2019 hr = IActiveScriptSiteWindow_GetWindow(site_window, &window);
2020 ok(hr == S_OK, "got 0x%08x\n", hr);
2021 ok(window == hwnd, "got %p, expected %p\n", window, hwnd);
2023 hr = IActiveScriptSiteWindow_EnableModeless(site_window, FALSE);
2024 ok(hr == S_OK, "got 0x%08x\n", hr);
2025 hr = IActiveScriptSiteWindow_EnableModeless(site_window, TRUE);
2026 ok(hr == S_OK, "got 0x%08x\n", hr);
2028 site_hwnd = 0xdeadbeef;
2029 hr = IScriptControl_put_SitehWnd(sc, 0);
2030 ok(hr == S_OK, "got 0x%08x\n", hr);
2031 hr = IScriptControl_get_SitehWnd(sc, &site_hwnd);
2032 ok(hr == S_OK, "got 0x%08x\n", hr);
2033 ok(!site_hwnd, "got %p\n", (HWND)(LONG_PTR)site_hwnd);
2035 window = (HWND)0xdeadbeef;
2036 hr = IActiveScriptSiteWindow_GetWindow(site_window, &window);
2037 ok(hr == S_OK, "got 0x%08x\n", hr);
2038 ok(!window, "got %p\n", window);
2040 site_hwnd = 0;
2041 hr = IScriptControl_put_SitehWnd(sc, (LONG)(LONG_PTR)hwnd);
2042 ok(hr == S_OK, "got 0x%08x\n", hr);
2043 hr = IScriptControl_get_SitehWnd(sc, &site_hwnd);
2044 ok(hr == S_OK, "got 0x%08x\n", hr);
2045 ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd);
2047 window = NULL;
2048 hr = IActiveScriptSiteWindow_GetWindow(site_window, &window);
2049 ok(hr == S_OK, "got 0x%08x\n", hr);
2050 ok(window == hwnd, "got %p, expected %p\n", window, hwnd);
2052 hr = IScriptControl_put_AllowUI(sc, VARIANT_FALSE);
2053 ok(hr == S_OK, "got 0x%08x\n", hr);
2055 hr = IScriptControl_get_SitehWnd(sc, &site_hwnd);
2056 ok(hr == S_OK, "got 0x%08x\n", hr);
2057 ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd);
2059 window = NULL;
2060 hr = IActiveScriptSiteWindow_GetWindow(site_window, &window);
2061 ok(hr == E_FAIL, "got 0x%08x\n", hr);
2062 ok(!window, "got %p\n", window);
2064 hr = IScriptControl_put_AllowUI(sc, VARIANT_TRUE);
2065 ok(hr == S_OK, "got 0x%08x\n", hr);
2067 window = NULL;
2068 hr = IActiveScriptSiteWindow_GetWindow(site_window, &window);
2069 ok(hr == S_OK, "got 0x%08x\n", hr);
2070 ok(window == hwnd, "got %p, expected %p\n", window, hwnd);
2072 IActiveScriptSite_Release(site);
2074 SET_EXPECT(Close);
2075 IScriptControl_Release(sc);
2076 CHECK_CALLED(Close);
2078 window = NULL;
2079 hr = IActiveScriptSiteWindow_GetWindow(site_window, &window);
2080 ok(hr == S_OK, "got 0x%08x\n", hr);
2081 ok(window == hwnd, "got %p, expected %p\n", window, hwnd);
2083 IActiveScriptSiteWindow_Release(site_window);
2086 DestroyWindow(hwnd);
2089 static void test_UseSafeSubset(void)
2091 IScriptControl *sc;
2092 VARIANT_BOOL use_safe_subset;
2093 HRESULT hr;
2094 BSTR str;
2096 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2097 &IID_IScriptControl, (void**)&sc);
2098 ok(hr == S_OK, "got 0x%08x\n", hr);
2100 hr = IScriptControl_get_UseSafeSubset(sc, NULL);
2101 ok(hr == E_POINTER, "got 0x%08x\n", hr);
2103 hr = IScriptControl_get_UseSafeSubset(sc, &use_safe_subset);
2104 ok(hr == S_OK, "got 0x%08x\n", hr);
2105 ok(use_safe_subset == VARIANT_FALSE, "got %d\n", use_safe_subset);
2107 hr = IScriptControl_put_UseSafeSubset(sc, VARIANT_TRUE);
2108 ok(hr == S_OK, "got 0x%08x\n", hr);
2110 hr = IScriptControl_get_UseSafeSubset(sc, &use_safe_subset);
2111 ok(hr == S_OK, "got 0x%08x\n", hr);
2112 ok(use_safe_subset == VARIANT_TRUE, "got %d\n", use_safe_subset);
2114 str = SysAllocString(L"VBScript");
2115 hr = IScriptControl_put_Language(sc, str);
2116 ok(hr == S_OK, "got 0x%08x\n", hr);
2117 SysFreeString(str);
2119 hr = IScriptControl_get_UseSafeSubset(sc, &use_safe_subset);
2120 ok(hr == S_OK, "got 0x%08x\n", hr);
2121 ok(use_safe_subset == VARIANT_TRUE, "got %d\n", use_safe_subset);
2123 IScriptControl_Release(sc);
2125 /* custom script engine */
2126 if (have_custom_engine)
2128 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2129 &IID_IScriptControl, (void **)&sc);
2130 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2132 SET_EXPECT(CreateInstance);
2133 SET_EXPECT(SetInterfaceSafetyOptions);
2134 SET_EXPECT(SetScriptSite);
2135 SET_EXPECT(QI_IActiveScriptParse);
2136 SET_EXPECT(InitNew);
2138 str = SysAllocString(L"testscript");
2139 hr = IScriptControl_put_Language(sc, str);
2140 ok(hr == S_OK, "got 0x%08x\n", hr);
2141 SysFreeString(str);
2143 CHECK_CALLED(CreateInstance);
2144 CHECK_CALLED(SetInterfaceSafetyOptions);
2145 CHECK_CALLED(SetScriptSite);
2146 CHECK_CALLED(QI_IActiveScriptParse);
2147 CHECK_CALLED(InitNew);
2149 hr = IScriptControl_get_UseSafeSubset(sc, &use_safe_subset);
2150 ok(hr == S_OK, "got 0x%08x\n", hr);
2151 ok(use_safe_subset == VARIANT_FALSE, "got %d\n", use_safe_subset);
2153 SET_EXPECT(SetInterfaceSafetyOptions_UseSafeSubset);
2154 hr = IScriptControl_put_UseSafeSubset(sc, VARIANT_TRUE);
2155 ok(hr == S_OK, "got 0x%08x\n", hr);
2156 CHECK_CALLED(SetInterfaceSafetyOptions_UseSafeSubset);
2158 hr = IScriptControl_get_UseSafeSubset(sc, &use_safe_subset);
2159 ok(hr == S_OK, "got 0x%08x\n", hr);
2160 ok(use_safe_subset == VARIANT_TRUE, "got %d\n", use_safe_subset);
2162 hr = IScriptControl_put_UseSafeSubset(sc, VARIANT_TRUE);
2163 ok(hr == S_OK, "got 0x%08x\n", hr);
2165 SET_EXPECT(SetInterfaceSafetyOptions);
2166 hr = IScriptControl_put_UseSafeSubset(sc, VARIANT_FALSE);
2167 ok(hr == S_OK, "got 0x%08x\n", hr);
2168 CHECK_CALLED(SetInterfaceSafetyOptions);
2170 hr = IScriptControl_put_UseSafeSubset(sc, VARIANT_FALSE);
2171 ok(hr == S_OK, "got 0x%08x\n", hr);
2173 IActiveScriptSite_Release(site);
2175 SET_EXPECT(Close);
2176 IScriptControl_Release(sc);
2177 CHECK_CALLED(Close);
2179 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2180 &IID_IScriptControl, (void **)&sc);
2181 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2183 hr = IScriptControl_put_UseSafeSubset(sc, VARIANT_TRUE);
2184 ok(hr == S_OK, "got 0x%08x\n", hr);
2186 SET_EXPECT(CreateInstance);
2187 SET_EXPECT(SetInterfaceSafetyOptions_UseSafeSubset);
2188 SET_EXPECT(SetScriptSite);
2189 SET_EXPECT(QI_IActiveScriptParse);
2190 SET_EXPECT(InitNew);
2192 str = SysAllocString(L"testscript");
2193 hr = IScriptControl_put_Language(sc, str);
2194 ok(hr == S_OK, "got 0x%08x\n", hr);
2195 SysFreeString(str);
2197 CHECK_CALLED(CreateInstance);
2198 CHECK_CALLED(SetInterfaceSafetyOptions_UseSafeSubset);
2199 CHECK_CALLED(SetScriptSite);
2200 CHECK_CALLED(QI_IActiveScriptParse);
2201 CHECK_CALLED(InitNew);
2203 IActiveScriptSite_Release(site);
2205 SET_EXPECT(Close);
2206 IScriptControl_Release(sc);
2207 CHECK_CALLED(Close);
2211 static void test_State(void)
2213 IScriptControl *sc;
2214 ScriptControlStates state;
2215 HRESULT hr;
2216 BSTR str;
2218 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2219 &IID_IScriptControl, (void**)&sc);
2220 ok(hr == S_OK, "got 0x%08x\n", hr);
2222 hr = IScriptControl_get_State(sc, NULL);
2223 ok(hr == E_POINTER, "got 0x%08x\n", hr);
2225 hr = IScriptControl_get_State(sc, &state);
2226 ok(hr == E_FAIL, "got 0x%08x\n", hr);
2228 hr = IScriptControl_put_State(sc, Connected);
2229 ok(hr == E_FAIL, "got 0x%08x\n", hr);
2231 str = SysAllocString(L"VBScript");
2232 hr = IScriptControl_put_Language(sc, str);
2233 ok(hr == S_OK, "got 0x%08x\n", hr);
2234 SysFreeString(str);
2236 hr = IScriptControl_get_State(sc, &state);
2237 ok(hr == S_OK, "got 0x%08x\n", hr);
2238 ok(state == Initialized, "got %d\n", state);
2240 hr = IScriptControl_put_State(sc, Connected);
2241 ok(hr == S_OK, "got 0x%08x\n", hr);
2243 hr = IScriptControl_get_State(sc, &state);
2244 ok(hr == S_OK, "got 0x%08x\n", hr);
2245 ok(state == Connected, "got %d\n", state);
2247 hr = IScriptControl_put_State(sc, 2);
2248 ok(hr == CTL_E_INVALIDPROPERTYVALUE, "got 0x%08x\n", hr);
2250 hr = IScriptControl_get_State(sc, &state);
2251 ok(hr == S_OK, "got 0x%08x\n", hr);
2252 ok(state == Connected, "got %d\n", state);
2254 hr = IScriptControl_put_State(sc, -1);
2255 ok(hr == CTL_E_INVALIDPROPERTYVALUE, "got 0x%08x\n", hr);
2257 hr = IScriptControl_get_State(sc, &state);
2258 ok(hr == S_OK, "got 0x%08x\n", hr);
2259 ok(state == Connected, "got %d\n", state);
2261 IScriptControl_Release(sc);
2263 /* custom script engine */
2264 if (have_custom_engine)
2266 BSTR language, code_str;
2268 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2269 &IID_IScriptControl, (void **)&sc);
2270 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2272 SET_EXPECT(CreateInstance);
2273 SET_EXPECT(SetInterfaceSafetyOptions);
2274 SET_EXPECT(SetScriptSite);
2275 SET_EXPECT(QI_IActiveScriptParse);
2276 SET_EXPECT(InitNew);
2278 language = SysAllocString(L"testscript");
2279 hr = IScriptControl_put_Language(sc, language);
2280 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2281 SysFreeString(language);
2283 CHECK_CALLED(CreateInstance);
2284 CHECK_CALLED(SetInterfaceSafetyOptions);
2285 CHECK_CALLED(SetScriptSite);
2286 CHECK_CALLED(QI_IActiveScriptParse);
2287 CHECK_CALLED(InitNew);
2289 SET_EXPECT(SetScriptState_STARTED);
2290 hr = IScriptControl_put_State(sc, Initialized);
2291 ok(hr == S_OK, "got 0x%08x\n", hr);
2292 CHECK_CALLED(SetScriptState_STARTED);
2294 SET_EXPECT(SetScriptState_STARTED);
2295 hr = IScriptControl_put_State(sc, Initialized);
2296 ok(hr == S_OK, "got 0x%08x\n", hr);
2297 CHECK_CALLED(SetScriptState_STARTED);
2299 SET_EXPECT(SetScriptState_CONNECTED);
2300 hr = IScriptControl_put_State(sc, Connected);
2301 ok(hr == S_OK, "got 0x%08x\n", hr);
2302 CHECK_CALLED(SetScriptState_CONNECTED);
2304 SET_EXPECT(SetScriptState_STARTED);
2305 hr = IScriptControl_put_State(sc, Initialized);
2306 ok(hr == S_OK, "got 0x%08x\n", hr);
2307 CHECK_CALLED(SetScriptState_STARTED);
2309 SET_EXPECT(SetScriptState_STARTED);
2310 SET_EXPECT(ParseScriptText);
2311 parse_item_name = NULL;
2312 parse_flags = SCRIPTTEXT_ISVISIBLE;
2313 code_str = SysAllocString(L"1 + 1");
2314 hr = IScriptControl_AddCode(sc, code_str);
2315 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
2316 SysFreeString(code_str);
2317 CHECK_CALLED(SetScriptState_STARTED);
2318 CHECK_CALLED(ParseScriptText);
2320 emulated_script_state = SCRIPTSTATE_INITIALIZED;
2321 SET_EXPECT(GetScriptState);
2322 hr = IScriptControl_get_State(sc, &state);
2323 ok(hr == S_OK, "got 0x%08x\n", hr);
2324 ok(state == Initialized, "got %d\n", state);
2325 CHECK_CALLED(GetScriptState);
2327 emulated_script_state = SCRIPTSTATE_STARTED;
2328 SET_EXPECT(GetScriptState);
2329 hr = IScriptControl_get_State(sc, &state);
2330 ok(hr == S_OK, "got 0x%08x\n", hr);
2331 ok(state == Initialized, "got %d\n", state);
2332 CHECK_CALLED(GetScriptState);
2334 emulated_script_state = SCRIPTSTATE_CONNECTED;
2335 SET_EXPECT(GetScriptState);
2336 hr = IScriptControl_get_State(sc, &state);
2337 ok(hr == S_OK, "got 0x%08x\n", hr);
2338 ok(state == Connected, "got %d\n", state);
2339 CHECK_CALLED(GetScriptState);
2341 emulated_script_state = SCRIPTSTATE_UNINITIALIZED;
2342 SET_EXPECT(GetScriptState);
2343 hr = IScriptControl_get_State(sc, &state);
2344 ok(hr == E_FAIL, "got 0x%08x\n", hr);
2345 CHECK_CALLED(GetScriptState);
2347 SET_EXPECT(ParseScriptText);
2348 code_str = SysAllocString(L"0x100");
2349 hr = IScriptControl_AddCode(sc, code_str);
2350 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
2351 SysFreeString(code_str);
2352 CHECK_CALLED(ParseScriptText);
2354 IActiveScriptSite_Release(site);
2356 SET_EXPECT(Close);
2357 IScriptControl_Release(sc);
2358 CHECK_CALLED(Close);
2360 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2361 &IID_IScriptControl, (void **)&sc);
2362 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2364 SET_EXPECT(CreateInstance);
2365 SET_EXPECT(SetInterfaceSafetyOptions);
2366 SET_EXPECT(SetScriptSite);
2367 SET_EXPECT(QI_IActiveScriptParse);
2368 SET_EXPECT(InitNew);
2370 language = SysAllocString(L"testscript");
2371 hr = IScriptControl_put_Language(sc, language);
2372 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2373 SysFreeString(language);
2375 CHECK_CALLED(CreateInstance);
2376 CHECK_CALLED(SetInterfaceSafetyOptions);
2377 CHECK_CALLED(SetScriptSite);
2378 CHECK_CALLED(QI_IActiveScriptParse);
2379 CHECK_CALLED(InitNew);
2381 SET_EXPECT(SetScriptState_STARTED);
2382 hr = IScriptControl_put_State(sc, Initialized);
2383 ok(hr == S_OK, "got 0x%08x\n", hr);
2384 CHECK_CALLED(SetScriptState_STARTED);
2386 SET_EXPECT(SetScriptState_STARTED);
2387 hr = IScriptControl_put_State(sc, Initialized);
2388 ok(hr == S_OK, "got 0x%08x\n", hr);
2389 CHECK_CALLED(SetScriptState_STARTED);
2391 SET_EXPECT(SetScriptState_CONNECTED);
2392 hr = IScriptControl_put_State(sc, Connected);
2393 ok(hr == S_OK, "got 0x%08x\n", hr);
2394 CHECK_CALLED(SetScriptState_CONNECTED);
2396 SET_EXPECT(SetScriptState_STARTED);
2397 SET_EXPECT(ParseScriptText);
2398 parse_item_name = NULL;
2399 parse_flags = SCRIPTTEXT_ISVISIBLE;
2400 code_str = SysAllocString(L"1 + 1");
2401 hr = IScriptControl_AddCode(sc, code_str);
2402 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
2403 SysFreeString(code_str);
2404 CHECK_CALLED(SetScriptState_STARTED);
2405 CHECK_CALLED(ParseScriptText);
2407 SET_EXPECT(SetScriptState_CONNECTED);
2408 hr = IScriptControl_put_State(sc, Connected);
2409 ok(hr == S_OK, "got 0x%08x\n", hr);
2410 CHECK_CALLED(SetScriptState_CONNECTED);
2412 SET_EXPECT(ParseScriptText);
2413 code_str = SysAllocString(L"0x100");
2414 hr = IScriptControl_AddCode(sc, code_str);
2415 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
2416 SysFreeString(code_str);
2417 CHECK_CALLED(ParseScriptText);
2419 IActiveScriptSite_Release(site);
2421 SET_EXPECT(Close);
2422 IScriptControl_Release(sc);
2423 CHECK_CALLED(Close);
2427 #define CHECK_ERROR(sc,exp_num) _check_error(sc, exp_num, FALSE, __LINE__)
2428 #define CHECK_ERROR_TODO(sc,exp_num) _check_error(sc, exp_num, TRUE, __LINE__)
2429 static void _check_error(IScriptControl *sc, LONG exp_num, BOOL todo, int line)
2431 IScriptError *script_err;
2432 LONG error_num;
2433 HRESULT hr;
2435 hr = IScriptControl_get_Error(sc, &script_err);
2436 ok_(__FILE__,line)(hr == S_OK, "IScriptControl_get_Error failed: 0x%08x.\n", hr);
2437 error_num = 0xdeadbeef;
2438 hr = IScriptError_get_Number(script_err, &error_num);
2439 ok_(__FILE__,line)(hr == S_OK, "IScriptError_get_Number failed: 0x%08x.\n", hr);
2440 todo_wine_if(todo == TRUE)
2441 ok_(__FILE__,line)(error_num == exp_num, "got wrong error number: %d, expected %d.\n",
2442 error_num, exp_num);
2443 IScriptError_Release(script_err);
2446 static void test_IScriptControl_Eval(void)
2448 IScriptControl *sc;
2449 HRESULT hr;
2450 BSTR script_str, language, expected_string;
2451 VARIANT var;
2452 ScriptControlStates state;
2454 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2455 &IID_IScriptControl, (void **)&sc);
2456 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2458 hr = IScriptControl_Eval(sc, NULL, NULL);
2459 ok(hr == E_POINTER, "IScriptControl_Eval returned: 0x%08x.\n", hr);
2461 script_str = SysAllocString(L"1 + 1");
2462 hr = IScriptControl_Eval(sc, script_str, NULL);
2463 ok(hr == E_POINTER, "IScriptControl_Eval returned: 0x%08x.\n", hr);
2464 SysFreeString(script_str);
2466 V_VT(&var) = VT_NULL;
2467 V_I4(&var) = 0xdeadbeef;
2468 hr = IScriptControl_Eval(sc, NULL, &var);
2469 ok(hr == E_FAIL, "IScriptControl_Eval returned: 0x%08x.\n", hr);
2470 ok((V_VT(&var) == VT_EMPTY) && (V_I4(&var) == 0xdeadbeef), "V_VT(var) = %d, V_I4(var) = %d.\n",
2471 V_VT(&var), V_I4(&var));
2472 CHECK_ERROR(sc, 0);
2474 script_str = SysAllocString(L"1 + 1");
2475 V_VT(&var) = VT_NULL;
2476 V_I4(&var) = 0xdeadbeef;
2477 hr = IScriptControl_Eval(sc, script_str, &var);
2478 ok(hr == E_FAIL, "IScriptControl_Eval returned: 0x%08x.\n", hr);
2479 ok((V_VT(&var) == VT_EMPTY) && (V_I4(&var) == 0xdeadbeef), "V_VT(var) = %d, V_I4(var) = %d.\n",
2480 V_VT(&var), V_I4(&var));
2481 SysFreeString(script_str);
2483 language = SysAllocString(L"jscript");
2484 hr = IScriptControl_put_Language(sc, language);
2485 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2486 hr = IScriptControl_get_State(sc, &state);
2487 ok(hr == S_OK, "IScriptControl_get_State failed: 0x%08x.\n", hr);
2488 ok(state == Initialized, "got wrong state: %d\n", state);
2489 SysFreeString(language);
2490 script_str = SysAllocString(L"var1 = 1 + 1");
2491 V_VT(&var) = VT_NULL;
2492 V_I4(&var) = 0xdeadbeef;
2493 hr = IScriptControl_Eval(sc, script_str, &var);
2494 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
2495 ok((V_VT(&var) == VT_I4) && (V_I4(&var) == 2), "V_VT(var) = %d, V_I4(var) = %d.\n",
2496 V_VT(&var), V_I4(&var));
2497 hr = IScriptControl_get_State(sc, &state);
2498 ok(hr == S_OK, "IScriptControl_get_State failed: 0x%08x.\n", hr);
2499 ok(state == Initialized, "got wrong state: %d\n", state);
2500 SysFreeString(script_str);
2502 script_str = SysAllocString(L"var2 = 10 + var1");
2503 V_VT(&var) = VT_NULL;
2504 V_I4(&var) = 0xdeadbeef;
2505 hr = IScriptControl_Eval(sc, script_str, &var);
2506 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
2507 ok((V_VT(&var) == VT_I4) && (V_I4(&var) == 12), "V_VT(var) = %d, V_I4(var) = %d.\n",
2508 V_VT(&var), V_I4(&var));
2509 SysFreeString(script_str);
2511 script_str = SysAllocString(L"invalid syntax");
2512 V_VT(&var) = VT_NULL;
2513 V_I4(&var) = 0xdeadbeef;
2514 hr = IScriptControl_Eval(sc, script_str, &var);
2515 todo_wine ok(hr == 0x800a03ec, "IScriptControl_Eval failed: 0x%08x.\n", hr);
2516 ok(V_VT(&var) == VT_EMPTY, "V_VT(var) = %d\n", V_VT(&var));
2517 ok(V_I4(&var) == 0xdeadbeef || broken(V_I4(&var) == 0) /* after Win8 */,
2518 "V_I4(var) = %d.\n", V_I4(&var));
2519 SysFreeString(script_str);
2520 CHECK_ERROR_TODO(sc, 1004);
2522 script_str = SysAllocString(L"var2 = var1 + var2");
2523 V_VT(&var) = VT_NULL;
2524 V_I4(&var) = 0xdeadbeef;
2525 hr = IScriptControl_Eval(sc, script_str, &var);
2526 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
2527 ok((V_VT(&var) == VT_I4) && (V_I4(&var) == 14), "V_VT(var) = %d, V_I4(var) = %d.\n",
2528 V_VT(&var), V_I4(&var));
2529 SysFreeString(script_str);
2531 script_str = SysAllocString(L"\"Hello\"");
2532 V_VT(&var) = VT_NULL;
2533 V_I4(&var) = 0xdeadbeef;
2534 hr = IScriptControl_Eval(sc, script_str, &var);
2535 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
2536 expected_string = SysAllocString(L"Hello");
2537 ok((V_VT(&var) == VT_BSTR) && (!lstrcmpW(V_BSTR(&var), expected_string)),
2538 "V_VT(var) = %d, V_BSTR(var) = %s.\n", V_VT(&var), wine_dbgstr_w(V_BSTR(&var)));
2539 SysFreeString(expected_string);
2540 SysFreeString(script_str);
2542 IScriptControl_Release(sc);
2544 if (have_custom_engine)
2546 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2547 &IID_IScriptControl, (void **)&sc);
2548 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2550 SET_EXPECT(CreateInstance);
2551 SET_EXPECT(SetInterfaceSafetyOptions);
2552 SET_EXPECT(SetScriptSite);
2553 SET_EXPECT(QI_IActiveScriptParse);
2554 SET_EXPECT(InitNew);
2556 language= SysAllocString(L"testscript");
2557 hr = IScriptControl_put_Language(sc, language);
2558 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2559 SysFreeString(language);
2561 CHECK_CALLED(CreateInstance);
2562 CHECK_CALLED(SetInterfaceSafetyOptions);
2563 CHECK_CALLED(SetScriptSite);
2564 CHECK_CALLED(QI_IActiveScriptParse);
2565 CHECK_CALLED(InitNew);
2567 SET_EXPECT(SetScriptState_STARTED);
2568 SET_EXPECT(ParseScriptText);
2569 parse_item_name = NULL;
2570 parse_flags = SCRIPTTEXT_ISEXPRESSION;
2571 script_str = SysAllocString(L"var1 = 1 + 1");
2572 V_VT(&var) = VT_NULL;
2573 hr = IScriptControl_Eval(sc, script_str, &var);
2574 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
2575 ok(V_VT(&var) == VT_EMPTY, "V_VT(var) = %d.\n", V_VT(&var));
2576 SysFreeString(script_str);
2577 CHECK_CALLED(SetScriptState_STARTED);
2578 CHECK_CALLED(ParseScriptText);
2580 SET_EXPECT(ParseScriptText);
2581 script_str = SysAllocString(L"var2 = 10 + var1");
2582 V_VT(&var) = VT_NULL;
2583 V_I4(&var) = 0xdeadbeef;
2584 hr = IScriptControl_Eval(sc, script_str, &var);
2585 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
2586 ok((V_VT(&var) == VT_EMPTY) && (V_I4(&var) == 0xdeadbeef), "V_VT(var) = %d, V_I4(var) = %d.\n",
2587 V_VT(&var), V_I4(&var));
2588 SysFreeString(script_str);
2589 CHECK_CALLED(ParseScriptText);
2591 SET_EXPECT(SetScriptState_INITIALIZED);
2592 hr = IScriptControl_Reset(sc);
2593 ok(hr == S_OK, "IScriptControl_Reset failed: 0x%08x.\n", hr);
2594 CHECK_CALLED(SetScriptState_INITIALIZED);
2596 SET_EXPECT(SetScriptState_STARTED);
2597 SET_EXPECT(ParseScriptText);
2598 script_str = SysAllocString(L"var2 = 10 + var1");
2599 V_VT(&var) = VT_NULL;
2600 V_I4(&var) = 0xdeadbeef;
2601 hr = IScriptControl_Eval(sc, script_str, &var);
2602 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
2603 ok((V_VT(&var) == VT_EMPTY) && (V_I4(&var) == 0xdeadbeef), "V_VT(var) = %d, V_I4(var) = %d.\n",
2604 V_VT(&var), V_I4(&var));
2605 SysFreeString(script_str);
2606 CHECK_CALLED(SetScriptState_STARTED);
2607 CHECK_CALLED(ParseScriptText);
2609 IActiveScriptSite_Release(site);
2611 SET_EXPECT(Close);
2613 IScriptControl_Release(sc);
2615 CHECK_CALLED(Close);
2619 static void test_IScriptControl_AddCode(void)
2621 BSTR code_str, language;
2622 IScriptControl *sc;
2623 VARIANT var;
2624 HRESULT hr;
2626 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2627 &IID_IScriptControl, (void **)&sc);
2628 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2630 code_str = SysAllocString(L"1 + 1");
2631 hr = IScriptControl_AddCode(sc, code_str);
2632 ok(hr == E_FAIL, "IScriptControl_AddCode returned: 0x%08x.\n", hr);
2633 SysFreeString(code_str);
2635 hr = IScriptControl_AddCode(sc, NULL);
2636 ok(hr == E_FAIL, "IScriptControl_AddCode returned: 0x%08x.\n", hr);
2638 language = SysAllocString(L"jscript");
2639 hr = IScriptControl_put_Language(sc, language);
2640 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2641 SysFreeString(language);
2643 code_str = SysAllocString(L"1 + 1");
2644 hr = IScriptControl_AddCode(sc, code_str);
2645 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
2646 SysFreeString(code_str);
2647 CHECK_ERROR(sc, 0);
2649 code_str = SysAllocString(L"invalid syntax");
2650 hr = IScriptControl_AddCode(sc, code_str);
2651 todo_wine ok(hr == 0x800a03ec, "IScriptControl_AddCode returned: 0x%08x.\n", hr);
2652 SysFreeString(code_str);
2653 CHECK_ERROR_TODO(sc, 1004);
2655 IScriptControl_Release(sc);
2657 /* custom script engine */
2658 if (have_custom_engine)
2660 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2661 &IID_IScriptControl, (void **)&sc);
2662 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2664 SET_EXPECT(CreateInstance);
2665 SET_EXPECT(SetInterfaceSafetyOptions);
2666 SET_EXPECT(SetScriptSite);
2667 SET_EXPECT(QI_IActiveScriptParse);
2668 SET_EXPECT(InitNew);
2670 language = SysAllocString(L"testscript");
2671 hr = IScriptControl_put_Language(sc, language);
2672 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2673 SysFreeString(language);
2675 CHECK_CALLED(CreateInstance);
2676 CHECK_CALLED(SetInterfaceSafetyOptions);
2677 CHECK_CALLED(SetScriptSite);
2678 CHECK_CALLED(QI_IActiveScriptParse);
2679 CHECK_CALLED(InitNew);
2681 SET_EXPECT(SetScriptState_STARTED);
2682 SET_EXPECT(ParseScriptText);
2683 parse_item_name = NULL;
2684 parse_flags = SCRIPTTEXT_ISVISIBLE;
2685 code_str = SysAllocString(L"1 + 1");
2686 hr = IScriptControl_AddCode(sc, code_str);
2687 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
2688 SysFreeString(code_str);
2689 CHECK_CALLED(SetScriptState_STARTED);
2690 CHECK_CALLED(ParseScriptText);
2692 SET_EXPECT(ParseScriptText);
2693 code_str = SysAllocString(L"0x100");
2694 hr = IScriptControl_AddCode(sc, code_str);
2695 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
2696 SysFreeString(code_str);
2697 CHECK_CALLED(ParseScriptText);
2699 /* Call Eval() after AddCode() for checking if it will call SetScriptState() again. */
2700 SET_EXPECT(ParseScriptText);
2701 parse_item_name = NULL;
2702 parse_flags = SCRIPTTEXT_ISEXPRESSION;
2703 code_str = SysAllocString(L"var2 = 10 + var1");
2704 V_VT(&var) = VT_NULL;
2705 hr = IScriptControl_Eval(sc, code_str, &var);
2706 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
2707 ok(V_VT(&var) == VT_EMPTY, "V_VT(var) = %d.\n", V_VT(&var));
2708 SysFreeString(code_str);
2709 CHECK_CALLED(ParseScriptText);
2711 IActiveScriptSite_Release(site);
2713 SET_EXPECT(Close);
2715 IScriptControl_Release(sc);
2717 CHECK_CALLED(Close);
2721 static void test_IScriptControl_ExecuteStatement(void)
2723 IScriptControl *sc;
2724 HRESULT hr;
2725 BSTR str;
2727 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2728 &IID_IScriptControl, (void**)&sc);
2729 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2731 str = SysAllocString(L"1 + 1");
2732 hr = IScriptControl_ExecuteStatement(sc, str);
2733 ok(hr == E_FAIL, "IScriptControl_ExecuteStatement returned: 0x%08x.\n", hr);
2734 SysFreeString(str);
2736 hr = IScriptControl_ExecuteStatement(sc, NULL);
2737 ok(hr == E_FAIL, "IScriptControl_ExecuteStatement returned: 0x%08x.\n", hr);
2739 str = SysAllocString(L"jscript");
2740 hr = IScriptControl_put_Language(sc, str);
2741 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2742 SysFreeString(str);
2744 str = SysAllocString(L"1 + 1");
2745 hr = IScriptControl_ExecuteStatement(sc, str);
2746 ok(hr == S_OK, "IScriptControl_ExecuteStatement failed: 0x%08x.\n", hr);
2747 SysFreeString(str);
2748 CHECK_ERROR(sc, 0);
2750 str = SysAllocString(L"invalid syntax");
2751 hr = IScriptControl_ExecuteStatement(sc, str);
2752 todo_wine ok(hr == 0x800a03ec, "IScriptControl_ExecuteStatement returned: 0x%08x.\n", hr);
2753 SysFreeString(str);
2754 CHECK_ERROR_TODO(sc, 1004);
2756 IScriptControl_Release(sc);
2758 /* custom script engine */
2759 if (have_custom_engine)
2761 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2762 &IID_IScriptControl, (void**)&sc);
2763 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2765 SET_EXPECT(CreateInstance);
2766 SET_EXPECT(SetInterfaceSafetyOptions);
2767 SET_EXPECT(SetScriptSite);
2768 SET_EXPECT(QI_IActiveScriptParse);
2769 SET_EXPECT(InitNew);
2771 str = SysAllocString(L"testscript");
2772 hr = IScriptControl_put_Language(sc, str);
2773 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2774 SysFreeString(str);
2776 CHECK_CALLED(CreateInstance);
2777 CHECK_CALLED(SetInterfaceSafetyOptions);
2778 CHECK_CALLED(SetScriptSite);
2779 CHECK_CALLED(QI_IActiveScriptParse);
2780 CHECK_CALLED(InitNew);
2782 SET_EXPECT(SetScriptState_STARTED);
2783 SET_EXPECT(ParseScriptText);
2784 parse_item_name = NULL;
2785 parse_flags = 0;
2786 str = SysAllocString(L"1 + 1");
2787 hr = IScriptControl_ExecuteStatement(sc, str);
2788 ok(hr == S_OK, "IScriptControl_ExecuteStatement failed: 0x%08x.\n", hr);
2789 SysFreeString(str);
2790 CHECK_CALLED(SetScriptState_STARTED);
2791 CHECK_CALLED(ParseScriptText);
2793 SET_EXPECT(ParseScriptText);
2794 str = SysAllocString(L"0x100");
2795 hr = IScriptControl_ExecuteStatement(sc, str);
2796 ok(hr == S_OK, "IScriptControl_ExecuteStatement failed: 0x%08x.\n", hr);
2797 SysFreeString(str);
2798 CHECK_CALLED(ParseScriptText);
2800 IActiveScriptSite_Release(site);
2802 SET_EXPECT(Close);
2803 IScriptControl_Release(sc);
2804 CHECK_CALLED(Close);
2808 static void test_IScriptControl_Run(void)
2810 SAFEARRAYBOUND bnd[] = { { 2, 0 }, { 2, 0 } };
2811 LONG idx0_0[] = { 0, 0 };
2812 LONG idx0_1[] = { 1, 0 };
2813 LONG idx1_0[] = { 0, 1 };
2814 LONG idx1_1[] = { 1, 1 };
2815 IScriptControl *sc;
2816 SAFEARRAY *params;
2817 VARIANT var;
2818 HRESULT hr;
2819 BSTR str;
2821 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2822 &IID_IScriptControl, (void**)&sc);
2823 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2825 params = NULL;
2826 str = SysAllocString(L"identifier");
2827 hr = IScriptControl_Run(sc, str, &params, &var);
2828 ok(hr == E_POINTER, "IScriptControl_Run returned: 0x%08x.\n", hr);
2830 params = SafeArrayCreate(VT_VARIANT, 1, bnd);
2831 ok(params != NULL, "Failed to create SafeArray.\n");
2833 V_VT(&var) = VT_I4;
2834 V_I4(&var) = 10;
2835 SafeArrayPutElement(params, idx0_0, &var);
2836 V_I4(&var) = 3;
2837 SafeArrayPutElement(params, idx0_1, &var);
2839 hr = IScriptControl_Run(sc, str, &params, &var);
2840 ok(hr == E_FAIL, "IScriptControl_Run returned: 0x%08x.\n", hr);
2842 hr = IScriptControl_Run(sc, str, NULL, &var);
2843 ok(hr == E_POINTER, "IScriptControl_Run returned: 0x%08x.\n", hr);
2845 hr = IScriptControl_Run(sc, str, &params, NULL);
2846 ok(hr == E_POINTER, "IScriptControl_Run returned: 0x%08x.\n", hr);
2847 SysFreeString(str);
2849 hr = IScriptControl_Run(sc, NULL, &params, &var);
2850 ok(hr == E_FAIL, "IScriptControl_Run returned: 0x%08x.\n", hr);
2852 str = SysAllocString(L"jscript");
2853 hr = IScriptControl_put_Language(sc, str);
2854 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2855 SysFreeString(str);
2857 str = SysAllocString(L"foobar");
2858 hr = IScriptControl_Run(sc, str, &params, &var);
2859 ok(hr == DISP_E_UNKNOWNNAME, "IScriptControl_Run failed: 0x%08x.\n", hr);
2860 CHECK_ERROR(sc, 0);
2861 SysFreeString(str);
2863 str = SysAllocString(L"function subtract(a, b) { return a - b; }\n");
2864 hr = IScriptControl_AddCode(sc, str);
2865 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
2866 CHECK_ERROR(sc, 0);
2867 SysFreeString(str);
2869 str = SysAllocString(L"Subtract");
2870 hr = IScriptControl_Run(sc, str, &params, &var);
2871 ok(hr == DISP_E_UNKNOWNNAME, "IScriptControl_Run failed: 0x%08x.\n", hr);
2872 SysFreeString(str);
2874 str = SysAllocString(L"subtract");
2875 hr = IScriptControl_Run(sc, str, &params, NULL);
2876 ok(hr == E_POINTER, "IScriptControl_Run failed: 0x%08x.\n", hr);
2877 CHECK_ERROR(sc, 0);
2879 hr = IScriptControl_Run(sc, str, &params, &var);
2880 ok(hr == S_OK, "IScriptControl_Run failed: 0x%08x.\n", hr);
2881 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));
2882 CHECK_ERROR(sc, 0);
2883 SafeArrayDestroy(params);
2885 /* The array's other dimensions are ignored */
2886 params = SafeArrayCreate(VT_VARIANT, 2, bnd);
2887 ok(params != NULL, "Failed to create SafeArray.\n");
2889 V_VT(&var) = VT_I4;
2890 V_I4(&var) = 10;
2891 SafeArrayPutElement(params, idx0_0, &var);
2892 V_I4(&var) = 3;
2893 SafeArrayPutElement(params, idx0_1, &var);
2894 V_I4(&var) = 90;
2895 SafeArrayPutElement(params, idx1_0, &var);
2896 V_I4(&var) = 80;
2897 SafeArrayPutElement(params, idx1_1, &var);
2899 hr = IScriptControl_Run(sc, str, &params, &var);
2900 ok(hr == S_OK, "IScriptControl_Run failed: 0x%08x.\n", hr);
2901 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));
2903 /* Hack the array's dimensions to 0 */
2904 params->cDims = 0;
2905 hr = IScriptControl_Run(sc, str, &params, &var);
2906 ok(hr == DISP_E_BADINDEX, "IScriptControl_Run returned: 0x%08x.\n", hr);
2907 ok(V_VT(&var) == VT_EMPTY, "V_VT(var) = %d.\n", V_VT(&var));
2908 params->cDims = 2;
2909 SysFreeString(str);
2910 IScriptControl_Release(sc);
2912 /* custom script engine */
2913 if (have_custom_engine)
2915 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
2916 &IID_IScriptControl, (void**)&sc);
2917 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
2919 SET_EXPECT(CreateInstance);
2920 SET_EXPECT(SetInterfaceSafetyOptions);
2921 SET_EXPECT(SetScriptSite);
2922 SET_EXPECT(QI_IActiveScriptParse);
2923 SET_EXPECT(InitNew);
2924 str = SysAllocString(L"testscript");
2925 hr = IScriptControl_put_Language(sc, str);
2926 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
2927 SysFreeString(str);
2928 CHECK_CALLED(CreateInstance);
2929 CHECK_CALLED(SetInterfaceSafetyOptions);
2930 CHECK_CALLED(SetScriptSite);
2931 CHECK_CALLED(QI_IActiveScriptParse);
2932 CHECK_CALLED(InitNew);
2934 GetScriptDispatch_expected_name = NULL;
2935 SET_EXPECT(SetScriptState_STARTED);
2936 SET_EXPECT(GetScriptDispatch);
2937 SET_EXPECT(QI_IDispatchEx);
2938 SET_EXPECT(GetIDsOfNames);
2939 SET_EXPECT(Invoke);
2940 Dispatch_expected_name = SysAllocString(L"function");
2941 hr = IScriptControl_Run(sc, Dispatch_expected_name, &params, &var);
2942 ok(hr == S_OK, "IScriptControl_Run failed: 0x%08x.\n", hr);
2943 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));
2944 SysFreeString(Dispatch_expected_name);
2945 CHECK_CALLED(SetScriptState_STARTED);
2946 CHECK_CALLED(GetScriptDispatch);
2947 CHECK_CALLED(QI_IDispatchEx);
2948 CHECK_CALLED(GetIDsOfNames);
2949 CHECK_CALLED(Invoke);
2951 /* GetScriptDispatch is cached and not called again */
2952 CLEAR_CALLED(GetScriptDispatch);
2953 SET_EXPECT(QI_IDispatchEx);
2954 SET_EXPECT(GetIDsOfNames);
2955 SET_EXPECT(Invoke);
2956 Dispatch_expected_name = SysAllocString(L"BarFoo");
2957 hr = IScriptControl_Run(sc, Dispatch_expected_name, &params, &var);
2958 ok(hr == S_OK, "IScriptControl_Run failed: 0x%08x.\n", hr);
2959 SysFreeString(Dispatch_expected_name);
2960 CHECK_NOT_CALLED(GetScriptDispatch);
2961 CHECK_CALLED(QI_IDispatchEx);
2962 CHECK_CALLED(GetIDsOfNames);
2963 CHECK_CALLED(Invoke);
2965 /* Make DispatchEx available */
2966 DispatchEx_available = TRUE;
2967 CLEAR_CALLED(GetScriptDispatch);
2968 SET_EXPECT(QI_IDispatchEx);
2969 SET_EXPECT(GetIDsOfNames);
2970 SET_EXPECT(InvokeEx);
2971 Dispatch_expected_name = SysAllocString(L"FooBar");
2972 hr = IScriptControl_Run(sc, Dispatch_expected_name, &params, &var);
2973 ok(hr == S_OK, "IScriptControl_Run failed: 0x%08x.\n", hr);
2974 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));
2975 SysFreeString(Dispatch_expected_name);
2976 CHECK_NOT_CALLED(GetScriptDispatch);
2977 CHECK_CALLED(QI_IDispatchEx);
2978 CHECK_CALLED(GetIDsOfNames);
2979 CHECK_CALLED(InvokeEx);
2981 /* QueryInterface for IDispatchEx is always called and not cached */
2982 CLEAR_CALLED(GetScriptDispatch);
2983 SET_EXPECT(QI_IDispatchEx);
2984 SET_EXPECT(GetIDsOfNames);
2985 SET_EXPECT(InvokeEx);
2986 Dispatch_expected_name = SysAllocString(L"1");
2987 hr = IScriptControl_Run(sc, Dispatch_expected_name, &params, &var);
2988 ok(hr == S_OK, "IScriptControl_Run failed: 0x%08x.\n", hr);
2989 SysFreeString(Dispatch_expected_name);
2990 CHECK_NOT_CALLED(GetScriptDispatch);
2991 CHECK_CALLED(QI_IDispatchEx);
2992 CHECK_CALLED(GetIDsOfNames);
2993 CHECK_CALLED(InvokeEx);
2994 DispatchEx_available = FALSE;
2996 IActiveScriptSite_Release(site);
2998 SET_EXPECT(Close);
2999 IScriptControl_Release(sc);
3000 CHECK_CALLED(Close);
3003 SafeArrayDestroy(params);
3006 static void test_IScriptControl_get_Modules(void)
3008 SAFEARRAYBOUND bnd[] = { { 2, 0 }, { 2, 0 } };
3009 LONG idx0_0[] = { 0, 0 };
3010 LONG idx0_1[] = { 1, 0 };
3011 LONG idx1_0[] = { 0, 1 };
3012 LONG idx1_1[] = { 1, 1 };
3014 IScriptProcedureCollection *procs;
3015 IEnumVARIANT *enumvar, *enumvar2;
3016 IScriptModuleCollection *mods;
3017 VARIANT var, vars[3];
3018 IScriptModule *mod;
3019 IScriptControl *sc;
3020 SAFEARRAY *params;
3021 IUnknown *unknown;
3022 IDispatch *disp;
3023 ULONG fetched;
3024 LONG count;
3025 HRESULT hr;
3026 DISPID id;
3027 BSTR str;
3028 UINT i;
3030 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
3031 &IID_IScriptControl, (void**)&sc);
3032 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
3034 hr = IScriptControl_get_Modules(sc, &mods);
3035 ok(hr == E_FAIL, "IScriptControl_get_Modules returned: 0x%08x.\n", hr);
3037 str = SysAllocString(L"jscript");
3038 hr = IScriptControl_put_Language(sc, str);
3039 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
3040 SysFreeString(str);
3042 hr = IScriptControl_get_Modules(sc, &mods);
3043 ok(hr == S_OK, "IScriptControl_get_Modules failed: 0x%08x.\n", hr);
3045 hr = IScriptModuleCollection_get_Count(mods, NULL);
3046 ok(hr == E_POINTER, "IScriptModuleCollection_get_Count returned: 0x%08x.\n", hr);
3047 count = 0;
3048 hr = IScriptModuleCollection_get_Count(mods, &count);
3049 ok(hr == S_OK, "IScriptModuleCollection_get_Count failed: 0x%08x.\n", hr);
3050 ok(count == 1, "count is not 1, got %d.\n", count);
3052 V_VT(&var) = VT_I4;
3053 V_I4(&var) = -1;
3054 hr = IScriptModuleCollection_get_Item(mods, var, NULL);
3055 ok(hr == E_POINTER, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
3056 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
3057 ok(hr == 0x800a0009, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
3059 V_VT(&var) = VT_EMPTY;
3060 str = SysAllocString(L"foobar");
3061 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
3062 ok(hr == E_INVALIDARG, "IScriptModuleCollection_Add returned: 0x%08x.\n", hr);
3063 hr = IScriptModuleCollection_Add(mods, str, &var, NULL);
3064 ok(hr == E_POINTER, "IScriptModuleCollection_Add returned: 0x%08x.\n", hr);
3065 V_VT(&var) = VT_DISPATCH;
3066 V_DISPATCH(&var) = NULL;
3067 hr = IScriptModuleCollection_Add(mods, NULL, &var, &mod);
3068 ok(hr == E_INVALIDARG, "IScriptModuleCollection_Add returned: 0x%08x.\n", hr);
3069 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
3070 ok(hr == S_OK, "IScriptModuleCollection_Add failed: 0x%08x.\n", hr);
3071 IScriptModule_Release(mod);
3072 SysFreeString(str);
3074 /* Grab an enumerator before we add another module */
3075 hr = IScriptModuleCollection_get__NewEnum(mods, NULL);
3076 ok(hr == E_POINTER, "IScriptModuleCollection_get__NewEnum returned: 0x%08x.\n", hr);
3077 hr = IScriptModuleCollection_get__NewEnum(mods, &unknown);
3078 ok(hr == S_OK, "IScriptModuleCollection_get__NewEnum failed: 0x%08x.\n", hr);
3079 hr = IUnknown_QueryInterface(unknown, &IID_IEnumVARIANT, (void**)&enumvar);
3080 ok(hr == S_OK, "Failed to query for IEnumVARIANT: 0x%08x.\n", hr);
3081 ok((char*)unknown == (char*)enumvar, "unknown and enumvar are not the same (%p vs %p).\n", unknown, enumvar);
3082 IUnknown_Release(unknown);
3084 str = SysAllocString(L"some other Module");
3085 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
3086 ok(hr == S_OK, "IScriptModuleCollection_Add failed: 0x%08x.\n", hr);
3087 IScriptModule_Release(mod);
3088 SysFreeString(str);
3090 /* Adding a module with the same name is invalid (case insensitive) */
3091 str = SysAllocString(L"FooBar");
3092 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
3093 ok(hr == E_INVALIDARG, "IScriptModuleCollection_Add failed: 0x%08x.\n", hr);
3094 SysFreeString(str);
3096 hr = IScriptModuleCollection_get_Count(mods, &count);
3097 ok(hr == S_OK, "IScriptModuleCollection_get_Count failed: 0x%08x.\n", hr);
3098 ok(count == 3, "count is not 3, got %d.\n", count);
3099 V_VT(&var) = VT_I4;
3100 V_I4(&var) = count + 1;
3101 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
3102 ok(hr == 0x800a0009, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
3103 V_VT(&var) = VT_BSTR;
3104 V_BSTR(&var) = SysAllocString(L"non-existent module");
3105 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
3106 ok(hr == CTL_E_ILLEGALFUNCTIONCALL, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
3107 ok(V_VT(&var) == VT_BSTR, "var type not BSTR, got %d.\n", V_VT(&var));
3108 VariantClear(&var);
3110 V_VT(&var) = VT_I4;
3111 V_I4(&var) = 1;
3112 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
3113 ok(hr == S_OK, "IScriptModuleCollection_get_Item failed: 0x%08x.\n", hr);
3114 hr = IScriptModule_get_Name(mod, NULL);
3115 ok(hr == E_POINTER, "IScriptModule_get_Name returned: 0x%08x.\n", hr);
3116 hr = IScriptModule_get_Name(mod, &str);
3117 ok(hr == S_OK, "IScriptModule_get_Name failed: 0x%08x.\n", hr);
3118 ok(!lstrcmpW(str, L"Global"), "got %s.\n", wine_dbgstr_w(str));
3119 SysFreeString(str);
3120 str = SysAllocString(L"function add(a, b) { return a + b; }\n");
3121 hr = IScriptModule_AddCode(mod, str);
3122 ok(hr == S_OK, "IScriptModule_AddCode failed: 0x%08x.\n", hr);
3123 IScriptModule_Release(mod);
3124 SysFreeString(str);
3126 V_VT(&var) = VT_BSTR;
3127 V_BSTR(&var) = SysAllocString(L"some other module");
3128 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
3129 ok(hr == S_OK, "IScriptModuleCollection_get_Item failed: 0x%08x.\n", hr);
3130 ok(V_VT(&var) == VT_BSTR, "var type not BSTR, got %d.\n", V_VT(&var));
3131 VariantClear(&var);
3132 hr = IScriptModule_get_Name(mod, &str);
3133 ok(hr == S_OK, "IScriptModule_get_Name failed: 0x%08x.\n", hr);
3134 ok(!lstrcmpW(str, L"some other Module"), "got %s.\n", wine_dbgstr_w(str));
3135 IScriptModule_Release(mod);
3136 SysFreeString(str);
3138 V_VT(&var) = VT_R8;
3139 V_R8(&var) = 2.0;
3140 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
3141 ok(hr == S_OK, "IScriptModuleCollection_get_Item failed: 0x%08x.\n", hr);
3142 hr = IScriptModule_get_Name(mod, &str);
3143 ok(hr == S_OK, "IScriptModule_get_Name failed: 0x%08x.\n", hr);
3144 ok(!lstrcmpW(str, L"foobar"), "got %s.\n", wine_dbgstr_w(str));
3145 SysFreeString(str);
3146 str = SysAllocString(L"function sub(a, b) { return a - b; }\n");
3147 hr = IScriptModule_AddCode(mod, str);
3148 ok(hr == S_OK, "IScriptModule_AddCode failed: 0x%08x.\n", hr);
3149 IScriptModule_Release(mod);
3150 SysFreeString(str);
3152 /* Test the enumerator, should be updated */
3153 fetched = 0xdeadbeef;
3154 hr = IEnumVARIANT_Next(enumvar, 0, NULL, NULL);
3155 ok(hr == E_POINTER, "IEnumVARIANT_Next returned: 0x%08x.\n", hr);
3156 hr = IEnumVARIANT_Next(enumvar, 0, NULL, &fetched);
3157 ok(hr == E_POINTER, "IEnumVARIANT_Next failed: 0x%08x.\n", hr);
3158 ok(fetched == 0xdeadbeef, "got %u.\n", fetched);
3159 hr = IEnumVARIANT_Next(enumvar, 0, &var, &fetched);
3160 ok(hr == S_OK, "IEnumVARIANT_Next returned: 0x%08x.\n", hr);
3161 ok(fetched == 0, "got %u.\n", fetched);
3162 hr = IEnumVARIANT_Next(enumvar, 0, &var, NULL);
3163 ok(hr == S_OK, "IEnumVARIANT_Next returned: 0x%08x.\n", hr);
3164 hr = IEnumVARIANT_Clone(enumvar, NULL);
3165 ok(hr == E_POINTER, "IEnumVARIANT_Clone failed: 0x%08x.\n", hr);
3167 hr = IEnumVARIANT_Next(enumvar, ARRAY_SIZE(vars), vars, &fetched);
3168 ok(hr == S_OK, "IEnumVARIANT_Next failed: 0x%08x.\n", hr);
3169 ok(fetched == ARRAY_SIZE(vars), "got %u.\n", fetched);
3170 hr = IEnumVARIANT_Next(enumvar, 1, &var, &fetched);
3171 ok(hr == S_FALSE, "IEnumVARIANT_Next failed: 0x%08x.\n", hr);
3172 ok(fetched == 0, "got %u.\n", fetched);
3173 hr = IEnumVARIANT_Skip(enumvar, 0);
3174 ok(hr == S_OK, "IEnumVARIANT_Skip failed: 0x%08x.\n", hr);
3175 hr = IEnumVARIANT_Skip(enumvar, 1);
3176 ok(hr == S_FALSE, "IEnumVARIANT_Skip failed: 0x%08x.\n", hr);
3177 hr = IEnumVARIANT_Clone(enumvar, &enumvar2);
3178 ok(hr == S_OK, "IEnumVARIANT_Clone failed: 0x%08x.\n", hr);
3179 hr = IEnumVARIANT_Skip(enumvar2, 1);
3180 ok(hr == S_FALSE, "IEnumVARIANT_Skip failed: 0x%08x.\n", hr);
3181 IEnumVARIANT_Release(enumvar2);
3183 for (i = 0; i < ARRAY_SIZE(vars); i++)
3185 ok(V_VT(&vars[i]) == VT_DISPATCH, "V_VT(vars[%u]) = %d.\n", i, V_VT(&vars[i]));
3186 hr = IDispatch_QueryInterface(V_DISPATCH(&vars[i]), &IID_IScriptModule, (void**)&mod);
3187 ok(hr == S_OK, "Failed to query IScriptModule from vars[%u]: 0x%08x.\n", i, hr);
3188 IScriptModule_Release(mod);
3189 VariantClear(&vars[i]);
3192 /* The 'Global' module is the same as the script control */
3193 str = SysAllocString(L"add(10, 5)");
3194 hr = IScriptControl_Eval(sc, str, &var);
3195 ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
3196 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));
3197 SysFreeString(str);
3198 str = SysAllocString(L"sub(10, 5)");
3199 hr = IScriptControl_Eval(sc, str, &var);
3200 ok(FAILED(hr), "IScriptControl_Eval succeeded: 0x%08x.\n", hr);
3201 SysFreeString(str);
3203 V_VT(&var) = VT_R4;
3204 V_R4(&var) = 2.0f;
3205 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
3206 ok(hr == S_OK, "IScriptModuleCollection_get_Item failed: 0x%08x.\n", hr);
3208 hr = IScriptModule_get_CodeObject(mod, &disp);
3209 ok(hr == S_OK, "IScriptModule_get_CodeObject failed: 0x%08x.\n", hr);
3211 str = SysAllocString(L"sub");
3212 hr = IDispatch_GetIDsOfNames(disp, &IID_NULL, &str, 1, LOCALE_USER_DEFAULT, &id);
3213 ok(hr == S_OK, "IDispatch_GetIDsOfNames failed: 0x%08x.\n", hr);
3214 ok(id != -1, "Unexpected id %d.\n", id);
3215 SysFreeString(str);
3217 str = SysAllocString(L"add");
3218 hr = IDispatch_GetIDsOfNames(disp, &IID_NULL, &str, 1, LOCALE_USER_DEFAULT, &id);
3219 ok(hr == DISP_E_UNKNOWNNAME, "IDispatch_GetIDsOfNames returned: 0x%08x.\n", hr);
3220 ok(id == -1, "Unexpected id %d.\n", id);
3221 SysFreeString(str);
3223 IDispatch_Release(disp);
3225 params = SafeArrayCreate(VT_VARIANT, 1, bnd);
3226 ok(params != NULL, "Failed to create SafeArray.\n");
3228 V_VT(&var) = VT_I4;
3229 V_I4(&var) = 10;
3230 SafeArrayPutElement(params, idx0_0, &var);
3231 V_I4(&var) = 3;
3232 SafeArrayPutElement(params, idx0_1, &var);
3234 str = SysAllocString(L"sub");
3235 hr = IScriptModule_Run(mod, str, NULL, &var);
3236 ok(hr == E_POINTER, "IScriptModule_Run returned: 0x%08x.\n", hr);
3237 hr = IScriptModule_Run(mod, str, &params, NULL);
3238 ok(hr == E_POINTER, "IScriptModule_Run returned: 0x%08x.\n", hr);
3240 hr = IScriptControl_Run(sc, str, &params, &var);
3241 ok(hr == DISP_E_UNKNOWNNAME, "IScriptControl_Run failed: 0x%08x.\n", hr);
3242 hr = IScriptModule_Run(mod, str, &params, &var);
3243 ok(hr == S_OK, "IScriptModule_Run failed: 0x%08x.\n", hr);
3244 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));
3245 SysFreeString(str);
3247 str = SysAllocString(L"add");
3248 hr = IScriptControl_Run(sc, str, &params, &var);
3249 ok(hr == S_OK, "IScriptControl_Run failed: 0x%08x.\n", hr);
3250 ok((V_VT(&var) == VT_I4) && (V_I4(&var) == 13), "V_VT(var) = %d, V_I4(var) = %d.\n", V_VT(&var), V_I4(&var));
3251 hr = IScriptModule_Run(mod, str, &params, &var);
3252 ok(hr == DISP_E_UNKNOWNNAME, "IScriptModule_Run failed: 0x%08x.\n", hr);
3253 SysFreeString(str);
3255 SafeArrayDestroy(params);
3256 params = SafeArrayCreate(VT_VARIANT, 2, bnd);
3257 ok(params != NULL, "Failed to create SafeArray.\n");
3259 V_VT(&var) = VT_I4;
3260 V_I4(&var) = 49;
3261 SafeArrayPutElement(params, idx0_0, &var);
3262 V_I4(&var) = 7;
3263 SafeArrayPutElement(params, idx0_1, &var);
3264 V_I4(&var) = 30;
3265 SafeArrayPutElement(params, idx1_0, &var);
3266 V_I4(&var) = 25;
3267 SafeArrayPutElement(params, idx1_1, &var);
3269 str = SysAllocString(L"sub");
3270 hr = IScriptModule_Run(mod, str, &params, &var);
3271 ok(hr == S_OK, "IScriptModule_Run failed: 0x%08x.\n", hr);
3272 ok((V_VT(&var) == VT_I4) && (V_I4(&var) == 42), "V_VT(var) = %d, V_I4(var) = %d.\n", V_VT(&var), V_I4(&var));
3274 params->cDims = 0;
3275 hr = IScriptModule_Run(mod, str, &params, &var);
3276 ok(hr == DISP_E_BADINDEX, "IScriptModule_Run returned: 0x%08x.\n", hr);
3277 ok(V_VT(&var) == VT_EMPTY, "V_VT(var) = %d.\n", V_VT(&var));
3278 params->cDims = 2;
3279 SysFreeString(str);
3281 IScriptModule_Release(mod);
3283 /* Grab a module ref and change the language to something valid */
3284 V_VT(&var) = VT_I2;
3285 V_I2(&var) = 3;
3286 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
3287 ok(hr == S_OK, "IScriptModuleCollection_get_Item failed: 0x%08x.\n", hr);
3288 str = SysAllocString(L"vbscript");
3289 hr = IScriptControl_put_Language(sc, str);
3290 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
3291 SysFreeString(str);
3293 /* The module collection changes and module ref is invalid */
3294 hr = IScriptModuleCollection_get_Count(mods, &count);
3295 ok(hr == S_OK, "IScriptModuleCollection_get_Count failed: 0x%08x.\n", hr);
3296 ok(count == 1, "count is not 1, got %d.\n", count);
3297 hr = IScriptModule_get_Name(mod, &str);
3298 ok(hr == E_FAIL, "IScriptModule_get_Name returned: 0x%08x.\n", hr);
3299 hr = IScriptModule_get_CodeObject(mod, &disp);
3300 ok(hr == E_FAIL, "IScriptModule_get_CodeObject returned: 0x%08x.\n", hr);
3301 hr = IScriptModule_get_Procedures(mod, &procs);
3302 ok(hr == E_FAIL, "IScriptModule_get_Procedures returned: 0x%08x.\n", hr);
3303 str = SysAllocString(L"function closed() { }\n");
3304 hr = IScriptModule_AddCode(mod, str);
3305 ok(hr == E_FAIL, "IScriptModule_AddCode failed: 0x%08x.\n", hr);
3306 SysFreeString(str);
3307 str = SysAllocString(L"sub closed\nend sub");
3308 hr = IScriptModule_AddCode(mod, str);
3309 ok(hr == E_FAIL, "IScriptModule_AddCode failed: 0x%08x.\n", hr);
3310 SysFreeString(str);
3311 str = SysAllocString(L"identifier");
3312 hr = IScriptModule_Run(mod, str, &params, &var);
3313 ok(hr == E_FAIL, "IScriptModule_Run returned: 0x%08x.\n", hr);
3314 IScriptModule_Release(mod);
3315 SafeArrayDestroy(params);
3316 SysFreeString(str);
3318 /* The enumerator is also invalid */
3319 hr = IEnumVARIANT_Reset(enumvar);
3320 ok(hr == E_FAIL, "IEnumVARIANT_Skip returned: 0x%08x.\n", hr);
3321 hr = IEnumVARIANT_Next(enumvar, 1, &var, &fetched);
3322 ok(hr == E_FAIL, "IEnumVARIANT_Next returned: 0x%08x.\n", hr);
3323 hr = IEnumVARIANT_Skip(enumvar, 0);
3324 ok(hr == E_FAIL, "IEnumVARIANT_Skip returned: 0x%08x.\n", hr);
3325 hr = IEnumVARIANT_Clone(enumvar, &enumvar2);
3326 ok(hr == E_FAIL, "IEnumVARIANT_Clone returned: 0x%08x.\n", hr);
3327 IEnumVARIANT_Release(enumvar);
3329 hr = IScriptControl_put_Language(sc, NULL);
3330 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
3332 hr = IScriptModuleCollection_get_Count(mods, &count);
3333 ok(hr == E_FAIL, "IScriptModuleCollection_get_Count returned: 0x%08x.\n", hr);
3334 V_VT(&var) = VT_I4;
3335 V_I4(&var) = 1;
3336 hr = IScriptModuleCollection_get_Item(mods, var, &mod);
3337 ok(hr == E_FAIL, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
3338 V_VT(&var) = VT_DISPATCH;
3339 V_DISPATCH(&var) = NULL;
3340 str = SysAllocString(L"module_name");
3341 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
3342 ok(hr == E_FAIL, "IScriptModuleCollection_Add returned: 0x%08x.\n", hr);
3343 SysFreeString(str);
3344 hr = IScriptModuleCollection_get__NewEnum(mods, &unknown);
3345 ok(hr == E_FAIL, "IScriptModuleCollection_get__NewEnum returned: 0x%08x.\n", hr);
3347 IScriptModuleCollection_Release(mods);
3348 hr = IScriptControl_get_Modules(sc, &mods);
3349 ok(hr == E_FAIL, "IScriptControl_get_Modules returned: 0x%08x.\n", hr);
3351 IScriptControl_Release(sc);
3353 /* custom script engine */
3354 if (have_custom_engine)
3356 BSTR code_str;
3358 /* A module collection ref keeps the control alive */
3359 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
3360 &IID_IScriptControl, (void**)&sc);
3361 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
3363 SET_EXPECT(CreateInstance);
3364 SET_EXPECT(SetInterfaceSafetyOptions);
3365 SET_EXPECT(SetScriptSite);
3366 SET_EXPECT(QI_IActiveScriptParse);
3367 SET_EXPECT(InitNew);
3368 str = SysAllocString(L"testscript");
3369 hr = IScriptControl_put_Language(sc, str);
3370 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
3371 SysFreeString(str);
3372 CHECK_CALLED(CreateInstance);
3373 CHECK_CALLED(SetInterfaceSafetyOptions);
3374 CHECK_CALLED(SetScriptSite);
3375 CHECK_CALLED(QI_IActiveScriptParse);
3376 CHECK_CALLED(InitNew);
3378 hr = IScriptControl_get_Modules(sc, &mods);
3379 ok(hr == S_OK, "IScriptControl_get_Modules failed: 0x%08x.\n", hr);
3381 IActiveScriptSite_Release(site);
3382 IScriptControl_Release(sc);
3384 SET_EXPECT(Close);
3385 IScriptModuleCollection_Release(mods);
3386 CHECK_CALLED(Close);
3388 /* Add a module with a non-null object and add some code to it */
3389 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
3390 &IID_IScriptControl, (void**)&sc);
3391 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
3393 SET_EXPECT(CreateInstance);
3394 SET_EXPECT(SetInterfaceSafetyOptions);
3395 SET_EXPECT(SetScriptSite);
3396 SET_EXPECT(QI_IActiveScriptParse);
3397 SET_EXPECT(InitNew);
3398 str = SysAllocString(L"testscript");
3399 hr = IScriptControl_put_Language(sc, str);
3400 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
3401 SysFreeString(str);
3402 CHECK_CALLED(CreateInstance);
3403 CHECK_CALLED(SetInterfaceSafetyOptions);
3404 CHECK_CALLED(SetScriptSite);
3405 CHECK_CALLED(QI_IActiveScriptParse);
3406 CHECK_CALLED(InitNew);
3408 hr = IScriptControl_get_Modules(sc, &mods);
3409 ok(hr == S_OK, "IScriptControl_get_Modules failed: 0x%08x.\n", hr);
3411 SET_EXPECT(AddNamedItem);
3412 str = SysAllocString(L"modname");
3413 AddNamedItem_expected_name = str;
3414 AddNamedItem_expected_flags = 0;
3415 V_VT(&var) = VT_DISPATCH;
3416 V_DISPATCH(&var) = &testdisp;
3417 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
3418 ok(hr == S_OK, "IScriptModuleCollection_Add failed: 0x%08x.\n", hr);
3419 VariantClear(&var);
3420 CHECK_CALLED(AddNamedItem);
3422 unknown = (IUnknown*)0xdeadbeef;
3423 hr = IActiveScriptSite_GetItemInfo(site, str, SCRIPTINFO_IUNKNOWN, &unknown, NULL);
3424 ok(hr == S_OK, "IActiveScriptSite_GetItemInfo failed: 0x%08x.\n", hr);
3425 ok(unknown == (IUnknown*)&testdisp, "Unexpected IUnknown for the item: %p.\n", unknown);
3426 IUnknown_Release(unknown);
3428 GetScriptDispatch_expected_name = str;
3429 SET_EXPECT(SetScriptState_STARTED);
3430 SET_EXPECT(GetScriptDispatch);
3431 hr = IScriptModule_get_CodeObject(mod, &disp);
3432 ok(hr == S_OK, "IScriptModule_get_CodeObject failed: 0x%08x.\n", hr);
3433 ok(disp == (IDispatch*)&DispatchEx, "Unexpected code object %p.\n", disp);
3434 CHECK_CALLED(GetScriptDispatch);
3435 CHECK_CALLED(SetScriptState_STARTED);
3436 GetScriptDispatch_expected_name = NULL;
3437 IDispatch_Release(disp);
3439 SET_EXPECT(ParseScriptText);
3440 parse_item_name = str;
3441 parse_flags = SCRIPTTEXT_ISVISIBLE;
3442 code_str = SysAllocString(L"some code");
3443 hr = IScriptModule_AddCode(mod, code_str);
3444 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
3445 CHECK_CALLED(ParseScriptText);
3446 SysFreeString(code_str);
3447 SysFreeString(str);
3449 /* Keep the module ref before changing the language */
3450 SET_EXPECT(Close);
3451 hr = IScriptControl_put_Language(sc, NULL);
3452 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
3453 CHECK_CALLED(Close);
3454 IScriptModuleCollection_Release(mods);
3455 IActiveScriptSite_Release(site);
3456 IScriptControl_Release(sc);
3457 IScriptModule_Release(mod);
3459 /* Now try holding a module ref while closing the script */
3460 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
3461 &IID_IScriptControl, (void**)&sc);
3462 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
3464 SET_EXPECT(CreateInstance);
3465 SET_EXPECT(SetInterfaceSafetyOptions);
3466 SET_EXPECT(SetScriptSite);
3467 SET_EXPECT(QI_IActiveScriptParse);
3468 SET_EXPECT(InitNew);
3469 str = SysAllocString(L"testscript");
3470 hr = IScriptControl_put_Language(sc, str);
3471 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
3472 SysFreeString(str);
3473 CHECK_CALLED(CreateInstance);
3474 CHECK_CALLED(SetInterfaceSafetyOptions);
3475 CHECK_CALLED(SetScriptSite);
3476 CHECK_CALLED(QI_IActiveScriptParse);
3477 CHECK_CALLED(InitNew);
3479 hr = IScriptControl_get_Modules(sc, &mods);
3480 ok(hr == S_OK, "IScriptControl_get_Modules failed: 0x%08x.\n", hr);
3482 SET_EXPECT(AddNamedItem);
3483 str = SysAllocString(L"foo");
3484 AddNamedItem_expected_name = str;
3485 AddNamedItem_expected_flags = SCRIPTITEM_CODEONLY;
3486 V_VT(&var) = VT_DISPATCH;
3487 V_DISPATCH(&var) = NULL;
3488 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
3489 ok(hr == S_OK, "IScriptModuleCollection_Add failed: 0x%08x.\n", hr);
3490 VariantClear(&var);
3491 CHECK_CALLED(AddNamedItem);
3493 unknown = (IUnknown*)0xdeadbeef;
3494 hr = IActiveScriptSite_GetItemInfo(site, str, SCRIPTINFO_IUNKNOWN, &unknown, NULL);
3495 ok(hr == TYPE_E_ELEMENTNOTFOUND, "IActiveScriptSite_GetItemInfo returned: 0x%08x.\n", hr);
3496 IScriptModuleCollection_Release(mods);
3497 IActiveScriptSite_Release(site);
3498 IScriptControl_Release(sc);
3500 SET_EXPECT(SetScriptState_STARTED);
3501 SET_EXPECT(ParseScriptText);
3502 parse_item_name = str;
3503 parse_flags = SCRIPTTEXT_ISVISIBLE;
3504 code_str = SysAllocString(L"code after close");
3505 hr = IScriptModule_AddCode(mod, code_str);
3506 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
3507 CHECK_CALLED(SetScriptState_STARTED);
3508 CHECK_CALLED(ParseScriptText);
3509 SysFreeString(code_str);
3510 SysFreeString(str);
3512 SET_EXPECT(Close);
3513 IScriptModule_Release(mod);
3514 CHECK_CALLED(Close);
3516 /* Hold an enumerator while releasing the script control */
3517 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
3518 &IID_IScriptControl, (void**)&sc);
3519 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
3521 SET_EXPECT(CreateInstance);
3522 SET_EXPECT(SetInterfaceSafetyOptions);
3523 SET_EXPECT(SetScriptSite);
3524 SET_EXPECT(QI_IActiveScriptParse);
3525 SET_EXPECT(InitNew);
3526 str = SysAllocString(L"testscript");
3527 hr = IScriptControl_put_Language(sc, str);
3528 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
3529 SysFreeString(str);
3530 CHECK_CALLED(CreateInstance);
3531 CHECK_CALLED(SetInterfaceSafetyOptions);
3532 CHECK_CALLED(SetScriptSite);
3533 CHECK_CALLED(QI_IActiveScriptParse);
3534 CHECK_CALLED(InitNew);
3536 hr = IScriptControl_get_Modules(sc, &mods);
3537 ok(hr == S_OK, "IScriptControl_get_Modules failed: 0x%08x.\n", hr);
3538 IScriptControl_Release(sc);
3540 SET_EXPECT(AddNamedItem);
3541 str = SysAllocString(L"bar");
3542 AddNamedItem_expected_name = str;
3543 AddNamedItem_expected_flags = SCRIPTITEM_CODEONLY;
3544 V_VT(&var) = VT_DISPATCH;
3545 V_DISPATCH(&var) = NULL;
3546 hr = IScriptModuleCollection_Add(mods, str, &var, &mod);
3547 ok(hr == S_OK, "IScriptModuleCollection_Add failed: 0x%08x.\n", hr);
3548 IScriptModule_Release(mod);
3549 VariantClear(&var);
3550 SysFreeString(str);
3551 CHECK_CALLED(AddNamedItem);
3553 hr = IScriptModuleCollection_get__NewEnum(mods, &unknown);
3554 ok(hr == S_OK, "IScriptModuleCollection_get__NewEnum failed: 0x%08x.\n", hr);
3555 hr = IUnknown_QueryInterface(unknown, &IID_IEnumVARIANT, (void**)&enumvar);
3556 ok(hr == S_OK, "Failed to query for IEnumVARIANT: 0x%08x.\n", hr);
3557 IUnknown_Release(unknown);
3559 IScriptModuleCollection_Release(mods);
3560 IActiveScriptSite_Release(site);
3562 hr = IEnumVARIANT_Next(enumvar, ARRAY_SIZE(vars), vars, &fetched);
3563 ok(hr == S_FALSE, "IEnumVARIANT_Next failed: 0x%08x.\n", hr);
3564 ok(fetched == 2, "got %u.\n", fetched);
3565 for (i = 0; i < fetched; i++)
3567 ok(V_VT(&vars[i]) == VT_DISPATCH, "V_VT(vars[%u]) = %d.\n", i, V_VT(&vars[i]));
3568 hr = IDispatch_QueryInterface(V_DISPATCH(&vars[i]), &IID_IScriptModule, (void**)&mod);
3569 ok(hr == S_OK, "Failed to query IScriptModule from vars[%u]: 0x%08x.\n", i, hr);
3570 hr = IScriptModule_get_Name(mod, &str);
3571 ok(hr == S_OK, "IScriptModule_get_Name failed for vars[%u]: 0x%08x.\n", i, hr);
3572 ok(!lstrcmpW(str, i ? L"bar" : L"Global"), "wrong name for vars[%u]: %s.\n", i, wine_dbgstr_w(str));
3573 IScriptModule_Release(mod);
3574 VariantClear(&vars[i]);
3575 SysFreeString(str);
3578 SET_EXPECT(Close);
3579 IEnumVARIANT_Release(enumvar);
3580 CHECK_CALLED(Close);
3584 static void test_IScriptControl_get_Error(void)
3586 IScriptError *error, *error2;
3587 IScriptControl *sc;
3588 HRESULT hr;
3589 BSTR str;
3590 LONG x;
3592 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
3593 &IID_IScriptControl, (void**)&sc);
3594 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
3596 hr = IScriptControl_get_Error(sc, NULL);
3597 ok(hr == E_POINTER, "IScriptControl_get_Error returned: 0x%08x.\n", hr);
3598 hr = IScriptControl_get_Error(sc, &error);
3599 ok(hr == S_OK, "IScriptControl_get_Error failed: 0x%08x.\n", hr);
3601 x = 0xdeadbeef;
3602 hr = IScriptError_get_Number(error, &x);
3603 ok(hr == S_OK, "IScriptError_get_Number failed: 0x%08x.\n", hr);
3604 ok(x == 0, "Error Number is not 0, got %d.\n", x);
3605 hr = IScriptError_get_Source(error, &str);
3606 ok(hr == S_OK, "IScriptError_get_Source failed: 0x%08x.\n", hr);
3607 ok(str == NULL, "Error Source is not (null), got %s.\n", wine_dbgstr_w(str));
3608 hr = IScriptError_get_Description(error, &str);
3609 ok(hr == S_OK, "IScriptError_get_Description failed: 0x%08x.\n", hr);
3610 ok(str == NULL, "Error Description is not (null), got %s.\n", wine_dbgstr_w(str));
3611 hr = IScriptError_get_HelpFile(error, &str);
3612 ok(hr == S_OK, "IScriptError_get_HelpFile failed: 0x%08x.\n", hr);
3613 ok(str == NULL, "Error HelpFile is not (null), got %s.\n", wine_dbgstr_w(str));
3614 hr = IScriptError_get_HelpContext(error, &x);
3615 ok(hr == S_OK, "IScriptError_get_HelpContext failed: 0x%08x.\n", hr);
3616 ok(x == 0, "Error HelpContext is not 0, got %d.\n", x);
3617 hr = IScriptError_get_Text(error, &str);
3618 ok(hr == S_OK, "IScriptError_get_Text failed: 0x%08x.\n", hr);
3619 ok(str == NULL, "Error Text is not (null), got %s.\n", wine_dbgstr_w(str));
3620 hr = IScriptError_get_Line(error, &x);
3621 ok(hr == S_OK, "IScriptError_get_Line failed: 0x%08x.\n", hr);
3622 ok(x == 0, "Error Line is not 0, got %d.\n", x);
3623 hr = IScriptError_get_Column(error, &x);
3624 ok(hr == S_OK, "IScriptError_get_Column failed: 0x%08x.\n", hr);
3625 ok(x == 0, "Error Column is not 0, got %d.\n", x);
3627 str = SysAllocString(L"jscript");
3628 hr = IScriptControl_put_Language(sc, str);
3629 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
3630 SysFreeString(str);
3632 str = SysAllocString(L""
3633 "var valid_var = 1;\n"
3634 "// comment\n"
3635 "this is an invalid line\n");
3636 hr = IScriptControl_AddCode(sc, str);
3637 ok(FAILED(hr), "IScriptControl_AddCode succeeded: 0x%08x.\n", hr);
3638 SysFreeString(str);
3640 x = 0xdeadbeef;
3641 hr = IScriptError_get_Number(error, &x);
3642 ok(hr == S_OK, "IScriptError_get_Number failed: 0x%08x.\n", hr);
3643 todo_wine ok(x > 1000, "Error Number is wrong, got %d.\n", x);
3644 hr = IScriptError_get_Source(error, &str);
3645 ok(hr == S_OK, "IScriptError_get_Source failed: 0x%08x.\n", hr);
3646 ok(str != NULL, "Error Source is (null).\n");
3647 SysFreeString(str);
3648 hr = IScriptError_get_Description(error, &str);
3649 ok(hr == S_OK, "IScriptError_get_Description failed: 0x%08x.\n", hr);
3650 ok(str != NULL, "Error Description is (null).\n");
3651 SysFreeString(str);
3652 hr = IScriptError_get_Text(error, &str);
3653 ok(hr == S_OK, "IScriptError_get_Text failed: 0x%08x.\n", hr);
3654 ok(!lstrcmpW(str, L"this is an invalid line"), "Error Text is wrong, got %s.\n", wine_dbgstr_w(str));
3655 SysFreeString(str);
3656 hr = IScriptError_get_Line(error, &x);
3657 ok(hr == S_OK, "IScriptError_get_Line failed: 0x%08x.\n", hr);
3658 ok(x == 3, "Error Line is not 3, got %d.\n", x);
3659 hr = IScriptError_get_Column(error, &x);
3660 ok(hr == S_OK, "IScriptError_get_Column failed: 0x%08x.\n", hr);
3661 ok(x == 5, "Error Column is not 5, got %d.\n", x);
3663 hr = IScriptError_Clear(error);
3664 ok(hr == S_OK, "IScriptError_Clear failed: 0x%08x.\n", hr);
3665 x = 0xdeadbeef;
3666 hr = IScriptError_get_Number(error, &x);
3667 ok(hr == S_OK, "IScriptError_get_Number failed: 0x%08x.\n", hr);
3668 ok(x == 0, "Error Number is not 0, got %d.\n", x);
3669 hr = IScriptError_get_Source(error, &str);
3670 ok(hr == S_OK, "IScriptError_get_Source failed: 0x%08x.\n", hr);
3671 ok(str == NULL, "Error Source is not (null), got %s.\n", wine_dbgstr_w(str));
3672 hr = IScriptError_get_Description(error, &str);
3673 ok(hr == S_OK, "IScriptError_get_Description failed: 0x%08x.\n", hr);
3674 ok(str == NULL, "Error Description is not (null), got %s.\n", wine_dbgstr_w(str));
3675 hr = IScriptError_get_HelpFile(error, &str);
3676 ok(hr == S_OK, "IScriptError_get_HelpFile failed: 0x%08x.\n", hr);
3677 ok(str == NULL, "Error HelpFile is not (null), got %s.\n", wine_dbgstr_w(str));
3678 hr = IScriptError_get_HelpContext(error, &x);
3679 ok(hr == S_OK, "IScriptError_get_HelpContext failed: 0x%08x.\n", hr);
3680 ok(x == 0, "Error HelpContext is not 0, got %d.\n", x);
3681 hr = IScriptError_get_Text(error, &str);
3682 ok(hr == S_OK, "IScriptError_get_Text failed: 0x%08x.\n", hr);
3683 ok(str == NULL, "Error Text is not (null), got %s.\n", wine_dbgstr_w(str));
3684 hr = IScriptError_get_Line(error, &x);
3685 ok(hr == S_OK, "IScriptError_get_Line failed: 0x%08x.\n", hr);
3686 ok(x == 0, "Error Line is not 0, got %d.\n", x);
3687 hr = IScriptError_get_Column(error, &x);
3688 ok(hr == S_OK, "IScriptError_get_Column failed: 0x%08x.\n", hr);
3689 ok(x == 0, "Error Column is not 0, got %d.\n", x);
3691 hr = IScriptControl_get_Error(sc, &error2);
3692 ok(hr == S_OK, "IScriptControl_get_Error failed: 0x%08x.\n", hr);
3693 ok(error == error2, "Error objects are not the same (%p vs %p).\n", error, error2);
3694 IScriptError_Release(error2);
3696 IScriptError_Release(error);
3697 IScriptControl_Release(sc);
3699 /* custom script engine */
3700 if (have_custom_engine)
3702 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
3703 &IID_IScriptControl, (void**)&sc);
3704 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
3706 SET_EXPECT(CreateInstance);
3707 SET_EXPECT(SetInterfaceSafetyOptions);
3708 SET_EXPECT(SetScriptSite);
3709 SET_EXPECT(QI_IActiveScriptParse);
3710 SET_EXPECT(InitNew);
3711 str = SysAllocString(L"testscript");
3712 hr = IScriptControl_put_Language(sc, str);
3713 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
3714 SysFreeString(str);
3715 CHECK_CALLED(CreateInstance);
3716 CHECK_CALLED(SetInterfaceSafetyOptions);
3717 CHECK_CALLED(SetScriptSite);
3718 CHECK_CALLED(QI_IActiveScriptParse);
3719 CHECK_CALLED(InitNew);
3721 hr = IScriptControl_get_Error(sc, &error);
3722 ok(hr == S_OK, "IScriptControl_get_Error failed: 0x%08x.\n", hr);
3724 x = 0xdeadbeef;
3725 hr = IScriptError_get_Number(error, &x);
3726 ok(hr == S_OK, "IScriptError_get_Number failed: 0x%08x.\n", hr);
3727 ok(x == 0, "Error Number is not 0, got %d.\n", x);
3729 /* The calls are cached even if they fail */
3730 ActiveScriptError_stage = 0;
3731 hr = IActiveScriptSite_OnScriptError(site, &ActiveScriptError);
3732 ok(hr == S_FALSE, "IActiveScriptSite_OnScriptError returned: 0x%08x.\n", hr);
3734 SET_EXPECT(GetExceptionInfo);
3735 x = 0xdeadbeef;
3736 hr = IScriptError_get_Number(error, &x);
3737 ok(hr == S_OK, "IScriptError_get_Number failed: 0x%08x.\n", hr);
3738 ok(x == 0, "Error Number is not 0, got %d.\n", x);
3739 CHECK_CALLED(GetExceptionInfo);
3740 hr = IScriptError_get_Source(error, &str);
3741 ok(hr == S_OK, "IScriptError_get_Source failed: 0x%08x.\n", hr);
3742 ok(str == NULL, "Error Source is not (null), got %s.\n", wine_dbgstr_w(str));
3743 hr = IScriptError_get_Description(error, &str);
3744 ok(hr == S_OK, "IScriptError_get_Description failed: 0x%08x.\n", hr);
3745 ok(str == NULL, "Error Description is not (null), got %s.\n", wine_dbgstr_w(str));
3746 hr = IScriptError_get_HelpFile(error, &str);
3747 ok(hr == S_OK, "IScriptError_get_HelpFile failed: 0x%08x.\n", hr);
3748 ok(str == NULL, "Error HelpFile is not (null), got %s.\n", wine_dbgstr_w(str));
3749 hr = IScriptError_get_HelpContext(error, &x);
3750 ok(hr == S_OK, "IScriptError_get_HelpContext failed: 0x%08x.\n", hr);
3751 ok(x == 0, "Error HelpContext is not 0, got %d.\n", x);
3753 SET_EXPECT(GetSourceLineText);
3754 hr = IScriptError_get_Text(error, &str);
3755 ok(hr == S_OK, "IScriptError_get_Text failed: 0x%08x.\n", hr);
3756 ok(!lstrcmpW(str, L"source line"), "Error Text is wrong, got %s.\n", wine_dbgstr_w(str));
3757 SysFreeString(str);
3758 CHECK_CALLED(GetSourceLineText);
3760 SET_EXPECT(GetSourcePosition);
3761 hr = IScriptError_get_Line(error, &x);
3762 ok(hr == S_OK, "IScriptError_get_Line failed: 0x%08x.\n", hr);
3763 ok(x == 0, "Error Line is not 0, got %d.\n", x);
3764 CHECK_CALLED(GetSourcePosition);
3765 hr = IScriptError_get_Column(error, &x);
3766 ok(hr == S_OK, "IScriptError_get_Column failed: 0x%08x.\n", hr);
3767 ok(x == 0, "Error Column is not 0, got %d.\n", x);
3769 /* Check with deferred fill-in */
3770 ActiveScriptError_stage = 1;
3771 hr = IActiveScriptSite_OnScriptError(site, &ActiveScriptError);
3772 ok(hr == S_FALSE, "IActiveScriptSite_OnScriptError returned: 0x%08x.\n", hr);
3774 SET_EXPECT(GetExceptionInfo);
3775 SET_EXPECT(DeferredFillIn);
3776 x = 0xdeadbeef;
3777 hr = IScriptError_get_Number(error, &x);
3778 ok(hr == S_OK, "IScriptError_get_Number failed: 0x%08x.\n", hr);
3779 ok(x == 0, "Error Number is not 0, got %d.\n", x);
3780 CHECK_CALLED(GetExceptionInfo);
3781 CHECK_CALLED(DeferredFillIn);
3782 hr = IScriptError_get_Source(error, &str);
3783 ok(hr == S_OK, "IScriptError_get_Source failed: 0x%08x.\n", hr);
3784 ok(!lstrcmpW(str, L"foobar"), "Error Source is wrong, got %s.\n", wine_dbgstr_w(str));
3785 SysFreeString(str);
3786 hr = IScriptError_get_Description(error, &str);
3787 ok(hr == S_OK, "IScriptError_get_Description failed: 0x%08x.\n", hr);
3788 ok(!lstrcmpW(str, L"barfoo"), "Error Description is wrong, got %s.\n", wine_dbgstr_w(str));
3789 SysFreeString(str);
3791 SET_EXPECT(GetSourceLineText);
3792 hr = IScriptError_get_Text(error, &str);
3793 ok(hr == S_OK, "IScriptError_get_Text failed: 0x%08x.\n", hr);
3794 ok(!lstrcmpW(str, L"source line"), "Error Text is wrong, got %s.\n", wine_dbgstr_w(str));
3795 SysFreeString(str);
3796 CHECK_CALLED(GetSourceLineText);
3798 SET_EXPECT(GetSourcePosition);
3799 hr = IScriptError_get_Line(error, &x);
3800 ok(hr == S_OK, "IScriptError_get_Line failed: 0x%08x.\n", hr);
3801 ok(x == 42, "Error Line is not 42, got %d.\n", x);
3802 CHECK_CALLED(GetSourcePosition);
3803 hr = IScriptError_get_Column(error, &x);
3804 ok(hr == S_OK, "IScriptError_get_Column failed: 0x%08x.\n", hr);
3805 ok(x == 10, "Error Column is not 10, got %d.\n", x);
3807 /* Check without deferred fill-in, but using scode */
3808 ActiveScriptError_stage = 2;
3809 hr = IActiveScriptSite_OnScriptError(site, &ActiveScriptError);
3810 ok(hr == S_FALSE, "IActiveScriptSite_OnScriptError returned: 0x%08x.\n", hr);
3812 SET_EXPECT(GetExceptionInfo);
3813 x = 0xdeadbeef;
3814 hr = IScriptError_get_Number(error, &x);
3815 ok(hr == S_OK, "IScriptError_get_Number failed: 0x%08x.\n", hr);
3816 ok(x == 0xbeef, "Error Number is not 0xbeef, got 0x%04x.\n", x);
3817 CHECK_CALLED(GetExceptionInfo);
3818 hr = IScriptError_get_Source(error, &str);
3819 ok(hr == S_OK, "IScriptError_get_Source failed: 0x%08x.\n", hr);
3820 ok(!lstrcmpW(str, L"source"), "Error Source is wrong, got %s.\n", wine_dbgstr_w(str));
3821 SysFreeString(str);
3822 hr = IScriptError_get_Description(error, &str);
3823 ok(hr == S_OK, "IScriptError_get_Description failed: 0x%08x.\n", hr);
3824 ok(str == NULL, "Error Description is not (null), got %s.\n", wine_dbgstr_w(str));
3826 SET_EXPECT(GetSourceLineText);
3827 hr = IScriptError_get_Text(error, &str);
3828 ok(hr == S_OK, "IScriptError_get_Text failed: 0x%08x.\n", hr);
3829 ok(!lstrcmpW(str, L"source line"), "Error Text is wrong, got %s.\n", wine_dbgstr_w(str));
3830 SysFreeString(str);
3831 CHECK_CALLED(GetSourceLineText);
3833 SET_EXPECT(GetSourcePosition);
3834 hr = IScriptError_get_Line(error, &x);
3835 ok(hr == S_OK, "IScriptError_get_Line failed: 0x%08x.\n", hr);
3836 ok(x == 42, "Error Line is not 42, got %d.\n", x);
3837 CHECK_CALLED(GetSourcePosition);
3838 hr = IScriptError_get_Column(error, &x);
3839 ok(hr == S_OK, "IScriptError_get_Column failed: 0x%08x.\n", hr);
3840 ok(x == 10, "Error Column is not 10, got %d.\n", x);
3842 IActiveScriptSite_Release(site);
3844 SET_EXPECT(Close);
3845 IScriptControl_Release(sc);
3846 CHECK_CALLED(Close);
3848 IScriptError_Release(error);
3852 static void test_IScriptControl_get_CodeObject(void)
3854 IScriptControl *sc;
3855 IDispatch *disp;
3856 HRESULT hr;
3857 BSTR str;
3859 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
3860 &IID_IScriptControl, (void**)&sc);
3861 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
3863 hr = IScriptControl_get_CodeObject(sc, &disp);
3864 ok(hr == E_FAIL, "IScriptControl_get_CodeObject returned: 0x%08x.\n", hr);
3866 str = SysAllocString(L"jscript");
3867 hr = IScriptControl_put_Language(sc, str);
3868 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
3869 SysFreeString(str);
3871 hr = IScriptControl_get_CodeObject(sc, &disp);
3872 ok(hr == S_OK, "IScriptControl_get_CodeObject failed: 0x%08x.\n", hr);
3874 IDispatch_Release(disp);
3875 IScriptControl_Release(sc);
3877 if (have_custom_engine)
3879 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
3880 &IID_IScriptControl, (void**)&sc);
3881 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
3883 SET_EXPECT(CreateInstance);
3884 SET_EXPECT(SetInterfaceSafetyOptions);
3885 SET_EXPECT(SetScriptSite);
3886 SET_EXPECT(QI_IActiveScriptParse);
3887 SET_EXPECT(InitNew);
3889 str = SysAllocString(L"testscript");
3890 hr = IScriptControl_put_Language(sc, str);
3891 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
3892 SysFreeString(str);
3894 CHECK_CALLED(CreateInstance);
3895 CHECK_CALLED(SetInterfaceSafetyOptions);
3896 CHECK_CALLED(SetScriptSite);
3897 CHECK_CALLED(QI_IActiveScriptParse);
3898 CHECK_CALLED(InitNew);
3900 GetScriptDispatch_expected_name = NULL;
3901 SET_EXPECT(SetScriptState_STARTED);
3902 SET_EXPECT(GetScriptDispatch);
3903 hr = IScriptControl_get_CodeObject(sc, &disp);
3904 ok(hr == S_OK, "IScriptControl_get_CodeObject failed: 0x%08x.\n", hr);
3905 ok(disp == (IDispatch*)&DispatchEx, "unexpected code object %p\n", disp);
3906 CHECK_CALLED(GetScriptDispatch);
3907 CHECK_CALLED(SetScriptState_STARTED);
3909 IDispatch_Release(disp);
3910 IActiveScriptSite_Release(site);
3912 SET_EXPECT(Close);
3913 IScriptControl_Release(sc);
3914 CHECK_CALLED(Close);
3918 static void test_IScriptControl_get_Procedures(void)
3920 IScriptProcedureCollection *procs, *procs2;
3921 IEnumVARIANT *enumvar, *enumvar2;
3922 IScriptProcedure *proc, *proc2;
3923 IScriptControl *sc;
3924 IUnknown *unknown;
3925 VARIANT_BOOL vbool;
3926 ULONG fetched;
3927 VARIANT var;
3928 LONG count;
3929 HRESULT hr;
3930 BSTR str;
3931 UINT i;
3933 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
3934 &IID_IScriptControl, (void**)&sc);
3935 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
3937 hr = IScriptControl_get_Procedures(sc, &procs);
3938 ok(hr == E_FAIL, "IScriptControl_get_Procedures returned: 0x%08x.\n", hr);
3940 str = SysAllocString(L"jscript");
3941 hr = IScriptControl_put_Language(sc, str);
3942 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
3943 SysFreeString(str);
3945 hr = IScriptControl_get_Procedures(sc, &procs);
3946 ok(hr == S_OK, "IScriptControl_get_Procedures failed: 0x%08x.\n", hr);
3948 hr = IScriptProcedureCollection_get_Count(procs, NULL);
3949 ok(hr == E_POINTER, "IScriptProcedureCollection_get_Count returned: 0x%08x.\n", hr);
3950 hr = IScriptProcedureCollection_get_Count(procs, &count);
3951 ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
3952 ok(count == 0, "count is not 0, got %d.\n", count);
3954 V_VT(&var) = VT_I4;
3955 V_I4(&var) = -1;
3956 hr = IScriptProcedureCollection_get_Item(procs, var, NULL);
3957 ok(hr == E_POINTER, "IScriptProcedureCollection_get_Item returned: 0x%08x.\n", hr);
3958 hr = IScriptProcedureCollection_get_Item(procs, var, &proc);
3959 ok(hr == 0x800a0009, "IScriptProcedureCollection_get_Item returned: 0x%08x.\n", hr);
3961 str = SysAllocString(L""
3962 "function add(a, b) { return a + b; }\n"
3963 "function nop(a) { }\n"
3964 "function muladd(a, b, c) { return a * b + c; }\n"
3966 hr = IScriptControl_AddCode(sc, str);
3967 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
3968 CHECK_ERROR(sc, 0);
3969 SysFreeString(str);
3971 hr = IScriptProcedureCollection_get_Count(procs, &count);
3972 ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
3973 ok(count == 3, "count is not 3, got %d.\n", count);
3975 V_VT(&var) = VT_I4;
3976 V_I4(&var) = 1;
3977 IScriptProcedureCollection_AddRef(procs);
3978 i = IScriptProcedureCollection_Release(procs);
3979 hr = IScriptProcedureCollection_get_Item(procs, var, &proc);
3980 ok(hr == S_OK, "IScriptProcedureCollection_get_Item failed: 0x%08x.\n", hr);
3981 IScriptProcedureCollection_AddRef(procs);
3982 ok(i == IScriptProcedureCollection_Release(procs),
3983 "IScriptProcedureCollection_get_Item should not have added a ref to the collection.\n");
3984 hr = IScriptProcedure_get_Name(proc, NULL);
3985 ok(hr == E_POINTER, "IScriptProcedure_get_Name returned: 0x%08x.\n", hr);
3986 hr = IScriptProcedure_get_Name(proc, &str);
3987 ok(hr == S_OK, "IScriptProcedure_get_Name failed: 0x%08x.\n", hr);
3988 ok(!lstrcmpW(str, L"add"), "Wrong name, got %s.\n", wine_dbgstr_w(str));
3989 SysFreeString(str);
3990 hr = IScriptProcedure_get_NumArgs(proc, NULL);
3991 ok(hr == E_POINTER, "IScriptProcedure_get_NumArgs returned: 0x%08x.\n", hr);
3992 hr = IScriptProcedure_get_NumArgs(proc, &count);
3993 ok(hr == S_OK, "IScriptProcedure_get_NumArgs failed: 0x%08x.\n", hr);
3994 ok(count == 2, "Wrong NumArgs, got %d.\n", count);
3995 hr = IScriptProcedure_get_HasReturnValue(proc, NULL);
3996 ok(hr == E_POINTER, "IScriptProcedure_get_HasReturnValue returned: 0x%08x.\n", hr);
3997 hr = IScriptProcedure_get_HasReturnValue(proc, &vbool);
3998 ok(hr == S_OK, "IScriptProcedure_get_HasReturnValue failed: 0x%08x.\n", hr);
3999 ok(vbool == VARIANT_TRUE, "HasReturnValue did not return True, got %x.\n", vbool);
4000 IScriptProcedure_Release(proc);
4002 V_VT(&var) = VT_BSTR;
4003 V_BSTR(&var) = SysAllocString(L"Nop");
4004 hr = IScriptProcedureCollection_get_Item(procs, var, &proc);
4005 ok(hr == S_OK, "IScriptProcedureCollection_get_Item failed: 0x%08x.\n", hr);
4006 ok(V_VT(&var) == VT_BSTR, "var type not BSTR, got %d.\n", V_VT(&var));
4007 VariantClear(&var);
4008 hr = IScriptProcedure_get_Name(proc, &str);
4009 ok(hr == S_OK, "IScriptProcedure_get_Name failed: 0x%08x.\n", hr);
4010 ok(!lstrcmpW(str, L"nop"), "Wrong name, got %s.\n", wine_dbgstr_w(str));
4011 SysFreeString(str);
4012 hr = IScriptProcedure_get_NumArgs(proc, &count);
4013 ok(hr == S_OK, "IScriptProcedure_get_NumArgs failed: 0x%08x.\n", hr);
4014 ok(count == 1, "Wrong NumArgs, got %d.\n", count);
4015 hr = IScriptProcedure_get_HasReturnValue(proc, &vbool);
4016 ok(hr == S_OK, "IScriptProcedure_get_HasReturnValue failed: 0x%08x.\n", hr);
4017 ok(vbool == VARIANT_TRUE, "HasReturnValue did not return True, got %x.\n", vbool);
4018 IScriptProcedure_Release(proc);
4020 V_VT(&var) = VT_R8;
4021 V_R8(&var) = 3.0;
4022 hr = IScriptProcedureCollection_get_Item(procs, var, &proc);
4023 ok(hr == S_OK, "IScriptProcedureCollection_get_Item failed: 0x%08x.\n", hr);
4024 hr = IScriptProcedure_get_Name(proc, &str);
4025 ok(hr == S_OK, "IScriptProcedure_get_Name failed: 0x%08x.\n", hr);
4026 ok(!lstrcmpW(str, L"muladd"), "Wrong name, got %s.\n", wine_dbgstr_w(str));
4027 SysFreeString(str);
4028 hr = IScriptProcedure_get_NumArgs(proc, &count);
4029 ok(hr == S_OK, "IScriptProcedure_get_NumArgs failed: 0x%08x.\n", hr);
4030 ok(count == 3, "Wrong NumArgs, got %d.\n", count);
4031 IScriptProcedure_Release(proc);
4033 IScriptProcedureCollection_Release(procs);
4034 IScriptControl_Release(sc);
4036 if (have_custom_engine)
4038 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
4039 &IID_IScriptControl, (void**)&sc);
4040 ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr);
4042 SET_EXPECT(CreateInstance);
4043 SET_EXPECT(SetInterfaceSafetyOptions);
4044 SET_EXPECT(SetScriptSite);
4045 SET_EXPECT(QI_IActiveScriptParse);
4046 SET_EXPECT(InitNew);
4048 str = SysAllocString(L"testscript");
4049 hr = IScriptControl_put_Language(sc, str);
4050 ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
4051 SysFreeString(str);
4053 CHECK_CALLED(CreateInstance);
4054 CHECK_CALLED(SetInterfaceSafetyOptions);
4055 CHECK_CALLED(SetScriptSite);
4056 CHECK_CALLED(QI_IActiveScriptParse);
4057 CHECK_CALLED(InitNew);
4059 hr = IScriptControl_get_Procedures(sc, &procs);
4060 ok(hr == S_OK, "IScriptControl_get_Procedures failed: 0x%08x.\n", hr);
4061 hr = IScriptControl_get_Procedures(sc, &procs2);
4062 ok(hr == S_OK, "IScriptControl_get_Procedures failed: 0x%08x.\n", hr);
4063 ok(procs == procs2, "Procedure collections are not the same (%p vs %p).\n", procs, procs2);
4064 IScriptProcedureCollection_Release(procs2);
4066 GetScriptDispatch_expected_name = NULL;
4067 SET_EXPECT(SetScriptState_STARTED);
4068 SET_EXPECT(GetScriptDispatch);
4069 SET_EXPECT(GetTypeInfo);
4070 SET_EXPECT(GetTypeAttr);
4071 SET_EXPECT(ReleaseTypeAttr);
4072 TypeInfo_GetTypeAttr_cFuncs = 1337;
4073 hr = IScriptProcedureCollection_get_Count(procs, &count);
4074 ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
4075 ok(count == 1337, "count is not 1337, got %d.\n", count);
4076 CHECK_CALLED(SetScriptState_STARTED);
4077 CHECK_CALLED(GetScriptDispatch);
4078 CHECK_CALLED(GetTypeInfo);
4079 CHECK_CALLED(GetTypeAttr);
4080 CHECK_CALLED(ReleaseTypeAttr);
4081 TypeInfo_GetTypeAttr_cFuncs = ARRAY_SIZE(custom_engine_funcs);
4082 count = 0;
4083 hr = IScriptProcedureCollection_get_Count(procs, &count);
4084 ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
4085 ok(count == 1337, "count is not 1337, got %d.\n", count);
4087 /* Reload the collection to update the cached function count */
4088 IScriptProcedureCollection_Release(procs);
4089 hr = IScriptControl_get_Procedures(sc, &procs);
4090 ok(hr == S_OK, "IScriptControl_get_Procedures failed: 0x%08x.\n", hr);
4091 count = 0;
4092 SET_EXPECT(GetTypeAttr);
4093 SET_EXPECT(ReleaseTypeAttr);
4094 hr = IScriptProcedureCollection_get_Count(procs, &count);
4095 ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
4096 ok(count == ARRAY_SIZE(custom_engine_funcs), "count is not %u, got %d.\n", TypeInfo_GetTypeAttr_cFuncs, count);
4097 CHECK_CALLED(GetTypeAttr);
4098 CHECK_CALLED(ReleaseTypeAttr);
4100 /* Adding code reloads the typeinfo the next time */
4101 SET_EXPECT(ParseScriptText);
4102 parse_item_name = NULL;
4103 parse_flags = SCRIPTTEXT_ISVISIBLE;
4104 str = SysAllocString(L" ");
4105 hr = IScriptControl_AddCode(sc, str);
4106 ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr);
4107 SysFreeString(str);
4108 CHECK_ERROR(sc, 0);
4109 CHECK_CALLED(ParseScriptText);
4111 GetScriptDispatch_expected_name = NULL;
4112 SET_EXPECT(GetScriptDispatch);
4113 SET_EXPECT(GetTypeInfo);
4114 SET_EXPECT(GetTypeAttr);
4115 SET_EXPECT(ReleaseTypeAttr);
4116 hr = IScriptProcedureCollection_get_Count(procs, &count);
4117 ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
4118 ok(count == ARRAY_SIZE(custom_engine_funcs), "count is not %u, got %d.\n", TypeInfo_GetTypeAttr_cFuncs, count);
4119 CHECK_CALLED(GetScriptDispatch);
4120 CHECK_CALLED(GetTypeInfo);
4121 CHECK_CALLED(GetTypeAttr);
4122 CHECK_CALLED(ReleaseTypeAttr);
4124 /* Reset uncaches the objects, but not the count */
4125 SET_EXPECT(SetScriptState_INITIALIZED);
4126 IScriptControl_Reset(sc);
4127 CHECK_CALLED(SetScriptState_INITIALIZED);
4128 count = 0;
4129 hr = IScriptProcedureCollection_get_Count(procs, &count);
4130 ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
4131 ok(count == ARRAY_SIZE(custom_engine_funcs), "count is not %u, got %d.\n", TypeInfo_GetTypeAttr_cFuncs, count);
4133 /* Try without ITypeComp interface */
4134 SET_EXPECT(SetScriptState_STARTED);
4135 SET_EXPECT(GetScriptDispatch);
4136 SET_EXPECT(GetTypeInfo);
4137 SET_EXPECT(QI_ITypeComp);
4138 V_VT(&var) = VT_BSTR;
4139 V_BSTR(&var) = SysAllocString(L"foobar");
4140 hr = IScriptProcedureCollection_get_Item(procs, var, &proc);
4141 ok(hr == E_NOINTERFACE, "IScriptProcedureCollection_get_Item returned: 0x%08x.\n", hr);
4142 ok(V_VT(&var) == VT_BSTR, "var type not BSTR, got %d.\n", V_VT(&var));
4143 VariantClear(&var);
4144 CHECK_CALLED(SetScriptState_STARTED);
4145 CHECK_CALLED(GetScriptDispatch);
4146 CHECK_CALLED(GetTypeInfo);
4147 CHECK_CALLED(QI_ITypeComp);
4149 count = 0;
4150 hr = IScriptProcedureCollection_get_Count(procs, &count);
4151 ok(hr == S_OK, "IScriptProcedureCollection_get_Count failed: 0x%08x.\n", hr);
4152 ok(count == ARRAY_SIZE(custom_engine_funcs), "count is not %u, got %d.\n", TypeInfo_GetTypeAttr_cFuncs, count);
4154 /* Make ITypeComp available */
4155 TypeComp_available = TRUE;
4156 SET_EXPECT(QI_ITypeComp);
4157 SET_EXPECT(Bind);
4158 V_VT(&var) = VT_BSTR;
4159 V_BSTR(&var) = SysAllocString(L"type_mismatch");
4160 hr = IScriptProcedureCollection_get_Item(procs, var, &proc);
4161 ok(hr == TYPE_E_TYPEMISMATCH, "IScriptProcedureCollection_get_Item returned: 0x%08x.\n", hr);
4162 VariantClear(&var);
4163 CHECK_CALLED(QI_ITypeComp);
4164 CHECK_CALLED(Bind);
4165 TypeComp_available = FALSE;
4167 SET_EXPECT(Bind);
4168 V_VT(&var) = VT_BSTR;
4169 V_BSTR(&var) = SysAllocString(L"not_found");
4170 hr = IScriptProcedureCollection_get_Item(procs, var, &proc);
4171 ok(hr == CTL_E_ILLEGALFUNCTIONCALL, "IScriptProcedureCollection_get_Item failed: 0x%08x.\n", hr);
4172 VariantClear(&var);
4173 CHECK_CALLED(Bind);
4175 SET_EXPECT(Bind);
4176 SET_EXPECT(ReleaseVarDesc);
4177 V_VT(&var) = VT_BSTR;
4178 V_BSTR(&var) = SysAllocString(L"variable");
4179 hr = IScriptProcedureCollection_get_Item(procs, var, &proc);
4180 ok(hr == CTL_E_ILLEGALFUNCTIONCALL, "IScriptProcedureCollection_get_Item failed: 0x%08x.\n", hr);
4181 VariantClear(&var);
4182 CHECK_CALLED(Bind);
4183 CHECK_CALLED(ReleaseVarDesc);
4185 /* Index 0 and below are invalid (doesn't even call GetFuncDesc) */
4186 V_VT(&var) = VT_I4;
4187 V_I4(&var) = 0;
4188 hr = IScriptProcedureCollection_get_Item(procs, var, &proc);
4189 ok(hr == 0x800a0009, "IScriptProcedureCollection_get_Item returned: 0x%08x.\n", hr);
4190 V_I4(&var) = -1;
4191 hr = IScriptProcedureCollection_get_Item(procs, var, &proc);
4192 ok(hr == 0x800a0009, "IScriptProcedureCollection_get_Item returned: 0x%08x.\n", hr);
4193 SET_EXPECT(GetFuncDesc);
4194 V_I4(&var) = 1337;
4195 hr = IScriptProcedureCollection_get_Item(procs, var, &proc);
4196 ok(hr == E_INVALIDARG, "IScriptProcedureCollection_get_Item returned: 0x%08x.\n", hr);
4197 CHECK_CALLED(GetFuncDesc);
4199 /* _NewEnum never caches the function count */
4200 hr = IScriptProcedureCollection_get__NewEnum(procs, NULL);
4201 ok(hr == E_POINTER, "IScriptProcedureCollection_get__NewEnum returned: 0x%08x.\n", hr);
4202 SET_EXPECT(GetTypeAttr);
4203 SET_EXPECT(ReleaseTypeAttr);
4204 hr = IScriptProcedureCollection_get__NewEnum(procs, &unknown);
4205 ok(hr == S_OK, "IScriptProcedureCollection_get__NewEnum failed: 0x%08x.\n", hr);
4206 CHECK_CALLED(GetTypeAttr);
4207 CHECK_CALLED(ReleaseTypeAttr);
4208 hr = IUnknown_QueryInterface(unknown, &IID_IEnumVARIANT, (void**)&enumvar);
4209 ok(hr == S_OK, "Failed to query for IEnumVARIANT: 0x%08x.\n", hr);
4210 ok((char*)unknown == (char*)enumvar, "unknown and enumvar are not the same (%p vs %p).\n", unknown, enumvar);
4211 IEnumVARIANT_Release(enumvar);
4212 IUnknown_Release(unknown);
4213 SET_EXPECT(GetTypeAttr);
4214 SET_EXPECT(ReleaseTypeAttr);
4215 hr = IScriptProcedureCollection_get__NewEnum(procs, &unknown);
4216 ok(hr == S_OK, "IScriptProcedureCollection_get__NewEnum failed: 0x%08x.\n", hr);
4217 CHECK_CALLED(GetTypeAttr);
4218 CHECK_CALLED(ReleaseTypeAttr);
4219 hr = IUnknown_QueryInterface(unknown, &IID_IEnumVARIANT, (void**)&enumvar);
4220 ok(hr == S_OK, "Failed to query for IEnumVARIANT: 0x%08x.\n", hr);
4221 IUnknown_Release(unknown);
4223 fetched = 0xdeadbeef;
4224 hr = IEnumVARIANT_Next(enumvar, 0, NULL, NULL);
4225 ok(hr == E_POINTER, "IEnumVARIANT_Next returned: 0x%08x.\n", hr);
4226 hr = IEnumVARIANT_Next(enumvar, 0, NULL, &fetched);
4227 ok(hr == E_POINTER, "IEnumVARIANT_Next failed: 0x%08x.\n", hr);
4228 ok(fetched == 0xdeadbeef, "got %u.\n", fetched);
4229 hr = IEnumVARIANT_Next(enumvar, 0, &var, &fetched);
4230 ok(hr == S_OK, "IEnumVARIANT_Next returned: 0x%08x.\n", hr);
4231 ok(fetched == 0, "got %u.\n", fetched);
4232 hr = IEnumVARIANT_Next(enumvar, 0, &var, NULL);
4233 ok(hr == S_OK, "IEnumVARIANT_Next returned: 0x%08x.\n", hr);
4234 hr = IEnumVARIANT_Clone(enumvar, NULL);
4235 ok(hr == E_POINTER, "IEnumVARIANT_Clone failed: 0x%08x.\n", hr);
4237 for (i = 0; i < ARRAY_SIZE(custom_engine_funcs); i++)
4239 /* Querying by index still goes through the Bind process */
4240 SET_EXPECT(GetFuncDesc);
4241 SET_EXPECT(GetNames);
4242 SET_EXPECT(ReleaseFuncDesc);
4243 V_VT(&var) = VT_R4;
4244 V_R4(&var) = i + 1;
4245 hr = IScriptProcedureCollection_get_Item(procs, var, &proc);
4246 ok(hr == S_OK, "get_Item for index %u failed: 0x%08x.\n", i, hr);
4247 CHECK_CALLED(GetFuncDesc);
4248 CHECK_CALLED(GetNames);
4249 CHECK_CALLED(ReleaseFuncDesc);
4251 /* The name is cached and not looked up with Bind anymore */
4252 V_VT(&var) = VT_BSTR;
4253 V_BSTR(&var) = SysAllocString(custom_engine_funcs[i].name);
4254 hr = IScriptProcedureCollection_get_Item(procs, var, &proc2);
4255 ok(hr == S_OK, "get_Item for %s failed: 0x%08x.\n", wine_dbgstr_w(custom_engine_funcs[i].name), hr);
4256 ok(proc == proc2, "proc and proc2 are not the same for %s and index %u.\n",
4257 wine_dbgstr_w(custom_engine_funcs[i].name), i + 1);
4258 IScriptProcedure_Release(proc);
4259 IScriptProcedure_Release(proc2);
4261 /* Since both were released, the cache entry is destroyed */
4262 SET_EXPECT(Bind);
4263 SET_EXPECT(GetNames);
4264 SET_EXPECT(ReleaseFuncDesc);
4265 hr = IScriptProcedureCollection_get_Item(procs, var, &proc);
4266 ok(hr == S_OK, "get_Item for %s failed: 0x%08x.\n", wine_dbgstr_w(custom_engine_funcs[i].name), hr);
4267 VariantClear(&var);
4268 CHECK_CALLED(Bind);
4269 CHECK_CALLED(GetNames);
4270 CHECK_CALLED(ReleaseFuncDesc);
4272 /* Compare with the enumerator */
4273 SET_EXPECT(GetFuncDesc);
4274 SET_EXPECT(GetNames);
4275 SET_EXPECT(ReleaseFuncDesc);
4276 hr = IEnumVARIANT_Next(enumvar, 1, &var, &fetched);
4277 ok(hr == S_OK, "IEnumVARIANT_Next for index %u failed: 0x%08x.\n", i, hr);
4278 ok(fetched == 1, "got %u.\n", fetched);
4279 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var) = %d.\n", V_VT(&var));
4280 CHECK_CALLED(GetFuncDesc);
4281 CHECK_CALLED(GetNames);
4282 CHECK_CALLED(ReleaseFuncDesc);
4283 hr = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IScriptProcedure, (void**)&proc2);
4284 ok(hr == S_OK, "Failed to query IScriptProcedure for index %u: 0x%08x.\n", i, hr);
4285 VariantClear(&var);
4287 ok(proc == proc2, "proc and proc2 are not the same for %s and enum index %u.\n",
4288 wine_dbgstr_w(custom_engine_funcs[i].name), i);
4289 IScriptProcedure_Release(proc2);
4291 /* Verify the properties */
4292 hr = IScriptProcedure_get_Name(proc, &str);
4293 ok(hr == S_OK, "get_Name for %s failed: 0x%08x.\n", wine_dbgstr_w(custom_engine_funcs[i].name), hr);
4294 ok(!lstrcmpW(str, custom_engine_funcs[i].name), "Name is not %s, got %s.\n",
4295 wine_dbgstr_w(custom_engine_funcs[i].name), wine_dbgstr_w(str));
4296 SysFreeString(str);
4297 hr = IScriptProcedure_get_NumArgs(proc, &count);
4298 ok(hr == S_OK, "get_NumArgs for %s failed: 0x%08x.\n", wine_dbgstr_w(custom_engine_funcs[i].name), hr);
4299 ok(count == custom_engine_funcs[i].num_args + custom_engine_funcs[i].num_opt_args,
4300 "NumArgs is not %d, got %d.\n", custom_engine_funcs[i].num_args + custom_engine_funcs[i].num_opt_args, count);
4301 hr = IScriptProcedure_get_HasReturnValue(proc, &vbool);
4302 ok(hr == S_OK, "get_HasReturnValue for %s failed: 0x%08x.\n", wine_dbgstr_w(custom_engine_funcs[i].name), hr);
4303 ok(vbool == ((custom_engine_funcs[i].ret_type == VT_VOID) ? VARIANT_FALSE : VARIANT_TRUE),
4304 "get_HasReturnValue for %s returned %x.\n", wine_dbgstr_w(custom_engine_funcs[i].name), vbool);
4306 IScriptProcedure_Release(proc);
4309 hr = IEnumVARIANT_Next(enumvar, 1, &var, &fetched);
4310 ok(hr == S_FALSE, "IEnumVARIANT_Next failed: 0x%08x.\n", hr);
4311 ok(fetched == 0, "got %u.\n", fetched);
4312 hr = IEnumVARIANT_Skip(enumvar, 0);
4313 ok(hr == S_OK, "IEnumVARIANT_Skip failed: 0x%08x.\n", hr);
4314 hr = IEnumVARIANT_Skip(enumvar, 1);
4315 ok(hr == S_FALSE, "IEnumVARIANT_Skip failed: 0x%08x.\n", hr);
4316 hr = IEnumVARIANT_Reset(enumvar);
4317 ok(hr == S_OK, "IEnumVARIANT_Reset failed: 0x%08x.\n", hr);
4318 hr = IEnumVARIANT_Skip(enumvar, ARRAY_SIZE(custom_engine_funcs) - 1);
4319 ok(hr == S_OK, "IEnumVARIANT_Skip failed: 0x%08x.\n", hr);
4320 hr = IEnumVARIANT_Clone(enumvar, &enumvar2);
4321 ok(hr == S_OK, "IEnumVARIANT_Clone failed: 0x%08x.\n", hr);
4322 hr = IEnumVARIANT_Skip(enumvar2, 1);
4323 ok(hr == S_OK, "IEnumVARIANT_Skip failed: 0x%08x.\n", hr);
4324 hr = IEnumVARIANT_Skip(enumvar2, 1);
4325 ok(hr == S_FALSE, "IEnumVARIANT_Skip failed: 0x%08x.\n", hr);
4327 IEnumVARIANT_Release(enumvar2);
4328 IEnumVARIANT_Release(enumvar);
4329 IScriptProcedureCollection_Release(procs);
4330 IActiveScriptSite_Release(site);
4332 SET_EXPECT(Close);
4333 IScriptControl_Release(sc);
4334 CHECK_CALLED(Close);
4338 START_TEST(msscript)
4340 IUnknown *unk;
4341 HRESULT hr;
4343 CoInitialize(NULL);
4345 hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
4346 &IID_IUnknown, (void**)&unk);
4347 if (FAILED(hr)) {
4348 win_skip("Could not create ScriptControl object: %08x\n", hr);
4349 return;
4351 IUnknown_Release(unk);
4353 have_custom_engine = register_script_engine();
4354 if (!have_custom_engine)
4355 skip("Could not register TestScript engine.\n");
4357 test_oleobject();
4358 test_persiststreaminit();
4359 test_olecontrol();
4360 test_Language();
4361 test_connectionpoints();
4362 test_quickactivate();
4363 test_viewobject();
4364 test_pointerinactive();
4365 test_timeout();
4366 test_Reset();
4367 test_AddObject();
4368 test_AllowUI();
4369 test_SitehWnd();
4370 test_UseSafeSubset();
4371 test_State();
4372 test_IScriptControl_Eval();
4373 test_IScriptControl_AddCode();
4374 test_IScriptControl_ExecuteStatement();
4375 test_IScriptControl_Run();
4376 test_IScriptControl_get_Modules();
4377 test_IScriptControl_get_Error();
4378 test_IScriptControl_get_CodeObject();
4379 test_IScriptControl_get_Procedures();
4381 init_registry(FALSE);
4383 CoUninitialize();