2 * Copyright 2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/test.h"
32 #define IActiveScriptParse_QueryInterface IActiveScriptParse64_QueryInterface
33 #define IActiveScriptParse_Release IActiveScriptParse64_Release
34 #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
35 #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
36 #define IActiveScriptParseProcedure2_Release \
37 IActiveScriptParseProcedure2_64_Release
41 #define IActiveScriptParse_QueryInterface IActiveScriptParse32_QueryInterface
42 #define IActiveScriptParse_Release IActiveScriptParse32_Release
43 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
44 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
45 #define IActiveScriptParseProcedure2_Release \
46 IActiveScriptParseProcedure2_32_Release
50 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
52 #define DEFINE_EXPECT(func) \
53 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
55 #define SET_EXPECT(func) \
56 expect_ ## func = TRUE
58 #define CHECK_EXPECT2(func) \
60 ok(expect_ ##func, "unexpected call " #func "\n"); \
61 called_ ## func = TRUE; \
64 #define CHECK_EXPECT(func) \
66 CHECK_EXPECT2(func); \
67 expect_ ## func = FALSE; \
70 #define CHECK_CALLED(func) \
72 ok(called_ ## func, "expected " #func "\n"); \
73 expect_ ## func = called_ ## func = FALSE; \
76 DEFINE_EXPECT(GetLCID);
77 DEFINE_EXPECT(OnStateChange_UNINITIALIZED);
78 DEFINE_EXPECT(OnStateChange_STARTED);
79 DEFINE_EXPECT(OnStateChange_CONNECTED);
80 DEFINE_EXPECT(OnStateChange_DISCONNECTED);
81 DEFINE_EXPECT(OnStateChange_CLOSED);
82 DEFINE_EXPECT(OnStateChange_INITIALIZED);
83 DEFINE_EXPECT(OnEnterScript);
84 DEFINE_EXPECT(OnLeaveScript);
86 DEFINE_GUID(CLSID_VBScript, 0xb54f3741, 0x5b07, 0x11cf, 0xa4,0xb0, 0x00,0xaa,0x00,0x4a,0x55,0xe8);
88 static BSTR a2bstr(const char *str)
93 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
94 ret = SysAllocStringLen(NULL, len-1);
95 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
100 #define test_state(s,ss) _test_state(__LINE__,s,ss)
101 static void _test_state(unsigned line, IActiveScript *script, SCRIPTSTATE exstate)
103 SCRIPTSTATE state = -1;
106 hres = IActiveScript_GetScriptState(script, &state);
107 ok_(__FILE__,line) (hres == S_OK, "GetScriptState failed: %08x\n", hres);
108 ok_(__FILE__,line) (state == exstate, "state=%d, expected %d\n", state, exstate);
111 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
115 if(IsEqualGUID(&IID_IUnknown, riid))
117 else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
120 return E_NOINTERFACE;
122 IUnknown_AddRef((IUnknown*)*ppv);
126 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
131 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
136 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
138 CHECK_EXPECT(GetLCID);
142 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
143 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
145 ok(0, "unexpected call\n");
149 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
151 ok(0, "unexpected call\n");
155 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
156 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
158 ok(0, "unexpected call\n");
162 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
164 switch(ssScriptState) {
165 case SCRIPTSTATE_UNINITIALIZED:
166 CHECK_EXPECT(OnStateChange_UNINITIALIZED);
168 case SCRIPTSTATE_STARTED:
169 CHECK_EXPECT(OnStateChange_STARTED);
171 case SCRIPTSTATE_CONNECTED:
172 CHECK_EXPECT(OnStateChange_CONNECTED);
174 case SCRIPTSTATE_DISCONNECTED:
175 CHECK_EXPECT(OnStateChange_DISCONNECTED);
177 case SCRIPTSTATE_CLOSED:
178 CHECK_EXPECT(OnStateChange_CLOSED);
180 case SCRIPTSTATE_INITIALIZED:
181 CHECK_EXPECT(OnStateChange_INITIALIZED);
184 ok(0, "unexpected call %d\n", ssScriptState);
190 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
192 ok(0, "unexpected call\n");
196 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
198 CHECK_EXPECT(OnEnterScript);
202 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
204 CHECK_EXPECT(OnLeaveScript);
208 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
209 ActiveScriptSite_QueryInterface,
210 ActiveScriptSite_AddRef,
211 ActiveScriptSite_Release,
212 ActiveScriptSite_GetLCID,
213 ActiveScriptSite_GetItemInfo,
214 ActiveScriptSite_GetDocVersionString,
215 ActiveScriptSite_OnScriptTerminate,
216 ActiveScriptSite_OnStateChange,
217 ActiveScriptSite_OnScriptError,
218 ActiveScriptSite_OnEnterScript,
219 ActiveScriptSite_OnLeaveScript
222 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
224 static void test_safety(IActiveScript *script)
226 IObjectSafety *safety;
227 DWORD supported, enabled;
230 hres = IActiveScript_QueryInterface(script, &IID_IObjectSafety, (void**)&safety);
231 ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
235 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, &supported, NULL);
236 ok(hres == E_POINTER, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres);
237 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, NULL, &enabled);
238 ok(hres == E_POINTER, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres);
240 supported = enabled = 0xdeadbeef;
241 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, &supported, &enabled);
242 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
243 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
244 "supported=%x\n", supported);
245 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
247 supported = enabled = 0xdeadbeef;
248 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScript, &supported, &enabled);
249 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
250 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
251 "supported=%x\n", supported);
252 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
254 supported = enabled = 0xdeadbeef;
255 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
256 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
257 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
258 "supported=%x\n", supported);
259 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
261 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
262 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER
263 |INTERFACESAFE_FOR_UNTRUSTED_CALLER,
264 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
265 ok(hres == E_FAIL, "SetInterfaceSafetyOptions failed: %08x, expected E_FAIL\n", hres);
267 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
268 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER,
269 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
270 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
272 supported = enabled = 0xdeadbeef;
273 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
274 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
275 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
276 "supported=%x\n", supported);
277 ok(enabled == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
278 "enabled=%x\n", enabled);
280 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, INTERFACESAFE_FOR_UNTRUSTED_DATA, 0);
281 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
283 supported = enabled = 0xdeadbeef;
284 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
285 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
286 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
287 "supported=%x\n", supported);
288 ok(enabled == (INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER), "enabled=%x\n", enabled);
290 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
291 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER, 0);
292 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
294 supported = enabled = 0xdeadbeef;
295 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
296 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
297 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
298 "supported=%x\n", supported);
299 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
301 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
302 INTERFACE_USES_DISPEX, 0);
303 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
305 supported = enabled = 0xdeadbeef;
306 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
307 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
308 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
309 "supported=%x\n", supported);
310 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
312 IObjectSafety_Release(safety);
315 static IDispatchEx *get_script_dispatch(IActiveScript *script)
321 disp = (void*)0xdeadbeef;
322 hres = IActiveScript_GetScriptDispatch(script, NULL, &disp);
323 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
327 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
328 IDispatch_Release(disp);
329 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
333 static void parse_script(IActiveScriptParse *parse, const char *src)
338 SET_EXPECT(OnEnterScript);
339 SET_EXPECT(OnLeaveScript);
342 hres = IActiveScriptParse_ParseScriptText(parse, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
344 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
346 CHECK_CALLED(OnEnterScript);
347 CHECK_CALLED(OnLeaveScript);
350 #define get_disp_id(a,b,c,d) _get_disp_id(__LINE__,a,b,c,d)
351 static void _get_disp_id(unsigned line, IDispatchEx *dispex, const char *name, HRESULT exhres, DISPID *id)
358 hres = IDispatchEx_GetDispID(dispex, str, 0, id);
359 ok_(__FILE__,line)(hres == exhres, "GetDispID(%s) returned %08x, expected %08x\n", name, hres, exhres);
361 hres = IDispatchEx_GetIDsOfNames(dispex, &IID_NULL, &str, 1, 0, &id2);
363 ok_(__FILE__,line)(hres == exhres, "GetIDsOfNames(%s) returned %08x, expected %08x\n", name, hres, exhres);
364 ok_(__FILE__,line)(*id == id2, "GetIDsOfNames(%s) id != id2\n", name);
367 static void test_no_script_dispatch(IActiveScript *script)
372 disp = (void*)0xdeadbeef;
373 hres = IActiveScript_GetScriptDispatch(script, NULL, &disp);
374 ok(hres == E_UNEXPECTED, "hres = %08x, expected E_UNEXPECTED\n", hres);
375 ok(!disp, "disp != NULL\n");
378 static IActiveScript *create_vbscript(void)
383 hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
384 &IID_IActiveScript, (void**)&ret);
385 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
390 static void test_scriptdisp(void)
392 IActiveScriptParse *parser;
393 IDispatchEx *script_disp;
394 IActiveScript *vbscript;
402 vbscript = create_vbscript();
404 hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParse, (void**)&parser);
405 ok(hres == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hres);
407 test_state(vbscript, SCRIPTSTATE_UNINITIALIZED);
408 test_safety(vbscript);
411 hres = IActiveScript_SetScriptSite(vbscript, &ActiveScriptSite);
412 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
413 CHECK_CALLED(GetLCID);
415 test_state(vbscript, SCRIPTSTATE_UNINITIALIZED);
417 SET_EXPECT(OnStateChange_INITIALIZED);
418 hres = IActiveScriptParse_InitNew(parser);
419 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
420 CHECK_CALLED(OnStateChange_INITIALIZED);
422 test_state(vbscript, SCRIPTSTATE_INITIALIZED);
424 SET_EXPECT(OnStateChange_CONNECTED);
425 hres = IActiveScript_SetScriptState(vbscript, SCRIPTSTATE_CONNECTED);
426 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
427 CHECK_CALLED(OnStateChange_CONNECTED);
429 test_state(vbscript, SCRIPTSTATE_CONNECTED);
431 script_disp = get_script_dispatch(vbscript);
434 get_disp_id(script_disp, "LCase", DISP_E_UNKNOWNNAME, &id);
435 ok(id == -1, "id = %d, expected -1\n", id);
437 get_disp_id(script_disp, "globalVariable", DISP_E_UNKNOWNNAME, &id);
438 parse_script(parser, "dim globalVariable\nglobalVariable = 3");
439 get_disp_id(script_disp, "globalVariable", S_OK, &id);
441 memset(&dp, 0, sizeof(dp));
442 memset(&ei, 0, sizeof(ei));
444 hres = IDispatchEx_InvokeEx(script_disp, id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
445 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
446 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
447 ok(V_I2(&v) == 3, "V_I2(v) = %d\n", V_I2(&v));
449 get_disp_id(script_disp, "globalVariable2", DISP_E_UNKNOWNNAME, &id);
450 parse_script(parser, "globalVariable2 = 4");
451 get_disp_id(script_disp, "globalVariable2", S_OK, &id);
453 get_disp_id(script_disp, "globalFunction", DISP_E_UNKNOWNNAME, &id);
454 parse_script(parser, "function globalFunction()\nglobalFunction=5\nend function");
455 get_disp_id(script_disp, "globalFunction", S_OK, &id);
457 SET_EXPECT(OnEnterScript);
458 SET_EXPECT(OnLeaveScript);
460 memset(&dp, 0, sizeof(dp));
461 memset(&ei, 0, sizeof(ei));
463 hres = IDispatchEx_InvokeEx(script_disp, id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
464 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
465 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
466 ok(V_I2(&v) == 5, "V_I2(v) = %d\n", V_I2(&v));
468 CHECK_CALLED(OnEnterScript);
469 CHECK_CALLED(OnLeaveScript);
471 SET_EXPECT(OnEnterScript);
472 SET_EXPECT(OnLeaveScript);
474 memset(&dp, 0, sizeof(dp));
475 memset(&ei, 0, sizeof(ei));
477 hres = IDispatchEx_Invoke(script_disp, id, &IID_NULL, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
478 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
479 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
480 ok(V_I2(&v) == 5, "V_I2(v) = %d\n", V_I2(&v));
482 CHECK_CALLED(OnEnterScript);
483 CHECK_CALLED(OnLeaveScript);
485 get_disp_id(script_disp, "globalSub", DISP_E_UNKNOWNNAME, &id);
486 parse_script(parser, "sub globalSub()\nend sub");
487 get_disp_id(script_disp, "globalSub", S_OK, &id);
488 get_disp_id(script_disp, "globalSub", S_OK, &id2);
489 ok(id == id2, "id != id2\n");
491 get_disp_id(script_disp, "constVariable", DISP_E_UNKNOWNNAME, &id);
492 parse_script(parser, "const constVariable = 6");
493 get_disp_id(script_disp, "ConstVariable", S_OK, &id);
494 get_disp_id(script_disp, "Constvariable", S_OK, &id2);
495 ok(id == id2, "id != id2\n");
497 IDispatchEx_Release(script_disp);
499 IActiveScriptParse_Release(parser);
501 SET_EXPECT(OnStateChange_DISCONNECTED);
502 SET_EXPECT(OnStateChange_INITIALIZED);
503 SET_EXPECT(OnStateChange_CLOSED);
504 hres = IActiveScript_Close(vbscript);
505 ok(hres == S_OK, "Close failed: %08x\n", hres);
506 CHECK_CALLED(OnStateChange_DISCONNECTED);
507 CHECK_CALLED(OnStateChange_INITIALIZED);
508 CHECK_CALLED(OnStateChange_CLOSED);
510 ref = IActiveScript_Release(vbscript);
511 ok(!ref, "ref = %d\n", ref);
514 static void test_vbscript(void)
516 IActiveScriptParseProcedure2 *parse_proc;
517 IActiveScriptParse *parser;
518 IActiveScript *vbscript;
522 vbscript = create_vbscript();
524 hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParse, (void**)&parser);
525 ok(hres == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hres);
527 test_state(vbscript, SCRIPTSTATE_UNINITIALIZED);
528 test_safety(vbscript);
531 hres = IActiveScript_SetScriptSite(vbscript, &ActiveScriptSite);
532 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
533 CHECK_CALLED(GetLCID);
535 test_state(vbscript, SCRIPTSTATE_UNINITIALIZED);
537 SET_EXPECT(OnStateChange_INITIALIZED);
538 hres = IActiveScriptParse_InitNew(parser);
539 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
540 CHECK_CALLED(OnStateChange_INITIALIZED);
542 test_state(vbscript, SCRIPTSTATE_INITIALIZED);
544 hres = IActiveScriptParse_InitNew(parser);
545 ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres);
547 SET_EXPECT(OnStateChange_CONNECTED);
548 hres = IActiveScript_SetScriptState(vbscript, SCRIPTSTATE_CONNECTED);
549 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
550 CHECK_CALLED(OnStateChange_CONNECTED);
552 test_state(vbscript, SCRIPTSTATE_CONNECTED);
554 SET_EXPECT(OnStateChange_DISCONNECTED);
555 SET_EXPECT(OnStateChange_INITIALIZED);
556 SET_EXPECT(OnStateChange_CLOSED);
557 hres = IActiveScript_Close(vbscript);
558 ok(hres == S_OK, "Close failed: %08x\n", hres);
559 CHECK_CALLED(OnStateChange_DISCONNECTED);
560 CHECK_CALLED(OnStateChange_INITIALIZED);
561 CHECK_CALLED(OnStateChange_CLOSED);
563 test_state(vbscript, SCRIPTSTATE_CLOSED);
564 test_no_script_dispatch(vbscript);
566 IActiveScriptParse_Release(parser);
568 hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParseProcedure, (void**)&parse_proc);
569 ok(hres == E_NOINTERFACE, "Got IActiveScriptParseProcedure interface, expected E_NOTIMPL\n");
571 hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc);
572 ok(hres == S_OK, "Could not get IActiveScriptParseProcedure2 interface\n");
573 IActiveScriptParseProcedure2_Release(parse_proc);
575 ref = IActiveScript_Release(vbscript);
576 ok(!ref, "ref = %d\n", ref);
579 static void test_vbscript_uninitializing(void)
581 IActiveScriptParse *parse;
582 IActiveScript *script;
587 static const WCHAR script_textW[] =
588 {'F','u','n','c','t','i','o','n',' ','f','\n','E','n','d',' ','F','u','n','c','t','i','o','n','\n',0};
590 script = create_vbscript();
592 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
593 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
595 test_state(script, SCRIPTSTATE_UNINITIALIZED);
597 hres = IActiveScriptParse_InitNew(parse);
598 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
601 SET_EXPECT(OnStateChange_INITIALIZED);
602 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
603 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
604 CHECK_CALLED(GetLCID);
605 CHECK_CALLED(OnStateChange_INITIALIZED);
607 test_state(script, SCRIPTSTATE_INITIALIZED);
609 hres = IActiveScriptParse_ParseScriptText(parse, script_textW, NULL, NULL, NULL, 0, 1, 0x42, NULL, NULL);
610 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
612 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
613 ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres);
615 SET_EXPECT(OnStateChange_UNINITIALIZED);
616 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
617 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
618 CHECK_CALLED(OnStateChange_UNINITIALIZED);
620 test_state(script, SCRIPTSTATE_UNINITIALIZED);
622 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
623 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
626 SET_EXPECT(OnStateChange_INITIALIZED);
627 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
628 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
629 CHECK_CALLED(GetLCID);
630 CHECK_CALLED(OnStateChange_INITIALIZED);
632 SET_EXPECT(OnStateChange_CONNECTED);
633 SET_EXPECT(OnEnterScript);
634 SET_EXPECT(OnLeaveScript);
635 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
636 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
637 CHECK_CALLED(OnStateChange_CONNECTED);
638 CHECK_CALLED(OnEnterScript);
639 CHECK_CALLED(OnLeaveScript);
641 test_state(script, SCRIPTSTATE_CONNECTED);
643 dispex = get_script_dispatch(script);
644 ok(dispex != NULL, "dispex == NULL\n");
646 IDispatchEx_Release(dispex);
648 SET_EXPECT(OnStateChange_DISCONNECTED);
649 SET_EXPECT(OnStateChange_INITIALIZED);
650 SET_EXPECT(OnStateChange_UNINITIALIZED);
651 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
652 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
653 CHECK_CALLED(OnStateChange_DISCONNECTED);
654 CHECK_CALLED(OnStateChange_INITIALIZED);
655 CHECK_CALLED(OnStateChange_UNINITIALIZED);
657 test_state(script, SCRIPTSTATE_UNINITIALIZED);
659 hres = IActiveScript_Close(script);
660 ok(hres == S_OK, "Close failed: %08x\n", hres);
662 test_state(script, SCRIPTSTATE_CLOSED);
664 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
665 ok(hres == E_UNEXPECTED, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x, expected E_UNEXPECTED\n", hres);
667 test_state(script, SCRIPTSTATE_CLOSED);
670 SET_EXPECT(OnStateChange_INITIALIZED);
671 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
672 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
673 CHECK_CALLED(GetLCID);
674 CHECK_CALLED(OnStateChange_INITIALIZED);
676 test_state(script, SCRIPTSTATE_INITIALIZED);
678 SET_EXPECT(OnStateChange_CLOSED);
679 hres = IActiveScript_Close(script);
680 ok(hres == S_OK, "Close failed: %08x\n", hres);
681 CHECK_CALLED(OnStateChange_CLOSED);
683 test_state(script, SCRIPTSTATE_CLOSED);
685 IActiveScriptParse_Release(parse);
687 ref = IActiveScript_Release(script);
688 ok(!ref, "ref = %d\n", ref);
691 static void test_vbscript_release(void)
693 IActiveScriptParse *parser;
694 IActiveScript *vbscript;
698 vbscript = create_vbscript();
700 hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParse, (void**)&parser);
701 ok(hres == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hres);
703 test_state(vbscript, SCRIPTSTATE_UNINITIALIZED);
704 test_safety(vbscript);
707 hres = IActiveScript_SetScriptSite(vbscript, &ActiveScriptSite);
708 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
709 CHECK_CALLED(GetLCID);
711 test_state(vbscript, SCRIPTSTATE_UNINITIALIZED);
713 SET_EXPECT(OnStateChange_INITIALIZED);
714 hres = IActiveScriptParse_InitNew(parser);
715 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
716 CHECK_CALLED(OnStateChange_INITIALIZED);
718 test_state(vbscript, SCRIPTSTATE_INITIALIZED);
720 SET_EXPECT(OnStateChange_CONNECTED);
721 hres = IActiveScript_SetScriptState(vbscript, SCRIPTSTATE_CONNECTED);
722 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
723 CHECK_CALLED(OnStateChange_CONNECTED);
725 test_state(vbscript, SCRIPTSTATE_CONNECTED);
727 IActiveScriptParse_Release(parser);
729 SET_EXPECT(OnStateChange_DISCONNECTED);
730 SET_EXPECT(OnStateChange_INITIALIZED);
731 SET_EXPECT(OnStateChange_CLOSED);
732 ref = IActiveScript_Release(vbscript);
733 ok(!ref, "ref = %d\n", ref);
734 CHECK_CALLED(OnStateChange_DISCONNECTED);
735 CHECK_CALLED(OnStateChange_INITIALIZED);
736 CHECK_CALLED(OnStateChange_CLOSED);
739 static void test_vbscript_simplecreate(void)
741 IActiveScript *script;
745 script = create_vbscript();
747 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
748 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
750 ref = IActiveScript_Release(script);
751 ok(!ref, "ref = %d\n", ref);
754 static void test_vbscript_initializing(void)
756 IActiveScriptParse *parse;
757 IActiveScript *script;
761 script = create_vbscript();
763 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
764 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
766 test_state(script, SCRIPTSTATE_UNINITIALIZED);
769 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
770 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
771 CHECK_CALLED(GetLCID);
773 SET_EXPECT(OnStateChange_INITIALIZED);
774 hres = IActiveScriptParse_InitNew(parse);
775 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
776 CHECK_CALLED(OnStateChange_INITIALIZED);
778 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
779 ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres);
781 SET_EXPECT(OnStateChange_CLOSED);
782 hres = IActiveScript_Close(script);
783 ok(hres == S_OK, "Close failed: %08x\n", hres);
784 CHECK_CALLED(OnStateChange_CLOSED);
786 test_state(script, SCRIPTSTATE_CLOSED);
788 IActiveScriptParse_Release(parse);
790 ref = IActiveScript_Release(script);
791 ok(!ref, "ref = %d\n", ref);
794 static BOOL check_vbscript(void)
796 IActiveScriptParseProcedure2 *vbscript;
799 hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
800 &IID_IActiveScriptParseProcedure2, (void**)&vbscript);
802 IActiveScriptParseProcedure2_Release(vbscript);
811 if(check_vbscript()) {
813 test_vbscript_uninitializing();
814 test_vbscript_release();
815 test_vbscript_simplecreate();
816 test_vbscript_initializing();
819 win_skip("VBScript engine not available or too old\n");