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 void 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
);
766 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
768 IDispatch_Release(script_disp
);
769 IActiveScript_Release(engine
);
770 IUnknown_Release(parser
);
773 static HRESULT
parse_htmlscript(BSTR script_str
)
775 IActiveScriptParse
*parser
;
776 IActiveScript
*engine
;
778 BSTR tmp
= a2bstr("</SCRIPT>");
780 engine
= create_script();
784 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptParse
, (void**)&parser
);
785 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
788 IActiveScript_Release(engine
);
792 hres
= IActiveScriptParse64_InitNew(parser
);
793 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
795 hres
= IActiveScript_SetScriptSite(engine
, &ActiveScriptSite
);
796 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
798 hres
= IActiveScript_AddNamedItem(engine
, testW
,
799 SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|SCRIPTITEM_GLOBALMEMBERS
);
800 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
802 hres
= IActiveScript_SetScriptState(engine
, SCRIPTSTATE_STARTED
);
803 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
805 hres
= IActiveScriptParse64_ParseScriptText(parser
, script_str
, NULL
, NULL
, tmp
, 0, 0, 0, NULL
, NULL
);
807 IActiveScript_Release(engine
);
808 IUnknown_Release(parser
);
814 static void parse_script_af(DWORD flags
, const char *src
)
816 BSTR tmp
= a2bstr(src
);
817 parse_script(flags
, tmp
);
821 static void parse_script_a(const char *src
)
823 parse_script_af(SCRIPTITEM_GLOBALMEMBERS
, src
);
826 static HRESULT
parse_htmlscript_a(const char *src
)
829 BSTR tmp
= a2bstr(src
);
830 hres
= parse_htmlscript(tmp
);
836 static BSTR
get_script_from_file(const char *filename
)
840 const char *file_map
;
843 file
= CreateFileA(filename
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_READONLY
, NULL
);
844 if(file
== INVALID_HANDLE_VALUE
) {
845 trace("Could not open file: %u\n", GetLastError());
849 size
= GetFileSize(file
, NULL
);
851 map
= CreateFileMapping(file
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
853 if(map
== INVALID_HANDLE_VALUE
) {
854 trace("Could not create file mapping: %u\n", GetLastError());
858 file_map
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
861 trace("MapViewOfFile failed: %u\n", GetLastError());
865 len
= MultiByteToWideChar(CP_ACP
, 0, file_map
, size
, NULL
, 0);
866 ret
= SysAllocStringLen(NULL
, len
);
867 MultiByteToWideChar(CP_ACP
, 0, file_map
, size
, ret
, len
);
869 UnmapViewOfFile(file_map
);
874 static void run_from_file(const char *filename
)
876 BSTR script_str
= get_script_from_file(filename
);
878 strict_dispid_check
= FALSE
;
881 parse_script(SCRIPTITEM_GLOBALMEMBERS
, script_str
);
883 SysFreeString(script_str
);
886 static void run_from_res(const char *name
)
893 strict_dispid_check
= FALSE
;
896 src
= FindResourceA(NULL
, name
, (LPCSTR
)40);
897 ok(src
!= NULL
, "Could not find resource %s\n", name
);
899 size
= SizeofResource(NULL
, src
);
900 data
= LoadResource(NULL
, src
);
902 len
= MultiByteToWideChar(CP_ACP
, 0, data
, size
, NULL
, 0);
903 str
= SysAllocStringLen(NULL
, len
);
904 len
= MultiByteToWideChar(CP_ACP
, 0, data
, size
, str
, len
);
906 SET_EXPECT(global_success_d
);
907 SET_EXPECT(global_success_i
);
908 parse_script(SCRIPTITEM_GLOBALMEMBERS
, str
);
909 CHECK_CALLED(global_success_d
);
910 CHECK_CALLED(global_success_i
);
915 static void test_isvisible(BOOL global_members
)
917 IActiveScriptParse
*parser
;
918 IActiveScript
*engine
;
921 static const WCHAR script_textW
[] =
922 {'v','a','r',' ','v',' ','=',' ','t','e','s','t','V','a','l',';',0};
924 engine
= create_script();
928 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptParse
, (void**)&parser
);
929 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
932 IActiveScript_Release(engine
);
936 hres
= IActiveScriptParse64_InitNew(parser
);
937 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
939 hres
= IActiveScript_SetScriptSite(engine
, &ActiveScriptSite
);
940 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
943 SET_EXPECT(GetItemInfo_testVal
);
944 hres
= IActiveScript_AddNamedItem(engine
, test_valW
,
945 SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|
946 (global_members
? SCRIPTITEM_GLOBALMEMBERS
: 0));
947 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
949 CHECK_CALLED(GetItemInfo_testVal
);
951 hres
= IActiveScript_SetScriptState(engine
, SCRIPTSTATE_STARTED
);
952 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
955 SET_EXPECT(GetItemInfo_testVal
);
956 hres
= IActiveScriptParse64_ParseScriptText(parser
, script_textW
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
957 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
959 CHECK_CALLED(GetItemInfo_testVal
);
961 hres
= IActiveScriptParse64_ParseScriptText(parser
, script_textW
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
962 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
964 IActiveScript_Release(engine
);
965 IUnknown_Release(parser
);
968 static void run_tests(void)
973 IActiveScript
*script
;
975 script
= create_script();
977 win_skip("Could not create script\n");
980 IActiveScript_Release(script
);
983 strict_dispid_check
= TRUE
;
986 parse_script_a("/* empty */ ;");
988 SET_EXPECT(global_propget_d
);
989 SET_EXPECT(global_propget_i
);
990 parse_script_a("testPropGet;");
991 CHECK_CALLED(global_propget_d
);
992 CHECK_CALLED(global_propget_i
);
994 SET_EXPECT(global_propput_d
);
995 SET_EXPECT(global_propput_i
);
996 parse_script_a("testPropPut = 1;");
997 CHECK_CALLED(global_propput_d
);
998 CHECK_CALLED(global_propput_i
);
1000 SET_EXPECT(global_success_d
);
1001 SET_EXPECT(global_success_i
);
1002 parse_script_a("reportSuccess();");
1003 CHECK_CALLED(global_success_d
);
1004 CHECK_CALLED(global_success_i
);
1006 SET_EXPECT(testobj_delete
);
1007 parse_script_a("delete testObj.deleteTest;");
1008 CHECK_CALLED(testobj_delete
);
1010 parse_script_a("ok(typeof(test) === 'object', \"typeof(test) != 'object'\");");
1012 parse_script_a("function reportSuccess() {}; reportSuccess();");
1014 SET_EXPECT(global_propget_d
);
1015 parse_script_a("var testPropGet");
1016 CHECK_CALLED(global_propget_d
);
1018 SET_EXPECT(global_notexists_d
);
1019 parse_script_a("var notExists; notExists = 1;");
1020 CHECK_CALLED(global_notexists_d
);
1022 parse_script_a("function f() { var testPropGet; }");
1024 parse_script_a("ok((testObj instanceof Object) === false, 'testObj is instance of Object');");
1026 SET_EXPECT(testobj_prop_d
);
1027 parse_script_a("ok(('prop' in testObj) === true, 'prop is not in testObj');");
1028 CHECK_CALLED(testobj_prop_d
);
1030 SET_EXPECT(testobj_noprop_d
);
1031 parse_script_a("ok(('noprop' in testObj) === false, 'noprop is in testObj');");
1032 CHECK_CALLED(testobj_noprop_d
);
1034 SET_EXPECT(testobj_value
);
1035 parse_script_a("ok(String(testObj) === '1', 'wrong testObj value');");
1036 CHECK_CALLED(testobj_value
);
1038 SET_EXPECT(testobj_value
);
1039 parse_script_a("ok(String.prototype.concat.call(testObj, ' OK') === '1 OK', 'wrong concat result');");
1040 CHECK_CALLED(testobj_value
);
1042 SET_EXPECT(global_propget_d
);
1043 SET_EXPECT(global_propget_i
);
1044 parse_script_a("this.testPropGet;");
1045 CHECK_CALLED(global_propget_d
);
1046 CHECK_CALLED(global_propget_i
);
1048 SET_EXPECT(global_propget_d
);
1049 SET_EXPECT(global_propget_i
);
1050 parse_script_a("(function () { this.testPropGet; })();");
1051 CHECK_CALLED(global_propget_d
);
1052 CHECK_CALLED(global_propget_i
);
1054 parse_script_a("testThis(this);");
1055 parse_script_a("(function () { testThis(this); })();");
1057 run_from_res("lang.js");
1058 run_from_res("api.js");
1059 run_from_res("regexp.js");
1061 test_isvisible(FALSE
);
1062 test_isvisible(TRUE
);
1064 parse_script_af(0, "test.testThis2(this);");
1065 parse_script_af(0, "(function () { test.testThis2(this); })();");
1067 hres
= parse_htmlscript_a("<!--");
1068 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1069 hres
= parse_htmlscript_a("-->");
1070 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1071 hres
= parse_htmlscript_a("<!--\nvar a=1;\n-->\n");
1072 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1073 hres
= parse_htmlscript_a("<!--\n<!-- ignore this\n-->\n");
1074 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1075 hres
= parse_htmlscript_a("var a=1;\nif(a-->0) a=5;\n");
1076 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1077 hres
= parse_htmlscript_a("var a=1;\nif(a\n-->0) a=5;\n");
1078 ok(hres
!= S_OK
, "ParseScriptText have not failed\n");
1086 argc
= winetest_get_mainargs(&argv
);
1091 run_from_file(argv
[2]);
1093 trace("invoke version 0\n");
1097 trace("invoke version 2\n");