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}};
34 static const CLSID CLSID_JScriptEncode
=
35 {0xf414c262,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
37 #define DEFINE_EXPECT(func) \
38 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
40 #define SET_EXPECT(func) \
41 expect_ ## func = TRUE
43 #define CHECK_EXPECT2(func) \
45 ok(expect_ ##func, "unexpected call " #func "\n"); \
46 called_ ## func = TRUE; \
49 #define CHECK_EXPECT(func) \
51 CHECK_EXPECT2(func); \
52 expect_ ## func = FALSE; \
55 #define CHECK_CALLED(func) \
57 ok(called_ ## func, "expected " #func "\n"); \
58 expect_ ## func = called_ ## func = FALSE; \
61 DEFINE_EXPECT(GetLCID
);
62 DEFINE_EXPECT(OnStateChange_UNINITIALIZED
);
63 DEFINE_EXPECT(OnStateChange_STARTED
);
64 DEFINE_EXPECT(OnStateChange_CONNECTED
);
65 DEFINE_EXPECT(OnStateChange_DISCONNECTED
);
66 DEFINE_EXPECT(OnStateChange_CLOSED
);
67 DEFINE_EXPECT(OnStateChange_INITIALIZED
);
68 DEFINE_EXPECT(OnEnterScript
);
69 DEFINE_EXPECT(OnLeaveScript
);
71 static const CLSID
*engine_clsid
= &CLSID_JScript
;
73 static BSTR
a2bstr(const char *str
)
78 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
79 ret
= SysAllocStringLen(NULL
, len
-1);
80 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
85 #define test_state(s,ss) _test_state(__LINE__,s,ss)
86 static void _test_state(unsigned line
, IActiveScript
*script
, SCRIPTSTATE exstate
)
88 SCRIPTSTATE state
= -1;
91 hres
= IActiveScript_GetScriptState(script
, &state
);
92 ok_(__FILE__
,line
) (hres
== S_OK
, "GetScriptState failed: %08x\n", hres
);
93 ok_(__FILE__
,line
) (state
== exstate
, "state=%d, expected %d\n", state
, exstate
);
96 static HRESULT WINAPI
ActiveScriptSite_QueryInterface(IActiveScriptSite
*iface
, REFIID riid
, void **ppv
)
100 if(IsEqualGUID(&IID_IUnknown
, riid
))
102 else if(IsEqualGUID(&IID_IActiveScriptSite
, riid
))
105 return E_NOINTERFACE
;
107 IUnknown_AddRef((IUnknown
*)*ppv
);
111 static ULONG WINAPI
ActiveScriptSite_AddRef(IActiveScriptSite
*iface
)
116 static ULONG WINAPI
ActiveScriptSite_Release(IActiveScriptSite
*iface
)
121 static HRESULT WINAPI
ActiveScriptSite_GetLCID(IActiveScriptSite
*iface
, LCID
*plcid
)
123 CHECK_EXPECT(GetLCID
);
127 static HRESULT WINAPI
ActiveScriptSite_GetItemInfo(IActiveScriptSite
*iface
, LPCOLESTR pstrName
,
128 DWORD dwReturnMask
, IUnknown
**ppiunkItem
, ITypeInfo
**ppti
)
130 ok(0, "unexpected call\n");
134 static HRESULT WINAPI
ActiveScriptSite_GetDocVersionString(IActiveScriptSite
*iface
, BSTR
*pbstrVersion
)
136 ok(0, "unexpected call\n");
140 static HRESULT WINAPI
ActiveScriptSite_OnScriptTerminate(IActiveScriptSite
*iface
,
141 const VARIANT
*pvarResult
, const EXCEPINFO
*pexcepinfo
)
143 ok(0, "unexpected call\n");
147 static HRESULT WINAPI
ActiveScriptSite_OnStateChange(IActiveScriptSite
*iface
, SCRIPTSTATE ssScriptState
)
149 switch(ssScriptState
) {
150 case SCRIPTSTATE_UNINITIALIZED
:
151 CHECK_EXPECT(OnStateChange_UNINITIALIZED
);
153 case SCRIPTSTATE_STARTED
:
154 CHECK_EXPECT(OnStateChange_STARTED
);
156 case SCRIPTSTATE_CONNECTED
:
157 CHECK_EXPECT(OnStateChange_CONNECTED
);
159 case SCRIPTSTATE_DISCONNECTED
:
160 CHECK_EXPECT(OnStateChange_DISCONNECTED
);
162 case SCRIPTSTATE_CLOSED
:
163 CHECK_EXPECT(OnStateChange_CLOSED
);
165 case SCRIPTSTATE_INITIALIZED
:
166 CHECK_EXPECT(OnStateChange_INITIALIZED
);
169 ok(0, "unexpected call %d\n", ssScriptState
);
175 static HRESULT WINAPI
ActiveScriptSite_OnScriptError(IActiveScriptSite
*iface
, IActiveScriptError
*pscripterror
)
177 ok(0, "unexpected call\n");
181 static HRESULT WINAPI
ActiveScriptSite_OnEnterScript(IActiveScriptSite
*iface
)
183 CHECK_EXPECT(OnEnterScript
);
187 static HRESULT WINAPI
ActiveScriptSite_OnLeaveScript(IActiveScriptSite
*iface
)
189 CHECK_EXPECT(OnLeaveScript
);
193 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl
= {
194 ActiveScriptSite_QueryInterface
,
195 ActiveScriptSite_AddRef
,
196 ActiveScriptSite_Release
,
197 ActiveScriptSite_GetLCID
,
198 ActiveScriptSite_GetItemInfo
,
199 ActiveScriptSite_GetDocVersionString
,
200 ActiveScriptSite_OnScriptTerminate
,
201 ActiveScriptSite_OnStateChange
,
202 ActiveScriptSite_OnScriptError
,
203 ActiveScriptSite_OnEnterScript
,
204 ActiveScriptSite_OnLeaveScript
207 static IActiveScriptSite ActiveScriptSite
= { &ActiveScriptSiteVtbl
};
209 static void test_script_dispatch(IDispatchEx
*dispex
)
211 DISPPARAMS dp
= {NULL
,NULL
,0,0};
218 str
= a2bstr("ActiveXObject");
219 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseSensitive
, &id
);
221 ok(hres
== S_OK
, "GetDispID failed: %08x\n", hres
);
223 str
= a2bstr("Math");
224 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseSensitive
, &id
);
226 ok(hres
== S_OK
, "GetDispID failed: %08x\n", hres
);
228 memset(&ei
, 0, sizeof(ei
));
229 hres
= IDispatchEx_InvokeEx(dispex
, id
, 0, DISPATCH_PROPERTYGET
, &dp
, &v
, &ei
, NULL
);
230 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
231 ok(V_VT(&v
) == VT_DISPATCH
, "V_VT(v) = %d\n", V_VT(&v
));
232 ok(V_DISPATCH(&v
) != NULL
, "V_DISPATCH(v) = NULL\n");
235 str
= a2bstr("String");
236 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseSensitive
, &id
);
238 ok(hres
== S_OK
, "GetDispID failed: %08x\n", hres
);
240 memset(&ei
, 0, sizeof(ei
));
241 hres
= IDispatchEx_InvokeEx(dispex
, id
, 0, DISPATCH_PROPERTYGET
, &dp
, &v
, &ei
, NULL
);
242 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
243 ok(V_VT(&v
) == VT_DISPATCH
, "V_VT(v) = %d\n", V_VT(&v
));
244 ok(V_DISPATCH(&v
) != NULL
, "V_DISPATCH(v) = NULL\n");
248 static IDispatchEx
*get_script_dispatch(IActiveScript
*script
)
254 disp
= (void*)0xdeadbeef;
255 hres
= IActiveScript_GetScriptDispatch(script
, NULL
, &disp
);
256 ok(hres
== S_OK
, "GetScriptDispatch failed: %08x\n", hres
);
258 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
259 IDispatch_Release(disp
);
260 ok(hres
== S_OK
, "Could not get IDispatch iface: %08x\n", hres
);
264 static void test_no_script_dispatch(IActiveScript
*script
)
269 disp
= (void*)0xdeadbeef;
270 hres
= IActiveScript_GetScriptDispatch(script
, NULL
, &disp
);
271 ok(hres
== E_UNEXPECTED
, "hres = %08x, expected E_UNEXPECTED\n", hres
);
272 ok(!disp
, "disp != NULL\n");
275 static void test_safety(IUnknown
*unk
)
277 IObjectSafety
*safety
;
278 DWORD supported
, enabled
;
281 hres
= IUnknown_QueryInterface(unk
, &IID_IObjectSafety
, (void**)&safety
);
282 ok(hres
== S_OK
, "Could not get IObjectSafety: %08x\n", hres
);
286 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_NULL
, &supported
, NULL
);
287 ok(hres
== E_POINTER
, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres
);
288 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_NULL
, NULL
, &enabled
);
289 ok(hres
== E_POINTER
, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres
);
291 supported
= enabled
= 0xdeadbeef;
292 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_NULL
, &supported
, &enabled
);
293 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
294 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
295 "supported=%x\n", supported
);
296 ok(enabled
== INTERFACE_USES_DISPEX
, "enabled=%x\n", enabled
);
298 supported
= enabled
= 0xdeadbeef;
299 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScript
, &supported
, &enabled
);
300 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
301 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
302 "supported=%x\n", supported
);
303 ok(enabled
== INTERFACE_USES_DISPEX
, "enabled=%x\n", enabled
);
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 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
,
313 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
314 |INTERFACESAFE_FOR_UNTRUSTED_CALLER
,
315 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
);
316 ok(hres
== E_FAIL
, "SetInterfaceSafetyOptions failed: %08x, expected E_FAIL\n", hres
);
318 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
,
319 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
,
320 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
);
321 ok(hres
== S_OK
, "SetInterfaceSafetyOptions failed: %08x\n", hres
);
323 supported
= enabled
= 0xdeadbeef;
324 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, &supported
, &enabled
);
325 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
326 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
327 "supported=%x\n", supported
);
328 ok(enabled
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
329 "enabled=%x\n", enabled
);
331 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, INTERFACESAFE_FOR_UNTRUSTED_DATA
, 0);
332 ok(hres
== S_OK
, "SetInterfaceSafetyOptions failed: %08x\n", hres
);
334 supported
= enabled
= 0xdeadbeef;
335 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, &supported
, &enabled
);
336 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
337 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
338 "supported=%x\n", supported
);
339 ok(enabled
== (INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
), "enabled=%x\n", enabled
);
341 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
,
342 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
, 0);
343 ok(hres
== S_OK
, "SetInterfaceSafetyOptions failed: %08x\n", hres
);
345 supported
= enabled
= 0xdeadbeef;
346 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, &supported
, &enabled
);
347 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
348 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
349 "supported=%x\n", supported
);
350 ok(enabled
== INTERFACE_USES_DISPEX
, "enabled=%x\n", enabled
);
352 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
,
353 INTERFACE_USES_DISPEX
, 0);
354 ok(hres
== S_OK
, "SetInterfaceSafetyOptions failed: %08x\n", hres
);
356 supported
= enabled
= 0xdeadbeef;
357 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, &supported
, &enabled
);
358 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
359 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
360 "supported=%x\n", supported
);
361 ok(enabled
== INTERFACE_USES_DISPEX
, "enabled=%x\n", enabled
);
363 IObjectSafety_Release(safety
);
366 static HRESULT
set_script_prop(IActiveScript
*engine
, DWORD property
, VARIANT
*val
)
368 IActiveScriptProperty
*script_prop
;
371 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptProperty
,
372 (void**)&script_prop
);
373 ok(hres
== S_OK
, "Could not get IActiveScriptProperty: %08x\n", hres
);
377 hres
= IActiveScriptProperty_SetProperty(script_prop
, property
, NULL
, val
);
378 IActiveScriptProperty_Release(script_prop
);
382 static void test_invoke_versioning(IActiveScript
*script
)
388 hres
= set_script_prop(script
, SCRIPTPROP_INVOKEVERSIONING
, &v
);
389 if(hres
== E_NOTIMPL
) {
390 win_skip("SCRIPTPROP_INVOKESTRING not supported\n");
393 ok(hres
== E_INVALIDARG
, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres
);
397 hres
= set_script_prop(script
, SCRIPTPROP_INVOKEVERSIONING
, &v
);
398 ok(hres
== E_INVALIDARG
, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres
);
402 hres
= set_script_prop(script
, SCRIPTPROP_INVOKEVERSIONING
, &v
);
403 ok(hres
== E_INVALIDARG
, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres
);
407 hres
= set_script_prop(script
, SCRIPTPROP_INVOKEVERSIONING
, &v
);
408 ok(hres
== S_OK
, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres
);
411 static IActiveScript
*create_jscript(void)
416 hres
= CoCreateInstance(engine_clsid
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
417 &IID_IActiveScript
, (void**)&ret
);
418 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
423 static void test_jscript(void)
425 IActiveScriptParse
*parse
;
426 IActiveScript
*script
;
431 script
= create_jscript();
433 hres
= IActiveScript_QueryInterface(script
, &IID_IActiveScriptParse
, (void**)&parse
);
434 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
436 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
437 test_safety((IUnknown
*)script
);
438 test_invoke_versioning(script
);
440 hres
= IActiveScriptParse64_InitNew(parse
);
441 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
443 hres
= IActiveScriptParse64_InitNew(parse
);
444 ok(hres
== E_UNEXPECTED
, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres
);
446 hres
= IActiveScript_SetScriptSite(script
, NULL
);
447 ok(hres
== E_POINTER
, "SetScriptSite failed: %08x, expected E_POINTER\n", hres
);
449 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
450 test_no_script_dispatch(script
);
453 SET_EXPECT(OnStateChange_INITIALIZED
);
454 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
455 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
456 CHECK_CALLED(GetLCID
);
457 CHECK_CALLED(OnStateChange_INITIALIZED
);
459 test_state(script
, SCRIPTSTATE_INITIALIZED
);
461 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
462 ok(hres
== E_UNEXPECTED
, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres
);
464 dispex
= get_script_dispatch(script
);
465 test_script_dispatch(dispex
);
467 SET_EXPECT(OnStateChange_STARTED
);
468 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_STARTED
);
469 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
470 CHECK_CALLED(OnStateChange_STARTED
);
472 test_state(script
, SCRIPTSTATE_STARTED
);
474 SET_EXPECT(OnStateChange_CLOSED
);
475 hres
= IActiveScript_Close(script
);
476 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
477 CHECK_CALLED(OnStateChange_CLOSED
);
479 test_state(script
, SCRIPTSTATE_CLOSED
);
480 test_no_script_dispatch(script
);
481 test_script_dispatch(dispex
);
482 IDispatchEx_Release(dispex
);
484 IUnknown_Release(parse
);
486 ref
= IActiveScript_Release(script
);
487 ok(!ref
, "ref = %d\n", ref
);
490 static void test_jscript2(void)
492 IActiveScriptParse
*parse
;
493 IActiveScript
*script
;
497 script
= create_jscript();
499 hres
= IActiveScript_QueryInterface(script
, &IID_IActiveScriptParse
, (void**)&parse
);
500 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
502 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
505 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
506 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
507 CHECK_CALLED(GetLCID
);
509 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
511 SET_EXPECT(OnStateChange_INITIALIZED
);
512 hres
= IActiveScriptParse64_InitNew(parse
);
513 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
514 CHECK_CALLED(OnStateChange_INITIALIZED
);
516 hres
= IActiveScriptParse64_InitNew(parse
);
517 ok(hres
== E_UNEXPECTED
, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres
);
519 SET_EXPECT(OnStateChange_CONNECTED
);
520 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_CONNECTED
);
521 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres
);
522 CHECK_CALLED(OnStateChange_CONNECTED
);
524 test_state(script
, SCRIPTSTATE_CONNECTED
);
526 SET_EXPECT(OnStateChange_DISCONNECTED
);
527 SET_EXPECT(OnStateChange_INITIALIZED
);
528 SET_EXPECT(OnStateChange_CLOSED
);
529 hres
= IActiveScript_Close(script
);
530 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
531 CHECK_CALLED(OnStateChange_DISCONNECTED
);
532 CHECK_CALLED(OnStateChange_INITIALIZED
);
533 CHECK_CALLED(OnStateChange_CLOSED
);
535 test_state(script
, SCRIPTSTATE_CLOSED
);
536 test_no_script_dispatch(script
);
538 IUnknown_Release(parse
);
540 ref
= IActiveScript_Release(script
);
541 ok(!ref
, "ref = %d\n", ref
);
544 static void test_jscript_uninitializing(void)
546 IActiveScriptParse
*parse
;
547 IActiveScript
*script
;
552 static const WCHAR script_textW
[] =
553 {'f','u','n','c','t','i','o','n',' ','f','(',')',' ','{','}',0};
555 script
= create_jscript();
557 hres
= IActiveScript_QueryInterface(script
, &IID_IActiveScriptParse
, (void**)&parse
);
558 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
560 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
562 hres
= IActiveScriptParse64_InitNew(parse
);
563 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
566 SET_EXPECT(OnStateChange_INITIALIZED
);
567 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
568 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
569 CHECK_CALLED(GetLCID
);
570 CHECK_CALLED(OnStateChange_INITIALIZED
);
572 test_state(script
, SCRIPTSTATE_INITIALIZED
);
574 hres
= IActiveScriptParse64_ParseScriptText(parse
, script_textW
, NULL
, NULL
, NULL
, 0, 1, 0x42, NULL
, NULL
);
575 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
577 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
578 ok(hres
== E_UNEXPECTED
, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres
);
580 SET_EXPECT(OnStateChange_UNINITIALIZED
);
581 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
582 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
583 CHECK_CALLED(OnStateChange_UNINITIALIZED
);
585 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
587 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
588 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
591 SET_EXPECT(OnStateChange_INITIALIZED
);
592 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
593 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
594 CHECK_CALLED(GetLCID
);
595 CHECK_CALLED(OnStateChange_INITIALIZED
);
597 SET_EXPECT(OnStateChange_CONNECTED
);
598 SET_EXPECT(OnEnterScript
);
599 SET_EXPECT(OnLeaveScript
);
600 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_CONNECTED
);
601 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres
);
602 CHECK_CALLED(OnStateChange_CONNECTED
);
603 CHECK_CALLED(OnEnterScript
);
604 CHECK_CALLED(OnLeaveScript
);
606 test_state(script
, SCRIPTSTATE_CONNECTED
);
608 dispex
= get_script_dispatch(script
);
609 ok(dispex
!= NULL
, "dispex == NULL\n");
610 IDispatchEx_Release(dispex
);
612 SET_EXPECT(OnStateChange_DISCONNECTED
);
613 SET_EXPECT(OnStateChange_INITIALIZED
);
614 SET_EXPECT(OnStateChange_UNINITIALIZED
);
615 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
616 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
617 CHECK_CALLED(OnStateChange_DISCONNECTED
);
618 CHECK_CALLED(OnStateChange_INITIALIZED
);
619 CHECK_CALLED(OnStateChange_UNINITIALIZED
);
621 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
623 hres
= IActiveScript_Close(script
);
624 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
626 test_state(script
, SCRIPTSTATE_CLOSED
);
628 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
629 ok(hres
== E_UNEXPECTED
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x, expected E_UNEXPECTED\n", hres
);
631 test_state(script
, SCRIPTSTATE_CLOSED
);
633 IUnknown_Release(parse
);
635 ref
= IActiveScript_Release(script
);
636 ok(!ref
, "ref = %d\n", ref
);
639 static void test_aggregation(void)
641 IUnknown
*unk
= (IUnknown
*)0xdeadbeef;
644 hres
= CoCreateInstance(&CLSID_JScript
, (IUnknown
*)0xdeadbeef, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
645 &IID_IUnknown
, (void**)&unk
);
646 ok(hres
== CLASS_E_NOAGGREGATION
|| broken(E_INVALIDARG
) /* win2k */,
647 "CoCreateInstance failed: %08x, expected CLASS_E_NOAGGREGATION\n", hres
);
648 ok(!unk
|| broken(unk
!= NULL
), "unk = %p\n", unk
);
651 static BOOL
check_jscript(void)
653 IActiveScriptProperty
*script_prop
;
656 hres
= CoCreateInstance(&CLSID_JScript
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
657 &IID_IActiveScriptProperty
, (void**)&script_prop
);
659 IActiveScriptProperty_Release(script_prop
);
668 if(check_jscript()) {
669 trace("Testing JScript object...\n");
672 test_jscript_uninitializing();
675 trace("Testing JScriptEncode object...\n");
676 engine_clsid
= &CLSID_JScriptEncode
;
679 win_skip("Broken engine, probably too old\n");