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(testobj_onlydispid_d
);
72 DEFINE_EXPECT(testobj_onlydispid_i
);
73 DEFINE_EXPECT(GetItemInfo_testVal
);
74 DEFINE_EXPECT(ActiveScriptSite_OnScriptError
);
75 DEFINE_EXPECT(invoke_func
);
77 #define DISPID_GLOBAL_TESTPROPGET 0x1000
78 #define DISPID_GLOBAL_TESTPROPPUT 0x1001
79 #define DISPID_GLOBAL_REPORTSUCCESS 0x1002
80 #define DISPID_GLOBAL_TRACE 0x1003
81 #define DISPID_GLOBAL_OK 0x1004
82 #define DISPID_GLOBAL_GETVT 0x1005
83 #define DISPID_GLOBAL_TESTOBJ 0x1006
84 #define DISPID_GLOBAL_NULL_BSTR 0x1007
85 #define DISPID_GLOBAL_NULL_DISP 0x1008
86 #define DISPID_GLOBAL_TESTTHIS 0x1009
87 #define DISPID_GLOBAL_TESTTHIS2 0x100a
88 #define DISPID_GLOBAL_INVOKEVERSION 0x100b
89 #define DISPID_GLOBAL_CREATEARRAY 0x100c
90 #define DISPID_GLOBAL_PROPGETFUNC 0x100d
91 #define DISPID_GLOBAL_OBJECT_FLAG 0x100e
92 #define DISPID_GLOBAL_ISWIN64 0x100f
93 #define DISPID_GLOBAL_PUREDISP 0x1010
95 #define DISPID_TESTOBJ_PROP 0x2000
96 #define DISPID_TESTOBJ_ONLYDISPID 0x2001
98 static const WCHAR testW
[] = {'t','e','s','t',0};
99 static const CHAR testA
[] = "test";
100 static const WCHAR test_valW
[] = {'t','e','s','t','V','a','l',0};
101 static const CHAR test_valA
[] = "testVal";
103 static BOOL strict_dispid_check
;
104 static const char *test_name
= "(null)";
105 static IDispatch
*script_disp
;
106 static int invoke_version
;
107 static IActiveScriptError
*script_error
;
109 static BSTR
a2bstr(const char *str
)
114 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
115 ret
= SysAllocStringLen(NULL
, len
-1);
116 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
121 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
124 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), 0, 0);
125 return lstrcmpA(buf
, stra
);
128 #define test_grfdex(a,b) _test_grfdex(__LINE__,a,b)
129 static void _test_grfdex(unsigned line
, DWORD grfdex
, DWORD expect
)
131 expect
|= invoke_version
<< 28;
132 ok_(__FILE__
,line
)(grfdex
== expect
, "grfdex = %x, expected %x\n", grfdex
, expect
);
135 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
139 if(IsEqualGUID(riid
, &IID_IUnknown
)
140 || IsEqualGUID(riid
, &IID_IDispatch
)
141 || IsEqualGUID(riid
, &IID_IDispatchEx
))
144 return E_NOINTERFACE
;
149 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
154 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
159 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
161 ok(0, "unexpected call\n");
165 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
166 LCID lcid
, ITypeInfo
**ppTInfo
)
168 ok(0, "unexpected call\n");
172 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
173 LPOLESTR
*rgszNames
, UINT cNames
,
174 LCID lcid
, DISPID
*rgDispId
)
176 ok(0, "unexpected call\n");
180 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
181 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
182 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
184 ok(0, "unexpected call\n");
188 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
190 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName
), grfdex
);
194 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
196 ok(0, "unexpected call\n");
200 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
202 ok(0, "unexpected call\n");
206 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
208 ok(0, "unexpected call\n");
212 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
214 ok(0, "unexpected call\n");
218 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
220 ok(0, "unexpected call\n");
224 static HRESULT WINAPI
testObj_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
226 if(!strcmp_wa(bstrName
, "prop")) {
227 CHECK_EXPECT(testobj_prop_d
);
228 test_grfdex(grfdex
, fdexNameCaseSensitive
);
229 *pid
= DISPID_TESTOBJ_PROP
;
232 if(!strcmp_wa(bstrName
, "noprop")) {
233 CHECK_EXPECT(testobj_noprop_d
);
234 test_grfdex(grfdex
, fdexNameCaseSensitive
);
235 return DISP_E_UNKNOWNNAME
;
237 if(!strcmp_wa(bstrName
, "onlyDispID")) {
238 if(strict_dispid_check
)
239 CHECK_EXPECT(testobj_onlydispid_d
);
240 test_grfdex(grfdex
, fdexNameCaseSensitive
);
241 *pid
= DISPID_TESTOBJ_ONLYDISPID
;
245 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName
));
249 static HRESULT WINAPI
testObj_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
250 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
254 ok(pdp
!= NULL
, "pdp == NULL\n");
255 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
256 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
257 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
258 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
259 ok(pei
!= NULL
, "pei == NULL\n");
262 case INVOKE_PROPERTYGET
:
263 CHECK_EXPECT(testobj_value
);
264 ok(!pdp
->rgvarg
, "rgvarg != NULL\n");
265 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
268 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
270 case INVOKE_FUNC
|INVOKE_PROPERTYGET
:
271 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
274 ok(0, "invalid flag (%x)\n", wFlags
);
277 V_VT(pvarRes
) = VT_I4
;
280 case DISPID_TESTOBJ_ONLYDISPID
:
281 if(strict_dispid_check
)
282 CHECK_EXPECT(testobj_onlydispid_i
);
283 ok(wFlags
== INVOKE_PROPERTYGET
, "wFlags = %x\n", wFlags
);
284 ok(pdp
!= NULL
, "pdp == NULL\n");
285 ok(!pdp
->rgvarg
, "rgvarg != NULL\n");
286 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
287 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
288 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
289 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
290 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
291 ok(pei
!= NULL
, "pei == NULL\n");
292 return DISP_E_MEMBERNOTFOUND
;
295 ok(0, "unexpected call %x\n", id
);
296 return DISP_E_MEMBERNOTFOUND
;
299 static HRESULT WINAPI
testObj_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
301 CHECK_EXPECT(testobj_delete
);
303 ok(!strcmp_wa(bstrName
, "deleteTest"), "unexpected name %s\n", wine_dbgstr_w(bstrName
));
304 test_grfdex(grfdex
, fdexNameCaseSensitive
);
308 static IDispatchExVtbl testObjVtbl
= {
309 DispatchEx_QueryInterface
,
312 DispatchEx_GetTypeInfoCount
,
313 DispatchEx_GetTypeInfo
,
314 DispatchEx_GetIDsOfNames
,
318 testObj_DeleteMemberByName
,
319 DispatchEx_DeleteMemberByDispID
,
320 DispatchEx_GetMemberProperties
,
321 DispatchEx_GetMemberName
,
322 DispatchEx_GetNextDispID
,
323 DispatchEx_GetNameSpaceParent
326 static IDispatchEx testObj
= { &testObjVtbl
};
328 static HRESULT WINAPI
pureDisp_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
330 if(IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_IDispatch
)) {
336 return E_NOINTERFACE
;
339 static IDispatchExVtbl pureDispVtbl
= {
340 pureDisp_QueryInterface
,
343 DispatchEx_GetTypeInfoCount
,
344 DispatchEx_GetTypeInfo
,
345 DispatchEx_GetIDsOfNames
,
349 static IDispatchEx pureDisp
= { &pureDispVtbl
};
351 static HRESULT WINAPI
Global_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
353 if(!strcmp_wa(bstrName
, "ok")) {
354 test_grfdex(grfdex
, fdexNameCaseSensitive
);
355 *pid
= DISPID_GLOBAL_OK
;
358 if(!strcmp_wa(bstrName
, "trace")) {
359 test_grfdex(grfdex
, fdexNameCaseSensitive
);
360 *pid
= DISPID_GLOBAL_TRACE
;
363 if(!strcmp_wa(bstrName
, "reportSuccess")) {
364 CHECK_EXPECT(global_success_d
);
365 test_grfdex(grfdex
, fdexNameCaseSensitive
);
366 *pid
= DISPID_GLOBAL_REPORTSUCCESS
;
369 if(!strcmp_wa(bstrName
, "testPropGet")) {
370 CHECK_EXPECT(global_propget_d
);
371 test_grfdex(grfdex
, fdexNameCaseSensitive
);
372 *pid
= DISPID_GLOBAL_TESTPROPGET
;
375 if(!strcmp_wa(bstrName
, "testPropPut")) {
376 CHECK_EXPECT(global_propput_d
);
377 test_grfdex(grfdex
, fdexNameCaseSensitive
);
378 *pid
= DISPID_GLOBAL_TESTPROPPUT
;
381 if(!strcmp_wa(bstrName
, "getVT")) {
382 test_grfdex(grfdex
, fdexNameCaseSensitive
);
383 *pid
= DISPID_GLOBAL_GETVT
;
386 if(!strcmp_wa(bstrName
, "testObj")) {
387 test_grfdex(grfdex
, fdexNameCaseSensitive
);
388 *pid
= DISPID_GLOBAL_TESTOBJ
;
391 if(!strcmp_wa(bstrName
, "createNullBSTR")) {
392 *pid
= DISPID_GLOBAL_NULL_BSTR
;
395 if(!strcmp_wa(bstrName
, "nullDisp")) {
396 *pid
= DISPID_GLOBAL_NULL_DISP
;
399 if(!strcmp_wa(bstrName
, "notExists")) {
400 CHECK_EXPECT(global_notexists_d
);
401 test_grfdex(grfdex
, fdexNameCaseSensitive
);
402 return DISP_E_UNKNOWNNAME
;
405 if(!strcmp_wa(bstrName
, "testThis")) {
406 test_grfdex(grfdex
, fdexNameCaseSensitive
);
407 *pid
= DISPID_GLOBAL_TESTTHIS
;
411 if(!strcmp_wa(bstrName
, "testThis2")) {
412 test_grfdex(grfdex
, fdexNameCaseSensitive
);
413 *pid
= DISPID_GLOBAL_TESTTHIS2
;
417 if(!strcmp_wa(bstrName
, "invokeVersion")) {
418 test_grfdex(grfdex
, fdexNameCaseSensitive
);
419 *pid
= DISPID_GLOBAL_INVOKEVERSION
;
422 if(!strcmp_wa(bstrName
, "createArray")) {
423 test_grfdex(grfdex
, fdexNameCaseSensitive
);
424 *pid
= DISPID_GLOBAL_CREATEARRAY
;
427 if(!strcmp_wa(bstrName
, "propGetFunc")) {
428 test_grfdex(grfdex
, fdexNameCaseSensitive
);
429 *pid
= DISPID_GLOBAL_PROPGETFUNC
;
432 if(!strcmp_wa(bstrName
, "objectFlag")) {
433 test_grfdex(grfdex
, fdexNameCaseSensitive
);
434 *pid
= DISPID_GLOBAL_OBJECT_FLAG
;
438 if(!strcmp_wa(bstrName
, "isWin64")) {
439 test_grfdex(grfdex
, fdexNameCaseSensitive
);
440 *pid
= DISPID_GLOBAL_ISWIN64
;
444 if(!strcmp_wa(bstrName
, "pureDisp")) {
445 test_grfdex(grfdex
, fdexNameCaseSensitive
);
446 *pid
= DISPID_GLOBAL_PUREDISP
;
450 if(strict_dispid_check
)
451 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName
));
452 return DISP_E_UNKNOWNNAME
;
455 static HRESULT WINAPI
Global_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
456 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
459 case DISPID_GLOBAL_OK
:
460 ok(wFlags
== INVOKE_FUNC
|| wFlags
== (INVOKE_FUNC
|INVOKE_PROPERTYGET
), "wFlags = %x\n", wFlags
);
461 ok(pdp
!= NULL
, "pdp == NULL\n");
462 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
463 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
464 ok(pdp
->cArgs
== 2, "cArgs = %d\n", pdp
->cArgs
);
465 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
466 if(wFlags
& INVOKE_PROPERTYGET
)
467 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
469 ok(!pvarRes
, "pvarRes != NULL\n");
470 ok(pei
!= NULL
, "pei == NULL\n");
472 ok(V_VT(pdp
->rgvarg
) == VT_BSTR
, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp
->rgvarg
));
473 ok(V_VT(pdp
->rgvarg
+1) == VT_BOOL
, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp
->rgvarg
));
474 ok(V_BOOL(pdp
->rgvarg
+1), "%s: %s\n", test_name
, wine_dbgstr_w(V_BSTR(pdp
->rgvarg
)));
478 case DISPID_GLOBAL_TRACE
:
479 ok(wFlags
== INVOKE_FUNC
, "wFlags = %x\n", wFlags
);
480 ok(pdp
!= NULL
, "pdp == NULL\n");
481 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
482 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
483 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
484 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
485 ok(!pvarRes
, "pvarRes != NULL\n");
486 ok(pei
!= NULL
, "pei == NULL\n");
488 ok(V_VT(pdp
->rgvarg
) == VT_BSTR
, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp
->rgvarg
));
489 if(V_VT(pdp
->rgvarg
) == VT_BSTR
)
490 trace("%s: %s\n", test_name
, wine_dbgstr_w(V_BSTR(pdp
->rgvarg
)));
494 case DISPID_GLOBAL_REPORTSUCCESS
:
495 CHECK_EXPECT(global_success_i
);
497 ok(wFlags
== INVOKE_FUNC
, "wFlags = %x\n", wFlags
);
498 ok(pdp
!= NULL
, "pdp == NULL\n");
499 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
500 ok(pdp
->cArgs
== 0, "cArgs = %d\n", pdp
->cArgs
);
501 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
502 ok(!pvarRes
, "pvarRes != NULL\n");
503 ok(pei
!= NULL
, "pei == NULL\n");
507 case DISPID_GLOBAL_TESTPROPGET
:
508 CHECK_EXPECT(global_propget_i
);
510 ok(wFlags
== INVOKE_PROPERTYGET
, "wFlags = %x\n", wFlags
);
511 ok(pdp
!= NULL
, "pdp == NULL\n");
512 ok(!pdp
->rgvarg
, "rgvarg != NULL\n");
513 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
514 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
515 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
516 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
517 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
518 ok(pei
!= NULL
, "pei == NULL\n");
520 V_VT(pvarRes
) = VT_I4
;
525 case DISPID_GLOBAL_TESTPROPPUT
:
526 CHECK_EXPECT(global_propput_i
);
528 ok(wFlags
== INVOKE_PROPERTYPUT
, "wFlags = %x\n", wFlags
);
529 ok(pdp
!= NULL
, "pdp == NULL\n");
530 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
531 ok(pdp
->rgdispidNamedArgs
!= NULL
, "rgdispidNamedArgs == NULL\n");
532 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
533 ok(pdp
->cNamedArgs
== 1, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
534 ok(pdp
->rgdispidNamedArgs
[0] == DISPID_PROPERTYPUT
, "pdp->rgdispidNamedArgs[0] = %d\n", pdp
->rgdispidNamedArgs
[0]);
535 ok(!pvarRes
, "pvarRes != NULL\n");
537 ok(V_VT(pdp
->rgvarg
) == VT_I4
, "V_VT(pdp->rgvarg)=%d\n", V_VT(pdp
->rgvarg
));
538 ok(V_I4(pdp
->rgvarg
) == 1, "V_I4(pdp->rgvarg)=%d\n", V_I4(pdp
->rgvarg
));
541 case DISPID_GLOBAL_GETVT
:
542 ok(pdp
!= NULL
, "pdp == NULL\n");
543 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
544 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
545 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
546 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
547 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
548 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
549 ok(pei
!= NULL
, "pei == NULL\n");
551 V_VT(pvarRes
) = VT_BSTR
;
552 switch(V_VT(pdp
->rgvarg
)) {
554 V_BSTR(pvarRes
) = a2bstr("VT_EMPTY");
557 V_BSTR(pvarRes
) = a2bstr("VT_NULL");
560 V_BSTR(pvarRes
) = a2bstr("VT_I4");
563 V_BSTR(pvarRes
) = a2bstr("VT_R8");
566 V_BSTR(pvarRes
) = a2bstr("VT_BSTR");
569 V_BSTR(pvarRes
) = a2bstr("VT_DISPATCH");
572 V_BSTR(pvarRes
) = a2bstr("VT_BOOL");
574 case VT_ARRAY
|VT_VARIANT
:
575 V_BSTR(pvarRes
) = a2bstr("VT_ARRAY|VT_VARIANT");
578 ok(0, "unknown vt %d\n", V_VT(pdp
->rgvarg
));
584 case DISPID_GLOBAL_TESTOBJ
:
585 ok(wFlags
== INVOKE_PROPERTYGET
, "wFlags = %x\n", wFlags
);
586 ok(pdp
!= NULL
, "pdp == NULL\n");
587 ok(!pdp
->rgvarg
, "rgvarg != NULL\n");
588 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
589 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
590 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
591 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
592 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
593 ok(pei
!= NULL
, "pei == NULL\n");
595 V_VT(pvarRes
) = VT_DISPATCH
;
596 V_DISPATCH(pvarRes
) = (IDispatch
*)&testObj
;
599 case DISPID_GLOBAL_PUREDISP
:
600 ok(wFlags
== INVOKE_PROPERTYGET
, "wFlags = %x\n", wFlags
);
601 ok(pdp
!= NULL
, "pdp == NULL\n");
602 ok(!pdp
->rgvarg
, "rgvarg != NULL\n");
603 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
604 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
605 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
606 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
607 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
608 ok(pei
!= NULL
, "pei == NULL\n");
610 V_VT(pvarRes
) = VT_DISPATCH
;
611 V_DISPATCH(pvarRes
) = (IDispatch
*)&pureDisp
;
614 case DISPID_GLOBAL_NULL_BSTR
:
616 V_VT(pvarRes
) = VT_BSTR
;
617 V_BSTR(pvarRes
) = NULL
;
621 case DISPID_GLOBAL_ISWIN64
:
623 V_VT(pvarRes
) = VT_BOOL
;
624 V_BOOL(pvarRes
) = sizeof(void*) == 8 ? VARIANT_TRUE
: VARIANT_FALSE
;
628 case DISPID_GLOBAL_NULL_DISP
:
629 ok(wFlags
== INVOKE_PROPERTYGET
, "wFlags = %x\n", wFlags
);
630 ok(pdp
!= NULL
, "pdp == NULL\n");
631 ok(!pdp
->rgvarg
, "rgvarg != NULL\n");
632 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
633 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
634 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
635 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
636 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
637 ok(pei
!= NULL
, "pei == NULL\n");
639 V_VT(pvarRes
) = VT_DISPATCH
;
640 V_DISPATCH(pvarRes
) = NULL
;
643 case DISPID_GLOBAL_TESTTHIS
:
644 ok(pdp
!= NULL
, "pdp == NULL\n");
645 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
646 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
647 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
648 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
649 ok(pvarRes
== NULL
, "pvarRes != NULL\n");
650 ok(pei
!= NULL
, "pei == NULL\n");
652 ok(V_VT(pdp
->rgvarg
) == VT_DISPATCH
, "V_VT(arg) = %d\n", V_VT(pdp
->rgvarg
));
653 ok(V_DISPATCH(pdp
->rgvarg
) == (IDispatch
*)iface
, "disp != iface\n");
657 case DISPID_GLOBAL_TESTTHIS2
:
658 ok(pdp
!= NULL
, "pdp == NULL\n");
659 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
660 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
661 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
662 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
663 ok(pvarRes
== NULL
, "pvarRes != NULL\n");
664 ok(pei
!= NULL
, "pei == NULL\n");
666 ok(V_VT(pdp
->rgvarg
) == VT_DISPATCH
, "V_VT(arg) = %d\n", V_VT(pdp
->rgvarg
));
667 ok(V_DISPATCH(pdp
->rgvarg
) != (IDispatch
*)iface
, "disp == iface\n");
668 ok(V_DISPATCH(pdp
->rgvarg
) == script_disp
, "disp != script_disp\n");
672 case DISPID_GLOBAL_INVOKEVERSION
:
673 ok(wFlags
== INVOKE_PROPERTYGET
, "wFlags = %x\n", wFlags
);
674 ok(pdp
!= NULL
, "pdp == NULL\n");
675 ok(!pdp
->rgvarg
, "rgvarg != NULL\n");
676 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
677 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
678 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
679 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
680 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
681 ok(pei
!= NULL
, "pei == NULL\n");
683 V_VT(pvarRes
) = VT_I4
;
684 V_I4(pvarRes
) = invoke_version
;
688 case DISPID_GLOBAL_CREATEARRAY
: {
689 SAFEARRAYBOUND bound
[2];
693 ok(wFlags
== INVOKE_FUNC
, "wFlags = %x\n", wFlags
);
694 ok(pdp
!= NULL
, "pdp == NULL\n");
695 todo_wine
ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
696 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
697 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
698 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
699 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
700 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
701 ok(pei
!= NULL
, "pei == NULL\n");
703 bound
[0].lLbound
= 0;
704 bound
[0].cElements
= 5;
705 bound
[1].lLbound
= 2;
706 bound
[1].cElements
= 2;
708 V_VT(pvarRes
) = VT_ARRAY
|VT_VARIANT
;
709 V_ARRAY(pvarRes
) = SafeArrayCreate(VT_VARIANT
, 2, bound
);
711 SafeArrayAccessData(V_ARRAY(pvarRes
), (void**)&data
);
719 SafeArrayUnaccessData(V_ARRAY(pvarRes
));
724 case DISPID_GLOBAL_PROPGETFUNC
:
727 CHECK_EXPECT(invoke_func
);
729 case INVOKE_FUNC
|INVOKE_PROPERTYGET
:
730 ok(pdp
->cArgs
!= 0, "pdp->cArgs = %d\n", pdp
->cArgs
);
731 ok(pvarRes
!= NULL
, "pdp->pvarRes == NULL\n");
734 ok(0, "invalid flag (%x)\n", wFlags
);
737 ok(pdp
!= NULL
, "pdp == NULL\n");
738 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
739 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
740 ok(pei
!= NULL
, "pei == NULL\n");
743 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
744 V_VT(pvarRes
) = VT_I4
;
745 V_I4(pvarRes
) = pdp
->cArgs
;
750 case DISPID_GLOBAL_OBJECT_FLAG
: {
755 hres
= IDispatch_QueryInterface(script_disp
, &IID_IDispatchEx
, (void**)&dispex
);
756 ok(hres
== S_OK
, "hres = %x\n", hres
);
758 str
= a2bstr("Object");
759 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseSensitive
, &id
);
761 ok(hres
== S_OK
, "hres = %x\n", hres
);
763 hres
= IDispatchEx_InvokeEx(dispex
, id
, lcid
, DISPATCH_METHOD
, pdp
, NULL
, pei
, pspCaller
);
764 ok(hres
== S_OK
, "hres = %x\n", hres
);
766 V_VT(pvarRes
) = VT_EMPTY
;
767 hres
= IDispatchEx_InvokeEx(dispex
, id
, lcid
, DISPATCH_METHOD
, pdp
, pvarRes
, pei
, pspCaller
);
768 ok(hres
== S_OK
, "hres = %x\n", hres
);
769 ok(V_VT(pvarRes
) == VT_DISPATCH
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
770 VariantClear(pvarRes
);
772 hres
= IDispatchEx_InvokeEx(dispex
, id
, lcid
, DISPATCH_METHOD
|DISPATCH_PROPERTYGET
, pdp
, NULL
, pei
, pspCaller
);
773 ok(hres
== S_OK
, "hres = %x\n", hres
);
775 V_VT(pvarRes
) = VT_EMPTY
;
776 hres
= IDispatchEx_InvokeEx(dispex
, id
, lcid
, DISPATCH_CONSTRUCT
, pdp
, pvarRes
, pei
, pspCaller
);
777 ok(hres
== S_OK
, "hres = %x\n", hres
);
778 ok(V_VT(pvarRes
) == VT_DISPATCH
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
779 VariantClear(pvarRes
);
781 hres
= IDispatchEx_InvokeEx(dispex
, id
, lcid
, DISPATCH_CONSTRUCT
, pdp
, NULL
, pei
, pspCaller
);
782 ok(hres
== S_OK
, "hres = %x\n", hres
);
784 V_VT(pvarRes
) = VT_EMPTY
;
785 hres
= IDispatchEx_InvokeEx(dispex
, id
, lcid
, DISPATCH_CONSTRUCT
|DISPATCH_PROPERTYGET
, pdp
, pvarRes
, pei
, pspCaller
);
786 ok(hres
== E_INVALIDARG
, "hres = %x\n", hres
);
788 V_VT(pvarRes
) = VT_EMPTY
;
789 hres
= IDispatchEx_InvokeEx(dispex
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
790 ok(hres
== S_OK
, "hres = %x\n", hres
);
791 ok(V_VT(pvarRes
) == VT_DISPATCH
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
792 IDispatchEx_Release(dispex
);
797 ok(0, "unexpected call %x\n", id
);
798 return DISP_E_MEMBERNOTFOUND
;
801 static IDispatchExVtbl GlobalVtbl
= {
802 DispatchEx_QueryInterface
,
805 DispatchEx_GetTypeInfoCount
,
806 DispatchEx_GetTypeInfo
,
807 DispatchEx_GetIDsOfNames
,
811 DispatchEx_DeleteMemberByName
,
812 DispatchEx_DeleteMemberByDispID
,
813 DispatchEx_GetMemberProperties
,
814 DispatchEx_GetMemberName
,
815 DispatchEx_GetNextDispID
,
816 DispatchEx_GetNameSpaceParent
819 static IDispatchEx Global
= { &GlobalVtbl
};
821 static HRESULT WINAPI
ActiveScriptSite_QueryInterface(IActiveScriptSite
*iface
, REFIID riid
, void **ppv
)
825 if(IsEqualGUID(&IID_IUnknown
, riid
))
827 else if(IsEqualGUID(&IID_IActiveScriptSite
, riid
))
830 return E_NOINTERFACE
;
832 IUnknown_AddRef((IUnknown
*)*ppv
);
836 static ULONG WINAPI
ActiveScriptSite_AddRef(IActiveScriptSite
*iface
)
841 static ULONG WINAPI
ActiveScriptSite_Release(IActiveScriptSite
*iface
)
846 static HRESULT WINAPI
ActiveScriptSite_GetLCID(IActiveScriptSite
*iface
, LCID
*plcid
)
848 *plcid
= GetUserDefaultLCID();
852 static HRESULT WINAPI
ActiveScriptSite_GetItemInfo(IActiveScriptSite
*iface
, LPCOLESTR pstrName
,
853 DWORD dwReturnMask
, IUnknown
**ppiunkItem
, ITypeInfo
**ppti
)
855 ok(dwReturnMask
== SCRIPTINFO_IUNKNOWN
, "unexpected dwReturnMask %x\n", dwReturnMask
);
856 ok(!ppti
, "ppti != NULL\n");
858 if(!strcmp_wa(pstrName
, test_valA
))
859 CHECK_EXPECT(GetItemInfo_testVal
);
860 else if(strcmp_wa(pstrName
, testA
))
861 ok(0, "unexpected pstrName %s\n", wine_dbgstr_w(pstrName
));
863 *ppiunkItem
= (IUnknown
*)&Global
;
867 static HRESULT WINAPI
ActiveScriptSite_GetDocVersionString(IActiveScriptSite
*iface
, BSTR
*pbstrVersion
)
872 static HRESULT WINAPI
ActiveScriptSite_OnScriptTerminate(IActiveScriptSite
*iface
,
873 const VARIANT
*pvarResult
, const EXCEPINFO
*pexcepinfo
)
878 static HRESULT WINAPI
ActiveScriptSite_OnStateChange(IActiveScriptSite
*iface
, SCRIPTSTATE ssScriptState
)
883 static HRESULT WINAPI
ActiveScriptSite_OnScriptError(IActiveScriptSite
*iface
, IActiveScriptError
*pscripterror
)
888 static HRESULT WINAPI
ActiveScriptSite_OnEnterScript(IActiveScriptSite
*iface
)
893 static HRESULT WINAPI
ActiveScriptSite_OnLeaveScript(IActiveScriptSite
*iface
)
898 #undef ACTSCPSITE_THIS
900 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl
= {
901 ActiveScriptSite_QueryInterface
,
902 ActiveScriptSite_AddRef
,
903 ActiveScriptSite_Release
,
904 ActiveScriptSite_GetLCID
,
905 ActiveScriptSite_GetItemInfo
,
906 ActiveScriptSite_GetDocVersionString
,
907 ActiveScriptSite_OnScriptTerminate
,
908 ActiveScriptSite_OnStateChange
,
909 ActiveScriptSite_OnScriptError
,
910 ActiveScriptSite_OnEnterScript
,
911 ActiveScriptSite_OnLeaveScript
914 static IActiveScriptSite ActiveScriptSite
= { &ActiveScriptSiteVtbl
};
916 static HRESULT WINAPI
ActiveScriptSite_OnScriptError_CheckError(IActiveScriptSite
*iface
, IActiveScriptError
*pscripterror
)
918 ok(pscripterror
!= NULL
, "ActiveScriptSite_OnScriptError -- expected pscripterror to be set, got NULL\n");
920 script_error
= pscripterror
;
921 IUnknown_AddRef(script_error
);
923 CHECK_EXPECT(ActiveScriptSite_OnScriptError
);
928 static const IActiveScriptSiteVtbl ActiveScriptSite_CheckErrorVtbl
= {
929 ActiveScriptSite_QueryInterface
,
930 ActiveScriptSite_AddRef
,
931 ActiveScriptSite_Release
,
932 ActiveScriptSite_GetLCID
,
933 ActiveScriptSite_GetItemInfo
,
934 ActiveScriptSite_GetDocVersionString
,
935 ActiveScriptSite_OnScriptTerminate
,
936 ActiveScriptSite_OnStateChange
,
937 ActiveScriptSite_OnScriptError_CheckError
,
938 ActiveScriptSite_OnEnterScript
,
939 ActiveScriptSite_OnLeaveScript
942 static IActiveScriptSite ActiveScriptSite_CheckError
= { &ActiveScriptSite_CheckErrorVtbl
};
944 static HRESULT
set_script_prop(IActiveScript
*engine
, DWORD property
, VARIANT
*val
)
946 IActiveScriptProperty
*script_prop
;
949 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptProperty
,
950 (void**)&script_prop
);
951 ok(hres
== S_OK
, "Could not get IActiveScriptProperty iface: %08x\n", hres
);
953 hres
= IActiveScriptProperty_SetProperty(script_prop
, property
, NULL
, val
);
954 IActiveScriptProperty_Release(script_prop
);
959 static IActiveScript
*create_script(void)
961 IActiveScript
*script
;
965 hres
= CoCreateInstance(&CLSID_JScript
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
966 &IID_IActiveScript
, (void**)&script
);
967 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
970 V_I4(&v
) = invoke_version
;
971 hres
= set_script_prop(script
, SCRIPTPROP_INVOKEVERSIONING
, &v
);
972 ok(hres
== S_OK
|| broken(hres
== E_NOTIMPL
), "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres
);
973 if(invoke_version
&& FAILED(hres
)) {
974 IActiveScript_Release(script
);
981 static HRESULT
parse_script(DWORD flags
, BSTR script_str
)
983 IActiveScriptParse
*parser
;
984 IActiveScript
*engine
;
987 engine
= create_script();
991 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptParse
, (void**)&parser
);
992 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
995 IActiveScript_Release(engine
);
999 hres
= IActiveScriptParse64_InitNew(parser
);
1000 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
1002 hres
= IActiveScript_SetScriptSite(engine
, &ActiveScriptSite
);
1003 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1005 hres
= IActiveScript_AddNamedItem(engine
, testW
,
1006 SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|flags
);
1007 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
1009 hres
= IActiveScript_SetScriptState(engine
, SCRIPTSTATE_STARTED
);
1010 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
1012 hres
= IActiveScript_GetScriptDispatch(engine
, NULL
, &script_disp
);
1013 ok(hres
== S_OK
, "GetScriptDispatch failed: %08x\n", hres
);
1014 ok(script_disp
!= NULL
, "script_disp == NULL\n");
1015 ok(script_disp
!= (IDispatch
*)&Global
, "script_disp == Global\n");
1017 hres
= IActiveScriptParse64_ParseScriptText(parser
, script_str
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
1019 IDispatch_Release(script_disp
);
1020 IActiveScript_Release(engine
);
1021 IUnknown_Release(parser
);
1026 static HRESULT
parse_htmlscript(BSTR script_str
)
1028 IActiveScriptParse
*parser
;
1029 IActiveScript
*engine
;
1031 BSTR tmp
= a2bstr("</SCRIPT>");
1033 engine
= create_script();
1037 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptParse
, (void**)&parser
);
1038 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
1041 IActiveScript_Release(engine
);
1045 hres
= IActiveScriptParse64_InitNew(parser
);
1046 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
1048 hres
= IActiveScript_SetScriptSite(engine
, &ActiveScriptSite
);
1049 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1051 hres
= IActiveScript_AddNamedItem(engine
, testW
,
1052 SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|SCRIPTITEM_GLOBALMEMBERS
);
1053 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
1055 hres
= IActiveScript_SetScriptState(engine
, SCRIPTSTATE_STARTED
);
1056 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
1058 hres
= IActiveScriptParse64_ParseScriptText(parser
, script_str
, NULL
, NULL
, tmp
, 0, 0, 0, NULL
, NULL
);
1060 IActiveScript_Release(engine
);
1061 IUnknown_Release(parser
);
1067 static void test_IActiveScriptError(IActiveScriptError
*error
, SCODE errorcode
, ULONG line
, LONG pos
, BSTR script_source
, BSTR description
, BSTR line_text
)
1070 DWORD source_context
;
1076 /* IActiveScriptError_GetSourcePosition */
1078 hres
= IActiveScriptError_GetSourcePosition(error
, NULL
, NULL
, NULL
);
1079 ok(hres
== S_OK
, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres
);
1081 source_context
= 0xdeadbeef;
1082 hres
= IActiveScriptError_GetSourcePosition(error
, &source_context
, NULL
, NULL
);
1083 ok(hres
== S_OK
, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres
);
1084 ok(source_context
== 0, "IActiveScriptError_GetSourcePosition -- source_context: expected 0, got 0x%08x\n", source_context
);
1086 line_number
= 0xdeadbeef;
1087 hres
= IActiveScriptError_GetSourcePosition(error
, NULL
, &line_number
, NULL
);
1088 ok(hres
== S_OK
, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres
);
1089 ok(line_number
== line
, "IActiveScriptError_GetSourcePosition -- line_number: expected %d, got %d\n", line
, line_number
);
1091 char_position
= 0xdeadbeef;
1092 hres
= IActiveScriptError_GetSourcePosition(error
, NULL
, NULL
, &char_position
);
1093 ok(hres
== S_OK
, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres
);
1094 ok(char_position
== pos
, "IActiveScriptError_GetSourcePosition -- char_position: expected %d, got %d\n", pos
, char_position
);
1096 /* IActiveScriptError_GetSourceLineText */
1098 hres
= IActiveScriptError_GetSourceLineText(error
, NULL
);
1099 ok(hres
== E_POINTER
, "IActiveScriptError_GetSourceLineText -- hres: expected E_POINTER, got 0x%08x\n", hres
);
1102 hres
= IActiveScriptError_GetSourceLineText(error
, &linetext
);
1104 ok(hres
== S_OK
, "IActiveScriptError_GetSourceLineText -- hres: expected S_OK, got 0x%08x\n", hres
);
1105 ok(linetext
!= NULL
&& !lstrcmpW(linetext
, line_text
),
1106 "IActiveScriptError_GetSourceLineText -- expected %s, got %s\n", wine_dbgstr_w(line_text
), wine_dbgstr_w(linetext
));
1108 ok(hres
== E_FAIL
, "IActiveScriptError_GetSourceLineText -- hres: expected S_OK, got 0x%08x\n", hres
);
1109 ok(linetext
== NULL
,
1110 "IActiveScriptError_GetSourceLineText -- expected NULL, got %s\n", wine_dbgstr_w(linetext
));
1112 SysFreeString(linetext
);
1114 /* IActiveScriptError_GetExceptionInfo */
1116 hres
= IActiveScriptError_GetExceptionInfo(error
, NULL
);
1117 ok(hres
== E_POINTER
, "IActiveScriptError_GetExceptionInfo -- hres: expected E_POINTER, got 0x%08x\n", hres
);
1119 excep
.wCode
= 0xdead;
1120 excep
.wReserved
= 0xdead;
1121 excep
.bstrSource
= (BSTR
)0xdeadbeef;
1122 excep
.bstrDescription
= (BSTR
)0xdeadbeef;
1123 excep
.bstrHelpFile
= (BSTR
)0xdeadbeef;
1124 excep
.dwHelpContext
= 0xdeadbeef;
1125 excep
.pvReserved
= (void *)0xdeadbeef;
1126 excep
.pfnDeferredFillIn
= (void *)0xdeadbeef;
1127 excep
.scode
= 0xdeadbeef;
1129 hres
= IActiveScriptError_GetExceptionInfo(error
, &excep
);
1130 ok(hres
== S_OK
, "IActiveScriptError_GetExceptionInfo -- hres: expected S_OK, got 0x%08x\n", hres
);
1132 ok(excep
.wCode
== 0, "IActiveScriptError_GetExceptionInfo -- excep.wCode: expected 0, got 0x%08x\n", excep
.wCode
);
1133 ok(excep
.wReserved
== 0, "IActiveScriptError_GetExceptionInfo -- excep.wReserved: expected 0, got %d\n", excep
.wReserved
);
1134 if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH
)
1135 skip("Non-english locale (test with hardcoded strings)\n");
1137 ok(excep
.bstrSource
!= NULL
&& !lstrcmpW(excep
.bstrSource
, script_source
),
1138 "IActiveScriptError_GetExceptionInfo -- excep.bstrSource is not valid: expected %s, got %s\n",
1139 wine_dbgstr_w(script_source
), wine_dbgstr_w(excep
.bstrSource
));
1140 ok(excep
.bstrDescription
!= NULL
&& !lstrcmpW(excep
.bstrDescription
, description
),
1141 "IActiveScriptError_GetExceptionInfo -- excep.bstrDescription is not valid: got %s\n", wine_dbgstr_w(excep
.bstrDescription
));
1143 ok(excep
.bstrHelpFile
== NULL
,
1144 "IActiveScriptError_GetExceptionInfo -- excep.bstrHelpFile: expected NULL, got %s\n", wine_dbgstr_w(excep
.bstrHelpFile
));
1145 ok(excep
.dwHelpContext
== 0, "IActiveScriptError_GetExceptionInfo -- excep.dwHelpContext: expected 0, got %d\n", excep
.dwHelpContext
);
1146 ok(excep
.pvReserved
== NULL
, "IActiveScriptError_GetExceptionInfo -- excep.pvReserved: expected NULL, got %p\n", excep
.pvReserved
);
1147 ok(excep
.pfnDeferredFillIn
== NULL
, "IActiveScriptError_GetExceptionInfo -- excep.pfnDeferredFillIn: expected NULL, got %p\n", excep
.pfnDeferredFillIn
);
1148 ok(excep
.scode
== errorcode
, "IActiveScriptError_GetExceptionInfo -- excep.scode: expected 0x%08x, got 0x%08x\n", errorcode
, excep
.scode
);
1150 SysFreeString(excep
.bstrSource
);
1151 SysFreeString(excep
.bstrDescription
);
1152 SysFreeString(excep
.bstrHelpFile
);
1155 static void parse_script_with_error(DWORD flags
, BSTR script_str
, SCODE errorcode
, ULONG line
, LONG pos
, BSTR script_source
, BSTR description
, BSTR line_text
)
1157 IActiveScriptParse
*parser
;
1158 IActiveScript
*engine
;
1161 engine
= create_script();
1165 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptParse
, (void**)&parser
);
1166 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
1169 IActiveScript_Release(engine
);
1173 hres
= IActiveScriptParse64_InitNew(parser
);
1174 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
1176 hres
= IActiveScript_SetScriptSite(engine
, &ActiveScriptSite_CheckError
);
1177 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1179 hres
= IActiveScript_AddNamedItem(engine
, testW
,
1180 SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|flags
);
1181 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
1183 hres
= IActiveScript_SetScriptState(engine
, SCRIPTSTATE_STARTED
);
1184 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
1186 hres
= IActiveScript_GetScriptDispatch(engine
, NULL
, &script_disp
);
1187 ok(hres
== S_OK
, "GetScriptDispatch failed: %08x\n", hres
);
1188 ok(script_disp
!= NULL
, "script_disp == NULL\n");
1189 ok(script_disp
!= (IDispatch
*)&Global
, "script_disp == Global\n");
1191 script_error
= NULL
;
1192 SET_EXPECT(ActiveScriptSite_OnScriptError
);
1193 hres
= IActiveScriptParse64_ParseScriptText(parser
, script_str
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
1194 todo_wine
ok(hres
== 0x80020101, "parse_script_with_error should have returned 0x80020101, got: 0x%08x\n", hres
);
1195 todo_wine
CHECK_CALLED(ActiveScriptSite_OnScriptError
);
1199 test_IActiveScriptError(script_error
, errorcode
, line
, pos
, script_source
, description
, line_text
);
1201 IUnknown_Release(script_error
);
1204 IDispatch_Release(script_disp
);
1205 IActiveScript_Release(engine
);
1206 IUnknown_Release(parser
);
1209 static void parse_script_af(DWORD flags
, const char *src
)
1215 hres
= parse_script(flags
, tmp
);
1217 ok(hres
== S_OK
, "parse_script failed: %08x\n", hres
);
1220 static void parse_script_a(const char *src
)
1222 parse_script_af(SCRIPTITEM_GLOBALMEMBERS
, src
);
1225 static void parse_script_with_error_a(const char *src
, SCODE errorcode
, ULONG line
, LONG pos
, LPCSTR source
, LPCSTR desc
, LPCSTR linetext
)
1227 BSTR tmp
, script_source
, description
, line_text
;
1230 script_source
= a2bstr(source
);
1231 description
= a2bstr(desc
);
1232 line_text
= a2bstr(linetext
);
1234 parse_script_with_error(SCRIPTITEM_GLOBALMEMBERS
, tmp
, errorcode
, line
, pos
, script_source
, description
, line_text
);
1236 SysFreeString(line_text
);
1237 SysFreeString(description
);
1238 SysFreeString(script_source
);
1242 static HRESULT
parse_htmlscript_a(const char *src
)
1245 BSTR tmp
= a2bstr(src
);
1246 hres
= parse_htmlscript(tmp
);
1252 static BSTR
get_script_from_file(const char *filename
)
1256 const char *file_map
;
1259 file
= CreateFileA(filename
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_READONLY
, NULL
);
1260 if(file
== INVALID_HANDLE_VALUE
) {
1261 trace("Could not open file: %u\n", GetLastError());
1265 size
= GetFileSize(file
, NULL
);
1267 map
= CreateFileMapping(file
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
1269 if(map
== INVALID_HANDLE_VALUE
) {
1270 trace("Could not create file mapping: %u\n", GetLastError());
1274 file_map
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
1277 trace("MapViewOfFile failed: %u\n", GetLastError());
1281 len
= MultiByteToWideChar(CP_ACP
, 0, file_map
, size
, NULL
, 0);
1282 ret
= SysAllocStringLen(NULL
, len
);
1283 MultiByteToWideChar(CP_ACP
, 0, file_map
, size
, ret
, len
);
1285 UnmapViewOfFile(file_map
);
1290 static void run_from_file(const char *filename
)
1295 script_str
= get_script_from_file(filename
);
1299 strict_dispid_check
= FALSE
;
1300 hres
= parse_script(SCRIPTITEM_GLOBALMEMBERS
, script_str
);
1301 SysFreeString(script_str
);
1302 ok(hres
== S_OK
, "parse_script failed: %08x\n", hres
);
1305 static void run_from_res(const char *name
)
1313 strict_dispid_check
= FALSE
;
1316 src
= FindResourceA(NULL
, name
, (LPCSTR
)40);
1317 ok(src
!= NULL
, "Could not find resource %s\n", name
);
1319 size
= SizeofResource(NULL
, src
);
1320 data
= LoadResource(NULL
, src
);
1322 len
= MultiByteToWideChar(CP_ACP
, 0, data
, size
, NULL
, 0);
1323 str
= SysAllocStringLen(NULL
, len
);
1324 MultiByteToWideChar(CP_ACP
, 0, data
, size
, str
, len
);
1326 SET_EXPECT(global_success_d
);
1327 SET_EXPECT(global_success_i
);
1328 hres
= parse_script(SCRIPTITEM_GLOBALMEMBERS
, str
);
1329 CHECK_CALLED(global_success_d
);
1330 CHECK_CALLED(global_success_i
);
1332 ok(hres
== S_OK
, "parse_script failed: %08x\n", hres
);
1336 static void test_isvisible(BOOL global_members
)
1338 IActiveScriptParse
*parser
;
1339 IActiveScript
*engine
;
1342 static const WCHAR script_textW
[] =
1343 {'v','a','r',' ','v',' ','=',' ','t','e','s','t','V','a','l',';',0};
1345 engine
= create_script();
1349 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptParse
, (void**)&parser
);
1350 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
1353 IActiveScript_Release(engine
);
1357 hres
= IActiveScriptParse64_InitNew(parser
);
1358 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
1360 hres
= IActiveScript_SetScriptSite(engine
, &ActiveScriptSite
);
1361 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1364 SET_EXPECT(GetItemInfo_testVal
);
1365 hres
= IActiveScript_AddNamedItem(engine
, test_valW
,
1366 SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|
1367 (global_members
? SCRIPTITEM_GLOBALMEMBERS
: 0));
1368 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
1370 CHECK_CALLED(GetItemInfo_testVal
);
1372 hres
= IActiveScript_SetScriptState(engine
, SCRIPTSTATE_STARTED
);
1373 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
1376 SET_EXPECT(GetItemInfo_testVal
);
1377 hres
= IActiveScriptParse64_ParseScriptText(parser
, script_textW
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
1378 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1380 CHECK_CALLED(GetItemInfo_testVal
);
1382 hres
= IActiveScriptParse64_ParseScriptText(parser
, script_textW
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
1383 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1385 IActiveScript_Release(engine
);
1386 IUnknown_Release(parser
);
1389 static void run_tests(void)
1393 if(invoke_version
) {
1394 IActiveScript
*script
;
1396 script
= create_script();
1398 win_skip("Could not create script\n");
1401 IActiveScript_Release(script
);
1404 strict_dispid_check
= TRUE
;
1407 parse_script_a("/* empty */ ;");
1409 SET_EXPECT(global_propget_d
);
1410 SET_EXPECT(global_propget_i
);
1411 parse_script_a("testPropGet;");
1412 CHECK_CALLED(global_propget_d
);
1413 CHECK_CALLED(global_propget_i
);
1415 SET_EXPECT(global_propput_d
);
1416 SET_EXPECT(global_propput_i
);
1417 parse_script_a("testPropPut = 1;");
1418 CHECK_CALLED(global_propput_d
);
1419 CHECK_CALLED(global_propput_i
);
1421 SET_EXPECT(global_success_d
);
1422 SET_EXPECT(global_success_i
);
1423 parse_script_a("reportSuccess();");
1424 CHECK_CALLED(global_success_d
);
1425 CHECK_CALLED(global_success_i
);
1427 SET_EXPECT(testobj_delete
);
1428 parse_script_a("delete testObj.deleteTest;");
1429 CHECK_CALLED(testobj_delete
);
1431 parse_script_a("ok(typeof(test) === 'object', \"typeof(test) != 'object'\");");
1433 parse_script_a("function reportSuccess() {}; reportSuccess();");
1435 SET_EXPECT(global_propget_d
);
1436 parse_script_a("var testPropGet");
1437 CHECK_CALLED(global_propget_d
);
1439 SET_EXPECT(global_propget_d
);
1440 parse_script_a("eval('var testPropGet;');");
1441 CHECK_CALLED(global_propget_d
);
1443 SET_EXPECT(global_notexists_d
);
1444 parse_script_a("var notExists; notExists = 1;");
1445 CHECK_CALLED(global_notexists_d
);
1447 parse_script_a("function f() { var testPropGet; }");
1448 parse_script_a("(function () { var testPropGet; })();");
1449 parse_script_a("(function () { eval('var testPropGet;'); })();");
1451 SET_EXPECT(invoke_func
);
1452 parse_script_a("ok(propGetFunc() == 0, \"Incorrect propGetFunc value\");");
1453 CHECK_CALLED(invoke_func
);
1454 parse_script_a("ok(propGetFunc(1) == 1, \"Incorrect propGetFunc value\");");
1455 parse_script_a("ok(propGetFunc(1, 2) == 2, \"Incorrect propGetFunc value\");");
1456 SET_EXPECT(invoke_func
);
1457 parse_script_a("ok(propGetFunc().toString() == 0, \"Incorrect propGetFunc value\");");
1458 CHECK_CALLED(invoke_func
);
1459 parse_script_a("ok(propGetFunc(1).toString() == 1, \"Incorrect propGetFunc value\");");
1460 SET_EXPECT(invoke_func
);
1461 parse_script_a("propGetFunc(1);");
1462 CHECK_CALLED(invoke_func
);
1464 parse_script_a("objectFlag(1).toString();");
1466 parse_script_a("(function() { var tmp = (function () { return testObj; })()(1);})();");
1467 parse_script_a("(function() { var tmp = (function () { return testObj; })()();})();");
1469 parse_script_a("ok((testObj instanceof Object) === false, 'testObj is instance of Object');");
1471 SET_EXPECT(testobj_prop_d
);
1472 parse_script_a("ok(('prop' in testObj) === true, 'prop is not in testObj');");
1473 CHECK_CALLED(testobj_prop_d
);
1475 SET_EXPECT(testobj_noprop_d
);
1476 parse_script_a("ok(('noprop' in testObj) === false, 'noprop is in testObj');");
1477 CHECK_CALLED(testobj_noprop_d
);
1479 SET_EXPECT(testobj_value
);
1480 parse_script_a("ok(String(testObj) === '1', 'wrong testObj value');");
1481 CHECK_CALLED(testobj_value
);
1483 SET_EXPECT(testobj_value
);
1484 parse_script_a("ok(String.prototype.concat.call(testObj, ' OK') === '1 OK', 'wrong concat result');");
1485 CHECK_CALLED(testobj_value
);
1487 SET_EXPECT(global_propget_d
);
1488 SET_EXPECT(global_propget_i
);
1489 parse_script_a("this.testPropGet;");
1490 CHECK_CALLED(global_propget_d
);
1491 CHECK_CALLED(global_propget_i
);
1493 SET_EXPECT(global_propget_d
);
1494 SET_EXPECT(global_propget_i
);
1495 parse_script_a("(function () { this.testPropGet; })();");
1496 CHECK_CALLED(global_propget_d
);
1497 CHECK_CALLED(global_propget_i
);
1499 parse_script_a("testThis(this);");
1500 parse_script_a("(function () { testThis(this); })();");
1502 SET_EXPECT(testobj_onlydispid_d
);
1503 SET_EXPECT(testobj_onlydispid_i
);
1504 parse_script_a("ok(typeof(testObj.onlyDispID) === 'unknown', 'unexpected typeof(testObj.onlyDispID)');");
1505 CHECK_CALLED(testobj_onlydispid_d
);
1506 CHECK_CALLED(testobj_onlydispid_i
);
1508 run_from_res("lang.js");
1509 run_from_res("api.js");
1510 run_from_res("regexp.js");
1511 run_from_res("cc.js");
1513 test_isvisible(FALSE
);
1514 test_isvisible(TRUE
);
1516 parse_script_af(0, "test.testThis2(this);");
1517 parse_script_af(0, "(function () { test.testThis2(this); })();");
1519 hres
= parse_htmlscript_a("<!--");
1520 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1521 hres
= parse_htmlscript_a("-->");
1522 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1523 hres
= parse_htmlscript_a("<!--\nvar a=1;\n-->\n");
1524 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1525 hres
= parse_htmlscript_a("<!--\n<!-- ignore this\n-->\n");
1526 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1527 hres
= parse_htmlscript_a("var a=1;\nif(a-->0) a=5;\n");
1528 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1529 hres
= parse_htmlscript_a("var a=1;\nif(a\n-->0) a=5;\n");
1530 ok(hres
!= S_OK
, "ParseScriptText have not failed\n");
1532 parse_script_with_error_a(
1535 "Microsoft JScript compilation error",
1539 parse_script_with_error_a(
1540 "var a=1;\nif(a\n-->0) a=5;\n",
1542 "Microsoft JScript compilation error",
1546 parse_script_with_error_a(
1549 "Microsoft JScript runtime error",
1550 "Object doesn't support this action",
1553 parse_script_with_error_a(
1556 "Microsoft JScript runtime error",
1560 parse_script_with_error_a(
1561 "var a;\nnew null;",
1563 "Microsoft JScript runtime error",
1567 parse_script_with_error_a(
1570 "Microsoft JScript runtime error",
1575 static BOOL
check_jscript(void)
1577 IActiveScriptProperty
*script_prop
;
1581 hres
= CoCreateInstance(&CLSID_JScript
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1582 &IID_IActiveScriptProperty
, (void**)&script_prop
);
1585 IActiveScriptProperty_Release(script_prop
);
1587 str
= a2bstr("if(!('localeCompare' in String.prototype)) throw 1;");
1588 hres
= parse_script(0, str
);
1591 return hres
== S_OK
;
1599 argc
= winetest_get_mainargs(&argv
);
1603 if(!check_jscript()) {
1604 win_skip("Broken engine, probably too old\n");
1605 }else if(argc
> 2) {
1606 run_from_file(argv
[2]);
1608 trace("invoke version 0\n");
1612 trace("invoke version 2\n");