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"
30 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
32 #define DEFINE_EXPECT(func) \
33 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
35 #define SET_EXPECT(func) \
36 expect_ ## func = TRUE
38 #define SET_CALLED(func) \
39 called_ ## func = TRUE
41 #define CHECK_EXPECT2(func) \
43 ok(expect_ ##func, "unexpected call " #func "\n"); \
44 called_ ## func = TRUE; \
47 #define CHECK_EXPECT(func) \
49 CHECK_EXPECT2(func); \
50 expect_ ## func = FALSE; \
53 #define CHECK_CALLED(func) \
55 ok(called_ ## func, "expected " #func "\n"); \
56 expect_ ## func = called_ ## func = FALSE; \
59 DEFINE_EXPECT(GetLCID
);
60 DEFINE_EXPECT(OnStateChange_UNINITIALIZED
);
61 DEFINE_EXPECT(OnStateChange_STARTED
);
62 DEFINE_EXPECT(OnStateChange_CONNECTED
);
63 DEFINE_EXPECT(OnStateChange_DISCONNECTED
);
64 DEFINE_EXPECT(OnStateChange_CLOSED
);
65 DEFINE_EXPECT(OnStateChange_INITIALIZED
);
66 DEFINE_EXPECT(OnEnterScript
);
67 DEFINE_EXPECT(OnLeaveScript
);
69 DEFINE_GUID(CLSID_VBScript
, 0xb54f3741, 0x5b07, 0x11cf, 0xa4,0xb0, 0x00,0xaa,0x00,0x4a,0x55,0xe8);
71 #define test_state(s,ss) _test_state(__LINE__,s,ss)
72 static void _test_state(unsigned line
, IActiveScript
*script
, SCRIPTSTATE exstate
)
74 SCRIPTSTATE state
= -1;
77 hres
= IActiveScript_GetScriptState(script
, &state
);
78 ok_(__FILE__
,line
) (hres
== S_OK
, "GetScriptState failed: %08x\n", hres
);
79 ok_(__FILE__
,line
) (state
== exstate
, "state=%d, expected %d\n", state
, exstate
);
82 static HRESULT WINAPI
ActiveScriptSite_QueryInterface(IActiveScriptSite
*iface
, REFIID riid
, void **ppv
)
86 if(IsEqualGUID(&IID_IUnknown
, riid
))
88 else if(IsEqualGUID(&IID_IActiveScriptSite
, riid
))
93 IUnknown_AddRef((IUnknown
*)*ppv
);
97 static ULONG WINAPI
ActiveScriptSite_AddRef(IActiveScriptSite
*iface
)
102 static ULONG WINAPI
ActiveScriptSite_Release(IActiveScriptSite
*iface
)
107 static HRESULT WINAPI
ActiveScriptSite_GetLCID(IActiveScriptSite
*iface
, LCID
*plcid
)
109 CHECK_EXPECT(GetLCID
);
113 static HRESULT WINAPI
ActiveScriptSite_GetItemInfo(IActiveScriptSite
*iface
, LPCOLESTR pstrName
,
114 DWORD dwReturnMask
, IUnknown
**ppiunkItem
, ITypeInfo
**ppti
)
116 ok(0, "unexpected call\n");
120 static HRESULT WINAPI
ActiveScriptSite_GetDocVersionString(IActiveScriptSite
*iface
, BSTR
*pbstrVersion
)
122 ok(0, "unexpected call\n");
126 static HRESULT WINAPI
ActiveScriptSite_OnScriptTerminate(IActiveScriptSite
*iface
,
127 const VARIANT
*pvarResult
, const EXCEPINFO
*pexcepinfo
)
129 ok(0, "unexpected call\n");
133 static HRESULT WINAPI
ActiveScriptSite_OnStateChange(IActiveScriptSite
*iface
, SCRIPTSTATE ssScriptState
)
135 switch(ssScriptState
) {
136 case SCRIPTSTATE_UNINITIALIZED
:
137 CHECK_EXPECT(OnStateChange_UNINITIALIZED
);
139 case SCRIPTSTATE_STARTED
:
140 CHECK_EXPECT(OnStateChange_STARTED
);
142 case SCRIPTSTATE_CONNECTED
:
143 CHECK_EXPECT(OnStateChange_CONNECTED
);
145 case SCRIPTSTATE_DISCONNECTED
:
146 CHECK_EXPECT(OnStateChange_DISCONNECTED
);
148 case SCRIPTSTATE_CLOSED
:
149 CHECK_EXPECT(OnStateChange_CLOSED
);
151 case SCRIPTSTATE_INITIALIZED
:
152 CHECK_EXPECT(OnStateChange_INITIALIZED
);
155 ok(0, "unexpected call %d\n", ssScriptState
);
161 static HRESULT WINAPI
ActiveScriptSite_OnScriptError(IActiveScriptSite
*iface
, IActiveScriptError
*pscripterror
)
163 ok(0, "unexpected call\n");
167 static HRESULT WINAPI
ActiveScriptSite_OnEnterScript(IActiveScriptSite
*iface
)
169 CHECK_EXPECT(OnEnterScript
);
173 static HRESULT WINAPI
ActiveScriptSite_OnLeaveScript(IActiveScriptSite
*iface
)
175 CHECK_EXPECT(OnLeaveScript
);
179 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl
= {
180 ActiveScriptSite_QueryInterface
,
181 ActiveScriptSite_AddRef
,
182 ActiveScriptSite_Release
,
183 ActiveScriptSite_GetLCID
,
184 ActiveScriptSite_GetItemInfo
,
185 ActiveScriptSite_GetDocVersionString
,
186 ActiveScriptSite_OnScriptTerminate
,
187 ActiveScriptSite_OnStateChange
,
188 ActiveScriptSite_OnScriptError
,
189 ActiveScriptSite_OnEnterScript
,
190 ActiveScriptSite_OnLeaveScript
193 static IActiveScriptSite ActiveScriptSite
= { &ActiveScriptSiteVtbl
};
195 static void test_safety(IActiveScript
*script
)
197 IObjectSafety
*safety
;
198 DWORD supported
, enabled
;
201 hres
= IActiveScript_QueryInterface(script
, &IID_IObjectSafety
, (void**)&safety
);
202 ok(hres
== S_OK
, "Could not get IObjectSafety: %08x\n", hres
);
206 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_NULL
, &supported
, NULL
);
207 ok(hres
== E_POINTER
, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres
);
208 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_NULL
, NULL
, &enabled
);
209 ok(hres
== E_POINTER
, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres
);
211 supported
= enabled
= 0xdeadbeef;
212 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_NULL
, &supported
, &enabled
);
213 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
214 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
215 "supported=%x\n", supported
);
216 ok(enabled
== INTERFACE_USES_DISPEX
, "enabled=%x\n", enabled
);
218 supported
= enabled
= 0xdeadbeef;
219 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScript
, &supported
, &enabled
);
220 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
221 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
222 "supported=%x\n", supported
);
223 ok(enabled
== INTERFACE_USES_DISPEX
, "enabled=%x\n", enabled
);
225 supported
= enabled
= 0xdeadbeef;
226 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, &supported
, &enabled
);
227 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
228 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
229 "supported=%x\n", supported
);
230 ok(enabled
== INTERFACE_USES_DISPEX
, "enabled=%x\n", enabled
);
232 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
,
233 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
234 |INTERFACESAFE_FOR_UNTRUSTED_CALLER
,
235 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
);
236 ok(hres
== E_FAIL
, "SetInterfaceSafetyOptions failed: %08x, expected E_FAIL\n", hres
);
238 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
,
239 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
,
240 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
);
241 ok(hres
== S_OK
, "SetInterfaceSafetyOptions failed: %08x\n", hres
);
243 supported
= enabled
= 0xdeadbeef;
244 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, &supported
, &enabled
);
245 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
246 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
247 "supported=%x\n", supported
);
248 ok(enabled
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
249 "enabled=%x\n", enabled
);
251 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, INTERFACESAFE_FOR_UNTRUSTED_DATA
, 0);
252 ok(hres
== S_OK
, "SetInterfaceSafetyOptions failed: %08x\n", hres
);
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
|INTERFACE_USES_SECURITY_MANAGER
), "enabled=%x\n", enabled
);
261 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
,
262 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
, 0);
263 ok(hres
== S_OK
, "SetInterfaceSafetyOptions failed: %08x\n", hres
);
265 supported
= enabled
= 0xdeadbeef;
266 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, &supported
, &enabled
);
267 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
268 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
269 "supported=%x\n", supported
);
270 ok(enabled
== INTERFACE_USES_DISPEX
, "enabled=%x\n", enabled
);
272 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
,
273 INTERFACE_USES_DISPEX
, 0);
274 ok(hres
== S_OK
, "SetInterfaceSafetyOptions failed: %08x\n", hres
);
276 supported
= enabled
= 0xdeadbeef;
277 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, &supported
, &enabled
);
278 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
279 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
280 "supported=%x\n", supported
);
281 ok(enabled
== INTERFACE_USES_DISPEX
, "enabled=%x\n", enabled
);
283 IObjectSafety_Release(safety
);
286 static IDispatchEx
*get_script_dispatch(IActiveScript
*script
)
292 disp
= (void*)0xdeadbeef;
293 hres
= IActiveScript_GetScriptDispatch(script
, NULL
, &disp
);
294 ok(hres
== S_OK
, "GetScriptDispatch failed: %08x\n", hres
);
298 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
299 IDispatch_Release(disp
);
300 ok(hres
== S_OK
, "Could not get IDispatchEx iface: %08x\n", hres
);
304 static void test_no_script_dispatch(IActiveScript
*script
)
309 disp
= (void*)0xdeadbeef;
310 hres
= IActiveScript_GetScriptDispatch(script
, NULL
, &disp
);
311 ok(hres
== E_UNEXPECTED
, "hres = %08x, expected E_UNEXPECTED\n", hres
);
312 ok(!disp
, "disp != NULL\n");
315 static IActiveScript
*create_vbscript(void)
320 hres
= CoCreateInstance(&CLSID_VBScript
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
321 &IID_IActiveScript
, (void**)&ret
);
322 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
327 static void test_vbscript(void)
329 IActiveScriptParse
*parser
;
330 IActiveScript
*vbscript
;
334 vbscript
= create_vbscript();
336 hres
= IActiveScript_QueryInterface(vbscript
, &IID_IActiveScriptParse
, (void**)&parser
);
337 ok(hres
== S_OK
, "Could not get IActiveScriptParse iface: %08x\n", hres
);
339 test_state(vbscript
, SCRIPTSTATE_UNINITIALIZED
);
340 test_safety(vbscript
);
343 hres
= IActiveScript_SetScriptSite(vbscript
, &ActiveScriptSite
);
344 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
345 CHECK_CALLED(GetLCID
);
347 test_state(vbscript
, SCRIPTSTATE_UNINITIALIZED
);
349 SET_EXPECT(OnStateChange_INITIALIZED
);
350 hres
= IActiveScriptParse64_InitNew(parser
);
351 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
352 CHECK_CALLED(OnStateChange_INITIALIZED
);
354 test_state(vbscript
, SCRIPTSTATE_INITIALIZED
);
356 hres
= IActiveScriptParse64_InitNew(parser
);
357 ok(hres
== E_UNEXPECTED
, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres
);
359 SET_EXPECT(OnStateChange_CONNECTED
);
360 hres
= IActiveScript_SetScriptState(vbscript
, SCRIPTSTATE_CONNECTED
);
361 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres
);
362 CHECK_CALLED(OnStateChange_CONNECTED
);
364 test_state(vbscript
, SCRIPTSTATE_CONNECTED
);
366 SET_EXPECT(OnStateChange_DISCONNECTED
);
367 SET_EXPECT(OnStateChange_INITIALIZED
);
368 SET_EXPECT(OnStateChange_CLOSED
);
369 hres
= IActiveScript_Close(vbscript
);
370 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
371 CHECK_CALLED(OnStateChange_DISCONNECTED
);
372 CHECK_CALLED(OnStateChange_INITIALIZED
);
373 CHECK_CALLED(OnStateChange_CLOSED
);
375 test_state(vbscript
, SCRIPTSTATE_CLOSED
);
376 test_no_script_dispatch(vbscript
);
378 IActiveScriptParse64_Release(parser
);
380 ref
= IActiveScript_Release(vbscript
);
381 ok(!ref
, "ref = %d\n", ref
);
384 static void test_vbscript_uninitializing(void)
386 IActiveScriptParse
*parse
;
387 IActiveScript
*script
;
392 static const WCHAR script_textW
[] =
393 {'F','u','n','c','t','i','o','n',' ','f','\n','E','n','d',' ','F','u','n','c','t','i','o','n','\n',0};
395 script
= create_vbscript();
397 hres
= IActiveScript_QueryInterface(script
, &IID_IActiveScriptParse
, (void**)&parse
);
398 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
400 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
402 hres
= IActiveScriptParse64_InitNew(parse
);
403 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
406 SET_EXPECT(OnStateChange_INITIALIZED
);
407 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
408 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
409 CHECK_CALLED(GetLCID
);
410 CHECK_CALLED(OnStateChange_INITIALIZED
);
412 test_state(script
, SCRIPTSTATE_INITIALIZED
);
414 hres
= IActiveScriptParse64_ParseScriptText(parse
, script_textW
, NULL
, NULL
, NULL
, 0, 1, 0x42, NULL
, NULL
);
415 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
417 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
418 ok(hres
== E_UNEXPECTED
, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres
);
420 SET_EXPECT(OnStateChange_UNINITIALIZED
);
421 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
422 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
423 CHECK_CALLED(OnStateChange_UNINITIALIZED
);
425 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
427 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
428 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
431 SET_EXPECT(OnStateChange_INITIALIZED
);
432 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
433 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
434 CHECK_CALLED(GetLCID
);
435 CHECK_CALLED(OnStateChange_INITIALIZED
);
437 SET_EXPECT(OnStateChange_CONNECTED
);
438 SET_EXPECT(OnEnterScript
);
439 SET_EXPECT(OnLeaveScript
);
440 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_CONNECTED
);
441 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres
);
442 CHECK_CALLED(OnStateChange_CONNECTED
);
443 CHECK_CALLED(OnEnterScript
);
444 CHECK_CALLED(OnLeaveScript
);
446 test_state(script
, SCRIPTSTATE_CONNECTED
);
448 dispex
= get_script_dispatch(script
);
449 ok(dispex
!= NULL
, "dispex == NULL\n");
451 IDispatchEx_Release(dispex
);
453 SET_EXPECT(OnStateChange_DISCONNECTED
);
454 SET_EXPECT(OnStateChange_INITIALIZED
);
455 SET_EXPECT(OnStateChange_UNINITIALIZED
);
456 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
457 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
458 CHECK_CALLED(OnStateChange_DISCONNECTED
);
459 CHECK_CALLED(OnStateChange_INITIALIZED
);
460 CHECK_CALLED(OnStateChange_UNINITIALIZED
);
462 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
464 hres
= IActiveScript_Close(script
);
465 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
467 test_state(script
, SCRIPTSTATE_CLOSED
);
469 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
470 ok(hres
== E_UNEXPECTED
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x, expected E_UNEXPECTED\n", hres
);
472 test_state(script
, SCRIPTSTATE_CLOSED
);
475 SET_EXPECT(OnStateChange_INITIALIZED
);
476 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
477 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
478 CHECK_CALLED(GetLCID
);
479 CHECK_CALLED(OnStateChange_INITIALIZED
);
481 test_state(script
, SCRIPTSTATE_INITIALIZED
);
483 SET_EXPECT(OnStateChange_CLOSED
);
484 hres
= IActiveScript_Close(script
);
485 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
486 CHECK_CALLED(OnStateChange_CLOSED
);
488 test_state(script
, SCRIPTSTATE_CLOSED
);
490 IUnknown_Release(parse
);
492 ref
= IActiveScript_Release(script
);
493 ok(!ref
, "ref = %d\n", ref
);
496 static void test_vbscript_release(void)
498 IActiveScriptParse
*parser
;
499 IActiveScript
*vbscript
;
503 vbscript
= create_vbscript();
505 hres
= IActiveScript_QueryInterface(vbscript
, &IID_IActiveScriptParse
, (void**)&parser
);
506 ok(hres
== S_OK
, "Could not get IActiveScriptParse iface: %08x\n", hres
);
508 test_state(vbscript
, SCRIPTSTATE_UNINITIALIZED
);
509 test_safety(vbscript
);
512 hres
= IActiveScript_SetScriptSite(vbscript
, &ActiveScriptSite
);
513 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
514 CHECK_CALLED(GetLCID
);
516 test_state(vbscript
, SCRIPTSTATE_UNINITIALIZED
);
518 SET_EXPECT(OnStateChange_INITIALIZED
);
519 hres
= IActiveScriptParse64_InitNew(parser
);
520 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
521 CHECK_CALLED(OnStateChange_INITIALIZED
);
523 test_state(vbscript
, SCRIPTSTATE_INITIALIZED
);
525 SET_EXPECT(OnStateChange_CONNECTED
);
526 hres
= IActiveScript_SetScriptState(vbscript
, SCRIPTSTATE_CONNECTED
);
527 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres
);
528 CHECK_CALLED(OnStateChange_CONNECTED
);
530 test_state(vbscript
, SCRIPTSTATE_CONNECTED
);
532 IActiveScriptParse64_Release(parser
);
534 SET_EXPECT(OnStateChange_DISCONNECTED
);
535 SET_EXPECT(OnStateChange_INITIALIZED
);
536 SET_EXPECT(OnStateChange_CLOSED
);
537 ref
= IActiveScript_Release(vbscript
);
538 ok(!ref
, "ref = %d\n", ref
);
539 CHECK_CALLED(OnStateChange_DISCONNECTED
);
540 CHECK_CALLED(OnStateChange_INITIALIZED
);
541 CHECK_CALLED(OnStateChange_CLOSED
);
544 static void test_vbscript_simplecreate(void)
546 IActiveScript
*script
;
550 script
= create_vbscript();
552 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
553 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
555 ref
= IActiveScript_Release(script
);
556 ok(!ref
, "ref = %d\n", ref
);
559 static void test_vbscript_initializing(void)
561 IActiveScriptParse
*parse
;
562 IActiveScript
*script
;
566 script
= create_vbscript();
568 hres
= IActiveScript_QueryInterface(script
, &IID_IActiveScriptParse
, (void**)&parse
);
569 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
571 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
574 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
575 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
576 CHECK_CALLED(GetLCID
);
578 SET_EXPECT(OnStateChange_INITIALIZED
);
579 hres
= IActiveScriptParse64_InitNew(parse
);
580 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
581 CHECK_CALLED(OnStateChange_INITIALIZED
);
583 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
584 ok(hres
== E_UNEXPECTED
, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres
);
586 SET_EXPECT(OnStateChange_CLOSED
);
587 hres
= IActiveScript_Close(script
);
588 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
589 CHECK_CALLED(OnStateChange_CLOSED
);
591 test_state(script
, SCRIPTSTATE_CLOSED
);
593 IUnknown_Release(parse
);
595 ref
= IActiveScript_Release(script
);
596 ok(!ref
, "ref = %d\n", ref
);
599 static BOOL
check_vbscript(void)
601 IActiveScript
*vbscript
;
604 hres
= CoCreateInstance(&CLSID_VBScript
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
605 &IID_IActiveScript
, (void**)&vbscript
);
607 IActiveScript_Release(vbscript
);
616 if(check_vbscript()) {
618 test_vbscript_uninitializing();
619 test_vbscript_release();
620 test_vbscript_simplecreate();
621 test_vbscript_initializing();
623 win_skip("VBScript engine not available\n");