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);
74 #define DISPID_GLOBAL_TESTPROPGET 0x1000
75 #define DISPID_GLOBAL_TESTPROPPUT 0x1001
76 #define DISPID_GLOBAL_REPORTSUCCESS 0x1002
77 #define DISPID_GLOBAL_TRACE 0x1003
78 #define DISPID_GLOBAL_OK 0x1004
79 #define DISPID_GLOBAL_GETVT 0x1005
80 #define DISPID_GLOBAL_TESTOBJ 0x1006
81 #define DISPID_GLOBAL_NULL_BSTR 0x1007
82 #define DISPID_GLOBAL_NULL_DISP 0x1008
83 #define DISPID_GLOBAL_TESTTHIS 0x1009
84 #define DISPID_GLOBAL_TESTTHIS2 0x100a
85 #define DISPID_GLOBAL_INVOKEVERSION 0x100b
86 #define DISPID_TEST_CREATEARRAY 0x100c
88 #define DISPID_TESTOBJ_PROP 0x2000
90 static const WCHAR testW[] = {'t','e','s','t',0};
91 static const CHAR testA[] = "test";
92 static const WCHAR test_valW[] = {'t','e','s','t','V','a','l',0};
93 static const CHAR test_valA[] = "testVal";
95 static BOOL strict_dispid_check;
96 static const char *test_name = "(null)";
97 static IDispatch *script_disp;
98 static int invoke_version;
99 static IActiveScriptError *script_error;
101 static BSTR a2bstr(const char *str)
106 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
107 ret = SysAllocStringLen(NULL, len-1);
108 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
113 static int strcmp_wa(LPCWSTR strw, const char *stra)
116 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
117 return lstrcmpA(buf, stra);
120 #define test_grfdex(a,b) _test_grfdex(__LINE__,a,b)
121 static void _test_grfdex(unsigned line, DWORD grfdex, DWORD expect)
123 expect |= invoke_version << 28;
124 ok_(__FILE__,line)(grfdex == expect, "grfdex = %x, expected %x\n", grfdex, expect);
127 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
131 if(IsEqualGUID(riid, &IID_IUnknown)
132 || IsEqualGUID(riid, &IID_IDispatch)
133 || IsEqualGUID(riid, &IID_IDispatchEx))
136 return E_NOINTERFACE;
141 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
146 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
151 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
153 ok(0, "unexpected call\n");
157 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
158 LCID lcid, ITypeInfo **ppTInfo)
160 ok(0, "unexpected call\n");
164 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
165 LPOLESTR *rgszNames, UINT cNames,
166 LCID lcid, DISPID *rgDispId)
168 ok(0, "unexpected call\n");
172 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
173 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
174 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
176 ok(0, "unexpected call\n");
180 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
182 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
186 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
188 ok(0, "unexpected call\n");
192 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
194 ok(0, "unexpected call\n");
198 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
200 ok(0, "unexpected call\n");
204 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
206 ok(0, "unexpected call\n");
210 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
212 ok(0, "unexpected call\n");
216 static HRESULT WINAPI testObj_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
218 if(!strcmp_wa(bstrName, "prop")) {
219 CHECK_EXPECT(testobj_prop_d);
220 test_grfdex(grfdex, fdexNameCaseSensitive);
221 *pid = DISPID_TESTOBJ_PROP;
224 if(!strcmp_wa(bstrName, "noprop")) {
225 CHECK_EXPECT(testobj_noprop_d);
226 test_grfdex(grfdex, fdexNameCaseSensitive);
227 return DISP_E_UNKNOWNNAME;
230 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
234 static HRESULT WINAPI testObj_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
235 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
239 CHECK_EXPECT(testobj_value);
241 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
242 ok(pdp != NULL, "pdp == NULL\n");
243 ok(!pdp->rgvarg, "rgvarg != NULL\n");
244 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
245 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
246 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
247 ok(pvarRes != NULL, "pvarRes == NULL\n");
248 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
249 ok(pei != NULL, "pei == NULL\n");
251 V_VT(pvarRes) = VT_I4;
256 ok(0, "unexpected call %x\n", id);
257 return DISP_E_MEMBERNOTFOUND;
260 static HRESULT WINAPI testObj_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
262 CHECK_EXPECT(testobj_delete);
264 ok(!strcmp_wa(bstrName, "deleteTest"), "unexpected name %s\n", wine_dbgstr_w(bstrName));
265 test_grfdex(grfdex, fdexNameCaseSensitive);
269 static IDispatchExVtbl testObjVtbl = {
270 DispatchEx_QueryInterface,
273 DispatchEx_GetTypeInfoCount,
274 DispatchEx_GetTypeInfo,
275 DispatchEx_GetIDsOfNames,
279 testObj_DeleteMemberByName,
280 DispatchEx_DeleteMemberByDispID,
281 DispatchEx_GetMemberProperties,
282 DispatchEx_GetMemberName,
283 DispatchEx_GetNextDispID,
284 DispatchEx_GetNameSpaceParent
287 static IDispatchEx testObj = { &testObjVtbl };
289 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
291 if(!strcmp_wa(bstrName, "ok")) {
292 test_grfdex(grfdex, fdexNameCaseSensitive);
293 *pid = DISPID_GLOBAL_OK;
296 if(!strcmp_wa(bstrName, "trace")) {
297 test_grfdex(grfdex, fdexNameCaseSensitive);
298 *pid = DISPID_GLOBAL_TRACE;
301 if(!strcmp_wa(bstrName, "reportSuccess")) {
302 CHECK_EXPECT(global_success_d);
303 test_grfdex(grfdex, fdexNameCaseSensitive);
304 *pid = DISPID_GLOBAL_REPORTSUCCESS;
307 if(!strcmp_wa(bstrName, "testPropGet")) {
308 CHECK_EXPECT(global_propget_d);
309 test_grfdex(grfdex, fdexNameCaseSensitive);
310 *pid = DISPID_GLOBAL_TESTPROPGET;
313 if(!strcmp_wa(bstrName, "testPropPut")) {
314 CHECK_EXPECT(global_propput_d);
315 test_grfdex(grfdex, fdexNameCaseSensitive);
316 *pid = DISPID_GLOBAL_TESTPROPPUT;
319 if(!strcmp_wa(bstrName, "getVT")) {
320 test_grfdex(grfdex, fdexNameCaseSensitive);
321 *pid = DISPID_GLOBAL_GETVT;
324 if(!strcmp_wa(bstrName, "testObj")) {
325 test_grfdex(grfdex, fdexNameCaseSensitive);
326 *pid = DISPID_GLOBAL_TESTOBJ;
329 if(!strcmp_wa(bstrName, "createNullBSTR")) {
330 *pid = DISPID_GLOBAL_NULL_BSTR;
333 if(!strcmp_wa(bstrName, "nullDisp")) {
334 *pid = DISPID_GLOBAL_NULL_DISP;
337 if(!strcmp_wa(bstrName, "notExists")) {
338 CHECK_EXPECT(global_notexists_d);
339 test_grfdex(grfdex, fdexNameCaseSensitive);
340 return DISP_E_UNKNOWNNAME;
343 if(!strcmp_wa(bstrName, "testThis")) {
344 test_grfdex(grfdex, fdexNameCaseSensitive);
345 *pid = DISPID_GLOBAL_TESTTHIS;
349 if(!strcmp_wa(bstrName, "testThis2")) {
350 test_grfdex(grfdex, fdexNameCaseSensitive);
351 *pid = DISPID_GLOBAL_TESTTHIS2;
355 if(!strcmp_wa(bstrName, "invokeVersion")) {
356 test_grfdex(grfdex, fdexNameCaseSensitive);
357 *pid = DISPID_GLOBAL_INVOKEVERSION;
360 if(!strcmp_wa(bstrName, "createArray")) {
361 test_grfdex(grfdex, fdexNameCaseSensitive);
362 *pid = DISPID_TEST_CREATEARRAY;
366 if(strict_dispid_check)
367 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
368 return DISP_E_UNKNOWNNAME;
371 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
372 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
375 case DISPID_GLOBAL_OK:
376 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
377 ok(pdp != NULL, "pdp == NULL\n");
378 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
379 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
380 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
381 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
382 if(wFlags & INVOKE_PROPERTYGET)
383 ok(pvarRes != NULL, "pvarRes == NULL\n");
385 ok(!pvarRes, "pvarRes != NULL\n");
386 ok(pei != NULL, "pei == NULL\n");
388 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
389 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
390 ok(V_BOOL(pdp->rgvarg+1), "%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
394 case DISPID_GLOBAL_TRACE:
395 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
396 ok(pdp != NULL, "pdp == NULL\n");
397 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
398 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
399 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
400 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
401 ok(!pvarRes, "pvarRes != NULL\n");
402 ok(pei != NULL, "pei == NULL\n");
404 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
405 if(V_VT(pdp->rgvarg) == VT_BSTR)
406 trace("%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
410 case DISPID_GLOBAL_REPORTSUCCESS:
411 CHECK_EXPECT(global_success_i);
413 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
414 ok(pdp != NULL, "pdp == NULL\n");
415 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
416 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
417 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
418 ok(!pvarRes, "pvarRes != NULL\n");
419 ok(pei != NULL, "pei == NULL\n");
423 case DISPID_GLOBAL_TESTPROPGET:
424 CHECK_EXPECT(global_propget_i);
426 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
427 ok(pdp != NULL, "pdp == NULL\n");
428 ok(!pdp->rgvarg, "rgvarg != NULL\n");
429 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
430 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
431 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
432 ok(pvarRes != NULL, "pvarRes == NULL\n");
433 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
434 ok(pei != NULL, "pei == NULL\n");
436 V_VT(pvarRes) = VT_I4;
441 case DISPID_GLOBAL_TESTPROPPUT:
442 CHECK_EXPECT(global_propput_i);
444 ok(wFlags == INVOKE_PROPERTYPUT, "wFlags = %x\n", wFlags);
445 ok(pdp != NULL, "pdp == NULL\n");
446 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
447 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
448 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
449 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
450 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
451 ok(!pvarRes, "pvarRes != NULL\n");
453 ok(V_VT(pdp->rgvarg) == VT_I4, "V_VT(pdp->rgvarg)=%d\n", V_VT(pdp->rgvarg));
454 ok(V_I4(pdp->rgvarg) == 1, "V_I4(pdp->rgvarg)=%d\n", V_I4(pdp->rgvarg));
457 case DISPID_GLOBAL_GETVT:
458 ok(pdp != NULL, "pdp == NULL\n");
459 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
460 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
461 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
462 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
463 ok(pvarRes != NULL, "pvarRes == NULL\n");
464 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
465 ok(pei != NULL, "pei == NULL\n");
467 V_VT(pvarRes) = VT_BSTR;
468 switch(V_VT(pdp->rgvarg)) {
470 V_BSTR(pvarRes) = a2bstr("VT_EMPTY");
473 V_BSTR(pvarRes) = a2bstr("VT_NULL");
476 V_BSTR(pvarRes) = a2bstr("VT_I4");
479 V_BSTR(pvarRes) = a2bstr("VT_R8");
482 V_BSTR(pvarRes) = a2bstr("VT_BSTR");
485 V_BSTR(pvarRes) = a2bstr("VT_DISPATCH");
488 V_BSTR(pvarRes) = a2bstr("VT_BOOL");
491 ok(0, "unknown vt %d\n", V_VT(pdp->rgvarg));
497 case DISPID_GLOBAL_TESTOBJ:
498 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
499 ok(pdp != NULL, "pdp == NULL\n");
500 ok(!pdp->rgvarg, "rgvarg != NULL\n");
501 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
502 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
503 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
504 ok(pvarRes != NULL, "pvarRes == NULL\n");
505 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
506 ok(pei != NULL, "pei == NULL\n");
508 V_VT(pvarRes) = VT_DISPATCH;
509 V_DISPATCH(pvarRes) = (IDispatch*)&testObj;
512 case DISPID_GLOBAL_NULL_BSTR:
514 V_VT(pvarRes) = VT_BSTR;
515 V_BSTR(pvarRes) = NULL;
519 case DISPID_GLOBAL_NULL_DISP:
520 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
521 ok(pdp != NULL, "pdp == NULL\n");
522 ok(!pdp->rgvarg, "rgvarg != NULL\n");
523 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
524 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
525 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
526 ok(pvarRes != NULL, "pvarRes == NULL\n");
527 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
528 ok(pei != NULL, "pei == NULL\n");
530 V_VT(pvarRes) = VT_DISPATCH;
531 V_DISPATCH(pvarRes) = NULL;
534 case DISPID_GLOBAL_TESTTHIS:
535 ok(pdp != NULL, "pdp == NULL\n");
536 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
537 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
538 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
539 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
540 ok(pvarRes == NULL, "pvarRes != NULL\n");
541 ok(pei != NULL, "pei == NULL\n");
543 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(arg) = %d\n", V_VT(pdp->rgvarg));
544 ok(V_DISPATCH(pdp->rgvarg) == (IDispatch*)iface, "disp != iface\n");
548 case DISPID_GLOBAL_TESTTHIS2:
549 ok(pdp != NULL, "pdp == NULL\n");
550 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
551 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
552 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
553 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
554 ok(pvarRes == NULL, "pvarRes != NULL\n");
555 ok(pei != NULL, "pei == NULL\n");
557 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(arg) = %d\n", V_VT(pdp->rgvarg));
558 ok(V_DISPATCH(pdp->rgvarg) != (IDispatch*)iface, "disp == iface\n");
559 ok(V_DISPATCH(pdp->rgvarg) == script_disp, "disp != script_disp\n");
563 case DISPID_GLOBAL_INVOKEVERSION:
564 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
565 ok(pdp != NULL, "pdp == NULL\n");
566 ok(!pdp->rgvarg, "rgvarg != NULL\n");
567 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
568 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
569 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
570 ok(pvarRes != NULL, "pvarRes == NULL\n");
571 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
572 ok(pei != NULL, "pei == NULL\n");
574 V_VT(pvarRes) = VT_I4;
575 V_I4(pvarRes) = invoke_version;
579 case DISPID_TEST_CREATEARRAY: {
580 SAFEARRAYBOUND bound[2];
584 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
585 ok(pdp != NULL, "pdp == NULL\n");
586 todo_wine ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
587 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
588 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
589 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
590 ok(pvarRes != NULL, "pvarRes == NULL\n");
591 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
592 ok(pei != NULL, "pei == NULL\n");
594 bound[0].lLbound = 0;
595 bound[0].cElements = 5;
596 bound[1].lLbound = 2;
597 bound[1].cElements = 2;
599 V_VT(pvarRes) = VT_ARRAY|VT_VARIANT;
600 V_ARRAY(pvarRes) = SafeArrayCreate(VT_VARIANT, 2, bound);
602 SafeArrayAccessData(V_ARRAY(pvarRes), (void**)&data);
610 SafeArrayUnaccessData(V_ARRAY(pvarRes));
616 ok(0, "unexpected call %x\n", id);
617 return DISP_E_MEMBERNOTFOUND;
620 static IDispatchExVtbl GlobalVtbl = {
621 DispatchEx_QueryInterface,
624 DispatchEx_GetTypeInfoCount,
625 DispatchEx_GetTypeInfo,
626 DispatchEx_GetIDsOfNames,
630 DispatchEx_DeleteMemberByName,
631 DispatchEx_DeleteMemberByDispID,
632 DispatchEx_GetMemberProperties,
633 DispatchEx_GetMemberName,
634 DispatchEx_GetNextDispID,
635 DispatchEx_GetNameSpaceParent
638 static IDispatchEx Global = { &GlobalVtbl };
640 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
644 if(IsEqualGUID(&IID_IUnknown, riid))
646 else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
649 return E_NOINTERFACE;
651 IUnknown_AddRef((IUnknown*)*ppv);
655 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
660 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
665 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
667 *plcid = GetUserDefaultLCID();
671 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
672 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
674 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
675 ok(!ppti, "ppti != NULL\n");
677 if(!strcmp_wa(pstrName, test_valA))
678 CHECK_EXPECT(GetItemInfo_testVal);
679 else if(strcmp_wa(pstrName, testA))
680 ok(0, "unexpected pstrName %s\n", wine_dbgstr_w(pstrName));
682 *ppiunkItem = (IUnknown*)&Global;
686 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
691 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
692 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
697 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
702 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
707 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
712 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
717 #undef ACTSCPSITE_THIS
719 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
720 ActiveScriptSite_QueryInterface,
721 ActiveScriptSite_AddRef,
722 ActiveScriptSite_Release,
723 ActiveScriptSite_GetLCID,
724 ActiveScriptSite_GetItemInfo,
725 ActiveScriptSite_GetDocVersionString,
726 ActiveScriptSite_OnScriptTerminate,
727 ActiveScriptSite_OnStateChange,
728 ActiveScriptSite_OnScriptError,
729 ActiveScriptSite_OnEnterScript,
730 ActiveScriptSite_OnLeaveScript
733 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
735 static HRESULT WINAPI ActiveScriptSite_OnScriptError_CheckError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
737 ok(pscripterror != NULL, "ActiveScriptSite_OnScriptError -- expected pscripterror to be set, got NULL\n");
739 script_error = pscripterror;
740 IUnknown_AddRef(script_error);
742 CHECK_EXPECT(ActiveScriptSite_OnScriptError);
747 static const IActiveScriptSiteVtbl ActiveScriptSite_CheckErrorVtbl = {
748 ActiveScriptSite_QueryInterface,
749 ActiveScriptSite_AddRef,
750 ActiveScriptSite_Release,
751 ActiveScriptSite_GetLCID,
752 ActiveScriptSite_GetItemInfo,
753 ActiveScriptSite_GetDocVersionString,
754 ActiveScriptSite_OnScriptTerminate,
755 ActiveScriptSite_OnStateChange,
756 ActiveScriptSite_OnScriptError_CheckError,
757 ActiveScriptSite_OnEnterScript,
758 ActiveScriptSite_OnLeaveScript
761 static IActiveScriptSite ActiveScriptSite_CheckError = { &ActiveScriptSite_CheckErrorVtbl };
763 static HRESULT set_script_prop(IActiveScript *engine, DWORD property, VARIANT *val)
765 IActiveScriptProperty *script_prop;
768 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptProperty,
769 (void**)&script_prop);
770 ok(hres == S_OK, "Could not get IActiveScriptProperty iface: %08x\n", hres);
772 hres = IActiveScriptProperty_SetProperty(script_prop, property, NULL, val);
773 IActiveScriptProperty_Release(script_prop);
778 static IActiveScript *create_script(void)
780 IActiveScript *script;
784 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
785 &IID_IActiveScript, (void**)&script);
786 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
789 V_I4(&v) = invoke_version;
790 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
791 ok(hres == S_OK || broken(hres == E_NOTIMPL), "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
792 if(invoke_version && FAILED(hres)) {
793 IActiveScript_Release(script);
800 static HRESULT parse_script(DWORD flags, BSTR script_str)
802 IActiveScriptParse *parser;
803 IActiveScript *engine;
806 engine = create_script();
810 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
811 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
814 IActiveScript_Release(engine);
818 hres = IActiveScriptParse64_InitNew(parser);
819 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
821 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
822 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
824 hres = IActiveScript_AddNamedItem(engine, testW,
825 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags);
826 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
828 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
829 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
831 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp);
832 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
833 ok(script_disp != NULL, "script_disp == NULL\n");
834 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n");
836 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
838 IDispatch_Release(script_disp);
839 IActiveScript_Release(engine);
840 IUnknown_Release(parser);
845 static HRESULT parse_htmlscript(BSTR script_str)
847 IActiveScriptParse *parser;
848 IActiveScript *engine;
850 BSTR tmp = a2bstr("</SCRIPT>");
852 engine = create_script();
856 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
857 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
860 IActiveScript_Release(engine);
864 hres = IActiveScriptParse64_InitNew(parser);
865 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
867 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
868 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
870 hres = IActiveScript_AddNamedItem(engine, testW,
871 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
872 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
874 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
875 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
877 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, tmp, 0, 0, 0, NULL, NULL);
879 IActiveScript_Release(engine);
880 IUnknown_Release(parser);
886 static void test_IActiveScriptError(IActiveScriptError *error, SCODE errorcode, ULONG line, LONG pos, BSTR script_source, BSTR description, BSTR line_text)
889 DWORD source_context;
895 /* IActiveScriptError_GetSourcePosition */
897 hres = IActiveScriptError_GetSourcePosition(error, NULL, NULL, NULL);
898 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
900 source_context = 0xdeadbeef;
901 hres = IActiveScriptError_GetSourcePosition(error, &source_context, NULL, NULL);
902 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
903 ok(source_context == 0, "IActiveScriptError_GetSourcePosition -- source_context: expected 0, got 0x%08x\n", source_context);
905 line_number = 0xdeadbeef;
906 hres = IActiveScriptError_GetSourcePosition(error, NULL, &line_number, NULL);
907 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
908 ok(line_number == line, "IActiveScriptError_GetSourcePosition -- line_number: expected %d, got %d\n", line, line_number);
910 char_position = 0xdeadbeef;
911 hres = IActiveScriptError_GetSourcePosition(error, NULL, NULL, &char_position);
912 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
913 ok(char_position == pos, "IActiveScriptError_GetSourcePosition -- char_position: expected %d, got %d\n", pos, char_position);
915 /* IActiveScriptError_GetSourceLineText */
917 hres = IActiveScriptError_GetSourceLineText(error, NULL);
918 ok(hres == E_POINTER, "IActiveScriptError_GetSourceLineText -- hres: expected E_POINTER, got 0x%08x\n", hres);
921 hres = IActiveScriptError_GetSourceLineText(error, &linetext);
923 ok(hres == S_OK, "IActiveScriptError_GetSourceLineText -- hres: expected S_OK, got 0x%08x\n", hres);
924 ok(linetext != NULL && !lstrcmpW(linetext, line_text),
925 "IActiveScriptError_GetSourceLineText -- expected %s, got %s\n", wine_dbgstr_w(line_text), wine_dbgstr_w(linetext));
927 ok(hres == E_FAIL, "IActiveScriptError_GetSourceLineText -- hres: expected S_OK, got 0x%08x\n", hres);
929 "IActiveScriptError_GetSourceLineText -- expected NULL, got %s\n", wine_dbgstr_w(linetext));
931 SysFreeString(linetext);
933 /* IActiveScriptError_GetExceptionInfo */
935 hres = IActiveScriptError_GetExceptionInfo(error, NULL);
936 ok(hres == E_POINTER, "IActiveScriptError_GetExceptionInfo -- hres: expected E_POINTER, got 0x%08x\n", hres);
938 excep.wCode = 0xdead;
939 excep.wReserved = 0xdead;
940 excep.bstrSource = (BSTR)0xdeadbeef;
941 excep.bstrDescription = (BSTR)0xdeadbeef;
942 excep.bstrHelpFile = (BSTR)0xdeadbeef;
943 excep.dwHelpContext = 0xdeadbeef;
944 excep.pvReserved = (void *)0xdeadbeef;
945 excep.pfnDeferredFillIn = (void *)0xdeadbeef;
946 excep.scode = 0xdeadbeef;
948 hres = IActiveScriptError_GetExceptionInfo(error, &excep);
949 ok(hres == S_OK, "IActiveScriptError_GetExceptionInfo -- hres: expected S_OK, got 0x%08x\n", hres);
951 ok(excep.wCode == 0, "IActiveScriptError_GetExceptionInfo -- excep.wCode: expected 0, got 0x%08x\n", excep.wCode);
952 ok(excep.wReserved == 0, "IActiveScriptError_GetExceptionInfo -- excep.wReserved: expected 0, got %d\n", excep.wReserved);
953 if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH)
954 skip("Non-english locale (test with hardcoded strings)\n");
956 ok(excep.bstrSource != NULL && !lstrcmpW(excep.bstrSource, script_source),
957 "IActiveScriptError_GetExceptionInfo -- excep.bstrSource is not valid: expected %s, got %s\n",
958 wine_dbgstr_w(script_source), wine_dbgstr_w(excep.bstrSource));
959 ok(excep.bstrDescription != NULL && !lstrcmpW(excep.bstrDescription, description),
960 "IActiveScriptError_GetExceptionInfo -- excep.bstrDescription is not valid: got %s\n", wine_dbgstr_w(excep.bstrDescription));
962 ok(excep.bstrHelpFile == NULL,
963 "IActiveScriptError_GetExceptionInfo -- excep.bstrHelpFile: expected NULL, got %s\n", wine_dbgstr_w(excep.bstrHelpFile));
964 ok(excep.dwHelpContext == 0, "IActiveScriptError_GetExceptionInfo -- excep.dwHelpContext: expected 0, got %d\n", excep.dwHelpContext);
965 ok(excep.pvReserved == NULL, "IActiveScriptError_GetExceptionInfo -- excep.pvReserved: expected NULL, got %p\n", excep.pvReserved);
966 ok(excep.pfnDeferredFillIn == NULL, "IActiveScriptError_GetExceptionInfo -- excep.pfnDeferredFillIn: expected NULL, got %p\n", excep.pfnDeferredFillIn);
967 ok(excep.scode == errorcode, "IActiveScriptError_GetExceptionInfo -- excep.scode: expected 0x%08x, got 0x%08x\n", errorcode, excep.scode);
969 SysFreeString(excep.bstrSource);
970 SysFreeString(excep.bstrDescription);
971 SysFreeString(excep.bstrHelpFile);
974 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)
976 IActiveScriptParse *parser;
977 IActiveScript *engine;
980 engine = create_script();
984 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
985 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
988 IActiveScript_Release(engine);
992 hres = IActiveScriptParse64_InitNew(parser);
993 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
995 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite_CheckError);
996 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
998 hres = IActiveScript_AddNamedItem(engine, testW,
999 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags);
1000 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1002 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1003 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1005 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp);
1006 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
1007 ok(script_disp != NULL, "script_disp == NULL\n");
1008 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n");
1010 script_error = NULL;
1011 SET_EXPECT(ActiveScriptSite_OnScriptError);
1012 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1013 todo_wine ok(hres == 0x80020101, "parse_script_with_error should have returned 0x80020101, got: 0x%08x\n", hres);
1014 todo_wine CHECK_CALLED(ActiveScriptSite_OnScriptError);
1018 test_IActiveScriptError(script_error, errorcode, line, pos, script_source, description, line_text);
1020 IUnknown_Release(script_error);
1023 IDispatch_Release(script_disp);
1024 IActiveScript_Release(engine);
1025 IUnknown_Release(parser);
1028 static void parse_script_af(DWORD flags, const char *src)
1034 hres = parse_script(flags, tmp);
1036 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1039 static void parse_script_a(const char *src)
1041 parse_script_af(SCRIPTITEM_GLOBALMEMBERS, src);
1044 static void parse_script_with_error_a(const char *src, SCODE errorcode, ULONG line, LONG pos, LPCSTR source, LPCSTR desc, LPCSTR linetext)
1046 BSTR tmp, script_source, description, line_text;
1049 script_source = a2bstr(source);
1050 description = a2bstr(desc);
1051 line_text = a2bstr(linetext);
1053 parse_script_with_error(SCRIPTITEM_GLOBALMEMBERS, tmp, errorcode, line, pos, script_source, description, line_text);
1055 SysFreeString(line_text);
1056 SysFreeString(description);
1057 SysFreeString(script_source);
1061 static HRESULT parse_htmlscript_a(const char *src)
1064 BSTR tmp = a2bstr(src);
1065 hres = parse_htmlscript(tmp);
1071 static BSTR get_script_from_file(const char *filename)
1075 const char *file_map;
1078 file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
1079 if(file == INVALID_HANDLE_VALUE) {
1080 trace("Could not open file: %u\n", GetLastError());
1084 size = GetFileSize(file, NULL);
1086 map = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
1088 if(map == INVALID_HANDLE_VALUE) {
1089 trace("Could not create file mapping: %u\n", GetLastError());
1093 file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
1096 trace("MapViewOfFile failed: %u\n", GetLastError());
1100 len = MultiByteToWideChar(CP_ACP, 0, file_map, size, NULL, 0);
1101 ret = SysAllocStringLen(NULL, len);
1102 MultiByteToWideChar(CP_ACP, 0, file_map, size, ret, len);
1104 UnmapViewOfFile(file_map);
1109 static void run_from_file(const char *filename)
1114 script_str = get_script_from_file(filename);
1118 strict_dispid_check = FALSE;
1119 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, script_str);
1120 SysFreeString(script_str);
1121 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1124 static void run_from_res(const char *name)
1132 strict_dispid_check = FALSE;
1135 src = FindResourceA(NULL, name, (LPCSTR)40);
1136 ok(src != NULL, "Could not find resource %s\n", name);
1138 size = SizeofResource(NULL, src);
1139 data = LoadResource(NULL, src);
1141 len = MultiByteToWideChar(CP_ACP, 0, data, size, NULL, 0);
1142 str = SysAllocStringLen(NULL, len);
1143 len = MultiByteToWideChar(CP_ACP, 0, data, size, str, len);
1145 SET_EXPECT(global_success_d);
1146 SET_EXPECT(global_success_i);
1147 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, str);
1148 CHECK_CALLED(global_success_d);
1149 CHECK_CALLED(global_success_i);
1151 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1155 static void test_isvisible(BOOL global_members)
1157 IActiveScriptParse *parser;
1158 IActiveScript *engine;
1161 static const WCHAR script_textW[] =
1162 {'v','a','r',' ','v',' ','=',' ','t','e','s','t','V','a','l',';',0};
1164 engine = create_script();
1168 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1169 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1172 IActiveScript_Release(engine);
1176 hres = IActiveScriptParse64_InitNew(parser);
1177 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1179 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1180 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1183 SET_EXPECT(GetItemInfo_testVal);
1184 hres = IActiveScript_AddNamedItem(engine, test_valW,
1185 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|
1186 (global_members ? SCRIPTITEM_GLOBALMEMBERS : 0));
1187 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1189 CHECK_CALLED(GetItemInfo_testVal);
1191 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1192 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1195 SET_EXPECT(GetItemInfo_testVal);
1196 hres = IActiveScriptParse64_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1197 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1199 CHECK_CALLED(GetItemInfo_testVal);
1201 hres = IActiveScriptParse64_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1202 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1204 IActiveScript_Release(engine);
1205 IUnknown_Release(parser);
1208 static void run_tests(void)
1212 if(invoke_version) {
1213 IActiveScript *script;
1215 script = create_script();
1217 win_skip("Could not create script\n");
1220 IActiveScript_Release(script);
1223 strict_dispid_check = TRUE;
1226 parse_script_a("/* empty */ ;");
1228 SET_EXPECT(global_propget_d);
1229 SET_EXPECT(global_propget_i);
1230 parse_script_a("testPropGet;");
1231 CHECK_CALLED(global_propget_d);
1232 CHECK_CALLED(global_propget_i);
1234 SET_EXPECT(global_propput_d);
1235 SET_EXPECT(global_propput_i);
1236 parse_script_a("testPropPut = 1;");
1237 CHECK_CALLED(global_propput_d);
1238 CHECK_CALLED(global_propput_i);
1240 SET_EXPECT(global_success_d);
1241 SET_EXPECT(global_success_i);
1242 parse_script_a("reportSuccess();");
1243 CHECK_CALLED(global_success_d);
1244 CHECK_CALLED(global_success_i);
1246 SET_EXPECT(testobj_delete);
1247 parse_script_a("delete testObj.deleteTest;");
1248 CHECK_CALLED(testobj_delete);
1250 parse_script_a("ok(typeof(test) === 'object', \"typeof(test) != 'object'\");");
1252 parse_script_a("function reportSuccess() {}; reportSuccess();");
1254 SET_EXPECT(global_propget_d);
1255 parse_script_a("var testPropGet");
1256 CHECK_CALLED(global_propget_d);
1258 SET_EXPECT(global_propget_d);
1259 parse_script_a("eval('var testPropGet;');");
1260 CHECK_CALLED(global_propget_d);
1262 SET_EXPECT(global_notexists_d);
1263 parse_script_a("var notExists; notExists = 1;");
1264 CHECK_CALLED(global_notexists_d);
1266 parse_script_a("function f() { var testPropGet; }");
1267 parse_script_a("(function () { var testPropGet; })();");
1268 parse_script_a("(function () { eval('var testPropGet;'); })();");
1270 parse_script_a("ok((testObj instanceof Object) === false, 'testObj is instance of Object');");
1272 SET_EXPECT(testobj_prop_d);
1273 parse_script_a("ok(('prop' in testObj) === true, 'prop is not in testObj');");
1274 CHECK_CALLED(testobj_prop_d);
1276 SET_EXPECT(testobj_noprop_d);
1277 parse_script_a("ok(('noprop' in testObj) === false, 'noprop is in testObj');");
1278 CHECK_CALLED(testobj_noprop_d);
1280 SET_EXPECT(testobj_value);
1281 parse_script_a("ok(String(testObj) === '1', 'wrong testObj value');");
1282 CHECK_CALLED(testobj_value);
1284 SET_EXPECT(testobj_value);
1285 parse_script_a("ok(String.prototype.concat.call(testObj, ' OK') === '1 OK', 'wrong concat result');");
1286 CHECK_CALLED(testobj_value);
1288 SET_EXPECT(global_propget_d);
1289 SET_EXPECT(global_propget_i);
1290 parse_script_a("this.testPropGet;");
1291 CHECK_CALLED(global_propget_d);
1292 CHECK_CALLED(global_propget_i);
1294 SET_EXPECT(global_propget_d);
1295 SET_EXPECT(global_propget_i);
1296 parse_script_a("(function () { this.testPropGet; })();");
1297 CHECK_CALLED(global_propget_d);
1298 CHECK_CALLED(global_propget_i);
1300 parse_script_a("testThis(this);");
1301 parse_script_a("(function () { testThis(this); })();");
1303 run_from_res("lang.js");
1304 run_from_res("api.js");
1305 run_from_res("regexp.js");
1307 test_isvisible(FALSE);
1308 test_isvisible(TRUE);
1310 parse_script_af(0, "test.testThis2(this);");
1311 parse_script_af(0, "(function () { test.testThis2(this); })();");
1313 hres = parse_htmlscript_a("<!--");
1314 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1315 hres = parse_htmlscript_a("-->");
1316 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1317 hres = parse_htmlscript_a("<!--\nvar a=1;\n-->\n");
1318 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1319 hres = parse_htmlscript_a("<!--\n<!-- ignore this\n-->\n");
1320 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1321 hres = parse_htmlscript_a("var a=1;\nif(a-->0) a=5;\n");
1322 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1323 hres = parse_htmlscript_a("var a=1;\nif(a\n-->0) a=5;\n");
1324 ok(hres != S_OK, "ParseScriptText have not failed\n");
1326 parse_script_with_error_a(
1329 "Microsoft JScript compilation error",
1333 parse_script_with_error_a(
1334 "var a=1;\nif(a\n-->0) a=5;\n",
1336 "Microsoft JScript compilation error",
1340 parse_script_with_error_a(
1343 "Microsoft JScript runtime error",
1344 "Object doesn't support this action",
1347 parse_script_with_error_a(
1350 "Microsoft JScript runtime error",
1354 parse_script_with_error_a(
1355 "var a;\nnew null;",
1357 "Microsoft JScript runtime error",
1361 parse_script_with_error_a(
1364 "Microsoft JScript runtime error",
1369 static BOOL check_jscript(void)
1371 IActiveScriptProperty *script_prop;
1375 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1376 &IID_IActiveScriptProperty, (void**)&script_prop);
1379 IActiveScriptProperty_Release(script_prop);
1381 str = a2bstr("if(!('localeCompare' in String.prototype)) throw 1;");
1382 hres = parse_script(0, str);
1385 return hres == S_OK;
1393 argc = winetest_get_mainargs(&argv);
1397 if(!check_jscript()) {
1398 win_skip("Broken engine, probably too old\n");
1399 }else if(argc > 2) {
1400 run_from_file(argv[2]);
1402 trace("invoke version 0\n");
1406 trace("invoke version 2\n");