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