[VBSCRIPT_WINETEST] Sync with Wine Staging 1.7.37. CORE-9246
[reactos.git] / rostests / winetests / vbscript / run.c
1 /*
2 * Copyright 2011 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 #include <stdio.h>
20
21 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_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 <vbsregexp55.h>
36
37 #include <wine/test.h>
38
39 #ifdef _WIN64
40
41 #define IActiveScriptParse_QueryInterface IActiveScriptParse64_QueryInterface
42 #define IActiveScriptParse_Release IActiveScriptParse64_Release
43 #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
44 #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
45 #define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_64_Release
46 #define IActiveScriptParseProcedure2_ParseProcedureText IActiveScriptParseProcedure2_64_ParseProcedureText
47
48 #else
49
50 #define IActiveScriptParse_QueryInterface IActiveScriptParse32_QueryInterface
51 #define IActiveScriptParse_Release IActiveScriptParse32_Release
52 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
53 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
54 #define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_32_Release
55 #define IActiveScriptParseProcedure2_ParseProcedureText IActiveScriptParseProcedure2_32_ParseProcedureText
56
57 #endif
58
59 extern const CLSID CLSID_VBScript;
60 extern const CLSID CLSID_VBScriptRegExp;
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 CLEAR_CALLED(func) \
87 expect_ ## func = called_ ## func = FALSE
88
89 DEFINE_EXPECT(global_success_d);
90 DEFINE_EXPECT(global_success_i);
91 DEFINE_EXPECT(global_vbvar_d);
92 DEFINE_EXPECT(global_vbvar_i);
93 DEFINE_EXPECT(testobj_propget_d);
94 DEFINE_EXPECT(testobj_propget_i);
95 DEFINE_EXPECT(testobj_propput_d);
96 DEFINE_EXPECT(testobj_propput_i);
97 DEFINE_EXPECT(testobj_value_i);
98 DEFINE_EXPECT(global_propargput_d);
99 DEFINE_EXPECT(global_propargput_i);
100 DEFINE_EXPECT(global_propargput1_d);
101 DEFINE_EXPECT(global_propargput1_i);
102 DEFINE_EXPECT(global_testoptionalarg_i);
103 DEFINE_EXPECT(collectionobj_newenum_i);
104 DEFINE_EXPECT(Next);
105 DEFINE_EXPECT(GetWindow);
106 DEFINE_EXPECT(GetUIBehavior);
107 DEFINE_EXPECT(EnableModeless);
108
109 #define DISPID_GLOBAL_REPORTSUCCESS 1000
110 #define DISPID_GLOBAL_TRACE 1001
111 #define DISPID_GLOBAL_OK 1002
112 #define DISPID_GLOBAL_GETVT 1003
113 #define DISPID_GLOBAL_ISENGLANG 1004
114 #define DISPID_GLOBAL_VBVAR 1005
115 #define DISPID_GLOBAL_TESTOBJ 1006
116 #define DISPID_GLOBAL_ISNULLDISP 1007
117 #define DISPID_GLOBAL_TESTDISP 1008
118 #define DISPID_GLOBAL_REFOBJ 1009
119 #define DISPID_GLOBAL_COUNTER 1010
120 #define DISPID_GLOBAL_PROPARGPUT 1011
121 #define DISPID_GLOBAL_PROPARGPUT1 1012
122 #define DISPID_GLOBAL_COLLOBJ 1013
123 #define DISPID_GLOBAL_DOUBLEASSTRING 1014
124 #define DISPID_GLOBAL_TESTARRAY 1015
125 #define DISPID_GLOBAL_THROWINT 1016
126 #define DISPID_GLOBAL_TESTOPTIONALARG 1017
127
128 #define DISPID_TESTOBJ_PROPGET 2000
129 #define DISPID_TESTOBJ_PROPPUT 2001
130
131 #define DISPID_COLLOBJ_RESET 3000
132
133 #define FACILITY_VBS 0xa
134 #define MAKE_VBSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_VBS, code)
135
136 static const WCHAR testW[] = {'t','e','s','t',0};
137 static const WCHAR emptyW[] = {0};
138
139 static BOOL strict_dispid_check, is_english, allow_ui;
140 static const char *test_name = "(null)";
141 static int test_counter;
142 static SCRIPTUICHANDLING uic_handling = SCRIPTUICHANDLING_NOUIERROR;
143
144 static BSTR a2bstr(const char *str)
145 {
146 BSTR ret;
147 int len;
148
149 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
150 ret = SysAllocStringLen(NULL, len-1);
151 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
152
153 return ret;
154 }
155
156 static int strcmp_wa(LPCWSTR strw, const char *stra)
157 {
158 CHAR buf[512];
159 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
160 return lstrcmpA(buf, stra);
161 }
162
163 static const char *vt2a(VARIANT *v)
164 {
165 if(V_VT(v) == (VT_BYREF|VT_VARIANT)) {
166 static char buf[64];
167 sprintf(buf, "%s*", vt2a(V_BYREF(v)));
168 return buf;
169 }
170
171 switch(V_VT(v)) {
172 case VT_EMPTY:
173 return "VT_EMPTY";
174 case VT_NULL:
175 return "VT_NULL";
176 case VT_I2:
177 return "VT_I2";
178 case VT_I4:
179 return "VT_I4";
180 case VT_R4:
181 return "VT_R4";
182 case VT_R8:
183 return "VT_R8";
184 case VT_CY:
185 return "VT_CY";
186 case VT_DATE:
187 return "VT_DATE";
188 case VT_BSTR:
189 return "VT_BSTR";
190 case VT_DISPATCH:
191 return "VT_DISPATCH";
192 case VT_BOOL:
193 return "VT_BOOL";
194 case VT_ARRAY|VT_VARIANT:
195 return "VT_ARRAY|VT_VARIANT";
196 case VT_ARRAY|VT_BYREF|VT_VARIANT:
197 return "VT_ARRAY|VT_BYREF|VT_VARIANT";
198 case VT_UI1:
199 return "VT_UI1";
200 default:
201 ok(0, "unknown vt %d\n", V_VT(v));
202 return NULL;
203 }
204 }
205
206 /* Returns true if the user interface is in English. Note that this does not
207 * presume of the formatting of dates, numbers, etc.
208 */
209 static BOOL is_lang_english(void)
210 {
211 static HMODULE hkernel32 = NULL;
212 static LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL;
213 static LANGID (WINAPI *pGetUserDefaultUILanguage)(void) = NULL;
214
215 if (!hkernel32)
216 {
217 hkernel32 = GetModuleHandleA("kernel32.dll");
218 pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
219 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
220 }
221 if (pGetThreadUILanguage && PRIMARYLANGID(pGetThreadUILanguage()) != LANG_ENGLISH)
222 return FALSE;
223 if (pGetUserDefaultUILanguage && PRIMARYLANGID(pGetUserDefaultUILanguage()) != LANG_ENGLISH)
224 return FALSE;
225
226 return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
227 }
228
229 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
230 {
231 ok(0, "unexpected call\n");
232 return E_NOINTERFACE;
233 }
234
235 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
236 {
237 return 2;
238 }
239
240 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
241 {
242 return 1;
243 }
244
245 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
246 REFIID riid, void **ppv)
247 {
248 ok(0, "unexpected service %s\n", wine_dbgstr_guid(guidService));
249 return E_NOINTERFACE;
250 }
251
252 static const IServiceProviderVtbl ServiceProviderVtbl = {
253 ServiceProvider_QueryInterface,
254 ServiceProvider_AddRef,
255 ServiceProvider_Release,
256 ServiceProvider_QueryService
257 };
258
259 static IServiceProvider caller_sp = { &ServiceProviderVtbl };
260
261 static void test_disp(IDispatch *disp)
262 {
263 DISPID id, public_prop_id, public_prop2_id, public_func_id, public_sub_id, defvalget_id, gs_getter_id;
264 DISPID named_args[5] = {DISPID_PROPERTYPUT};
265 VARIANT v, args[5];
266 DISPPARAMS dp = {args, named_args};
267 IDispatchEx *dispex;
268 EXCEPINFO ei = {0};
269 BSTR str;
270 HRESULT hres;
271
272 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
273 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
274
275 str = a2bstr("publicProp");
276 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_prop_id);
277 SysFreeString(str);
278 ok(hres == S_OK, "GetDispID(publicProp) failed: %08x\n", hres);
279
280 str = a2bstr("PUBLICPROP");
281 hres = IDispatchEx_GetDispID(dispex, str, 0, &id);
282 SysFreeString(str);
283 ok(hres == S_OK, "GetDispID(PUBLICPROP) failed: %08x\n", hres);
284 ok(public_prop_id == id, "id = %d\n", public_prop_id);
285
286 str = a2bstr("publicPROP2");
287 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_prop2_id);
288 SysFreeString(str);
289 ok(hres == S_OK, "GetDispID(publicProp2) failed: %08x\n", hres);
290
291 str = a2bstr("defValGet");
292 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &defvalget_id);
293 SysFreeString(str);
294 ok(hres == S_OK, "GetDispID(defValGet) failed: %08x\n", hres);
295 ok(defvalget_id == DISPID_VALUE, "id = %d\n", defvalget_id);
296
297 str = a2bstr("privateProp");
298 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &id);
299 SysFreeString(str);
300 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateProp) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
301 ok(id == -1, "id = %d\n", id);
302
303 str = a2bstr("class_initialize");
304 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &id);
305 SysFreeString(str);
306 ok(hres == S_OK, "GetDispID(publicProp2) failed: %08x\n", hres);
307
308 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
309 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
310 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
311
312 V_VT(args) = VT_BOOL;
313 V_BOOL(args) = VARIANT_TRUE;
314 dp.cArgs = dp.cNamedArgs = 1;
315 V_VT(&v) = VT_BOOL;
316 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYPUT, &dp, &v, &ei, NULL);
317 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
318 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
319
320 dp.cArgs = dp.cNamedArgs = 0;
321 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
322 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
323 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
324 ok(V_BOOL(&v), "V_BOOL(v) = %x\n", V_BOOL(&v));
325
326 dp.cArgs = dp.cNamedArgs = 0;
327 hres = IDispatchEx_Invoke(dispex, public_prop_id, &IID_NULL, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
328 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
329 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
330 ok(V_BOOL(&v), "V_BOOL(v) = %x\n", V_BOOL(&v));
331
332 dp.cArgs = dp.cNamedArgs = 0;
333 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
334 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
335 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
336 ok(V_BOOL(&v), "V_BOOL(v) = %x\n", V_BOOL(&v));
337
338 dp.cArgs = 1;
339 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
340 ok(hres == DISP_E_MEMBERNOTFOUND, "InvokeEx failed: %08x, expected DISP_E_MEMBERNOTFOUND\n", hres);
341 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
342
343 V_VT(args) = VT_BOOL;
344 V_BOOL(args) = VARIANT_FALSE;
345 dp.cArgs = 1;
346 V_VT(&v) = VT_BOOL;
347 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYPUT, &dp, NULL, &ei, NULL);
348 ok(hres == DISP_E_PARAMNOTOPTIONAL, "InvokeEx failed: %08x, expected DISP_E_PARAMNOTOPTIONAL\n", hres);
349
350 str = a2bstr("publicFunction");
351 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_func_id);
352 SysFreeString(str);
353 ok(hres == S_OK, "GetDispID(publicFunction) failed: %08x\n", hres);
354 ok(public_func_id != -1, "public_func_id = -1\n");
355
356 str = a2bstr("publicSub");
357 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_sub_id);
358 SysFreeString(str);
359 ok(hres == S_OK, "GetDispID(publicSub) failed: %08x\n", hres);
360 ok(public_sub_id != -1, "public_func_id = -1\n");
361
362 dp.cArgs = dp.cNamedArgs = 0;
363 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
364 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
365 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
366 ok(V_I2(&v) == 4, "V_I2(v) = %d\n", V_I2(&v));
367
368 dp.cArgs = dp.cNamedArgs = 0;
369 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
370 ok(hres == DISP_E_MEMBERNOTFOUND, "InvokeEx failed: %08x, expected DISP_E_MEMBERNOTFOUND\n", hres);
371 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
372
373 dp.cArgs = dp.cNamedArgs = 0;
374 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
375 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
376 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
377 ok(V_I2(&v) == 4, "V_I2(v) = %d\n", V_I2(&v));
378
379 dp.cArgs = dp.cNamedArgs = 0;
380 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
381 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
382 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
383
384 dp.cArgs = dp.cNamedArgs = 0;
385 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
386 ok(hres == DISP_E_MEMBERNOTFOUND, "InvokeEx failed: %08x, expected DISP_E_MEMBERNOTFOUND\n", hres);
387 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
388
389 dp.cArgs = dp.cNamedArgs = 0;
390 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
391 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
392 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
393
394 V_VT(args) = VT_BOOL;
395 V_BOOL(args) = VARIANT_TRUE;
396 dp.cArgs = dp.cNamedArgs = 1;
397 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_PROPERTYPUT, &dp, NULL, &ei, NULL);
398 ok(FAILED(hres), "InvokeEx succeeded: %08x\n", hres);
399
400 dp.cArgs = dp.cNamedArgs = 0;
401 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
402 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
403 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
404 ok(V_I2(&v) == 4, "V_I2(v) = %d\n", V_I2(&v));
405
406 dp.cArgs = dp.cNamedArgs = 0;
407 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
408 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
409 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
410 ok(V_I2(&v) == 4, "V_I2(v) = %d\n", V_I2(&v));
411
412 dp.cArgs = dp.cNamedArgs = 0;
413 hres = IDispatchEx_Invoke(dispex, public_func_id, &IID_NULL, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
414 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
415 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
416 ok(V_I2(&v) == 4, "V_I2(v) = %d\n", V_I2(&v));
417
418 dp.cArgs = dp.cNamedArgs = 0;
419 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
420 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
421 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
422
423 dp.cArgs = dp.cNamedArgs = 0;
424 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
425 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
426 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
427
428 str = a2bstr("privateSub");
429 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &id);
430 SysFreeString(str);
431 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateSub) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
432 ok(id == -1, "id = %d\n", id);
433
434 str = a2bstr("dynprop");
435 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive|fdexNameEnsure, &id);
436 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateProp) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
437 ok(id == -1, "id = %d\n", id);
438 hres = IDispatchEx_GetDispID(dispex, str, fdexNameEnsure, &id);
439 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateProp) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
440 ok(id == -1, "id = %d\n", id);
441 SysFreeString(str);
442
443 str = a2bstr("publicProp");
444 hres = IDispatchEx_GetDispID(dispex, str, 0x80000000|fdexNameCaseInsensitive, &public_prop_id);
445 SysFreeString(str);
446 ok(hres == S_OK, "GetDispID(publicProp) failed: %08x\n", hres);
447
448 id = 0xdeadbeef;
449 str = a2bstr("publicProp");
450 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
451 SysFreeString(str);
452 ok(hres == S_OK, "GetDispID(publicProp) failed: %08x\n", hres);
453 ok(id == public_prop_id, "id = %d, expected %d\n", id, public_prop_id);
454
455 id = 0xdeadbeef;
456 str = a2bstr("publicprop");
457 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
458 SysFreeString(str);
459 ok(hres == S_OK, "GetDispID(publicProp) failed: %08x\n", hres);
460 ok(id == public_prop_id, "id = %d, expected %d\n", id, public_prop_id);
461
462 str = a2bstr("gsGetProp");
463 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &gs_getter_id);
464 SysFreeString(str);
465 ok(hres == S_OK, "GetDispID(publicFunction) failed: %08x\n", hres);
466 ok(gs_getter_id != -1, "gs_getter_id = -1\n");
467
468 V_VT(args) = VT_BOOL;
469 V_BOOL(args) = VARIANT_TRUE;
470 dp.cNamedArgs = 0;
471 dp.cArgs = 1;
472 V_VT(&v) = VT_I8;
473 hres = IDispatchEx_InvokeEx(dispex, gs_getter_id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
474 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
475 ok(V_VT(&v) == VT_BOOL && V_BOOL(&v), "V_VT(v) = %d\n", V_VT(&v));
476
477 hres = IDispatchEx_InvokeEx(dispex, gs_getter_id, 0, DISPATCH_PROPERTYGET, &dp, NULL, &ei, NULL);
478 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
479
480 V_VT(args) = VT_BOOL;
481 V_BOOL(args) = VARIANT_FALSE;
482 dp.cArgs = 1;
483 V_VT(&v) = VT_I8;
484 hres = IDispatchEx_InvokeEx(dispex, gs_getter_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
485 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
486 ok(V_VT(&v) == VT_BOOL && !V_BOOL(&v), "V_VT(v) = %d\n", V_VT(&v));
487
488 V_VT(args) = VT_BOOL;
489 V_BOOL(args) = VARIANT_TRUE;
490 V_VT(&v) = VT_I8;
491 dp.cArgs = 1;
492 hres = IDispatchEx_InvokeEx(dispex, gs_getter_id, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
493 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
494 ok(V_VT(&v) == VT_BOOL && V_BOOL(&v), "V_VT(v) = %d\n", V_VT(&v));
495
496 IDispatchEx_Release(dispex);
497 }
498
499 static void test_safearray(SAFEARRAY *safearray, unsigned indims)
500 {
501 int i, exdims = indims;
502
503 if(!exdims)
504 exdims = 1;
505 ok(safearray->cDims == exdims, "safearray->cDims = %d, expected %d\n", safearray->cDims, exdims);
506 todo_wine
507 ok(safearray->fFeatures == (FADF_VARIANT|FADF_HAVEVARTYPE|FADF_FIXEDSIZE|FADF_STATIC),
508 "safearray->fFeatures = %x\n", safearray->fFeatures);
509 ok(safearray->cbElements == sizeof(VARIANT), "safearray->cbElements = %x\n", safearray->cbElements);
510 ok(!safearray->cLocks, "safearray->cLocks = %x\n", safearray->cLocks);
511
512 for(i=0; i < safearray->cDims; i++) {
513 ok(safearray->rgsabound[i].cElements == indims ? i+4 : 1, "safearray->rgsabound[%d].cElements = %d\n", i,
514 safearray->rgsabound[i].cElements);
515 ok(!safearray->rgsabound[i].lLbound, "safearray->rgsabound[%d].lLbound = %d\n", i, safearray->rgsabound[i].lLbound);
516 }
517 }
518
519 #define test_grfdex(a,b) _test_grfdex(__LINE__,a,b)
520 static void _test_grfdex(unsigned line, DWORD grfdex, DWORD expect)
521 {
522 ok_(__FILE__,line)(grfdex == expect, "grfdex = %x, expected %x\n", grfdex, expect);
523 }
524
525 static IDispatchEx enumDisp;
526
527 static HRESULT WINAPI EnumVARIANT_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv)
528 {
529 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IEnumVARIANT)) {
530 *ppv = iface;
531 return S_OK;
532 }
533
534 if(IsEqualGUID(riid, &IID_IDispatch)) {
535 *ppv = &enumDisp;
536 return S_OK;
537 }
538
539 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid));
540 return E_NOINTERFACE;
541 }
542
543 static ULONG WINAPI EnumVARIANT_AddRef(IEnumVARIANT *iface)
544 {
545 return 2;
546 }
547
548 static ULONG WINAPI EnumVARIANT_Release(IEnumVARIANT *iface)
549 {
550 return 1;
551 }
552
553 static unsigned next_cnt;
554
555 static HRESULT WINAPI EnumVARIANT_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
556 {
557 if(strict_dispid_check)
558 CHECK_EXPECT2(Next);
559
560 ok(celt == 1, "celt = %d\n", celt);
561 ok(V_VT(rgVar) == VT_EMPTY, "V_VT(rgVar) = %d\n", V_VT(rgVar));
562 ok(!pCeltFetched, "pCeltFetched = %p\n", pCeltFetched);
563
564 if(next_cnt++ < 3) {
565 V_VT(rgVar) = VT_I2;
566 V_I2(rgVar) = next_cnt;
567 return S_OK;
568 }
569
570 return S_FALSE;
571 }
572
573 static HRESULT WINAPI EnumVARIANT_Skip(IEnumVARIANT *iface, ULONG celt)
574 {
575 ok(0, "unexpected call\n");
576 return E_NOTIMPL;
577 }
578
579 static HRESULT WINAPI EnumVARIANT_Reset(IEnumVARIANT *iface)
580 {
581 ok(0, "unexpected call\n");
582 return E_NOTIMPL;
583 }
584
585 static HRESULT WINAPI EnumVARIANT_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum)
586 {
587 ok(0, "unexpected call\n");
588 return E_NOTIMPL;
589 }
590
591 static const IEnumVARIANTVtbl EnumVARIANTVtbl = {
592 EnumVARIANT_QueryInterface,
593 EnumVARIANT_AddRef,
594 EnumVARIANT_Release,
595 EnumVARIANT_Next,
596 EnumVARIANT_Skip,
597 EnumVARIANT_Reset,
598 EnumVARIANT_Clone
599 };
600
601 static IEnumVARIANT enumObj = { &EnumVARIANTVtbl };
602
603 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
604 {
605 *ppv = NULL;
606
607 if(IsEqualGUID(riid, &IID_IUnknown)
608 || IsEqualGUID(riid, &IID_IDispatch)
609 || IsEqualGUID(riid, &IID_IDispatchEx))
610 *ppv = iface;
611 else {
612 trace("QI %s\n", wine_dbgstr_guid(riid));
613 return E_NOINTERFACE;
614 }
615
616 IUnknown_AddRef((IUnknown*)*ppv);
617 return S_OK;
618 }
619
620 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
621 {
622 return 2;
623 }
624
625 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
626 {
627 return 1;
628 }
629
630 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
631 {
632 ok(0, "unexpected call\n");
633 return E_NOTIMPL;
634 }
635
636 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
637 LCID lcid, ITypeInfo **ppTInfo)
638 {
639 ok(0, "unexpected call\n");
640 return E_NOTIMPL;
641 }
642
643 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
644 LPOLESTR *rgszNames, UINT cNames,
645 LCID lcid, DISPID *rgDispId)
646 {
647 ok(0, "unexpected call\n");
648 return E_NOTIMPL;
649 }
650
651 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
652 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
653 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
654 {
655 ok(0, "unexpected call\n");
656 return E_NOTIMPL;
657 }
658
659 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
660 {
661 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
662 return E_NOTIMPL;
663 }
664
665 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
666 {
667 ok(0, "unexpected call\n");
668 return E_NOTIMPL;
669 }
670
671 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
672 {
673 ok(0, "unexpected call\n");
674 return E_NOTIMPL;
675 }
676
677 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
678 {
679 ok(0, "unexpected call\n");
680 return E_NOTIMPL;
681 }
682
683 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
684 {
685 ok(0, "unexpected call\n");
686 return E_NOTIMPL;
687 }
688
689 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
690 {
691 ok(0, "unexpected call\n");
692 return E_NOTIMPL;
693 }
694
695 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
696 {
697 ok(0, "unexpected call\n");
698 return E_NOTIMPL;
699 }
700
701 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
702 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
703 {
704 ok(0, "unexpected call %d\n", id);
705 return E_NOTIMPL;
706 }
707
708 static HRESULT WINAPI testObj_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
709 {
710 if(!strcmp_wa(bstrName, "propget")) {
711 CHECK_EXPECT(testobj_propget_d);
712 test_grfdex(grfdex, fdexNameCaseInsensitive);
713 *pid = DISPID_TESTOBJ_PROPGET;
714 return S_OK;
715 }
716 if(!strcmp_wa(bstrName, "propput")) {
717 CHECK_EXPECT(testobj_propput_d);
718 test_grfdex(grfdex, fdexNameCaseInsensitive);
719 *pid = DISPID_TESTOBJ_PROPPUT;
720 return S_OK;
721 }
722
723 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
724 return DISP_E_UNKNOWNNAME;
725 }
726
727 static HRESULT WINAPI testObj_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
728 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
729 {
730 switch(id) {
731 case DISPID_VALUE: {
732 VARIANT *arg;
733 int i;
734
735 CHECK_EXPECT(testobj_value_i);
736
737 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
738 ok(pdp != NULL, "pdp == NULL\n");
739 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
740 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
741 ok(pvarRes != NULL, "pvarRes == NULL\n");
742 ok(pei != NULL, "pei == NULL\n");
743
744 for(i=0; i<pdp->cArgs; i++) {
745 arg = pdp->rgvarg+pdp->cArgs-i-1;
746 ok(V_VT(arg) == VT_I2, "V_VT(arg) = %d\n", V_VT(arg));
747 ok(V_I2(arg) == i+1, "V_I2(arg) = %d\n", V_I2(arg));
748 }
749
750 V_VT(pvarRes) = VT_I2;
751 V_I2(pvarRes) = pdp->cArgs;
752 return S_OK;
753 }
754 case DISPID_TESTOBJ_PROPGET:
755 CHECK_EXPECT(testobj_propget_i);
756
757 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
758 ok(pdp != NULL, "pdp == NULL\n");
759 ok(!pdp->rgvarg, "rgvarg == NULL\n");
760 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
761 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
762 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
763 ok(pvarRes != NULL, "pvarRes == NULL\n");
764 ok(pei != NULL, "pei == NULL\n");
765
766 V_VT(pvarRes) = VT_I2;
767 V_I2(pvarRes) = 10;
768 return S_OK;
769 case DISPID_TESTOBJ_PROPPUT:
770 CHECK_EXPECT(testobj_propput_i);
771
772 ok(wFlags == DISPATCH_PROPERTYPUT, "wFlags = %x\n", wFlags);
773 ok(pdp != NULL, "pdp == NULL\n");
774 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
775 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
776 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
777 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
778 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
779 ok(!pvarRes, "pvarRes != NULL\n");
780 ok(pei != NULL, "pei == NULL\n");
781
782 ok(V_VT(pdp->rgvarg) == VT_I2, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
783 ok(V_I2(pdp->rgvarg) == 1, "V_I2(psp->rgvargs) = %d\n", V_I2(pdp->rgvarg));
784 return S_OK;
785 }
786
787 ok(0, "unexpected call %d\n", id);
788 return E_FAIL;
789 }
790
791 static IDispatchExVtbl testObjVtbl = {
792 DispatchEx_QueryInterface,
793 DispatchEx_AddRef,
794 DispatchEx_Release,
795 DispatchEx_GetTypeInfoCount,
796 DispatchEx_GetTypeInfo,
797 DispatchEx_GetIDsOfNames,
798 DispatchEx_Invoke,
799 testObj_GetDispID,
800 testObj_InvokeEx,
801 DispatchEx_DeleteMemberByName,
802 DispatchEx_DeleteMemberByDispID,
803 DispatchEx_GetMemberProperties,
804 DispatchEx_GetMemberName,
805 DispatchEx_GetNextDispID,
806 DispatchEx_GetNameSpaceParent
807 };
808
809 static IDispatchEx testObj = { &testObjVtbl };
810
811 static HRESULT WINAPI enumDisp_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
812 {
813 return IEnumVARIANT_QueryInterface(&enumObj, riid, ppv);
814 }
815
816 static IDispatchExVtbl enumDispVtbl = {
817 enumDisp_QueryInterface,
818 DispatchEx_AddRef,
819 DispatchEx_Release,
820 DispatchEx_GetTypeInfoCount,
821 DispatchEx_GetTypeInfo,
822 DispatchEx_GetIDsOfNames,
823 DispatchEx_Invoke,
824 DispatchEx_GetDispID,
825 DispatchEx_InvokeEx,
826 DispatchEx_DeleteMemberByName,
827 DispatchEx_DeleteMemberByDispID,
828 DispatchEx_GetMemberProperties,
829 DispatchEx_GetMemberName,
830 DispatchEx_GetNextDispID,
831 DispatchEx_GetNameSpaceParent
832 };
833
834 static IDispatchEx enumDisp = { &enumDispVtbl };
835
836 static HRESULT WINAPI collectionObj_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
837 {
838 if(!strcmp_wa(bstrName, "reset")) {
839 *pid = DISPID_COLLOBJ_RESET;
840 return S_OK;
841 }
842
843 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
844 return DISP_E_UNKNOWNNAME;
845 }
846
847 static HRESULT WINAPI collectionObj_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
848 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
849 {
850 switch(id) {
851 case DISPID_NEWENUM:
852 if(strict_dispid_check)
853 CHECK_EXPECT(collectionobj_newenum_i);
854
855 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
856 ok(pdp != NULL, "pdp == NULL\n");
857 ok(!pdp->rgvarg, "rgvarg == NULL\n");
858 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
859 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
860 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
861 ok(pvarRes != NULL, "pvarRes == NULL\n");
862 ok(pei != NULL, "pei == NULL\n");
863
864 V_VT(pvarRes) = VT_UNKNOWN;
865 V_UNKNOWN(pvarRes) = (IUnknown*)&enumObj;
866 return S_OK;
867 case DISPID_COLLOBJ_RESET:
868 next_cnt = 0;
869 return S_OK;
870 }
871
872 ok(0, "unexpected call %d\n", id);
873 return E_NOTIMPL;
874 }
875
876 static IDispatchExVtbl collectionObjVtbl = {
877 DispatchEx_QueryInterface,
878 DispatchEx_AddRef,
879 DispatchEx_Release,
880 DispatchEx_GetTypeInfoCount,
881 DispatchEx_GetTypeInfo,
882 DispatchEx_GetIDsOfNames,
883 DispatchEx_Invoke,
884 collectionObj_GetDispID,
885 collectionObj_InvokeEx,
886 DispatchEx_DeleteMemberByName,
887 DispatchEx_DeleteMemberByDispID,
888 DispatchEx_GetMemberProperties,
889 DispatchEx_GetMemberName,
890 DispatchEx_GetNextDispID,
891 DispatchEx_GetNameSpaceParent
892 };
893
894 static IDispatchEx collectionObj = { &collectionObjVtbl };
895
896 static ULONG refobj_ref;
897
898 static ULONG WINAPI RefObj_AddRef(IDispatchEx *iface)
899 {
900 return ++refobj_ref;
901 }
902
903 static ULONG WINAPI RefObj_Release(IDispatchEx *iface)
904 {
905 return --refobj_ref;
906 }
907
908 static IDispatchExVtbl RefObjVtbl = {
909 DispatchEx_QueryInterface,
910 RefObj_AddRef,
911 RefObj_Release,
912 DispatchEx_GetTypeInfoCount,
913 DispatchEx_GetTypeInfo,
914 DispatchEx_GetIDsOfNames,
915 DispatchEx_Invoke,
916 DispatchEx_GetDispID,
917 DispatchEx_InvokeEx,
918 DispatchEx_DeleteMemberByName,
919 DispatchEx_DeleteMemberByDispID,
920 DispatchEx_GetMemberProperties,
921 DispatchEx_GetMemberName,
922 DispatchEx_GetNextDispID,
923 DispatchEx_GetNameSpaceParent
924 };
925
926 static IDispatchEx RefObj = { &RefObjVtbl };
927
928 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
929 {
930 if(!strcmp_wa(bstrName, "ok")) {
931 test_grfdex(grfdex, fdexNameCaseInsensitive);
932 *pid = DISPID_GLOBAL_OK;
933 return S_OK;
934 }
935 if(!strcmp_wa(bstrName, "trace")) {
936 test_grfdex(grfdex, fdexNameCaseInsensitive);
937 *pid = DISPID_GLOBAL_TRACE;
938 return S_OK;
939 }
940 if(!strcmp_wa(bstrName, "reportSuccess")) {
941 CHECK_EXPECT(global_success_d);
942 test_grfdex(grfdex, fdexNameCaseInsensitive);
943 *pid = DISPID_GLOBAL_REPORTSUCCESS;
944 return S_OK;
945 }
946 if(!strcmp_wa(bstrName, "getVT")) {
947 test_grfdex(grfdex, fdexNameCaseInsensitive);
948 *pid = DISPID_GLOBAL_GETVT;
949 return S_OK;
950 }
951 if(!strcmp_wa(bstrName, "isEnglishLang")) {
952 test_grfdex(grfdex, fdexNameCaseInsensitive);
953 *pid = DISPID_GLOBAL_ISENGLANG;
954 return S_OK;
955 }
956 if(!strcmp_wa(bstrName, "testObj")) {
957 test_grfdex(grfdex, fdexNameCaseInsensitive);
958 *pid = DISPID_GLOBAL_TESTOBJ;
959 return S_OK;
960 }
961 if(!strcmp_wa(bstrName, "collectionObj")) {
962 test_grfdex(grfdex, fdexNameCaseInsensitive);
963 *pid = DISPID_GLOBAL_COLLOBJ;
964 return S_OK;
965 }
966 if(!strcmp_wa(bstrName, "vbvar")) {
967 CHECK_EXPECT(global_vbvar_d);
968 test_grfdex(grfdex, fdexNameCaseInsensitive);
969 *pid = DISPID_GLOBAL_VBVAR;
970 return S_OK;
971 }
972 if(!strcmp_wa(bstrName, "isNullDisp")) {
973 test_grfdex(grfdex, fdexNameCaseInsensitive);
974 *pid = DISPID_GLOBAL_ISNULLDISP;
975 return S_OK;
976 }
977 if(!strcmp_wa(bstrName, "testDisp")) {
978 test_grfdex(grfdex, fdexNameCaseInsensitive);
979 *pid = DISPID_GLOBAL_TESTDISP;
980 return S_OK;
981 }
982 if(!strcmp_wa(bstrName, "RefObj")) {
983 test_grfdex(grfdex, fdexNameCaseInsensitive);
984 *pid = DISPID_GLOBAL_REFOBJ;
985 return S_OK;
986 }
987 if(!strcmp_wa(bstrName, "propargput")) {
988 CHECK_EXPECT(global_propargput_d);
989 test_grfdex(grfdex, fdexNameCaseInsensitive);
990 *pid = DISPID_GLOBAL_PROPARGPUT;
991 return S_OK;
992 }
993 if(!strcmp_wa(bstrName, "propargput1")) {
994 CHECK_EXPECT(global_propargput1_d);
995 test_grfdex(grfdex, fdexNameCaseInsensitive);
996 *pid = DISPID_GLOBAL_PROPARGPUT1;
997 return S_OK;
998 }
999 if(!strcmp_wa(bstrName, "counter")) {
1000 test_grfdex(grfdex, fdexNameCaseInsensitive);
1001 *pid = DISPID_GLOBAL_COUNTER;
1002 return S_OK;
1003 }
1004 if(!strcmp_wa(bstrName, "doubleAsString")) {
1005 test_grfdex(grfdex, fdexNameCaseInsensitive);
1006 *pid = DISPID_GLOBAL_DOUBLEASSTRING;
1007 return S_OK;
1008 }
1009 if(!strcmp_wa(bstrName, "testArray")) {
1010 test_grfdex(grfdex, fdexNameCaseInsensitive);
1011 *pid = DISPID_GLOBAL_TESTARRAY;
1012 return S_OK;
1013 }
1014 if(!strcmp_wa(bstrName, "throwInt")) {
1015 test_grfdex(grfdex, fdexNameCaseInsensitive);
1016 *pid = DISPID_GLOBAL_THROWINT;
1017 return S_OK;
1018 }
1019 if(!strcmp_wa(bstrName, "testOptionalArg")) {
1020 test_grfdex(grfdex, fdexNameCaseInsensitive);
1021 *pid = DISPID_GLOBAL_TESTOPTIONALARG;
1022 return S_OK;
1023 }
1024
1025 if(strict_dispid_check && strcmp_wa(bstrName, "x"))
1026 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
1027 return DISP_E_UNKNOWNNAME;
1028 }
1029
1030 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1031 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1032 {
1033 switch(id) {
1034 case DISPID_GLOBAL_OK: {
1035 VARIANT *b;
1036
1037 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
1038 ok(pdp != NULL, "pdp == NULL\n");
1039 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1040 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1041 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
1042 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1043 if(wFlags & INVOKE_PROPERTYGET)
1044 ok(pvarRes != NULL, "pvarRes == NULL\n");
1045 else
1046 ok(!pvarRes, "pvarRes != NULL\n");
1047 ok(pei != NULL, "pei == NULL\n");
1048
1049 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1050
1051 b = pdp->rgvarg+1;
1052 if(V_VT(b) == (VT_BYREF|VT_VARIANT))
1053 b = V_BYREF(b);
1054
1055 ok(V_VT(b) == VT_BOOL, "V_VT(b) = %d\n", V_VT(b));
1056
1057 ok(V_BOOL(b), "%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
1058 return S_OK;
1059 }
1060
1061 case DISPID_GLOBAL_TRACE:
1062 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1063 ok(pdp != NULL, "pdp == NULL\n");
1064 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1065 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1066 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1067 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1068 ok(!pvarRes, "pvarRes != NULL\n");
1069 ok(pei != NULL, "pei == NULL\n");
1070
1071 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1072 if(V_VT(pdp->rgvarg) == VT_BSTR)
1073 trace("%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
1074
1075 return S_OK;
1076
1077 case DISPID_GLOBAL_REPORTSUCCESS:
1078 CHECK_EXPECT(global_success_i);
1079
1080 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1081 ok(pdp != NULL, "pdp == NULL\n");
1082 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1083 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
1084 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1085 ok(!pvarRes, "pvarRes != NULL\n");
1086 ok(pei != NULL, "pei == NULL\n");
1087
1088 return S_OK;
1089
1090 case DISPID_GLOBAL_GETVT:
1091 ok(pdp != NULL, "pdp == NULL\n");
1092 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1093 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1094 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1095 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1096 ok(pvarRes != NULL, "pvarRes == NULL\n");
1097 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1098 ok(pei != NULL, "pei == NULL\n");
1099
1100 V_VT(pvarRes) = VT_BSTR;
1101 V_BSTR(pvarRes) = a2bstr(vt2a(pdp->rgvarg));
1102 return S_OK;
1103
1104 case DISPID_GLOBAL_ISENGLANG:
1105 ok(wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
1106 ok(pdp != NULL, "pdp == NULL\n");
1107 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1108 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
1109 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1110 ok(pvarRes != NULL, "pvarRes == NULL\n");
1111 ok(pei != NULL, "pei == NULL\n");
1112
1113 V_VT(pvarRes) = VT_BOOL;
1114 V_BOOL(pvarRes) = is_english ? VARIANT_TRUE : VARIANT_FALSE;
1115 return S_OK;
1116
1117 case DISPID_GLOBAL_VBVAR:
1118 CHECK_EXPECT(global_vbvar_i);
1119
1120 ok(wFlags == DISPATCH_PROPERTYPUT, "wFlags = %x\n", wFlags);
1121 ok(pdp != NULL, "pdp == NULL\n");
1122 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1123 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
1124 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1125 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
1126 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
1127 ok(!pvarRes, "pvarRes != NULL\n");
1128 ok(pei != NULL, "pei == NULL\n");
1129
1130 ok(V_VT(pdp->rgvarg) == VT_I2, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1131 ok(V_I2(pdp->rgvarg) == 3, "V_I2(psp->rgvargs) = %d\n", V_I2(pdp->rgvarg));
1132 return S_OK;
1133
1134 case DISPID_GLOBAL_TESTOBJ:
1135 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
1136
1137 ok(pdp != NULL, "pdp == NULL\n");
1138 ok(!pdp->rgvarg, "rgvarg != NULL\n");
1139 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1140 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1141 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1142 ok(pvarRes != NULL, "pvarRes == NULL\n");
1143 ok(pei != NULL, "pei == NULL\n");
1144
1145 V_VT(pvarRes) = VT_DISPATCH;
1146 V_DISPATCH(pvarRes) = (IDispatch*)&testObj;
1147 return S_OK;
1148
1149 case DISPID_GLOBAL_COLLOBJ:
1150 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
1151
1152 ok(pdp != NULL, "pdp == NULL\n");
1153 ok(!pdp->rgvarg, "rgvarg != NULL\n");
1154 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1155 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1156 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1157 ok(pvarRes != NULL, "pvarRes == NULL\n");
1158 ok(pei != NULL, "pei == NULL\n");
1159
1160 V_VT(pvarRes) = VT_DISPATCH;
1161 V_DISPATCH(pvarRes) = (IDispatch*)&collectionObj;
1162 return S_OK;
1163
1164 case DISPID_GLOBAL_REFOBJ:
1165 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
1166
1167 ok(pdp != NULL, "pdp == NULL\n");
1168 ok(!pdp->rgvarg, "rgvarg == NULL\n");
1169 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1170 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1171 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1172 ok(pvarRes != NULL, "pvarRes == NULL\n");
1173 ok(pei != NULL, "pei == NULL\n");
1174
1175 IDispatchEx_AddRef(&RefObj);
1176 V_VT(pvarRes) = VT_DISPATCH;
1177 V_DISPATCH(pvarRes) = (IDispatch*)&RefObj;
1178 return S_OK;
1179
1180 case DISPID_GLOBAL_ISNULLDISP: {
1181 VARIANT *v;
1182
1183 ok(wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
1184 ok(pdp != NULL, "pdp == NULL\n");
1185 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1186 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1187 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1188 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1189 ok(pvarRes != NULL, "pvarRes == NULL\n");
1190 ok(pei != NULL, "pei == NULL\n");
1191
1192 v = pdp->rgvarg;
1193 if(V_VT(v) == (VT_VARIANT|VT_BYREF))
1194 v = V_VARIANTREF(v);
1195
1196 ok(V_VT(v) == VT_DISPATCH, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1197 V_VT(pvarRes) = VT_BOOL;
1198 V_BOOL(pvarRes) = V_DISPATCH(v) ? VARIANT_FALSE : VARIANT_TRUE;
1199 return S_OK;
1200 }
1201
1202 case DISPID_GLOBAL_TESTDISP:
1203 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1204 ok(pdp != NULL, "pdp == NULL\n");
1205 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1206 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1207 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1208 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1209 ok(!pvarRes, "pvarRes != NULL\n");
1210 ok(pei != NULL, "pei == NULL\n");
1211
1212 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1213 test_disp(V_DISPATCH(pdp->rgvarg));
1214 return S_OK;
1215
1216 case DISPID_GLOBAL_PROPARGPUT:
1217 CHECK_EXPECT(global_propargput_i);
1218
1219 ok(wFlags == DISPATCH_PROPERTYPUT, "wFlags = %x\n", wFlags);
1220 ok(pdp != NULL, "pdp == NULL\n");
1221 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1222 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
1223 ok(pdp->cArgs == 3, "cArgs = %d\n", pdp->cArgs);
1224 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
1225 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
1226 ok(!pvarRes, "pvarRes != NULL\n");
1227 ok(pei != NULL, "pei == NULL\n");
1228
1229 ok(V_VT(pdp->rgvarg) == VT_I2, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1230 ok(V_I2(pdp->rgvarg) == 0, "V_I2(psp->rgvargs) = %d\n", V_I2(pdp->rgvarg));
1231
1232 ok(V_VT(pdp->rgvarg+1) == VT_I2, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg+1));
1233 ok(V_I2(pdp->rgvarg+1) == 2, "V_I2(psp->rgvargs+1) = %d\n", V_I2(pdp->rgvarg+1));
1234
1235 ok(V_VT(pdp->rgvarg+2) == VT_I2, "V_VT(psp->rgvargs+2) = %d\n", V_VT(pdp->rgvarg+2));
1236 ok(V_I2(pdp->rgvarg+2) == 1, "V_I2(psp->rgvargs+2) = %d\n", V_I2(pdp->rgvarg+2));
1237 return S_OK;
1238
1239 case DISPID_GLOBAL_PROPARGPUT1:
1240 CHECK_EXPECT(global_propargput1_i);
1241
1242 ok(wFlags == DISPATCH_PROPERTYPUT, "wFlags = %x\n", wFlags);
1243 ok(pdp != NULL, "pdp == NULL\n");
1244 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1245 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
1246 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
1247 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
1248 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
1249 ok(!pvarRes, "pvarRes != NULL\n");
1250 ok(pei != NULL, "pei == NULL\n");
1251
1252 ok(V_VT(pdp->rgvarg) == VT_I2, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1253 ok(V_I2(pdp->rgvarg) == 0, "V_I2(psp->rgvargs) = %d\n", V_I2(pdp->rgvarg));
1254
1255 ok(V_VT(pdp->rgvarg+1) == VT_I2, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg+1));
1256 ok(V_I2(pdp->rgvarg+1) == 1, "V_I2(psp->rgvargs+1) = %d\n", V_I2(pdp->rgvarg+1));
1257
1258 return S_OK;
1259
1260 case DISPID_GLOBAL_COUNTER:
1261 ok(pdp != NULL, "pdp == NULL\n");
1262 todo_wine ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1263 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1264 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1265 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1266 ok(pvarRes != NULL, "pvarRes == NULL\n");
1267 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1268 ok(pei != NULL, "pei == NULL\n");
1269
1270 V_VT(pvarRes) = VT_I2;
1271 V_I2(pvarRes) = test_counter++;
1272 return S_OK;
1273
1274 case DISPID_GLOBAL_DOUBLEASSTRING:
1275 ok(wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
1276 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1277 ok(V_VT(pdp->rgvarg) == VT_R8, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
1278 ok(pvarRes != NULL, "pvarRes == NULL\n");
1279
1280 V_VT(pvarRes) = VT_BSTR;
1281 return VarBstrFromR8(V_R8(pdp->rgvarg), 0, 0, &V_BSTR(pvarRes));
1282
1283 case DISPID_GLOBAL_TESTARRAY:
1284 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1285 ok(pdp != NULL, "pdp == NULL\n");
1286 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1287 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1288 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
1289 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1290 ok(!pvarRes, "pvarRes != NULL\n");
1291 ok(pei != NULL, "pei == NULL\n");
1292
1293 ok(V_VT(pdp->rgvarg+1) == VT_I2, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg+1));
1294 ok(V_VT(pdp->rgvarg) == (VT_BYREF|VT_VARIANT), "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1295 ok(V_VT(V_VARIANTREF(pdp->rgvarg)) == (VT_ARRAY|VT_BYREF|VT_VARIANT),
1296 "V_VT(V_VARIANTREF(psp->rgvargs)) = %d\n", V_VT(V_VARIANTREF(pdp->rgvarg)));
1297 if(V_I2(pdp->rgvarg+1) == -1)
1298 ok(!*V_ARRAYREF(V_VARIANTREF(pdp->rgvarg)), "*V_ARRAYREF(V_VARIANTREF(pdp->rgvarg)) != NULL\n");
1299 else
1300 test_safearray(*V_ARRAYREF(V_VARIANTREF(pdp->rgvarg)), V_I2(pdp->rgvarg+1));
1301 return S_OK;
1302
1303 case DISPID_GLOBAL_THROWINT: {
1304 VARIANT *v = pdp->rgvarg;
1305 HRESULT hres;
1306
1307 ok((wFlags & ~INVOKE_PROPERTYGET) == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1308 ok(pdp != NULL, "pdp == NULL\n");
1309 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1310 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1311 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1312 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1313 ok(pei != NULL, "pei == NULL\n");
1314 if(pvarRes) {
1315 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1316 V_VT(pvarRes) = VT_BOOL;
1317 V_BOOL(pvarRes) = VARIANT_FALSE;
1318 }
1319
1320 if(V_VT(v) == (VT_VARIANT|VT_BYREF))
1321 v = V_VARIANTREF(v);
1322
1323 switch(V_VT(v)) {
1324 case VT_I2:
1325 hres = V_I2(v);
1326 break;
1327 case VT_I4:
1328 hres = V_I4(v);
1329 break;
1330 default:
1331 ok(0, "unexpected vt %d\n", V_VT(v));
1332 return E_INVALIDARG;
1333 }
1334
1335 return hres;
1336 }
1337
1338 case DISPID_GLOBAL_TESTOPTIONALARG: {
1339 VARIANT *v;
1340 int opt;
1341
1342 CHECK_EXPECT(global_testoptionalarg_i);
1343
1344 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1345 ok(pdp != NULL, "pdp == NULL\n");
1346 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1347 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1348 ok(pdp->cArgs == 3, "cArgs = %d\n", pdp->cArgs);
1349 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1350 ok(!pvarRes, "pvarRes != NULL\n");
1351 ok(pei != NULL, "pei == NULL\n");
1352
1353 ok(V_VT(pdp->rgvarg) == VT_I2, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
1354 opt = V_I2(pdp->rgvarg);
1355 ok(opt == 1 || opt == 2, "opt = %d\n", opt);
1356 v = pdp->rgvarg+pdp->cArgs-opt;
1357 ok(V_VT(v) == VT_ERROR, "V_VT(v) = %d\n", V_VT(v));
1358 ok(V_ERROR(v) == DISP_E_PARAMNOTFOUND, "V_ERROR(v) = %08x\n", V_ERROR(v));
1359 return S_OK;
1360 }
1361 }
1362
1363 ok(0, "unexpected call %d\n", id);
1364 return DISP_E_MEMBERNOTFOUND;
1365 }
1366
1367 static IDispatchExVtbl GlobalVtbl = {
1368 DispatchEx_QueryInterface,
1369 DispatchEx_AddRef,
1370 DispatchEx_Release,
1371 DispatchEx_GetTypeInfoCount,
1372 DispatchEx_GetTypeInfo,
1373 DispatchEx_GetIDsOfNames,
1374 DispatchEx_Invoke,
1375 Global_GetDispID,
1376 Global_InvokeEx,
1377 DispatchEx_DeleteMemberByName,
1378 DispatchEx_DeleteMemberByDispID,
1379 DispatchEx_GetMemberProperties,
1380 DispatchEx_GetMemberName,
1381 DispatchEx_GetNextDispID,
1382 DispatchEx_GetNameSpaceParent
1383 };
1384
1385 static IDispatchEx Global = { &GlobalVtbl };
1386
1387 static HRESULT WINAPI ActiveScriptSiteWindow_QueryInterface(IActiveScriptSiteWindow *iface, REFIID riid, void **ppv)
1388 {
1389 ok(0, "unexpected call\n");
1390 return E_NOINTERFACE;
1391 }
1392
1393 static ULONG WINAPI ActiveScriptSiteWindow_AddRef(IActiveScriptSiteWindow *iface)
1394 {
1395 return 2;
1396 }
1397
1398 static ULONG WINAPI ActiveScriptSiteWindow_Release(IActiveScriptSiteWindow *iface)
1399 {
1400 return 1;
1401 }
1402
1403 static HRESULT WINAPI ActiveScriptSiteWindow_GetWindow(IActiveScriptSiteWindow *iface, HWND *phwnd)
1404 {
1405 if(!allow_ui)
1406 CHECK_EXPECT(GetWindow);
1407 *phwnd = NULL;
1408 return S_OK;
1409 }
1410
1411 static HRESULT WINAPI ActiveScriptSiteWindow_EnableModeless(IActiveScriptSiteWindow *iface, BOOL fEnable)
1412 {
1413 if(allow_ui)
1414 return S_OK;
1415
1416 CHECK_EXPECT(EnableModeless);
1417 ok(!fEnable, "fEnable = %x\n", fEnable);
1418 return E_FAIL;
1419 }
1420
1421 static const IActiveScriptSiteWindowVtbl ActiveScriptSiteWindowVtbl = {
1422 ActiveScriptSiteWindow_QueryInterface,
1423 ActiveScriptSiteWindow_AddRef,
1424 ActiveScriptSiteWindow_Release,
1425 ActiveScriptSiteWindow_GetWindow,
1426 ActiveScriptSiteWindow_EnableModeless
1427 };
1428
1429 static IActiveScriptSiteWindow ActiveScriptSiteWindow = { &ActiveScriptSiteWindowVtbl };
1430
1431 static HRESULT WINAPI ActiveScriptSiteUIControl_QueryInterface(IActiveScriptSiteUIControl *iface, REFIID riid, void **ppv)
1432 {
1433 ok(0, "unexpected call\n");
1434 return E_NOINTERFACE;
1435 }
1436
1437 static ULONG WINAPI ActiveScriptSiteUIControl_AddRef(IActiveScriptSiteUIControl *iface)
1438 {
1439 return 2;
1440 }
1441
1442 static ULONG WINAPI ActiveScriptSiteUIControl_Release(IActiveScriptSiteUIControl *iface)
1443 {
1444 return 1;
1445 }
1446
1447 static HRESULT WINAPI ActiveScriptSiteUIControl_GetUIBehavior(IActiveScriptSiteUIControl *iface, SCRIPTUICITEM UicItem,
1448 SCRIPTUICHANDLING *pUicHandling)
1449 {
1450 if(!allow_ui) {
1451 CHECK_EXPECT(GetUIBehavior);
1452 ok(UicItem == SCRIPTUICITEM_MSGBOX, "UidItem = %d\n", UicItem);
1453 }
1454 *pUicHandling = uic_handling;
1455 return S_OK;
1456 }
1457
1458 static const IActiveScriptSiteUIControlVtbl ActiveScriptSiteUIControlVtbl = {
1459 ActiveScriptSiteUIControl_QueryInterface,
1460 ActiveScriptSiteUIControl_AddRef,
1461 ActiveScriptSiteUIControl_Release,
1462 ActiveScriptSiteUIControl_GetUIBehavior
1463 };
1464
1465 static IActiveScriptSiteUIControl ActiveScriptSiteUIControl = { &ActiveScriptSiteUIControlVtbl };
1466
1467 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
1468 {
1469 *ppv = NULL;
1470
1471 if(IsEqualGUID(&IID_IUnknown, riid))
1472 *ppv = iface;
1473 else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
1474 *ppv = iface;
1475 else if(IsEqualGUID(&IID_IActiveScriptSiteWindow, riid))
1476 *ppv = &ActiveScriptSiteWindow;
1477 else if(IsEqualGUID(&IID_IActiveScriptSiteUIControl, riid))
1478 *ppv = &ActiveScriptSiteUIControl;
1479 else
1480 return E_NOINTERFACE;
1481
1482 IUnknown_AddRef((IUnknown*)*ppv);
1483 return S_OK;
1484 }
1485
1486 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
1487 {
1488 return 2;
1489 }
1490
1491 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
1492 {
1493 return 1;
1494 }
1495
1496 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
1497 {
1498 *plcid = GetUserDefaultLCID();
1499 return S_OK;
1500 }
1501
1502 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
1503 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
1504 {
1505 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
1506 ok(!ppti, "ppti != NULL\n");
1507
1508 if(strcmp_wa(pstrName, "test"))
1509 ok(0, "unexpected pstrName %s\n", wine_dbgstr_w(pstrName));
1510
1511 *ppiunkItem = (IUnknown*)&Global;
1512 return S_OK;
1513 }
1514
1515 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
1516 {
1517 return E_NOTIMPL;
1518 }
1519
1520 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
1521 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
1522 {
1523 return E_NOTIMPL;
1524 }
1525
1526 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
1527 {
1528 return E_NOTIMPL;
1529 }
1530
1531 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
1532 {
1533 return E_NOTIMPL;
1534 }
1535
1536 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
1537 {
1538 return E_NOTIMPL;
1539 }
1540
1541 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
1542 {
1543 return E_NOTIMPL;
1544 }
1545
1546 #undef ACTSCPSITE_THIS
1547
1548 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
1549 ActiveScriptSite_QueryInterface,
1550 ActiveScriptSite_AddRef,
1551 ActiveScriptSite_Release,
1552 ActiveScriptSite_GetLCID,
1553 ActiveScriptSite_GetItemInfo,
1554 ActiveScriptSite_GetDocVersionString,
1555 ActiveScriptSite_OnScriptTerminate,
1556 ActiveScriptSite_OnStateChange,
1557 ActiveScriptSite_OnScriptError,
1558 ActiveScriptSite_OnEnterScript,
1559 ActiveScriptSite_OnLeaveScript
1560 };
1561
1562 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
1563
1564 static IActiveScript *create_script(void)
1565 {
1566 IActiveScript *script;
1567 HRESULT hres;
1568
1569 hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1570 &IID_IActiveScript, (void**)&script);
1571 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1572
1573 return script;
1574 }
1575
1576 static IActiveScript *create_and_init_script(DWORD flags)
1577 {
1578 IActiveScriptParse *parser;
1579 IActiveScript *engine;
1580 HRESULT hres;
1581
1582 engine = create_script();
1583 if(!engine)
1584 return NULL;
1585
1586 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1587 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1588
1589 hres = IActiveScriptParse_InitNew(parser);
1590 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1591
1592 IActiveScriptParse_Release(parser);
1593
1594 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1595 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1596
1597 hres = IActiveScript_AddNamedItem(engine, testW,
1598 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags);
1599 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1600
1601 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1602 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1603
1604 return engine;
1605 }
1606
1607 static void close_script(IActiveScript *script)
1608 {
1609 ULONG ref;
1610 HRESULT hres;
1611
1612 hres = IActiveScript_Close(script);
1613 ok(hres == S_OK, "Close failed: %08x\n", hres);
1614
1615 ref = IActiveScript_Release(script);
1616 ok(!ref, "ref=%u\n", ref);
1617 }
1618
1619 static HRESULT parse_script(DWORD flags, BSTR script_str, const WCHAR *delim)
1620 {
1621 IActiveScriptParse *parser;
1622 IActiveScript *engine;
1623 IDispatch *script_disp;
1624 LONG ref;
1625 HRESULT hres;
1626
1627 engine = create_and_init_script(flags);
1628 if(!engine)
1629 return S_OK;
1630
1631 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1632 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1633 if (FAILED(hres))
1634 {
1635 IActiveScript_Release(engine);
1636 return hres;
1637 }
1638
1639 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp);
1640 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
1641 ok(script_disp != NULL, "script_disp == NULL\n");
1642 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n");
1643
1644 test_counter = 0;
1645
1646 hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, delim, 0, 0, 0, NULL, NULL);
1647
1648 IActiveScript_Close(engine);
1649
1650 IDispatch_Release(script_disp);
1651 IActiveScript_Release(engine);
1652
1653 ref = IActiveScriptParse_Release(parser);
1654 ok(!ref, "ref=%d\n", ref);
1655 return hres;
1656 }
1657
1658 static void parse_script_af(DWORD flags, const char *src)
1659 {
1660 BSTR tmp;
1661 HRESULT hres;
1662
1663 tmp = a2bstr(src);
1664 hres = parse_script(flags, tmp, NULL);
1665 SysFreeString(tmp);
1666 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1667 }
1668
1669 static HRESULT parse_script_ar(const char *src)
1670 {
1671 BSTR tmp;
1672 HRESULT hres;
1673
1674 tmp = a2bstr(src);
1675 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, tmp, NULL);
1676 SysFreeString(tmp);
1677 return hres;
1678 }
1679
1680 static void parse_script_a(const char *src)
1681 {
1682 parse_script_af(SCRIPTITEM_GLOBALMEMBERS, src);
1683 }
1684
1685 #define parse_htmlscript_a(a) _parse_htmlscript_a(__LINE__,a)
1686 static void _parse_htmlscript_a(unsigned line, const char *src)
1687 {
1688 BSTR tmp;
1689 HRESULT hres;
1690
1691 static const WCHAR script_delimW[] = {'<','/','S','C','R','I','P','T','>',0};
1692
1693 tmp = a2bstr(src);
1694 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, tmp, script_delimW);
1695 SysFreeString(tmp);
1696 ok_(__FILE__,line)(hres == S_OK, "parse_script failed: %08x\n", hres);
1697 }
1698
1699 static IDispatchEx *parse_procedure(IActiveScriptParseProcedure2 *parse_proc, const char *src)
1700 {
1701 IDispatchEx *dispex;
1702 IDispatch *disp;
1703 BSTR str;
1704 HRESULT hres;
1705
1706 static const WCHAR delimiterW[] = {'\"',0};
1707
1708 str = a2bstr(src);
1709 hres = IActiveScriptParseProcedure2_ParseProcedureText(parse_proc, str, NULL, emptyW, NULL, NULL, delimiterW, 0, 0,
1710 SCRIPTPROC_HOSTMANAGESSOURCE|SCRIPTPROC_IMPLICIT_THIS|SCRIPTPROC_IMPLICIT_PARENTS, &disp);
1711 SysFreeString(str);
1712 ok(hres == S_OK, "ParseProcedureText failed: %08x\n", hres);
1713 ok(disp != NULL, "disp = NULL\n");
1714
1715 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1716 IDispatch_Release(disp);
1717 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
1718
1719 return dispex;
1720 }
1721
1722
1723 static void test_procedures(void)
1724 {
1725 IActiveScriptParseProcedure2 *parse_proc;
1726 DISPPARAMS dp = {NULL};
1727 IActiveScript *script;
1728 IDispatchEx *proc;
1729 EXCEPINFO ei = {0};
1730 VARIANT v;
1731 HRESULT hres;
1732
1733 script = create_and_init_script(0);
1734
1735 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc);
1736 ok(hres == S_OK, "Could not get IActiveScriptParseProcedure2 iface: %08x\n", hres);
1737
1738 proc = parse_procedure(parse_proc, "dim x\nif true then x=false");
1739
1740 V_VT(&v) = VT_EMPTY;
1741 hres = IDispatchEx_InvokeEx(proc, DISPID_VALUE, 0, DISPATCH_METHOD, &dp, &v, &ei, &caller_sp);
1742 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1743
1744 IDispatchEx_Release(proc);
1745
1746 IActiveScriptParseProcedure2_Release(parse_proc);
1747
1748 close_script(script);
1749 }
1750
1751 static void test_gc(void)
1752 {
1753 IActiveScriptParse *parser;
1754 IActiveScript *engine;
1755 BSTR src;
1756 HRESULT hres;
1757
1758 strict_dispid_check = FALSE;
1759
1760 engine = create_script();
1761 if(!engine)
1762 return;
1763
1764 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1765 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1766
1767 hres = IActiveScriptParse_InitNew(parser);
1768 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1769
1770 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1771 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1772
1773 hres = IActiveScript_AddNamedItem(engine, testW,
1774 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
1775 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1776
1777 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1778 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1779
1780 src = a2bstr(
1781 "class C\n"
1782 " Public ref\n"
1783 " Public Sub Class_Terminate\n"
1784 " Call reportSuccess()\n"
1785 " End Sub\n"
1786 "End Class\n"
1787 "Dim x\n"
1788 "set x = new C\n"
1789 "set x.ref = x\n"
1790 "set x = nothing\n");
1791
1792 hres = IActiveScriptParse_ParseScriptText(parser, src, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1793 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1794 SysFreeString(src);
1795
1796 SET_EXPECT(global_success_d);
1797 SET_EXPECT(global_success_i);
1798 IActiveScript_Close(engine);
1799 CHECK_CALLED(global_success_d);
1800 CHECK_CALLED(global_success_i);
1801
1802 IActiveScript_Release(engine);
1803 IActiveScriptParse_Release(parser);
1804 }
1805
1806 static void test_msgbox(void)
1807 {
1808 HRESULT hres;
1809
1810 uic_handling = SCRIPTUICHANDLING_NOUIDEFAULT;
1811
1812 SET_EXPECT(GetUIBehavior);
1813 SET_EXPECT(GetWindow);
1814 SET_EXPECT(EnableModeless);
1815 hres = parse_script_ar("MsgBox \"testing...\"");
1816 CLEAR_CALLED(GetUIBehavior);
1817 CLEAR_CALLED(GetWindow);
1818 CLEAR_CALLED(EnableModeless);
1819 if(FAILED(hres)) {
1820 win_skip("Skipping MsgBox tests, broken (probably too old) vbscript\n");
1821 return;
1822 }
1823
1824 SET_EXPECT(GetUIBehavior);
1825 parse_script_a("dim r\n r=MsgBox(\"testing...\")\n Call ok(r=0, \"r=\"&r)");
1826 CHECK_CALLED(GetUIBehavior);
1827
1828 SET_EXPECT(GetUIBehavior);
1829 parse_script_a("MsgBox 10");
1830 CHECK_CALLED(GetUIBehavior);
1831
1832 uic_handling = SCRIPTUICHANDLING_ALLOW;
1833
1834 SET_EXPECT(GetUIBehavior);
1835 SET_EXPECT(GetWindow);
1836 SET_EXPECT(EnableModeless);
1837 hres = parse_script_ar("MsgBox \"testing...\"");
1838 ok(FAILED(hres), "script not failed\n");
1839 CHECK_CALLED(GetUIBehavior);
1840 CHECK_CALLED(GetWindow);
1841 CHECK_CALLED(EnableModeless);
1842
1843 uic_handling = SCRIPTUICHANDLING_NOUIERROR;
1844
1845 SET_EXPECT(GetUIBehavior);
1846 hres = parse_script_ar("MsgBox \"testing...\"");
1847 ok(FAILED(hres), "script not failed\n");
1848 CHECK_CALLED(GetUIBehavior);
1849 }
1850
1851 static HRESULT test_global_vars_ref(BOOL use_close)
1852 {
1853 IActiveScriptParse *parser;
1854 IActiveScript *engine;
1855 BSTR script_str;
1856 LONG ref;
1857 HRESULT hres;
1858
1859 engine = create_script();
1860 if(!engine)
1861 return S_OK;
1862
1863 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1864 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1865 if (FAILED(hres))
1866 {
1867 IActiveScript_Release(engine);
1868 return hres;
1869 }
1870
1871 hres = IActiveScriptParse_InitNew(parser);
1872 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1873
1874 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1875 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1876
1877 hres = IActiveScript_AddNamedItem(engine, testW, SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
1878 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1879
1880 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1881 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1882
1883 refobj_ref = 0;
1884
1885 script_str = a2bstr("Dim x\nset x = RefObj\n");
1886 hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1887 SysFreeString(script_str);
1888
1889 ok(refobj_ref, "refobj_ref = 0\n");
1890
1891 if(use_close) {
1892 hres = IActiveScript_Close(engine);
1893 ok(hres == S_OK, "Close failed: %08x\n", hres);
1894 }else {
1895 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_UNINITIALIZED);
1896 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1897 }
1898
1899 ok(!refobj_ref, "refobj_ref = %d\n", refobj_ref);
1900
1901 IActiveScript_Release(engine);
1902
1903 ref = IActiveScriptParse_Release(parser);
1904 ok(!ref, "ref=%d\n", ref);
1905 return hres;
1906 }
1907
1908 static BSTR get_script_from_file(const char *filename)
1909 {
1910 DWORD size, len;
1911 HANDLE file, map;
1912 const char *file_map;
1913 BSTR ret;
1914
1915 file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
1916 if(file == INVALID_HANDLE_VALUE) {
1917 trace("Could not open file: %u\n", GetLastError());
1918 return NULL;
1919 }
1920
1921 size = GetFileSize(file, NULL);
1922
1923 map = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
1924 CloseHandle(file);
1925 if(map == INVALID_HANDLE_VALUE) {
1926 trace("Could not create file mapping: %u\n", GetLastError());
1927 return NULL;
1928 }
1929
1930 file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
1931 CloseHandle(map);
1932 if(!file_map) {
1933 trace("MapViewOfFile failed: %u\n", GetLastError());
1934 return NULL;
1935 }
1936
1937 len = MultiByteToWideChar(CP_ACP, 0, file_map, size, NULL, 0);
1938 ret = SysAllocStringLen(NULL, len);
1939 MultiByteToWideChar(CP_ACP, 0, file_map, size, ret, len);
1940
1941 UnmapViewOfFile(file_map);
1942
1943 return ret;
1944 }
1945
1946 static void run_from_file(const char *filename)
1947 {
1948 BSTR script_str;
1949 HRESULT hres;
1950
1951 script_str = get_script_from_file(filename);
1952 if(!script_str)
1953 return;
1954
1955 strict_dispid_check = FALSE;
1956 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, script_str, NULL);
1957 SysFreeString(script_str);
1958 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1959 }
1960
1961 static void run_from_res(const char *name)
1962 {
1963 const char *data;
1964 DWORD size, len;
1965 BSTR str;
1966 HRSRC src;
1967 HRESULT hres;
1968
1969 strict_dispid_check = FALSE;
1970 test_name = name;
1971
1972 src = FindResourceA(NULL, name, (LPCSTR)40);
1973 ok(src != NULL, "Could not find resource %s\n", name);
1974
1975 size = SizeofResource(NULL, src);
1976 data = LoadResource(NULL, src);
1977
1978 len = MultiByteToWideChar(CP_ACP, 0, data, size, NULL, 0);
1979 str = SysAllocStringLen(NULL, len);
1980 MultiByteToWideChar(CP_ACP, 0, data, size, str, len);
1981
1982 SET_EXPECT(global_success_d);
1983 SET_EXPECT(global_success_i);
1984 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, str, NULL);
1985 CHECK_CALLED(global_success_d);
1986 CHECK_CALLED(global_success_i);
1987
1988 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1989 SysFreeString(str);
1990 }
1991
1992 static void run_tests(void)
1993 {
1994 HRESULT hres;
1995
1996 strict_dispid_check = TRUE;
1997
1998 parse_script_a("");
1999 parse_script_a("' empty ;");
2000
2001 SET_EXPECT(global_success_d);
2002 SET_EXPECT(global_success_i);
2003 parse_script_a("reportSuccess");
2004 CHECK_CALLED(global_success_d);
2005 CHECK_CALLED(global_success_i);
2006
2007 SET_EXPECT(global_success_d);
2008 SET_EXPECT(global_success_i);
2009 parse_script_a("reportSuccess()");
2010 CHECK_CALLED(global_success_d);
2011 CHECK_CALLED(global_success_i);
2012
2013 SET_EXPECT(global_success_d);
2014 SET_EXPECT(global_success_i);
2015 parse_script_a("Call reportSuccess");
2016 CHECK_CALLED(global_success_d);
2017 CHECK_CALLED(global_success_i);
2018
2019 SET_EXPECT(global_success_d);
2020 SET_EXPECT(global_success_i);
2021 parse_script_a("test.reportSuccess()");
2022 CHECK_CALLED(global_success_d);
2023 CHECK_CALLED(global_success_i);
2024
2025 SET_EXPECT(global_vbvar_d);
2026 SET_EXPECT(global_vbvar_i);
2027 parse_script_a("Option Explicit\nvbvar = 3");
2028 CHECK_CALLED(global_vbvar_d);
2029 CHECK_CALLED(global_vbvar_i);
2030
2031 SET_EXPECT(global_vbvar_d);
2032 SET_EXPECT(global_vbvar_i);
2033 parse_script_a("Option Explicit\nvbvar() = 3");
2034 CHECK_CALLED(global_vbvar_d);
2035 CHECK_CALLED(global_vbvar_i);
2036
2037 SET_EXPECT(testobj_propget_d);
2038 SET_EXPECT(testobj_propget_i);
2039 parse_script_a("dim x\nx = testObj.propget");
2040 CHECK_CALLED(testobj_propget_d);
2041 CHECK_CALLED(testobj_propget_i);
2042
2043 SET_EXPECT(testobj_propput_d);
2044 SET_EXPECT(testobj_propput_i);
2045 parse_script_a("testObj.propput = 1");
2046 CHECK_CALLED(testobj_propput_d);
2047 CHECK_CALLED(testobj_propput_i);
2048
2049 SET_EXPECT(global_propargput_d);
2050 SET_EXPECT(global_propargput_i);
2051 parse_script_a("propargput(counter(), counter()) = counter()");
2052 CHECK_CALLED(global_propargput_d);
2053 CHECK_CALLED(global_propargput_i);
2054
2055 SET_EXPECT(global_propargput_d);
2056 SET_EXPECT(global_propargput_i);
2057 parse_script_a("test.propargput(counter(), counter()) = counter()");
2058 CHECK_CALLED(global_propargput_d);
2059 CHECK_CALLED(global_propargput_i);
2060
2061 SET_EXPECT(global_propargput1_d);
2062 SET_EXPECT(global_propargput1_i);
2063 parse_script_a("propargput1 (counter()) = counter()");
2064 CHECK_CALLED(global_propargput1_d);
2065 CHECK_CALLED(global_propargput1_i);
2066
2067 SET_EXPECT(global_propargput1_d);
2068 SET_EXPECT(global_propargput1_i);
2069 parse_script_a("test.propargput1(counter()) = counter()");
2070 CHECK_CALLED(global_propargput1_d);
2071 CHECK_CALLED(global_propargput1_i);
2072
2073 parse_htmlscript_a("<!--");
2074 parse_htmlscript_a(" -->");
2075 parse_htmlscript_a("<!--\ndim x\nx=1\n-->\n");
2076 parse_htmlscript_a("<!--\ndim x\n-->\n<!--\nx=1\n-->\n");
2077
2078 hres = parse_script_ar("<!--");
2079 ok(FAILED(hres), "script didn't fail\n");
2080
2081 SET_EXPECT(global_success_d);
2082 SET_EXPECT(global_success_i);
2083 parse_htmlscript_a("<!--\n<!-- ignore this <> <>\n--> <>\nCall reportSuccess()\n-->\n");
2084 CHECK_CALLED(global_success_d);
2085 CHECK_CALLED(global_success_i);
2086
2087 next_cnt = 0;
2088 SET_EXPECT(collectionobj_newenum_i);
2089 SET_EXPECT(Next);
2090 parse_script_a("for each x in collectionObj\nnext");
2091 CHECK_CALLED(collectionobj_newenum_i);
2092 CHECK_CALLED(Next);
2093 ok(next_cnt == 4, "next_cnt = %d\n", next_cnt);
2094
2095 parse_script_a("x = 1\n Call ok(x = 1, \"x = \" & x)");
2096
2097 parse_script_a("x = _ \n3");
2098
2099 test_global_vars_ref(TRUE);
2100 test_global_vars_ref(FALSE);
2101
2102 hres = parse_script_ar("throwInt(&h80080008&)");
2103 ok(hres == 0x80080008, "hres = %08x\n", hres);
2104
2105 /* DISP_E_BADINDEX */
2106 hres = parse_script_ar("throwInt(&h8002000b&)");
2107 ok(hres == MAKE_VBSERROR(9), "hres = %08x\n", hres);
2108
2109 hres = parse_script_ar("throwInt(&h800a0009&)");
2110 ok(hres == MAKE_VBSERROR(9), "hres = %08x\n", hres);
2111
2112 /* E_NOTIMPL */
2113 hres = parse_script_ar("throwInt(&h80004001&)");
2114 ok(hres == MAKE_VBSERROR(445), "hres = %08x\n", hres);
2115
2116 SET_EXPECT(global_testoptionalarg_i);
2117 parse_script_a("call testOptionalArg(1,,2)");
2118 CHECK_CALLED(global_testoptionalarg_i);
2119
2120 SET_EXPECT(global_testoptionalarg_i);
2121 parse_script_a("call testOptionalArg(,1,1)");
2122 CHECK_CALLED(global_testoptionalarg_i);
2123
2124 SET_EXPECT(global_testoptionalarg_i);
2125 parse_script_a("testOptionalArg 1,,2");
2126 CHECK_CALLED(global_testoptionalarg_i);
2127
2128 strict_dispid_check = FALSE;
2129
2130 SET_EXPECT(testobj_value_i);
2131 parse_script_a("dim n,o\n set o = testObj\n n = o(1,2)\n call ok(n=2, \"n = \" & n)\n");
2132 CHECK_CALLED(testobj_value_i);
2133
2134 SET_EXPECT(testobj_value_i);
2135 parse_script_a("dim n,o\n set o = testObj\n n = o\n call ok(n=0, \"n = \" & n)\n");
2136 CHECK_CALLED(testobj_value_i);
2137
2138 parse_script_a("Sub testsub\n"
2139 "x = 1\n"
2140 "Call ok(x = 1, \"x = \" & x)\n"
2141 "End Sub\n"
2142 "Call testsub()");
2143
2144 parse_script_a("Call ok(getVT(x) = \"VT_EMPTY*\", \"getVT(x) = \" & getVT(x))\n");
2145 parse_script_a("Call ok(x = \"\", \"x = \" & x)\n");
2146 parse_script_a("x = y\n"
2147 "Call ok(getVT(x) = \"VT_EMPTY*\", \"getVT(x) = \" & getVT(x))\n"
2148 "Call ok(getVT(y) = \"VT_EMPTY*\", \"getVT(y) = \" & getVT(y))");
2149 hres = parse_script_ar("x = y(\"a\")");
2150 ok(FAILED(hres), "script didn't fail\n");
2151
2152 run_from_res("lang.vbs");
2153 run_from_res("api.vbs");
2154 run_from_res("regexp.vbs");
2155 run_from_res("error.vbs");
2156
2157 test_procedures();
2158 test_gc();
2159 test_msgbox();
2160 }
2161
2162 static BOOL check_vbscript(void)
2163 {
2164 IRegExp2 *regexp;
2165 IUnknown *unk;
2166 HRESULT hres;
2167
2168 hres = CoCreateInstance(&CLSID_VBScriptRegExp, NULL,
2169 CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2170 &IID_IUnknown, (void**)&unk);
2171 if(hres == REGDB_E_CLASSNOTREG)
2172 return FALSE;
2173 ok(hres == S_OK, "CoCreateInstance(CLSID_VBScriptRegExp) failed: %x\n", hres);
2174
2175 hres = IUnknown_QueryInterface(unk, &IID_IRegExp2, (void**)&regexp);
2176 if(SUCCEEDED(hres))
2177 IRegExp2_Release(regexp);
2178 IUnknown_Release(unk);
2179
2180 return hres == S_OK;
2181 }
2182
2183 START_TEST(run)
2184 {
2185 int argc;
2186 char **argv;
2187
2188 is_english = is_lang_english();
2189 if(!is_english)
2190 skip("Skipping some tests in non-English locale\n");
2191
2192 argc = winetest_get_mainargs(&argv);
2193
2194 CoInitialize(NULL);
2195
2196 if(!check_vbscript()) {
2197 win_skip("Broken engine, probably too old\n");
2198 }else if(argc > 2) {
2199 allow_ui = TRUE;
2200 uic_handling = SCRIPTUICHANDLING_ALLOW;
2201 run_from_file(argv[2]);
2202 }else {
2203 run_tests();
2204 }
2205
2206 CoUninitialize();
2207 }