ReactOS 0.4.15-dev-8390-g075894b
jscript.c
Go to the documentation of this file.
1/*
2 * Copyright 2008 Jacek Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19#define COBJMACROS
20#define CONST_VTABLE
21
22#include <initguid.h>
23#include <ole2.h>
24#include <activscp.h>
25#include <objsafe.h>
26#include <dispex.h>
27
28#include "wine/test.h"
29
30#ifdef _WIN64
31
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
37#else
38
39#define IActiveScriptParse_QueryInterface IActiveScriptParse32_QueryInterface
40#define IActiveScriptParse_Release IActiveScriptParse32_Release
41#define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
42#define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
43
44#endif
45
46DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
47
48static const CLSID CLSID_JScript =
49 {0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
51 {0xf414c262,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
52
53#define DEFINE_EXPECT(func) \
54 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
55
56#define SET_EXPECT(func) \
57 expect_ ## func = TRUE
58
59#define CHECK_EXPECT2(func) \
60 do { \
61 ok(expect_ ##func, "unexpected call " #func "\n"); \
62 called_ ## func = TRUE; \
63 }while(0)
64
65#define CHECK_EXPECT(func) \
66 do { \
67 CHECK_EXPECT2(func); \
68 expect_ ## func = FALSE; \
69 }while(0)
70
71#define CHECK_CALLED(func) \
72 do { \
73 ok(called_ ## func, "expected " #func "\n"); \
74 expect_ ## func = called_ ## func = FALSE; \
75 }while(0)
76
78DEFINE_EXPECT(OnStateChange_UNINITIALIZED);
79DEFINE_EXPECT(OnStateChange_STARTED);
80DEFINE_EXPECT(OnStateChange_CONNECTED);
81DEFINE_EXPECT(OnStateChange_DISCONNECTED);
82DEFINE_EXPECT(OnStateChange_CLOSED);
83DEFINE_EXPECT(OnStateChange_INITIALIZED);
84DEFINE_EXPECT(OnEnterScript);
85DEFINE_EXPECT(OnLeaveScript);
86
88
89static BSTR a2bstr(const char *str)
90{
91 BSTR ret;
92 int len;
93
94 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
97
98 return ret;
99}
100
101#define test_state(s,ss) _test_state(__LINE__,s,ss)
102static void _test_state(unsigned line, IActiveScript *script, SCRIPTSTATE exstate)
103{
104 SCRIPTSTATE state = -1;
106
107 hres = IActiveScript_GetScriptState(script, &state);
108 ok_(__FILE__,line) (hres == S_OK, "GetScriptState failed: %08x\n", hres);
109 ok_(__FILE__,line) (state == exstate, "state=%d, expected %d\n", state, exstate);
110}
111
113{
114 *ppv = NULL;
115
117 *ppv = iface;
118 else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
119 *ppv = iface;
120 else
121 return E_NOINTERFACE;
122
123 IUnknown_AddRef((IUnknown*)*ppv);
124 return S_OK;
125}
126
128{
129 return 2;
130}
131
133{
134 return 1;
135}
136
138{
139 CHECK_EXPECT(GetLCID);
140 return E_NOTIMPL;
141}
142
144 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
145{
146 ok(0, "unexpected call\n");
147 return E_NOTIMPL;
148}
149
151{
152 ok(0, "unexpected call\n");
153 return E_NOTIMPL;
154}
155
157 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
158{
159 ok(0, "unexpected call\n");
160 return E_NOTIMPL;
161}
162
164{
165 switch(ssScriptState) {
167 CHECK_EXPECT(OnStateChange_UNINITIALIZED);
168 return S_OK;
170 CHECK_EXPECT(OnStateChange_STARTED);
171 return S_OK;
173 CHECK_EXPECT(OnStateChange_CONNECTED);
174 return S_OK;
176 CHECK_EXPECT(OnStateChange_DISCONNECTED);
177 return S_OK;
179 CHECK_EXPECT(OnStateChange_CLOSED);
180 return S_OK;
182 CHECK_EXPECT(OnStateChange_INITIALIZED);
183 return S_OK;
184 default:
185 ok(0, "unexpected call %d\n", ssScriptState);
186 }
187
188 return E_NOTIMPL;
189}
190
192{
193 ok(0, "unexpected call\n");
194 return E_NOTIMPL;
195}
196
198{
199 CHECK_EXPECT(OnEnterScript);
200 return S_OK;
201}
202
204{
205 CHECK_EXPECT(OnLeaveScript);
206 return S_OK;
207}
208
209static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
221};
222
224
226{
227 DISPPARAMS dp = {NULL,NULL,0,0};
228 EXCEPINFO ei;
229 BSTR str;
230 DISPID id;
231 VARIANT v;
233
234 str = a2bstr("ActiveXObject");
235 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
237 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
238
239 str = a2bstr("Math");
240 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
242 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
243
244 memset(&ei, 0, sizeof(ei));
245 hres = IDispatchEx_InvokeEx(dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
246 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
247 ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v));
248 ok(V_DISPATCH(&v) != NULL, "V_DISPATCH(v) = NULL\n");
249 VariantClear(&v);
250
251 str = a2bstr("String");
252 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
254 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
255
256 memset(&ei, 0, sizeof(ei));
257 hres = IDispatchEx_InvokeEx(dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
258 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
259 ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v));
260 ok(V_DISPATCH(&v) != NULL, "V_DISPATCH(v) = NULL\n");
261 VariantClear(&v);
262}
263
265{
266 IDispatchEx *dispex;
267 IDispatch *disp;
269
270 disp = (void*)0xdeadbeef;
271 hres = IActiveScript_GetScriptDispatch(script, NULL, &disp);
272 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
273
274 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
275 IDispatch_Release(disp);
276 ok(hres == S_OK, "Could not get IDispatch iface: %08x\n", hres);
277 return dispex;
278}
279
281{
282 IDispatch *disp;
284
285 disp = (void*)0xdeadbeef;
286 hres = IActiveScript_GetScriptDispatch(script, NULL, &disp);
287 ok(hres == E_UNEXPECTED, "hres = %08x, expected E_UNEXPECTED\n", hres);
288 ok(!disp, "disp != NULL\n");
289}
290
291static void test_safety(IUnknown *unk)
292{
293 IObjectSafety *safety;
294 DWORD supported, enabled;
296
297 hres = IUnknown_QueryInterface(unk, &IID_IObjectSafety, (void**)&safety);
298 ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
299 if(FAILED(hres))
300 return;
301
302 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, &supported, NULL);
303 ok(hres == E_POINTER, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres);
304 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, NULL, &enabled);
305 ok(hres == E_POINTER, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres);
306
307 supported = enabled = 0xdeadbeef;
308 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, &supported, &enabled);
309 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
310 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
311 "supported=%x\n", supported);
312 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
313
314 supported = enabled = 0xdeadbeef;
315 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScript, &supported, &enabled);
316 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
317 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
318 "supported=%x\n", supported);
319 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
320
321 supported = enabled = 0xdeadbeef;
322 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
323 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
324 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
325 "supported=%x\n", supported);
326 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
327
328 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
329 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER
330 |INTERFACESAFE_FOR_UNTRUSTED_CALLER,
331 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
332 ok(hres == E_FAIL, "SetInterfaceSafetyOptions failed: %08x, expected E_FAIL\n", hres);
333
334 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
335 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER,
336 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
337 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
338
339 supported = enabled = 0xdeadbeef;
340 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
341 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
342 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
343 "supported=%x\n", supported);
344 ok(enabled == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
345 "enabled=%x\n", enabled);
346
347 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, INTERFACESAFE_FOR_UNTRUSTED_DATA, 0);
348 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
349
350 supported = enabled = 0xdeadbeef;
351 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
352 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
353 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
354 "supported=%x\n", supported);
355 ok(enabled == (INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER), "enabled=%x\n", enabled);
356
357 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
358 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER, 0);
359 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
360
361 supported = enabled = 0xdeadbeef;
362 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
363 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
364 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
365 "supported=%x\n", supported);
366 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
367
368 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
369 INTERFACE_USES_DISPEX, 0);
370 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
371
372 supported = enabled = 0xdeadbeef;
373 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
374 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
375 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
376 "supported=%x\n", supported);
377 ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
378
379 IObjectSafety_Release(safety);
380}
381
383{
384 IActiveScriptProperty *script_prop;
386
387 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptProperty,
388 (void**)&script_prop);
389 ok(hres == S_OK, "Could not get IActiveScriptProperty: %08x\n", hres);
390 if(FAILED(hres))
391 return hres;
392
393 hres = IActiveScriptProperty_SetProperty(script_prop, property, NULL, val);
394 IActiveScriptProperty_Release(script_prop);
395 return hres;
396}
397
399{
400 VARIANT v;
402
403 V_VT(&v) = VT_NULL;
404 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
405 if(hres == E_NOTIMPL) {
406 win_skip("SCRIPTPROP_INVOKESTRING not supported\n");
407 return;
408 }
409 ok(hres == E_INVALIDARG, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
410
411 V_VT(&v) = VT_I2;
412 V_I2(&v) = 0;
413 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
414 ok(hres == E_INVALIDARG, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
415
416 V_VT(&v) = VT_I4;
417 V_I4(&v) = 16;
418 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
419 ok(hres == E_INVALIDARG, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
420
421 V_VT(&v) = VT_I4;
422 V_I4(&v) = 2;
423 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
424 ok(hres == S_OK, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
425}
426
428{
431
432 hres = CoCreateInstance(engine_clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
433 &IID_IActiveScript, (void**)&ret);
434 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
435
436 return ret;
437}
438
439static void test_jscript(void)
440{
441 IActiveScriptParse *parse;
443 IDispatchEx *dispex;
444 ULONG ref;
446
448
449 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
450 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
451
455
457 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
458
460 ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres);
461
462 hres = IActiveScript_SetScriptSite(script, NULL);
463 ok(hres == E_POINTER, "SetScriptSite failed: %08x, expected E_POINTER\n", hres);
464
467
468 SET_EXPECT(GetLCID);
469 SET_EXPECT(OnStateChange_INITIALIZED);
470 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
471 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
472 CHECK_CALLED(GetLCID);
473 CHECK_CALLED(OnStateChange_INITIALIZED);
474
476
477 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
478 ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres);
479
480 dispex = get_script_dispatch(script);
481 test_script_dispatch(dispex);
482
483 SET_EXPECT(OnStateChange_STARTED);
484 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED);
485 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
486 CHECK_CALLED(OnStateChange_STARTED);
487
489
490 SET_EXPECT(OnStateChange_CLOSED);
491 hres = IActiveScript_Close(script);
492 ok(hres == S_OK, "Close failed: %08x\n", hres);
493 CHECK_CALLED(OnStateChange_CLOSED);
494
497 test_script_dispatch(dispex);
498 IDispatchEx_Release(dispex);
499
501
502 ref = IActiveScript_Release(script);
503 ok(!ref, "ref = %d\n", ref);
504}
505
506static void test_jscript2(void)
507{
508 IActiveScriptParse *parse;
510 ULONG ref;
512
514
515 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
516 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
517
519
520 SET_EXPECT(GetLCID);
521 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
522 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
523 CHECK_CALLED(GetLCID);
524
526
527 SET_EXPECT(OnStateChange_INITIALIZED);
529 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
530 CHECK_CALLED(OnStateChange_INITIALIZED);
531
533 ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres);
534
535 SET_EXPECT(OnStateChange_CONNECTED);
536 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
537 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
538 CHECK_CALLED(OnStateChange_CONNECTED);
539
541
542 SET_EXPECT(OnStateChange_DISCONNECTED);
543 SET_EXPECT(OnStateChange_INITIALIZED);
544 SET_EXPECT(OnStateChange_CLOSED);
545 hres = IActiveScript_Close(script);
546 ok(hres == S_OK, "Close failed: %08x\n", hres);
547 CHECK_CALLED(OnStateChange_DISCONNECTED);
548 CHECK_CALLED(OnStateChange_INITIALIZED);
549 CHECK_CALLED(OnStateChange_CLOSED);
550
553
555
556 ref = IActiveScript_Release(script);
557 ok(!ref, "ref = %d\n", ref);
558}
559
561{
562 IActiveScriptParse *parse;
564 IDispatchEx *dispex;
565 ULONG ref;
567
568 static const WCHAR script_textW[] =
569 {'f','u','n','c','t','i','o','n',' ','f','(',')',' ','{','}',0};
570
572
573 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
574 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
575
577
579 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
580
581 SET_EXPECT(GetLCID);
582 SET_EXPECT(OnStateChange_INITIALIZED);
583 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
584 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
585 CHECK_CALLED(GetLCID);
586 CHECK_CALLED(OnStateChange_INITIALIZED);
587
589
590 hres = IActiveScriptParse_ParseScriptText(parse, script_textW, NULL, NULL, NULL, 0, 1, 0x42, NULL, NULL);
591 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
592
593 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
594 ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres);
595
596 SET_EXPECT(OnStateChange_UNINITIALIZED);
597 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
598 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
599 CHECK_CALLED(OnStateChange_UNINITIALIZED);
600
602
603 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
604 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
605
606 SET_EXPECT(GetLCID);
607 SET_EXPECT(OnStateChange_INITIALIZED);
608 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
609 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
610 CHECK_CALLED(GetLCID);
611 CHECK_CALLED(OnStateChange_INITIALIZED);
612
613 SET_EXPECT(OnStateChange_CONNECTED);
614 SET_EXPECT(OnEnterScript);
615 SET_EXPECT(OnLeaveScript);
616 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
617 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
618 CHECK_CALLED(OnStateChange_CONNECTED);
619 CHECK_CALLED(OnEnterScript);
620 CHECK_CALLED(OnLeaveScript);
621
623
624 dispex = get_script_dispatch(script);
625 ok(dispex != NULL, "dispex == NULL\n");
626 IDispatchEx_Release(dispex);
627
628 SET_EXPECT(OnStateChange_DISCONNECTED);
629 SET_EXPECT(OnStateChange_INITIALIZED);
630 SET_EXPECT(OnStateChange_UNINITIALIZED);
631 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
632 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
633 CHECK_CALLED(OnStateChange_DISCONNECTED);
634 CHECK_CALLED(OnStateChange_INITIALIZED);
635 CHECK_CALLED(OnStateChange_UNINITIALIZED);
636
638
639 hres = IActiveScript_Close(script);
640 ok(hres == S_OK, "Close failed: %08x\n", hres);
641
643
644 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
645 ok(hres == E_UNEXPECTED, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x, expected E_UNEXPECTED\n", hres);
646
648
650
651 ref = IActiveScript_Release(script);
652 ok(!ref, "ref = %d\n", ref);
653}
654
655static void test_aggregation(void)
656{
657 IUnknown *unk = (IUnknown*)0xdeadbeef;
659
660 hres = CoCreateInstance(&CLSID_JScript, (IUnknown*)0xdeadbeef, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
661 &IID_IUnknown, (void**)&unk);
663 "CoCreateInstance failed: %08x, expected CLASS_E_NOAGGREGATION\n", hres);
664 ok(!unk || broken(unk != NULL), "unk = %p\n", unk);
665}
666
667static BOOL check_jscript(void)
668{
669 IActiveScriptProperty *script_prop;
671
672 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
673 &IID_IActiveScriptProperty, (void**)&script_prop);
674 if(SUCCEEDED(hres))
675 IActiveScriptProperty_Release(script_prop);
676
677 return hres == S_OK;
678}
679
681{
683
684 if(check_jscript()) {
685 trace("Testing JScript object...\n");
686 test_jscript();
690
691 trace("Testing JScriptEncode object...\n");
693 test_jscript();
694 }else {
695 win_skip("Broken engine, probably too old\n");
696 }
697
699}
#define broken(x)
Definition: _sntprintf.h:21
@ SCRIPTSTATE_INITIALIZED
Definition: activscp.idl:62
@ SCRIPTSTATE_DISCONNECTED
Definition: activscp.idl:60
@ SCRIPTSTATE_STARTED
Definition: activscp.idl:58
@ SCRIPTSTATE_UNINITIALIZED
Definition: activscp.idl:57
@ SCRIPTSTATE_CLOSED
Definition: activscp.idl:61
@ SCRIPTSTATE_CONNECTED
Definition: activscp.idl:59
enum tagSCRIPTSTATE SCRIPTSTATE
static int state
Definition: maze.c:121
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ok_(x1, x2)
Definition: atltest.h:61
const GUID IID_IUnknown
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define CP_ACP
Definition: compat.h:109
OLECHAR * BSTR
Definition: compat.h:2293
#define MultiByteToWideChar
Definition: compat.h:110
@ VT_NULL
Definition: compat.h:2296
@ VT_I4
Definition: compat.h:2298
@ VT_I2
Definition: compat.h:2297
@ VT_DISPATCH
Definition: compat.h:2304
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
const GLdouble * v
Definition: gl.h:2040
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glext.h:7750
GLuint GLfloat * val
Definition: glext.h:7180
GLenum GLsizei len
Definition: glext.h:6722
GLuint id
Definition: glext.h:5910
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define GUID_NULL
Definition: ks.h:106
HRESULT hres
Definition: protocol.c:465
static BOOL check_jscript(void)
Definition: jscript.c:667
#define SET_EXPECT(func)
Definition: jscript.c:56
static IActiveScript * create_jscript(void)
Definition: jscript.c:427
static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
Definition: jscript.c:132
static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
Definition: jscript.c:203
static void test_invoke_versioning(IActiveScript *script)
Definition: jscript.c:398
static void test_jscript_uninitializing(void)
Definition: jscript.c:560
static void test_aggregation(void)
Definition: jscript.c:655
static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
Definition: jscript.c:163
static const CLSID CLSID_JScript
Definition: jscript.c:48
static void test_script_dispatch(IDispatchEx *dispex)
Definition: jscript.c:225
#define CHECK_EXPECT(func)
Definition: jscript.c:65
static void test_jscript(void)
Definition: jscript.c:439
static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
Definition: jscript.c:150
static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName, DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
Definition: jscript.c:143
#define DEFINE_EXPECT(func)
Definition: jscript.c:53
#define IActiveScriptParse_InitNew
Definition: jscript.c:41
#define IActiveScriptParse_ParseScriptText
Definition: jscript.c:42
#define IActiveScriptParse_Release
Definition: jscript.c:40
static BSTR a2bstr(const char *str)
Definition: jscript.c:89
#define test_state(s, ss)
Definition: jscript.c:101
static void _test_state(unsigned line, IActiveScript *script, SCRIPTSTATE exstate)
Definition: jscript.c:102
static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
Definition: jscript.c:112
static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
Definition: jscript.c:197
#define CHECK_CALLED(func)
Definition: jscript.c:71
static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
Definition: jscript.c:127
static const CLSID CLSID_JScriptEncode
Definition: jscript.c:50
static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface, const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
Definition: jscript.c:156
static void test_safety(IUnknown *unk)
Definition: jscript.c:291
static void test_no_script_dispatch(IActiveScript *script)
Definition: jscript.c:280
static void test_jscript2(void)
Definition: jscript.c:506
static const CLSID * engine_clsid
Definition: jscript.c:87
static IDispatchEx * get_script_dispatch(IActiveScript *script)
Definition: jscript.c:264
static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl
Definition: jscript.c:209
static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
Definition: jscript.c:137
static HRESULT set_script_prop(IActiveScript *engine, DWORD property, VARIANT *val)
Definition: jscript.c:382
static IActiveScriptSite ActiveScriptSite
Definition: jscript.c:223
static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
Definition: jscript.c:191
static VARIANTARG static DISPID
Definition: ordinal.c:52
script
Definition: msipriv.h:383
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:339
#define V_VT(A)
Definition: oleauto.h:211
#define V_I4(A)
Definition: oleauto.h:247
#define V_DISPATCH(A)
Definition: oleauto.h:239
#define DISPATCH_PROPERTYGET
Definition: oleauto.h:1007
#define V_I2(A)
Definition: oleauto.h:245
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
Definition: guiddef.h:68
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
#define IID_NULL
Definition: guiddef.h:98
const WCHAR * str
DWORD LCID
Definition: nls.h:13
#define win_skip
Definition: test.h:163
#define memset(x, y, z)
Definition: compat.h:39
Definition: parser.c:49
Definition: send.c:48
uint32_t ULONG
Definition: typedefs.h:59
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
int ret
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:2364
#define CLASS_E_NOAGGREGATION
Definition: winerror.h:2662
#define E_UNEXPECTED
Definition: winerror.h:2456
#define E_POINTER
Definition: winerror.h:2365
__wchar_t WCHAR
Definition: xmlstorage.h:180