2 * Copyright 2019 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/test.h"
30 #include "wine/heap.h"
32 static HRESULT (WINAPI
*pDllInstall
)(BOOL
, const WCHAR
*);
34 static const CLSID CLSID_WineTest
= {0xa8a83483,0xa6ac,0x474d,{0xb2,0x2a,0x9a,0x5f,0x2d,0x68,0xcb,0x7f}};
35 #define CLSID_STR "{a8a83483-a6ac-474d-b22a-9a5f2d68cb7f}"
37 #define TESTSCRIPT_CLSID "{178fc164-f585-4e24-9c13-4bb7faf80746}"
38 static const GUID CLSID_TestScript
=
39 {0x178fc164,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x07,0x46}};
43 #define CTXARG_T DWORDLONG
44 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
45 #define IActiveScriptSiteDebug_Release IActiveScriptSiteDebug64_Release
49 #define CTXARG_T DWORD
50 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
51 #define IActiveScriptSiteDebug_Release IActiveScriptSiteDebug32_Release
55 #define DEFINE_EXPECT(func) \
56 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
58 #define SET_EXPECT(func) \
59 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
61 #define CHECK_EXPECT2(func) \
63 ok(expect_ ##func, "unexpected call " #func "\n"); \
64 called_ ## func = TRUE; \
67 #define CHECK_EXPECT(func) \
69 CHECK_EXPECT2(func); \
70 expect_ ## func = FALSE; \
73 #define CHECK_CALLED(func) \
75 ok(called_ ## func, "expected " #func "\n"); \
76 expect_ ## func = called_ ## func = FALSE; \
79 #define CHECK_CALLED_BROKEN(func) \
81 ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
82 expect_ ## func = called_ ## func = FALSE; \
85 #define CHECK_NOT_CALLED(func) \
87 ok(!called_ ## func, "unexpected " #func "\n"); \
88 expect_ ## func = called_ ## func = FALSE; \
91 #define CLEAR_CALLED(func) \
92 expect_ ## func = called_ ## func = FALSE
94 DEFINE_EXPECT(CreateInstance
);
95 DEFINE_EXPECT(InitNew
);
97 DEFINE_EXPECT(SetScriptSite
);
98 DEFINE_EXPECT(QI_IActiveScriptParse
);
99 DEFINE_EXPECT(SetScriptState_INITIALIZED
);
100 DEFINE_EXPECT(SetScriptState_UNINITIALIZED
);
101 DEFINE_EXPECT(SetScriptState_STARTED
);
102 DEFINE_EXPECT(AddNamedItem_scriptlet
);
103 DEFINE_EXPECT(AddNamedItem_globals
);
104 DEFINE_EXPECT(ParseScriptText
);
105 DEFINE_EXPECT(Clone
);
106 DEFINE_EXPECT(GetScriptDispatch
);
107 DEFINE_EXPECT(GetDispID_vbAddOne
);
108 DEFINE_EXPECT(GetDispID_wtTest
);
109 DEFINE_EXPECT(GetDispID_get_gsProp
);
110 DEFINE_EXPECT(GetDispID_put_gsProp
);
111 DEFINE_EXPECT(InvokeEx
);
112 DEFINE_EXPECT(InvokeEx_get_gsProp
);
113 DEFINE_EXPECT(InvokeEx_put_gsProp
);
115 #define DISPID_WTTEST 100
116 #define DISPID_GET_GSPROP 101
117 #define DISPID_PUT_GSPROP 102
119 static DWORD parse_flags
;
120 static BOOL support_clone
;
122 static IActiveScriptSite
*site
;
123 static SCRIPTSTATE state
;
125 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
129 if (IsEqualGUID(riid
, &IID_IUnknown
)
130 || IsEqualGUID(riid
, &IID_IDispatch
)
131 || IsEqualGUID(riid
, &IID_IDispatchEx
))
134 return E_NOINTERFACE
;
139 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
144 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
149 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
151 ok(0, "unexpected call\n");
155 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
156 LCID lcid
, ITypeInfo
**ppTInfo
)
161 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
162 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
164 ok(0, "unexpected call\n");
168 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
169 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
170 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
172 ok(0, "unexpected call\n");
176 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR name
, DWORD grfdex
, DISPID
*pid
)
178 if (!wcscmp(name
, L
"vbAddOne"))
180 CHECK_EXPECT(GetDispID_vbAddOne
);
181 ok(grfdex
== fdexNameCaseInsensitive
, "grfdex = %x\n", grfdex
);
182 return DISP_E_UNKNOWNNAME
;
184 if (!wcscmp(name
, L
"wtTest"))
186 CHECK_EXPECT(GetDispID_wtTest
);
187 ok(!grfdex
, "grfdex = %x\n", grfdex
);
188 *pid
= DISPID_WTTEST
;
191 if (!wcscmp(name
, L
"get_gsProp"))
193 CHECK_EXPECT(GetDispID_get_gsProp
);
194 ok(!grfdex
, "grfdex = %x\n", grfdex
);
195 *pid
= DISPID_GET_GSPROP
;
198 if (!wcscmp(name
, L
"put_gsProp"))
200 CHECK_EXPECT(GetDispID_put_gsProp
);
201 ok(!grfdex
, "grfdex = %x\n", grfdex
);
202 *pid
= DISPID_PUT_GSPROP
;
205 ok(0, "unexpected name %s\n", wine_dbgstr_w(name
));
206 return DISP_E_UNKNOWNNAME
;
209 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*pdp
,
210 VARIANT
*res
, EXCEPINFO
*pei
, IServiceProvider
*caller
)
215 CHECK_EXPECT(InvokeEx
);
216 ok(lcid
== 0x100, "lcid = %x\n", lcid
);
217 ok(flags
== DISPATCH_METHOD
, "flags = %x\n", flags
);
218 ok(caller
== (void*)0xdeadbeef, "called = %p\n", caller
);
220 V_BOOL(res
) = VARIANT_TRUE
;
222 case DISPID_GET_GSPROP
:
223 CHECK_EXPECT(InvokeEx_get_gsProp
);
224 ok(flags
== DISPATCH_METHOD
, "flags = %x\n", flags
);
225 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
227 V_BOOL(res
) = VARIANT_TRUE
;
229 case DISPID_PUT_GSPROP
:
230 CHECK_EXPECT(InvokeEx_put_gsProp
);
231 ok(flags
== DISPATCH_METHOD
, "flags = %x\n", flags
);
232 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
233 ok(pdp
->cNamedArgs
== 0, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
235 V_BOOL(res
) = VARIANT_FALSE
;
239 ok(0, "unexpected id %u\n", id
);
243 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR name
, DWORD grfdex
)
245 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(name
), grfdex
);
249 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
251 ok(0, "unexpected call\n");
255 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
257 ok(0, "unexpected call\n");
261 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*name
)
263 ok(0, "unexpected call\n");
267 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
269 ok(0, "unexpected call\n");
273 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
275 ok(0, "unexpected call\n");
279 static IDispatchExVtbl DispatchExVtbl
= {
280 DispatchEx_QueryInterface
,
283 DispatchEx_GetTypeInfoCount
,
284 DispatchEx_GetTypeInfo
,
285 DispatchEx_GetIDsOfNames
,
287 DispatchEx_GetDispID
,
289 DispatchEx_DeleteMemberByName
,
290 DispatchEx_DeleteMemberByDispID
,
291 DispatchEx_GetMemberProperties
,
292 DispatchEx_GetMemberName
,
293 DispatchEx_GetNextDispID
,
294 DispatchEx_GetNameSpaceParent
297 static IDispatchEx script_global
= { &DispatchExVtbl
};
299 static HRESULT WINAPI
ActiveScriptParse_QueryInterface(IActiveScriptParse
*iface
, REFIID riid
, void **ppv
)
302 ok(0, "unexpected call\n");
303 return E_NOINTERFACE
;
306 static ULONG WINAPI
ActiveScriptParse_AddRef(IActiveScriptParse
*iface
)
311 static ULONG WINAPI
ActiveScriptParse_Release(IActiveScriptParse
*iface
)
316 static HRESULT WINAPI
ActiveScriptParse_InitNew(IActiveScriptParse
*iface
)
318 CHECK_EXPECT(InitNew
);
322 static HRESULT WINAPI
ActiveScriptParse_AddScriptlet(IActiveScriptParse
*iface
,
323 LPCOLESTR pstrDefaultName
, LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
,
324 LPCOLESTR pstrSubItemName
, LPCOLESTR pstrEventName
, LPCOLESTR pstrDelimiter
,
325 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
,
326 BSTR
*pbstrName
, EXCEPINFO
*pexcepinfo
)
328 ok(0, "unexpected call\n");
332 static HRESULT WINAPI
ActiveScriptParse_ParseScriptText(IActiveScriptParse
*iface
,
333 LPCOLESTR code
, LPCOLESTR item_name
, IUnknown
*context
,
334 LPCOLESTR delimiter
, CTXARG_T dwSourceContextCookie
, ULONG ulStartingLine
,
335 DWORD flags
, VARIANT
*result
, EXCEPINFO
*excepinfo
)
337 CHECK_EXPECT(ParseScriptText
);
338 ok(!wcscmp(code
, L
"WTTest body"), "unexpected code %s\n", wine_dbgstr_w(code
));
339 ok(!item_name
, "pstrItemName = %s\n", wine_dbgstr_w(item_name
));
340 ok(!context
, "punkContext = %p\n", context
);
341 ok(!delimiter
, "pstrDelimiter = %s\n", wine_dbgstr_w(delimiter
));
342 ok(flags
== parse_flags
, "dwFlags = %x\n", flags
);
343 ok(!result
, "pvarResult = NULL\n");
344 ok(!excepinfo
, "pexcepinfo = %p\n", excepinfo
);
348 static const IActiveScriptParseVtbl ActiveScriptParseVtbl
= {
349 ActiveScriptParse_QueryInterface
,
350 ActiveScriptParse_AddRef
,
351 ActiveScriptParse_Release
,
352 ActiveScriptParse_InitNew
,
353 ActiveScriptParse_AddScriptlet
,
354 ActiveScriptParse_ParseScriptText
357 static IActiveScriptParse ActiveScriptParse
= { &ActiveScriptParseVtbl
};
359 static HRESULT WINAPI
ActiveScript_QueryInterface(IActiveScript
*iface
, REFIID riid
, void **ppv
)
361 if (IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IActiveScript
, riid
))
367 if (IsEqualGUID(&IID_IActiveScriptParse
, riid
))
369 CHECK_EXPECT(QI_IActiveScriptParse
);
370 *ppv
= &ActiveScriptParse
;
374 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid
));
376 return E_NOINTERFACE
;
379 static ULONG WINAPI
ActiveScript_AddRef(IActiveScript
*iface
)
384 static ULONG WINAPI
ActiveScript_Release(IActiveScript
*iface
)
389 static HRESULT WINAPI
ActiveScript_SetScriptSite(IActiveScript
*iface
, IActiveScriptSite
*pass
)
391 IActiveScriptSiteInterruptPoll
*poll
;
392 IActiveScriptSiteWindow
*window
;
393 IActiveScriptSiteDebug
*debug
;
394 IServiceProvider
*service
;
395 ICanHandleException
*canexception
;
399 CHECK_EXPECT(SetScriptSite
);
401 ok(pass
!= NULL
, "pass == NULL\n");
403 hres
= IActiveScriptSite_QueryInterface(pass
, &IID_IActiveScriptSiteInterruptPoll
, (void**)&poll
);
404 ok(hres
== E_NOINTERFACE
, "Got IActiveScriptSiteInterruptPoll interface: %08x\n", hres
);
406 hres
= IActiveScriptSite_GetLCID(pass
, &lcid
);
407 ok(hres
== S_OK
, "GetLCID failed: %08x\n", hres
);
409 hres
= IActiveScriptSite_OnStateChange(pass
, (state
= SCRIPTSTATE_INITIALIZED
));
410 ok(hres
== E_NOTIMPL
, "OnStateChange failed: %08x\n", hres
);
412 hres
= IActiveScriptSite_QueryInterface(pass
, &IID_IActiveScriptSiteDebug
, (void**)&debug
);
414 ok(hres
== S_OK
, "IActiveScriptSiteDebug not supported: %08x\n", hres
);
416 IActiveScriptSiteDebug_Release(debug
);
418 hres
= IActiveScriptSite_QueryInterface(pass
, &IID_ICanHandleException
, (void**)&canexception
);
419 ok(hres
== E_NOINTERFACE
, "Got IID_ICanHandleException interface: %08x\n", hres
);
421 hres
= IActiveScriptSite_QueryInterface(pass
, &IID_IServiceProvider
, (void**)&service
);
422 ok(hres
== S_OK
, "Could not get IServiceProvider interface: %08x\n", hres
);
424 IServiceProvider_Release(service
);
426 hres
= IActiveScriptSite_QueryInterface(pass
, &IID_IActiveScriptSiteWindow
, (void**)&window
);
427 ok(hres
== S_OK
, "Could not get IActiveScriptSiteWindow interface: %08x\n", hres
);
429 IActiveScriptSiteWindow_Release(window
);
432 IActiveScriptSite_Release(site
);
434 IActiveScriptSite_AddRef(site
);
439 static HRESULT WINAPI
ActiveScript_GetScriptSite(IActiveScript
*iface
, REFIID riid
, void **ppv
)
441 ok(0, "unexpected call\n");
445 static HRESULT WINAPI
ActiveScript_SetScriptState(IActiveScript
*iface
, SCRIPTSTATE ss
)
449 case SCRIPTSTATE_INITIALIZED
:
450 CHECK_EXPECT(SetScriptState_INITIALIZED
);
452 case SCRIPTSTATE_UNINITIALIZED
:
453 CHECK_EXPECT(SetScriptState_UNINITIALIZED
);
455 case SCRIPTSTATE_STARTED
:
456 CHECK_EXPECT(SetScriptState_STARTED
);
459 ok(0, "unexpected call, state %u\n", ss
);
465 static HRESULT WINAPI
ActiveScript_GetScriptState(IActiveScript
*iface
, SCRIPTSTATE
*pssState
)
467 ok(0, "unexpected call\n");
471 static HRESULT WINAPI
ActiveScript_Close(IActiveScript
*iface
)
476 IActiveScriptSite_Release(site
);
482 static HRESULT WINAPI
ActiveScript_AddNamedItem(IActiveScript
*iface
, LPCOLESTR name
, DWORD flags
)
484 if (!wcscmp(name
, L
"scriptlet"))
486 CHECK_EXPECT(AddNamedItem_scriptlet
);
487 ok(flags
== (SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_GLOBALMEMBERS
), "got flags %#x\n", flags
);
489 else if (!wcscmp(name
, L
"globals"))
491 CHECK_EXPECT(AddNamedItem_globals
);
492 ok(flags
== SCRIPTITEM_ISVISIBLE
, "got flags %#x\n", flags
);
496 ok(0, "got name %s\n", wine_dbgstr_w(name
));
502 static HRESULT WINAPI
ActiveScript_AddTypeLib(IActiveScript
*iface
, REFGUID rguidTypeLib
,
503 DWORD dwMajor
, DWORD dwMinor
, DWORD dwFlags
)
505 ok(0, "unexpected call\n");
509 static HRESULT WINAPI
ActiveScript_GetScriptDispatch(IActiveScript
*iface
, LPCOLESTR item_name
,
512 CHECK_EXPECT(GetScriptDispatch
);
513 ok(!item_name
, "item name %s\n", wine_dbgstr_w(item_name
));
514 IDispatch_AddRef(*ppdisp
= (IDispatch
*)&script_global
);
518 static HRESULT WINAPI
ActiveScript_GetCurrentScriptThreadID(IActiveScript
*iface
,
519 SCRIPTTHREADID
*pstridThread
)
521 ok(0, "unexpected call\n");
525 static HRESULT WINAPI
ActiveScript_GetScriptThreadID(IActiveScript
*iface
,
526 DWORD dwWin32ThreadId
, SCRIPTTHREADID
*pstidThread
)
528 ok(0, "unexpected call\n");
532 static HRESULT WINAPI
ActiveScript_GetScriptThreadState(IActiveScript
*iface
,
533 SCRIPTTHREADID stidThread
, SCRIPTTHREADSTATE
*pstsState
)
535 ok(0, "unexpected call\n");
539 static HRESULT WINAPI
ActiveScript_InterruptScriptThread(IActiveScript
*iface
,
540 SCRIPTTHREADID stidThread
, const EXCEPINFO
*pexcepinfo
, DWORD dwFlags
)
542 ok(0, "unexpected call\n");
546 static HRESULT WINAPI
ActiveScript_Clone(IActiveScript
*iface
, IActiveScript
**ppscript
)
556 if (parse_flags
== SCRIPTTEXT_ISVISIBLE
) return E_NOTIMPL
;
558 CHECK_CALLED(CreateInstance
);
559 CHECK_CALLED(QI_IActiveScriptParse
);
560 CHECK_CALLED(InitNew
);
561 CHECK_CALLED(SetScriptSite
);
562 CHECK_CALLED(ParseScriptText
);
563 CHECK_CALLED(SetScriptState_UNINITIALIZED
);
565 SET_EXPECT(CreateInstance
);
566 SET_EXPECT(QI_IActiveScriptParse
);
568 SET_EXPECT(SetScriptSite
);
569 SET_EXPECT(AddNamedItem_scriptlet
);
570 SET_EXPECT(AddNamedItem_globals
);
571 SET_EXPECT(GetScriptDispatch
);
572 SET_EXPECT(GetDispID_vbAddOne
);
573 SET_EXPECT(GetDispID_wtTest
);
574 SET_EXPECT(GetDispID_get_gsProp
);
575 SET_EXPECT(GetDispID_put_gsProp
);
576 SET_EXPECT(SetScriptState_STARTED
);
577 SET_EXPECT(ParseScriptText
);
579 parse_flags
= SCRIPTTEXT_ISVISIBLE
;
583 static const IActiveScriptVtbl ActiveScriptVtbl
= {
584 ActiveScript_QueryInterface
,
586 ActiveScript_Release
,
587 ActiveScript_SetScriptSite
,
588 ActiveScript_GetScriptSite
,
589 ActiveScript_SetScriptState
,
590 ActiveScript_GetScriptState
,
592 ActiveScript_AddNamedItem
,
593 ActiveScript_AddTypeLib
,
594 ActiveScript_GetScriptDispatch
,
595 ActiveScript_GetCurrentScriptThreadID
,
596 ActiveScript_GetScriptThreadID
,
597 ActiveScript_GetScriptThreadState
,
598 ActiveScript_InterruptScriptThread
,
602 static IActiveScript ActiveScript
= { &ActiveScriptVtbl
};
604 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
608 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IClassFactory
, riid
)) {
613 if(IsEqualGUID(&IID_IMarshal
, riid
) || IsEqualGUID(&IID_IClassFactoryEx
, riid
))
614 return E_NOINTERFACE
;
616 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid
));
617 return E_NOINTERFACE
;
620 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
625 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
630 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **ppv
)
632 CHECK_EXPECT(CreateInstance
);
634 ok(!outer
, "outer = %p\n", outer
);
635 ok(IsEqualGUID(&IID_IUnknown
, riid
), "unexpected riid %s\n", wine_dbgstr_guid(riid
));
636 *ppv
= &ActiveScript
;
640 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
642 ok(0, "unexpected call\n");
646 static const IClassFactoryVtbl ClassFactoryVtbl
= {
647 ClassFactory_QueryInterface
,
649 ClassFactory_Release
,
650 ClassFactory_CreateInstance
,
651 ClassFactory_LockServer
654 static IClassFactory script_cf
= { &ClassFactoryVtbl
};
656 static BOOL
init_key(const char *key_name
, const char *def_value
, BOOL init
)
662 RegDeleteKeyA(HKEY_CLASSES_ROOT
, key_name
);
666 res
= RegCreateKeyA(HKEY_CLASSES_ROOT
, key_name
, &hkey
);
667 if(res
!= ERROR_SUCCESS
)
671 res
= RegSetValueA(hkey
, NULL
, REG_SZ
, def_value
, strlen(def_value
));
675 return res
== ERROR_SUCCESS
;
678 static BOOL
register_script_engine(BOOL init
)
683 if (!init_key("WTScript\\CLSID", TESTSCRIPT_CLSID
, init
)) return FALSE
;
684 if (!init
) return TRUE
;
686 hres
= CoRegisterClassObject(&CLSID_TestScript
, (IUnknown
*)&script_cf
,
687 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, ®id
);
688 ok(hres
== S_OK
, "Could not register script engine: %08x\n", hres
);
692 static WCHAR
*get_test_file(const char *res_name
)
694 WCHAR path
[MAX_PATH
], buffer
[MAX_PATH
], *ret
;
701 src
= FindResourceA(NULL
, res_name
, (const char *)40);
702 ok(src
!= NULL
, "Could not find resource %s\n", res_name
);
703 size
= SizeofResource(NULL
, src
);
704 data
= LoadResource(NULL
, src
);
706 GetTempPathW(ARRAY_SIZE(path
), path
);
707 GetTempFileNameW(path
, L
"wsc", 0, buffer
);
708 handle
= CreateFileW(buffer
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
709 ok(handle
!= INVALID_HANDLE_VALUE
, "failed to create temp file\n");
711 res
= WriteFile(handle
, data
, size
, &size
, NULL
);
712 ok(res
, "WriteFile failed: %u\n", GetLastError());
714 res
= CloseHandle(handle
);
715 ok(res
, "CloseHandle failed: %u\n", GetLastError());
717 size
= (wcslen(buffer
) + 1) * sizeof(WCHAR
);
718 ret
= heap_alloc(size
);
719 memcpy(ret
, buffer
, size
);
723 #define test_key_value(a,b) test_key_value_(a,b,__LINE__)
724 static void test_key_value_(const char *key_name
, const char *expect
, unsigned line
)
727 LONG size
= sizeof(buf
);
729 status
= RegQueryValueA(HKEY_CLASSES_ROOT
, key_name
, buf
, &size
);
730 ok_(__FILE__
,line
)(!status
, "RegQueryValueA failed: %u\n", status
);
732 ok_(__FILE__
,line
)(size
>= strlen(expect
) + 1 && !strcmp(buf
+ size
- strlen(expect
), expect
+ 1),
733 "Unexpected value \"%s\", expected \"%s\"\n", buf
, expect
);
735 ok_(__FILE__
,line
)(size
== strlen(expect
) + 1 && !memicmp(buf
, expect
, size
),
736 "Unexpected value \"%s\", expected \"%s\"\n", buf
, expect
);
739 static void test_key_deleted(const char *key_name
)
743 status
= RegOpenKeyA(HKEY_CLASSES_ROOT
, key_name
, &key
);
744 ok(status
== ERROR_FILE_NOT_FOUND
, "RegOpenKey(\"%s\") returned %u\n", key_name
, status
);
747 static void register_script_object(BOOL do_register
, const WCHAR
*file_name
)
751 parse_flags
= SCRIPTTEXT_ISPERSISTENT
| SCRIPTTEXT_ISVISIBLE
;
753 SET_EXPECT(CreateInstance
);
754 SET_EXPECT(QI_IActiveScriptParse
);
756 SET_EXPECT(SetScriptSite
);
757 SET_EXPECT(ParseScriptText
);
758 SET_EXPECT(SetScriptState_UNINITIALIZED
);
760 hres
= pDllInstall(do_register
, file_name
);
761 CHECK_CALLED(CreateInstance
);
762 CHECK_CALLED(QI_IActiveScriptParse
);
763 CHECK_CALLED(InitNew
);
764 CHECK_CALLED(SetScriptSite
);
765 CHECK_CALLED(ParseScriptText
);
766 CHECK_CALLED(SetScriptState_UNINITIALIZED
);
768 ok(hres
== S_OK
, "DllInstall failed: %08x\n", hres
);
772 test_key_value("CLSID\\" CLSID_STR
, "WineTest object");
773 test_key_value("CLSID\\" CLSID_STR
"\\InprocServer32", "*\\scrobj.dll");
774 test_key_value("CLSID\\" CLSID_STR
"\\ProgID", "WineTest.1.23");
775 test_key_value("CLSID\\" CLSID_STR
"\\VersionIndependentProgID", "WineTest");
776 test_key_value("WineTest", "WineTest object");
777 test_key_value("WineTest\\CLSID", CLSID_STR
);
778 test_key_value("WineTest.1.23", "WineTest object");
779 test_key_value("WineTest.1.23\\CLSID", CLSID_STR
);
783 test_key_deleted("CLSID\\" CLSID_STR
);
784 test_key_deleted("WineTest");
785 test_key_deleted("WineTest.1.23");
789 static void test_create_object(void)
791 DISPID vb_add_one_id
, js_add_two_id
, wt_test_id
, wt_gsprop_id
, id
;
792 DISPID id_propput
= DISPID_PROPERTYPUT
;
803 hres
= CoGetClassObject(&CLSID_WineTest
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
, NULL
,
804 &IID_IClassFactory
, (void**)&cf
);
805 ok(hres
== S_OK
, "Could not get class factory: %08x\n", hres
);
807 parse_flags
= SCRIPTTEXT_ISPERSISTENT
| SCRIPTTEXT_ISVISIBLE
;
809 /* CreateInstance creates two script engine instances. The first one is for validation
810 * and is created once per class factry. Then, when object instance is created, it tries
811 * to clone that or create a new instance from scratch.
812 * We don't implement Clone in tests, but we use it to check already called functions
813 * and set new expected once.
815 SET_EXPECT(CreateInstance
);
816 SET_EXPECT(QI_IActiveScriptParse
);
818 SET_EXPECT(SetScriptSite
);
819 SET_EXPECT(ParseScriptText
);
820 SET_EXPECT(SetScriptState_UNINITIALIZED
);
822 hres
= IClassFactory_CreateInstance(cf
, NULL
, &IID_IUnknown
, (void**)&unk
);
823 ok(hres
== S_OK
, "Could not create scriptlet instance: %08x\n", hres
);
825 CHECK_CALLED(CreateInstance
);
826 CHECK_CALLED(QI_IActiveScriptParse
);
827 CHECK_CALLED(InitNew
);
828 CHECK_CALLED(SetScriptSite
);
829 CHECK_CALLED(AddNamedItem_scriptlet
);
830 CHECK_CALLED(AddNamedItem_globals
);
831 CHECK_CALLED(GetScriptDispatch
);
833 CHECK_CALLED(GetDispID_vbAddOne
);
834 CHECK_CALLED(GetDispID_wtTest
);
835 CHECK_CALLED(GetDispID_get_gsProp
);
836 CHECK_CALLED(GetDispID_put_gsProp
);
837 CHECK_CALLED(SetScriptState_STARTED
);
838 CHECK_CALLED(ParseScriptText
);
840 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)&disp
);
841 ok(hres
== S_OK
, "Could not get IDispatch iface: %08x\n", hres
);
843 IDispatch_Release(disp
);
845 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatchEx
, (void**)&dispex
);
846 ok(hres
== S_OK
, "Could not get IDispatch iface: %08x\n", hres
);
848 str
= SysAllocString(L
"vbAddOne");
849 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseSensitive
, &vb_add_one_id
);
850 ok(hres
== S_OK
, "Could not get vkAddOne id: %08x\n", hres
);
853 str
= SysAllocString(L
"jsAddTwo");
854 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseSensitive
, &js_add_two_id
);
855 ok(hres
== S_OK
, "Could not get jsAddTwo id: %08x\n", hres
);
858 str
= SysAllocString(L
"wtTest");
859 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseSensitive
, &wt_test_id
);
860 ok(hres
== S_OK
, "Could not get wtTest id: %08x\n", hres
);
863 str
= SysAllocString(L
"gsProp");
864 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseSensitive
, &wt_gsprop_id
);
865 ok(hres
== S_OK
, "Could not get wtTest id: %08x\n", hres
);
868 str
= SysAllocString(L
"vbaddone");
869 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseSensitive
, &id
);
870 ok(hres
== DISP_E_UNKNOWNNAME
, "invalid case returned: %08x\n", hres
);
873 str
= SysAllocString(L
"vbaddone");
874 hres
= IDispatchEx_GetDispID(dispex
, str
, 0, &id
);
875 ok(hres
== DISP_E_UNKNOWNNAME
, "invalid case returned: %08x\n", hres
);
878 str
= SysAllocString(L
"vbaddone");
879 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseInsensitive
, &id
);
880 ok(hres
== S_OK
, "case insensitive returned: %08x\n", hres
);
881 ok(id
== vb_add_one_id
, "id = %u, expected %u\n", id
, vb_add_one_id
);
884 memset(&ei
, 0, sizeof(ei
));
885 memset(&dp
, 0, sizeof(dp
));
891 hres
= IDispatchEx_InvokeEx(dispex
, vb_add_one_id
, 0, DISPATCH_PROPERTYGET
|DISPATCH_METHOD
, &dp
, &r
, &ei
, NULL
);
892 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
893 ok(V_VT(&r
) == VT_I4
, "V_VT(r) = %d\n", V_VT(&r
));
894 ok(V_I4(&r
) == 3, "V_I4(r) = %d\n", V_I4(&r
));
896 memset(&ei
, 0, sizeof(ei
));
897 memset(&dp
, 0, sizeof(dp
));
903 hres
= IDispatchEx_InvokeEx(dispex
, js_add_two_id
, 0, DISPATCH_PROPERTYGET
|DISPATCH_METHOD
, &dp
, &r
, &ei
, NULL
);
904 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
905 ok(V_VT(&r
) == VT_I4
, "V_VT(r) = %d\n", V_VT(&r
));
906 ok(V_I4(&r
) == 6, "V_I4(r) = %d\n", V_I4(&r
));
908 memset(&ei
, 0, sizeof(ei
));
909 memset(&dp
, 0, sizeof(dp
));
915 SET_EXPECT(InvokeEx
);
916 hres
= IDispatchEx_InvokeEx(dispex
, wt_test_id
, 0x100, DISPATCH_PROPERTYGET
|DISPATCH_METHOD
, &dp
, &r
, &ei
, (void*)0xdeadbeef);
917 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
918 CHECK_CALLED(InvokeEx
);
919 ok(V_VT(&r
) == VT_BOOL
, "V_VT(r) = %d\n", V_VT(&r
));
920 ok(V_BOOL(&r
) == VARIANT_TRUE
, "V_I4(r) = %d\n", V_I4(&r
));
922 memset(&ei
, 0, sizeof(ei
));
923 memset(&dp
, 0, sizeof(dp
));
925 SET_EXPECT(InvokeEx
);
926 hres
= IDispatchEx_InvokeEx(dispex
, wt_test_id
, 0x100, DISPATCH_METHOD
, &dp
, &r
, &ei
, (void*)0xdeadbeef);
927 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
928 CHECK_CALLED(InvokeEx
);
929 ok(V_VT(&r
) == VT_BOOL
, "V_VT(r) = %d\n", V_VT(&r
));
930 ok(V_BOOL(&r
) == VARIANT_TRUE
, "V_I4(r) = %d\n", V_I4(&r
));
932 memset(&ei
, 0, sizeof(ei
));
933 memset(&dp
, 0, sizeof(dp
));
939 SET_EXPECT(InvokeEx_get_gsProp
);
940 hres
= IDispatchEx_InvokeEx(dispex
, wt_gsprop_id
, 0, DISPATCH_PROPERTYGET
|DISPATCH_METHOD
, &dp
, &r
, &ei
, NULL
);
941 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
942 CHECK_CALLED(InvokeEx_get_gsProp
);
943 ok(V_VT(&r
) == VT_BOOL
, "V_VT(r) = %d\n", V_VT(&r
));
944 ok(V_BOOL(&r
) == VARIANT_TRUE
, "V_I4(r) = %d\n", V_I4(&r
));
946 memset(&ei
, 0, sizeof(ei
));
947 memset(&dp
, 0, sizeof(dp
));
952 dp
.rgdispidNamedArgs
= &id_propput
;
955 SET_EXPECT(InvokeEx_put_gsProp
);
956 hres
= IDispatchEx_InvokeEx(dispex
, wt_gsprop_id
, 0, DISPATCH_PROPERTYPUT
, &dp
, &r
, &ei
, NULL
);
957 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
958 CHECK_CALLED(InvokeEx_put_gsProp
);
959 ok(V_VT(&r
) == VT_BOOL
, "V_VT(r) = %d\n", V_VT(&r
));
960 ok(V_BOOL(&r
) == VARIANT_FALSE
, "V_I4(r) = %d\n", V_I4(&r
));
962 hres
= IDispatchEx_InvokeEx(dispex
, wt_test_id
, 0x100, DISPATCH_PROPERTYGET
, &dp
, &r
, &ei
, (void*)0xdeadbeef);
963 ok(hres
== DISP_E_MEMBERNOTFOUND
, "InvokeEx returned: %08x\n", hres
);
965 hres
= IDispatchEx_InvokeEx(dispex
, 0xdeadbeef, 0, DISPATCH_METHOD
, &dp
, &r
, &ei
, (void*)0xdeadbeef);
966 ok(hres
== DISP_E_MEMBERNOTFOUND
, "InvokeEx returned: %08x\n", hres
);
968 hres
= IDispatchEx_InvokeEx(dispex
, DISPID_VALUE
, 0, DISPATCH_METHOD
, &dp
, &r
, &ei
, (void*)0xdeadbeef);
969 ok(hres
== DISP_E_MEMBERNOTFOUND
, "InvokeEx returned: %08x\n", hres
);
971 IDispatchEx_Release(dispex
);
973 SET_EXPECT(SetScriptState_UNINITIALIZED
);
975 IUnknown_Release(unk
);
976 CHECK_CALLED(SetScriptState_UNINITIALIZED
);
979 parse_flags
= SCRIPTTEXT_ISVISIBLE
;
982 SET_EXPECT(CreateInstance
);
983 SET_EXPECT(QI_IActiveScriptParse
);
985 SET_EXPECT(SetScriptSite
);
986 SET_EXPECT(AddNamedItem_scriptlet
);
987 SET_EXPECT(AddNamedItem_globals
);
988 SET_EXPECT(GetScriptDispatch
);
989 SET_EXPECT(GetDispID_vbAddOne
);
990 SET_EXPECT(GetDispID_wtTest
);
991 SET_EXPECT(GetDispID_get_gsProp
);
992 SET_EXPECT(GetDispID_put_gsProp
);
993 SET_EXPECT(SetScriptState_STARTED
);
994 SET_EXPECT(ParseScriptText
);
995 hres
= IClassFactory_CreateInstance(cf
, NULL
, &IID_IUnknown
, (void**)&unk
);
996 ok(hres
== S_OK
, "Could not create scriptlet instance: %08x\n", hres
);
998 CHECK_CALLED(CreateInstance
);
999 CHECK_CALLED(QI_IActiveScriptParse
);
1000 CHECK_CALLED(InitNew
);
1001 CHECK_CALLED(SetScriptSite
);
1002 CHECK_CALLED(AddNamedItem_scriptlet
);
1003 CHECK_CALLED(AddNamedItem_globals
);
1004 CHECK_CALLED(GetScriptDispatch
);
1006 CHECK_CALLED(GetDispID_vbAddOne
);
1007 CHECK_CALLED(GetDispID_wtTest
);
1008 CHECK_CALLED(GetDispID_get_gsProp
);
1009 CHECK_CALLED(GetDispID_put_gsProp
);
1010 CHECK_CALLED(SetScriptState_STARTED
);
1011 CHECK_CALLED(ParseScriptText
);
1013 SET_EXPECT(SetScriptState_UNINITIALIZED
);
1015 IUnknown_Release(unk
);
1016 CHECK_CALLED(SetScriptState_UNINITIALIZED
);
1017 CHECK_CALLED(Close
);
1019 support_clone
= TRUE
;
1021 SET_EXPECT(QI_IActiveScriptParse
);
1022 SET_EXPECT(SetScriptSite
);
1023 SET_EXPECT(AddNamedItem_scriptlet
);
1024 SET_EXPECT(AddNamedItem_globals
);
1025 SET_EXPECT(GetScriptDispatch
);
1026 SET_EXPECT(GetDispID_vbAddOne
);
1027 SET_EXPECT(GetDispID_wtTest
);
1028 SET_EXPECT(GetDispID_get_gsProp
);
1029 SET_EXPECT(GetDispID_put_gsProp
);
1030 SET_EXPECT(SetScriptState_STARTED
);
1031 hres
= IClassFactory_CreateInstance(cf
, NULL
, &IID_IUnknown
, (void**)&unk
);
1032 ok(hres
== S_OK
, "Could not create scriptlet instance: %08x\n", hres
);
1033 CHECK_CALLED(Clone
);
1034 CHECK_CALLED(QI_IActiveScriptParse
);
1035 CHECK_CALLED(SetScriptSite
);
1036 CHECK_CALLED(AddNamedItem_scriptlet
);
1037 CHECK_CALLED(AddNamedItem_globals
);
1038 CHECK_CALLED(GetScriptDispatch
);
1040 CHECK_CALLED(GetDispID_vbAddOne
);
1041 CHECK_CALLED(GetDispID_wtTest
);
1042 CHECK_CALLED(GetDispID_get_gsProp
);
1043 CHECK_CALLED(GetDispID_put_gsProp
);
1044 CHECK_CALLED(SetScriptState_STARTED
);
1046 SET_EXPECT(SetScriptState_UNINITIALIZED
);
1048 IUnknown_Release(unk
);
1049 CHECK_CALLED(SetScriptState_UNINITIALIZED
);
1050 CHECK_CALLED(Close
);
1053 IClassFactory_Release(cf
);
1054 CHECK_CALLED(Close
);
1059 HMODULE scrobj_module
;
1063 hres
= CoInitialize(NULL
);
1064 ok(hres
== S_OK
, "CoInitialize failed: %08x\n", hres
);
1066 scrobj_module
= LoadLibraryA("scrobj.dll");
1067 ok(scrobj_module
!= NULL
, "Could not load scrobj.dll\n");
1069 pDllInstall
= (void *)GetProcAddress(scrobj_module
, "DllInstall");
1070 ok(pDllInstall
!= NULL
, "DllInstall not found in scrobj.dll\n");
1072 if (register_script_engine(TRUE
))
1074 test_file
= get_test_file("scrobj.wsc");
1076 register_script_object(TRUE
, test_file
);
1077 test_create_object();
1078 register_script_object(FALSE
, test_file
);
1080 register_script_engine(FALSE
);
1081 heap_free(test_file
);
1084 skip("Could not register script engine\n");