[JSCRIPT_WINETEST]
[reactos.git] / rostests / winetests / jscript / run.c
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #define WIN32_NO_STATUS
20 #define _INC_WINDOWS
21 #define COM_NO_WINDOWS_H
22
23 #include <stdio.h>
24
25 #define COBJMACROS
26 #define CONST_VTABLE
27
28 #include <windef.h>
29 #include <winbase.h>
30 #include <winnls.h>
31 #include <ole2.h>
32 #include <dispex.h>
33 #include <activscp.h>
34
35 #include <wine/test.h>
36
37 #ifdef _WIN64
38
39 #define IActiveScriptParse_QueryInterface IActiveScriptParse64_QueryInterface
40 #define IActiveScriptParse_Release IActiveScriptParse64_Release
41 #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
42 #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
43 #define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_64_Release
44 #define IActiveScriptParseProcedure2_ParseProcedureText IActiveScriptParseProcedure2_64_ParseProcedureText
45
46 #else
47
48 #define IActiveScriptParse_QueryInterface IActiveScriptParse32_QueryInterface
49 #define IActiveScriptParse_Release IActiveScriptParse32_Release
50 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
51 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
52 #define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_32_Release
53 #define IActiveScriptParseProcedure2_ParseProcedureText IActiveScriptParseProcedure2_32_ParseProcedureText
54
55 #endif
56
57 static const CLSID CLSID_JScript =
58 {0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
59 static const CLSID CLSID_JScriptEncode =
60 {0xf414c262,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
61
62 #define DEFINE_EXPECT(func) \
63 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
64
65 #define SET_EXPECT(func) \
66 expect_ ## func = TRUE
67
68 #define CHECK_EXPECT2(func) \
69 do { \
70 ok(expect_ ##func, "unexpected call " #func "\n"); \
71 called_ ## func = TRUE; \
72 }while(0)
73
74 #define CHECK_EXPECT(func) \
75 do { \
76 CHECK_EXPECT2(func); \
77 expect_ ## func = FALSE; \
78 }while(0)
79
80 #define CHECK_CALLED(func) \
81 do { \
82 ok(called_ ## func, "expected " #func "\n"); \
83 expect_ ## func = called_ ## func = FALSE; \
84 }while(0)
85
86 DEFINE_EXPECT(global_propget_d);
87 DEFINE_EXPECT(global_propget_i);
88 DEFINE_EXPECT(global_propput_d);
89 DEFINE_EXPECT(global_propput_i);
90 DEFINE_EXPECT(global_propdelete_d);
91 DEFINE_EXPECT(global_nopropdelete_d);
92 DEFINE_EXPECT(global_success_d);
93 DEFINE_EXPECT(global_success_i);
94 DEFINE_EXPECT(global_notexists_d);
95 DEFINE_EXPECT(global_propargput_d);
96 DEFINE_EXPECT(global_propargput_i);
97 DEFINE_EXPECT(global_testargtypes_i);
98 DEFINE_EXPECT(puredisp_prop_d);
99 DEFINE_EXPECT(puredisp_noprop_d);
100 DEFINE_EXPECT(puredisp_value);
101 DEFINE_EXPECT(dispexfunc_value);
102 DEFINE_EXPECT(testobj_delete_test);
103 DEFINE_EXPECT(testobj_delete_nodelete);
104 DEFINE_EXPECT(testobj_value);
105 DEFINE_EXPECT(testobj_prop_d);
106 DEFINE_EXPECT(testobj_withprop_d);
107 DEFINE_EXPECT(testobj_withprop_i);
108 DEFINE_EXPECT(testobj_noprop_d);
109 DEFINE_EXPECT(testobj_onlydispid_d);
110 DEFINE_EXPECT(testobj_onlydispid_i);
111 DEFINE_EXPECT(GetItemInfo_testVal);
112 DEFINE_EXPECT(ActiveScriptSite_OnScriptError);
113 DEFINE_EXPECT(invoke_func);
114 DEFINE_EXPECT(DeleteMemberByDispID);
115 DEFINE_EXPECT(DeleteMemberByDispID_false);
116
117 #define DISPID_GLOBAL_TESTPROPGET 0x1000
118 #define DISPID_GLOBAL_TESTPROPPUT 0x1001
119 #define DISPID_GLOBAL_REPORTSUCCESS 0x1002
120 #define DISPID_GLOBAL_TRACE 0x1003
121 #define DISPID_GLOBAL_OK 0x1004
122 #define DISPID_GLOBAL_GETVT 0x1005
123 #define DISPID_GLOBAL_TESTOBJ 0x1006
124 #define DISPID_GLOBAL_GETNULLBSTR 0x1007
125 #define DISPID_GLOBAL_NULL_DISP 0x1008
126 #define DISPID_GLOBAL_TESTTHIS 0x1009
127 #define DISPID_GLOBAL_TESTTHIS2 0x100a
128 #define DISPID_GLOBAL_INVOKEVERSION 0x100b
129 #define DISPID_GLOBAL_CREATEARRAY 0x100c
130 #define DISPID_GLOBAL_PROPGETFUNC 0x100d
131 #define DISPID_GLOBAL_OBJECT_FLAG 0x100e
132 #define DISPID_GLOBAL_ISWIN64 0x100f
133 #define DISPID_GLOBAL_PUREDISP 0x1010
134 #define DISPID_GLOBAL_ISNULLBSTR 0x1011
135 #define DISPID_GLOBAL_PROPARGPUT 0x1012
136 #define DISPID_GLOBAL_SHORTPROP 0x1013
137 #define DISPID_GLOBAL_GETSHORT 0x1014
138 #define DISPID_GLOBAL_TESTARGTYPES 0x1015
139 #define DISPID_GLOBAL_INTPROP 0x1016
140 #define DISPID_GLOBAL_DISPUNK 0x1017
141 #define DISPID_GLOBAL_TESTRES 0x1018
142 #define DISPID_GLOBAL_TESTNORES 0x1019
143 #define DISPID_GLOBAL_DISPEXFUNC 0x101a
144
145 #define DISPID_GLOBAL_TESTPROPDELETE 0x2000
146 #define DISPID_GLOBAL_TESTNOPROPDELETE 0x2001
147
148 #define DISPID_TESTOBJ_PROP 0x2000
149 #define DISPID_TESTOBJ_ONLYDISPID 0x2001
150 #define DISPID_TESTOBJ_WITHPROP 0x2002
151
152 #define JS_E_INVALID_CHAR 0x800a03f6
153
154 static const WCHAR testW[] = {'t','e','s','t',0};
155 static const CHAR testA[] = "test";
156 static const WCHAR test_valW[] = {'t','e','s','t','V','a','l',0};
157 static const CHAR test_valA[] = "testVal";
158 static const WCHAR emptyW[] = {0};
159
160 static BOOL strict_dispid_check, testing_expr;
161 static const char *test_name = "(null)";
162 static IDispatch *script_disp;
163 static int invoke_version;
164 static IActiveScriptError *script_error;
165 static const CLSID *engine_clsid = &CLSID_JScript;
166
167 /* Returns true if the user interface is in English. Note that this does not
168 * presume of the formatting of dates, numbers, etc.
169 */
170 static BOOL is_lang_english(void)
171 {
172 static HMODULE hkernel32 = NULL;
173 static LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL;
174 static LANGID (WINAPI *pGetUserDefaultUILanguage)(void) = NULL;
175
176 if (!hkernel32)
177 {
178 hkernel32 = GetModuleHandleA("kernel32.dll");
179 pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
180 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
181 }
182 if (pGetThreadUILanguage)
183 return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH;
184 if (pGetUserDefaultUILanguage)
185 return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH;
186
187 return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
188 }
189
190 static BSTR a2bstr(const char *str)
191 {
192 BSTR ret;
193 int len;
194
195 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
196 ret = SysAllocStringLen(NULL, len-1);
197 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
198
199 return ret;
200 }
201
202 static int strcmp_wa(LPCWSTR strw, const char *stra)
203 {
204 CHAR buf[512];
205 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
206 return lstrcmpA(buf, stra);
207 }
208
209 #define test_grfdex(a,b) _test_grfdex(__LINE__,a,b)
210 static void _test_grfdex(unsigned line, DWORD grfdex, DWORD expect)
211 {
212 expect |= invoke_version << 28;
213 ok_(__FILE__,line)(grfdex == expect, "grfdex = %x, expected %x\n", grfdex, expect);
214 }
215
216 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
217 {
218 *ppv = NULL;
219
220 if(IsEqualGUID(riid, &IID_IUnknown)
221 || IsEqualGUID(riid, &IID_IDispatch)
222 || IsEqualGUID(riid, &IID_IDispatchEx))
223 *ppv = iface;
224 else
225 return E_NOINTERFACE;
226
227 return S_OK;
228 }
229
230 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
231 {
232 return 2;
233 }
234
235 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
236 {
237 return 1;
238 }
239
240 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
241 {
242 ok(0, "unexpected call\n");
243 return E_NOTIMPL;
244 }
245
246 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
247 LCID lcid, ITypeInfo **ppTInfo)
248 {
249 ok(0, "unexpected call\n");
250 return E_NOTIMPL;
251 }
252
253 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
254 LPOLESTR *rgszNames, UINT cNames,
255 LCID lcid, DISPID *rgDispId)
256 {
257 ok(0, "unexpected call\n");
258 return E_NOTIMPL;
259 }
260
261 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
262 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
263 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
264 {
265 ok(0, "unexpected call\n");
266 return E_NOTIMPL;
267 }
268
269 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
270 {
271 ok(0, "unexpected call\n");
272 return E_NOTIMPL;
273 }
274
275 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
276 {
277 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
278 return E_NOTIMPL;
279 }
280
281 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
282 {
283 ok(0, "unexpected call\n");
284 return E_NOTIMPL;
285 }
286
287 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
288 {
289 ok(0, "unexpected call\n");
290 return E_NOTIMPL;
291 }
292
293 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
294 {
295 ok(0, "unexpected call\n");
296 return E_NOTIMPL;
297 }
298
299 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
300 {
301 ok(0, "unexpected call\n");
302 return E_NOTIMPL;
303 }
304
305 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
306 {
307 ok(0, "unexpected call\n");
308 return E_NOTIMPL;
309 }
310
311 static HRESULT WINAPI testObj_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
312 {
313 if(!strcmp_wa(bstrName, "prop")) {
314 CHECK_EXPECT(testobj_prop_d);
315 test_grfdex(grfdex, fdexNameCaseSensitive);
316 *pid = DISPID_TESTOBJ_PROP;
317 return S_OK;
318 }
319 if(!strcmp_wa(bstrName, "withProp")) {
320 CHECK_EXPECT(testobj_withprop_d);
321 test_grfdex(grfdex, fdexNameCaseSensitive|fdexNameImplicit);
322 *pid = DISPID_TESTOBJ_WITHPROP;
323 return S_OK;
324 }
325 if(!strcmp_wa(bstrName, "noprop")) {
326 CHECK_EXPECT(testobj_noprop_d);
327 test_grfdex(grfdex, fdexNameCaseSensitive);
328 return DISP_E_UNKNOWNNAME;
329 }
330 if(!strcmp_wa(bstrName, "onlyDispID")) {
331 if(strict_dispid_check)
332 CHECK_EXPECT(testobj_onlydispid_d);
333 test_grfdex(grfdex, fdexNameCaseSensitive);
334 *pid = DISPID_TESTOBJ_ONLYDISPID;
335 return S_OK;
336 }
337
338 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
339 return E_NOTIMPL;
340 }
341
342 static HRESULT WINAPI testObj_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
343 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
344 {
345 ok(pspCaller != NULL, "pspCaller = NULL\n");
346
347 switch(id) {
348 case DISPID_VALUE:
349 ok(pdp != NULL, "pdp == NULL\n");
350 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
351 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
352 ok(pvarRes != NULL, "pvarRes == NULL\n");
353 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
354 ok(pei != NULL, "pei == NULL\n");
355
356 switch(wFlags) {
357 case INVOKE_PROPERTYGET:
358 CHECK_EXPECT(testobj_value);
359 ok(!pdp->rgvarg, "rgvarg != NULL\n");
360 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
361 break;
362 case INVOKE_FUNC:
363 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
364 break;
365 case INVOKE_FUNC|INVOKE_PROPERTYGET:
366 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
367 break;
368 default:
369 ok(0, "invalid flag (%x)\n", wFlags);
370 }
371
372 V_VT(pvarRes) = VT_I4;
373 V_I4(pvarRes) = 1;
374 return S_OK;
375 case DISPID_TESTOBJ_ONLYDISPID:
376 if(strict_dispid_check)
377 CHECK_EXPECT(testobj_onlydispid_i);
378 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
379 ok(pdp != NULL, "pdp == NULL\n");
380 ok(!pdp->rgvarg, "rgvarg != NULL\n");
381 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
382 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
383 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
384 ok(pvarRes != NULL, "pvarRes == NULL\n");
385 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
386 ok(pei != NULL, "pei == NULL\n");
387 return DISP_E_MEMBERNOTFOUND;
388 case DISPID_TESTOBJ_WITHPROP:
389 CHECK_EXPECT(testobj_withprop_i);
390
391 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
392 ok(pdp != NULL, "pdp == NULL\n");
393 ok(!pdp->rgvarg, "rgvarg != NULL\n");
394 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
395 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
396 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
397 ok(pvarRes != NULL, "pvarRes == NULL\n");
398 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
399 ok(pei != NULL, "pei == NULL\n");
400
401 V_VT(pvarRes) = VT_I4;
402 V_I4(pvarRes) = 1;
403
404 return S_OK;
405 }
406
407 ok(0, "unexpected call %x\n", id);
408 return DISP_E_MEMBERNOTFOUND;
409 }
410
411 static HRESULT WINAPI testObj_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
412 {
413 if(!strcmp_wa(bstrName, "deleteTest")) {
414 CHECK_EXPECT(testobj_delete_test);
415 test_grfdex(grfdex, fdexNameCaseSensitive);
416 return S_OK;
417 }
418 if(!strcmp_wa(bstrName, "noDeleteTest")) {
419 CHECK_EXPECT(testobj_delete_nodelete);
420 test_grfdex(grfdex, fdexNameCaseSensitive);
421 return S_FALSE;
422 }
423
424 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
425 return E_FAIL;
426 }
427
428 static IDispatchExVtbl testObjVtbl = {
429 DispatchEx_QueryInterface,
430 DispatchEx_AddRef,
431 DispatchEx_Release,
432 DispatchEx_GetTypeInfoCount,
433 DispatchEx_GetTypeInfo,
434 DispatchEx_GetIDsOfNames,
435 DispatchEx_Invoke,
436 testObj_GetDispID,
437 testObj_InvokeEx,
438 testObj_DeleteMemberByName,
439 DispatchEx_DeleteMemberByDispID,
440 DispatchEx_GetMemberProperties,
441 DispatchEx_GetMemberName,
442 DispatchEx_GetNextDispID,
443 DispatchEx_GetNameSpaceParent
444 };
445
446 static IDispatchEx testObj = { &testObjVtbl };
447
448 static HRESULT WINAPI dispexFunc_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
449 VARIANT *res, EXCEPINFO *pei, IServiceProvider *pspCaller)
450 {
451 ok(pspCaller != NULL, "pspCaller = NULL\n");
452
453 switch(id) {
454 case DISPID_VALUE:
455 CHECK_EXPECT(dispexfunc_value);
456
457 ok(pdp != NULL, "pdp == NULL\n");
458 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
459 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs != NULL\n");
460 ok(*pdp->rgdispidNamedArgs == DISPID_THIS, "*rgdispidNamedArgs = %d\n", *pdp->rgdispidNamedArgs);
461 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
462 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
463 ok(res != NULL, "res == NULL\n");
464 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
465 ok(pei != NULL, "pei == NULL\n");
466
467 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(pdp->rgvarg+1) = %d\n", V_VT(pdp->rgvarg+1));
468 ok(!V_BOOL(pdp->rgvarg+1), "V_BOOL(pdp->rgvarg+1) = %x\n", V_BOOL(pdp->rgvarg+1));
469
470 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
471 ok(V_DISPATCH(pdp->rgvarg) != NULL, "V_DISPATCH(pdp->rgvarg) == NULL\n");
472
473 if(res)
474 V_VT(res) = VT_NULL;
475 return S_OK;
476 default:
477 ok(0, "unexpected call %x\n", id);
478 return DISP_E_MEMBERNOTFOUND;
479 }
480 }
481
482 static IDispatchExVtbl dispexFuncVtbl = {
483 DispatchEx_QueryInterface,
484 DispatchEx_AddRef,
485 DispatchEx_Release,
486 DispatchEx_GetTypeInfoCount,
487 DispatchEx_GetTypeInfo,
488 DispatchEx_GetIDsOfNames,
489 DispatchEx_Invoke,
490 DispatchEx_GetDispID,
491 dispexFunc_InvokeEx,
492 DispatchEx_DeleteMemberByName,
493 DispatchEx_DeleteMemberByDispID,
494 DispatchEx_GetMemberProperties,
495 DispatchEx_GetMemberName,
496 DispatchEx_GetNextDispID,
497 DispatchEx_GetNameSpaceParent
498 };
499
500 static IDispatchEx dispexFunc = { &dispexFuncVtbl };
501
502 static HRESULT WINAPI pureDisp_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
503 {
504 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IDispatch)) {
505 *ppv = iface;
506 return S_OK;
507 }
508
509 *ppv = NULL;
510 return E_NOINTERFACE;
511 }
512
513 static HRESULT WINAPI pureDisp_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
514 LPOLESTR *rgszNames, UINT cNames,
515 LCID lcid, DISPID *rgDispId)
516 {
517 ok(IsEqualGUID(riid, &IID_NULL), "Expected IID_NULL\n");
518 ok(cNames==1, "cNames = %d\n", cNames);
519
520 if(!strcmp_wa(*rgszNames, "prop")) {
521 CHECK_EXPECT(puredisp_prop_d);
522 *rgDispId = DISPID_TESTOBJ_PROP;
523 return S_OK;
524 } else if(!strcmp_wa(*rgszNames, "noprop")) {
525 CHECK_EXPECT(puredisp_noprop_d);
526 return DISP_E_UNKNOWNNAME;
527 }
528
529 ok(0, "unexpected call\n");
530 return E_NOTIMPL;
531 }
532
533 static HRESULT WINAPI pureDisp_Invoke(IDispatchEx *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
534 WORD wFlags, DISPPARAMS *pdp, VARIANT *res, EXCEPINFO *ei, UINT *puArgErr)
535 {
536 ok(IsEqualGUID(&IID_NULL, riid), "unexpected riid\n");
537
538 switch(dispIdMember) {
539 case DISPID_VALUE:
540 CHECK_EXPECT(puredisp_value);
541
542 ok(pdp != NULL, "pdp == NULL\n");
543 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
544 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
545 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
546 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
547 ok(res != NULL, "res == NULL\n");
548 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
549 ok(ei != NULL, "ei == NULL\n");
550 ok(puArgErr != NULL, "puArgErr == NULL\n");
551
552 ok(V_VT(pdp->rgvarg) == VT_BOOL, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
553 ok(!V_BOOL(pdp->rgvarg), "V_BOOL(pdp->rgvarg) = %x\n", V_BOOL(pdp->rgvarg));
554
555 if(res)
556 V_VT(res) = VT_NULL;
557 return S_OK;
558 default:
559 ok(0, "unexpected call\n");
560 return E_NOTIMPL;
561 }
562 }
563
564 static IDispatchExVtbl pureDispVtbl = {
565 pureDisp_QueryInterface,
566 DispatchEx_AddRef,
567 DispatchEx_Release,
568 DispatchEx_GetTypeInfoCount,
569 DispatchEx_GetTypeInfo,
570 pureDisp_GetIDsOfNames,
571 pureDisp_Invoke
572 };
573
574 static IDispatchEx pureDisp = { &pureDispVtbl };
575
576 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
577 {
578 if(!strcmp_wa(bstrName, "ok")) {
579 test_grfdex(grfdex, fdexNameCaseSensitive);
580 *pid = DISPID_GLOBAL_OK;
581 return S_OK;
582 }
583 if(!strcmp_wa(bstrName, "trace")) {
584 test_grfdex(grfdex, fdexNameCaseSensitive);
585 *pid = DISPID_GLOBAL_TRACE;
586 return S_OK;
587 }
588 if(!strcmp_wa(bstrName, "reportSuccess")) {
589 CHECK_EXPECT(global_success_d);
590 test_grfdex(grfdex, fdexNameCaseSensitive);
591 *pid = DISPID_GLOBAL_REPORTSUCCESS;
592 return S_OK;
593 }
594 if(!strcmp_wa(bstrName, "testPropGet")) {
595 CHECK_EXPECT(global_propget_d);
596 test_grfdex(grfdex, fdexNameCaseSensitive);
597 *pid = DISPID_GLOBAL_TESTPROPGET;
598 return S_OK;
599 }
600 if(!strcmp_wa(bstrName, "testPropPut")) {
601 CHECK_EXPECT(global_propput_d);
602 test_grfdex(grfdex, fdexNameCaseSensitive);
603 *pid = DISPID_GLOBAL_TESTPROPPUT;
604 return S_OK;
605 }
606 if(!strcmp_wa(bstrName, "testPropDelete")) {
607 CHECK_EXPECT(global_propdelete_d);
608 test_grfdex(grfdex, fdexNameCaseSensitive);
609 *pid = DISPID_GLOBAL_TESTPROPDELETE;
610 return S_OK;
611 }
612 if(!strcmp_wa(bstrName, "testNoPropDelete")) {
613 CHECK_EXPECT(global_nopropdelete_d);
614 test_grfdex(grfdex, fdexNameCaseSensitive);
615 *pid = DISPID_GLOBAL_TESTNOPROPDELETE;
616 return S_OK;
617 }
618 if(!strcmp_wa(bstrName, "getVT")) {
619 test_grfdex(grfdex, fdexNameCaseSensitive);
620 *pid = DISPID_GLOBAL_GETVT;
621 return S_OK;
622 }
623 if(!strcmp_wa(bstrName, "testObj")) {
624 test_grfdex(grfdex, fdexNameCaseSensitive);
625 *pid = DISPID_GLOBAL_TESTOBJ;
626 return S_OK;
627 }
628 if(!strcmp_wa(bstrName, "getNullBSTR")) {
629 *pid = DISPID_GLOBAL_GETNULLBSTR;
630 return S_OK;
631 }
632 if(!strcmp_wa(bstrName, "isNullBSTR")) {
633 *pid = DISPID_GLOBAL_ISNULLBSTR;
634 return S_OK;
635 }
636 if(!strcmp_wa(bstrName, "nullDisp")) {
637 *pid = DISPID_GLOBAL_NULL_DISP;
638 return S_OK;
639 }
640 if(!strcmp_wa(bstrName, "notExists")) {
641 CHECK_EXPECT(global_notexists_d);
642 test_grfdex(grfdex, fdexNameCaseSensitive);
643 return DISP_E_UNKNOWNNAME;
644 }
645
646 if(!strcmp_wa(bstrName, "testThis")) {
647 test_grfdex(grfdex, fdexNameCaseSensitive);
648 *pid = DISPID_GLOBAL_TESTTHIS;
649 return S_OK;
650 }
651
652 if(!strcmp_wa(bstrName, "testThis2")) {
653 test_grfdex(grfdex, fdexNameCaseSensitive);
654 *pid = DISPID_GLOBAL_TESTTHIS2;
655 return S_OK;
656 }
657
658 if(!strcmp_wa(bstrName, "invokeVersion")) {
659 test_grfdex(grfdex, fdexNameCaseSensitive);
660 *pid = DISPID_GLOBAL_INVOKEVERSION;
661 return S_OK;
662 }
663 if(!strcmp_wa(bstrName, "createArray")) {
664 test_grfdex(grfdex, fdexNameCaseSensitive);
665 *pid = DISPID_GLOBAL_CREATEARRAY;
666 return S_OK;
667 }
668 if(!strcmp_wa(bstrName, "propGetFunc")) {
669 test_grfdex(grfdex, fdexNameCaseSensitive);
670 *pid = DISPID_GLOBAL_PROPGETFUNC;
671 return S_OK;
672 }
673 if(!strcmp_wa(bstrName, "objectFlag")) {
674 test_grfdex(grfdex, fdexNameCaseSensitive);
675 *pid = DISPID_GLOBAL_OBJECT_FLAG;
676 return S_OK;
677 }
678
679 if(!strcmp_wa(bstrName, "isWin64")) {
680 test_grfdex(grfdex, fdexNameCaseSensitive);
681 *pid = DISPID_GLOBAL_ISWIN64;
682 return S_OK;
683 }
684
685 if(!strcmp_wa(bstrName, "pureDisp")) {
686 test_grfdex(grfdex, fdexNameCaseSensitive);
687 *pid = DISPID_GLOBAL_PUREDISP;
688 return S_OK;
689 }
690
691 if(!strcmp_wa(bstrName, "propArgPutG")) {
692 CHECK_EXPECT(global_propargput_d);
693 test_grfdex(grfdex, fdexNameCaseSensitive);
694 *pid = DISPID_GLOBAL_PROPARGPUT;
695 return S_OK;
696 }
697
698 if(!strcmp_wa(bstrName, "propArgPutO")) {
699 CHECK_EXPECT(global_propargput_d);
700 test_grfdex(grfdex, fdexNameEnsure|fdexNameCaseSensitive);
701 *pid = DISPID_GLOBAL_PROPARGPUT;
702 return S_OK;
703 }
704
705 if(!strcmp_wa(bstrName, "shortProp")) {
706 *pid = DISPID_GLOBAL_SHORTPROP;
707 return S_OK;
708 }
709
710 if(!strcmp_wa(bstrName, "getShort")) {
711 *pid = DISPID_GLOBAL_GETSHORT;
712 return S_OK;
713 }
714
715 if(!strcmp_wa(bstrName, "testArgTypes")) {
716 *pid = DISPID_GLOBAL_TESTARGTYPES;
717 return S_OK;
718 }
719
720 if(!strcmp_wa(bstrName, "intProp")) {
721 *pid = DISPID_GLOBAL_INTPROP;
722 return S_OK;
723 }
724
725 if(!strcmp_wa(bstrName, "dispUnk")) {
726 *pid = DISPID_GLOBAL_DISPUNK;
727 return S_OK;
728 }
729
730 if(!strcmp_wa(bstrName, "testRes")) {
731 *pid = DISPID_GLOBAL_TESTRES;
732 return S_OK;
733 }
734
735 if(!strcmp_wa(bstrName, "testNoRes")) {
736 *pid = DISPID_GLOBAL_TESTNORES;
737 return S_OK;
738 }
739
740 if(!strcmp_wa(bstrName, "dispexFunc")) {
741 *pid = DISPID_GLOBAL_DISPEXFUNC;
742 return S_OK;
743 }
744
745 if(strict_dispid_check && strcmp_wa(bstrName, "t"))
746 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
747 return DISP_E_UNKNOWNNAME;
748 }
749
750 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
751 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
752 {
753 ok(pspCaller != NULL, "pspCaller = NULL\n");
754
755 switch(id) {
756 case DISPID_GLOBAL_OK:
757 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
758 ok(pdp != NULL, "pdp == NULL\n");
759 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
760 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
761 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
762 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
763 if(wFlags & INVOKE_PROPERTYGET)
764 ok(pvarRes != NULL, "pvarRes == NULL\n");
765 else
766 ok(!pvarRes, "pvarRes != NULL\n");
767 ok(pei != NULL, "pei == NULL\n");
768
769 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
770 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(pdp->rgvarg+1) = %d\n", V_VT(pdp->rgvarg+1));
771 ok(V_BOOL(pdp->rgvarg+1), "%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
772
773 return S_OK;
774
775 case DISPID_GLOBAL_TRACE:
776 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
777 ok(pdp != NULL, "pdp == NULL\n");
778 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
779 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
780 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
781 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
782 ok(!pvarRes, "pvarRes != NULL\n");
783 ok(pei != NULL, "pei == NULL\n");
784
785 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
786 if(V_VT(pdp->rgvarg) == VT_BSTR)
787 trace("%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
788
789 return S_OK;
790
791 case DISPID_GLOBAL_REPORTSUCCESS:
792 CHECK_EXPECT(global_success_i);
793
794 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
795 ok(pdp != NULL, "pdp == NULL\n");
796 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
797 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
798 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
799 if(!testing_expr)
800 ok(!pvarRes, "pvarRes != NULL\n");
801 ok(pei != NULL, "pei == NULL\n");
802
803 return S_OK;
804
805 case DISPID_GLOBAL_TESTPROPGET:
806 CHECK_EXPECT(global_propget_i);
807
808 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
809 ok(pdp != NULL, "pdp == NULL\n");
810 ok(!pdp->rgvarg, "rgvarg != NULL\n");
811 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
812 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
813 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
814 ok(pvarRes != NULL, "pvarRes == NULL\n");
815 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
816 ok(pei != NULL, "pei == NULL\n");
817
818 V_VT(pvarRes) = VT_I4;
819 V_I4(pvarRes) = 1;
820
821 return S_OK;
822
823 case DISPID_GLOBAL_TESTPROPPUT:
824 CHECK_EXPECT(global_propput_i);
825
826 ok(wFlags == INVOKE_PROPERTYPUT, "wFlags = %x\n", wFlags);
827 ok(pdp != NULL, "pdp == NULL\n");
828 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
829 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
830 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
831 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
832 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
833 ok(!pvarRes, "pvarRes != NULL\n");
834
835 ok(V_VT(pdp->rgvarg) == VT_I4, "V_VT(pdp->rgvarg)=%d\n", V_VT(pdp->rgvarg));
836 ok(V_I4(pdp->rgvarg) == 1, "V_I4(pdp->rgvarg)=%d\n", V_I4(pdp->rgvarg));
837 return S_OK;
838
839 case DISPID_GLOBAL_GETVT:
840 ok(pdp != NULL, "pdp == NULL\n");
841 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
842 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
843 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
844 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
845 ok(pvarRes != NULL, "pvarRes == NULL\n");
846 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
847 ok(pei != NULL, "pei == NULL\n");
848
849 V_VT(pvarRes) = VT_BSTR;
850 switch(V_VT(pdp->rgvarg)) {
851 case VT_EMPTY:
852 V_BSTR(pvarRes) = a2bstr("VT_EMPTY");
853 break;
854 case VT_NULL:
855 V_BSTR(pvarRes) = a2bstr("VT_NULL");
856 break;
857 case VT_I4:
858 V_BSTR(pvarRes) = a2bstr("VT_I4");
859 break;
860 case VT_R8:
861 V_BSTR(pvarRes) = a2bstr("VT_R8");
862 break;
863 case VT_BSTR:
864 V_BSTR(pvarRes) = a2bstr("VT_BSTR");
865 break;
866 case VT_DISPATCH:
867 V_BSTR(pvarRes) = a2bstr("VT_DISPATCH");
868 break;
869 case VT_BOOL:
870 V_BSTR(pvarRes) = a2bstr("VT_BOOL");
871 break;
872 case VT_ARRAY|VT_VARIANT:
873 V_BSTR(pvarRes) = a2bstr("VT_ARRAY|VT_VARIANT");
874 break;
875 default:
876 ok(0, "unknown vt %d\n", V_VT(pdp->rgvarg));
877 return E_FAIL;
878 }
879
880 return S_OK;
881
882 case DISPID_GLOBAL_TESTRES:
883 ok(pvarRes != NULL, "pvarRes = NULL\n");
884 if(pvarRes) {
885 V_VT(pvarRes) = VT_BOOL;
886 V_BOOL(pvarRes) = VARIANT_TRUE;
887 }
888 return S_OK;
889
890 case DISPID_GLOBAL_TESTNORES:
891 ok(!pvarRes, "pvarRes != NULL\n");
892 if(pvarRes)
893 V_VT(pvarRes) = VT_NULL;
894 return S_OK;
895
896 case DISPID_GLOBAL_TESTOBJ:
897 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
898 ok(pdp != NULL, "pdp == NULL\n");
899 ok(!pdp->rgvarg, "rgvarg != NULL\n");
900 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
901 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
902 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
903 ok(pvarRes != NULL, "pvarRes == NULL\n");
904 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
905 ok(pei != NULL, "pei == NULL\n");
906
907 V_VT(pvarRes) = VT_DISPATCH;
908 V_DISPATCH(pvarRes) = (IDispatch*)&testObj;
909 return S_OK;
910
911 case DISPID_GLOBAL_PUREDISP:
912 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
913 ok(pdp != NULL, "pdp == NULL\n");
914 ok(!pdp->rgvarg, "rgvarg != NULL\n");
915 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
916 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
917 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
918 ok(pvarRes != NULL, "pvarRes == NULL\n");
919 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
920 ok(pei != NULL, "pei == NULL\n");
921
922 V_VT(pvarRes) = VT_DISPATCH;
923 V_DISPATCH(pvarRes) = (IDispatch*)&pureDisp;
924 return S_OK;
925
926 case DISPID_GLOBAL_DISPEXFUNC:
927 V_VT(pvarRes) = VT_DISPATCH;
928 V_DISPATCH(pvarRes) = (IDispatch*)&dispexFunc;
929 return S_OK;
930
931 case DISPID_GLOBAL_GETNULLBSTR:
932 if(pvarRes) {
933 V_VT(pvarRes) = VT_BSTR;
934 V_BSTR(pvarRes) = NULL;
935 }
936 return S_OK;
937
938 case DISPID_GLOBAL_ISNULLBSTR:
939 ok(pdp != NULL, "pdp == NULL\n");
940 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
941 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
942 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
943 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
944 ok(pvarRes != NULL, "pvarRes == NULL\n");
945 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
946 ok(pei != NULL, "pei == NULL\n");
947 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
948
949 V_VT(pvarRes) = VT_BOOL;
950 V_BOOL(pvarRes) = V_BSTR(pdp->rgvarg) ? VARIANT_FALSE : VARIANT_TRUE;
951 return S_OK;
952
953 case DISPID_GLOBAL_ISWIN64:
954 if(pvarRes) {
955 V_VT(pvarRes) = VT_BOOL;
956 V_BOOL(pvarRes) = sizeof(void*) == 8 ? VARIANT_TRUE : VARIANT_FALSE;
957 }
958 return S_OK;
959
960 case DISPID_GLOBAL_NULL_DISP:
961 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
962 ok(pdp != NULL, "pdp == NULL\n");
963 ok(!pdp->rgvarg, "rgvarg != NULL\n");
964 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
965 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
966 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
967 ok(pvarRes != NULL, "pvarRes == NULL\n");
968 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
969 ok(pei != NULL, "pei == NULL\n");
970
971 V_VT(pvarRes) = VT_DISPATCH;
972 V_DISPATCH(pvarRes) = NULL;
973 return S_OK;
974
975 case DISPID_GLOBAL_TESTTHIS:
976 ok(pdp != NULL, "pdp == NULL\n");
977 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
978 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
979 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
980 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
981 ok(pvarRes == NULL, "pvarRes != NULL\n");
982 ok(pei != NULL, "pei == NULL\n");
983
984 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
985 ok(V_DISPATCH(pdp->rgvarg) == (IDispatch*)iface, "disp != iface\n");
986
987 return S_OK;
988
989 case DISPID_GLOBAL_TESTTHIS2:
990 ok(pdp != NULL, "pdp == NULL\n");
991 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
992 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
993 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
994 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
995 ok(pvarRes == NULL, "pvarRes != NULL\n");
996 ok(pei != NULL, "pei == NULL\n");
997
998 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(arg) = %d\n", V_VT(pdp->rgvarg));
999 ok(V_DISPATCH(pdp->rgvarg) != (IDispatch*)iface, "disp == iface\n");
1000 ok(V_DISPATCH(pdp->rgvarg) == script_disp, "disp != script_disp\n");
1001
1002 return S_OK;
1003
1004 case DISPID_GLOBAL_INVOKEVERSION:
1005 ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags);
1006 ok(pdp != NULL, "pdp == NULL\n");
1007 ok(!pdp->rgvarg, "rgvarg != NULL\n");
1008 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1009 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1010 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1011 ok(pvarRes != NULL, "pvarRes == NULL\n");
1012 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1013 ok(pei != NULL, "pei == NULL\n");
1014
1015 V_VT(pvarRes) = VT_I4;
1016 V_I4(pvarRes) = invoke_version;
1017
1018 return S_OK;
1019
1020 case DISPID_GLOBAL_CREATEARRAY: {
1021 SAFEARRAYBOUND bound[2];
1022 VARIANT *data;
1023 int i,j;
1024
1025 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1026 ok(pdp != NULL, "pdp == NULL\n");
1027 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1028 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1029 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1030 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1031 ok(pvarRes != NULL, "pvarRes == NULL\n");
1032 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1033 ok(pei != NULL, "pei == NULL\n");
1034
1035 bound[0].lLbound = 0;
1036 bound[0].cElements = 5;
1037 bound[1].lLbound = 2;
1038 bound[1].cElements = 2;
1039
1040 V_VT(pvarRes) = VT_ARRAY|VT_VARIANT;
1041 V_ARRAY(pvarRes) = SafeArrayCreate(VT_VARIANT, 2, bound);
1042
1043 SafeArrayAccessData(V_ARRAY(pvarRes), (void**)&data);
1044 for(i=0; i<5; i++) {
1045 for(j=2; j<4; j++) {
1046 V_VT(data) = VT_I4;
1047 V_I4(data) = i*10+j;
1048 data++;
1049 }
1050 }
1051 SafeArrayUnaccessData(V_ARRAY(pvarRes));
1052
1053 return S_OK;
1054 }
1055
1056 case DISPID_GLOBAL_PROPGETFUNC:
1057 switch(wFlags) {
1058 case INVOKE_FUNC:
1059 CHECK_EXPECT(invoke_func);
1060 break;
1061 case INVOKE_FUNC|INVOKE_PROPERTYGET:
1062 ok(pdp->cArgs != 0, "pdp->cArgs = %d\n", pdp->cArgs);
1063 ok(pvarRes != NULL, "pdp->pvarRes == NULL\n");
1064 break;
1065 default:
1066 ok(0, "invalid flag (%x)\n", wFlags);
1067 }
1068
1069 ok(pdp != NULL, "pdp == NULL\n");
1070 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1071 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1072 ok(pei != NULL, "pei == NULL\n");
1073
1074 if(pvarRes) {
1075 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1076 V_VT(pvarRes) = VT_I4;
1077 V_I4(pvarRes) = pdp->cArgs;
1078 }
1079
1080 return S_OK;
1081
1082 case DISPID_GLOBAL_PROPARGPUT:
1083 CHECK_EXPECT(global_propargput_i);
1084 ok(wFlags == INVOKE_PROPERTYPUT, "wFlags = %x\n", wFlags);
1085 ok(pdp != NULL, "pdp == NULL\n");
1086 ok(pdp->rgvarg != NULL, "rgvarg != NULL\n");
1087 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
1088 ok(pdp->cArgs == 3, "cArgs = %d\n", pdp->cArgs);
1089 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
1090 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
1091 ok(!pvarRes, "pvarRes != NULL\n");
1092 ok(pei != NULL, "pei == NULL\n");
1093
1094 ok(V_VT(pdp->rgvarg) == VT_I4, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
1095 ok(V_I4(pdp->rgvarg) == 2, "V_I4(pdp->rgvarg) = %d\n", V_I4(pdp->rgvarg));
1096
1097 ok(V_VT(pdp->rgvarg+1) == VT_I4, "V_VT(pdp->rgvarg+1) = %d\n", V_VT(pdp->rgvarg+1));
1098 ok(V_I4(pdp->rgvarg+1) == 1, "V_I4(pdp->rgvarg+1) = %d\n", V_I4(pdp->rgvarg+1));
1099
1100 ok(V_VT(pdp->rgvarg+2) == VT_I4, "V_VT(pdp->rgvarg+2) = %d\n", V_VT(pdp->rgvarg+2));
1101 ok(V_I4(pdp->rgvarg+2) == 0, "V_I4(pdp->rgvarg+2) = %d\n", V_I4(pdp->rgvarg+2));
1102 return S_OK;
1103
1104 case DISPID_GLOBAL_OBJECT_FLAG: {
1105 IDispatchEx *dispex;
1106 BSTR str;
1107 HRESULT hres;
1108
1109 hres = IDispatch_QueryInterface(script_disp, &IID_IDispatchEx, (void**)&dispex);
1110 ok(hres == S_OK, "hres = %x\n", hres);
1111
1112 str = a2bstr("Object");
1113 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
1114 SysFreeString(str);
1115 ok(hres == S_OK, "hres = %x\n", hres);
1116
1117 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD, pdp, NULL, pei, pspCaller);
1118 ok(hres == S_OK, "hres = %x\n", hres);
1119
1120 V_VT(pvarRes) = VT_EMPTY;
1121 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD, pdp, pvarRes, pei, pspCaller);
1122 ok(hres == S_OK, "hres = %x\n", hres);
1123 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1124 VariantClear(pvarRes);
1125
1126 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_METHOD|DISPATCH_PROPERTYGET, pdp, NULL, pei, pspCaller);
1127 ok(hres == S_OK, "hres = %x\n", hres);
1128
1129 V_VT(pvarRes) = VT_EMPTY;
1130 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT, pdp, pvarRes, pei, pspCaller);
1131 ok(hres == S_OK, "hres = %x\n", hres);
1132 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1133 VariantClear(pvarRes);
1134
1135 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT, pdp, NULL, pei, pspCaller);
1136 ok(hres == S_OK, "hres = %x\n", hres);
1137
1138 V_VT(pvarRes) = VT_EMPTY;
1139 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_CONSTRUCT|DISPATCH_PROPERTYGET, pdp, pvarRes, pei, pspCaller);
1140 ok(hres == E_INVALIDARG, "hres = %x\n", hres);
1141
1142 V_VT(pvarRes) = VT_EMPTY;
1143 hres = IDispatchEx_InvokeEx(dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1144 ok(hres == S_OK, "hres = %x\n", hres);
1145 ok(V_VT(pvarRes) == VT_DISPATCH, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1146 IDispatchEx_Release(dispex);
1147 return S_OK;
1148 }
1149 case DISPID_GLOBAL_SHORTPROP:
1150 case DISPID_GLOBAL_GETSHORT:
1151 V_VT(pvarRes) = VT_I2;
1152 V_I2(pvarRes) = 10;
1153 return S_OK;
1154
1155 case DISPID_GLOBAL_INTPROP:
1156 V_VT(pvarRes) = VT_INT;
1157 V_INT(pvarRes) = 22;
1158 return S_OK;
1159
1160 case DISPID_GLOBAL_DISPUNK:
1161 V_VT(pvarRes) = VT_UNKNOWN;
1162 V_UNKNOWN(pvarRes) = (IUnknown*)&testObj;
1163 return S_OK;
1164
1165 case DISPID_GLOBAL_TESTARGTYPES: {
1166 VARIANT args[4];
1167 DISPPARAMS dp = {args, NULL, sizeof(args)/sizeof(*args), 0};
1168 HRESULT hres;
1169
1170 CHECK_EXPECT(global_testargtypes_i);
1171 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
1172 ok(pdp != NULL, "pdp == NULL\n");
1173 ok(pdp->rgvarg != NULL, "rgvarg != NULL\n");
1174 ok(pdp->cArgs == 6, "cArgs = %d\n", pdp->cArgs);
1175 ok(!pvarRes, "pvarRes != NULL\n");
1176
1177 ok(V_VT(pdp->rgvarg+1) == VT_I4, "V_VT(pdp->rgvarg+1) = %d\n", V_VT(pdp->rgvarg+1));
1178 ok(V_I4(pdp->rgvarg+1) == 10, "V_I4(pdp->rgvarg+1) = %d\n", V_I4(pdp->rgvarg+1));
1179
1180 ok(V_VT(pdp->rgvarg+2) == VT_I4, "V_VT(pdp->rgvarg+2) = %d\n", V_VT(pdp->rgvarg+2));
1181 ok(V_I4(pdp->rgvarg+2) == 10, "V_I4(pdp->rgvarg+2) = %d\n", V_I4(pdp->rgvarg+2));
1182
1183 ok(V_VT(pdp->rgvarg+3) == VT_I4, "V_VT(pdp->rgvarg+3) = %d\n", V_VT(pdp->rgvarg+3));
1184 ok(V_I4(pdp->rgvarg+3) == 22, "V_I4(pdp->rgvarg+3) = %d\n", V_I4(pdp->rgvarg+3));
1185
1186 ok(V_VT(pdp->rgvarg+4) == VT_I4, "V_VT(pdp->rgvarg+4) = %d\n", V_VT(pdp->rgvarg+4));
1187 ok(V_I4(pdp->rgvarg+4) == 22, "V_I4(pdp->rgvarg+4) = %d\n", V_I4(pdp->rgvarg+4));
1188
1189 ok(V_VT(pdp->rgvarg+5) == VT_DISPATCH, "V_VT(pdp->rgvarg+5) = %d\n", V_VT(pdp->rgvarg+5));
1190 ok(V_DISPATCH(pdp->rgvarg+5) == (IDispatch*)&testObj, "V_DISPATCH(pdp->rgvarg+5) != testObj\n");
1191
1192 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
1193
1194 V_VT(args) = VT_I2;
1195 V_I2(args) = 2;
1196 V_VT(args+1) = VT_INT;
1197 V_INT(args+1) = 22;
1198 V_VT(args+2) = VT_UNKNOWN;
1199 V_UNKNOWN(args+2) = (IUnknown*)&testObj;
1200 V_VT(args+3) = VT_UNKNOWN;
1201 V_UNKNOWN(args+3) = NULL;
1202 hres = IDispatch_Invoke(V_DISPATCH(pdp->rgvarg), DISPID_VALUE, &IID_NULL, 0, DISPATCH_METHOD, &dp, NULL, NULL, NULL);
1203 ok(hres == S_OK, "Invoke failed: %08x\n", hres);
1204
1205 return S_OK;
1206 }
1207 }
1208
1209 ok(0, "unexpected call %x\n", id);
1210 return DISP_E_MEMBERNOTFOUND;
1211 }
1212
1213 static HRESULT WINAPI Global_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1214 {
1215 switch(id) {
1216 case DISPID_GLOBAL_TESTPROPDELETE:
1217 CHECK_EXPECT(DeleteMemberByDispID);
1218 return S_OK;
1219 case DISPID_GLOBAL_TESTNOPROPDELETE:
1220 CHECK_EXPECT(DeleteMemberByDispID_false);
1221 return S_FALSE;
1222 default:
1223 ok(0, "id = %d\n", id);
1224 }
1225
1226 return E_FAIL;
1227 }
1228
1229 static IDispatchExVtbl GlobalVtbl = {
1230 DispatchEx_QueryInterface,
1231 DispatchEx_AddRef,
1232 DispatchEx_Release,
1233 DispatchEx_GetTypeInfoCount,
1234 DispatchEx_GetTypeInfo,
1235 DispatchEx_GetIDsOfNames,
1236 DispatchEx_Invoke,
1237 Global_GetDispID,
1238 Global_InvokeEx,
1239 DispatchEx_DeleteMemberByName,
1240 Global_DeleteMemberByDispID,
1241 DispatchEx_GetMemberProperties,
1242 DispatchEx_GetMemberName,
1243 DispatchEx_GetNextDispID,
1244 DispatchEx_GetNameSpaceParent
1245 };
1246
1247 static IDispatchEx Global = { &GlobalVtbl };
1248
1249 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
1250 {
1251 *ppv = NULL;
1252
1253 if(IsEqualGUID(&IID_IUnknown, riid))
1254 *ppv = iface;
1255 else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
1256 *ppv = iface;
1257 else
1258 return E_NOINTERFACE;
1259
1260 IUnknown_AddRef((IUnknown*)*ppv);
1261 return S_OK;
1262 }
1263
1264 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
1265 {
1266 return 2;
1267 }
1268
1269 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
1270 {
1271 return 1;
1272 }
1273
1274 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
1275 {
1276 *plcid = GetUserDefaultLCID();
1277 return S_OK;
1278 }
1279
1280 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
1281 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
1282 {
1283 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
1284 ok(!ppti, "ppti != NULL\n");
1285
1286 if(!strcmp_wa(pstrName, test_valA))
1287 CHECK_EXPECT(GetItemInfo_testVal);
1288 else if(strcmp_wa(pstrName, testA))
1289 ok(0, "unexpected pstrName %s\n", wine_dbgstr_w(pstrName));
1290
1291 *ppiunkItem = (IUnknown*)&Global;
1292 return S_OK;
1293 }
1294
1295 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
1296 {
1297 return E_NOTIMPL;
1298 }
1299
1300 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
1301 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
1302 {
1303 return E_NOTIMPL;
1304 }
1305
1306 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
1307 {
1308 return E_NOTIMPL;
1309 }
1310
1311 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
1312 {
1313 return E_NOTIMPL;
1314 }
1315
1316 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
1317 {
1318 return E_NOTIMPL;
1319 }
1320
1321 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
1322 {
1323 return E_NOTIMPL;
1324 }
1325
1326 #undef ACTSCPSITE_THIS
1327
1328 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
1329 ActiveScriptSite_QueryInterface,
1330 ActiveScriptSite_AddRef,
1331 ActiveScriptSite_Release,
1332 ActiveScriptSite_GetLCID,
1333 ActiveScriptSite_GetItemInfo,
1334 ActiveScriptSite_GetDocVersionString,
1335 ActiveScriptSite_OnScriptTerminate,
1336 ActiveScriptSite_OnStateChange,
1337 ActiveScriptSite_OnScriptError,
1338 ActiveScriptSite_OnEnterScript,
1339 ActiveScriptSite_OnLeaveScript
1340 };
1341
1342 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
1343
1344 static HRESULT WINAPI ActiveScriptSite_OnScriptError_CheckError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
1345 {
1346 ok(pscripterror != NULL, "ActiveScriptSite_OnScriptError -- expected pscripterror to be set, got NULL\n");
1347
1348 script_error = pscripterror;
1349 IActiveScriptError_AddRef(script_error);
1350
1351 CHECK_EXPECT(ActiveScriptSite_OnScriptError);
1352
1353 return S_OK;
1354 }
1355
1356 static const IActiveScriptSiteVtbl ActiveScriptSite_CheckErrorVtbl = {
1357 ActiveScriptSite_QueryInterface,
1358 ActiveScriptSite_AddRef,
1359 ActiveScriptSite_Release,
1360 ActiveScriptSite_GetLCID,
1361 ActiveScriptSite_GetItemInfo,
1362 ActiveScriptSite_GetDocVersionString,
1363 ActiveScriptSite_OnScriptTerminate,
1364 ActiveScriptSite_OnStateChange,
1365 ActiveScriptSite_OnScriptError_CheckError,
1366 ActiveScriptSite_OnEnterScript,
1367 ActiveScriptSite_OnLeaveScript
1368 };
1369
1370 static IActiveScriptSite ActiveScriptSite_CheckError = { &ActiveScriptSite_CheckErrorVtbl };
1371
1372 static HRESULT set_script_prop(IActiveScript *engine, DWORD property, VARIANT *val)
1373 {
1374 IActiveScriptProperty *script_prop;
1375 HRESULT hres;
1376
1377 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptProperty,
1378 (void**)&script_prop);
1379 ok(hres == S_OK, "Could not get IActiveScriptProperty iface: %08x\n", hres);
1380
1381 hres = IActiveScriptProperty_SetProperty(script_prop, property, NULL, val);
1382 IActiveScriptProperty_Release(script_prop);
1383
1384 return hres;
1385 }
1386
1387 static IActiveScript *create_script(void)
1388 {
1389 IActiveScript *script;
1390 VARIANT v;
1391 HRESULT hres;
1392
1393 hres = CoCreateInstance(engine_clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1394 &IID_IActiveScript, (void**)&script);
1395 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1396
1397 V_VT(&v) = VT_I4;
1398 V_I4(&v) = invoke_version;
1399 hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
1400 ok(hres == S_OK || broken(hres == E_NOTIMPL), "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
1401 if(invoke_version && FAILED(hres)) {
1402 IActiveScript_Release(script);
1403 return NULL;
1404 }
1405
1406 return script;
1407 }
1408
1409 static HRESULT parse_script(DWORD flags, BSTR script_str)
1410 {
1411 IActiveScriptParse *parser;
1412 IActiveScript *engine;
1413 HRESULT hres;
1414
1415 engine = create_script();
1416 if(!engine)
1417 return S_OK;
1418
1419 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1420 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1421 if (FAILED(hres))
1422 {
1423 IActiveScript_Release(engine);
1424 return hres;
1425 }
1426
1427 hres = IActiveScriptParse_InitNew(parser);
1428 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1429
1430 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1431 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1432
1433 hres = IActiveScript_AddNamedItem(engine, testW,
1434 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags);
1435 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1436
1437 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1438 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1439
1440 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp);
1441 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
1442 ok(script_disp != NULL, "script_disp == NULL\n");
1443 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n");
1444
1445 hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1446
1447 IDispatch_Release(script_disp);
1448 IActiveScript_Release(engine);
1449 IActiveScriptParse_Release(parser);
1450
1451 return hres;
1452 }
1453
1454 static HRESULT invoke_procedure(const char *argsa, const char *sourcea, DISPPARAMS *dp)
1455 {
1456 IActiveScriptParseProcedure2 *parse_proc;
1457 IActiveScriptParse *parser;
1458 IActiveScript *engine;
1459 IDispatchEx *dispex;
1460 EXCEPINFO ei = {0};
1461 BSTR source, args;
1462 IDispatch *disp;
1463 VARIANT res;
1464 HRESULT hres;
1465
1466 engine = create_script();
1467 if(!engine)
1468 return S_OK;
1469
1470 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1471 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1472
1473 hres = IActiveScriptParse_InitNew(parser);
1474 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1475
1476 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1477 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1478
1479 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1480 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1481
1482 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc);
1483 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1484
1485 source = a2bstr(sourcea);
1486 args = argsa ? a2bstr(argsa) : NULL;
1487 hres = IActiveScriptParseProcedure2_ParseProcedureText(parse_proc, source, args, emptyW, NULL, NULL, NULL, 0, 0,
1488 SCRIPTPROC_HOSTMANAGESSOURCE|SCRIPTPROC_IMPLICIT_THIS|SCRIPTPROC_IMPLICIT_PARENTS, &disp);
1489 ok(hres == S_OK, "ParseProcedureText failed: %08x\n", hres);
1490 SysFreeString(source);
1491 SysFreeString(args);
1492
1493 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1494 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
1495 IDispatch_Release(disp);
1496
1497 V_VT(&res) = VT_EMPTY;
1498 hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, 0, DISPATCH_METHOD, dp, &res, &ei, NULL);
1499 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1500 ok(V_VT(&res) == VT_BOOL && V_BOOL(&res), "InvokeEx returned vt %d (%x)\n", V_VT(&res), V_I4(&res));
1501 IDispatchEx_Release(dispex);
1502
1503 IActiveScriptParseProcedure2_Release(parse_proc);
1504 IActiveScript_Release(engine);
1505 IActiveScriptParse_Release(parser);
1506
1507 return hres;
1508 }
1509
1510 static HRESULT parse_htmlscript(BSTR script_str)
1511 {
1512 IActiveScriptParse *parser;
1513 IActiveScript *engine;
1514 HRESULT hres;
1515 BSTR tmp = a2bstr("</SCRIPT>");
1516
1517 engine = create_script();
1518 if(!engine)
1519 return E_FAIL;
1520
1521 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1522 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1523 if (FAILED(hres))
1524 {
1525 IActiveScript_Release(engine);
1526 return E_FAIL;
1527 }
1528
1529 hres = IActiveScriptParse_InitNew(parser);
1530 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1531
1532 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1533 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1534
1535 hres = IActiveScript_AddNamedItem(engine, testW,
1536 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
1537 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1538
1539 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1540 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1541
1542 hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, tmp, 0, 0, 0, NULL, NULL);
1543
1544 IActiveScript_Release(engine);
1545 IActiveScriptParse_Release(parser);
1546 SysFreeString(tmp);
1547
1548 return hres;
1549 }
1550
1551 static void test_IActiveScriptError(IActiveScriptError *error, SCODE errorcode, ULONG line, LONG pos, BSTR script_source, BSTR description, BSTR line_text)
1552 {
1553 HRESULT hres;
1554 DWORD source_context;
1555 ULONG line_number;
1556 LONG char_position;
1557 BSTR linetext;
1558 EXCEPINFO excep;
1559
1560 /* IActiveScriptError_GetSourcePosition */
1561
1562 hres = IActiveScriptError_GetSourcePosition(error, NULL, NULL, NULL);
1563 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1564
1565 source_context = 0xdeadbeef;
1566 hres = IActiveScriptError_GetSourcePosition(error, &source_context, NULL, NULL);
1567 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1568 ok(source_context == 0, "IActiveScriptError_GetSourcePosition -- source_context: expected 0, got 0x%08x\n", source_context);
1569
1570 line_number = 0xdeadbeef;
1571 hres = IActiveScriptError_GetSourcePosition(error, NULL, &line_number, NULL);
1572 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1573 ok(line_number == line, "IActiveScriptError_GetSourcePosition -- line_number: expected %d, got %d\n", line, line_number);
1574
1575 char_position = 0xdeadbeef;
1576 hres = IActiveScriptError_GetSourcePosition(error, NULL, NULL, &char_position);
1577 ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
1578 ok(char_position == pos, "IActiveScriptError_GetSourcePosition -- char_position: expected %d, got %d\n", pos, char_position);
1579
1580 /* IActiveScriptError_GetSourceLineText */
1581
1582 hres = IActiveScriptError_GetSourceLineText(error, NULL);
1583 ok(hres == E_POINTER, "IActiveScriptError_GetSourceLineText -- hres: expected E_POINTER, got 0x%08x\n", hres);
1584
1585 linetext = NULL;
1586 hres = IActiveScriptError_GetSourceLineText(error, &linetext);
1587 if (line_text) {
1588 ok(hres == S_OK, "IActiveScriptError_GetSourceLineText -- hres: expected S_OK, got 0x%08x\n", hres);
1589 ok(linetext != NULL && !lstrcmpW(linetext, line_text),
1590 "IActiveScriptError_GetSourceLineText -- expected %s, got %s\n", wine_dbgstr_w(line_text), wine_dbgstr_w(linetext));
1591 } else {
1592 ok(hres == E_FAIL, "IActiveScriptError_GetSourceLineText -- hres: expected S_OK, got 0x%08x\n", hres);
1593 ok(linetext == NULL,
1594 "IActiveScriptError_GetSourceLineText -- expected NULL, got %s\n", wine_dbgstr_w(linetext));
1595 }
1596 SysFreeString(linetext);
1597
1598 /* IActiveScriptError_GetExceptionInfo */
1599
1600 hres = IActiveScriptError_GetExceptionInfo(error, NULL);
1601 ok(hres == E_POINTER, "IActiveScriptError_GetExceptionInfo -- hres: expected E_POINTER, got 0x%08x\n", hres);
1602
1603 excep.wCode = 0xdead;
1604 excep.wReserved = 0xdead;
1605 excep.bstrSource = (BSTR)0xdeadbeef;
1606 excep.bstrDescription = (BSTR)0xdeadbeef;
1607 excep.bstrHelpFile = (BSTR)0xdeadbeef;
1608 excep.dwHelpContext = 0xdeadbeef;
1609 excep.pvReserved = (void *)0xdeadbeef;
1610 excep.pfnDeferredFillIn = (void *)0xdeadbeef;
1611 excep.scode = 0xdeadbeef;
1612
1613 hres = IActiveScriptError_GetExceptionInfo(error, &excep);
1614 ok(hres == S_OK, "IActiveScriptError_GetExceptionInfo -- hres: expected S_OK, got 0x%08x\n", hres);
1615
1616 ok(excep.wCode == 0, "IActiveScriptError_GetExceptionInfo -- excep.wCode: expected 0, got 0x%08x\n", excep.wCode);
1617 ok(excep.wReserved == 0, "IActiveScriptError_GetExceptionInfo -- excep.wReserved: expected 0, got %d\n", excep.wReserved);
1618 if (!is_lang_english())
1619 skip("Non-english UI (test with hardcoded strings)\n");
1620 else {
1621 ok(excep.bstrSource != NULL && !lstrcmpW(excep.bstrSource, script_source),
1622 "IActiveScriptError_GetExceptionInfo -- excep.bstrSource is not valid: expected %s, got %s\n",
1623 wine_dbgstr_w(script_source), wine_dbgstr_w(excep.bstrSource));
1624 ok(excep.bstrDescription != NULL && !lstrcmpW(excep.bstrDescription, description),
1625 "IActiveScriptError_GetExceptionInfo -- excep.bstrDescription is not valid: got %s\n", wine_dbgstr_w(excep.bstrDescription));
1626 }
1627 ok(excep.bstrHelpFile == NULL,
1628 "IActiveScriptError_GetExceptionInfo -- excep.bstrHelpFile: expected NULL, got %s\n", wine_dbgstr_w(excep.bstrHelpFile));
1629 ok(excep.dwHelpContext == 0, "IActiveScriptError_GetExceptionInfo -- excep.dwHelpContext: expected 0, got %d\n", excep.dwHelpContext);
1630 ok(excep.pvReserved == NULL, "IActiveScriptError_GetExceptionInfo -- excep.pvReserved: expected NULL, got %p\n", excep.pvReserved);
1631 ok(excep.pfnDeferredFillIn == NULL, "IActiveScriptError_GetExceptionInfo -- excep.pfnDeferredFillIn: expected NULL, got %p\n", excep.pfnDeferredFillIn);
1632 ok(excep.scode == errorcode, "IActiveScriptError_GetExceptionInfo -- excep.scode: expected 0x%08x, got 0x%08x\n", errorcode, excep.scode);
1633
1634 SysFreeString(excep.bstrSource);
1635 SysFreeString(excep.bstrDescription);
1636 SysFreeString(excep.bstrHelpFile);
1637 }
1638
1639 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)
1640 {
1641 IActiveScriptParse *parser;
1642 IActiveScript *engine;
1643 HRESULT hres;
1644
1645 engine = create_script();
1646 if(!engine)
1647 return;
1648
1649 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1650 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1651 if (FAILED(hres))
1652 {
1653 IActiveScript_Release(engine);
1654 return;
1655 }
1656
1657 hres = IActiveScriptParse_InitNew(parser);
1658 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1659
1660 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite_CheckError);
1661 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1662
1663 hres = IActiveScript_AddNamedItem(engine, testW,
1664 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags);
1665 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1666
1667 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1668 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1669
1670 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp);
1671 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
1672 ok(script_disp != NULL, "script_disp == NULL\n");
1673 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n");
1674
1675 script_error = NULL;
1676 SET_EXPECT(ActiveScriptSite_OnScriptError);
1677 hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1678 todo_wine ok(hres == 0x80020101, "parse_script_with_error should have returned 0x80020101, got: 0x%08x\n", hres);
1679 todo_wine CHECK_CALLED(ActiveScriptSite_OnScriptError);
1680
1681 if (script_error)
1682 {
1683 test_IActiveScriptError(script_error, errorcode, line, pos, script_source, description, line_text);
1684
1685 IActiveScriptError_Release(script_error);
1686 }
1687
1688 IDispatch_Release(script_disp);
1689 IActiveScript_Release(engine);
1690 IActiveScriptParse_Release(parser);
1691 }
1692
1693 static void parse_script_af(DWORD flags, const char *src)
1694 {
1695 BSTR tmp;
1696 HRESULT hres;
1697
1698 tmp = a2bstr(src);
1699 hres = parse_script(flags, tmp);
1700 SysFreeString(tmp);
1701 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1702 }
1703
1704 static void parse_script_a(const char *src)
1705 {
1706 parse_script_af(SCRIPTITEM_GLOBALMEMBERS, src);
1707 }
1708
1709 static void parse_script_with_error_a(const char *src, SCODE errorcode, ULONG line, LONG pos, LPCSTR source, LPCSTR desc, LPCSTR linetext)
1710 {
1711 BSTR tmp, script_source, description, line_text;
1712
1713 tmp = a2bstr(src);
1714 script_source = a2bstr(source);
1715 description = a2bstr(desc);
1716 line_text = a2bstr(linetext);
1717
1718 parse_script_with_error(SCRIPTITEM_GLOBALMEMBERS, tmp, errorcode, line, pos, script_source, description, line_text);
1719
1720 SysFreeString(line_text);
1721 SysFreeString(description);
1722 SysFreeString(script_source);
1723 SysFreeString(tmp);
1724 }
1725
1726 static HRESULT parse_htmlscript_a(const char *src)
1727 {
1728 HRESULT hres;
1729 BSTR tmp = a2bstr(src);
1730 hres = parse_htmlscript(tmp);
1731 SysFreeString(tmp);
1732
1733 return hres;
1734 }
1735
1736 static BSTR get_script_from_file(const char *filename)
1737 {
1738 DWORD size, len;
1739 HANDLE file, map;
1740 const char *file_map;
1741 BSTR ret;
1742
1743 file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
1744 if(file == INVALID_HANDLE_VALUE) {
1745 trace("Could not open file: %u\n", GetLastError());
1746 return NULL;
1747 }
1748
1749 size = GetFileSize(file, NULL);
1750
1751 map = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
1752 CloseHandle(file);
1753 if(map == INVALID_HANDLE_VALUE) {
1754 trace("Could not create file mapping: %u\n", GetLastError());
1755 return NULL;
1756 }
1757
1758 file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
1759 CloseHandle(map);
1760 if(!file_map) {
1761 trace("MapViewOfFile failed: %u\n", GetLastError());
1762 return NULL;
1763 }
1764
1765 len = MultiByteToWideChar(CP_ACP, 0, file_map, size, NULL, 0);
1766 ret = SysAllocStringLen(NULL, len);
1767 MultiByteToWideChar(CP_ACP, 0, file_map, size, ret, len);
1768
1769 UnmapViewOfFile(file_map);
1770
1771 return ret;
1772 }
1773
1774 static void run_from_file(const char *filename)
1775 {
1776 BSTR script_str;
1777 HRESULT hres;
1778
1779 script_str = get_script_from_file(filename);
1780 if(!script_str)
1781 return;
1782
1783 strict_dispid_check = FALSE;
1784 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, script_str);
1785 SysFreeString(script_str);
1786 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1787 }
1788
1789 static BSTR load_res(const char *name)
1790 {
1791 const char *data;
1792 DWORD size, len;
1793 BSTR str;
1794 HRSRC src;
1795
1796 strict_dispid_check = FALSE;
1797 test_name = name;
1798
1799 src = FindResourceA(NULL, name, (LPCSTR)40);
1800 ok(src != NULL, "Could not find resource %s\n", name);
1801
1802 size = SizeofResource(NULL, src);
1803 data = LoadResource(NULL, src);
1804
1805 len = MultiByteToWideChar(CP_ACP, 0, data, size, NULL, 0);
1806 str = SysAllocStringLen(NULL, len);
1807 MultiByteToWideChar(CP_ACP, 0, data, size, str, len);
1808
1809 return str;
1810 }
1811
1812 static void run_from_res(const char *name)
1813 {
1814 BSTR str;
1815 HRESULT hres;
1816
1817 str = load_res(name);
1818
1819 SET_EXPECT(global_success_d);
1820 SET_EXPECT(global_success_i);
1821 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, str);
1822 CHECK_CALLED(global_success_d);
1823 CHECK_CALLED(global_success_i);
1824
1825 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1826 SysFreeString(str);
1827 }
1828
1829 static void test_isvisible(BOOL global_members)
1830 {
1831 IActiveScriptParse *parser;
1832 IActiveScript *engine;
1833 HRESULT hres;
1834
1835 static const WCHAR script_textW[] =
1836 {'v','a','r',' ','v',' ','=',' ','t','e','s','t','V','a','l',';',0};
1837
1838 engine = create_script();
1839 if(!engine)
1840 return;
1841
1842 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1843 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1844 if (FAILED(hres))
1845 {
1846 IActiveScript_Release(engine);
1847 return;
1848 }
1849
1850 hres = IActiveScriptParse_InitNew(parser);
1851 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1852
1853 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1854 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1855
1856 if(global_members)
1857 SET_EXPECT(GetItemInfo_testVal);
1858 hres = IActiveScript_AddNamedItem(engine, test_valW,
1859 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|
1860 (global_members ? SCRIPTITEM_GLOBALMEMBERS : 0));
1861 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1862 if(global_members)
1863 CHECK_CALLED(GetItemInfo_testVal);
1864
1865 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1866 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1867
1868 if(!global_members)
1869 SET_EXPECT(GetItemInfo_testVal);
1870 hres = IActiveScriptParse_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1871 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1872 if(!global_members)
1873 CHECK_CALLED(GetItemInfo_testVal);
1874
1875 hres = IActiveScriptParse_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1876 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1877
1878 IActiveScript_Release(engine);
1879 IActiveScriptParse_Release(parser);
1880 }
1881
1882 static HRESULT parse_script_expr(const char *expr, VARIANT *res)
1883 {
1884 IActiveScriptParse *parser;
1885 IActiveScript *engine;
1886 BSTR str;
1887 HRESULT hres;
1888
1889 engine = create_script();
1890
1891 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1892 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1893
1894 hres = IActiveScriptParse_InitNew(parser);
1895 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1896
1897 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1898 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1899
1900 SET_EXPECT(GetItemInfo_testVal);
1901 hres = IActiveScript_AddNamedItem(engine, test_valW,
1902 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
1903 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1904 CHECK_CALLED(GetItemInfo_testVal);
1905
1906 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1907 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1908
1909 str = a2bstr(expr);
1910 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, res, NULL);
1911 SysFreeString(str);
1912
1913 IActiveScript_Release(engine);
1914 IActiveScriptParse_Release(parser);
1915
1916 return hres;
1917 }
1918
1919 static void test_script_exprs(void)
1920 {
1921 VARIANT v;
1922 HRESULT hres;
1923
1924 testing_expr = TRUE;
1925
1926 hres = parse_script_expr("true", &v);
1927 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
1928 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
1929 ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v));
1930
1931 hres = parse_script_expr("false, true", &v);
1932 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
1933 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
1934 ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v));
1935
1936 SET_EXPECT(global_success_d);
1937 SET_EXPECT(global_success_i);
1938 hres = parse_script_expr("reportSuccess(); true", &v);
1939 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
1940 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
1941 ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v));
1942 CHECK_CALLED(global_success_d);
1943 CHECK_CALLED(global_success_i);
1944
1945 hres = parse_script_expr("if(false) true", &v);
1946 ok(hres == S_OK, "parse_script_expr failed: %08x\n", hres);
1947 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
1948
1949 hres = parse_script_expr("return testPropGet", &v);
1950 ok(hres == 0x800a03fa, "parse_script_expr failed: %08x\n", hres);
1951
1952 hres = parse_script_expr("reportSuccess(); return true", &v);
1953 ok(hres == 0x800a03fa, "parse_script_expr failed: %08x\n", hres);
1954
1955 testing_expr = FALSE;
1956 }
1957
1958 static BOOL run_tests(void)
1959 {
1960 HRESULT hres;
1961
1962 if(invoke_version) {
1963 IActiveScript *script;
1964
1965 script = create_script();
1966 if(!script) {
1967 win_skip("Could not create script\n");
1968 return FALSE;
1969 }
1970 IActiveScript_Release(script);
1971 }
1972
1973 strict_dispid_check = TRUE;
1974
1975 parse_script_a("");
1976 parse_script_a("/* empty */ ;");
1977
1978 SET_EXPECT(global_propget_d);
1979 SET_EXPECT(global_propget_i);
1980 parse_script_a("testPropGet;");
1981 CHECK_CALLED(global_propget_d);
1982 CHECK_CALLED(global_propget_i);
1983
1984 SET_EXPECT(global_propput_d);
1985 SET_EXPECT(global_propput_i);
1986 parse_script_a("testPropPut = 1;");
1987 CHECK_CALLED(global_propput_d);
1988 CHECK_CALLED(global_propput_i);
1989
1990 SET_EXPECT(global_success_d);
1991 SET_EXPECT(global_success_i);
1992 parse_script_a("reportSuccess();");
1993 CHECK_CALLED(global_success_d);
1994 CHECK_CALLED(global_success_i);
1995
1996 SET_EXPECT(testobj_delete_test);
1997 parse_script_a("ok((delete testObj.deleteTest) === true, 'delete testObj.deleteTest did not return true');");
1998 CHECK_CALLED(testobj_delete_test);
1999
2000 SET_EXPECT(testobj_delete_nodelete);
2001 parse_script_a("ok((delete testObj.noDeleteTest) === false, 'delete testObj.noDeleteTest did not return false');");
2002 CHECK_CALLED(testobj_delete_nodelete);
2003
2004 SET_EXPECT(global_propdelete_d);
2005 SET_EXPECT(DeleteMemberByDispID);
2006 parse_script_a("ok((delete testPropDelete) === true, 'delete testPropDelete did not return true');");
2007 CHECK_CALLED(global_propdelete_d);
2008 CHECK_CALLED(DeleteMemberByDispID);
2009
2010 SET_EXPECT(global_nopropdelete_d);
2011 SET_EXPECT(DeleteMemberByDispID_false);
2012 parse_script_a("ok((delete testNoPropDelete) === false, 'delete testPropDelete did not return false');");
2013 CHECK_CALLED(global_nopropdelete_d);
2014 CHECK_CALLED(DeleteMemberByDispID_false);
2015
2016 SET_EXPECT(puredisp_prop_d);
2017 parse_script_a("ok((delete pureDisp.prop) === false, 'delete pureDisp.prop did not return true');");
2018 CHECK_CALLED(puredisp_prop_d);
2019
2020 SET_EXPECT(puredisp_noprop_d);
2021 parse_script_a("ok((delete pureDisp.noprop) === true, 'delete pureDisp.noprop did not return false');");
2022 CHECK_CALLED(puredisp_noprop_d);
2023
2024 SET_EXPECT(puredisp_value);
2025 parse_script_a("var t=pureDisp; t=t(false);");
2026 CHECK_CALLED(puredisp_value);
2027
2028 SET_EXPECT(puredisp_value);
2029 parse_script_a("var t = {func: pureDisp}; t = t.func(false);");
2030 CHECK_CALLED(puredisp_value);
2031
2032 SET_EXPECT(dispexfunc_value);
2033 parse_script_a("var t = dispexFunc; t = t(false);");
2034 CHECK_CALLED(dispexfunc_value);
2035
2036 SET_EXPECT(dispexfunc_value);
2037 parse_script_a("var t = {func: dispexFunc}; t = t.func(false);");
2038 CHECK_CALLED(dispexfunc_value);
2039
2040 parse_script_a("(function reportSuccess() {})()");
2041
2042 parse_script_a("ok(typeof(test) === 'object', \"typeof(test) != 'object'\");");
2043
2044 parse_script_a("function reportSuccess() {}; reportSuccess();");
2045
2046 SET_EXPECT(global_propget_d);
2047 parse_script_a("var testPropGet");
2048 CHECK_CALLED(global_propget_d);
2049
2050 SET_EXPECT(global_propget_d);
2051 parse_script_a("eval('var testPropGet;');");
2052 CHECK_CALLED(global_propget_d);
2053
2054 SET_EXPECT(global_notexists_d);
2055 parse_script_a("var notExists; notExists = 1;");
2056 CHECK_CALLED(global_notexists_d);
2057
2058 parse_script_a("function f() { var testPropGet; }");
2059 parse_script_a("(function () { var testPropGet; })();");
2060 parse_script_a("(function () { eval('var testPropGet;'); })();");
2061
2062 SET_EXPECT(invoke_func);
2063 parse_script_a("ok(propGetFunc() == 0, \"Incorrect propGetFunc value\");");
2064 CHECK_CALLED(invoke_func);
2065 parse_script_a("ok(propGetFunc(1) == 1, \"Incorrect propGetFunc value\");");
2066 parse_script_a("ok(propGetFunc(1, 2) == 2, \"Incorrect propGetFunc value\");");
2067 SET_EXPECT(invoke_func);
2068 parse_script_a("ok(propGetFunc().toString() == 0, \"Incorrect propGetFunc value\");");
2069 CHECK_CALLED(invoke_func);
2070 parse_script_a("ok(propGetFunc(1).toString() == 1, \"Incorrect propGetFunc value\");");
2071 SET_EXPECT(invoke_func);
2072 parse_script_a("propGetFunc(1);");
2073 CHECK_CALLED(invoke_func);
2074
2075 parse_script_a("objectFlag(1).toString();");
2076
2077 parse_script_a("(function() { var tmp = (function () { return testObj; })()(1);})();");
2078 parse_script_a("(function() { var tmp = (function () { return testObj; })()();})();");
2079
2080 parse_script_a("ok((testObj instanceof Object) === false, 'testObj is instance of Object');");
2081
2082 SET_EXPECT(testobj_prop_d);
2083 parse_script_a("ok(('prop' in testObj) === true, 'prop is not in testObj');");
2084 CHECK_CALLED(testobj_prop_d);
2085
2086 SET_EXPECT(testobj_noprop_d);
2087 parse_script_a("ok(('noprop' in testObj) === false, 'noprop is in testObj');");
2088 CHECK_CALLED(testobj_noprop_d);
2089
2090 SET_EXPECT(testobj_prop_d);
2091 parse_script_a("ok(Object.prototype.hasOwnProperty.call(testObj, 'prop') === true, 'hasOwnProperty(\\\"prop\\\") returned false');");
2092 CHECK_CALLED(testobj_prop_d);
2093
2094 SET_EXPECT(testobj_noprop_d);
2095 parse_script_a("ok(Object.prototype.hasOwnProperty.call(testObj, 'noprop') === false, 'hasOwnProperty(\\\"noprop\\\") returned true');");
2096 CHECK_CALLED(testobj_noprop_d);
2097
2098 SET_EXPECT(puredisp_prop_d);
2099 parse_script_a("ok(Object.prototype.hasOwnProperty.call(pureDisp, 'prop') === true, 'hasOwnProperty(\\\"noprop\\\") returned false');");
2100 CHECK_CALLED(puredisp_prop_d);
2101
2102 SET_EXPECT(puredisp_noprop_d);
2103 parse_script_a("ok(Object.prototype.hasOwnProperty.call(pureDisp, 'noprop') === false, 'hasOwnProperty(\\\"noprop\\\") returned true');");
2104 CHECK_CALLED(puredisp_noprop_d);
2105
2106 SET_EXPECT(testobj_value);
2107 parse_script_a("ok(String(testObj) === '1', 'wrong testObj value');");
2108 CHECK_CALLED(testobj_value);
2109
2110 SET_EXPECT(testobj_value);
2111 parse_script_a("ok(String.prototype.concat.call(testObj, ' OK') === '1 OK', 'wrong concat result');");
2112 CHECK_CALLED(testobj_value);
2113
2114 SET_EXPECT(global_propget_d);
2115 SET_EXPECT(global_propget_i);
2116 parse_script_a("this.testPropGet;");
2117 CHECK_CALLED(global_propget_d);
2118 CHECK_CALLED(global_propget_i);
2119
2120 SET_EXPECT(global_propget_d);
2121 SET_EXPECT(global_propget_i);
2122 parse_script_a("(function () { this.testPropGet; })();");
2123 CHECK_CALLED(global_propget_d);
2124 CHECK_CALLED(global_propget_i);
2125
2126 parse_script_a("testThis(this);");
2127 parse_script_a("(function () { testThis(this); })();");
2128 parse_script_a("function x() { testThis(this); }; x();");
2129 parse_script_a("var t = {func: function () { ok(this === t, 'this !== t'); }}; with(t) { func(); }");
2130 parse_script_a("function x() { testThis(this); }; with({y: 1}) { x(); }");
2131 parse_script_a("(function () { function x() { testThis(this);} x(); })();");
2132
2133 SET_EXPECT(testobj_onlydispid_d);
2134 SET_EXPECT(testobj_onlydispid_i);
2135 parse_script_a("ok(typeof(testObj.onlyDispID) === 'unknown', 'unexpected typeof(testObj.onlyDispID)');");
2136 CHECK_CALLED(testobj_onlydispid_d);
2137 CHECK_CALLED(testobj_onlydispid_i);
2138
2139 SET_EXPECT(global_propargput_d);
2140 SET_EXPECT(global_propargput_i);
2141 parse_script_a("var t=0; propArgPutG(t++, t++) = t++;");
2142 CHECK_CALLED(global_propargput_d);
2143 CHECK_CALLED(global_propargput_i);
2144
2145 SET_EXPECT(global_propargput_d);
2146 SET_EXPECT(global_propargput_i);
2147 parse_script_a("var t=0; test.propArgPutO(t++, t++) = t++;");
2148 CHECK_CALLED(global_propargput_d);
2149 CHECK_CALLED(global_propargput_i);
2150
2151 SET_EXPECT(global_testargtypes_i);
2152 parse_script_a("testArgTypes(dispUnk, intProp(), intProp, getShort(), shortProp, function(nullunk,d,i,s) {"
2153 " ok(getVT(i) === 'VT_I4', 'getVT(i) = ' + getVT(i));"
2154 " ok(getVT(s) === 'VT_I4', 'getVT(s) = ' + getVT(s));"
2155 " ok(getVT(d) === 'VT_DISPATCH', 'getVT(d) = ' + getVT(d));"
2156 " ok(getVT(nullunk) === 'VT_DISPATCH', 'getVT(nullunk) = ' + getVT(nullunk));"
2157 " ok(nullunk === null, 'nullunk !== null');"
2158 "});");
2159 CHECK_CALLED(global_testargtypes_i);
2160
2161 SET_EXPECT(testobj_withprop_d);
2162 SET_EXPECT(testobj_withprop_i);
2163 parse_script_a("var t = (function () { with(testObj) { return withProp; }})(); ok(t === 1, 't = ' + t);");
2164 CHECK_CALLED(testobj_withprop_d);
2165 CHECK_CALLED(testobj_withprop_i);
2166
2167 run_from_res("lang.js");
2168 run_from_res("api.js");
2169 run_from_res("regexp.js");
2170 run_from_res("cc.js");
2171
2172 test_isvisible(FALSE);
2173 test_isvisible(TRUE);
2174
2175 parse_script_af(0, "test.testThis2(this);");
2176 parse_script_af(0, "(function () { test.testThis2(this); })();");
2177
2178 hres = parse_htmlscript_a("<!--");
2179 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2180 hres = parse_htmlscript_a("-->");
2181 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2182 hres = parse_htmlscript_a("<!--\nvar a=1;\n-->\n");
2183 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2184 hres = parse_htmlscript_a("<!--\n<!-- ignore this\n-->\n");
2185 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2186 hres = parse_htmlscript_a("var a=1;\nif(a-->0) a=5;\n");
2187 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2188 hres = parse_htmlscript_a("var a=1;\nif(a\n-->0) a=5;\n");
2189 ok(hres != S_OK, "ParseScriptText have not failed\n");
2190
2191 test_script_exprs();
2192
2193 parse_script_with_error_a(
2194 "?",
2195 0x800a03ea, 0, 0,
2196 "Microsoft JScript compilation error",
2197 "Syntax error",
2198 "?");
2199
2200 parse_script_with_error_a(
2201 "var a=1;\nif(a\n-->0) a=5;\n",
2202 0x800a03ee, 2, 0,
2203 "Microsoft JScript compilation error",
2204 "Expected ')'",
2205 "-->0) a=5;");
2206
2207 parse_script_with_error_a(
2208 "new 3;",
2209 0x800a01bd, 0, 0,
2210 "Microsoft JScript runtime error",
2211 "Object doesn't support this action",
2212 NULL);
2213
2214 parse_script_with_error_a(
2215 "new null;",
2216 0x800a138f, 0, 0,
2217 "Microsoft JScript runtime error",
2218 "Object expected",
2219 NULL);
2220
2221 parse_script_with_error_a(
2222 "var a;\nnew null;",
2223 0x800a138f, 1, 0,
2224 "Microsoft JScript runtime error",
2225 "Object expected",
2226 NULL);
2227
2228 parse_script_with_error_a(
2229 "var a; new null;",
2230 0x800a138f, 0, 7,
2231 "Microsoft JScript runtime error",
2232 "Object expected",
2233 NULL);
2234
2235 return TRUE;
2236 }
2237
2238 static void test_parse_proc(void)
2239 {
2240 VARIANT args[2];
2241 DISPPARAMS dp = {args};
2242
2243 dp.cArgs = 0;
2244 invoke_procedure(NULL, "return true;", &dp);
2245
2246 dp.cArgs = 1;
2247 V_VT(args) = VT_EMPTY;
2248 invoke_procedure(NULL, "return arguments.length == 1;", &dp);
2249
2250 V_VT(args) = VT_BOOL;
2251 V_BOOL(args) = VARIANT_TRUE;
2252 invoke_procedure(" x ", "return x;", &dp);
2253
2254 dp.cArgs = 2;
2255 V_VT(args) = VT_I4;
2256 V_I4(args) = 2;
2257 V_VT(args+1) = VT_I4;
2258 V_I4(args+1) = 1;
2259 invoke_procedure(" _x1 , y_2", "return _x1 === 1 && y_2 === 2;", &dp);
2260 }
2261
2262 static void run_encoded_tests(void)
2263 {
2264 BSTR src;
2265 HRESULT hres;
2266
2267 engine_clsid = &CLSID_JScriptEncode;
2268
2269 SET_EXPECT(global_success_d);
2270 SET_EXPECT(global_success_i);
2271 /* |reportSuccess(); | */
2272 parse_script_a("#@~^EAAAAA==.\x7fwGMYUEm1+kd`*iAQYAAA==^#~@");
2273 CHECK_CALLED(global_success_d);
2274 CHECK_CALLED(global_success_i);
2275
2276 SET_EXPECT(global_success_d);
2277 SET_EXPECT(global_success_i);
2278 parse_script_a("reportSuccess();");
2279 CHECK_CALLED(global_success_d);
2280 CHECK_CALLED(global_success_i);
2281
2282 SET_EXPECT(global_success_d);
2283 SET_EXPECT(global_success_i);
2284 /* |Success | */
2285 parse_script_a("report#@~^BwAAAA==j!m^\x7f/k2QIAAA==^#~@();");
2286 CHECK_CALLED(global_success_d);
2287 CHECK_CALLED(global_success_i);
2288
2289 SET_EXPECT(global_success_d);
2290 SET_EXPECT(global_success_i);
2291 /* |\r\n\treportSuccess();\r\n | */
2292 parse_script_a("#@~^GQAAAA==@#@&d.\x7fwKDYUE1^+k/c#p@#@&OAYAAA==^#~@");
2293 CHECK_CALLED(global_success_d);
2294 CHECK_CALLED(global_success_i);
2295
2296 /* v */
2297 src = a2bstr("#@~^EAA*AA==.\x7fwGMYUEm1+kd`*iAQYAAA==^#~@");
2298 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src);
2299 SysFreeString(src);
2300 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres);
2301
2302 /* vv */
2303 src = a2bstr("#@~^EAAAAAAA==.\x7fwGMYUEm1+kd`*iAQYAAA==^#~@");
2304 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src);
2305 SysFreeString(src);
2306 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres);
2307
2308 /* v */
2309 src = a2bstr("#@~^EAAAAA^=.\x7fwGMYUEm1+kd`*iAQYAAA==^#~@");
2310 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src);
2311 SysFreeString(src);
2312 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres);
2313
2314 /* v */
2315 src = a2bstr("#@~^EAAAAA==.\x7fwGMYUEm1ekd`*iAQYAAA==^#~@");
2316 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src);
2317 SysFreeString(src);
2318 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres);
2319
2320 /* vv */
2321 src = a2bstr("#@~^EAAAAA==.\x7fwGMYUEm1+kd`*iAQYAAA==^~#@");
2322 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src);
2323 SysFreeString(src);
2324 ok(hres == JS_E_INVALID_CHAR, "parse_script failed %08x\n", hres);
2325 }
2326
2327 static void run_benchmark(const char *script_name)
2328 {
2329 IActiveScriptParse *parser;
2330 IActiveScript *engine;
2331 ULONG start, end;
2332 BSTR src;
2333 HRESULT hres;
2334
2335 engine = create_script();
2336 if(!engine)
2337 return;
2338
2339 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
2340 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
2341 if (FAILED(hres)) {
2342 IActiveScript_Release(engine);
2343 return;
2344 }
2345
2346 hres = IActiveScriptParse_InitNew(parser);
2347 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
2348
2349 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
2350 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
2351
2352 hres = IActiveScript_AddNamedItem(engine, testW,
2353 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE);
2354 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
2355
2356 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
2357 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
2358
2359 src = load_res(script_name);
2360
2361 start = GetTickCount();
2362 hres = IActiveScriptParse_ParseScriptText(parser, src, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2363 end = GetTickCount();
2364 ok(hres == S_OK, "%s: ParseScriptText failed: %08x\n", script_name, hres);
2365
2366 trace("%s ran in %u ms\n", script_name, end-start);
2367
2368 IActiveScript_Release(engine);
2369 IActiveScriptParse_Release(parser);
2370 SysFreeString(src);
2371 }
2372
2373 static void run_benchmarks(void)
2374 {
2375 trace("Running benchmarks...\n");
2376
2377 run_benchmark("dna.js");
2378 run_benchmark("base64.js");
2379 run_benchmark("validateinput.js");
2380 }
2381
2382 static BOOL check_jscript(void)
2383 {
2384 IActiveScriptProperty *script_prop;
2385 BSTR str;
2386 HRESULT hres;
2387
2388 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2389 &IID_IActiveScriptProperty, (void**)&script_prop);
2390 if(FAILED(hres))
2391 return FALSE;
2392 IActiveScriptProperty_Release(script_prop);
2393
2394 str = a2bstr("if(!('localeCompare' in String.prototype)) throw 1;");
2395 hres = parse_script(0, str);
2396 SysFreeString(str);
2397
2398 return hres == S_OK;
2399 }
2400
2401 START_TEST(run)
2402 {
2403 int argc;
2404 char **argv;
2405
2406 argc = winetest_get_mainargs(&argv);
2407
2408 CoInitialize(NULL);
2409
2410 if(!check_jscript()) {
2411 win_skip("Broken engine, probably too old\n");
2412 }else if(argc > 2) {
2413 invoke_version = 2;
2414 run_from_file(argv[2]);
2415 }else {
2416 trace("invoke version 0\n");
2417 invoke_version = 0;
2418 run_tests();
2419
2420 trace("invoke version 2\n");
2421 invoke_version = 2;
2422 if(run_tests()) {
2423 trace("JSctipt.Encode tests...\n");
2424 run_encoded_tests();
2425 trace("ParseProcedureText tests...\n");
2426 test_parse_proc();
2427 }
2428
2429 if(winetest_interactive)
2430 run_benchmarks();
2431 }
2432
2433 CoUninitialize();
2434 }