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