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 static const CLSID CLSID_JScript
=
31 {0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
33 #define DEFINE_EXPECT(func) \
34 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
36 #define SET_EXPECT(func) \
37 expect_ ## func = TRUE
39 #define SET_CALLED(func) \
40 called_ ## func = TRUE
42 #define CHECK_EXPECT2(func) \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
48 #define CHECK_EXPECT(func) \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
54 #define CHECK_CALLED(func) \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
60 DEFINE_EXPECT(global_propget_d
);
61 DEFINE_EXPECT(global_propget_i
);
62 DEFINE_EXPECT(global_propput_d
);
63 DEFINE_EXPECT(global_propput_i
);
64 DEFINE_EXPECT(global_success_d
);
65 DEFINE_EXPECT(global_success_i
);
66 DEFINE_EXPECT(global_notexists_d
);
67 DEFINE_EXPECT(testobj_delete
);
68 DEFINE_EXPECT(testobj_value
);
69 DEFINE_EXPECT(testobj_prop_d
);
70 DEFINE_EXPECT(testobj_noprop_d
);
71 DEFINE_EXPECT(GetItemInfo_testVal
);
73 #define DISPID_GLOBAL_TESTPROPGET 0x1000
74 #define DISPID_GLOBAL_TESTPROPPUT 0x1001
75 #define DISPID_GLOBAL_REPORTSUCCESS 0x1002
76 #define DISPID_GLOBAL_TRACE 0x1003
77 #define DISPID_GLOBAL_OK 0x1004
78 #define DISPID_GLOBAL_GETVT 0x1005
79 #define DISPID_GLOBAL_TESTOBJ 0x1006
80 #define DISPID_GLOBAL_NULL_BSTR 0x1007
81 #define DISPID_GLOBAL_NULL_DISP 0x1008
82 #define DISPID_GLOBAL_TESTTHIS 0x1009
83 #define DISPID_GLOBAL_TESTTHIS2 0x100a
84 #define DISPID_GLOBAL_INVOKEVERSION 0x100b
86 #define DISPID_TESTOBJ_PROP 0x2000
88 static const WCHAR testW
[] = {'t','e','s','t',0};
89 static const CHAR testA
[] = "test";
90 static const WCHAR test_valW
[] = {'t','e','s','t','V','a','l',0};
91 static const CHAR test_valA
[] = "testVal";
93 static BOOL strict_dispid_check
;
94 static const char *test_name
= "(null)";
95 static IDispatch
*script_disp
;
96 static int invoke_version
;
98 static BSTR
a2bstr(const char *str
)
103 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
104 ret
= SysAllocStringLen(NULL
, len
-1);
105 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
110 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
113 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), 0, 0);
114 return lstrcmpA(buf
, stra
);
117 #define test_grfdex(a,b) _test_grfdex(__LINE__,a,b)
118 static void _test_grfdex(unsigned line
, DWORD grfdex
, DWORD expect
)
120 expect
|= invoke_version
<< 28;
121 ok_(__FILE__
,line
)(grfdex
== expect
, "grfdex = %x, expected %x\n", grfdex
, expect
);
124 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
128 if(IsEqualGUID(riid
, &IID_IUnknown
)
129 || IsEqualGUID(riid
, &IID_IDispatch
)
130 || IsEqualGUID(riid
, &IID_IDispatchEx
))
133 return E_NOINTERFACE
;
138 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
143 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
148 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
150 ok(0, "unexpected call\n");
154 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
155 LCID lcid
, ITypeInfo
**ppTInfo
)
157 ok(0, "unexpected call\n");
161 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
162 LPOLESTR
*rgszNames
, UINT cNames
,
163 LCID lcid
, DISPID
*rgDispId
)
165 ok(0, "unexpected call\n");
169 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
170 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
171 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
173 ok(0, "unexpected call\n");
177 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
179 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName
), grfdex
);
183 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
185 ok(0, "unexpected call\n");
189 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
191 ok(0, "unexpected call\n");
195 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
197 ok(0, "unexpected call\n");
201 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
203 ok(0, "unexpected call\n");
207 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
209 ok(0, "unexpected call\n");
213 static HRESULT WINAPI
testObj_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
215 if(!strcmp_wa(bstrName
, "prop")) {
216 CHECK_EXPECT(testobj_prop_d
);
217 test_grfdex(grfdex
, fdexNameCaseSensitive
);
218 *pid
= DISPID_TESTOBJ_PROP
;
221 if(!strcmp_wa(bstrName
, "noprop")) {
222 CHECK_EXPECT(testobj_noprop_d
);
223 test_grfdex(grfdex
, fdexNameCaseSensitive
);
224 return DISP_E_UNKNOWNNAME
;
227 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName
));
231 static HRESULT WINAPI
testObj_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
232 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
236 CHECK_EXPECT(testobj_value
);
238 ok(wFlags
== INVOKE_PROPERTYGET
, "wFlags = %x\n", wFlags
);
239 ok(pdp
!= NULL
, "pdp == NULL\n");
240 ok(!pdp
->rgvarg
, "rgvarg != NULL\n");
241 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
242 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
243 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
244 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
245 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
246 ok(pei
!= NULL
, "pei == NULL\n");
248 V_VT(pvarRes
) = VT_I4
;
253 ok(0, "unexpected call %x\n", id
);
254 return DISP_E_MEMBERNOTFOUND
;
257 static HRESULT WINAPI
testObj_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
259 CHECK_EXPECT(testobj_delete
);
261 ok(!strcmp_wa(bstrName
, "deleteTest"), "unexpected name %s\n", wine_dbgstr_w(bstrName
));
262 test_grfdex(grfdex
, fdexNameCaseSensitive
);
266 static IDispatchExVtbl testObjVtbl
= {
267 DispatchEx_QueryInterface
,
270 DispatchEx_GetTypeInfoCount
,
271 DispatchEx_GetTypeInfo
,
272 DispatchEx_GetIDsOfNames
,
276 testObj_DeleteMemberByName
,
277 DispatchEx_DeleteMemberByDispID
,
278 DispatchEx_GetMemberProperties
,
279 DispatchEx_GetMemberName
,
280 DispatchEx_GetNextDispID
,
281 DispatchEx_GetNameSpaceParent
284 static IDispatchEx testObj
= { &testObjVtbl
};
286 static HRESULT WINAPI
Global_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
288 if(!strcmp_wa(bstrName
, "ok")) {
289 test_grfdex(grfdex
, fdexNameCaseSensitive
);
290 *pid
= DISPID_GLOBAL_OK
;
293 if(!strcmp_wa(bstrName
, "trace")) {
294 test_grfdex(grfdex
, fdexNameCaseSensitive
);
295 *pid
= DISPID_GLOBAL_TRACE
;
298 if(!strcmp_wa(bstrName
, "reportSuccess")) {
299 CHECK_EXPECT(global_success_d
);
300 test_grfdex(grfdex
, fdexNameCaseSensitive
);
301 *pid
= DISPID_GLOBAL_REPORTSUCCESS
;
304 if(!strcmp_wa(bstrName
, "testPropGet")) {
305 CHECK_EXPECT(global_propget_d
);
306 test_grfdex(grfdex
, fdexNameCaseSensitive
);
307 *pid
= DISPID_GLOBAL_TESTPROPGET
;
310 if(!strcmp_wa(bstrName
, "testPropPut")) {
311 CHECK_EXPECT(global_propput_d
);
312 test_grfdex(grfdex
, fdexNameCaseSensitive
);
313 *pid
= DISPID_GLOBAL_TESTPROPPUT
;
316 if(!strcmp_wa(bstrName
, "getVT")) {
317 test_grfdex(grfdex
, fdexNameCaseSensitive
);
318 *pid
= DISPID_GLOBAL_GETVT
;
321 if(!strcmp_wa(bstrName
, "testObj")) {
322 test_grfdex(grfdex
, fdexNameCaseSensitive
);
323 *pid
= DISPID_GLOBAL_TESTOBJ
;
326 if(!strcmp_wa(bstrName
, "createNullBSTR")) {
327 *pid
= DISPID_GLOBAL_NULL_BSTR
;
330 if(!strcmp_wa(bstrName
, "nullDisp")) {
331 *pid
= DISPID_GLOBAL_NULL_DISP
;
334 if(!strcmp_wa(bstrName
, "notExists")) {
335 CHECK_EXPECT(global_notexists_d
);
336 test_grfdex(grfdex
, fdexNameCaseSensitive
);
337 return DISP_E_UNKNOWNNAME
;
340 if(!strcmp_wa(bstrName
, "testThis")) {
341 test_grfdex(grfdex
, fdexNameCaseSensitive
);
342 *pid
= DISPID_GLOBAL_TESTTHIS
;
346 if(!strcmp_wa(bstrName
, "testThis2")) {
347 test_grfdex(grfdex
, fdexNameCaseSensitive
);
348 *pid
= DISPID_GLOBAL_TESTTHIS2
;
352 if(!strcmp_wa(bstrName
, "invokeVersion")) {
353 test_grfdex(grfdex
, fdexNameCaseSensitive
);
354 *pid
= DISPID_GLOBAL_INVOKEVERSION
;
358 if(strict_dispid_check
)
359 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName
));
360 return DISP_E_UNKNOWNNAME
;
363 static HRESULT WINAPI
Global_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
364 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
367 case DISPID_GLOBAL_OK
:
368 ok(wFlags
== INVOKE_FUNC
|| wFlags
== (INVOKE_FUNC
|INVOKE_PROPERTYGET
), "wFlags = %x\n", wFlags
);
369 ok(pdp
!= NULL
, "pdp == NULL\n");
370 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
371 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
372 ok(pdp
->cArgs
== 2, "cArgs = %d\n", pdp
->cArgs
);
373 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
374 if(wFlags
& INVOKE_PROPERTYGET
)
375 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
377 ok(!pvarRes
, "pvarRes != NULL\n");
378 ok(pei
!= NULL
, "pei == NULL\n");
380 ok(V_VT(pdp
->rgvarg
) == VT_BSTR
, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp
->rgvarg
));
381 ok(V_VT(pdp
->rgvarg
+1) == VT_BOOL
, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp
->rgvarg
));
382 ok(V_BOOL(pdp
->rgvarg
+1), "%s: %s\n", test_name
, wine_dbgstr_w(V_BSTR(pdp
->rgvarg
)));
386 case DISPID_GLOBAL_TRACE
:
387 ok(wFlags
== INVOKE_FUNC
, "wFlags = %x\n", wFlags
);
388 ok(pdp
!= NULL
, "pdp == NULL\n");
389 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
390 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
391 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
392 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
393 ok(!pvarRes
, "pvarRes != NULL\n");
394 ok(pei
!= NULL
, "pei == NULL\n");
396 ok(V_VT(pdp
->rgvarg
) == VT_BSTR
, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp
->rgvarg
));
397 if(V_VT(pdp
->rgvarg
) == VT_BSTR
)
398 trace("%s: %s\n", test_name
, wine_dbgstr_w(V_BSTR(pdp
->rgvarg
)));
402 case DISPID_GLOBAL_REPORTSUCCESS
:
403 CHECK_EXPECT(global_success_i
);
405 ok(wFlags
== INVOKE_FUNC
, "wFlags = %x\n", wFlags
);
406 ok(pdp
!= NULL
, "pdp == NULL\n");
407 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
408 ok(pdp
->cArgs
== 0, "cArgs = %d\n", pdp
->cArgs
);
409 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
410 ok(!pvarRes
, "pvarRes != NULL\n");
411 ok(pei
!= NULL
, "pei == NULL\n");
415 case DISPID_GLOBAL_TESTPROPGET
:
416 CHECK_EXPECT(global_propget_i
);
418 ok(wFlags
== INVOKE_PROPERTYGET
, "wFlags = %x\n", wFlags
);
419 ok(pdp
!= NULL
, "pdp == NULL\n");
420 ok(!pdp
->rgvarg
, "rgvarg != NULL\n");
421 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
422 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
423 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
424 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
425 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
426 ok(pei
!= NULL
, "pei == NULL\n");
428 V_VT(pvarRes
) = VT_I4
;
433 case DISPID_GLOBAL_TESTPROPPUT
:
434 CHECK_EXPECT(global_propput_i
);
436 ok(wFlags
== INVOKE_PROPERTYPUT
, "wFlags = %x\n", wFlags
);
437 ok(pdp
!= NULL
, "pdp == NULL\n");
438 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
439 ok(pdp
->rgdispidNamedArgs
!= NULL
, "rgdispidNamedArgs == NULL\n");
440 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
441 ok(pdp
->cNamedArgs
== 1, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
442 ok(pdp
->rgdispidNamedArgs
[0] == DISPID_PROPERTYPUT
, "pdp->rgdispidNamedArgs[0] = %d\n", pdp
->rgdispidNamedArgs
[0]);
443 ok(!pvarRes
, "pvarRes != NULL\n");
445 ok(V_VT(pdp
->rgvarg
) == VT_I4
, "V_VT(pdp->rgvarg)=%d\n", V_VT(pdp
->rgvarg
));
446 ok(V_I4(pdp
->rgvarg
) == 1, "V_I4(pdp->rgvarg)=%d\n", V_I4(pdp
->rgvarg
));
449 case DISPID_GLOBAL_GETVT
:
450 ok(pdp
!= NULL
, "pdp == NULL\n");
451 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
452 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
453 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
454 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
455 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
456 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
457 ok(pei
!= NULL
, "pei == NULL\n");
459 V_VT(pvarRes
) = VT_BSTR
;
460 switch(V_VT(pdp
->rgvarg
)) {
462 V_BSTR(pvarRes
) = a2bstr("VT_EMPTY");
465 V_BSTR(pvarRes
) = a2bstr("VT_NULL");
468 V_BSTR(pvarRes
) = a2bstr("VT_I4");
471 V_BSTR(pvarRes
) = a2bstr("VT_R8");
474 V_BSTR(pvarRes
) = a2bstr("VT_BSTR");
477 V_BSTR(pvarRes
) = a2bstr("VT_DISPATCH");
480 V_BSTR(pvarRes
) = a2bstr("VT_BOOL");
483 ok(0, "unknown vt %d\n", V_VT(pdp
->rgvarg
));
489 case DISPID_GLOBAL_TESTOBJ
:
490 ok(wFlags
== INVOKE_PROPERTYGET
, "wFlags = %x\n", wFlags
);
491 ok(pdp
!= NULL
, "pdp == NULL\n");
492 ok(!pdp
->rgvarg
, "rgvarg != NULL\n");
493 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
494 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
495 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
496 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
497 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
498 ok(pei
!= NULL
, "pei == NULL\n");
500 V_VT(pvarRes
) = VT_DISPATCH
;
501 V_DISPATCH(pvarRes
) = (IDispatch
*)&testObj
;
504 case DISPID_GLOBAL_NULL_BSTR
:
506 V_VT(pvarRes
) = VT_BSTR
;
507 V_BSTR(pvarRes
) = NULL
;
511 case DISPID_GLOBAL_NULL_DISP
:
512 ok(wFlags
== INVOKE_PROPERTYGET
, "wFlags = %x\n", wFlags
);
513 ok(pdp
!= NULL
, "pdp == NULL\n");
514 ok(!pdp
->rgvarg
, "rgvarg != NULL\n");
515 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
516 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
517 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
518 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
519 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
520 ok(pei
!= NULL
, "pei == NULL\n");
522 V_VT(pvarRes
) = VT_DISPATCH
;
523 V_DISPATCH(pvarRes
) = NULL
;
526 case DISPID_GLOBAL_TESTTHIS
:
527 ok(pdp
!= NULL
, "pdp == NULL\n");
528 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
529 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
530 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
531 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
532 ok(pvarRes
== NULL
, "pvarRes != NULL\n");
533 ok(pei
!= NULL
, "pei == NULL\n");
535 ok(V_VT(pdp
->rgvarg
) == VT_DISPATCH
, "V_VT(arg) = %d\n", V_VT(pdp
->rgvarg
));
536 ok(V_DISPATCH(pdp
->rgvarg
) == (IDispatch
*)iface
, "disp != iface\n");
540 case DISPID_GLOBAL_TESTTHIS2
:
541 ok(pdp
!= NULL
, "pdp == NULL\n");
542 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
543 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
544 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
545 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
546 ok(pvarRes
== NULL
, "pvarRes != NULL\n");
547 ok(pei
!= NULL
, "pei == NULL\n");
549 ok(V_VT(pdp
->rgvarg
) == VT_DISPATCH
, "V_VT(arg) = %d\n", V_VT(pdp
->rgvarg
));
550 ok(V_DISPATCH(pdp
->rgvarg
) != (IDispatch
*)iface
, "disp == iface\n");
551 ok(V_DISPATCH(pdp
->rgvarg
) == script_disp
, "disp != script_disp\n");
555 case DISPID_GLOBAL_INVOKEVERSION
:
556 ok(wFlags
== INVOKE_PROPERTYGET
, "wFlags = %x\n", wFlags
);
557 ok(pdp
!= NULL
, "pdp == NULL\n");
558 ok(!pdp
->rgvarg
, "rgvarg != NULL\n");
559 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
560 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
561 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
562 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
563 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
564 ok(pei
!= NULL
, "pei == NULL\n");
566 V_VT(pvarRes
) = VT_I4
;
567 V_I4(pvarRes
) = invoke_version
;
573 ok(0, "unexpected call %x\n", id
);
574 return DISP_E_MEMBERNOTFOUND
;
577 static IDispatchExVtbl GlobalVtbl
= {
578 DispatchEx_QueryInterface
,
581 DispatchEx_GetTypeInfoCount
,
582 DispatchEx_GetTypeInfo
,
583 DispatchEx_GetIDsOfNames
,
587 DispatchEx_DeleteMemberByName
,
588 DispatchEx_DeleteMemberByDispID
,
589 DispatchEx_GetMemberProperties
,
590 DispatchEx_GetMemberName
,
591 DispatchEx_GetNextDispID
,
592 DispatchEx_GetNameSpaceParent
595 static IDispatchEx Global
= { &GlobalVtbl
};
597 static HRESULT WINAPI
ActiveScriptSite_QueryInterface(IActiveScriptSite
*iface
, REFIID riid
, void **ppv
)
601 if(IsEqualGUID(&IID_IUnknown
, riid
))
603 else if(IsEqualGUID(&IID_IActiveScriptSite
, riid
))
606 return E_NOINTERFACE
;
608 IUnknown_AddRef((IUnknown
*)*ppv
);
612 static ULONG WINAPI
ActiveScriptSite_AddRef(IActiveScriptSite
*iface
)
617 static ULONG WINAPI
ActiveScriptSite_Release(IActiveScriptSite
*iface
)
622 static HRESULT WINAPI
ActiveScriptSite_GetLCID(IActiveScriptSite
*iface
, LCID
*plcid
)
624 *plcid
= GetUserDefaultLCID();
628 static HRESULT WINAPI
ActiveScriptSite_GetItemInfo(IActiveScriptSite
*iface
, LPCOLESTR pstrName
,
629 DWORD dwReturnMask
, IUnknown
**ppiunkItem
, ITypeInfo
**ppti
)
631 ok(dwReturnMask
== SCRIPTINFO_IUNKNOWN
, "unexpected dwReturnMask %x\n", dwReturnMask
);
632 ok(!ppti
, "ppti != NULL\n");
634 if(!strcmp_wa(pstrName
, test_valA
))
635 CHECK_EXPECT(GetItemInfo_testVal
);
636 else if(strcmp_wa(pstrName
, testA
))
637 ok(0, "unexpected pstrName %s\n", wine_dbgstr_w(pstrName
));
639 *ppiunkItem
= (IUnknown
*)&Global
;
643 static HRESULT WINAPI
ActiveScriptSite_GetDocVersionString(IActiveScriptSite
*iface
, BSTR
*pbstrVersion
)
648 static HRESULT WINAPI
ActiveScriptSite_OnScriptTerminate(IActiveScriptSite
*iface
,
649 const VARIANT
*pvarResult
, const EXCEPINFO
*pexcepinfo
)
654 static HRESULT WINAPI
ActiveScriptSite_OnStateChange(IActiveScriptSite
*iface
, SCRIPTSTATE ssScriptState
)
659 static HRESULT WINAPI
ActiveScriptSite_OnScriptError(IActiveScriptSite
*iface
, IActiveScriptError
*pscripterror
)
664 static HRESULT WINAPI
ActiveScriptSite_OnEnterScript(IActiveScriptSite
*iface
)
669 static HRESULT WINAPI
ActiveScriptSite_OnLeaveScript(IActiveScriptSite
*iface
)
674 #undef ACTSCPSITE_THIS
676 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl
= {
677 ActiveScriptSite_QueryInterface
,
678 ActiveScriptSite_AddRef
,
679 ActiveScriptSite_Release
,
680 ActiveScriptSite_GetLCID
,
681 ActiveScriptSite_GetItemInfo
,
682 ActiveScriptSite_GetDocVersionString
,
683 ActiveScriptSite_OnScriptTerminate
,
684 ActiveScriptSite_OnStateChange
,
685 ActiveScriptSite_OnScriptError
,
686 ActiveScriptSite_OnEnterScript
,
687 ActiveScriptSite_OnLeaveScript
690 static IActiveScriptSite ActiveScriptSite
= { &ActiveScriptSiteVtbl
};
692 static HRESULT
set_script_prop(IActiveScript
*engine
, DWORD property
, VARIANT
*val
)
694 IActiveScriptProperty
*script_prop
;
697 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptProperty
,
698 (void**)&script_prop
);
699 ok(hres
== S_OK
, "Could not get IActiveScriptProperty iface: %08x\n", hres
);
701 hres
= IActiveScriptProperty_SetProperty(script_prop
, property
, NULL
, val
);
702 IActiveScriptProperty_Release(script_prop
);
707 static IActiveScript
*create_script(void)
709 IActiveScript
*script
;
713 hres
= CoCreateInstance(&CLSID_JScript
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
714 &IID_IActiveScript
, (void**)&script
);
715 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
718 V_I4(&v
) = invoke_version
;
719 hres
= set_script_prop(script
, SCRIPTPROP_INVOKEVERSIONING
, &v
);
720 ok(hres
== S_OK
|| broken(hres
== E_NOTIMPL
), "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres
);
721 if(invoke_version
&& FAILED(hres
)) {
722 IActiveScript_Release(script
);
729 static HRESULT
parse_script(DWORD flags
, BSTR script_str
)
731 IActiveScriptParse
*parser
;
732 IActiveScript
*engine
;
735 engine
= create_script();
739 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptParse
, (void**)&parser
);
740 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
743 IActiveScript_Release(engine
);
747 hres
= IActiveScriptParse64_InitNew(parser
);
748 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
750 hres
= IActiveScript_SetScriptSite(engine
, &ActiveScriptSite
);
751 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
753 hres
= IActiveScript_AddNamedItem(engine
, testW
,
754 SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|flags
);
755 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
757 hres
= IActiveScript_SetScriptState(engine
, SCRIPTSTATE_STARTED
);
758 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
760 hres
= IActiveScript_GetScriptDispatch(engine
, NULL
, &script_disp
);
761 ok(hres
== S_OK
, "GetScriptDispatch failed: %08x\n", hres
);
762 ok(script_disp
!= NULL
, "script_disp == NULL\n");
763 ok(script_disp
!= (IDispatch
*)&Global
, "script_disp == Global\n");
765 hres
= IActiveScriptParse64_ParseScriptText(parser
, script_str
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
767 IDispatch_Release(script_disp
);
768 IActiveScript_Release(engine
);
769 IUnknown_Release(parser
);
774 static HRESULT
parse_htmlscript(BSTR script_str
)
776 IActiveScriptParse
*parser
;
777 IActiveScript
*engine
;
779 BSTR tmp
= a2bstr("</SCRIPT>");
781 engine
= create_script();
785 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptParse
, (void**)&parser
);
786 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
789 IActiveScript_Release(engine
);
793 hres
= IActiveScriptParse64_InitNew(parser
);
794 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
796 hres
= IActiveScript_SetScriptSite(engine
, &ActiveScriptSite
);
797 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
799 hres
= IActiveScript_AddNamedItem(engine
, testW
,
800 SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|SCRIPTITEM_GLOBALMEMBERS
);
801 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
803 hres
= IActiveScript_SetScriptState(engine
, SCRIPTSTATE_STARTED
);
804 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
806 hres
= IActiveScriptParse64_ParseScriptText(parser
, script_str
, NULL
, NULL
, tmp
, 0, 0, 0, NULL
, NULL
);
808 IActiveScript_Release(engine
);
809 IUnknown_Release(parser
);
815 static void parse_script_af(DWORD flags
, const char *src
)
821 hres
= parse_script(flags
, tmp
);
823 ok(hres
== S_OK
, "parse_script failed: %08x\n", hres
);
826 static void parse_script_a(const char *src
)
828 parse_script_af(SCRIPTITEM_GLOBALMEMBERS
, src
);
831 static HRESULT
parse_htmlscript_a(const char *src
)
834 BSTR tmp
= a2bstr(src
);
835 hres
= parse_htmlscript(tmp
);
841 static BSTR
get_script_from_file(const char *filename
)
845 const char *file_map
;
848 file
= CreateFileA(filename
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_READONLY
, NULL
);
849 if(file
== INVALID_HANDLE_VALUE
) {
850 trace("Could not open file: %u\n", GetLastError());
854 size
= GetFileSize(file
, NULL
);
856 map
= CreateFileMapping(file
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
858 if(map
== INVALID_HANDLE_VALUE
) {
859 trace("Could not create file mapping: %u\n", GetLastError());
863 file_map
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
866 trace("MapViewOfFile failed: %u\n", GetLastError());
870 len
= MultiByteToWideChar(CP_ACP
, 0, file_map
, size
, NULL
, 0);
871 ret
= SysAllocStringLen(NULL
, len
);
872 MultiByteToWideChar(CP_ACP
, 0, file_map
, size
, ret
, len
);
874 UnmapViewOfFile(file_map
);
879 static void run_from_file(const char *filename
)
884 script_str
= get_script_from_file(filename
);
888 strict_dispid_check
= FALSE
;
889 hres
= parse_script(SCRIPTITEM_GLOBALMEMBERS
, script_str
);
890 SysFreeString(script_str
);
891 ok(hres
== S_OK
, "parse_script failed: %08x\n", hres
);
894 static void run_from_res(const char *name
)
902 strict_dispid_check
= FALSE
;
905 src
= FindResourceA(NULL
, name
, (LPCSTR
)40);
906 ok(src
!= NULL
, "Could not find resource %s\n", name
);
908 size
= SizeofResource(NULL
, src
);
909 data
= LoadResource(NULL
, src
);
911 len
= MultiByteToWideChar(CP_ACP
, 0, data
, size
, NULL
, 0);
912 str
= SysAllocStringLen(NULL
, len
);
913 len
= MultiByteToWideChar(CP_ACP
, 0, data
, size
, str
, len
);
915 SET_EXPECT(global_success_d
);
916 SET_EXPECT(global_success_i
);
917 hres
= parse_script(SCRIPTITEM_GLOBALMEMBERS
, str
);
918 CHECK_CALLED(global_success_d
);
919 CHECK_CALLED(global_success_i
);
921 ok(hres
== S_OK
, "parse_script failed: %08x\n", hres
);
925 static void test_isvisible(BOOL global_members
)
927 IActiveScriptParse
*parser
;
928 IActiveScript
*engine
;
931 static const WCHAR script_textW
[] =
932 {'v','a','r',' ','v',' ','=',' ','t','e','s','t','V','a','l',';',0};
934 engine
= create_script();
938 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptParse
, (void**)&parser
);
939 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
942 IActiveScript_Release(engine
);
946 hres
= IActiveScriptParse64_InitNew(parser
);
947 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
949 hres
= IActiveScript_SetScriptSite(engine
, &ActiveScriptSite
);
950 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
953 SET_EXPECT(GetItemInfo_testVal
);
954 hres
= IActiveScript_AddNamedItem(engine
, test_valW
,
955 SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|
956 (global_members
? SCRIPTITEM_GLOBALMEMBERS
: 0));
957 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
959 CHECK_CALLED(GetItemInfo_testVal
);
961 hres
= IActiveScript_SetScriptState(engine
, SCRIPTSTATE_STARTED
);
962 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
965 SET_EXPECT(GetItemInfo_testVal
);
966 hres
= IActiveScriptParse64_ParseScriptText(parser
, script_textW
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
967 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
969 CHECK_CALLED(GetItemInfo_testVal
);
971 hres
= IActiveScriptParse64_ParseScriptText(parser
, script_textW
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
972 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
974 IActiveScript_Release(engine
);
975 IUnknown_Release(parser
);
978 static void run_tests(void)
983 IActiveScript
*script
;
985 script
= create_script();
987 win_skip("Could not create script\n");
990 IActiveScript_Release(script
);
993 strict_dispid_check
= TRUE
;
996 parse_script_a("/* empty */ ;");
998 SET_EXPECT(global_propget_d
);
999 SET_EXPECT(global_propget_i
);
1000 parse_script_a("testPropGet;");
1001 CHECK_CALLED(global_propget_d
);
1002 CHECK_CALLED(global_propget_i
);
1004 SET_EXPECT(global_propput_d
);
1005 SET_EXPECT(global_propput_i
);
1006 parse_script_a("testPropPut = 1;");
1007 CHECK_CALLED(global_propput_d
);
1008 CHECK_CALLED(global_propput_i
);
1010 SET_EXPECT(global_success_d
);
1011 SET_EXPECT(global_success_i
);
1012 parse_script_a("reportSuccess();");
1013 CHECK_CALLED(global_success_d
);
1014 CHECK_CALLED(global_success_i
);
1016 SET_EXPECT(testobj_delete
);
1017 parse_script_a("delete testObj.deleteTest;");
1018 CHECK_CALLED(testobj_delete
);
1020 parse_script_a("ok(typeof(test) === 'object', \"typeof(test) != 'object'\");");
1022 parse_script_a("function reportSuccess() {}; reportSuccess();");
1024 SET_EXPECT(global_propget_d
);
1025 parse_script_a("var testPropGet");
1026 CHECK_CALLED(global_propget_d
);
1028 SET_EXPECT(global_notexists_d
);
1029 parse_script_a("var notExists; notExists = 1;");
1030 CHECK_CALLED(global_notexists_d
);
1032 parse_script_a("function f() { var testPropGet; }");
1034 parse_script_a("ok((testObj instanceof Object) === false, 'testObj is instance of Object');");
1036 SET_EXPECT(testobj_prop_d
);
1037 parse_script_a("ok(('prop' in testObj) === true, 'prop is not in testObj');");
1038 CHECK_CALLED(testobj_prop_d
);
1040 SET_EXPECT(testobj_noprop_d
);
1041 parse_script_a("ok(('noprop' in testObj) === false, 'noprop is in testObj');");
1042 CHECK_CALLED(testobj_noprop_d
);
1044 SET_EXPECT(testobj_value
);
1045 parse_script_a("ok(String(testObj) === '1', 'wrong testObj value');");
1046 CHECK_CALLED(testobj_value
);
1048 SET_EXPECT(testobj_value
);
1049 parse_script_a("ok(String.prototype.concat.call(testObj, ' OK') === '1 OK', 'wrong concat result');");
1050 CHECK_CALLED(testobj_value
);
1052 SET_EXPECT(global_propget_d
);
1053 SET_EXPECT(global_propget_i
);
1054 parse_script_a("this.testPropGet;");
1055 CHECK_CALLED(global_propget_d
);
1056 CHECK_CALLED(global_propget_i
);
1058 SET_EXPECT(global_propget_d
);
1059 SET_EXPECT(global_propget_i
);
1060 parse_script_a("(function () { this.testPropGet; })();");
1061 CHECK_CALLED(global_propget_d
);
1062 CHECK_CALLED(global_propget_i
);
1064 parse_script_a("testThis(this);");
1065 parse_script_a("(function () { testThis(this); })();");
1067 run_from_res("lang.js");
1068 run_from_res("api.js");
1069 run_from_res("regexp.js");
1071 test_isvisible(FALSE
);
1072 test_isvisible(TRUE
);
1074 parse_script_af(0, "test.testThis2(this);");
1075 parse_script_af(0, "(function () { test.testThis2(this); })();");
1077 hres
= parse_htmlscript_a("<!--");
1078 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1079 hres
= parse_htmlscript_a("-->");
1080 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1081 hres
= parse_htmlscript_a("<!--\nvar a=1;\n-->\n");
1082 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1083 hres
= parse_htmlscript_a("<!--\n<!-- ignore this\n-->\n");
1084 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1085 hres
= parse_htmlscript_a("var a=1;\nif(a-->0) a=5;\n");
1086 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1087 hres
= parse_htmlscript_a("var a=1;\nif(a\n-->0) a=5;\n");
1088 ok(hres
!= S_OK
, "ParseScriptText have not failed\n");
1091 static BOOL
check_jscript(void)
1096 str
= a2bstr("if(!('localeCompare' in String.prototype)) throw 1;");
1097 hres
= parse_script(0, str
);
1100 return hres
== S_OK
;
1108 argc
= winetest_get_mainargs(&argv
);
1112 if(!check_jscript()) {
1113 win_skip("Broken engine, probably too old\n");
1114 }else if(argc
> 2) {
1115 run_from_file(argv
[2]);
1117 trace("invoke version 0\n");
1121 trace("invoke version 2\n");