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
28 #include "wine/test.h"
30 extern const CLSID CLSID_VBScript;
32 #define DEFINE_EXPECT(func) \
33 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
35 #define SET_EXPECT(func) \
36 expect_ ## func = TRUE
38 #define SET_CALLED(func) \
39 called_ ## func = TRUE
41 #define CHECK_EXPECT2(func) \
43 ok(expect_ ##func, "unexpected call " #func "\n"); \
44 called_ ## func = TRUE; \
47 #define CHECK_EXPECT(func) \
49 CHECK_EXPECT2(func); \
50 expect_ ## func = FALSE; \
53 #define CHECK_CALLED(func) \
55 ok(called_ ## func, "expected " #func "\n"); \
56 expect_ ## func = called_ ## func = FALSE; \
59 DEFINE_EXPECT(global_success_d);
60 DEFINE_EXPECT(global_success_i);
61 DEFINE_EXPECT(global_vbvar_d);
62 DEFINE_EXPECT(global_vbvar_i);
63 DEFINE_EXPECT(testobj_propget_d);
64 DEFINE_EXPECT(testobj_propget_i);
65 DEFINE_EXPECT(testobj_propput_d);
66 DEFINE_EXPECT(testobj_propput_i);
68 #define DISPID_GLOBAL_REPORTSUCCESS 1000
69 #define DISPID_GLOBAL_TRACE 1001
70 #define DISPID_GLOBAL_OK 1002
71 #define DISPID_GLOBAL_GETVT 1003
72 #define DISPID_GLOBAL_ISENGLANG 1004
73 #define DISPID_GLOBAL_VBVAR 1005
74 #define DISPID_GLOBAL_TESTOBJ 1006
75 #define DISPID_GLOBAL_ISNULLDISP 1007
76 #define DISPID_GLOBAL_TESTDISP 1008
77 #define DISPID_GLOBAL_REFOBJ 1009
79 #define DISPID_TESTOBJ_PROPGET 2000
80 #define DISPID_TESTOBJ_PROPPUT 2001
82 static const WCHAR testW[] = {'t','e','s','t',0};
84 static BOOL strict_dispid_check;
85 static const char *test_name = "(null)";
87 static BSTR a2bstr(const char *str)
92 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
93 ret = SysAllocStringLen(NULL, len-1);
94 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
99 static int strcmp_wa(LPCWSTR strw, const char *stra)
102 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
103 return lstrcmpA(buf, stra);
106 static const char *vt2a(VARIANT *v)
108 if(V_VT(v) == (VT_BYREF|VT_VARIANT)) {
110 sprintf(buf, "%s*", vt2a(V_BYREF(v)));
128 return "VT_DISPATCH";
131 case VT_ARRAY|VT_VARIANT:
132 return "VT_ARRAY|VT_VARIANT";
134 ok(0, "unknown vt %d\n", V_VT(v));
139 /* Returns true if the user interface is in English. Note that this does not
140 * presume of the formatting of dates, numbers, etc.
142 static BOOL is_lang_english(void)
144 static HMODULE hkernel32 = NULL;
145 static LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL;
146 static LANGID (WINAPI *pGetUserDefaultUILanguage)(void) = NULL;
150 hkernel32 = GetModuleHandleA("kernel32.dll");
151 pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
152 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
154 if (pGetThreadUILanguage)
155 return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH;
156 if (pGetUserDefaultUILanguage)
157 return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH;
159 return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
162 static void test_disp(IDispatch *disp)
164 DISPID id, public_prop_id, public_prop2_id, public_func_id, public_sub_id, defvalget_id;
165 DISPID named_args[5] = {DISPID_PROPERTYPUT};
167 DISPPARAMS dp = {args, named_args};
173 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
174 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
176 str = a2bstr("publicProp");
177 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_prop_id);
179 ok(hres == S_OK, "GetDispID(publicProp) failed: %08x\n", hres);
181 str = a2bstr("PUBLICPROP");
182 hres = IDispatchEx_GetDispID(dispex, str, 0, &id);
184 ok(hres == S_OK, "GetDispID(PUBLICPROP) failed: %08x\n", hres);
185 ok(public_prop_id == id, "id = %d\n", public_prop_id);
187 str = a2bstr("publicPROP2");
188 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_prop2_id);
190 ok(hres == S_OK, "GetDispID(publicProp2) failed: %08x\n", hres);
192 str = a2bstr("defValGet");
193 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &defvalget_id);
195 ok(hres == S_OK, "GetDispID(defValGet) failed: %08x\n", hres);
196 ok(defvalget_id == DISPID_VALUE, "id = %d\n", defvalget_id);
198 str = a2bstr("privateProp");
199 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &id);
201 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateProp) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
202 ok(id == -1, "id = %d\n", id);
204 str = a2bstr("class_initialize");
205 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &id);
207 ok(hres == S_OK, "GetDispID(publicProp2) failed: %08x\n", hres);
209 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
210 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
211 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
213 V_VT(args) = VT_BOOL;
214 V_BOOL(args) = VARIANT_TRUE;
215 dp.cArgs = dp.cNamedArgs = 1;
217 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYPUT, &dp, &v, &ei, NULL);
218 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
219 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
221 dp.cArgs = dp.cNamedArgs = 0;
222 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
223 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
224 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
225 ok(V_BOOL(&v), "V_BOOL(v) = %x\n", V_BOOL(&v));
228 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
229 ok(hres == DISP_E_MEMBERNOTFOUND, "InvokeEx failed: %08x, expected DISP_E_MEMBERNOTFOUND\n", hres);
230 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
232 V_VT(args) = VT_BOOL;
233 V_BOOL(args) = VARIANT_FALSE;
236 hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYPUT, &dp, NULL, &ei, NULL);
237 ok(hres == DISP_E_PARAMNOTOPTIONAL, "InvokeEx failed: %08x, expected DISP_E_PARAMNOTOPTIONAL\n", hres);
239 str = a2bstr("publicFunction");
240 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_func_id);
242 ok(hres == S_OK, "GetDispID(publicFunction) failed: %08x\n", hres);
243 ok(public_func_id != -1, "public_func_id = -1\n");
245 str = a2bstr("publicSub");
246 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_sub_id);
248 ok(hres == S_OK, "GetDispID(publicSub) failed: %08x\n", hres);
249 ok(public_sub_id != -1, "public_func_id = -1\n");
251 dp.cArgs = dp.cNamedArgs = 0;
252 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
253 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
254 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
255 ok(V_I2(&v) == 4, "V_I2(v) = %d\n", V_I2(&v));
257 dp.cArgs = dp.cNamedArgs = 0;
258 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
259 ok(hres == DISP_E_MEMBERNOTFOUND, "InvokeEx failed: %08x, expected DISP_E_MEMBERNOTFOUND\n", hres);
260 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
262 dp.cArgs = dp.cNamedArgs = 0;
263 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
264 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
265 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
266 ok(V_I2(&v) == 4, "V_I2(v) = %d\n", V_I2(&v));
268 dp.cArgs = dp.cNamedArgs = 0;
269 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
270 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
271 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
273 dp.cArgs = dp.cNamedArgs = 0;
274 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
275 ok(hres == DISP_E_MEMBERNOTFOUND, "InvokeEx failed: %08x, expected DISP_E_MEMBERNOTFOUND\n", hres);
276 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
278 dp.cArgs = dp.cNamedArgs = 0;
279 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
280 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
281 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
283 V_VT(args) = VT_BOOL;
284 V_BOOL(args) = VARIANT_TRUE;
285 dp.cArgs = dp.cNamedArgs = 1;
286 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_PROPERTYPUT, &dp, NULL, &ei, NULL);
287 ok(FAILED(hres), "InvokeEx succeeded: %08x\n", hres);
289 dp.cArgs = dp.cNamedArgs = 0;
290 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
291 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
292 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
293 ok(V_I2(&v) == 4, "V_I2(v) = %d\n", V_I2(&v));
295 dp.cArgs = dp.cNamedArgs = 0;
296 hres = IDispatchEx_InvokeEx(dispex, public_func_id, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
297 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
298 ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
299 ok(V_I2(&v) == 4, "V_I2(v) = %d\n", V_I2(&v));
301 dp.cArgs = dp.cNamedArgs = 0;
302 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
303 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
304 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
306 dp.cArgs = dp.cNamedArgs = 0;
307 hres = IDispatchEx_InvokeEx(dispex, public_sub_id, 0, DISPATCH_METHOD, &dp, &v, &ei, NULL);
308 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
309 ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
311 str = a2bstr("privateSub");
312 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &id);
314 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateSub) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
315 ok(id == -1, "id = %d\n", id);
317 str = a2bstr("dynprop");
318 hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive|fdexNameEnsure, &id);
319 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateProp) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
320 ok(id == -1, "id = %d\n", id);
321 hres = IDispatchEx_GetDispID(dispex, str, fdexNameEnsure, &id);
322 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateProp) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
323 ok(id == -1, "id = %d\n", id);
326 IDispatchEx_Release(dispex);
329 #define test_grfdex(a,b) _test_grfdex(__LINE__,a,b)
330 static void _test_grfdex(unsigned line, DWORD grfdex, DWORD expect)
332 ok_(__FILE__,line)(grfdex == expect, "grfdex = %x, expected %x\n", grfdex, expect);
335 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
339 if(IsEqualGUID(riid, &IID_IUnknown)
340 || IsEqualGUID(riid, &IID_IDispatch)
341 || IsEqualGUID(riid, &IID_IDispatchEx))
344 return E_NOINTERFACE;
346 IUnknown_AddRef((IUnknown*)*ppv);
350 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
355 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
360 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
362 ok(0, "unexpected call\n");
366 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
367 LCID lcid, ITypeInfo **ppTInfo)
369 ok(0, "unexpected call\n");
373 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
374 LPOLESTR *rgszNames, UINT cNames,
375 LCID lcid, DISPID *rgDispId)
377 ok(0, "unexpected call\n");
381 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
382 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
383 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
385 ok(0, "unexpected call\n");
389 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
391 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
395 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
397 ok(0, "unexpected call\n");
401 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
403 ok(0, "unexpected call\n");
407 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
409 ok(0, "unexpected call\n");
413 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
415 ok(0, "unexpected call\n");
419 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
421 ok(0, "unexpected call\n");
425 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
427 ok(0, "unexpected call\n");
431 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
432 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
434 ok(0, "unexpected call\n");
438 static HRESULT WINAPI testObj_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
440 if(!strcmp_wa(bstrName, "propget")) {
441 CHECK_EXPECT(testobj_propget_d);
442 test_grfdex(grfdex, fdexNameCaseInsensitive);
443 *pid = DISPID_TESTOBJ_PROPGET;
446 if(!strcmp_wa(bstrName, "propput")) {
447 CHECK_EXPECT(testobj_propput_d);
448 test_grfdex(grfdex, fdexNameCaseInsensitive);
449 *pid = DISPID_TESTOBJ_PROPPUT;
453 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
454 return DISP_E_UNKNOWNNAME;
457 static HRESULT WINAPI testObj_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
458 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
461 case DISPID_TESTOBJ_PROPGET:
462 CHECK_EXPECT(testobj_propget_i);
464 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
465 ok(pdp != NULL, "pdp == NULL\n");
466 ok(!pdp->rgvarg, "rgvarg == NULL\n");
467 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
468 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
469 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
470 ok(pvarRes != NULL, "pvarRes == NULL\n");
471 ok(pei != NULL, "pei == NULL\n");
473 V_VT(pvarRes) = VT_I2;
476 case DISPID_TESTOBJ_PROPPUT:
477 CHECK_EXPECT(testobj_propput_i);
479 ok(wFlags == DISPATCH_PROPERTYPUT, "wFlags = %x\n", wFlags);
480 ok(pdp != NULL, "pdp == NULL\n");
481 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
482 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
483 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
484 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
485 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
486 ok(!pvarRes, "pvarRes != NULL\n");
487 ok(pei != NULL, "pei == NULL\n");
489 ok(V_VT(pdp->rgvarg) == VT_I2, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
490 ok(V_I2(pdp->rgvarg) == 1, "V_I2(psp->rgvargs) = %d\n", V_I2(pdp->rgvarg));
494 ok(0, "unexpected call %d\n", id);
498 static IDispatchExVtbl testObjVtbl = {
499 DispatchEx_QueryInterface,
502 DispatchEx_GetTypeInfoCount,
503 DispatchEx_GetTypeInfo,
504 DispatchEx_GetIDsOfNames,
508 DispatchEx_DeleteMemberByName,
509 DispatchEx_DeleteMemberByDispID,
510 DispatchEx_GetMemberProperties,
511 DispatchEx_GetMemberName,
512 DispatchEx_GetNextDispID,
513 DispatchEx_GetNameSpaceParent
516 static IDispatchEx testObj = { &testObjVtbl };
518 static ULONG refobj_ref;
520 static ULONG WINAPI RefObj_AddRef(IDispatchEx *iface)
525 static ULONG WINAPI RefObj_Release(IDispatchEx *iface)
530 static IDispatchExVtbl RefObjVtbl = {
531 DispatchEx_QueryInterface,
534 DispatchEx_GetTypeInfoCount,
535 DispatchEx_GetTypeInfo,
536 DispatchEx_GetIDsOfNames,
538 DispatchEx_GetDispID,
540 DispatchEx_DeleteMemberByName,
541 DispatchEx_DeleteMemberByDispID,
542 DispatchEx_GetMemberProperties,
543 DispatchEx_GetMemberName,
544 DispatchEx_GetNextDispID,
545 DispatchEx_GetNameSpaceParent
548 static IDispatchEx RefObj = { &RefObjVtbl };
550 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
552 if(!strcmp_wa(bstrName, "ok")) {
553 test_grfdex(grfdex, fdexNameCaseInsensitive);
554 *pid = DISPID_GLOBAL_OK;
557 if(!strcmp_wa(bstrName, "trace")) {
558 test_grfdex(grfdex, fdexNameCaseInsensitive);
559 *pid = DISPID_GLOBAL_TRACE;
562 if(!strcmp_wa(bstrName, "reportSuccess")) {
563 CHECK_EXPECT(global_success_d);
564 test_grfdex(grfdex, fdexNameCaseInsensitive);
565 *pid = DISPID_GLOBAL_REPORTSUCCESS;
568 if(!strcmp_wa(bstrName, "getVT")) {
569 test_grfdex(grfdex, fdexNameCaseInsensitive);
570 *pid = DISPID_GLOBAL_GETVT;
573 if(!strcmp_wa(bstrName, "isEnglishLang")) {
574 test_grfdex(grfdex, fdexNameCaseInsensitive);
575 *pid = DISPID_GLOBAL_ISENGLANG;
578 if(!strcmp_wa(bstrName, "testObj")) {
579 test_grfdex(grfdex, fdexNameCaseInsensitive);
580 *pid = DISPID_GLOBAL_TESTOBJ;
583 if(!strcmp_wa(bstrName, "vbvar")) {
584 CHECK_EXPECT(global_vbvar_d);
585 test_grfdex(grfdex, fdexNameCaseInsensitive);
586 *pid = DISPID_GLOBAL_VBVAR;
589 if(!strcmp_wa(bstrName, "isNullDisp")) {
590 test_grfdex(grfdex, fdexNameCaseInsensitive);
591 *pid = DISPID_GLOBAL_ISNULLDISP;
594 if(!strcmp_wa(bstrName, "testDisp")) {
595 test_grfdex(grfdex, fdexNameCaseInsensitive);
596 *pid = DISPID_GLOBAL_TESTDISP;
599 if(!strcmp_wa(bstrName, "RefObj")) {
600 test_grfdex(grfdex, fdexNameCaseInsensitive);
601 *pid = DISPID_GLOBAL_REFOBJ;
605 if(strict_dispid_check && strcmp_wa(bstrName, "x"))
606 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
607 return DISP_E_UNKNOWNNAME;
610 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
611 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
614 case DISPID_GLOBAL_OK: {
617 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
618 ok(pdp != NULL, "pdp == NULL\n");
619 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
620 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
621 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
622 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
623 if(wFlags & INVOKE_PROPERTYGET)
624 ok(pvarRes != NULL, "pvarRes == NULL\n");
626 ok(!pvarRes, "pvarRes != NULL\n");
627 ok(pei != NULL, "pei == NULL\n");
629 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
632 if(V_VT(b) == (VT_BYREF|VT_VARIANT))
635 ok(V_VT(b) == VT_BOOL, "V_VT(b) = %d\n", V_VT(b));
637 ok(V_BOOL(b), "%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
641 case DISPID_GLOBAL_TRACE:
642 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
643 ok(pdp != NULL, "pdp == NULL\n");
644 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
645 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
646 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
647 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
648 ok(!pvarRes, "pvarRes != NULL\n");
649 ok(pei != NULL, "pei == NULL\n");
651 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
652 if(V_VT(pdp->rgvarg) == VT_BSTR)
653 trace("%s: %s\n", test_name, wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
657 case DISPID_GLOBAL_REPORTSUCCESS:
658 CHECK_EXPECT(global_success_i);
660 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
661 ok(pdp != NULL, "pdp == NULL\n");
662 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
663 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
664 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
665 ok(!pvarRes, "pvarRes != NULL\n");
666 ok(pei != NULL, "pei == NULL\n");
670 case DISPID_GLOBAL_GETVT:
671 ok(pdp != NULL, "pdp == NULL\n");
672 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
673 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
674 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
675 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
676 ok(pvarRes != NULL, "pvarRes == NULL\n");
677 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pvarRes) = %d\n", V_VT(pvarRes));
678 ok(pei != NULL, "pei == NULL\n");
680 V_VT(pvarRes) = VT_BSTR;
681 V_BSTR(pvarRes) = a2bstr(vt2a(pdp->rgvarg));
684 case DISPID_GLOBAL_ISENGLANG:
685 ok(wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
686 ok(pdp != NULL, "pdp == NULL\n");
687 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
688 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
689 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
690 ok(pvarRes != NULL, "pvarRes == NULL\n");
691 ok(pei != NULL, "pei == NULL\n");
693 V_VT(pvarRes) = VT_BOOL;
694 if(is_lang_english()) {
695 V_BOOL(pvarRes) = VARIANT_TRUE;
697 skip("Skipping some tests in non-English UIs\n");
698 V_BOOL(pvarRes) = VARIANT_FALSE;
702 case DISPID_GLOBAL_VBVAR:
703 CHECK_EXPECT(global_vbvar_i);
705 ok(wFlags == DISPATCH_PROPERTYPUT, "wFlags = %x\n", wFlags);
706 ok(pdp != NULL, "pdp == NULL\n");
707 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
708 ok(pdp->rgdispidNamedArgs != NULL, "rgdispidNamedArgs == NULL\n");
709 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
710 ok(pdp->cNamedArgs == 1, "cNamedArgs = %d\n", pdp->cNamedArgs);
711 ok(pdp->rgdispidNamedArgs[0] == DISPID_PROPERTYPUT, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
712 ok(!pvarRes, "pvarRes != NULL\n");
713 ok(pei != NULL, "pei == NULL\n");
715 ok(V_VT(pdp->rgvarg) == VT_I2, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
716 ok(V_I2(pdp->rgvarg) == 3, "V_I2(psp->rgvargs) = %d\n", V_I2(pdp->rgvarg));
719 case DISPID_GLOBAL_TESTOBJ:
720 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
722 ok(pdp != NULL, "pdp == NULL\n");
723 ok(!pdp->rgvarg, "rgvarg == NULL\n");
724 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
725 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
726 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
727 ok(pvarRes != NULL, "pvarRes == NULL\n");
728 ok(pei != NULL, "pei == NULL\n");
730 V_VT(pvarRes) = VT_DISPATCH;
731 V_DISPATCH(pvarRes) = (IDispatch*)&testObj;
734 case DISPID_GLOBAL_REFOBJ:
735 ok(wFlags == (DISPATCH_PROPERTYGET|DISPATCH_METHOD), "wFlags = %x\n", wFlags);
737 ok(pdp != NULL, "pdp == NULL\n");
738 ok(!pdp->rgvarg, "rgvarg == NULL\n");
739 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
740 ok(!pdp->cArgs, "cArgs = %d\n", pdp->cArgs);
741 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
742 ok(pvarRes != NULL, "pvarRes == NULL\n");
743 ok(pei != NULL, "pei == NULL\n");
745 IDispatchEx_AddRef(&RefObj);
746 V_VT(pvarRes) = VT_DISPATCH;
747 V_DISPATCH(pvarRes) = (IDispatch*)&RefObj;
750 case DISPID_GLOBAL_ISNULLDISP: {
753 ok(wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
754 ok(pdp != NULL, "pdp == NULL\n");
755 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
756 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
757 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
758 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
759 ok(pvarRes != NULL, "pvarRes == NULL\n");
760 ok(pei != NULL, "pei == NULL\n");
763 if(V_VT(v) == (VT_VARIANT|VT_BYREF))
766 ok(V_VT(v) == VT_DISPATCH, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
767 V_VT(pvarRes) = VT_BOOL;
768 V_BOOL(pvarRes) = V_DISPATCH(v) ? VARIANT_FALSE : VARIANT_TRUE;
772 case DISPID_GLOBAL_TESTDISP:
773 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
774 ok(pdp != NULL, "pdp == NULL\n");
775 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
776 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
777 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
778 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
779 ok(!pvarRes, "pvarRes != NULL\n");
780 ok(pei != NULL, "pei == NULL\n");
782 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
783 test_disp(V_DISPATCH(pdp->rgvarg));
787 ok(0, "unexpected call %d\n", id);
788 return DISP_E_MEMBERNOTFOUND;
791 static IDispatchExVtbl GlobalVtbl = {
792 DispatchEx_QueryInterface,
795 DispatchEx_GetTypeInfoCount,
796 DispatchEx_GetTypeInfo,
797 DispatchEx_GetIDsOfNames,
801 DispatchEx_DeleteMemberByName,
802 DispatchEx_DeleteMemberByDispID,
803 DispatchEx_GetMemberProperties,
804 DispatchEx_GetMemberName,
805 DispatchEx_GetNextDispID,
806 DispatchEx_GetNameSpaceParent
809 static IDispatchEx Global = { &GlobalVtbl };
811 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
815 if(IsEqualGUID(&IID_IUnknown, riid))
817 else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
820 return E_NOINTERFACE;
822 IUnknown_AddRef((IUnknown*)*ppv);
826 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
831 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
836 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
838 *plcid = GetUserDefaultLCID();
842 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
843 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
845 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
846 ok(!ppti, "ppti != NULL\n");
848 if(strcmp_wa(pstrName, "test"))
849 ok(0, "unexpected pstrName %s\n", wine_dbgstr_w(pstrName));
851 *ppiunkItem = (IUnknown*)&Global;
855 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
860 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
861 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
866 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
871 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
876 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
881 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
886 #undef ACTSCPSITE_THIS
888 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
889 ActiveScriptSite_QueryInterface,
890 ActiveScriptSite_AddRef,
891 ActiveScriptSite_Release,
892 ActiveScriptSite_GetLCID,
893 ActiveScriptSite_GetItemInfo,
894 ActiveScriptSite_GetDocVersionString,
895 ActiveScriptSite_OnScriptTerminate,
896 ActiveScriptSite_OnStateChange,
897 ActiveScriptSite_OnScriptError,
898 ActiveScriptSite_OnEnterScript,
899 ActiveScriptSite_OnLeaveScript
902 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
904 static IActiveScript *create_script(void)
906 IActiveScript *script;
909 hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
910 &IID_IActiveScript, (void**)&script);
911 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
916 static HRESULT parse_script(DWORD flags, BSTR script_str)
918 IActiveScriptParse *parser;
919 IActiveScript *engine;
920 IDispatch *script_disp;
924 engine = create_script();
928 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
929 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
932 IActiveScript_Release(engine);
936 hres = IActiveScriptParse64_InitNew(parser);
937 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
939 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
940 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
942 hres = IActiveScript_AddNamedItem(engine, testW,
943 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags);
944 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
946 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
947 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
949 hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp);
950 ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
951 ok(script_disp != NULL, "script_disp == NULL\n");
952 ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n");
954 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
956 IActiveScript_Close(engine);
958 IDispatch_Release(script_disp);
959 IActiveScript_Release(engine);
961 ref = IUnknown_Release(parser);
962 ok(!ref, "ref=%d\n", ref);
966 static void parse_script_af(DWORD flags, const char *src)
972 hres = parse_script(flags, tmp);
974 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
977 static void parse_script_a(const char *src)
979 parse_script_af(SCRIPTITEM_GLOBALMEMBERS, src);
982 static void test_gc(void)
984 IActiveScriptParse *parser;
985 IActiveScript *engine;
989 strict_dispid_check = FALSE;
991 engine = create_script();
995 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
996 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
998 hres = IActiveScriptParse64_InitNew(parser);
999 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1001 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1002 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1004 hres = IActiveScript_AddNamedItem(engine, testW,
1005 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
1006 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1008 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1009 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1014 " Public Sub Class_Terminate\n"
1015 " Call reportSuccess()\n"
1021 "set x = nothing\n");
1023 hres = IActiveScriptParse64_ParseScriptText(parser, src, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1024 ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
1027 SET_EXPECT(global_success_d);
1028 SET_EXPECT(global_success_i);
1029 IActiveScript_Close(engine);
1030 CHECK_CALLED(global_success_d);
1031 CHECK_CALLED(global_success_i);
1033 IActiveScript_Release(engine);
1034 IUnknown_Release(parser);
1037 static HRESULT test_global_vars_ref(BOOL use_close)
1039 IActiveScriptParse *parser;
1040 IActiveScript *engine;
1045 engine = create_script();
1049 hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
1050 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
1053 IActiveScript_Release(engine);
1057 hres = IActiveScriptParse64_InitNew(parser);
1058 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
1060 hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
1061 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
1063 hres = IActiveScript_AddNamedItem(engine, testW, SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
1064 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
1066 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
1067 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1071 script_str = a2bstr("Dim x\nset x = RefObj\n");
1072 hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1073 SysFreeString(script_str);
1075 ok(refobj_ref, "refobj_ref = 0\n");
1078 hres = IActiveScript_Close(engine);
1079 ok(hres == S_OK, "Close failed: %08x\n", hres);
1081 hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_UNINITIALIZED);
1082 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
1085 ok(!refobj_ref, "refobj_ref = %d\n", refobj_ref);
1087 IActiveScript_Release(engine);
1089 ref = IUnknown_Release(parser);
1090 ok(!ref, "ref=%d\n", ref);
1094 static BSTR get_script_from_file(const char *filename)
1098 const char *file_map;
1101 file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
1102 if(file == INVALID_HANDLE_VALUE) {
1103 trace("Could not open file: %u\n", GetLastError());
1107 size = GetFileSize(file, NULL);
1109 map = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
1111 if(map == INVALID_HANDLE_VALUE) {
1112 trace("Could not create file mapping: %u\n", GetLastError());
1116 file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
1119 trace("MapViewOfFile failed: %u\n", GetLastError());
1123 len = MultiByteToWideChar(CP_ACP, 0, file_map, size, NULL, 0);
1124 ret = SysAllocStringLen(NULL, len);
1125 MultiByteToWideChar(CP_ACP, 0, file_map, size, ret, len);
1127 UnmapViewOfFile(file_map);
1132 static void run_from_file(const char *filename)
1137 script_str = get_script_from_file(filename);
1141 strict_dispid_check = FALSE;
1142 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, script_str);
1143 SysFreeString(script_str);
1144 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1147 static void run_from_res(const char *name)
1155 strict_dispid_check = FALSE;
1158 src = FindResourceA(NULL, name, (LPCSTR)40);
1159 ok(src != NULL, "Could not find resource %s\n", name);
1161 size = SizeofResource(NULL, src);
1162 data = LoadResource(NULL, src);
1164 len = MultiByteToWideChar(CP_ACP, 0, data, size, NULL, 0);
1165 str = SysAllocStringLen(NULL, len);
1166 MultiByteToWideChar(CP_ACP, 0, data, size, str, len);
1168 SET_EXPECT(global_success_d);
1169 SET_EXPECT(global_success_i);
1170 hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, str);
1171 CHECK_CALLED(global_success_d);
1172 CHECK_CALLED(global_success_i);
1174 ok(hres == S_OK, "parse_script failed: %08x\n", hres);
1178 static void run_tests(void)
1180 strict_dispid_check = TRUE;
1183 parse_script_a("' empty ;");
1185 SET_EXPECT(global_success_d);
1186 SET_EXPECT(global_success_i);
1187 parse_script_a("reportSuccess");
1188 CHECK_CALLED(global_success_d);
1189 CHECK_CALLED(global_success_i);
1191 SET_EXPECT(global_success_d);
1192 SET_EXPECT(global_success_i);
1193 parse_script_a("reportSuccess()");
1194 CHECK_CALLED(global_success_d);
1195 CHECK_CALLED(global_success_i);
1197 SET_EXPECT(global_success_d);
1198 SET_EXPECT(global_success_i);
1199 parse_script_a("Call reportSuccess");
1200 CHECK_CALLED(global_success_d);
1201 CHECK_CALLED(global_success_i);
1203 SET_EXPECT(global_vbvar_d);
1204 SET_EXPECT(global_vbvar_i);
1205 parse_script_a("Option Explicit\nvbvar = 3");
1206 CHECK_CALLED(global_vbvar_d);
1207 CHECK_CALLED(global_vbvar_i);
1209 SET_EXPECT(global_vbvar_d);
1210 SET_EXPECT(global_vbvar_i);
1211 parse_script_a("Option Explicit\nvbvar() = 3");
1212 CHECK_CALLED(global_vbvar_d);
1213 CHECK_CALLED(global_vbvar_i);
1215 SET_EXPECT(testobj_propget_d);
1216 SET_EXPECT(testobj_propget_i);
1217 parse_script_a("dim x\nx = testObj.propget");
1218 CHECK_CALLED(testobj_propget_d);
1219 CHECK_CALLED(testobj_propget_i);
1221 SET_EXPECT(testobj_propput_d);
1222 SET_EXPECT(testobj_propput_i);
1223 parse_script_a("testObj.propput = 1");
1224 CHECK_CALLED(testobj_propput_d);
1225 CHECK_CALLED(testobj_propput_i);
1227 parse_script_a("x = 1\n Call ok(x = 1, \"x = \" & x)");
1229 parse_script_a("x = _ \n3");
1231 test_global_vars_ref(TRUE);
1232 test_global_vars_ref(FALSE);
1234 strict_dispid_check = FALSE;
1236 parse_script_a("Sub testsub\n"
1238 "Call ok(x = 1, \"x = \" & x)\n"
1242 run_from_res("lang.vbs");
1243 run_from_res("api.vbs");
1248 static BOOL check_vbscript(void)
1250 IActiveScript *vbscript;
1253 hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1254 &IID_IActiveScript, (void**)&vbscript);
1256 IActiveScript_Release(vbscript);
1258 return hres == S_OK;
1266 argc = winetest_get_mainargs(&argv);
1270 if(!check_vbscript()) {
1271 win_skip("Broken engine, probably too old\n");
1272 }else if(argc > 2) {
1273 run_from_file(argv[2]);