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