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);
72 DEFINE_EXPECT(ActiveScriptSite_OnScriptError);
73 DEFINE_EXPECT(invoke_func);
75 #define DISPID_GLOBAL_TESTPROPGET 0x1000
76 #define DISPID_GLOBAL_TESTPROPPUT 0x1001
77 #define DISPID_GLOBAL_REPORTSUCCESS 0x1002
78 #define DISPID_GLOBAL_TRACE 0x1003
79 #define DISPID_GLOBAL_OK 0x1004
80 #define DISPID_GLOBAL_GETVT 0x1005
81 #define DISPID_GLOBAL_TESTOBJ 0x1006
82 #define DISPID_GLOBAL_NULL_BSTR 0x1007
83 #define DISPID_GLOBAL_NULL_DISP 0x1008
84 #define DISPID_GLOBAL_TESTTHIS 0x1009
85 #define DISPID_GLOBAL_TESTTHIS2 0x100a
86 #define DISPID_GLOBAL_INVOKEVERSION 0x100b
87 #define DISPID_GLOBAL_CREATEARRAY 0x100c
88 #define DISPID_GLOBAL_PROPGETFUNC 0x100d
89 #define DISPID_GLOBAL_OBJECT_FLAG 0x100e
91 #define DISPID_TESTOBJ_PROP 0x2000
93 static const WCHAR testW[] = {'t','e','s','t',0};
94 static const CHAR testA[] = "test";
95 static const WCHAR test_valW[] = {'t','e','s','t','V','a','l',0};
96 static const CHAR test_valA[] = "testVal";
98 static BOOL strict_dispid_check;
99 static const char *test_name = "(null)";
100 static IDispatch *script_disp;
101 static int invoke_version;
102 static IActiveScriptError *script_error;
104 static BSTR a2bstr(const char *str)
109 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
110 ret = SysAllocStringLen(NULL, len-1);
111 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
116 static int strcmp_wa(LPCWSTR strw, const char *stra)
119 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
120 return lstrcmpA(buf, stra);
123 #define test_grfdex(a,b) _test_grfdex(__LINE__,a,b)
124 static void _test_grfdex(unsigned line, DWORD grfdex, DWORD expect)
126 expect |= invoke_version << 28;
127 ok_(__FILE__,line)(grfdex == expect, "grfdex = %x, expected %x\n", grfdex, expect);
130 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
134 if(IsEqualGUID(riid, &IID_IUnknown)
135 || IsEqualGUID(riid, &IID_IDispatch)
136 || IsEqualGUID(riid, &IID_IDispatchEx))
139 return E_NOINTERFACE;
144 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
149 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
154 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
156 ok(0, "unexpected call\n");
160 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
161 LCID lcid, ITypeInfo **ppTInfo)
163 ok(0, "unexpected call\n");
167 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
168 LPOLESTR *rgszNames, UINT cNames,
169 LCID lcid, DISPID *rgDispId)
171 ok(0, "unexpected call\n");
175 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
176 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
177 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
179 ok(0, "unexpected call\n");
183 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
185 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
189 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
191 ok(0, "unexpected call\n");
195 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
197 ok(0, "unexpected call\n");
201 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
203 ok(0, "unexpected call\n");
207 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
209 ok(0, "unexpected call\n");
213 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
215 ok(0, "unexpected call\n");
219 static HRESULT WINAPI testObj_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
221 if(!strcmp_wa(bstrName, "prop")) {
222 CHECK_EXPECT(testobj_prop_d);
223 test_grfdex(grfdex, fdexNameCaseSensitive);
224 *pid = DISPID_TESTOBJ_PROP;
227 if(!strcmp_wa(bstrName, "noprop")) {
228 CHECK_EXPECT(testobj_noprop_d);
229 test_grfdex(grfdex, fdexNameCaseSensitive);
230 return DISP_E_UNKNOWNNAME;
233 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
237 static HRESULT WINAPI testObj_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
238 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
242 ok(pdp != NULL, "pdp == NULL\n");
243 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
244 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
245 ok(pvarRes != NULL, "pvarRes == NULL\n");
246 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
247 ok(pei != NULL, "pei == NULL\n");
250 case INVOKE_PROPERTYGET:
251 CHECK_EXPECT(testobj_value);
252 ok(!pdp->rgvarg, "rgvarg != NULL\n");
253 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
256 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
258 case INVOKE_FUNC|INVOKE_PROPERTYGET:
259 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
262 ok(0, "invalid flag (%x)\n", wFlags);
265 V_VT(pvarRes) = VT_I4;
270 ok(0, "unexpected call %x\n", id);
271 return DISP_E_MEMBERNOTFOUND;
274 static HRESULT WINAPI testObj_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
276 CHECK_EXPECT(testobj_delete);
278 ok(!strcmp_wa(bstrName, "deleteTest"), "unexpected name %s\n", wine_dbgstr_w(bstrName));
279 test_grfdex(grfdex, fdexNameCaseSensitive);
283 static IDispatchExVtbl testObjVtbl = {
284 DispatchEx_QueryInterface,
287 DispatchEx_GetTypeInfoCount,
288 DispatchEx_GetTypeInfo,
289 DispatchEx_GetIDsOfNames,
293 testObj_DeleteMemberByName,
294 DispatchEx_DeleteMemberByDispID,
295 DispatchEx_GetMemberProperties,
296 DispatchEx_GetMemberName,
297 DispatchEx_GetNextDispID,
298 DispatchEx_GetNameSpaceParent
301 static IDispatchEx testObj = { &testObjVtbl };
303 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
305 if(!strcmp_wa(bstrName, "ok")) {
306 test_grfdex(grfdex, fdexNameCaseSensitive);
307 *pid = DISPID_GLOBAL_OK;
310 if(!strcmp_wa(bstrName, "trace")) {
311 test_grfdex(grfdex, fdexNameCaseSensitive);
312 *pid = DISPID_GLOBAL_TRACE;
315 if(!strcmp_wa(bstrName, "reportSuccess")) {
316 CHECK_EXPECT(global_success_d);
317 test_grfdex(grfdex, fdexNameCaseSensitive);
318 *pid = DISPID_GLOBAL_REPORTSUCCESS;
321 if(!strcmp_wa(bstrName, "testPropGet")) {
322 CHECK_EXPECT(global_propget_d);
323 test_grfdex(grfdex, fdexNameCaseSensitive);
324 *pid = DISPID_GLOBAL_TESTPROPGET;
327 if(!strcmp_wa(bstrName, "testPropPut")) {
328 CHECK_EXPECT(global_propput_d);
329 test_grfdex(grfdex, fdexNameCaseSensitive);
330 *pid = DISPID_GLOBAL_TESTPROPPUT;
333 if(!strcmp_wa(bstrName, "getVT")) {
334 test_grfdex(grfdex, fdexNameCaseSensitive);
335 *pid = DISPID_GLOBAL_GETVT;
338 if(!strcmp_wa(bstrName, "testObj")) {
339 test_grfdex(grfdex, fdexNameCaseSensitive);
340 *pid = DISPID_GLOBAL_TESTOBJ;
343 if(!strcmp_wa(bstrName, "createNullBSTR")) {
344 *pid = DISPID_GLOBAL_NULL_BSTR;
347 if(!strcmp_wa(bstrName, "nullDisp")) {
348 *pid = DISPID_GLOBAL_NULL_DISP;
351 if(!strcmp_wa(bstrName, "notExists")) {
352 CHECK_EXPECT(global_notexists_d);
353 test_grfdex(grfdex, fdexNameCaseSensitive);
354 return DISP_E_UNKNOWNNAME;
357 if(!strcmp_wa(bstrName, "testThis")) {
358 test_grfdex(grfdex, fdexNameCaseSensitive);
359 *pid = DISPID_GLOBAL_TESTTHIS;
363 if(!strcmp_wa(bstrName, "testThis2")) {
364 test_grfdex(grfdex, fdexNameCaseSensitive);
365 *pid = DISPID_GLOBAL_TESTTHIS2;
369 if(!strcmp_wa(bstrName, "invokeVersion")) {
370 test_grfdex(grfdex, fdexNameCaseSensitive);
371 *pid = DISPID_GLOBAL_INVOKEVERSION;
374 if(!strcmp_wa(bstrName, "createArray")) {
375 test_grfdex(grfdex, fdexNameCaseSensitive);
376 *pid = DISPID_GLOBAL_CREATEARRAY;
379 if(!strcmp_wa(bstrName, "propGetFunc")) {
380 test_grfdex(grfdex, fdexNameCaseSensitive);
381 *pid = DISPID_GLOBAL_PROPGETFUNC;
384 if(!strcmp_wa(bstrName, "objectFlag")) {
385 test_grfdex(grfdex, fdexNameCaseSensitive);
386 *pid = DISPID_GLOBAL_OBJECT_FLAG;
390 if(strict_dispid_check)
391 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
392 return DISP_E_UNKNOWNNAME;
395 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
396 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
399 case DISPID_GLOBAL_OK:
400 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
401 ok(pdp != NULL, "pdp == NULL\n");
402 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
403 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
404 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
405 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
406 if(wFlags & INVOKE_PROPERTYGET)
407 ok(pvarRes != NULL, "pvarRes == NULL\n");
409 ok(!pvarRes, "pvarRes != NULL\n");
410 ok(pei != NULL, "pei == NULL\n");
412 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
413 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
414 ok(V_BOOL(pdp->rgvarg+1), "%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
418 case DISPID_GLOBAL_TRACE:
419 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
420 ok(pdp != NULL, "pdp == NULL\n");
421 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
422 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
423 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
424 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
425 ok(!pvarRes, "pvarRes != NULL\n");
426 ok(pei != NULL, "pei == NULL\n");
428 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
429 if(V_VT(pdp->rgvarg) == VT_BSTR)
430 trace("%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
434 case DISPID_GLOBAL_REPORTSUCCESS:
435 CHECK_EXPECT(global_success_i);
437 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
438 ok(pdp != NULL, "pdp == NULL\n");
439 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
440 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
441 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
442 ok(!pvarRes, "pvarRes != NULL\n");
443 ok(pei != NULL, "pei == NULL\n");
447 case DISPID_GLOBAL_TESTPROPGET:
448 CHECK_EXPECT(global_propget_i);
450 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
451 ok(pdp != NULL, "pdp == NULL\n");
452 ok(!pdp->rgvarg, "rgvarg != NULL\n");
453 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
454 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
455 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
456 ok(pvarRes != NULL, "pvarRes == NULL\n");
457 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
458 ok(pei != NULL, "pei == NULL\n");
460 V_VT(pvarRes) = VT_I4;
465 case DISPID_GLOBAL_TESTPROPPUT:
466 CHECK_EXPECT(global_propput_i);
468 ok(wFlags == INVOKE_PROPERTYPUT, "wFlags = %x\n", wFlags);
469 ok(pdp != NULL, "pdp == NULL\n");
470 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
471 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
472 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
473 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
474 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
475 ok(!pvarRes, "pvarRes != NULL\n");
477 ok(V_VT(pdp->rgvarg) == VT_I4, "V_VT(pdp->rgvarg)=%d\n", V_VT(pdp->rgvarg));
478 ok(V_I4(pdp->rgvarg) == 1, "V_I4(pdp->rgvarg)=%d\n", V_I4(pdp->rgvarg));
481 case DISPID_GLOBAL_GETVT:
482 ok(pdp != NULL, "pdp == NULL\n");
483 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
484 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
485 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
486 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
487 ok(pvarRes != NULL, "pvarRes == NULL\n");
488 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
489 ok(pei != NULL, "pei == NULL\n");
491 V_VT(pvarRes) = VT_BSTR;
492 switch(V_VT(pdp->rgvarg)) {
494 V_BSTR(pvarRes) = a2bstr("VT_EMPTY");
497 V_BSTR(pvarRes) = a2bstr("VT_NULL");
500 V_BSTR(pvarRes) = a2bstr("VT_I4");
503 V_BSTR(pvarRes) = a2bstr("VT_R8");
506 V_BSTR(pvarRes) = a2bstr("VT_BSTR");
509 V_BSTR(pvarRes) = a2bstr("VT_DISPATCH");
512 V_BSTR(pvarRes) = a2bstr("VT_BOOL");
514 case VT_ARRAY|VT_VARIANT:
515 V_BSTR(pvarRes) = a2bstr("VT_ARRAY|VT_VARIANT");
518 ok(0, "unknown vt %d\n", V_VT(pdp->rgvarg));
524 case DISPID_GLOBAL_TESTOBJ:
525 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
526 ok(pdp != NULL, "pdp == NULL\n");
527 ok(!pdp->rgvarg, "rgvarg != NULL\n");
528 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
529 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
530 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
531 ok(pvarRes != NULL, "pvarRes == NULL\n");
532 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
533 ok(pei != NULL, "pei == NULL\n");
535 V_VT(pvarRes) = VT_DISPATCH;
536 V_DISPATCH(pvarRes) = (IDispatch*)&testObj;
539 case DISPID_GLOBAL_NULL_BSTR:
541 V_VT(pvarRes) = VT_BSTR;
542 V_BSTR(pvarRes) = NULL;
546 case DISPID_GLOBAL_NULL_DISP:
547 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
548 ok(pdp != NULL, "pdp == NULL\n");
549 ok(!pdp->rgvarg, "rgvarg != NULL\n");
550 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
551 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
552 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
553 ok(pvarRes != NULL, "pvarRes == NULL\n");
554 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
555 ok(pei != NULL, "pei == NULL\n");
557 V_VT(pvarRes) = VT_DISPATCH;
558 V_DISPATCH(pvarRes) = NULL;
561 case DISPID_GLOBAL_TESTTHIS:
562 ok(pdp != NULL, "pdp == NULL\n");
563 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
564 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
565 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
566 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
567 ok(pvarRes == NULL, "pvarRes != NULL\n");
568 ok(pei != NULL, "pei == NULL\n");
570 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(arg) = %d\n", V_VT(pdp->rgvarg));
571 ok(V_DISPATCH(pdp->rgvarg) == (IDispatch*)iface, "disp != iface\n");
575 case DISPID_GLOBAL_TESTTHIS2:
576 ok(pdp != NULL, "pdp == NULL\n");
577 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
578 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
579 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
580 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
581 ok(pvarRes == NULL, "pvarRes != NULL\n");
582 ok(pei != NULL, "pei == NULL\n");
584 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(arg) = %d\n", V_VT(pdp->rgvarg));
585 ok(V_DISPATCH(pdp->rgvarg) != (IDispatch*)iface, "disp == iface\n");
586 ok(V_DISPATCH(pdp->rgvarg) == script_disp, "disp != script_disp\n");
590 case DISPID_GLOBAL_INVOKEVERSION:
591 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
592 ok(pdp != NULL, "pdp == NULL\n");
593 ok(!pdp->rgvarg, "rgvarg != NULL\n");
594 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
595 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
596 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
597 ok(pvarRes != NULL, "pvarRes == NULL\n");
598 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
599 ok(pei != NULL, "pei == NULL\n");
601 V_VT(pvarRes) = VT_I4;
602 V_I4(pvarRes) = invoke_version;
606 case DISPID_GLOBAL_CREATEARRAY: {
607 SAFEARRAYBOUND bound[2];
611 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
612 ok(pdp != NULL, "pdp == NULL\n");
613 todo_wine ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
614 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
615 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
616 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
617 ok(pvarRes != NULL, "pvarRes == NULL\n");
618 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
619 ok(pei != NULL, "pei == NULL\n");
621 bound[0].lLbound = 0;
622 bound[0].cElements = 5;
623 bound[1].lLbound = 2;
624 bound[1].cElements = 2;
626 V_VT(pvarRes) = VT_ARRAY|VT_VARIANT;
627 V_ARRAY(pvarRes) = SafeArrayCreate(VT_VARIANT, 2, bound);
629 SafeArrayAccessData(V_ARRAY(pvarRes), (void**)&data);
637 SafeArrayUnaccessData(V_ARRAY(pvarRes));
642 case DISPID_GLOBAL_PROPGETFUNC:
645 CHECK_EXPECT(invoke_func);
647 case INVOKE_FUNC|INVOKE_PROPERTYGET:
648 ok(pdp->cArgs != 0, "pdp->cArgs = %d\n", pdp->cArgs);
649 ok(pvarRes != NULL, "pdp->pvarRes == NULL\n");
652 ok(0, "invalid flag (%x)\n", wFlags);
655 ok(pdp != NULL, "pdp == NULL\n");
656 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
657 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
658 ok(pei != NULL, "pei == NULL\n");
661 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
662 V_VT(pvarRes) = VT_I4;
663 V_I4(pvarRes) = pdp->cArgs;
668 case DISPID_GLOBAL_OBJECT_FLAG: {
673 hres = IDispatch_QueryInterface(script_disp, &IID_IDispatchEx, (void**)&dispex);
674 ok(hres == S_OK, "hres = %x\n", hres);
676 str = a2bstr("Object");
677 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
679 ok(hres == S_OK, "hres = %x\n", hres);
681 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD, pdp, NULL, pei, pspCaller);
682 ok(hres == S_OK, "hres = %x\n", hres);
684 V_VT(pvarRes) = VT_EMPTY;
685 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD, pdp, pvarRes, pei, pspCaller);
686 ok(hres == S_OK, "hres = %x\n", hres);
687 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
688 VariantClear(pvarRes);
690 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD|DISPATCH_PROPERTYGET, pdp, NULL, pei, pspCaller);
691 ok(hres == S_OK, "hres = %x\n", hres);
693 V_VT(pvarRes) = VT_EMPTY;
694 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT, pdp, pvarRes, pei, pspCaller);
695 ok(hres == S_OK, "hres = %x\n", hres);
696 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
697 VariantClear(pvarRes);
699 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT, pdp, NULL, pei, pspCaller);
700 ok(hres == S_OK, "hres = %x\n", hres);
702 V_VT(pvarRes) = VT_EMPTY;
703 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT|DISPATCH_PROPERTYGET, pdp, pvarRes, pei, pspCaller);
704 ok(hres == E_INVALIDARG, "hres = %x\n", hres);
706 V_VT(pvarRes) = VT_EMPTY;
707 hres = IDispatchEx_InvokeEx(dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
708 ok(hres == S_OK, "hres = %x\n", hres);
709 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
710 IDispatchEx_Release(dispex);
715 ok(0, "unexpected call %x\n", id);
716 return DISP_E_MEMBERNOTFOUND;
719 static IDispatchExVtbl GlobalVtbl = {
720 DispatchEx_QueryInterface,
723 DispatchEx_GetTypeInfoCount,
724 DispatchEx_GetTypeInfo,
725 DispatchEx_GetIDsOfNames,
729 DispatchEx_DeleteMemberByName,
730 DispatchEx_DeleteMemberByDispID,
731 DispatchEx_GetMemberProperties,
732 DispatchEx_GetMemberName,
733 DispatchEx_GetNextDispID,
734 DispatchEx_GetNameSpaceParent
737 static IDispatchEx Global = { &GlobalVtbl };
739 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
743 if(IsEqualGUID(&IID_IUnknown, riid))
745 else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
748 return E_NOINTERFACE;
750 IUnknown_AddRef((IUnknown*)*ppv);
754 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
759 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
764 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
766 *plcid = GetUserDefaultLCID();
770 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
771 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
773 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
774 ok(!ppti, "ppti != NULL\n");
776 if(!strcmp_wa(pstrName, test_valA))
777 CHECK_EXPECT(GetItemInfo_testVal);
778 else if(strcmp_wa(pstrName, testA))
779 ok(0, "unexpected pstrName %s\n", wine_dbgstr_w(pstrName));
781 *ppiunkItem = (IUnknown*)&Global;
785 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
790 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
791 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
796 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
801 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
806 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
811 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
816 #undef ACTSCPSITE_THIS
818 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
819 ActiveScriptSite_QueryInterface,
820 ActiveScriptSite_AddRef,
821 ActiveScriptSite_Release,
822 ActiveScriptSite_GetLCID,
823 ActiveScriptSite_GetItemInfo,
824 ActiveScriptSite_GetDocVersionString,
825 ActiveScriptSite_OnScriptTerminate,
826 ActiveScriptSite_OnStateChange,
827 ActiveScriptSite_OnScriptError,
828 ActiveScriptSite_OnEnterScript,
829 ActiveScriptSite_OnLeaveScript
832 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
834 static HRESULT WINAPI ActiveScriptSite_OnScriptError_CheckError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
836 ok(pscripterror != NULL, "ActiveScriptSite_OnScriptError -- expected pscripterror to be set, got NULL\n");
838 script_error = pscripterror;
839 IUnknown_AddRef(script_error);
841 CHECK_EXPECT(ActiveScriptSite_OnScriptError);
846 static const IActiveScriptSiteVtbl ActiveScriptSite_CheckErrorVtbl = {
847 ActiveScriptSite_QueryInterface,
848 ActiveScriptSite_AddRef,
849 ActiveScriptSite_Release,
850 ActiveScriptSite_GetLCID,
851 ActiveScriptSite_GetItemInfo,
852 ActiveScriptSite_GetDocVersionString,
853 ActiveScriptSite_OnScriptTerminate,
854 ActiveScriptSite_OnStateChange,
855 ActiveScriptSite_OnScriptError_CheckError,
856 ActiveScriptSite_OnEnterScript,
857 ActiveScriptSite_OnLeaveScript
860 static IActiveScriptSite ActiveScriptSite_CheckError = { &ActiveScriptSite_CheckErrorVtbl };
862 static HRESULT set_script_prop(IActiveScript *engine, DWORD property, VARIANT *val)
864 IActiveScriptProperty *script_prop;
867 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptProperty,
868 (void**)&script_prop);
869 ok(hres == S_OK, "Could not get IActiveScriptProperty iface: %08x\n", hres);
871 hres = IActiveScriptProperty_SetProperty(script_prop, property, NULL, val);
872 IActiveScriptProperty_Release(script_prop);
877 static IActiveScript *create_script(void)
879 IActiveScript *script;
883 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
884 &IID_IActiveScript, (void**)&script);
885 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
888 V_I4(&v) = invoke_version;
889 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
890 ok(hres == S_OK || broken(hres == E_NOTIMPL), "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
891 if(invoke_version && FAILED(hres)) {
892 IActiveScript_Release(script);
899 static HRESULT parse_script(DWORD flags, BSTR script_str)
901 IActiveScriptParse *parser;
902 IActiveScript *engine;
905 engine = create_script();
909 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
910 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
913 IActiveScript_Release(engine);
917 hres = IActiveScriptParse64_InitNew(parser);
918 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
920 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
921 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
923 hres = IActiveScript_AddNamedItem(engine, testW,
924 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags);
925 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
927 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
928 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
930 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp);
931 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
932 ok(script_disp != NULL, "script_disp == NULL\n");
933 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n");
935 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
937 IDispatch_Release(script_disp);
938 IActiveScript_Release(engine);
939 IUnknown_Release(parser);
944 static HRESULT parse_htmlscript(BSTR script_str)
946 IActiveScriptParse *parser;
947 IActiveScript *engine;
949 BSTR tmp = a2bstr("</SCRIPT>");
951 engine = create_script();
955 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
956 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
959 IActiveScript_Release(engine);
963 hres = IActiveScriptParse64_InitNew(parser);
964 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
966 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
967 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
969 hres = IActiveScript_AddNamedItem(engine, testW,
970 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
971 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
973 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
974 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
976 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, tmp, 0, 0, 0, NULL, NULL);
978 IActiveScript_Release(engine);
979 IUnknown_Release(parser);
985 static void test_IActiveScriptError(IActiveScriptError *error, SCODE errorcode, ULONG line, LONG pos, BSTR script_source, BSTR description, BSTR line_text)
988 DWORD source_context;
994 /* IActiveScriptError_GetSourcePosition */
996 hres = IActiveScriptError_GetSourcePosition(error, NULL, NULL, NULL);
997 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
999 source_context = 0xdeadbeef;
1000 hres = IActiveScriptError_GetSourcePosition(error, &source_context, NULL, NULL);
1001 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1002 ok(source_context == 0, "IActiveScriptError_GetSourcePosition -- source_context: expected 0, got 0x%08x\n", source_context);
1004 line_number = 0xdeadbeef;
1005 hres = IActiveScriptError_GetSourcePosition(error, NULL, &line_number, NULL);
1006 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1007 ok(line_number == line, "IActiveScriptError_GetSourcePosition -- line_number: expected %d, got %d\n", line, line_number);
1009 char_position = 0xdeadbeef;
1010 hres = IActiveScriptError_GetSourcePosition(error, NULL, NULL, &char_position);
1011 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1012 ok(char_position == pos, "IActiveScriptError_GetSourcePosition -- char_position: expected %d, got %d\n", pos, char_position);
1014 /* IActiveScriptError_GetSourceLineText */
1016 hres = IActiveScriptError_GetSourceLineText(error, NULL);
1017 ok(hres == E_POINTER, "IActiveScriptError_GetSourceLineText -- hres: expected E_POINTER, got 0x%08x\n", hres);
1020 hres = IActiveScriptError_GetSourceLineText(error, &linetext);
1022 ok(hres == S_OK, "IActiveScriptError_GetSourceLineText -- hres: expected S_OK, got 0x%08x\n", hres);
1023 ok(linetext != NULL && !lstrcmpW(linetext, line_text),
1024 "IActiveScriptError_GetSourceLineText -- expected %s, got %s\n", wine_dbgstr_w(line_text), wine_dbgstr_w(linetext));
1026 ok(hres == E_FAIL, "IActiveScriptError_GetSourceLineText -- hres: expected S_OK, got 0x%08x\n", hres);
1027 ok(linetext == NULL,
1028 "IActiveScriptError_GetSourceLineText -- expected NULL, got %s\n", wine_dbgstr_w(linetext));
1030 SysFreeString(linetext);
1032 /* IActiveScriptError_GetExceptionInfo */
1034 hres = IActiveScriptError_GetExceptionInfo(error, NULL);
1035 ok(hres == E_POINTER, "IActiveScriptError_GetExceptionInfo -- hres: expected E_POINTER, got 0x%08x\n", hres);
1037 excep.wCode = 0xdead;
1038 excep.wReserved = 0xdead;
1039 excep.bstrSource = (BSTR)0xdeadbeef;
1040 excep.bstrDescription = (BSTR)0xdeadbeef;
1041 excep.bstrHelpFile = (BSTR)0xdeadbeef;
1042 excep.dwHelpContext = 0xdeadbeef;
1043 excep.pvReserved = (void *)0xdeadbeef;
1044 excep.pfnDeferredFillIn = (void *)0xdeadbeef;
1045 excep.scode = 0xdeadbeef;
1047 hres = IActiveScriptError_GetExceptionInfo(error, &excep);
1048 ok(hres == S_OK, "IActiveScriptError_GetExceptionInfo -- hres: expected S_OK, got 0x%08x\n", hres);
1050 ok(excep.wCode == 0, "IActiveScriptError_GetExceptionInfo -- excep.wCode: expected 0, got 0x%08x\n", excep.wCode);
1051 ok(excep.wReserved == 0, "IActiveScriptError_GetExceptionInfo -- excep.wReserved: expected 0, got %d\n", excep.wReserved);
1052 if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH)
1053 skip("Non-english locale (test with hardcoded strings)\n");
1055 ok(excep.bstrSource != NULL && !lstrcmpW(excep.bstrSource, script_source),
1056 "IActiveScriptError_GetExceptionInfo -- excep.bstrSource is not valid: expected %s, got %s\n",
1057 wine_dbgstr_w(script_source), wine_dbgstr_w(excep.bstrSource));
1058 ok(excep.bstrDescription != NULL && !lstrcmpW(excep.bstrDescription, description),
1059 "IActiveScriptError_GetExceptionInfo -- excep.bstrDescription is not valid: got %s\n", wine_dbgstr_w(excep.bstrDescription));
1061 ok(excep.bstrHelpFile == NULL,
1062 "IActiveScriptError_GetExceptionInfo -- excep.bstrHelpFile: expected NULL, got %s\n", wine_dbgstr_w(excep.bstrHelpFile));
1063 ok(excep.dwHelpContext == 0, "IActiveScriptError_GetExceptionInfo -- excep.dwHelpContext: expected 0, got %d\n", excep.dwHelpContext);
1064 ok(excep.pvReserved == NULL, "IActiveScriptError_GetExceptionInfo -- excep.pvReserved: expected NULL, got %p\n", excep.pvReserved);
1065 ok(excep.pfnDeferredFillIn == NULL, "IActiveScriptError_GetExceptionInfo -- excep.pfnDeferredFillIn: expected NULL, got %p\n", excep.pfnDeferredFillIn);
1066 ok(excep.scode == errorcode, "IActiveScriptError_GetExceptionInfo -- excep.scode: expected 0x%08x, got 0x%08x\n", errorcode, excep.scode);
1068 SysFreeString(excep.bstrSource);
1069 SysFreeString(excep.bstrDescription);
1070 SysFreeString(excep.bstrHelpFile);
1073 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)
1075 IActiveScriptParse *parser;
1076 IActiveScript *engine;
1079 engine = create_script();
1083 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1084 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1087 IActiveScript_Release(engine);
1091 hres = IActiveScriptParse64_InitNew(parser);
1092 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1094 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite_CheckError);
1095 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1097 hres = IActiveScript_AddNamedItem(engine, testW,
1098 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags);
1099 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1101 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1102 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1104 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp);
1105 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
1106 ok(script_disp != NULL, "script_disp == NULL\n");
1107 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n");
1109 script_error = NULL;
1110 SET_EXPECT(ActiveScriptSite_OnScriptError);
1111 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1112 todo_wine ok(hres == 0x80020101, "parse_script_with_error should have returned 0x80020101, got: 0x%08x\n", hres);
1113 todo_wine CHECK_CALLED(ActiveScriptSite_OnScriptError);
1117 test_IActiveScriptError(script_error, errorcode, line, pos, script_source, description, line_text);
1119 IUnknown_Release(script_error);
1122 IDispatch_Release(script_disp);
1123 IActiveScript_Release(engine);
1124 IUnknown_Release(parser);
1127 static void parse_script_af(DWORD flags, const char *src)
1133 hres = parse_script(flags, tmp);
1135 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1138 static void parse_script_a(const char *src)
1140 parse_script_af(SCRIPTITEM_GLOBALMEMBERS, src);
1143 static void parse_script_with_error_a(const char *src, SCODE errorcode, ULONG line, LONG pos, LPCSTR source, LPCSTR desc, LPCSTR linetext)
1145 BSTR tmp, script_source, description, line_text;
1148 script_source = a2bstr(source);
1149 description = a2bstr(desc);
1150 line_text = a2bstr(linetext);
1152 parse_script_with_error(SCRIPTITEM_GLOBALMEMBERS, tmp, errorcode, line, pos, script_source, description, line_text);
1154 SysFreeString(line_text);
1155 SysFreeString(description);
1156 SysFreeString(script_source);
1160 static HRESULT parse_htmlscript_a(const char *src)
1163 BSTR tmp = a2bstr(src);
1164 hres = parse_htmlscript(tmp);
1170 static BSTR get_script_from_file(const char *filename)
1174 const char *file_map;
1177 file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
1178 if(file == INVALID_HANDLE_VALUE) {
1179 trace("Could not open file: %u\n", GetLastError());
1183 size = GetFileSize(file, NULL);
1185 map = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
1187 if(map == INVALID_HANDLE_VALUE) {
1188 trace("Could not create file mapping: %u\n", GetLastError());
1192 file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
1195 trace("MapViewOfFile failed: %u\n", GetLastError());
1199 len = MultiByteToWideChar(CP_ACP, 0, file_map, size, NULL, 0);
1200 ret = SysAllocStringLen(NULL, len);
1201 MultiByteToWideChar(CP_ACP, 0, file_map, size, ret, len);
1203 UnmapViewOfFile(file_map);
1208 static void run_from_file(const char *filename)
1213 script_str = get_script_from_file(filename);
1217 strict_dispid_check = FALSE;
1218 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, script_str);
1219 SysFreeString(script_str);
1220 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1223 static void run_from_res(const char *name)
1231 strict_dispid_check = FALSE;
1234 src = FindResourceA(NULL, name, (LPCSTR)40);
1235 ok(src != NULL, "Could not find resource %s\n", name);
1237 size = SizeofResource(NULL, src);
1238 data = LoadResource(NULL, src);
1240 len = MultiByteToWideChar(CP_ACP, 0, data, size, NULL, 0);
1241 str = SysAllocStringLen(NULL, len);
1242 len = MultiByteToWideChar(CP_ACP, 0, data, size, str, len);
1244 SET_EXPECT(global_success_d);
1245 SET_EXPECT(global_success_i);
1246 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, str);
1247 CHECK_CALLED(global_success_d);
1248 CHECK_CALLED(global_success_i);
1250 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1254 static void test_isvisible(BOOL global_members)
1256 IActiveScriptParse *parser;
1257 IActiveScript *engine;
1260 static const WCHAR script_textW[] =
1261 {'v','a','r',' ','v',' ','=',' ','t','e','s','t','V','a','l',';',0};
1263 engine = create_script();
1267 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1268 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1271 IActiveScript_Release(engine);
1275 hres = IActiveScriptParse64_InitNew(parser);
1276 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1278 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1279 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1282 SET_EXPECT(GetItemInfo_testVal);
1283 hres = IActiveScript_AddNamedItem(engine, test_valW,
1284 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|
1285 (global_members ? SCRIPTITEM_GLOBALMEMBERS : 0));
1286 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1288 CHECK_CALLED(GetItemInfo_testVal);
1290 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1291 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1294 SET_EXPECT(GetItemInfo_testVal);
1295 hres = IActiveScriptParse64_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1296 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1298 CHECK_CALLED(GetItemInfo_testVal);
1300 hres = IActiveScriptParse64_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1301 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1303 IActiveScript_Release(engine);
1304 IUnknown_Release(parser);
1307 static void run_tests(void)
1311 if(invoke_version) {
1312 IActiveScript *script;
1314 script = create_script();
1316 win_skip("Could not create script\n");
1319 IActiveScript_Release(script);
1322 strict_dispid_check = TRUE;
1325 parse_script_a("/* empty */ ;");
1327 SET_EXPECT(global_propget_d);
1328 SET_EXPECT(global_propget_i);
1329 parse_script_a("testPropGet;");
1330 CHECK_CALLED(global_propget_d);
1331 CHECK_CALLED(global_propget_i);
1333 SET_EXPECT(global_propput_d);
1334 SET_EXPECT(global_propput_i);
1335 parse_script_a("testPropPut = 1;");
1336 CHECK_CALLED(global_propput_d);
1337 CHECK_CALLED(global_propput_i);
1339 SET_EXPECT(global_success_d);
1340 SET_EXPECT(global_success_i);
1341 parse_script_a("reportSuccess();");
1342 CHECK_CALLED(global_success_d);
1343 CHECK_CALLED(global_success_i);
1345 SET_EXPECT(testobj_delete);
1346 parse_script_a("delete testObj.deleteTest;");
1347 CHECK_CALLED(testobj_delete);
1349 parse_script_a("ok(typeof(test) === 'object', \"typeof(test) != 'object'\");");
1351 parse_script_a("function reportSuccess() {}; reportSuccess();");
1353 SET_EXPECT(global_propget_d);
1354 parse_script_a("var testPropGet");
1355 CHECK_CALLED(global_propget_d);
1357 SET_EXPECT(global_propget_d);
1358 parse_script_a("eval('var testPropGet;');");
1359 CHECK_CALLED(global_propget_d);
1361 SET_EXPECT(global_notexists_d);
1362 parse_script_a("var notExists; notExists = 1;");
1363 CHECK_CALLED(global_notexists_d);
1365 parse_script_a("function f() { var testPropGet; }");
1366 parse_script_a("(function () { var testPropGet; })();");
1367 parse_script_a("(function () { eval('var testPropGet;'); })();");
1369 SET_EXPECT(invoke_func);
1370 parse_script_a("ok(propGetFunc() == 0, \"Incorrect propGetFunc value\");");
1371 CHECK_CALLED(invoke_func);
1372 parse_script_a("ok(propGetFunc(1) == 1, \"Incorrect propGetFunc value\");");
1373 parse_script_a("ok(propGetFunc(1, 2) == 2, \"Incorrect propGetFunc value\");");
1374 SET_EXPECT(invoke_func);
1375 parse_script_a("ok(propGetFunc().toString() == 0, \"Incorrect propGetFunc value\");");
1376 CHECK_CALLED(invoke_func);
1377 parse_script_a("ok(propGetFunc(1).toString() == 1, \"Incorrect propGetFunc value\");");
1378 SET_EXPECT(invoke_func);
1379 parse_script_a("propGetFunc(1);");
1380 CHECK_CALLED(invoke_func);
1382 parse_script_a("objectFlag(1).toString();");
1384 parse_script_a("(function() { var tmp = (function () { return testObj; })()(1);})();");
1385 parse_script_a("(function() { var tmp = (function () { return testObj; })()();})();");
1387 parse_script_a("ok((testObj instanceof Object) === false, 'testObj is instance of Object');");
1389 SET_EXPECT(testobj_prop_d);
1390 parse_script_a("ok(('prop' in testObj) === true, 'prop is not in testObj');");
1391 CHECK_CALLED(testobj_prop_d);
1393 SET_EXPECT(testobj_noprop_d);
1394 parse_script_a("ok(('noprop' in testObj) === false, 'noprop is in testObj');");
1395 CHECK_CALLED(testobj_noprop_d);
1397 SET_EXPECT(testobj_value);
1398 parse_script_a("ok(String(testObj) === '1', 'wrong testObj value');");
1399 CHECK_CALLED(testobj_value);
1401 SET_EXPECT(testobj_value);
1402 parse_script_a("ok(String.prototype.concat.call(testObj, ' OK') === '1 OK', 'wrong concat result');");
1403 CHECK_CALLED(testobj_value);
1405 SET_EXPECT(global_propget_d);
1406 SET_EXPECT(global_propget_i);
1407 parse_script_a("this.testPropGet;");
1408 CHECK_CALLED(global_propget_d);
1409 CHECK_CALLED(global_propget_i);
1411 SET_EXPECT(global_propget_d);
1412 SET_EXPECT(global_propget_i);
1413 parse_script_a("(function () { this.testPropGet; })();");
1414 CHECK_CALLED(global_propget_d);
1415 CHECK_CALLED(global_propget_i);
1417 parse_script_a("testThis(this);");
1418 parse_script_a("(function () { testThis(this); })();");
1420 run_from_res("lang.js");
1421 run_from_res("api.js");
1422 run_from_res("regexp.js");
1424 test_isvisible(FALSE);
1425 test_isvisible(TRUE);
1427 parse_script_af(0, "test.testThis2(this);");
1428 parse_script_af(0, "(function () { test.testThis2(this); })();");
1430 hres = parse_htmlscript_a("<!--");
1431 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1432 hres = parse_htmlscript_a("-->");
1433 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1434 hres = parse_htmlscript_a("<!--\nvar a=1;\n-->\n");
1435 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1436 hres = parse_htmlscript_a("<!--\n<!-- ignore this\n-->\n");
1437 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1438 hres = parse_htmlscript_a("var a=1;\nif(a-->0) a=5;\n");
1439 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1440 hres = parse_htmlscript_a("var a=1;\nif(a\n-->0) a=5;\n");
1441 ok(hres != S_OK, "ParseScriptText have not failed\n");
1443 parse_script_with_error_a(
1446 "Microsoft JScript compilation error",
1450 parse_script_with_error_a(
1451 "var a=1;\nif(a\n-->0) a=5;\n",
1453 "Microsoft JScript compilation error",
1457 parse_script_with_error_a(
1460 "Microsoft JScript runtime error",
1461 "Object doesn't support this action",
1464 parse_script_with_error_a(
1467 "Microsoft JScript runtime error",
1471 parse_script_with_error_a(
1472 "var a;\nnew null;",
1474 "Microsoft JScript runtime error",
1478 parse_script_with_error_a(
1481 "Microsoft JScript runtime error",
1486 static BOOL check_jscript(void)
1488 IActiveScriptProperty *script_prop;
1492 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1493 &IID_IActiveScriptProperty, (void**)&script_prop);
1496 IActiveScriptProperty_Release(script_prop);
1498 str = a2bstr("if(!('localeCompare' in String.prototype)) throw 1;");
1499 hres = parse_script(0, str);
1502 return hres == S_OK;
1510 argc = winetest_get_mainargs(&argv);
1514 if(!check_jscript()) {
1515 win_skip("Broken engine, probably too old\n");
1516 }else if(argc > 2) {
1517 run_from_file(argv[2]);
1519 trace("invoke version 0\n");
1523 trace("invoke version 2\n");