mfreadwrite/reader: Add missing allocation check (Coverity).
[wine/zf.git] / dlls / vbscript / tests / run.c
blobbb33e6576eaf308ac5944b046b0aceb37fab8d38
1 /*
2 * Copyright 2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdio.h>
21 #define COBJMACROS
22 #define CONST_VTABLE
24 #include <ole2.h>
25 #include <dispex.h>
26 #include <activscp.h>
28 #include "vbsregexp55.h"
30 #include "wine/test.h"
32 #ifdef _WIN64
34 #define IActiveScriptParse_QueryInterface IActiveScriptParse64_QueryInterface
35 #define IActiveScriptParse_Release IActiveScriptParse64_Release
36 #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
37 #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
38 #define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_64_Release
39 #define IActiveScriptParseProcedure2_ParseProcedureText IActiveScriptParseProcedure2_64_ParseProcedureText
41 #else
43 #define IActiveScriptParse_QueryInterface IActiveScriptParse32_QueryInterface
44 #define IActiveScriptParse_Release IActiveScriptParse32_Release
45 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
46 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
47 #define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_32_Release
48 #define IActiveScriptParseProcedure2_ParseProcedureText IActiveScriptParseProcedure2_32_ParseProcedureText
50 #endif
52 extern const CLSID CLSID_VBScript;
53 extern const CLSID CLSID_VBScriptRegExp;
55 #define DEFINE_EXPECT(func) \
56 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
58 #define SET_EXPECT(func) \
59 expect_ ## func = TRUE
61 #define REF_EXPECT(func) \
62 (&expect_ ## func), (&called_ ## func)
64 #define CHECK_EXPECT2(func) \
65 do { \
66 ok(expect_ ##func, "unexpected call " #func "\n"); \
67 called_ ## func = TRUE; \
68 }while(0)
70 #define CHECK_EXPECT(func) \
71 do { \
72 CHECK_EXPECT2(func); \
73 expect_ ## func = FALSE; \
74 }while(0)
76 #define CHECK_CALLED(func) \
77 do { \
78 ok(called_ ## func, "expected " #func "\n"); \
79 expect_ ## func = called_ ## func = FALSE; \
80 }while(0)
82 #define CHECK_NOT_CALLED(func) \
83 do { \
84 ok(!called_ ## func, "unexpected " #func "\n"); \
85 expect_ ## func = called_ ## func = FALSE; \
86 }while(0)
88 #define CLEAR_CALLED(func) \
89 expect_ ## func = called_ ## func = FALSE
91 DEFINE_EXPECT(global_success_d);
92 DEFINE_EXPECT(global_success_i);
93 DEFINE_EXPECT(global_vbvar_d);
94 DEFINE_EXPECT(global_vbvar_i);
95 DEFINE_EXPECT(global_letobj_i);
96 DEFINE_EXPECT(global_setobj_i);
97 DEFINE_EXPECT(global_globalcallback_i);
98 DEFINE_EXPECT(testobj_propget_d);
99 DEFINE_EXPECT(testobj_propget_i);
100 DEFINE_EXPECT(testobj_propput_d);
101 DEFINE_EXPECT(testobj_propput_i);
102 DEFINE_EXPECT(testobj_value_i);
103 DEFINE_EXPECT(testobj_valueput_i);
104 DEFINE_EXPECT(global_propargput_d);
105 DEFINE_EXPECT(global_propargput_i);
106 DEFINE_EXPECT(global_propargput1_d);
107 DEFINE_EXPECT(global_propargput1_i);
108 DEFINE_EXPECT(global_propargset_d);
109 DEFINE_EXPECT(global_propargset_i);
110 DEFINE_EXPECT(global_testoptionalarg_i);
111 DEFINE_EXPECT(global_testerrorobject_i);
112 DEFINE_EXPECT(collectionobj_newenum_i);
113 DEFINE_EXPECT(Next);
114 DEFINE_EXPECT(GetWindow);
115 DEFINE_EXPECT(GetUIBehavior);
116 DEFINE_EXPECT(EnableModeless);
117 DEFINE_EXPECT(OnScriptError);
118 DEFINE_EXPECT(OnEnterScript);
119 DEFINE_EXPECT(OnLeaveScript);
121 #define DISPID_GLOBAL_REPORTSUCCESS 1000
122 #define DISPID_GLOBAL_TRACE 1001
123 #define DISPID_GLOBAL_OK 1002
124 #define DISPID_GLOBAL_GETVT 1003
125 #define DISPID_GLOBAL_ISENGLANG 1004
126 #define DISPID_GLOBAL_VBVAR 1005
127 #define DISPID_GLOBAL_TESTOBJ 1006
128 #define DISPID_GLOBAL_ISNULLDISP 1007
129 #define DISPID_GLOBAL_TESTDISP 1008
130 #define DISPID_GLOBAL_REFOBJ 1009
131 #define DISPID_GLOBAL_COUNTER 1010
132 #define DISPID_GLOBAL_PROPARGPUT 1011
133 #define DISPID_GLOBAL_PROPARGPUT1 1012
134 #define DISPID_GLOBAL_COLLOBJ 1013
135 #define DISPID_GLOBAL_DOUBLEASSTRING 1014
136 #define DISPID_GLOBAL_TESTARRAY 1015
137 #define DISPID_GLOBAL_THROWINT 1016
138 #define DISPID_GLOBAL_TESTOPTIONALARG 1017
139 #define DISPID_GLOBAL_LETOBJ 1018
140 #define DISPID_GLOBAL_SETOBJ 1019
141 #define DISPID_GLOBAL_TODO_WINE_OK 1020
142 #define DISPID_GLOBAL_WEEKSTARTDAY 1021
143 #define DISPID_GLOBAL_GLOBALCALLBACK 1022
144 #define DISPID_GLOBAL_TESTERROROBJECT 1023
145 #define DISPID_GLOBAL_THROWWITHDESC 1024
146 #define DISPID_GLOBAL_PROPARGSET 1025
147 #define DISPID_GLOBAL_UNKOBJ 1026
149 #define DISPID_TESTOBJ_PROPGET 2000
150 #define DISPID_TESTOBJ_PROPPUT 2001
151 #define DISPID_TESTOBJ_KEYWORD 2002
153 #define DISPID_COLLOBJ_RESET 3000
155 #define FACILITY_VBS 0xa
156 #define MAKE_VBSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_VBS, code)
158 static BOOL strict_dispid_check, is_english, allow_ui;
159 static int first_day_of_week;
160 static const char *test_name = "(null)";
161 static int test_counter;
162 static SCRIPTUICHANDLING uic_handling = SCRIPTUICHANDLING_NOUIERROR;
163 static IDispatchEx testObj;
164 static HRESULT onerror_hres = E_NOTIMPL;
165 static BOOL strict_enter_script;
167 static BSTR a2bstr(const char *str)
169 BSTR ret;
170 int len;
172 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
173 ret = SysAllocStringLen(NULL, len-1);
174 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
176 return ret;
179 static const char *vt2a(VARIANT *v)
181 if(V_VT(v) == (VT_BYREF|VT_VARIANT)) {
182 static char buf[64];
183 sprintf(buf, "%s*", vt2a(V_BYREF(v)));
184 return buf;
187 switch(V_VT(v)) {
188 case VT_EMPTY:
189 return "VT_EMPTY";
190 case VT_NULL:
191 return "VT_NULL";
192 case VT_I2:
193 return "VT_I2";
194 case VT_I4:
195 return "VT_I4";
196 case VT_R4:
197 return "VT_R4";
198 case VT_R8:
199 return "VT_R8";
200 case VT_CY:
201 return "VT_CY";
202 case VT_DATE:
203 return "VT_DATE";
204 case VT_BSTR:
205 return "VT_BSTR";
206 case VT_DISPATCH:
207 return "VT_DISPATCH";
208 case VT_UNKNOWN:
209 return "VT_UNKNOWN";
210 case VT_BOOL:
211 return "VT_BOOL";
212 case VT_ARRAY|VT_VARIANT:
213 return "VT_ARRAY|VT_VARIANT";
214 case VT_ARRAY|VT_BYREF|VT_VARIANT:
215 return "VT_ARRAY|VT_BYREF|VT_VARIANT";
216 case VT_UI1:
217 return "VT_UI1";
218 default:
219 ok(0, "unknown vt %d\n", V_VT(v));
220 return NULL;
224 /* Sets is_english to true if the user interface is in English. Note that this
225 * does not presume the formatting of dates, numbers, etc.
226 * Sets first_day_of_week to 1 if Sunday, 2 if Monday, and so on.
228 static void detect_locale(void)
230 HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
231 LANGID (WINAPI *pGetThreadUILanguage)(void) = (void*)GetProcAddress(kernel32, "GetThreadUILanguage");
233 is_english = ((!pGetThreadUILanguage || PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH) &&
234 PRIMARYLANGID(GetUserDefaultUILanguage()) == LANG_ENGLISH &&
235 PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH);
237 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK | LOCALE_RETURN_NUMBER,
238 (void*)&first_day_of_week, sizeof(first_day_of_week));
239 first_day_of_week = 1 + (first_day_of_week + 1) % 7;
242 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
244 ok(0, "unexpected call\n");
245 return E_NOINTERFACE;
248 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
250 return 2;
253 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
255 return 1;
258 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
259 REFIID riid, void **ppv)
261 ok(0, "unexpected service %s\n", wine_dbgstr_guid(guidService));
262 return E_NOINTERFACE;
265 static const IServiceProviderVtbl ServiceProviderVtbl = {
266 ServiceProvider_QueryInterface,
267 ServiceProvider_AddRef,
268 ServiceProvider_Release,
269 ServiceProvider_QueryService
272 static IServiceProvider caller_sp = { &ServiceProviderVtbl };
274 static void test_disp(IDispatch *disp)
276 DISPID id, public_prop_id, public_prop2_id, public_func_id, public_sub_id, defvalget_id, gs_getter_id;
277 DISPID named_args[5] = {DISPID_PROPERTYPUT};
278 VARIANT v, args[5];
279 DISPPARAMS dp = {args, named_args};
280 IDispatchEx *dispex;
281 EXCEPINFO ei = {0};
282 BSTR str;
283 HRESULT hres;
285 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
286 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
288 str = a2bstr("publicProp");
289 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_prop_id);
290 SysFreeString(str);
291 ok(hres == S_OK, "GetDispID(publicProp) failed: %08x\n", hres);
293 str = a2bstr("PUBLICPROP");
294 hres = IDispatchEx_GetDispID(dispex, str, 0, &id);
295 SysFreeString(str);
296 ok(hres == S_OK, "GetDispID(PUBLICPROP) failed: %08x\n", hres);
297 ok(public_prop_id == id, "id = %d\n", public_prop_id);
299 str = a2bstr("publicPROP2");
300 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_prop2_id);
301 SysFreeString(str);
302 ok(hres == S_OK, "GetDispID(publicProp2) failed: %08x\n", hres);
304 str = a2bstr("defValGet");
305 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &defvalget_id);
306 SysFreeString(str);
307 ok(hres == S_OK, "GetDispID(defValGet) failed: %08x\n", hres);
308 ok(defvalget_id == DISPID_VALUE, "id = %d\n", defvalget_id);
310 str = a2bstr("privateProp");
311 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &id);
312 SysFreeString(str);
313 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateProp) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
314 ok(id == -1, "id = %d\n", id);
316 str = a2bstr("class_initialize");
317 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &id);
318 SysFreeString(str);
319 ok(hres == S_OK, "GetDispID(publicProp2) failed: %08x\n", hres);
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_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
325 V_VT(args) = VT_BOOL;
326 V_BOOL(args) = VARIANT_TRUE;
327 dp.cArgs = dp.cNamedArgs = 1;
328 V_VT(&v) = VT_BOOL;
329 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYPUT, &dp, &v, &ei, NULL);
330 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
331 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
333 dp.cArgs = dp.cNamedArgs = 0;
334 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
335 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
336 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
337 ok(V_BOOL(&v), "V_BOOL(v) = %x\n", V_BOOL(&v));
339 dp.cArgs = dp.cNamedArgs = 0;
340 hres = IDispatchEx_Invoke(dispex, public_prop_id, &IID_NULL, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
341 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
342 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
343 ok(V_BOOL(&v), "V_BOOL(v) = %x\n", V_BOOL(&v));
345 dp.cArgs = dp.cNamedArgs = 0;
346 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
347 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
348 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
349 ok(V_BOOL(&v), "V_BOOL(v) = %x\n", V_BOOL(&v));
351 dp.cArgs = 1;
352 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
353 ok(hres == DISP_E_MEMBERNOTFOUND, "InvokeEx failed: %08x, expected DISP_E_MEMBERNOTFOUND\n", hres);
354 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
356 SET_EXPECT(testobj_value_i);
357 V_VT(args) = VT_DISPATCH;
358 V_DISPATCH(args) = (IDispatch*)&testObj;
359 dp.cArgs = dp.cNamedArgs = 1;
360 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYPUT, &dp, NULL, &ei, NULL);
361 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
362 CHECK_CALLED(testobj_value_i);
364 dp.cArgs = dp.cNamedArgs = 0;
365 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
366 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
367 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
368 ok(V_I2(&v) == 0, "V_I2(v) = %d\n", V_I2(&v));
370 V_VT(args) = VT_DISPATCH;
371 V_DISPATCH(args) = (IDispatch*)&testObj;
372 dp.cArgs = dp.cNamedArgs = 1;
373 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYPUT|DISPATCH_PROPERTYPUTREF, &dp, NULL, &ei, NULL);
374 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
376 V_VT(args) = VT_DISPATCH;
377 V_DISPATCH(args) = (IDispatch*)&testObj;
378 dp.cArgs = dp.cNamedArgs = 1;
379 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYPUTREF, &dp, NULL, &ei, NULL);
380 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
382 dp.cArgs = dp.cNamedArgs = 0;
383 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
384 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
385 ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v));
386 ok(V_DISPATCH(&v) == (IDispatch*)&testObj, "V_DISPATCH(v) != testObj\n");
388 V_VT(args) = VT_BOOL;
389 V_BOOL(args) = VARIANT_TRUE;
390 dp.cArgs = dp.cNamedArgs = 1;
391 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYPUT|DISPATCH_PROPERTYPUTREF, &dp, NULL, &ei, NULL);
392 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
394 dp.cArgs = dp.cNamedArgs = 0;
395 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
396 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
397 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
398 ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v));
400 V_VT(args) = VT_BOOL;
401 V_BOOL(args) = VARIANT_FALSE;
402 dp.cArgs = dp.cNamedArgs = 1;
403 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYPUTREF, &dp, NULL, &ei, NULL);
404 ok(hres == DISP_E_EXCEPTION, "InvokeEx failed: %08x, expected DISP_E_EXCEPTION\n", hres);
406 V_VT(args) = VT_BOOL;
407 V_BOOL(args) = VARIANT_FALSE;
408 dp.cArgs = 1;
409 dp.cNamedArgs = 0;
410 V_VT(&v) = VT_BOOL;
411 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYPUT, &dp, NULL, &ei, NULL);
412 ok(hres == DISP_E_PARAMNOTOPTIONAL, "InvokeEx failed: %08x, expected DISP_E_PARAMNOTOPTIONAL\n", hres);
414 str = a2bstr("publicFunction");
415 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_func_id);
416 SysFreeString(str);
417 ok(hres == S_OK, "GetDispID(publicFunction) failed: %08x\n", hres);
418 ok(public_func_id != -1, "public_func_id = -1\n");
420 str = a2bstr("publicSub");
421 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_sub_id);
422 SysFreeString(str);
423 ok(hres == S_OK, "GetDispID(publicSub) failed: %08x\n", hres);
424 ok(public_sub_id != -1, "public_func_id = -1\n");
426 dp.cArgs = dp.cNamedArgs = 0;
427 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
428 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
429 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
430 ok(V_I2(&v) == 4, "V_I2(v) = %d\n", V_I2(&v));
432 dp.cArgs = dp.cNamedArgs = 0;
433 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
434 ok(hres == DISP_E_MEMBERNOTFOUND, "InvokeEx failed: %08x, expected DISP_E_MEMBERNOTFOUND\n", hres);
435 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
437 dp.cArgs = dp.cNamedArgs = 0;
438 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
439 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
440 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
441 ok(V_I2(&v) == 4, "V_I2(v) = %d\n", V_I2(&v));
443 dp.cArgs = dp.cNamedArgs = 0;
444 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
445 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
446 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
448 dp.cArgs = dp.cNamedArgs = 0;
449 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
450 ok(hres == DISP_E_MEMBERNOTFOUND, "InvokeEx failed: %08x, expected DISP_E_MEMBERNOTFOUND\n", hres);
451 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
453 dp.cArgs = dp.cNamedArgs = 0;
454 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
455 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
456 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
458 V_VT(args) = VT_BOOL;
459 V_BOOL(args) = VARIANT_TRUE;
460 dp.cArgs = dp.cNamedArgs = 1;
461 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_PROPERTYPUT, &dp, NULL, &ei, NULL);
462 ok(FAILED(hres), "InvokeEx succeeded: %08x\n", hres);
464 dp.cArgs = dp.cNamedArgs = 0;
465 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
466 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
467 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
468 ok(V_I2(&v) == 4, "V_I2(v) = %d\n", V_I2(&v));
470 dp.cArgs = dp.cNamedArgs = 0;
471 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
472 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
473 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
474 ok(V_I2(&v) == 4, "V_I2(v) = %d\n", V_I2(&v));
476 dp.cArgs = dp.cNamedArgs = 0;
477 hres = IDispatchEx_Invoke(dispex, public_func_id, &IID_NULL, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
478 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
479 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
480 ok(V_I2(&v) == 4, "V_I2(v) = %d\n", V_I2(&v));
482 dp.cArgs = dp.cNamedArgs = 0;
483 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
484 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
485 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
487 dp.cArgs = dp.cNamedArgs = 0;
488 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
489 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
490 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
492 str = a2bstr("privateSub");
493 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &id);
494 SysFreeString(str);
495 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateSub) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
496 ok(id == -1, "id = %d\n", id);
498 str = a2bstr("dynprop");
499 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive|fdexNameEnsure, &id);
500 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateProp) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
501 ok(id == -1, "id = %d\n", id);
502 hres = IDispatchEx_GetDispID(dispex, str, fdexNameEnsure, &id);
503 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateProp) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
504 ok(id == -1, "id = %d\n", id);
505 SysFreeString(str);
507 str = a2bstr("publicProp");
508 hres = IDispatchEx_GetDispID(dispex, str, 0x80000000|fdexNameCaseInsensitive, &public_prop_id);
509 SysFreeString(str);
510 ok(hres == S_OK, "GetDispID(publicProp) failed: %08x\n", hres);
512 id = 0xdeadbeef;
513 str = a2bstr("publicProp");
514 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
515 SysFreeString(str);
516 ok(hres == S_OK, "GetDispID(publicProp) failed: %08x\n", hres);
517 ok(id == public_prop_id, "id = %d, expected %d\n", id, public_prop_id);
519 id = 0xdeadbeef;
520 str = a2bstr("publicprop");
521 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
522 SysFreeString(str);
523 ok(hres == S_OK, "GetDispID(publicProp) failed: %08x\n", hres);
524 ok(id == public_prop_id, "id = %d, expected %d\n", id, public_prop_id);
526 str = a2bstr("gsGetProp");
527 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &gs_getter_id);
528 SysFreeString(str);
529 ok(hres == S_OK, "GetDispID(publicFunction) failed: %08x\n", hres);
530 ok(gs_getter_id != -1, "gs_getter_id = -1\n");
532 V_VT(args) = VT_BOOL;
533 V_BOOL(args) = VARIANT_TRUE;
534 dp.cNamedArgs = 0;
535 dp.cArgs = 1;
536 V_VT(&v) = VT_I8;
537 hres = IDispatchEx_InvokeEx(dispex, gs_getter_id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
538 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
539 ok(V_VT(&v) == VT_BOOL && V_BOOL(&v), "V_VT(v) = %d\n", V_VT(&v));
541 hres = IDispatchEx_InvokeEx(dispex, gs_getter_id, 0, DISPATCH_PROPERTYGET, &dp, NULL, &ei, NULL);
542 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
544 V_VT(args) = VT_BOOL;
545 V_BOOL(args) = VARIANT_FALSE;
546 dp.cArgs = 1;
547 V_VT(&v) = VT_I8;
548 hres = IDispatchEx_InvokeEx(dispex, gs_getter_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
549 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
550 ok(V_VT(&v) == VT_BOOL && !V_BOOL(&v), "V_VT(v) = %d\n", V_VT(&v));
552 V_VT(args) = VT_BOOL;
553 V_BOOL(args) = VARIANT_TRUE;
554 V_VT(&v) = VT_I8;
555 dp.cArgs = 1;
556 hres = IDispatchEx_InvokeEx(dispex, gs_getter_id, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
557 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
558 ok(V_VT(&v) == VT_BOOL && V_BOOL(&v), "V_VT(v) = %d\n", V_VT(&v));
560 IDispatchEx_Release(dispex);
563 static void test_safearray(SAFEARRAY *safearray, unsigned indims)
565 int i, exdims = indims;
567 if(!exdims)
568 exdims = 1;
569 ok(safearray->cDims == exdims, "safearray->cDims = %d, expected %d\n", safearray->cDims, exdims);
570 todo_wine
571 ok(safearray->fFeatures == (FADF_VARIANT|FADF_HAVEVARTYPE|FADF_FIXEDSIZE|FADF_STATIC),
572 "safearray->fFeatures = %x\n", safearray->fFeatures);
573 ok(safearray->cbElements == sizeof(VARIANT), "safearray->cbElements = %x\n", safearray->cbElements);
574 ok(!safearray->cLocks, "safearray->cLocks = %x\n", safearray->cLocks);
576 for(i=0; i < safearray->cDims; i++) {
577 ok(safearray->rgsabound[i].cElements == (indims ? i+4 : 1), "safearray->rgsabound[%d].cElements = %d\n", i,
578 safearray->rgsabound[i].cElements);
579 ok(!safearray->rgsabound[i].lLbound, "safearray->rgsabound[%d].lLbound = %d\n", i, safearray->rgsabound[i].lLbound);
583 #define test_grfdex(a,b) _test_grfdex(__LINE__,a,b)
584 static void _test_grfdex(unsigned line, DWORD grfdex, DWORD expect)
586 ok_(__FILE__,line)(grfdex == expect, "grfdex = %x, expected %x\n", grfdex, expect);
589 static IDispatchEx enumDisp;
591 static HRESULT WINAPI unkObj_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
593 if(IsEqualGUID(riid, &IID_IUnknown)) {
594 *ppv = iface;
595 return S_OK;
598 *ppv = NULL;
599 return E_NOINTERFACE;
602 static ULONG WINAPI unkObj_AddRef(IUnknown *iface)
604 return 2;
607 static ULONG WINAPI unkObj_Release(IUnknown *iface)
609 return 1;
612 static const IUnknownVtbl unkObjVtbl = {
613 unkObj_QueryInterface,
614 unkObj_AddRef,
615 unkObj_Release
618 static IUnknown unkObj = { &unkObjVtbl };
620 static HRESULT WINAPI EnumVARIANT_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv)
622 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IEnumVARIANT)) {
623 *ppv = iface;
624 return S_OK;
627 if(IsEqualGUID(riid, &IID_IDispatch)) {
628 *ppv = &enumDisp;
629 return S_OK;
632 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid));
633 return E_NOINTERFACE;
636 static ULONG WINAPI EnumVARIANT_AddRef(IEnumVARIANT *iface)
638 return 2;
641 static ULONG WINAPI EnumVARIANT_Release(IEnumVARIANT *iface)
643 return 1;
646 static unsigned next_cnt;
648 static HRESULT WINAPI EnumVARIANT_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
650 if(strict_dispid_check)
651 CHECK_EXPECT2(Next);
653 ok(celt == 1, "celt = %d\n", celt);
654 ok(V_VT(rgVar) == VT_EMPTY, "V_VT(rgVar) = %d\n", V_VT(rgVar));
655 ok(!pCeltFetched, "pCeltFetched = %p\n", pCeltFetched);
657 if(next_cnt++ < 3) {
658 V_VT(rgVar) = VT_I2;
659 V_I2(rgVar) = next_cnt;
660 return S_OK;
663 return S_FALSE;
666 static HRESULT WINAPI EnumVARIANT_Skip(IEnumVARIANT *iface, ULONG celt)
668 ok(0, "unexpected call\n");
669 return E_NOTIMPL;
672 static HRESULT WINAPI EnumVARIANT_Reset(IEnumVARIANT *iface)
674 ok(0, "unexpected call\n");
675 return E_NOTIMPL;
678 static HRESULT WINAPI EnumVARIANT_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum)
680 ok(0, "unexpected call\n");
681 return E_NOTIMPL;
684 static const IEnumVARIANTVtbl EnumVARIANTVtbl = {
685 EnumVARIANT_QueryInterface,
686 EnumVARIANT_AddRef,
687 EnumVARIANT_Release,
688 EnumVARIANT_Next,
689 EnumVARIANT_Skip,
690 EnumVARIANT_Reset,
691 EnumVARIANT_Clone
694 static IEnumVARIANT enumObj = { &EnumVARIANTVtbl };
696 typedef struct {
697 const WCHAR *name;
698 DISPID pid;
699 BOOL *expect;
700 BOOL *called;
701 } dispid_t;
703 static BOOL get_dispid(BSTR name, const dispid_t *dispids, SIZE_T dispids_cnt, DISPID *id)
705 int i;
707 for(i = 0; i < dispids_cnt; i++) {
708 if(!wcsicmp(name, dispids[i].name)) {
709 const dispid_t *d = &dispids[i];
710 if(d->expect) {
711 ok(*d->expect, "unexpected call %s\n", wine_dbgstr_w(d->name));
712 *d->called = TRUE;
713 *d->expect = FALSE;
715 *id = d->pid;
716 return TRUE;
720 return FALSE;
723 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
725 *ppv = NULL;
727 if(IsEqualGUID(riid, &IID_IUnknown)
728 || IsEqualGUID(riid, &IID_IDispatch)
729 || IsEqualGUID(riid, &IID_IDispatchEx))
730 *ppv = iface;
731 else {
732 trace("QI %s\n", wine_dbgstr_guid(riid));
733 return E_NOINTERFACE;
736 IUnknown_AddRef((IUnknown*)*ppv);
737 return S_OK;
740 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
742 return 2;
745 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
747 return 1;
750 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
752 ok(0, "unexpected call\n");
753 return E_NOTIMPL;
756 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
757 LCID lcid, ITypeInfo **ppTInfo)
759 return E_NOTIMPL;
762 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
763 LPOLESTR *rgszNames, UINT cNames,
764 LCID lcid, DISPID *rgDispId)
766 ok(0, "unexpected call\n");
767 return E_NOTIMPL;
770 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
771 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
772 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
774 ok(0, "unexpected call\n");
775 return E_NOTIMPL;
778 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
780 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
781 return E_NOTIMPL;
784 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
786 ok(0, "unexpected call\n");
787 return E_NOTIMPL;
790 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
792 ok(0, "unexpected call\n");
793 return E_NOTIMPL;
796 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
798 ok(0, "unexpected call\n");
799 return E_NOTIMPL;
802 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
804 ok(0, "unexpected call\n");
805 return E_NOTIMPL;
808 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
810 ok(0, "unexpected call\n");
811 return E_NOTIMPL;
814 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
816 ok(0, "unexpected call\n");
817 return E_NOTIMPL;
820 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
821 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
823 ok(0, "unexpected call %d\n", id);
824 return E_NOTIMPL;
827 static HRESULT WINAPI testObj_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
829 static const dispid_t dispids[] = {
830 { L"propget", DISPID_TESTOBJ_PROPGET, REF_EXPECT(testobj_propget_d) },
831 { L"propput", DISPID_TESTOBJ_PROPPUT, REF_EXPECT(testobj_propput_d) },
832 { L"rem", DISPID_TESTOBJ_KEYWORD },
833 { L"true", DISPID_TESTOBJ_KEYWORD },
834 { L"false", DISPID_TESTOBJ_KEYWORD },
835 { L"not", DISPID_TESTOBJ_KEYWORD },
836 { L"and", DISPID_TESTOBJ_KEYWORD },
837 { L"or", DISPID_TESTOBJ_KEYWORD },
838 { L"xor", DISPID_TESTOBJ_KEYWORD },
839 { L"eqv", DISPID_TESTOBJ_KEYWORD },
840 { L"imp", DISPID_TESTOBJ_KEYWORD },
841 { L"is", DISPID_TESTOBJ_KEYWORD },
842 { L"mod", DISPID_TESTOBJ_KEYWORD },
843 { L"call", DISPID_TESTOBJ_KEYWORD },
844 { L"dim", DISPID_TESTOBJ_KEYWORD },
845 { L"sub", DISPID_TESTOBJ_KEYWORD },
846 { L"function", DISPID_TESTOBJ_KEYWORD },
847 { L"get", DISPID_TESTOBJ_KEYWORD },
848 { L"let", DISPID_TESTOBJ_KEYWORD },
849 { L"const", DISPID_TESTOBJ_KEYWORD },
850 { L"if", DISPID_TESTOBJ_KEYWORD },
851 { L"else", DISPID_TESTOBJ_KEYWORD },
852 { L"elseif", DISPID_TESTOBJ_KEYWORD },
853 { L"end", DISPID_TESTOBJ_KEYWORD },
854 { L"then", DISPID_TESTOBJ_KEYWORD },
855 { L"exit", DISPID_TESTOBJ_KEYWORD },
856 { L"while", DISPID_TESTOBJ_KEYWORD },
857 { L"wend", DISPID_TESTOBJ_KEYWORD },
858 { L"do", DISPID_TESTOBJ_KEYWORD },
859 { L"loop", DISPID_TESTOBJ_KEYWORD },
860 { L"until", DISPID_TESTOBJ_KEYWORD },
861 { L"for", DISPID_TESTOBJ_KEYWORD },
862 { L"to", DISPID_TESTOBJ_KEYWORD },
863 { L"each", DISPID_TESTOBJ_KEYWORD },
864 { L"in", DISPID_TESTOBJ_KEYWORD },
865 { L"select", DISPID_TESTOBJ_KEYWORD },
866 { L"case", DISPID_TESTOBJ_KEYWORD },
867 { L"byref", DISPID_TESTOBJ_KEYWORD },
868 { L"byval", DISPID_TESTOBJ_KEYWORD },
869 { L"option", DISPID_TESTOBJ_KEYWORD },
870 { L"nothing", DISPID_TESTOBJ_KEYWORD },
871 { L"empty", DISPID_TESTOBJ_KEYWORD },
872 { L"null", DISPID_TESTOBJ_KEYWORD },
873 { L"class", DISPID_TESTOBJ_KEYWORD },
874 { L"set", DISPID_TESTOBJ_KEYWORD },
875 { L"new", DISPID_TESTOBJ_KEYWORD },
876 { L"public", DISPID_TESTOBJ_KEYWORD },
877 { L"private", DISPID_TESTOBJ_KEYWORD },
878 { L"next", DISPID_TESTOBJ_KEYWORD },
879 { L"on", DISPID_TESTOBJ_KEYWORD },
880 { L"resume", DISPID_TESTOBJ_KEYWORD },
881 { L"goto", DISPID_TESTOBJ_KEYWORD },
882 { L"redim", DISPID_TESTOBJ_KEYWORD },
883 { L"preserve", DISPID_TESTOBJ_KEYWORD },
884 { L"with", DISPID_TESTOBJ_KEYWORD },
885 { L"property", DISPID_TESTOBJ_KEYWORD },
886 { L"me", DISPID_TESTOBJ_KEYWORD },
887 { L"stop", DISPID_TESTOBJ_KEYWORD }
890 test_grfdex(grfdex, fdexNameCaseInsensitive);
891 if(get_dispid(bstrName, dispids, ARRAY_SIZE(dispids), pid))
892 return S_OK;
893 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
894 return DISP_E_UNKNOWNNAME;
897 static HRESULT WINAPI testObj_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
898 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
900 switch(id) {
901 case DISPID_VALUE:
902 if(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD)) {
903 VARIANT *arg;
904 int i;
906 CHECK_EXPECT(testobj_value_i);
908 ok(pdp != NULL, "pdp == NULL\n");
909 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
910 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
911 ok(pvarRes != NULL, "pvarRes == NULL\n");
912 ok(pei != NULL, "pei == NULL\n");
914 for(i=0; i<pdp->cArgs; i++) {
915 arg = pdp->rgvarg+pdp->cArgs-i-1;
916 ok(V_VT(arg) == VT_I2, "V_VT(arg) = %d\n", V_VT(arg));
917 ok(V_I2(arg) == i+1, "V_I2(arg) = %d\n", V_I2(arg));
920 V_VT(pvarRes) = VT_I2;
921 V_I2(pvarRes) = pdp->cArgs;
922 return S_OK;
924 if(wFlags == DISPATCH_PROPERTYPUT) {
925 CHECK_EXPECT(testobj_valueput_i);
927 ok(pdp->cArgs == 3, "cArgs = %d\n", pdp->cArgs);
928 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
929 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
930 ok(!pvarRes, "pvarRes != NULL\n");
931 ok(pei != NULL, "pei == NULL\n");
933 ok(V_VT(pdp->rgvarg) == VT_I2, "V_VT(args[0]) = %d\n", V_VT(pdp->rgvarg));
934 ok(V_I2(pdp->rgvarg) == 0, "V_I2(args[0]) = %d\n", V_I2(pdp->rgvarg));
935 ok(V_VT(pdp->rgvarg+1) == VT_I2, "V_VT(args[1]) = %d\n", V_VT(pdp->rgvarg+1));
936 ok(V_I2(pdp->rgvarg+1) == 2, "V_I2(args[1]) = %d\n", V_I2(pdp->rgvarg+1));
937 ok(V_VT(pdp->rgvarg+2) == VT_I2, "V_VT(args[2]) = %d\n", V_VT(pdp->rgvarg+2));
938 ok(V_I2(pdp->rgvarg+2) == 1, "V_I2(args[2]) = %d\n", V_I2(pdp->rgvarg+2));
940 return S_OK;
942 ok(0, "wFlags = %x\n", wFlags);
943 break;
944 case DISPID_TESTOBJ_PROPGET:
945 CHECK_EXPECT(testobj_propget_i);
947 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
948 ok(pdp != NULL, "pdp == NULL\n");
949 ok(!pdp->rgvarg, "rgvarg == NULL\n");
950 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
951 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
952 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
953 ok(pvarRes != NULL, "pvarRes == NULL\n");
954 ok(pei != NULL, "pei == NULL\n");
956 V_VT(pvarRes) = VT_I2;
957 V_I2(pvarRes) = 10;
958 return S_OK;
959 case DISPID_TESTOBJ_PROPPUT:
960 CHECK_EXPECT(testobj_propput_i);
962 ok(wFlags == DISPATCH_PROPERTYPUT, "wFlags = %x\n", wFlags);
963 ok(pdp != NULL, "pdp == NULL\n");
964 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
965 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
966 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
967 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
968 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
969 ok(!pvarRes, "pvarRes != NULL\n");
970 ok(pei != NULL, "pei == NULL\n");
972 ok(V_VT(pdp->rgvarg) == VT_I2, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
973 ok(V_I2(pdp->rgvarg) == 1, "V_I2(psp->rgvargs) = %d\n", V_I2(pdp->rgvarg));
974 return S_OK;
976 case DISPID_TESTOBJ_KEYWORD:
977 V_VT(pvarRes) = VT_I2;
978 V_I2(pvarRes) = 10;
979 return S_OK;
982 ok(0, "unexpected call %d\n", id);
983 return E_FAIL;
986 static IDispatchExVtbl testObjVtbl = {
987 DispatchEx_QueryInterface,
988 DispatchEx_AddRef,
989 DispatchEx_Release,
990 DispatchEx_GetTypeInfoCount,
991 DispatchEx_GetTypeInfo,
992 DispatchEx_GetIDsOfNames,
993 DispatchEx_Invoke,
994 testObj_GetDispID,
995 testObj_InvokeEx,
996 DispatchEx_DeleteMemberByName,
997 DispatchEx_DeleteMemberByDispID,
998 DispatchEx_GetMemberProperties,
999 DispatchEx_GetMemberName,
1000 DispatchEx_GetNextDispID,
1001 DispatchEx_GetNameSpaceParent
1004 static IDispatchEx testObj = { &testObjVtbl };
1006 static HRESULT WINAPI enumDisp_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1008 return IEnumVARIANT_QueryInterface(&enumObj, riid, ppv);
1011 static IDispatchExVtbl enumDispVtbl = {
1012 enumDisp_QueryInterface,
1013 DispatchEx_AddRef,
1014 DispatchEx_Release,
1015 DispatchEx_GetTypeInfoCount,
1016 DispatchEx_GetTypeInfo,
1017 DispatchEx_GetIDsOfNames,
1018 DispatchEx_Invoke,
1019 DispatchEx_GetDispID,
1020 DispatchEx_InvokeEx,
1021 DispatchEx_DeleteMemberByName,
1022 DispatchEx_DeleteMemberByDispID,
1023 DispatchEx_GetMemberProperties,
1024 DispatchEx_GetMemberName,
1025 DispatchEx_GetNextDispID,
1026 DispatchEx_GetNameSpaceParent
1029 static IDispatchEx enumDisp = { &enumDispVtbl };
1031 static HRESULT WINAPI collectionObj_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1033 if(!lstrcmpW(bstrName, L"reset")) {
1034 *pid = DISPID_COLLOBJ_RESET;
1035 return S_OK;
1038 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
1039 return DISP_E_UNKNOWNNAME;
1042 static HRESULT WINAPI collectionObj_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1043 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1045 switch(id) {
1046 case DISPID_NEWENUM:
1047 if(strict_dispid_check)
1048 CHECK_EXPECT(collectionobj_newenum_i);
1050 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
1051 ok(pdp != NULL, "pdp == NULL\n");
1052 ok(!pdp->rgvarg, "rgvarg == NULL\n");
1053 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1054 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1055 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1056 ok(pvarRes != NULL, "pvarRes == NULL\n");
1057 ok(pei != NULL, "pei == NULL\n");
1059 V_VT(pvarRes) = VT_UNKNOWN;
1060 V_UNKNOWN(pvarRes) = (IUnknown*)&enumObj;
1061 return S_OK;
1062 case DISPID_COLLOBJ_RESET:
1063 next_cnt = 0;
1064 return S_OK;
1067 ok(0, "unexpected call %d\n", id);
1068 return E_NOTIMPL;
1071 static IDispatchExVtbl collectionObjVtbl = {
1072 DispatchEx_QueryInterface,
1073 DispatchEx_AddRef,
1074 DispatchEx_Release,
1075 DispatchEx_GetTypeInfoCount,
1076 DispatchEx_GetTypeInfo,
1077 DispatchEx_GetIDsOfNames,
1078 DispatchEx_Invoke,
1079 collectionObj_GetDispID,
1080 collectionObj_InvokeEx,
1081 DispatchEx_DeleteMemberByName,
1082 DispatchEx_DeleteMemberByDispID,
1083 DispatchEx_GetMemberProperties,
1084 DispatchEx_GetMemberName,
1085 DispatchEx_GetNextDispID,
1086 DispatchEx_GetNameSpaceParent
1089 static IDispatchEx collectionObj = { &collectionObjVtbl };
1091 static ULONG refobj_ref;
1093 static ULONG WINAPI RefObj_AddRef(IDispatchEx *iface)
1095 return ++refobj_ref;
1098 static ULONG WINAPI RefObj_Release(IDispatchEx *iface)
1100 return --refobj_ref;
1103 static IDispatchExVtbl RefObjVtbl = {
1104 DispatchEx_QueryInterface,
1105 RefObj_AddRef,
1106 RefObj_Release,
1107 DispatchEx_GetTypeInfoCount,
1108 DispatchEx_GetTypeInfo,
1109 DispatchEx_GetIDsOfNames,
1110 DispatchEx_Invoke,
1111 DispatchEx_GetDispID,
1112 DispatchEx_InvokeEx,
1113 DispatchEx_DeleteMemberByName,
1114 DispatchEx_DeleteMemberByDispID,
1115 DispatchEx_GetMemberProperties,
1116 DispatchEx_GetMemberName,
1117 DispatchEx_GetNextDispID,
1118 DispatchEx_GetNameSpaceParent
1121 static IDispatchEx RefObj = { &RefObjVtbl };
1123 static ULONG global_ref;
1125 static ULONG WINAPI Global_AddRef(IDispatchEx *iface)
1127 return ++global_ref;
1130 static ULONG WINAPI Global_Release(IDispatchEx *iface)
1132 return --global_ref;
1135 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1137 static const dispid_t dispids[] = {
1138 { L"ok", DISPID_GLOBAL_OK },
1139 { L"todo_wine_ok", DISPID_GLOBAL_TODO_WINE_OK },
1140 { L"trace", DISPID_GLOBAL_TRACE },
1141 { L"reportSuccess", DISPID_GLOBAL_REPORTSUCCESS, REF_EXPECT(global_success_d) },
1142 { L"getVT", DISPID_GLOBAL_GETVT },
1143 { L"isEnglishLang", DISPID_GLOBAL_ISENGLANG },
1144 { L"firstDayOfWeek", DISPID_GLOBAL_WEEKSTARTDAY },
1145 { L"globalCallback", DISPID_GLOBAL_GLOBALCALLBACK },
1146 { L"testObj", DISPID_GLOBAL_TESTOBJ },
1147 { L"collectionObj" , DISPID_GLOBAL_COLLOBJ },
1148 { L"vbvar", DISPID_GLOBAL_VBVAR, REF_EXPECT(global_vbvar_d) },
1149 { L"letobj", DISPID_GLOBAL_LETOBJ },
1150 { L"setobj", DISPID_GLOBAL_SETOBJ },
1151 { L"isNullDisp", DISPID_GLOBAL_ISNULLDISP },
1152 { L"testDisp", DISPID_GLOBAL_TESTDISP },
1153 { L"RefObj", DISPID_GLOBAL_REFOBJ },
1154 { L"propargput", DISPID_GLOBAL_PROPARGPUT, REF_EXPECT(global_propargput_d) },
1155 { L"propargput1", DISPID_GLOBAL_PROPARGPUT1, REF_EXPECT(global_propargput1_d) },
1156 { L"propargset", DISPID_GLOBAL_PROPARGSET, REF_EXPECT(global_propargset_d) },
1157 { L"counter", DISPID_GLOBAL_COUNTER },
1158 { L"doubleAsString", DISPID_GLOBAL_DOUBLEASSTRING },
1159 { L"testArray", DISPID_GLOBAL_TESTARRAY },
1160 { L"throwInt", DISPID_GLOBAL_THROWINT },
1161 { L"testOptionalArg", DISPID_GLOBAL_TESTOPTIONALARG },
1162 { L"testErrorObject", DISPID_GLOBAL_TESTERROROBJECT },
1163 { L"throwWithDesc", DISPID_GLOBAL_THROWWITHDESC },
1164 { L"unkObj", DISPID_GLOBAL_UNKOBJ }
1167 test_grfdex(grfdex, fdexNameCaseInsensitive);
1168 if(get_dispid(bstrName, dispids, ARRAY_SIZE(dispids), pid))
1169 return S_OK;
1170 if(strict_dispid_check && wcscmp(bstrName, L"x"))
1171 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
1172 return DISP_E_UNKNOWNNAME;
1175 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1176 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1178 switch(id) {
1179 case DISPID_GLOBAL_TODO_WINE_OK:
1180 case DISPID_GLOBAL_OK: {
1181 VARIANT *b;
1183 ok(wFlags == INVOKE_FUNC || 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 == 2, "cArgs = %d\n", pdp->cArgs);
1188 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1189 if(wFlags & INVOKE_PROPERTYGET)
1190 ok(pvarRes != NULL, "pvarRes == NULL\n");
1191 else
1192 ok(!pvarRes, "pvarRes != NULL\n");
1193 ok(pei != NULL, "pei == NULL\n");
1195 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1197 b = pdp->rgvarg+1;
1198 if(V_VT(b) == (VT_BYREF|VT_VARIANT))
1199 b = V_BYREF(b);
1201 ok(V_VT(b) == VT_BOOL, "V_VT(b) = %d\n", V_VT(b));
1203 todo_wine_if(id == DISPID_GLOBAL_TODO_WINE_OK)
1204 ok(V_BOOL(b), "%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
1205 return S_OK;
1208 case DISPID_GLOBAL_TRACE:
1209 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1210 ok(pdp != NULL, "pdp == NULL\n");
1211 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1212 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1213 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1214 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1215 ok(!pvarRes, "pvarRes != NULL\n");
1216 ok(pei != NULL, "pei == NULL\n");
1218 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1219 if(V_VT(pdp->rgvarg) == VT_BSTR)
1220 trace("%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
1222 return S_OK;
1224 case DISPID_GLOBAL_REPORTSUCCESS:
1225 CHECK_EXPECT(global_success_i);
1227 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1228 ok(pdp != NULL, "pdp == NULL\n");
1229 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1230 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
1231 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1232 ok(!pvarRes, "pvarRes != NULL\n");
1233 ok(pei != NULL, "pei == NULL\n");
1235 return S_OK;
1237 case DISPID_GLOBAL_GETVT:
1238 ok(pdp != NULL, "pdp == NULL\n");
1239 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1240 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1241 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1242 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1243 ok(pvarRes != NULL, "pvarRes == NULL\n");
1244 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1245 ok(pei != NULL, "pei == NULL\n");
1247 V_VT(pvarRes) = VT_BSTR;
1248 V_BSTR(pvarRes) = a2bstr(vt2a(pdp->rgvarg));
1249 return S_OK;
1251 case DISPID_GLOBAL_ISENGLANG:
1252 ok(wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
1253 ok(pdp != NULL, "pdp == NULL\n");
1254 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1255 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
1256 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1257 ok(pvarRes != NULL, "pvarRes == NULL\n");
1258 ok(pei != NULL, "pei == NULL\n");
1260 V_VT(pvarRes) = VT_BOOL;
1261 V_BOOL(pvarRes) = is_english ? VARIANT_TRUE : VARIANT_FALSE;
1262 return S_OK;
1264 case DISPID_GLOBAL_WEEKSTARTDAY:
1265 V_VT(pvarRes) = VT_I4;
1266 V_I4(pvarRes) = first_day_of_week;
1267 return S_OK;
1269 case DISPID_GLOBAL_VBVAR:
1270 CHECK_EXPECT(global_vbvar_i);
1272 ok(wFlags == DISPATCH_PROPERTYPUT, "wFlags = %x\n", wFlags);
1273 ok(pdp != NULL, "pdp == NULL\n");
1274 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1275 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
1276 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1277 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
1278 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
1279 ok(!pvarRes, "pvarRes != NULL\n");
1280 ok(pei != NULL, "pei == NULL\n");
1282 ok(V_VT(pdp->rgvarg) == VT_I2, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1283 ok(V_I2(pdp->rgvarg) == 3, "V_I2(psp->rgvargs) = %d\n", V_I2(pdp->rgvarg));
1284 return S_OK;
1286 case DISPID_GLOBAL_LETOBJ:
1287 CHECK_EXPECT(global_letobj_i);
1289 ok(wFlags == DISPATCH_PROPERTYPUT, "wFlags = %x\n", wFlags);
1290 ok(pdp != NULL, "pdp == NULL\n");
1291 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1292 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
1293 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1294 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
1295 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
1296 ok(!pvarRes, "pvarRes != NULL\n");
1297 ok(pei != NULL, "pei == NULL\n");
1299 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1300 ok(V_DISPATCH(pdp->rgvarg) == (IDispatch*)&testObj, "V_DISPATCH(psp->rgvargs) != testObj\n");
1301 return S_OK;
1303 case DISPID_GLOBAL_SETOBJ:
1304 CHECK_EXPECT(global_setobj_i);
1306 ok(wFlags == DISPATCH_PROPERTYPUTREF, "wFlags = %x\n", wFlags);
1307 ok(pdp != NULL, "pdp == NULL\n");
1308 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1309 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
1310 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1311 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
1312 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
1313 ok(!pvarRes, "pvarRes != NULL\n");
1314 ok(pei != NULL, "pei == NULL\n");
1316 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1317 ok(V_DISPATCH(pdp->rgvarg) == (IDispatch*)&testObj, "V_DISPATCH(psp->rgvargs) != testObj\n");
1318 return S_OK;
1320 case DISPID_GLOBAL_TESTOBJ:
1321 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
1323 ok(pdp != NULL, "pdp == NULL\n");
1324 ok(!pdp->rgvarg, "rgvarg != NULL\n");
1325 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1326 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1327 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1328 ok(pvarRes != NULL, "pvarRes == NULL\n");
1329 ok(pei != NULL, "pei == NULL\n");
1331 V_VT(pvarRes) = VT_DISPATCH;
1332 V_DISPATCH(pvarRes) = (IDispatch*)&testObj;
1333 return S_OK;
1335 case DISPID_GLOBAL_COLLOBJ:
1336 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
1338 ok(pdp != NULL, "pdp == NULL\n");
1339 ok(!pdp->rgvarg, "rgvarg != NULL\n");
1340 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1341 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1342 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1343 ok(pvarRes != NULL, "pvarRes == NULL\n");
1344 ok(pei != NULL, "pei == NULL\n");
1346 V_VT(pvarRes) = VT_DISPATCH;
1347 V_DISPATCH(pvarRes) = (IDispatch*)&collectionObj;
1348 return S_OK;
1350 case DISPID_GLOBAL_REFOBJ:
1351 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
1353 ok(pdp != NULL, "pdp == NULL\n");
1354 ok(!pdp->rgvarg, "rgvarg == NULL\n");
1355 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1356 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1357 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1358 ok(pvarRes != NULL, "pvarRes == NULL\n");
1359 ok(pei != NULL, "pei == NULL\n");
1361 IDispatchEx_AddRef(&RefObj);
1362 V_VT(pvarRes) = VT_DISPATCH;
1363 V_DISPATCH(pvarRes) = (IDispatch*)&RefObj;
1364 return S_OK;
1366 case DISPID_GLOBAL_ISNULLDISP: {
1367 VARIANT *v;
1369 ok(wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
1370 ok(pdp != NULL, "pdp == NULL\n");
1371 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1372 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1373 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1374 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1375 ok(pvarRes != NULL, "pvarRes == NULL\n");
1376 ok(pei != NULL, "pei == NULL\n");
1378 v = pdp->rgvarg;
1379 if(V_VT(v) == (VT_VARIANT|VT_BYREF))
1380 v = V_VARIANTREF(v);
1382 ok(V_VT(v) == VT_DISPATCH, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1383 V_VT(pvarRes) = VT_BOOL;
1384 V_BOOL(pvarRes) = V_DISPATCH(v) ? VARIANT_FALSE : VARIANT_TRUE;
1385 return S_OK;
1388 case DISPID_GLOBAL_TESTDISP:
1389 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1390 ok(pdp != NULL, "pdp == NULL\n");
1391 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1392 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1393 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1394 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1395 ok(!pvarRes, "pvarRes != NULL\n");
1396 ok(pei != NULL, "pei == NULL\n");
1398 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1399 test_disp(V_DISPATCH(pdp->rgvarg));
1400 return S_OK;
1402 case DISPID_GLOBAL_PROPARGPUT:
1403 CHECK_EXPECT(global_propargput_i);
1405 ok(wFlags == DISPATCH_PROPERTYPUT, "wFlags = %x\n", wFlags);
1406 ok(pdp != NULL, "pdp == NULL\n");
1407 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1408 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
1409 ok(pdp->cArgs == 3, "cArgs = %d\n", pdp->cArgs);
1410 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
1411 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
1412 ok(!pvarRes, "pvarRes != NULL\n");
1413 ok(pei != NULL, "pei == NULL\n");
1415 ok(V_VT(pdp->rgvarg) == VT_I2, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1416 ok(V_I2(pdp->rgvarg) == 0, "V_I2(psp->rgvargs) = %d\n", V_I2(pdp->rgvarg));
1418 ok(V_VT(pdp->rgvarg+1) == VT_I2, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg+1));
1419 ok(V_I2(pdp->rgvarg+1) == 2, "V_I2(psp->rgvargs+1) = %d\n", V_I2(pdp->rgvarg+1));
1421 ok(V_VT(pdp->rgvarg+2) == VT_I2, "V_VT(psp->rgvargs+2) = %d\n", V_VT(pdp->rgvarg+2));
1422 ok(V_I2(pdp->rgvarg+2) == 1, "V_I2(psp->rgvargs+2) = %d\n", V_I2(pdp->rgvarg+2));
1423 return S_OK;
1425 case DISPID_GLOBAL_PROPARGPUT1:
1426 CHECK_EXPECT(global_propargput1_i);
1428 ok(wFlags == DISPATCH_PROPERTYPUT, "wFlags = %x\n", wFlags);
1429 ok(pdp != NULL, "pdp == NULL\n");
1430 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1431 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
1432 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
1433 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
1434 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
1435 ok(!pvarRes, "pvarRes != NULL\n");
1436 ok(pei != NULL, "pei == NULL\n");
1438 ok(V_VT(pdp->rgvarg) == VT_I2, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1439 ok(V_I2(pdp->rgvarg) == 0, "V_I2(psp->rgvargs) = %d\n", V_I2(pdp->rgvarg));
1441 ok(V_VT(pdp->rgvarg+1) == VT_I2, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg+1));
1442 ok(V_I2(pdp->rgvarg+1) == 1, "V_I2(psp->rgvargs+1) = %d\n", V_I2(pdp->rgvarg+1));
1444 return S_OK;
1446 case DISPID_GLOBAL_PROPARGSET:
1447 CHECK_EXPECT(global_propargset_i);
1449 ok(wFlags == DISPATCH_PROPERTYPUTREF, "wFlags = %x\n", wFlags);
1450 ok(pdp != NULL, "pdp == NULL\n");
1451 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1452 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
1453 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
1454 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
1455 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
1456 ok(!pvarRes, "pvarRes != NULL\n");
1457 ok(pei != NULL, "pei == NULL\n");
1459 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1460 ok(V_DISPATCH(pdp->rgvarg) == (IDispatch*)&testObj, "V_DISPATCH(psp->rgvargs) = %p\n", V_DISPATCH(pdp->rgvarg));
1462 ok(V_VT(pdp->rgvarg+1) == VT_I2, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg+1));
1463 ok(V_I2(pdp->rgvarg+1) == 0, "V_I2(psp->rgvargs+1) = %d\n", V_I2(pdp->rgvarg+1));
1465 return S_OK;
1467 case DISPID_GLOBAL_COUNTER:
1468 ok(pdp != NULL, "pdp == NULL\n");
1469 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1470 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
1471 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1472 ok(pvarRes != NULL, "pvarRes == NULL\n");
1473 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1474 ok(pei != NULL, "pei == NULL\n");
1476 V_VT(pvarRes) = VT_I2;
1477 V_I2(pvarRes) = test_counter++;
1478 return S_OK;
1480 case DISPID_GLOBAL_DOUBLEASSTRING:
1481 ok(wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
1482 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1483 ok(V_VT(pdp->rgvarg) == VT_R8, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
1484 ok(pvarRes != NULL, "pvarRes == NULL\n");
1486 V_VT(pvarRes) = VT_BSTR;
1487 return VarBstrFromR8(V_R8(pdp->rgvarg), 0, 0, &V_BSTR(pvarRes));
1489 case DISPID_GLOBAL_TESTARRAY:
1490 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1491 ok(pdp != NULL, "pdp == NULL\n");
1492 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1493 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1494 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
1495 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1496 ok(!pvarRes, "pvarRes != NULL\n");
1497 ok(pei != NULL, "pei == NULL\n");
1499 ok(V_VT(pdp->rgvarg+1) == VT_I2, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg+1));
1500 ok(V_VT(pdp->rgvarg) == (VT_BYREF|VT_VARIANT), "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
1501 ok(V_VT(V_VARIANTREF(pdp->rgvarg)) == (VT_ARRAY|VT_BYREF|VT_VARIANT),
1502 "V_VT(V_VARIANTREF(psp->rgvargs)) = %d\n", V_VT(V_VARIANTREF(pdp->rgvarg)));
1503 if(V_I2(pdp->rgvarg+1) == -1)
1504 ok(!*V_ARRAYREF(V_VARIANTREF(pdp->rgvarg)), "*V_ARRAYREF(V_VARIANTREF(pdp->rgvarg)) != NULL\n");
1505 else
1506 test_safearray(*V_ARRAYREF(V_VARIANTREF(pdp->rgvarg)), V_I2(pdp->rgvarg+1));
1507 return S_OK;
1509 case DISPID_GLOBAL_THROWINT: {
1510 VARIANT *v = pdp->rgvarg;
1511 HRESULT hres;
1513 ok((wFlags & ~INVOKE_PROPERTYGET) == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1514 ok(pdp != NULL, "pdp == NULL\n");
1515 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1516 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1517 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1518 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1519 ok(pei != NULL, "pei == NULL\n");
1520 if(pvarRes) {
1521 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
1522 V_VT(pvarRes) = VT_BOOL;
1523 V_BOOL(pvarRes) = VARIANT_FALSE;
1526 if(V_VT(v) == (VT_VARIANT|VT_BYREF))
1527 v = V_VARIANTREF(v);
1529 switch(V_VT(v)) {
1530 case VT_I2:
1531 hres = V_I2(v);
1532 break;
1533 case VT_I4:
1534 hres = V_I4(v);
1535 break;
1536 default:
1537 ok(0, "unexpected vt %d\n", V_VT(v));
1538 return E_INVALIDARG;
1541 return hres;
1543 case DISPID_GLOBAL_THROWWITHDESC:
1544 pei->scode = 0xdeadbeef;
1545 pei->bstrDescription = SysAllocString(L"test");
1546 pei->bstrHelpFile = SysAllocString(L"test.chm");
1547 pei->dwHelpContext = 10;
1548 return DISP_E_EXCEPTION;
1551 case DISPID_GLOBAL_TESTOPTIONALARG: {
1552 VARIANT *v;
1553 int opt;
1555 CHECK_EXPECT(global_testoptionalarg_i);
1557 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1558 ok(pdp != NULL, "pdp == NULL\n");
1559 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1560 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1561 ok(pdp->cArgs == 3, "cArgs = %d\n", pdp->cArgs);
1562 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1563 ok(!pvarRes, "pvarRes != NULL\n");
1564 ok(pei != NULL, "pei == NULL\n");
1566 ok(V_VT(pdp->rgvarg) == VT_I2, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
1567 opt = V_I2(pdp->rgvarg);
1568 ok(opt == 1 || opt == 2, "opt = %d\n", opt);
1569 v = pdp->rgvarg+pdp->cArgs-opt;
1570 ok(V_VT(v) == VT_ERROR, "V_VT(v) = %d\n", V_VT(v));
1571 ok(V_ERROR(v) == DISP_E_PARAMNOTFOUND, "V_ERROR(v) = %08x\n", V_ERROR(v));
1572 return S_OK;
1574 case DISPID_GLOBAL_GLOBALCALLBACK: {
1575 DISPPARAMS dp = {0};
1576 IDispatchEx *dispex;
1577 EXCEPINFO ei;
1578 VARIANT v;
1579 DISPID id;
1580 BSTR str;
1581 HRESULT hres;
1583 CHECK_EXPECT(global_globalcallback_i);
1584 CHECK_CALLED(OnEnterScript);
1586 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1587 ok(pdp != NULL, "pdp == NULL\n");
1588 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1589 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
1590 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1591 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1592 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1593 ok(!pvarRes, "pvarRes != NULL\n");
1594 ok(pei != NULL, "pei == NULL\n");
1596 hres = IDispatch_QueryInterface(V_DISPATCH(pdp->rgvarg), &IID_IDispatchEx, (void**)&dispex);
1597 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
1599 str = SysAllocString(L"callback");
1600 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &id);
1601 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1602 SysFreeString(str);
1604 SET_EXPECT(OnEnterScript);
1605 SET_EXPECT(OnLeaveScript);
1606 memset(&ei, 0, sizeof(ei));
1607 hres = IDispatchEx_InvokeEx(dispex, id, 0, DISPATCH_METHOD, &dp, &v, &ei, pspCaller);
1608 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1609 CHECK_CALLED(OnEnterScript);
1610 CHECK_CALLED(OnLeaveScript);
1611 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
1612 ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(v) = %x\n", V_BOOL(&v));
1614 IDispatchEx_Release(dispex);
1616 SET_EXPECT(OnLeaveScript);
1617 return S_OK;
1619 case DISPID_GLOBAL_TESTERROROBJECT: {
1620 ITypeInfo *typeinfo;
1621 IDispatchEx *dispex;
1622 DISPPARAMS dp;
1623 VARIANT v, r;
1624 EXCEPINFO ei;
1625 IDispatch *disp;
1626 WCHAR *names[1];
1627 UINT count, i;
1628 DISPID id;
1629 HRESULT hres;
1631 static WCHAR props[][32] = { L"clear", L"description", L"helpcontext", L"helpFILE", L"number", L"raise", L"source" };
1633 CHECK_EXPECT(global_testerrorobject_i);
1635 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
1636 ok(pdp != NULL, "pdp == NULL\n");
1637 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
1638 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
1639 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
1640 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
1641 ok(!pvarRes, "pvarRes != NULL\n");
1642 ok(pei != NULL, "pei == NULL\n");
1644 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
1645 disp = V_DISPATCH(pdp->rgvarg);
1646 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1647 ok(hres == E_NOINTERFACE, "Could not get IDispatchEx iface: %08x\n", hres);
1649 hres = IDispatch_GetTypeInfoCount(disp, &count);
1650 ok(hres == S_OK, "GetTypeInfoCount returned: %08x\n", hres);
1651 ok(count == 0, "count = %u\n", count);
1653 hres = IDispatch_GetTypeInfo(disp, 0, 0, &typeinfo);
1654 ok(hres == DISP_E_BADINDEX, "GetTypeInfo returned: %08x\n", hres);
1656 for(i = 0; i < ARRAY_SIZE(props); i++) {
1657 names[0] = props[i];
1658 hres = IDispatch_GetIDsOfNames(disp, &IID_NULL, names, 1, 0, &id);
1659 ok(hres == S_OK, "GetIDsOfNames failed: %08x\n", hres);
1660 ok(id == i + 1, "%s id = %u\n", wine_dbgstr_w(props[i]), id);
1663 memset(&dp, 0, sizeof(dp));
1664 memset(&ei, 0, sizeof(ei));
1665 V_VT(&v) = VT_ERROR;
1666 hres = IDispatch_Invoke(disp, 5, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
1667 ok(hres == S_OK, "Invoke failed: %08x\n", hres);
1668 ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
1669 ok(V_I4(&v) == 1, "V_I4(v) = %d\n", V_I4(&v));
1670 hres = IDispatch_Invoke(disp, DISPID_VALUE, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
1671 ok(hres == S_OK, "Invoke failed: %08x\n", hres);
1672 ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
1673 ok(V_I4(&v) == 1, "V_I4(v) = %d\n", V_I4(&v));
1675 dp.rgvarg = &v;
1676 V_VT(&v) = VT_I4;
1677 V_I4(&v) = 6;
1678 V_VT(&r) = VT_EMPTY;
1679 hres = IDispatch_Invoke(disp, DISPID_VALUE, &IID_NULL, 6, DISPATCH_METHOD|DISPATCH_PROPERTYGET, &dp, &r, &ei, NULL);
1680 ok(hres == S_OK, "Invoke failed: %08x\n", hres);
1681 return S_OK;
1683 case DISPID_GLOBAL_UNKOBJ:
1684 V_VT(pvarRes) = VT_UNKNOWN;
1685 V_UNKNOWN(pvarRes) = &unkObj;
1686 return S_OK;
1689 ok(0, "unexpected call %d\n", id);
1690 return DISP_E_MEMBERNOTFOUND;
1693 static IDispatchExVtbl GlobalVtbl = {
1694 DispatchEx_QueryInterface,
1695 Global_AddRef,
1696 Global_Release,
1697 DispatchEx_GetTypeInfoCount,
1698 DispatchEx_GetTypeInfo,
1699 DispatchEx_GetIDsOfNames,
1700 DispatchEx_Invoke,
1701 Global_GetDispID,
1702 Global_InvokeEx,
1703 DispatchEx_DeleteMemberByName,
1704 DispatchEx_DeleteMemberByDispID,
1705 DispatchEx_GetMemberProperties,
1706 DispatchEx_GetMemberName,
1707 DispatchEx_GetNextDispID,
1708 DispatchEx_GetNameSpaceParent
1711 static IDispatchEx Global = { &GlobalVtbl };
1713 static HRESULT WINAPI ActiveScriptSiteWindow_QueryInterface(IActiveScriptSiteWindow *iface, REFIID riid, void **ppv)
1715 ok(0, "unexpected call\n");
1716 return E_NOINTERFACE;
1719 static ULONG WINAPI ActiveScriptSiteWindow_AddRef(IActiveScriptSiteWindow *iface)
1721 return 2;
1724 static ULONG WINAPI ActiveScriptSiteWindow_Release(IActiveScriptSiteWindow *iface)
1726 return 1;
1729 static HRESULT WINAPI ActiveScriptSiteWindow_GetWindow(IActiveScriptSiteWindow *iface, HWND *phwnd)
1731 if(!allow_ui)
1732 CHECK_EXPECT(GetWindow);
1733 *phwnd = NULL;
1734 return S_OK;
1737 static HRESULT WINAPI ActiveScriptSiteWindow_EnableModeless(IActiveScriptSiteWindow *iface, BOOL fEnable)
1739 if(allow_ui)
1740 return S_OK;
1742 CHECK_EXPECT(EnableModeless);
1743 ok(!fEnable, "fEnable = %x\n", fEnable);
1744 return E_FAIL;
1747 static const IActiveScriptSiteWindowVtbl ActiveScriptSiteWindowVtbl = {
1748 ActiveScriptSiteWindow_QueryInterface,
1749 ActiveScriptSiteWindow_AddRef,
1750 ActiveScriptSiteWindow_Release,
1751 ActiveScriptSiteWindow_GetWindow,
1752 ActiveScriptSiteWindow_EnableModeless
1755 static IActiveScriptSiteWindow ActiveScriptSiteWindow = { &ActiveScriptSiteWindowVtbl };
1757 static HRESULT WINAPI ActiveScriptSiteUIControl_QueryInterface(IActiveScriptSiteUIControl *iface, REFIID riid, void **ppv)
1759 ok(0, "unexpected call\n");
1760 return E_NOINTERFACE;
1763 static ULONG WINAPI ActiveScriptSiteUIControl_AddRef(IActiveScriptSiteUIControl *iface)
1765 return 2;
1768 static ULONG WINAPI ActiveScriptSiteUIControl_Release(IActiveScriptSiteUIControl *iface)
1770 return 1;
1773 static HRESULT WINAPI ActiveScriptSiteUIControl_GetUIBehavior(IActiveScriptSiteUIControl *iface, SCRIPTUICITEM UicItem,
1774 SCRIPTUICHANDLING *pUicHandling)
1776 if(!allow_ui) {
1777 CHECK_EXPECT(GetUIBehavior);
1778 ok(UicItem == SCRIPTUICITEM_MSGBOX, "UidItem = %d\n", UicItem);
1780 *pUicHandling = uic_handling;
1781 return S_OK;
1784 static const IActiveScriptSiteUIControlVtbl ActiveScriptSiteUIControlVtbl = {
1785 ActiveScriptSiteUIControl_QueryInterface,
1786 ActiveScriptSiteUIControl_AddRef,
1787 ActiveScriptSiteUIControl_Release,
1788 ActiveScriptSiteUIControl_GetUIBehavior
1791 static IActiveScriptSiteUIControl ActiveScriptSiteUIControl = { &ActiveScriptSiteUIControlVtbl };
1793 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
1795 *ppv = NULL;
1797 if(IsEqualGUID(&IID_IUnknown, riid))
1798 *ppv = iface;
1799 else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
1800 *ppv = iface;
1801 else if(IsEqualGUID(&IID_IActiveScriptSiteWindow, riid))
1802 *ppv = &ActiveScriptSiteWindow;
1803 else if(IsEqualGUID(&IID_IActiveScriptSiteUIControl, riid))
1804 *ppv = &ActiveScriptSiteUIControl;
1805 else
1806 return E_NOINTERFACE;
1808 IUnknown_AddRef((IUnknown*)*ppv);
1809 return S_OK;
1812 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
1814 return 2;
1817 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
1819 return 1;
1822 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
1824 *plcid = GetUserDefaultLCID();
1825 return S_OK;
1828 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
1829 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
1831 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
1832 ok(!ppti, "ppti != NULL\n");
1834 if(lstrcmpW(pstrName, L"test"))
1835 ok(0, "unexpected pstrName %s\n", wine_dbgstr_w(pstrName));
1837 *ppiunkItem = (IUnknown*)&Global;
1838 IUnknown_AddRef(*ppiunkItem);
1839 return S_OK;
1842 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
1844 return E_NOTIMPL;
1847 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
1848 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
1850 return E_NOTIMPL;
1853 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
1855 return E_NOTIMPL;
1858 static IActiveScriptError **store_script_error;
1859 static ULONG error_line;
1860 static LONG error_char;
1862 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
1864 HRESULT hr = onerror_hres, hres;
1866 hres = IActiveScriptError_GetSourcePosition(pscripterror, NULL, &error_line, &error_char);
1867 ok(hres == S_OK, "GetSourcePosition failed: %08x\n", hres);
1869 if(!expect_OnScriptError) {
1870 EXCEPINFO info;
1872 hres = IActiveScriptError_GetExceptionInfo(pscripterror, &info);
1873 if(SUCCEEDED(hres))
1874 trace("Error in line %u: %x %s\n", error_line + 1, info.wCode, wine_dbgstr_w(info.bstrDescription));
1875 }else {
1876 IDispatchEx *dispex;
1878 hres = IActiveScriptError_QueryInterface(pscripterror, &IID_IDispatchEx, (void**)&dispex);
1879 ok(hres == E_NOINTERFACE, "QI(IDispatchEx) returned: %08x\n", hres);
1882 if(store_script_error) {
1883 IActiveScriptError_AddRef(pscripterror);
1884 *store_script_error = pscripterror;
1885 store_script_error = NULL;
1888 CHECK_EXPECT(OnScriptError);
1889 onerror_hres = E_NOTIMPL;
1891 return hr;
1894 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
1896 if(strict_enter_script)
1897 CHECK_EXPECT(OnEnterScript);
1898 return E_NOTIMPL;
1901 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
1903 if(strict_enter_script)
1904 CHECK_EXPECT(OnLeaveScript);
1905 return E_NOTIMPL;
1908 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
1909 ActiveScriptSite_QueryInterface,
1910 ActiveScriptSite_AddRef,
1911 ActiveScriptSite_Release,
1912 ActiveScriptSite_GetLCID,
1913 ActiveScriptSite_GetItemInfo,
1914 ActiveScriptSite_GetDocVersionString,
1915 ActiveScriptSite_OnScriptTerminate,
1916 ActiveScriptSite_OnStateChange,
1917 ActiveScriptSite_OnScriptError,
1918 ActiveScriptSite_OnEnterScript,
1919 ActiveScriptSite_OnLeaveScript
1922 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
1924 static IActiveScript *create_script(void)
1926 IActiveScript *script;
1927 HRESULT hres;
1929 hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1930 &IID_IActiveScript, (void**)&script);
1931 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1933 return script;
1936 static IActiveScript *create_and_init_script(DWORD flags, BOOL start)
1938 IActiveScriptParse *parser;
1939 IActiveScript *engine;
1940 HRESULT hres;
1942 engine = create_script();
1943 if(!engine)
1944 return NULL;
1946 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1947 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1949 hres = IActiveScriptParse_InitNew(parser);
1950 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1952 IActiveScriptParse_Release(parser);
1954 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1955 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1957 hres = IActiveScript_AddNamedItem(engine, L"test",
1958 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags);
1959 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1961 if (start)
1963 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1964 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1967 return engine;
1970 static void close_script(IActiveScript *script)
1972 ULONG ref;
1973 HRESULT hres;
1975 hres = IActiveScript_Close(script);
1976 ok(hres == S_OK, "Close failed: %08x\n", hres);
1978 ref = IActiveScript_Release(script);
1979 ok(!ref, "ref=%u\n", ref);
1982 static HRESULT parse_script(DWORD flags, BSTR script_str, const WCHAR *delim)
1984 IActiveScriptParse *parser;
1985 IActiveScript *engine;
1986 IDispatch *script_disp;
1987 HRESULT hres;
1989 engine = create_and_init_script(flags, TRUE);
1990 if(!engine)
1991 return S_OK;
1993 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1994 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1995 if (FAILED(hres))
1997 IActiveScript_Release(engine);
1998 return hres;
2001 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp);
2002 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
2003 ok(script_disp != NULL, "script_disp == NULL\n");
2004 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n");
2006 test_counter = 0;
2008 hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, delim, 0, 0, 0, NULL, NULL);
2010 IDispatch_Release(script_disp);
2011 IActiveScriptParse_Release(parser);
2012 close_script(engine);
2014 return hres;
2017 static void parse_script_af(DWORD flags, const char *src)
2019 BSTR tmp;
2020 HRESULT hres;
2022 tmp = a2bstr(src);
2023 hres = parse_script(flags, tmp, NULL);
2024 SysFreeString(tmp);
2025 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
2028 static HRESULT parse_script_ar(const char *src)
2030 BSTR tmp;
2031 HRESULT hres;
2033 tmp = a2bstr(src);
2034 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, tmp, NULL);
2035 SysFreeString(tmp);
2036 return hres;
2039 static void test_parse_context(void)
2041 IActiveScriptParse *parser;
2042 IActiveScript *engine;
2043 BSTR str;
2044 HRESULT hres;
2046 global_ref = 1;
2047 engine = create_and_init_script(0, TRUE);
2048 if(!engine)
2049 return;
2051 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
2052 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
2054 /* NULL code text succeeds but does nothing */
2055 hres = IActiveScriptParse_ParseScriptText(parser, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2056 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2058 /* unknown identifier context is not a valid argument */
2059 str = a2bstr("Call reportSuccess()\n");
2060 hres = IActiveScriptParse_ParseScriptText(parser, str, L"y", NULL, NULL, 0, 0, 0, NULL, NULL);
2061 ok(hres == E_INVALIDARG, "ParseScriptText failed: %08x\n", hres);
2062 SysFreeString(str);
2064 str = a2bstr("class Cl\n"
2065 " Public Sub ClMethod\n"
2066 " Call reportSuccess()\n"
2067 " End Sub\n"
2068 "End Class\n"
2069 "Dim x\n"
2070 "set x = new Cl\n");
2071 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2072 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2073 SysFreeString(str);
2075 /* known global variable is not a valid context */
2076 str = a2bstr("Call reportSuccess()\n");
2077 hres = IActiveScriptParse_ParseScriptText(parser, str, L"x", NULL, NULL, 0, 0, 0, NULL, NULL);
2078 ok(hres == E_INVALIDARG, "ParseScriptText failed: %08x\n", hres);
2079 SysFreeString(str);
2081 SET_EXPECT(global_success_d);
2082 SET_EXPECT(global_success_i);
2083 str = a2bstr("Call reportSuccess()\n");
2084 hres = IActiveScriptParse_ParseScriptText(parser, str, L"test", NULL, NULL, 0, 0, 0, NULL, NULL);
2085 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2086 SysFreeString(str);
2087 CHECK_CALLED(global_success_d);
2088 CHECK_CALLED(global_success_i);
2090 IActiveScriptParse_Release(parser);
2091 close_script(engine);
2092 ok(global_ref == 1, "global_ref = %u\n", global_ref);
2095 static void parse_script_a(const char *src)
2097 parse_script_af(SCRIPTITEM_GLOBALMEMBERS, src);
2100 #define parse_htmlscript_a(a) _parse_htmlscript_a(__LINE__,a)
2101 static void _parse_htmlscript_a(unsigned line, const char *src)
2103 BSTR tmp;
2104 HRESULT hres;
2106 tmp = a2bstr(src);
2107 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, tmp, L"</SCRIPT>");
2108 SysFreeString(tmp);
2109 ok_(__FILE__,line)(hres == S_OK, "parse_script failed: %08x\n", hres);
2112 static IDispatchEx *parse_procedure(IActiveScriptParseProcedure2 *parse_proc, const char *src, DWORD flags)
2114 IDispatchEx *dispex;
2115 IDispatch *disp;
2116 BSTR str;
2117 HRESULT hres;
2119 str = a2bstr(src);
2120 hres = IActiveScriptParseProcedure2_ParseProcedureText(parse_proc, str, NULL, L"", NULL, NULL, L"\"", 0, 0,
2121 SCRIPTPROC_HOSTMANAGESSOURCE|SCRIPTPROC_IMPLICIT_THIS|SCRIPTPROC_IMPLICIT_PARENTS|flags, &disp);
2122 SysFreeString(str);
2123 ok(hres == S_OK, "ParseProcedureText failed: %08x\n", hres);
2124 ok(disp != NULL, "disp = NULL\n");
2126 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
2127 IDispatch_Release(disp);
2128 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
2130 return dispex;
2134 static void test_procedures(void)
2136 IActiveScriptParseProcedure2 *parse_proc;
2137 DISPPARAMS dp = {NULL};
2138 IActiveScript *script;
2139 IDispatchEx *proc;
2140 IDispatch *disp;
2141 EXCEPINFO ei = {0};
2142 VARIANT v;
2143 HRESULT hres;
2145 strict_enter_script = TRUE;
2146 script = create_and_init_script(0, TRUE);
2148 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc);
2149 ok(hres == S_OK, "Could not get IActiveScriptParseProcedure2 iface: %08x\n", hres);
2151 hres = IActiveScriptParseProcedure2_ParseProcedureText(parse_proc, NULL, NULL, L"", NULL, NULL, NULL, 0, 0, 0, &disp);
2152 ok(hres == S_OK, "ParseProcedureText failed: %08x\n", hres);
2153 IDispatch_Release(disp);
2155 proc = parse_procedure(parse_proc, "dim x\nif true then x=false", 0);
2157 SET_EXPECT(OnEnterScript);
2158 SET_EXPECT(OnLeaveScript);
2159 V_VT(&v) = VT_EMPTY;
2160 hres = IDispatchEx_InvokeEx(proc, DISPID_VALUE, 0, DISPATCH_METHOD, &dp, &v, &ei, &caller_sp);
2161 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2162 CHECK_CALLED(OnEnterScript);
2163 CHECK_CALLED(OnLeaveScript);
2164 VariantClear(&v);
2165 IDispatchEx_Release(proc);
2167 proc = parse_procedure(parse_proc, "\"foobar\"", SCRIPTPROC_ISEXPRESSION);
2169 SET_EXPECT(OnEnterScript);
2170 SET_EXPECT(OnLeaveScript);
2171 hres = IDispatchEx_InvokeEx(proc, DISPID_VALUE, 0, DISPATCH_METHOD, &dp, &v, &ei, &caller_sp);
2172 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2173 CHECK_CALLED(OnEnterScript);
2174 CHECK_CALLED(OnLeaveScript);
2175 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR, got %s\n", vt2a(&v));
2176 ok(!lstrcmpW(V_BSTR(&v), L"foobar"), "Wrong string, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
2177 VariantClear(&v);
2178 IDispatchEx_Release(proc);
2180 IActiveScriptParseProcedure2_Release(parse_proc);
2182 close_script(script);
2183 strict_enter_script = FALSE;
2186 static void free_ei(EXCEPINFO *ei)
2188 SysFreeString(ei->bstrSource);
2189 SysFreeString(ei->bstrDescription);
2190 SysFreeString(ei->bstrHelpFile);
2193 static void test_callbacks(void)
2195 IActiveScriptError *error1, *error2;
2196 IActiveScriptParse *parser;
2197 DISPPARAMS dp = {NULL};
2198 IActiveScript *script;
2199 IDispatchEx *dispex;
2200 IDispatch *disp;
2201 DISPID id;
2202 EXCEPINFO ei = {0};
2203 BSTR str;
2204 VARIANT v;
2205 HRESULT hres;
2207 strict_enter_script = TRUE;
2208 script = create_and_init_script(SCRIPTITEM_GLOBALMEMBERS, TRUE);
2210 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser);
2211 ok(hres == S_OK, "Could not get IActiveScriptParseProcedure2 iface: %08x\n", hres);
2213 SET_EXPECT(OnEnterScript);
2214 SET_EXPECT(OnLeaveScript);
2215 hres = IActiveScriptParse_ParseScriptText(parser,
2216 L"class CallbackClass\n"
2217 L" public function callback()\n"
2218 L" call ok(err.number = 2, \"err.number = \" & err.number)\n"
2219 L" callback = true\n"
2220 L" end function\n"
2221 L"end class\n"
2222 L"function callGlobalCallback()\n"
2223 L" on error resume next\n"
2224 L" err.raise 2\n"
2225 L" call test.globalCallback(new CallbackClass)\n"
2226 L" call ok(err.number = 2, \"err.number = \" & err.number)\n"
2227 L"end function\n",
2228 NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2229 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2230 CHECK_CALLED(OnEnterScript);
2231 CHECK_CALLED(OnLeaveScript);
2233 hres = IActiveScript_GetScriptDispatch(script, NULL, &disp);
2234 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
2236 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
2237 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
2238 IDispatch_Release(disp);
2240 str = SysAllocString(L"callGlobalCallback");
2241 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &id);
2242 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2243 SysFreeString(str);
2245 SET_EXPECT(OnEnterScript);
2246 /* OnLeaveScript will be set in global callback */
2247 SET_EXPECT(global_globalcallback_i);
2248 hres = IDispatchEx_InvokeEx(dispex, id, 0, DISPATCH_METHOD, &dp, &v, &ei, &caller_sp);
2249 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2250 /* OnEnterScript was checked in global callback */
2251 CHECK_CALLED(OnLeaveScript);
2252 CHECK_CALLED(global_globalcallback_i);
2254 store_script_error = &error1;
2256 SET_EXPECT(OnEnterScript);
2257 SET_EXPECT(OnLeaveScript);
2258 SET_EXPECT(OnScriptError);
2259 hres = IActiveScriptParse_ParseScriptText(parser, L"err.raise 2\n",
2260 NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2261 ok(hres == MAKE_VBSERROR(2), "ParseScriptText failed: %08x\n", hres);
2262 CHECK_CALLED(OnEnterScript);
2263 CHECK_CALLED(OnLeaveScript);
2264 CHECK_CALLED(OnScriptError);
2266 store_script_error = &error2;
2268 SET_EXPECT(OnEnterScript);
2269 SET_EXPECT(OnLeaveScript);
2270 SET_EXPECT(OnScriptError);
2271 hres = IActiveScriptParse_ParseScriptText(parser,
2272 L"call ok(err.number = 0, \"err.number = \" & err.number)\n"
2273 L"err.raise &h86664004&, \"src\", \"desc\", \"help\", 1\n",
2274 NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2275 ok(hres == SCRIPT_E_RECORDED, "ParseScriptText failed: %08x\n", hres);
2276 CHECK_CALLED(OnEnterScript);
2277 CHECK_CALLED(OnLeaveScript);
2278 CHECK_CALLED(OnScriptError);
2280 memset(&ei, 0xcc, sizeof(ei));
2281 hres = IActiveScriptError_GetExceptionInfo(error1, &ei);
2282 ok(hres == S_OK, "GetExceptionInfo returned %08x\n", hres);
2283 ok(!ei.wCode, "wCode = %x\n", ei.wCode);
2284 ok(!ei.wReserved, "wReserved = %x\n", ei.wReserved);
2285 if(is_english) {
2286 ok(!wcscmp(ei.bstrSource, L"Microsoft VBScript runtime error"),
2287 "bstrSource = %s\n", wine_dbgstr_w(ei.bstrSource));
2288 ok(!wcscmp(ei.bstrDescription, L"Unknown runtime error"),
2289 "bstrDescription = %s\n", wine_dbgstr_w(ei.bstrDescription));
2291 ok(!ei.bstrHelpFile, "bstrHelpFile = %s\n", wine_dbgstr_w(ei.bstrHelpFile));
2292 ok(!ei.dwHelpContext, "dwHelpContext = %x\n", ei.dwHelpContext);
2293 ok(!ei.pvReserved, "pvReserved = %p\n", ei.pvReserved);
2294 ok(!ei.pfnDeferredFillIn, "pfnDeferredFillIn = %p\n", ei.pfnDeferredFillIn);
2295 ok(ei.scode == MAKE_VBSERROR(2), "scode = %x\n", ei.scode);
2296 free_ei(&ei);
2298 IActiveScriptError_Release(error1);
2300 memset(&ei, 0xcc, sizeof(ei));
2301 hres = IActiveScriptError_GetExceptionInfo(error2, &ei);
2302 ok(hres == S_OK, "GetExceptionInfo returned %08x\n", hres);
2303 ok(!ei.wCode, "wCode = %x\n", ei.wCode);
2304 ok(!ei.wReserved, "wReserved = %x\n", ei.wReserved);
2305 ok(!wcscmp(ei.bstrSource, L"src"), "bstrSource = %s\n", wine_dbgstr_w(ei.bstrSource));
2306 ok(!wcscmp(ei.bstrDescription, L"desc"), "bstrDescription = %s\n", wine_dbgstr_w(ei.bstrDescription));
2307 ok(!wcscmp(ei.bstrHelpFile, L"help"), "bstrHelpFile = %s\n", wine_dbgstr_w(ei.bstrHelpFile));
2308 ok(ei.dwHelpContext == 1, "dwHelpContext = %x\n", ei.dwHelpContext);
2309 ok(!ei.pvReserved, "pvReserved = %p\n", ei.pvReserved);
2310 ok(!ei.pfnDeferredFillIn, "pfnDeferredFillIn = %p\n", ei.pfnDeferredFillIn);
2311 ok(ei.scode == SCRIPT_E_RECORDED, "scode = %x\n", ei.scode);
2312 free_ei(&ei);
2314 IActiveScriptError_Release(error2);
2316 SET_EXPECT(OnEnterScript);
2317 SET_EXPECT(OnLeaveScript);
2318 SET_EXPECT(OnScriptError);
2319 hres = IActiveScriptParse_ParseScriptText(parser, L"err.raise &hffff&\n",
2320 NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2321 ok(hres == MAKE_VBSERROR(0xffff), "ParseScriptText failed: %08x\n", hres);
2322 CHECK_CALLED(OnEnterScript);
2323 CHECK_CALLED(OnLeaveScript);
2324 CHECK_CALLED(OnScriptError);
2326 SET_EXPECT(OnEnterScript);
2327 SET_EXPECT(OnLeaveScript);
2328 SET_EXPECT(OnScriptError);
2329 hres = IActiveScriptParse_ParseScriptText(parser, L"err.raise &h80102030&\n",
2330 NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2331 ok(hres == 0x80102030, "ParseScriptText failed: %08x\n", hres);
2332 CHECK_CALLED(OnEnterScript);
2333 CHECK_CALLED(OnLeaveScript);
2334 CHECK_CALLED(OnScriptError);
2336 SET_EXPECT(OnEnterScript);
2337 SET_EXPECT(global_testerrorobject_i);
2338 SET_EXPECT(OnLeaveScript);
2339 hres = IActiveScriptParse_ParseScriptText(parser,
2340 L"on error resume next\n"
2341 L"err.raise 1\n"
2342 L"testErrorObject err\n",
2343 NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2344 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2345 CHECK_CALLED(OnEnterScript);
2346 CHECK_CALLED(global_testerrorobject_i);
2347 CHECK_CALLED(OnLeaveScript);
2349 IDispatchEx_Release(dispex);
2351 IActiveScriptParse_Release(parser);
2352 close_script(script);
2353 strict_enter_script = FALSE;
2356 static void test_gc(void)
2358 IActiveScriptParse *parser;
2359 IActiveScript *engine;
2360 BSTR src;
2361 HRESULT hres;
2363 strict_dispid_check = FALSE;
2365 engine = create_script();
2366 if(!engine)
2367 return;
2369 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
2370 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
2372 hres = IActiveScriptParse_InitNew(parser);
2373 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
2375 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
2376 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
2378 hres = IActiveScript_AddNamedItem(engine, L"test",
2379 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
2380 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
2382 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
2383 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
2385 src = a2bstr(
2386 "class C\n"
2387 " Public ref\n"
2388 " Public Sub Class_Terminate\n"
2389 " Call reportSuccess()\n"
2390 " End Sub\n"
2391 "End Class\n"
2392 "Dim x\n"
2393 "set x = new C\n"
2394 "set x.ref = x\n"
2395 "set x = nothing\n");
2397 hres = IActiveScriptParse_ParseScriptText(parser, src, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2398 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2399 SysFreeString(src);
2401 SET_EXPECT(global_success_d);
2402 SET_EXPECT(global_success_i);
2403 hres = IActiveScript_Close(engine);
2404 ok(hres == S_OK, "Close failed: %08x\n", hres);
2405 CHECK_CALLED(global_success_d);
2406 CHECK_CALLED(global_success_i);
2408 IActiveScript_Release(engine);
2409 IActiveScriptParse_Release(parser);
2412 static void test_parse_errors(void)
2414 static const struct
2416 const char *src;
2417 unsigned error_line;
2418 int error_char;
2420 invalid_scripts[] =
2423 /* If...End If */
2424 "If 0 > 1 Then\n"
2425 " x = 0 End If\n",
2426 1, 10
2429 /* While...End While */
2430 "While False\n"
2431 " x = 0 End While\n",
2432 1, 10
2435 /* While...Wend */
2436 "While False\n"
2437 " x = 0 Wend\n",
2438 1, 10
2441 /* Do While...Loop */
2442 "Do While False\n"
2443 " x = 0 Loop\n",
2444 1, 10
2447 /* Do Until...Loop */
2448 "Do Until True\n"
2449 " x = 0 Loop\n",
2450 1, 10
2453 /* Do...Loop While */
2454 "Do\n"
2455 " x = 0 Loop While False\n",
2456 1, 10
2459 /* Do...Loop Until */
2460 "Do\n"
2461 " x = 0 Loop Until True\n",
2462 1, 10
2465 /* Select...End Select */
2466 "x = False\n"
2467 "Select Case 42\n"
2468 " Case 0\n"
2469 " Call ok(False, \"unexpected case\")\n"
2470 " Case 42\n"
2471 " x = True End Select\n"
2472 "Call ok(x, \"wrong case\")\n",
2473 5, 17
2476 /* Class...End Class (empty) */
2477 "Class C End Class",
2478 0, 8
2481 /* Class...End Class (empty) */
2482 "Class C _\nEnd Class",
2483 1, 0
2486 /* invalid use of parentheses for call statement */
2487 "strcomp(\"x\", \"y\")",
2488 0, -17
2491 "\n\n\n cint _\n throwInt(&h80001234&)",
2492 3, 2
2495 "dim x\n"
2496 "if true then throwInt(&h80001234&)",
2497 1, 13
2500 "dim x\n"
2501 "if x = throwInt(&h80001234&) then x = 1",
2502 1, 0
2505 "sub test\n"
2506 " dim x\n"
2507 " if x = throwInt(&h80001234&) then x = 1\n"
2508 "end sub\n"
2509 "test\n",
2510 2, 4
2513 "dim x\n"
2514 "do\n"
2515 " x = 1\n"
2516 "loop until throwInt(&h80001234&)\n",
2517 3, 0
2520 "\n select case 3\n"
2521 " case 2\n"
2522 " ok false, \"unexpected case\"\n"
2523 " case throwInt(&h80001234&)\n"
2524 " throwInt &h87001234&\n"
2525 "end select\n",
2526 1, 2
2529 "if false then\n"
2530 " ok false, \"unexpected case\"\n"
2531 " elseif throwInt(&h80001234&) then\n"
2532 " throwInt &h87001234&\n"
2533 "else\n"
2534 " throwInt &h87001234&\n"
2535 "end if\n",
2536 2, 1
2539 HRESULT hres;
2540 UINT i;
2542 for (i = 0; i < ARRAY_SIZE(invalid_scripts); i++)
2544 error_line = ~0;
2545 error_char = -1;
2546 onerror_hres = S_OK;
2548 SET_EXPECT(OnScriptError);
2549 hres = parse_script_ar(invalid_scripts[i].src);
2550 ok(hres == SCRIPT_E_REPORTED, "[%u] script returned: %08x\n", i, hres);
2551 CHECK_CALLED(OnScriptError);
2553 ok(error_line == invalid_scripts[i].error_line, "[%u] error line %u expected %u\n",
2554 i, error_line, invalid_scripts[i].error_line);
2555 todo_wine_if(invalid_scripts[i].error_char < 0)
2556 ok(error_char == abs(invalid_scripts[i].error_char), "[%u] error char %d expected %d\n",
2557 i, error_char, invalid_scripts[i].error_char);
2561 static void test_msgbox(void)
2563 HRESULT hres;
2565 uic_handling = SCRIPTUICHANDLING_NOUIDEFAULT;
2567 SET_EXPECT(GetUIBehavior);
2568 SET_EXPECT(GetWindow);
2569 SET_EXPECT(EnableModeless);
2570 hres = parse_script_ar("MsgBox \"testing...\"");
2571 CLEAR_CALLED(GetUIBehavior);
2572 CLEAR_CALLED(GetWindow);
2573 CLEAR_CALLED(EnableModeless);
2574 if(FAILED(hres)) {
2575 win_skip("Skipping MsgBox tests, broken (probably too old) vbscript\n");
2576 return;
2579 SET_EXPECT(GetUIBehavior);
2580 parse_script_a("dim r\n r=MsgBox(\"testing...\")\n Call ok(r=0, \"r=\"&r)");
2581 CHECK_CALLED(GetUIBehavior);
2583 SET_EXPECT(GetUIBehavior);
2584 parse_script_a("MsgBox 10");
2585 CHECK_CALLED(GetUIBehavior);
2587 uic_handling = SCRIPTUICHANDLING_ALLOW;
2589 SET_EXPECT(GetUIBehavior);
2590 SET_EXPECT(GetWindow);
2591 SET_EXPECT(EnableModeless);
2592 SET_EXPECT(OnScriptError);
2593 hres = parse_script_ar("MsgBox \"testing...\"");
2594 ok(FAILED(hres), "script not failed\n");
2595 CHECK_CALLED(GetUIBehavior);
2596 CHECK_CALLED(GetWindow);
2597 CHECK_CALLED(EnableModeless);
2598 CHECK_CALLED(OnScriptError);
2600 uic_handling = SCRIPTUICHANDLING_NOUIERROR;
2602 SET_EXPECT(GetUIBehavior);
2603 SET_EXPECT(OnScriptError);
2604 hres = parse_script_ar("MsgBox \"testing...\"");
2605 ok(FAILED(hres), "script not failed\n");
2606 CHECK_CALLED(GetUIBehavior);
2607 CHECK_CALLED(OnScriptError);
2610 static HRESULT test_global_vars_ref(BOOL use_close)
2612 IActiveScriptParse *parser;
2613 IActiveScript *engine;
2614 BSTR script_str;
2615 LONG ref;
2616 HRESULT hres;
2618 engine = create_script();
2619 if(!engine)
2620 return S_OK;
2622 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
2623 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
2624 if (FAILED(hres))
2626 IActiveScript_Release(engine);
2627 return hres;
2630 hres = IActiveScriptParse_InitNew(parser);
2631 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
2633 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
2634 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
2636 hres = IActiveScript_AddNamedItem(engine, L"test", SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
2637 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
2639 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
2640 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
2642 refobj_ref = 0;
2644 script_str = a2bstr("Dim x\nset x = RefObj\n");
2645 hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2646 SysFreeString(script_str);
2648 ok(refobj_ref, "refobj_ref = 0\n");
2650 if(use_close) {
2651 hres = IActiveScript_Close(engine);
2652 ok(hres == S_OK, "Close failed: %08x\n", hres);
2653 }else {
2654 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_UNINITIALIZED);
2655 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
2658 ok(!refobj_ref, "refobj_ref = %d\n", refobj_ref);
2660 IActiveScript_Release(engine);
2662 ref = IActiveScriptParse_Release(parser);
2663 ok(!ref, "ref=%d\n", ref);
2664 return hres;
2667 static void test_isexpression(void)
2669 IActiveScriptParse *parser;
2670 IActiveScript *engine;
2671 IDispatch *disp;
2672 SCRIPTSTATE ss;
2673 HRESULT hres;
2674 VARIANT var;
2675 BSTR str;
2677 if (!(engine = create_and_init_script(0, FALSE)))
2678 return;
2680 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
2681 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
2682 if (FAILED(hres))
2684 close_script(engine);
2685 return;
2688 /* Expression when script is not started is still executed */
2689 hres = IActiveScript_GetScriptState(engine, &ss);
2690 ok(hres == S_OK, "GetScriptState failed: %08x\n", hres);
2691 ok(ss == SCRIPTSTATE_INITIALIZED, "Wrong script state %u\n", ss);
2693 str = a2bstr("13");
2694 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
2695 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2696 ok(V_VT(&var) == VT_I2, "Expected VT_I2, got %s\n", vt2a(&var));
2697 ok(V_I2(&var) == 13, "Expected 13, got %d\n", V_I2(&var));
2698 VariantClear(&var);
2699 SysFreeString(str);
2701 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
2702 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
2704 /* Empty expressions */
2705 V_VT(&var) = VT_I2;
2706 str = a2bstr("");
2707 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
2708 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2709 ok(V_VT(&var) == VT_EMPTY, "Expected VT_EMPTY, got %s\n", vt2a(&var));
2710 VariantClear(&var);
2711 SysFreeString(str);
2713 /* Two expressions fail */
2714 str = a2bstr("1\n3");
2715 SET_EXPECT(OnScriptError);
2716 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
2717 ok(FAILED(hres), "ParseScriptText did not fail: %08x\n", hres);
2718 CHECK_CALLED(OnScriptError);
2719 VariantClear(&var);
2720 SysFreeString(str);
2722 /* Simple numerical expression */
2723 str = a2bstr("(1 + 7) * 2 - 3");
2724 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, NULL, NULL);
2725 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2727 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
2728 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2729 ok(V_VT(&var) == VT_I2, "Expected VT_I2, got %s\n", vt2a(&var));
2730 ok(V_I2(&var) == 13, "Expected 13, got %d\n", V_I2(&var));
2731 VariantClear(&var);
2732 SysFreeString(str);
2734 /* Without a global host or named item context, "me" returns the script dispatch */
2735 hres = IActiveScript_GetScriptDispatch(engine, NULL, &disp);
2736 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
2737 str = a2bstr("me");
2738 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
2739 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2740 ok(V_VT(&var) == VT_DISPATCH, "Expected VT_DISPATCH, got %s\n", vt2a(&var));
2741 ok(V_DISPATCH(&var) == disp, "Wrong dispatch returned for 'me'\n");
2742 IDispatch_Release(disp);
2743 VariantClear(&var);
2744 SysFreeString(str);
2746 /* An expression can also refer to a variable, function, class, etc previously set */
2747 V_VT(&var) = VT_I2;
2748 str = a2bstr("If True Then foo = 42 Else foo = 0\n");
2749 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, &var, NULL);
2750 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2751 ok(V_VT(&var) == VT_EMPTY, "Expected VT_EMPTY, got %s\n", vt2a(&var));
2752 VariantClear(&var);
2753 SysFreeString(str);
2755 str = a2bstr("foo\n\n");
2756 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
2757 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2758 ok(V_VT(&var) == VT_I2, "Expected VT_I2, got %s\n", vt2a(&var));
2759 ok(V_I2(&var) == 42, "Expected 42, got %d\n", V_I2(&var));
2760 VariantClear(&var);
2761 SysFreeString(str);
2763 str = a2bstr("foo : ");
2764 SET_EXPECT(OnScriptError);
2765 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
2766 ok(FAILED(hres), "ParseScriptText did not fail: %08x\n", hres);
2767 CHECK_CALLED(OnScriptError);
2768 VariantClear(&var);
2769 SysFreeString(str);
2771 str = a2bstr("\"foo is \" & CStr(foo) \n \n\n ");
2772 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
2773 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2774 ok(V_VT(&var) == VT_BSTR, "Expected VT_BSTR, got %s\n", vt2a(&var));
2775 ok(!lstrcmpW(V_BSTR(&var), L"foo is 42"), "Wrong string, got %s\n", wine_dbgstr_w(V_BSTR(&var)));
2776 VariantClear(&var);
2777 SysFreeString(str);
2779 str = a2bstr("Function test(x)\n"
2780 " test = x + 0.5\n"
2781 "End Function\n");
2782 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2783 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2784 SysFreeString(str);
2786 str = a2bstr("test(4) * 3\n");
2787 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
2788 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2789 ok(V_VT(&var) == VT_R8, "Expected VT_R8, got %s\n", vt2a(&var));
2790 ok(V_R8(&var) == 13.5, "Expected %lf, got %lf\n", 13.5, V_R8(&var));
2791 VariantClear(&var);
2792 SysFreeString(str);
2794 str = a2bstr("Class C\n"
2795 " Public x\n"
2796 "End Class\n"
2797 "Set obj = New C\n"
2798 "obj.x = True\n");
2799 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2800 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2801 SysFreeString(str);
2803 str = a2bstr("obj.x");
2804 hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL);
2805 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2806 ok(V_VT(&var) == VT_BOOL, "Expected VT_BOOL, got %s\n", vt2a(&var));
2807 ok(V_BOOL(&var) == VARIANT_TRUE, "Expected %x, got %x\n", VARIANT_TRUE, V_BOOL(&var));
2808 VariantClear(&var);
2809 SysFreeString(str);
2811 IActiveScriptParse_Release(parser);
2812 close_script(engine);
2815 static void test_multiple_parse(void)
2817 IActiveScriptParse *parser;
2818 IActiveScript *script;
2819 HRESULT hres;
2821 script = create_and_init_script(SCRIPTITEM_GLOBALMEMBERS, TRUE);
2823 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser);
2824 ok(hres == S_OK, "Could not get IActiveScriptParseProcedure2 iface: %08x\n", hres);
2826 hres = IActiveScriptParse_ParseScriptText(parser,
2827 L"function duplicatedfunc\n"
2828 L" ok false, \"duplicatedfunc called\"\n"
2829 L"end function\n",
2830 NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2831 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2833 hres = IActiveScriptParse_ParseScriptText(parser,
2834 L"sub duplicatedfunc\n"
2835 L" ok false, \"duplicatedfunc called\"\n"
2836 L"end sub\n",
2837 NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2838 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2840 hres = IActiveScriptParse_ParseScriptText(parser,
2841 L"function duplicatedfunc\n"
2842 L" duplicatedfunc = 2\n"
2843 L"end function\n",
2844 NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2845 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2847 hres = IActiveScriptParse_ParseScriptText(parser,
2848 L"ok duplicatedfunc() = 2, \"duplicatedfunc = \" & duplicatedfunc()\n",
2849 NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
2850 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
2852 IActiveScriptParse_Release(parser);
2853 close_script(script);
2856 static BSTR get_script_from_file(const char *filename)
2858 DWORD size, len;
2859 HANDLE file, map;
2860 const char *file_map;
2861 BSTR ret;
2863 file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
2864 if(file == INVALID_HANDLE_VALUE) {
2865 trace("Could not open file: %u\n", GetLastError());
2866 return NULL;
2869 size = GetFileSize(file, NULL);
2871 map = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
2872 CloseHandle(file);
2873 if(map == INVALID_HANDLE_VALUE) {
2874 trace("Could not create file mapping: %u\n", GetLastError());
2875 return NULL;
2878 file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
2879 CloseHandle(map);
2880 if(!file_map) {
2881 trace("MapViewOfFile failed: %u\n", GetLastError());
2882 return NULL;
2885 len = MultiByteToWideChar(CP_ACP, 0, file_map, size, NULL, 0);
2886 ret = SysAllocStringLen(NULL, len);
2887 MultiByteToWideChar(CP_ACP, 0, file_map, size, ret, len);
2889 UnmapViewOfFile(file_map);
2891 return ret;
2894 static void run_from_file(const char *filename)
2896 BSTR script_str;
2897 HRESULT hres;
2899 script_str = get_script_from_file(filename);
2900 if(!script_str)
2901 return;
2903 strict_dispid_check = FALSE;
2904 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, script_str, NULL);
2905 SysFreeString(script_str);
2906 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
2909 static void run_from_res(const char *name)
2911 const char *data;
2912 DWORD size, len;
2913 BSTR str;
2914 HRSRC src;
2915 HRESULT hres;
2917 strict_dispid_check = FALSE;
2918 test_name = name;
2920 src = FindResourceA(NULL, name, (LPCSTR)40);
2921 ok(src != NULL, "Could not find resource %s\n", name);
2923 size = SizeofResource(NULL, src);
2924 data = LoadResource(NULL, src);
2926 len = MultiByteToWideChar(CP_ACP, 0, data, size, NULL, 0);
2927 str = SysAllocStringLen(NULL, len);
2928 MultiByteToWideChar(CP_ACP, 0, data, size, str, len);
2930 SET_EXPECT(global_success_d);
2931 SET_EXPECT(global_success_i);
2932 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, str, NULL);
2933 CHECK_CALLED(global_success_d);
2934 CHECK_CALLED(global_success_i);
2936 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
2937 SysFreeString(str);
2938 test_name = "";
2941 static void run_tests(void)
2943 HRESULT hres;
2945 strict_dispid_check = TRUE;
2947 parse_script_a("");
2948 parse_script_a("' empty ;");
2950 SET_EXPECT(global_success_d);
2951 SET_EXPECT(global_success_i);
2952 parse_script_a("reportSuccess");
2953 CHECK_CALLED(global_success_d);
2954 CHECK_CALLED(global_success_i);
2956 SET_EXPECT(global_success_d);
2957 SET_EXPECT(global_success_i);
2958 parse_script_a("reportSuccess()");
2959 CHECK_CALLED(global_success_d);
2960 CHECK_CALLED(global_success_i);
2962 SET_EXPECT(global_success_d);
2963 SET_EXPECT(global_success_i);
2964 parse_script_a("Call reportSuccess");
2965 CHECK_CALLED(global_success_d);
2966 CHECK_CALLED(global_success_i);
2968 SET_EXPECT(global_success_d);
2969 SET_EXPECT(global_success_i);
2970 parse_script_a("test.reportSuccess()");
2971 CHECK_CALLED(global_success_d);
2972 CHECK_CALLED(global_success_i);
2974 SET_EXPECT(global_success_d);
2975 SET_EXPECT(global_success_i);
2976 parse_script_af(0, "TEST.reportSuccess()");
2977 CHECK_CALLED(global_success_d);
2978 CHECK_CALLED(global_success_i);
2980 SET_EXPECT(global_vbvar_d);
2981 SET_EXPECT(global_vbvar_i);
2982 parse_script_a("Option Explicit\nvbvar = 3");
2983 CHECK_CALLED(global_vbvar_d);
2984 CHECK_CALLED(global_vbvar_i);
2986 SET_EXPECT(global_vbvar_d);
2987 SET_EXPECT(global_vbvar_i);
2988 parse_script_a("Option Explicit\nvbvar() = 3");
2989 CHECK_CALLED(global_vbvar_d);
2990 CHECK_CALLED(global_vbvar_i);
2992 SET_EXPECT(global_letobj_i);
2993 parse_script_a("Option Explicit\nletobj = testObj");
2994 CHECK_CALLED(global_letobj_i);
2996 SET_EXPECT(global_letobj_i);
2997 parse_script_a("Option Explicit\ntest.letobj = testObj");
2998 CHECK_CALLED(global_letobj_i);
3000 SET_EXPECT(global_setobj_i);
3001 parse_script_a("Option Explicit\nset setobj = testObj");
3002 CHECK_CALLED(global_setobj_i);
3004 SET_EXPECT(global_setobj_i);
3005 parse_script_a("Option Explicit\nset test.setobj = testObj");
3006 CHECK_CALLED(global_setobj_i);
3008 hres = parse_script_ar("dim x\nx = testObj.rem");
3009 ok(hres == S_OK, "use of 'rem' as dot identifier failed: %x08\n", hres);
3011 SET_EXPECT(testobj_propget_d);
3012 SET_EXPECT(testobj_propget_i);
3013 parse_script_a("dim x\nx = testObj.propget");
3014 CHECK_CALLED(testobj_propget_d);
3015 CHECK_CALLED(testobj_propget_i);
3017 SET_EXPECT(testobj_propput_d);
3018 SET_EXPECT(testobj_propput_i);
3019 parse_script_a("testObj.propput = 1");
3020 CHECK_CALLED(testobj_propput_d);
3021 CHECK_CALLED(testobj_propput_i);
3023 SET_EXPECT(global_propargput_d);
3024 SET_EXPECT(global_propargput_i);
3025 parse_script_a("propargput(counter(), counter()) = counter()");
3026 CHECK_CALLED(global_propargput_d);
3027 CHECK_CALLED(global_propargput_i);
3029 SET_EXPECT(global_propargput_d);
3030 SET_EXPECT(global_propargput_i);
3031 parse_script_a("test.propargput(counter(), counter()) = counter()");
3032 CHECK_CALLED(global_propargput_d);
3033 CHECK_CALLED(global_propargput_i);
3035 SET_EXPECT(global_propargput1_d);
3036 SET_EXPECT(global_propargput1_i);
3037 parse_script_a("propargput1 (counter()) = counter()");
3038 CHECK_CALLED(global_propargput1_d);
3039 CHECK_CALLED(global_propargput1_i);
3041 SET_EXPECT(global_propargput1_d);
3042 SET_EXPECT(global_propargput1_i);
3043 parse_script_a("test.propargput1(counter()) = counter()");
3044 CHECK_CALLED(global_propargput1_d);
3045 CHECK_CALLED(global_propargput1_i);
3047 SET_EXPECT(global_propargset_d);
3048 SET_EXPECT(global_propargset_i);
3049 parse_script_a("set propargset (counter()) = testObj");
3050 CHECK_CALLED(global_propargset_d);
3051 CHECK_CALLED(global_propargset_i);
3053 SET_EXPECT(testobj_propget_d);
3054 SET_EXPECT(testobj_propget_i);
3055 parse_script_a("dim x\nwith testObj\nx=1+.propget\nend with");
3056 CHECK_CALLED(testobj_propget_d);
3057 CHECK_CALLED(testobj_propget_i);
3059 SET_EXPECT(testobj_propput_d);
3060 SET_EXPECT(testobj_propput_i);
3061 parse_script_a("with testObj\n.propput = 1\nend with");
3062 CHECK_CALLED(testobj_propput_d);
3063 CHECK_CALLED(testobj_propput_i);
3065 SET_EXPECT(testobj_valueput_i);
3066 parse_script_a("dim x\n"
3067 "set x = testObj\n"
3068 "x(counter(), counter()) = counter\n");
3069 CHECK_CALLED(testobj_valueput_i);
3071 parse_script_a("dim x\nx = testObj.property(1)");
3073 parse_htmlscript_a("<!--");
3074 parse_htmlscript_a(" -->");
3075 parse_htmlscript_a("<!--\ndim x\nx=1\n-->\n");
3076 parse_htmlscript_a("<!--\ndim x\n-->\n<!--\nx=1\n-->\n");
3078 SET_EXPECT(OnScriptError);
3079 hres = parse_script_ar("<!--");
3080 ok(FAILED(hres), "script didn't fail\n");
3081 CHECK_CALLED(OnScriptError);
3083 SET_EXPECT(global_success_d);
3084 SET_EXPECT(global_success_i);
3085 parse_htmlscript_a("<!--\n<!-- ignore this <> <>\n--> <>\nCall reportSuccess()\n-->\n");
3086 CHECK_CALLED(global_success_d);
3087 CHECK_CALLED(global_success_i);
3089 next_cnt = 0;
3090 SET_EXPECT(collectionobj_newenum_i);
3091 SET_EXPECT(Next);
3092 parse_script_a("for each x in collectionObj\nnext");
3093 CHECK_CALLED(collectionobj_newenum_i);
3094 CHECK_CALLED(Next);
3095 ok(next_cnt == 4, "next_cnt = %d\n", next_cnt);
3097 parse_script_a("x = 1\n Call ok(x = 1, \"x = \" & x)");
3099 parse_script_a("x = _ \n3");
3101 test_global_vars_ref(TRUE);
3102 test_global_vars_ref(FALSE);
3104 SET_EXPECT(OnScriptError);
3105 hres = parse_script_ar("throwInt(&h80080008&)");
3106 ok(hres == 0x80080008, "hres = %08x\n", hres);
3107 CHECK_CALLED(OnScriptError);
3109 /* DISP_E_BADINDEX */
3110 SET_EXPECT(OnScriptError);
3111 hres = parse_script_ar("throwInt(&h8002000b&)");
3112 ok(hres == MAKE_VBSERROR(9), "hres = %08x\n", hres);
3113 CHECK_CALLED(OnScriptError);
3115 SET_EXPECT(OnScriptError);
3116 hres = parse_script_ar("throwInt(&h800a0009&)");
3117 ok(hres == MAKE_VBSERROR(9), "hres = %08x\n", hres);
3118 CHECK_CALLED(OnScriptError);
3120 onerror_hres = S_OK;
3121 SET_EXPECT(OnScriptError);
3122 hres = parse_script_ar("throwInt(&h800a0009&)");
3123 ok(hres == SCRIPT_E_REPORTED, "hres = %08x\n", hres);
3124 CHECK_CALLED(OnScriptError);
3126 /* E_NOTIMPL */
3127 SET_EXPECT(OnScriptError);
3128 hres = parse_script_ar("throwInt(&h80004001&)");
3129 ok(hres == MAKE_VBSERROR(445), "hres = %08x\n", hres);
3130 CHECK_CALLED(OnScriptError);
3132 onerror_hres = S_OK;
3133 SET_EXPECT(OnScriptError);
3134 hres = parse_script_ar("throwInt(&h80004001&)");
3135 ok(hres == SCRIPT_E_REPORTED, "hres = %08x\n", hres);
3136 CHECK_CALLED(OnScriptError);
3138 SET_EXPECT(global_testoptionalarg_i);
3139 parse_script_a("call testOptionalArg(1,,2)");
3140 CHECK_CALLED(global_testoptionalarg_i);
3142 SET_EXPECT(global_testoptionalarg_i);
3143 parse_script_a("call testOptionalArg(,1,1)");
3144 CHECK_CALLED(global_testoptionalarg_i);
3146 SET_EXPECT(global_testoptionalarg_i);
3147 parse_script_a("testOptionalArg 1,,2");
3148 CHECK_CALLED(global_testoptionalarg_i);
3150 parse_script_a("sub x()\n"
3151 " dim y\n"
3152 " y = cint(3)\n"
3153 "end sub\n"
3154 "x\n");
3156 strict_dispid_check = FALSE;
3158 SET_EXPECT(testobj_value_i);
3159 parse_script_a("dim n,o\n set o = testObj\n n = o(1,2)\n call ok(n=2, \"n = \" & n)\n");
3160 CHECK_CALLED(testobj_value_i);
3162 SET_EXPECT(testobj_value_i);
3163 parse_script_a("dim n,o\n set o = testObj\n n = o\n call ok(n=0, \"n = \" & n)\n");
3164 CHECK_CALLED(testobj_value_i);
3166 parse_script_a("Sub testsub\n"
3167 "x = 1\n"
3168 "Call ok(x = 1, \"x = \" & x)\n"
3169 "End Sub\n"
3170 "Call testsub()");
3172 parse_script_a("Call ok(getVT(x) = \"VT_EMPTY*\", \"getVT(x) = \" & getVT(x))\n");
3173 parse_script_a("Call ok(x = \"\", \"x = \" & x)\n");
3174 parse_script_a("x = y\n"
3175 "Call ok(getVT(x) = \"VT_EMPTY*\", \"getVT(x) = \" & getVT(x))\n"
3176 "Call ok(getVT(y) = \"VT_EMPTY*\", \"getVT(y) = \" & getVT(y))");
3177 SET_EXPECT(OnScriptError);
3178 hres = parse_script_ar("x = y(\"a\")");
3179 ok(FAILED(hres), "script didn't fail\n");
3180 CHECK_CALLED(OnScriptError);
3182 SET_EXPECT(global_success_d);
3183 SET_EXPECT(global_success_i);
3184 parse_script_a("' comment\r"
3185 "x = _\r3\r"
3186 "x = _\n3\r"
3187 "x = _\r\n3\r"
3188 "Sub testsub(arg)\r"
3189 "If arg = 1 Then\r\r"
3190 "Call reportSuccess()\n\n"
3191 "End If\r\n"
3192 "End Sub\n\r"
3193 "Call testsub(1)");
3194 CHECK_CALLED(global_success_d);
3195 CHECK_CALLED(global_success_i);
3197 run_from_res("lang.vbs");
3198 run_from_res("api.vbs");
3199 run_from_res("regexp.vbs");
3200 run_from_res("error.vbs");
3202 test_procedures();
3203 test_gc();
3204 test_msgbox();
3205 test_isexpression();
3206 test_parse_errors();
3207 test_parse_context();
3208 test_callbacks();
3209 test_multiple_parse();
3212 static BOOL check_vbscript(void)
3214 IRegExp2 *regexp;
3215 IUnknown *unk;
3216 HRESULT hres;
3218 hres = CoCreateInstance(&CLSID_VBScriptRegExp, NULL,
3219 CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
3220 &IID_IUnknown, (void**)&unk);
3221 if(hres == REGDB_E_CLASSNOTREG)
3222 return FALSE;
3223 ok(hres == S_OK, "CoCreateInstance(CLSID_VBScriptRegExp) failed: %x\n", hres);
3225 hres = IUnknown_QueryInterface(unk, &IID_IRegExp2, (void**)&regexp);
3226 if(SUCCEEDED(hres))
3227 IRegExp2_Release(regexp);
3228 IUnknown_Release(unk);
3230 return hres == S_OK;
3233 START_TEST(run)
3235 int argc;
3236 char **argv;
3238 detect_locale();
3239 if(!is_english)
3240 skip("Skipping some tests in non-English locale\n");
3242 argc = winetest_get_mainargs(&argv);
3244 CoInitialize(NULL);
3246 if(!check_vbscript()) {
3247 win_skip("Broken engine, probably too old\n");
3248 }else if(argc > 2) {
3249 allow_ui = TRUE;
3250 uic_handling = SCRIPTUICHANDLING_ALLOW;
3251 run_from_file(argv[2]);
3252 }else {
3253 run_tests();
3256 CoUninitialize();