2 * Copyright 2008 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 static const CLSID CLSID_JScript =
33 {0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
35 #define DEFINE_EXPECT(func) \
36 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
38 #define SET_EXPECT(func) \
39 expect_ ## func = TRUE
41 #define SET_CALLED(func) \
42 called_ ## func = TRUE
44 #define CHECK_EXPECT2(func) \
46 ok(expect_ ##func, "unexpected call " #func "\n"); \
47 called_ ## func = TRUE; \
50 #define CHECK_EXPECT(func) \
52 CHECK_EXPECT2(func); \
53 expect_ ## func = FALSE; \
56 #define CHECK_CALLED(func) \
58 ok(called_ ## func, "expected " #func "\n"); \
59 expect_ ## func = called_ ## func = FALSE; \
62 DEFINE_EXPECT(GetLCID);
63 DEFINE_EXPECT(OnStateChange_UNINITIALIZED);
64 DEFINE_EXPECT(OnStateChange_STARTED);
65 DEFINE_EXPECT(OnStateChange_CONNECTED);
66 DEFINE_EXPECT(OnStateChange_DISCONNECTED);
67 DEFINE_EXPECT(OnStateChange_CLOSED);
68 DEFINE_EXPECT(OnStateChange_INITIALIZED);
69 DEFINE_EXPECT(OnEnterScript);
70 DEFINE_EXPECT(OnLeaveScript);
72 static BSTR a2bstr(const char *str)
77 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
78 ret = SysAllocStringLen(NULL, len-1);
79 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
84 #define test_state(s,ss) _test_state(__LINE__,s,ss)
85 static void _test_state(unsigned line, IActiveScript *script, SCRIPTSTATE exstate)
87 SCRIPTSTATE state = -1;
90 hres = IActiveScript_GetScriptState(script, &state);
91 ok_(__FILE__,line) (hres == S_OK, "GetScriptState failed: %08x\n", hres);
92 ok_(__FILE__,line) (state == exstate, "state=%d, expected %d\n", state, exstate);
95 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
99 if(IsEqualGUID(&IID_IUnknown, riid))
101 else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
104 return E_NOINTERFACE;
106 IUnknown_AddRef((IUnknown*)*ppv);
110 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
115 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
120 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
122 CHECK_EXPECT(GetLCID);
126 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
127 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
129 ok(0, "unexpected call\n");
133 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
135 ok(0, "unexpected call\n");
139 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
140 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
142 ok(0, "unexpected call\n");
146 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
148 switch(ssScriptState) {
149 case SCRIPTSTATE_UNINITIALIZED:
150 CHECK_EXPECT(OnStateChange_UNINITIALIZED);
152 case SCRIPTSTATE_STARTED:
153 CHECK_EXPECT(OnStateChange_STARTED);
155 case SCRIPTSTATE_CONNECTED:
156 CHECK_EXPECT(OnStateChange_CONNECTED);
158 case SCRIPTSTATE_DISCONNECTED:
159 CHECK_EXPECT(OnStateChange_DISCONNECTED);
161 case SCRIPTSTATE_CLOSED:
162 CHECK_EXPECT(OnStateChange_CLOSED);
164 case SCRIPTSTATE_INITIALIZED:
165 CHECK_EXPECT(OnStateChange_INITIALIZED);
168 ok(0, "unexpected call %d\n", ssScriptState);
174 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
176 ok(0, "unexpected call\n");
180 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
182 CHECK_EXPECT(OnEnterScript);
186 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
188 CHECK_EXPECT(OnLeaveScript);
192 #undef ACTSCPSITE_THIS
194 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
195 ActiveScriptSite_QueryInterface,
196 ActiveScriptSite_AddRef,
197 ActiveScriptSite_Release,
198 ActiveScriptSite_GetLCID,
199 ActiveScriptSite_GetItemInfo,
200 ActiveScriptSite_GetDocVersionString,
201 ActiveScriptSite_OnScriptTerminate,
202 ActiveScriptSite_OnStateChange,
203 ActiveScriptSite_OnScriptError,
204 ActiveScriptSite_OnEnterScript,
205 ActiveScriptSite_OnLeaveScript
208 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
210 static void test_script_dispatch(IDispatchEx *dispex)
212 DISPPARAMS dp = {NULL,NULL,0,0};
219 str = a2bstr("ActiveXObject");
220 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
222 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
224 str = a2bstr("Math");
225 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
227 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
229 memset(&ei, 0, sizeof(ei));
230 hres = IDispatchEx_InvokeEx(dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
231 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
232 ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v));
233 ok(V_DISPATCH(&v) != NULL, "V_DISPATCH(v) = NULL\n");
236 str = a2bstr("String");
237 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
239 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
241 memset(&ei, 0, sizeof(ei));
242 hres = IDispatchEx_InvokeEx(dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
243 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
244 ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v));
245 ok(V_DISPATCH(&v) != NULL, "V_DISPATCH(v) = NULL\n");
249 static IDispatchEx *get_script_dispatch(IActiveScript *script)
255 disp = (void*)0xdeadbeef;
256 hres = IActiveScript_GetScriptDispatch(script, NULL, &disp);
257 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
259 IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
260 IDispatch_Release(disp);
261 ok(hres == S_OK, "Could not get IDispatch iface: %08x\n", hres);
265 static void test_no_script_dispatch(IActiveScript *script)
270 disp = (void*)0xdeadbeef;
271 hres = IActiveScript_GetScriptDispatch(script, NULL, &disp);
272 ok(hres == E_UNEXPECTED, "hres = %08x, expected E_UNEXPECTED\n", hres);
273 ok(!disp, "disp != NULL\n");
276 static void test_safety(IUnknown *unk)
278 IObjectSafety *safety;
279 DWORD supported, enabled;
282 hres = IUnknown_QueryInterface(unk, &IID_IObjectSafety, (void**)&safety);
283 ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
287 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, &supported, NULL);
288 ok(hres == E_POINTER, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres);
289 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, NULL, &enabled);
290 ok(hres == E_POINTER, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres);
292 supported = enabled = 0xdeadbeef;
293 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, &supported, &enabled);
294 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
295 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
296 "supported=%x\n", supported);
297 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
299 supported = enabled = 0xdeadbeef;
300 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScript, &supported, &enabled);
301 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
302 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
303 "supported=%x\n", supported);
304 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
306 supported = enabled = 0xdeadbeef;
307 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
308 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
309 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
310 "supported=%x\n", supported);
311 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
313 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
314 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER
315 |INTERFACESAFE_FOR_UNTRUSTED_CALLER,
316 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
317 ok(hres == E_FAIL, "SetInterfaceSafetyOptions failed: %08x, expected E_FAIL\n", hres);
319 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
320 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER,
321 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
322 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
324 supported = enabled = 0xdeadbeef;
325 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
326 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
327 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
328 "supported=%x\n", supported);
329 ok(enabled == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
330 "enabled=%x\n", enabled);
332 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, INTERFACESAFE_FOR_UNTRUSTED_DATA, 0);
333 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
335 supported = enabled = 0xdeadbeef;
336 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
337 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
338 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
339 "supported=%x\n", supported);
340 ok(enabled == (INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER), "enabled=%x\n", enabled);
342 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
343 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER, 0);
344 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
346 supported = enabled = 0xdeadbeef;
347 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
348 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
349 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
350 "supported=%x\n", supported);
351 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
353 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
354 INTERFACE_USES_DISPEX, 0);
355 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
357 supported = enabled = 0xdeadbeef;
358 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
359 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
360 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
361 "supported=%x\n", supported);
362 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
364 IObjectSafety_Release(safety);
367 static HRESULT set_script_prop(IActiveScript *engine, DWORD property, VARIANT *val)
369 IActiveScriptProperty *script_prop;
372 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptProperty,
373 (void**)&script_prop);
374 ok(hres == S_OK, "Could not get IActiveScriptProperty: %08x\n", hres);
378 hres = IActiveScriptProperty_SetProperty(script_prop, property, NULL, val);
379 IActiveScriptProperty_Release(script_prop);
383 static void test_invoke_versioning(IActiveScript *script)
389 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
390 if(hres == E_NOTIMPL) {
391 win_skip("SCRIPTPROP_INVOKESTRING not supported\n");
394 ok(hres == E_INVALIDARG, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
398 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
399 ok(hres == E_INVALIDARG, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
403 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
404 ok(hres == E_INVALIDARG, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
408 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
409 ok(hres == S_OK, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
412 static IActiveScript *create_jscript(void)
417 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
418 &IID_IActiveScript, (void**)&ret);
419 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
424 static void test_jscript(void)
426 IActiveScriptParse *parse;
427 IActiveScript *script;
432 script = create_jscript();
434 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
435 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
437 test_state(script, SCRIPTSTATE_UNINITIALIZED);
438 test_safety((IUnknown*)script);
439 test_invoke_versioning(script);
441 hres = IActiveScriptParse64_InitNew(parse);
442 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
444 hres = IActiveScriptParse64_InitNew(parse);
445 ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres);
447 hres = IActiveScript_SetScriptSite(script, NULL);
448 ok(hres == E_POINTER, "SetScriptSite failed: %08x, expected E_POINTER\n", hres);
450 test_state(script, SCRIPTSTATE_UNINITIALIZED);
451 test_no_script_dispatch(script);
454 SET_EXPECT(OnStateChange_INITIALIZED);
455 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
456 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
457 CHECK_CALLED(GetLCID);
458 CHECK_CALLED(OnStateChange_INITIALIZED);
460 test_state(script, SCRIPTSTATE_INITIALIZED);
462 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
463 ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres);
465 dispex = get_script_dispatch(script);
466 test_script_dispatch(dispex);
468 SET_EXPECT(OnStateChange_STARTED);
469 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED);
470 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
471 CHECK_CALLED(OnStateChange_STARTED);
473 test_state(script, SCRIPTSTATE_STARTED);
475 SET_EXPECT(OnStateChange_CLOSED);
476 hres = IActiveScript_Close(script);
477 ok(hres == S_OK, "Close failed: %08x\n", hres);
478 CHECK_CALLED(OnStateChange_CLOSED);
480 test_state(script, SCRIPTSTATE_CLOSED);
481 test_no_script_dispatch(script);
482 test_script_dispatch(dispex);
483 IDispatchEx_Release(dispex);
485 IUnknown_Release(parse);
487 ref = IActiveScript_Release(script);
488 ok(!ref, "ref = %d\n", ref);
491 static void test_jscript2(void)
493 IActiveScriptParse *parse;
494 IActiveScript *script;
498 script = create_jscript();
500 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
501 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
503 test_state(script, SCRIPTSTATE_UNINITIALIZED);
506 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
507 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
508 CHECK_CALLED(GetLCID);
510 test_state(script, SCRIPTSTATE_UNINITIALIZED);
512 SET_EXPECT(OnStateChange_INITIALIZED);
513 hres = IActiveScriptParse64_InitNew(parse);
514 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
515 CHECK_CALLED(OnStateChange_INITIALIZED);
517 hres = IActiveScriptParse64_InitNew(parse);
518 ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres);
520 SET_EXPECT(OnStateChange_CONNECTED);
521 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
522 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
523 CHECK_CALLED(OnStateChange_CONNECTED);
525 test_state(script, SCRIPTSTATE_CONNECTED);
527 SET_EXPECT(OnStateChange_DISCONNECTED);
528 SET_EXPECT(OnStateChange_INITIALIZED);
529 SET_EXPECT(OnStateChange_CLOSED);
530 hres = IActiveScript_Close(script);
531 ok(hres == S_OK, "Close failed: %08x\n", hres);
532 CHECK_CALLED(OnStateChange_DISCONNECTED);
533 CHECK_CALLED(OnStateChange_INITIALIZED);
534 CHECK_CALLED(OnStateChange_CLOSED);
536 test_state(script, SCRIPTSTATE_CLOSED);
537 test_no_script_dispatch(script);
539 IUnknown_Release(parse);
541 ref = IActiveScript_Release(script);
542 ok(!ref, "ref = %d\n", ref);
545 static void test_jscript_uninitializing(void)
547 IActiveScriptParse *parse;
548 IActiveScript *script;
553 static const WCHAR script_textW[] =
554 {'f','u','n','c','t','i','o','n',' ','f','(',')',' ','{','}',0};
556 script = create_jscript();
558 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
559 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
561 test_state(script, SCRIPTSTATE_UNINITIALIZED);
563 hres = IActiveScriptParse64_InitNew(parse);
564 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
567 SET_EXPECT(OnStateChange_INITIALIZED);
568 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
569 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
570 CHECK_CALLED(GetLCID);
571 CHECK_CALLED(OnStateChange_INITIALIZED);
573 test_state(script, SCRIPTSTATE_INITIALIZED);
575 hres = IActiveScriptParse64_ParseScriptText(parse, script_textW, NULL, NULL, NULL, 0, 1, 0x42, NULL, NULL);
576 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
578 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
579 ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres);
581 SET_EXPECT(OnStateChange_UNINITIALIZED);
582 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
583 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
584 CHECK_CALLED(OnStateChange_UNINITIALIZED);
586 test_state(script, SCRIPTSTATE_UNINITIALIZED);
588 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
589 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
592 SET_EXPECT(OnStateChange_INITIALIZED);
593 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
594 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
595 CHECK_CALLED(GetLCID);
596 CHECK_CALLED(OnStateChange_INITIALIZED);
598 SET_EXPECT(OnStateChange_CONNECTED);
599 SET_EXPECT(OnEnterScript);
600 SET_EXPECT(OnLeaveScript);
601 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
602 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
603 CHECK_CALLED(OnStateChange_CONNECTED);
604 CHECK_CALLED(OnEnterScript);
605 CHECK_CALLED(OnLeaveScript);
607 test_state(script, SCRIPTSTATE_CONNECTED);
609 dispex = get_script_dispatch(script);
610 ok(dispex != NULL, "dispex == NULL\n");
611 IDispatchEx_Release(dispex);
613 SET_EXPECT(OnStateChange_DISCONNECTED);
614 SET_EXPECT(OnStateChange_INITIALIZED);
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_DISCONNECTED);
619 CHECK_CALLED(OnStateChange_INITIALIZED);
620 CHECK_CALLED(OnStateChange_UNINITIALIZED);
622 test_state(script, SCRIPTSTATE_UNINITIALIZED);
624 hres = IActiveScript_Close(script);
625 ok(hres == S_OK, "Close failed: %08x\n", hres);
627 test_state(script, SCRIPTSTATE_CLOSED);
629 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
630 ok(hres == E_UNEXPECTED, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x, expected E_UNEXPECTED\n", hres);
632 test_state(script, SCRIPTSTATE_CLOSED);
634 IUnknown_Release(parse);
636 ref = IActiveScript_Release(script);
637 ok(!ref, "ref = %d\n", ref);
640 static void test_aggregation(void)
642 IUnknown *unk = (IUnknown*)0xdeadbeef;
645 hres = CoCreateInstance(&CLSID_JScript, (IUnknown*)0xdeadbeef, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
646 &IID_IUnknown, (void**)&unk);
647 ok(hres == CLASS_E_NOAGGREGATION || broken(E_INVALIDARG) /* win2k */,
648 "CoCreateInstance failed: %08x, expected CLASS_E_NOAGGREGATION\n", hres);
649 ok(!unk, "unk = %p\n", unk);
652 static BOOL check_jscript(void)
654 IActiveScriptProperty *script_prop;
657 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
658 &IID_IActiveScriptProperty, (void**)&script_prop);
660 IActiveScriptProperty_Release(script_prop);
669 if(check_jscript()) {
672 test_jscript_uninitializing();
675 win_skip("Broken engine, probably too old\n");