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 CHECK_EXPECT2(func) \
40 ok(expect_ ##func, "unexpected call " #func "\n"); \
41 called_ ## func = TRUE; \
44 #define CHECK_EXPECT(func) \
46 CHECK_EXPECT2(func); \
47 expect_ ## func = FALSE; \
50 #define CHECK_CALLED(func) \
52 ok(called_ ## func, "expected " #func "\n"); \
53 expect_ ## func = called_ ## func = FALSE; \
56 DEFINE_EXPECT(global_success_d
);
57 DEFINE_EXPECT(global_success_i
);
58 DEFINE_EXPECT(global_vbvar_d
);
59 DEFINE_EXPECT(global_vbvar_i
);
60 DEFINE_EXPECT(testobj_propget_d
);
61 DEFINE_EXPECT(testobj_propget_i
);
62 DEFINE_EXPECT(testobj_propput_d
);
63 DEFINE_EXPECT(testobj_propput_i
);
64 DEFINE_EXPECT(global_propargput_d
);
65 DEFINE_EXPECT(global_propargput_i
);
67 #define DISPID_GLOBAL_REPORTSUCCESS 1000
68 #define DISPID_GLOBAL_TRACE 1001
69 #define DISPID_GLOBAL_OK 1002
70 #define DISPID_GLOBAL_GETVT 1003
71 #define DISPID_GLOBAL_ISENGLANG 1004
72 #define DISPID_GLOBAL_VBVAR 1005
73 #define DISPID_GLOBAL_TESTOBJ 1006
74 #define DISPID_GLOBAL_ISNULLDISP 1007
75 #define DISPID_GLOBAL_TESTDISP 1008
76 #define DISPID_GLOBAL_REFOBJ 1009
77 #define DISPID_GLOBAL_PROPARGPUT 1010
78 #define DISPID_GLOBAL_COUNTER 1011
80 #define DISPID_TESTOBJ_PROPGET 2000
81 #define DISPID_TESTOBJ_PROPPUT 2001
83 static const WCHAR testW
[] = {'t','e','s','t',0};
85 static BOOL strict_dispid_check
;
86 static const char *test_name
= "(null)";
87 static int test_counter
;
89 static BSTR
a2bstr(const char *str
)
94 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
95 ret
= SysAllocStringLen(NULL
, len
-1);
96 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
101 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
104 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), 0, 0);
105 return lstrcmpA(buf
, stra
);
108 static const char *vt2a(VARIANT
*v
)
110 if(V_VT(v
) == (VT_BYREF
|VT_VARIANT
)) {
112 sprintf(buf
, "%s*", vt2a(V_BYREF(v
)));
130 return "VT_DISPATCH";
133 case VT_ARRAY
|VT_VARIANT
:
134 return "VT_ARRAY|VT_VARIANT";
136 ok(0, "unknown vt %d\n", V_VT(v
));
141 /* Returns true if the user interface is in English. Note that this does not
142 * presume of the formatting of dates, numbers, etc.
144 static BOOL
is_lang_english(void)
146 static HMODULE hkernel32
= NULL
;
147 static LANGID (WINAPI
*pGetThreadUILanguage
)(void) = NULL
;
148 static LANGID (WINAPI
*pGetUserDefaultUILanguage
)(void) = NULL
;
152 hkernel32
= GetModuleHandleA("kernel32.dll");
153 pGetThreadUILanguage
= (void*)GetProcAddress(hkernel32
, "GetThreadUILanguage");
154 pGetUserDefaultUILanguage
= (void*)GetProcAddress(hkernel32
, "GetUserDefaultUILanguage");
156 if (pGetThreadUILanguage
)
157 return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH
;
158 if (pGetUserDefaultUILanguage
)
159 return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH
;
161 return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH
;
164 static void test_disp(IDispatch
*disp
)
166 DISPID id
, public_prop_id
, public_prop2_id
, public_func_id
, public_sub_id
, defvalget_id
;
167 DISPID named_args
[5] = {DISPID_PROPERTYPUT
};
169 DISPPARAMS dp
= {args
, named_args
};
175 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
176 ok(hres
== S_OK
, "Could not get IDispatchEx iface: %08x\n", hres
);
178 str
= a2bstr("publicProp");
179 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseInsensitive
, &public_prop_id
);
181 ok(hres
== S_OK
, "GetDispID(publicProp) failed: %08x\n", hres
);
183 str
= a2bstr("PUBLICPROP");
184 hres
= IDispatchEx_GetDispID(dispex
, str
, 0, &id
);
186 ok(hres
== S_OK
, "GetDispID(PUBLICPROP) failed: %08x\n", hres
);
187 ok(public_prop_id
== id
, "id = %d\n", public_prop_id
);
189 str
= a2bstr("publicPROP2");
190 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseInsensitive
, &public_prop2_id
);
192 ok(hres
== S_OK
, "GetDispID(publicProp2) failed: %08x\n", hres
);
194 str
= a2bstr("defValGet");
195 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseInsensitive
, &defvalget_id
);
197 ok(hres
== S_OK
, "GetDispID(defValGet) failed: %08x\n", hres
);
198 ok(defvalget_id
== DISPID_VALUE
, "id = %d\n", defvalget_id
);
200 str
= a2bstr("privateProp");
201 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseInsensitive
, &id
);
203 ok(hres
== DISP_E_UNKNOWNNAME
, "GetDispID(privateProp) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres
);
204 ok(id
== -1, "id = %d\n", id
);
206 str
= a2bstr("class_initialize");
207 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseInsensitive
, &id
);
209 ok(hres
== S_OK
, "GetDispID(publicProp2) failed: %08x\n", hres
);
211 hres
= IDispatchEx_InvokeEx(dispex
, public_prop_id
, 0, DISPATCH_PROPERTYGET
|DISPATCH_METHOD
, &dp
, &v
, &ei
, NULL
);
212 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
213 ok(V_VT(&v
) == VT_EMPTY
, "V_VT(v) = %d\n", V_VT(&v
));
215 V_VT(args
) = VT_BOOL
;
216 V_BOOL(args
) = VARIANT_TRUE
;
217 dp
.cArgs
= dp
.cNamedArgs
= 1;
219 hres
= IDispatchEx_InvokeEx(dispex
, public_prop_id
, 0, DISPATCH_PROPERTYPUT
, &dp
, &v
, &ei
, NULL
);
220 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
221 ok(V_VT(&v
) == VT_EMPTY
, "V_VT(v) = %d\n", V_VT(&v
));
223 dp
.cArgs
= dp
.cNamedArgs
= 0;
224 hres
= IDispatchEx_InvokeEx(dispex
, public_prop_id
, 0, DISPATCH_PROPERTYGET
|DISPATCH_METHOD
, &dp
, &v
, &ei
, NULL
);
225 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
226 ok(V_VT(&v
) == VT_BOOL
, "V_VT(v) = %d\n", V_VT(&v
));
227 ok(V_BOOL(&v
), "V_BOOL(v) = %x\n", V_BOOL(&v
));
230 hres
= IDispatchEx_InvokeEx(dispex
, public_prop_id
, 0, DISPATCH_PROPERTYGET
|DISPATCH_METHOD
, &dp
, &v
, &ei
, NULL
);
231 ok(hres
== DISP_E_MEMBERNOTFOUND
, "InvokeEx failed: %08x, expected DISP_E_MEMBERNOTFOUND\n", hres
);
232 ok(V_VT(&v
) == VT_EMPTY
, "V_VT(v) = %d\n", V_VT(&v
));
234 V_VT(args
) = VT_BOOL
;
235 V_BOOL(args
) = VARIANT_FALSE
;
238 hres
= IDispatchEx_InvokeEx(dispex
, public_prop_id
, 0, DISPATCH_PROPERTYPUT
, &dp
, NULL
, &ei
, NULL
);
239 ok(hres
== DISP_E_PARAMNOTOPTIONAL
, "InvokeEx failed: %08x, expected DISP_E_PARAMNOTOPTIONAL\n", hres
);
241 str
= a2bstr("publicFunction");
242 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseInsensitive
, &public_func_id
);
244 ok(hres
== S_OK
, "GetDispID(publicFunction) failed: %08x\n", hres
);
245 ok(public_func_id
!= -1, "public_func_id = -1\n");
247 str
= a2bstr("publicSub");
248 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseInsensitive
, &public_sub_id
);
250 ok(hres
== S_OK
, "GetDispID(publicSub) failed: %08x\n", hres
);
251 ok(public_sub_id
!= -1, "public_func_id = -1\n");
253 dp
.cArgs
= dp
.cNamedArgs
= 0;
254 hres
= IDispatchEx_InvokeEx(dispex
, public_func_id
, 0, DISPATCH_PROPERTYGET
|DISPATCH_METHOD
, &dp
, &v
, &ei
, NULL
);
255 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
256 ok(V_VT(&v
) == VT_I2
, "V_VT(v) = %d\n", V_VT(&v
));
257 ok(V_I2(&v
) == 4, "V_I2(v) = %d\n", V_I2(&v
));
259 dp
.cArgs
= dp
.cNamedArgs
= 0;
260 hres
= IDispatchEx_InvokeEx(dispex
, public_func_id
, 0, DISPATCH_PROPERTYGET
, &dp
, &v
, &ei
, NULL
);
261 ok(hres
== DISP_E_MEMBERNOTFOUND
, "InvokeEx failed: %08x, expected DISP_E_MEMBERNOTFOUND\n", hres
);
262 ok(V_VT(&v
) == VT_EMPTY
, "V_VT(v) = %d\n", V_VT(&v
));
264 dp
.cArgs
= dp
.cNamedArgs
= 0;
265 hres
= IDispatchEx_InvokeEx(dispex
, public_func_id
, 0, DISPATCH_METHOD
, &dp
, &v
, &ei
, NULL
);
266 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
267 ok(V_VT(&v
) == VT_I2
, "V_VT(v) = %d\n", V_VT(&v
));
268 ok(V_I2(&v
) == 4, "V_I2(v) = %d\n", V_I2(&v
));
270 dp
.cArgs
= dp
.cNamedArgs
= 0;
271 hres
= IDispatchEx_InvokeEx(dispex
, public_sub_id
, 0, DISPATCH_PROPERTYGET
|DISPATCH_METHOD
, &dp
, &v
, &ei
, NULL
);
272 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
273 ok(V_VT(&v
) == VT_EMPTY
, "V_VT(v) = %d\n", V_VT(&v
));
275 dp
.cArgs
= dp
.cNamedArgs
= 0;
276 hres
= IDispatchEx_InvokeEx(dispex
, public_sub_id
, 0, DISPATCH_PROPERTYGET
, &dp
, &v
, &ei
, NULL
);
277 ok(hres
== DISP_E_MEMBERNOTFOUND
, "InvokeEx failed: %08x, expected DISP_E_MEMBERNOTFOUND\n", hres
);
278 ok(V_VT(&v
) == VT_EMPTY
, "V_VT(v) = %d\n", V_VT(&v
));
280 dp
.cArgs
= dp
.cNamedArgs
= 0;
281 hres
= IDispatchEx_InvokeEx(dispex
, public_sub_id
, 0, DISPATCH_METHOD
, &dp
, &v
, &ei
, NULL
);
282 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
283 ok(V_VT(&v
) == VT_EMPTY
, "V_VT(v) = %d\n", V_VT(&v
));
285 V_VT(args
) = VT_BOOL
;
286 V_BOOL(args
) = VARIANT_TRUE
;
287 dp
.cArgs
= dp
.cNamedArgs
= 1;
288 hres
= IDispatchEx_InvokeEx(dispex
, public_sub_id
, 0, DISPATCH_PROPERTYPUT
, &dp
, NULL
, &ei
, NULL
);
289 ok(FAILED(hres
), "InvokeEx succeeded: %08x\n", hres
);
291 dp
.cArgs
= dp
.cNamedArgs
= 0;
292 hres
= IDispatchEx_InvokeEx(dispex
, public_func_id
, 0, DISPATCH_PROPERTYGET
|DISPATCH_METHOD
, &dp
, &v
, &ei
, NULL
);
293 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
294 ok(V_VT(&v
) == VT_I2
, "V_VT(v) = %d\n", V_VT(&v
));
295 ok(V_I2(&v
) == 4, "V_I2(v) = %d\n", V_I2(&v
));
297 dp
.cArgs
= dp
.cNamedArgs
= 0;
298 hres
= IDispatchEx_InvokeEx(dispex
, public_func_id
, 0, DISPATCH_METHOD
, &dp
, &v
, &ei
, NULL
);
299 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
300 ok(V_VT(&v
) == VT_I2
, "V_VT(v) = %d\n", V_VT(&v
));
301 ok(V_I2(&v
) == 4, "V_I2(v) = %d\n", V_I2(&v
));
303 dp
.cArgs
= dp
.cNamedArgs
= 0;
304 hres
= IDispatchEx_InvokeEx(dispex
, public_sub_id
, 0, DISPATCH_PROPERTYGET
|DISPATCH_METHOD
, &dp
, &v
, &ei
, NULL
);
305 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
306 ok(V_VT(&v
) == VT_EMPTY
, "V_VT(v) = %d\n", V_VT(&v
));
308 dp
.cArgs
= dp
.cNamedArgs
= 0;
309 hres
= IDispatchEx_InvokeEx(dispex
, public_sub_id
, 0, DISPATCH_METHOD
, &dp
, &v
, &ei
, NULL
);
310 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
311 ok(V_VT(&v
) == VT_EMPTY
, "V_VT(v) = %d\n", V_VT(&v
));
313 str
= a2bstr("privateSub");
314 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseInsensitive
, &id
);
316 ok(hres
== DISP_E_UNKNOWNNAME
, "GetDispID(privateSub) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres
);
317 ok(id
== -1, "id = %d\n", id
);
319 str
= a2bstr("dynprop");
320 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameCaseInsensitive
|fdexNameEnsure
, &id
);
321 ok(hres
== DISP_E_UNKNOWNNAME
, "GetDispID(privateProp) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres
);
322 ok(id
== -1, "id = %d\n", id
);
323 hres
= IDispatchEx_GetDispID(dispex
, str
, fdexNameEnsure
, &id
);
324 ok(hres
== DISP_E_UNKNOWNNAME
, "GetDispID(privateProp) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres
);
325 ok(id
== -1, "id = %d\n", id
);
328 IDispatchEx_Release(dispex
);
331 #define test_grfdex(a,b) _test_grfdex(__LINE__,a,b)
332 static void _test_grfdex(unsigned line
, DWORD grfdex
, DWORD expect
)
334 ok_(__FILE__
,line
)(grfdex
== expect
, "grfdex = %x, expected %x\n", grfdex
, expect
);
337 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
341 if(IsEqualGUID(riid
, &IID_IUnknown
)
342 || IsEqualGUID(riid
, &IID_IDispatch
)
343 || IsEqualGUID(riid
, &IID_IDispatchEx
))
346 return E_NOINTERFACE
;
348 IUnknown_AddRef((IUnknown
*)*ppv
);
352 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
357 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
362 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
364 ok(0, "unexpected call\n");
368 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
369 LCID lcid
, ITypeInfo
**ppTInfo
)
371 ok(0, "unexpected call\n");
375 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
376 LPOLESTR
*rgszNames
, UINT cNames
,
377 LCID lcid
, DISPID
*rgDispId
)
379 ok(0, "unexpected call\n");
383 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
384 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
385 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
387 ok(0, "unexpected call\n");
391 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
393 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName
), grfdex
);
397 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
399 ok(0, "unexpected call\n");
403 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
405 ok(0, "unexpected call\n");
409 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
411 ok(0, "unexpected call\n");
415 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
417 ok(0, "unexpected call\n");
421 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
423 ok(0, "unexpected call\n");
427 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
429 ok(0, "unexpected call\n");
433 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
434 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
436 ok(0, "unexpected call\n");
440 static HRESULT WINAPI
testObj_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
442 if(!strcmp_wa(bstrName
, "propget")) {
443 CHECK_EXPECT(testobj_propget_d
);
444 test_grfdex(grfdex
, fdexNameCaseInsensitive
);
445 *pid
= DISPID_TESTOBJ_PROPGET
;
448 if(!strcmp_wa(bstrName
, "propput")) {
449 CHECK_EXPECT(testobj_propput_d
);
450 test_grfdex(grfdex
, fdexNameCaseInsensitive
);
451 *pid
= DISPID_TESTOBJ_PROPPUT
;
455 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName
));
456 return DISP_E_UNKNOWNNAME
;
459 static HRESULT WINAPI
testObj_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
460 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
463 case DISPID_TESTOBJ_PROPGET
:
464 CHECK_EXPECT(testobj_propget_i
);
466 ok(wFlags
== (DISPATCH_PROPERTYGET
|DISPATCH_METHOD
), "wFlags = %x\n", wFlags
);
467 ok(pdp
!= NULL
, "pdp == NULL\n");
468 ok(!pdp
->rgvarg
, "rgvarg == NULL\n");
469 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
470 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
471 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
472 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
473 ok(pei
!= NULL
, "pei == NULL\n");
475 V_VT(pvarRes
) = VT_I2
;
478 case DISPID_TESTOBJ_PROPPUT
:
479 CHECK_EXPECT(testobj_propput_i
);
481 ok(wFlags
== DISPATCH_PROPERTYPUT
, "wFlags = %x\n", wFlags
);
482 ok(pdp
!= NULL
, "pdp == NULL\n");
483 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
484 ok(pdp
->rgdispidNamedArgs
!= NULL
, "rgdispidNamedArgs == NULL\n");
485 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
486 ok(pdp
->cNamedArgs
== 1, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
487 ok(pdp
->rgdispidNamedArgs
[0] == DISPID_PROPERTYPUT
, "pdp->rgdispidNamedArgs[0] = %d\n", pdp
->rgdispidNamedArgs
[0]);
488 ok(!pvarRes
, "pvarRes != NULL\n");
489 ok(pei
!= NULL
, "pei == NULL\n");
491 ok(V_VT(pdp
->rgvarg
) == VT_I2
, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp
->rgvarg
));
492 ok(V_I2(pdp
->rgvarg
) == 1, "V_I2(psp->rgvargs) = %d\n", V_I2(pdp
->rgvarg
));
496 ok(0, "unexpected call %d\n", id
);
500 static IDispatchExVtbl testObjVtbl
= {
501 DispatchEx_QueryInterface
,
504 DispatchEx_GetTypeInfoCount
,
505 DispatchEx_GetTypeInfo
,
506 DispatchEx_GetIDsOfNames
,
510 DispatchEx_DeleteMemberByName
,
511 DispatchEx_DeleteMemberByDispID
,
512 DispatchEx_GetMemberProperties
,
513 DispatchEx_GetMemberName
,
514 DispatchEx_GetNextDispID
,
515 DispatchEx_GetNameSpaceParent
518 static IDispatchEx testObj
= { &testObjVtbl
};
520 static ULONG refobj_ref
;
522 static ULONG WINAPI
RefObj_AddRef(IDispatchEx
*iface
)
527 static ULONG WINAPI
RefObj_Release(IDispatchEx
*iface
)
532 static IDispatchExVtbl RefObjVtbl
= {
533 DispatchEx_QueryInterface
,
536 DispatchEx_GetTypeInfoCount
,
537 DispatchEx_GetTypeInfo
,
538 DispatchEx_GetIDsOfNames
,
540 DispatchEx_GetDispID
,
542 DispatchEx_DeleteMemberByName
,
543 DispatchEx_DeleteMemberByDispID
,
544 DispatchEx_GetMemberProperties
,
545 DispatchEx_GetMemberName
,
546 DispatchEx_GetNextDispID
,
547 DispatchEx_GetNameSpaceParent
550 static IDispatchEx RefObj
= { &RefObjVtbl
};
552 static HRESULT WINAPI
Global_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
554 if(!strcmp_wa(bstrName
, "ok")) {
555 test_grfdex(grfdex
, fdexNameCaseInsensitive
);
556 *pid
= DISPID_GLOBAL_OK
;
559 if(!strcmp_wa(bstrName
, "trace")) {
560 test_grfdex(grfdex
, fdexNameCaseInsensitive
);
561 *pid
= DISPID_GLOBAL_TRACE
;
564 if(!strcmp_wa(bstrName
, "reportSuccess")) {
565 CHECK_EXPECT(global_success_d
);
566 test_grfdex(grfdex
, fdexNameCaseInsensitive
);
567 *pid
= DISPID_GLOBAL_REPORTSUCCESS
;
570 if(!strcmp_wa(bstrName
, "getVT")) {
571 test_grfdex(grfdex
, fdexNameCaseInsensitive
);
572 *pid
= DISPID_GLOBAL_GETVT
;
575 if(!strcmp_wa(bstrName
, "isEnglishLang")) {
576 test_grfdex(grfdex
, fdexNameCaseInsensitive
);
577 *pid
= DISPID_GLOBAL_ISENGLANG
;
580 if(!strcmp_wa(bstrName
, "testObj")) {
581 test_grfdex(grfdex
, fdexNameCaseInsensitive
);
582 *pid
= DISPID_GLOBAL_TESTOBJ
;
585 if(!strcmp_wa(bstrName
, "vbvar")) {
586 CHECK_EXPECT(global_vbvar_d
);
587 test_grfdex(grfdex
, fdexNameCaseInsensitive
);
588 *pid
= DISPID_GLOBAL_VBVAR
;
591 if(!strcmp_wa(bstrName
, "isNullDisp")) {
592 test_grfdex(grfdex
, fdexNameCaseInsensitive
);
593 *pid
= DISPID_GLOBAL_ISNULLDISP
;
596 if(!strcmp_wa(bstrName
, "testDisp")) {
597 test_grfdex(grfdex
, fdexNameCaseInsensitive
);
598 *pid
= DISPID_GLOBAL_TESTDISP
;
601 if(!strcmp_wa(bstrName
, "RefObj")) {
602 test_grfdex(grfdex
, fdexNameCaseInsensitive
);
603 *pid
= DISPID_GLOBAL_REFOBJ
;
606 if(!strcmp_wa(bstrName
, "propargput")) {
607 CHECK_EXPECT(global_propargput_d
);
608 test_grfdex(grfdex
, fdexNameCaseInsensitive
);
609 *pid
= DISPID_GLOBAL_PROPARGPUT
;
612 if(!strcmp_wa(bstrName
, "counter")) {
613 test_grfdex(grfdex
, fdexNameCaseInsensitive
);
614 *pid
= DISPID_GLOBAL_COUNTER
;
618 if(strict_dispid_check
&& strcmp_wa(bstrName
, "x"))
619 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName
), grfdex
);
620 return DISP_E_UNKNOWNNAME
;
623 static HRESULT WINAPI
Global_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
624 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
627 case DISPID_GLOBAL_OK
: {
630 ok(wFlags
== INVOKE_FUNC
|| wFlags
== (INVOKE_FUNC
|INVOKE_PROPERTYGET
), "wFlags = %x\n", wFlags
);
631 ok(pdp
!= NULL
, "pdp == NULL\n");
632 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
633 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
634 ok(pdp
->cArgs
== 2, "cArgs = %d\n", pdp
->cArgs
);
635 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
636 if(wFlags
& INVOKE_PROPERTYGET
)
637 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
639 ok(!pvarRes
, "pvarRes != NULL\n");
640 ok(pei
!= NULL
, "pei == NULL\n");
642 ok(V_VT(pdp
->rgvarg
) == VT_BSTR
, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp
->rgvarg
));
645 if(V_VT(b
) == (VT_BYREF
|VT_VARIANT
))
648 ok(V_VT(b
) == VT_BOOL
, "V_VT(b) = %d\n", V_VT(b
));
650 ok(V_BOOL(b
), "%s: %s\n", test_name
, wine_dbgstr_w(V_BSTR(pdp
->rgvarg
)));
654 case DISPID_GLOBAL_TRACE
:
655 ok(wFlags
== INVOKE_FUNC
, "wFlags = %x\n", wFlags
);
656 ok(pdp
!= NULL
, "pdp == NULL\n");
657 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
658 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
659 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
660 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
661 ok(!pvarRes
, "pvarRes != NULL\n");
662 ok(pei
!= NULL
, "pei == NULL\n");
664 ok(V_VT(pdp
->rgvarg
) == VT_BSTR
, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp
->rgvarg
));
665 if(V_VT(pdp
->rgvarg
) == VT_BSTR
)
666 trace("%s: %s\n", test_name
, wine_dbgstr_w(V_BSTR(pdp
->rgvarg
)));
670 case DISPID_GLOBAL_REPORTSUCCESS
:
671 CHECK_EXPECT(global_success_i
);
673 ok(wFlags
== INVOKE_FUNC
, "wFlags = %x\n", wFlags
);
674 ok(pdp
!= NULL
, "pdp == NULL\n");
675 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
676 ok(pdp
->cArgs
== 0, "cArgs = %d\n", pdp
->cArgs
);
677 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
678 ok(!pvarRes
, "pvarRes != NULL\n");
679 ok(pei
!= NULL
, "pei == NULL\n");
683 case DISPID_GLOBAL_GETVT
:
684 ok(pdp
!= NULL
, "pdp == NULL\n");
685 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
686 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
687 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
688 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
689 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
690 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
691 ok(pei
!= NULL
, "pei == NULL\n");
693 V_VT(pvarRes
) = VT_BSTR
;
694 V_BSTR(pvarRes
) = a2bstr(vt2a(pdp
->rgvarg
));
697 case DISPID_GLOBAL_ISENGLANG
:
698 ok(wFlags
== (INVOKE_FUNC
|INVOKE_PROPERTYGET
), "wFlags = %x\n", wFlags
);
699 ok(pdp
!= NULL
, "pdp == NULL\n");
700 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
701 ok(pdp
->cArgs
== 0, "cArgs = %d\n", pdp
->cArgs
);
702 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
703 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
704 ok(pei
!= NULL
, "pei == NULL\n");
706 V_VT(pvarRes
) = VT_BOOL
;
707 if(is_lang_english()) {
708 V_BOOL(pvarRes
) = VARIANT_TRUE
;
710 skip("Skipping some tests in non-English UIs\n");
711 V_BOOL(pvarRes
) = VARIANT_FALSE
;
715 case DISPID_GLOBAL_VBVAR
:
716 CHECK_EXPECT(global_vbvar_i
);
718 ok(wFlags
== DISPATCH_PROPERTYPUT
, "wFlags = %x\n", wFlags
);
719 ok(pdp
!= NULL
, "pdp == NULL\n");
720 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
721 ok(pdp
->rgdispidNamedArgs
!= NULL
, "rgdispidNamedArgs == NULL\n");
722 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
723 ok(pdp
->cNamedArgs
== 1, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
724 ok(pdp
->rgdispidNamedArgs
[0] == DISPID_PROPERTYPUT
, "pdp->rgdispidNamedArgs[0] = %d\n", pdp
->rgdispidNamedArgs
[0]);
725 ok(!pvarRes
, "pvarRes != NULL\n");
726 ok(pei
!= NULL
, "pei == NULL\n");
728 ok(V_VT(pdp
->rgvarg
) == VT_I2
, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp
->rgvarg
));
729 ok(V_I2(pdp
->rgvarg
) == 3, "V_I2(psp->rgvargs) = %d\n", V_I2(pdp
->rgvarg
));
732 case DISPID_GLOBAL_TESTOBJ
:
733 ok(wFlags
== (DISPATCH_PROPERTYGET
|DISPATCH_METHOD
), "wFlags = %x\n", wFlags
);
735 ok(pdp
!= NULL
, "pdp == NULL\n");
736 ok(!pdp
->rgvarg
, "rgvarg != NULL\n");
737 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
738 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
739 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
740 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
741 ok(pei
!= NULL
, "pei == NULL\n");
743 V_VT(pvarRes
) = VT_DISPATCH
;
744 V_DISPATCH(pvarRes
) = (IDispatch
*)&testObj
;
747 case DISPID_GLOBAL_REFOBJ
:
748 ok(wFlags
== (DISPATCH_PROPERTYGET
|DISPATCH_METHOD
), "wFlags = %x\n", wFlags
);
750 ok(pdp
!= NULL
, "pdp == NULL\n");
751 ok(!pdp
->rgvarg
, "rgvarg == NULL\n");
752 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
753 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
754 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
755 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
756 ok(pei
!= NULL
, "pei == NULL\n");
758 IDispatchEx_AddRef(&RefObj
);
759 V_VT(pvarRes
) = VT_DISPATCH
;
760 V_DISPATCH(pvarRes
) = (IDispatch
*)&RefObj
;
763 case DISPID_GLOBAL_ISNULLDISP
: {
766 ok(wFlags
== (INVOKE_FUNC
|INVOKE_PROPERTYGET
), "wFlags = %x\n", wFlags
);
767 ok(pdp
!= NULL
, "pdp == NULL\n");
768 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
769 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
770 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
771 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
772 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
773 ok(pei
!= NULL
, "pei == NULL\n");
776 if(V_VT(v
) == (VT_VARIANT
|VT_BYREF
))
779 ok(V_VT(v
) == VT_DISPATCH
, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp
->rgvarg
));
780 V_VT(pvarRes
) = VT_BOOL
;
781 V_BOOL(pvarRes
) = V_DISPATCH(v
) ? VARIANT_FALSE
: VARIANT_TRUE
;
785 case DISPID_GLOBAL_TESTDISP
:
786 ok(wFlags
== INVOKE_FUNC
, "wFlags = %x\n", wFlags
);
787 ok(pdp
!= NULL
, "pdp == NULL\n");
788 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
789 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
790 ok(pdp
->cArgs
== 1, "cArgs = %d\n", pdp
->cArgs
);
791 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
792 ok(!pvarRes
, "pvarRes != NULL\n");
793 ok(pei
!= NULL
, "pei == NULL\n");
795 ok(V_VT(pdp
->rgvarg
) == VT_DISPATCH
, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp
->rgvarg
));
796 test_disp(V_DISPATCH(pdp
->rgvarg
));
799 case DISPID_GLOBAL_PROPARGPUT
:
800 CHECK_EXPECT(global_propargput_i
);
802 ok(wFlags
== DISPATCH_PROPERTYPUT
, "wFlags = %x\n", wFlags
);
803 ok(pdp
!= NULL
, "pdp == NULL\n");
804 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
805 ok(pdp
->rgdispidNamedArgs
!= NULL
, "rgdispidNamedArgs == NULL\n");
806 ok(pdp
->cArgs
== 3, "cArgs = %d\n", pdp
->cArgs
);
807 ok(pdp
->cNamedArgs
== 1, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
808 ok(pdp
->rgdispidNamedArgs
[0] == DISPID_PROPERTYPUT
, "pdp->rgdispidNamedArgs[0] = %d\n", pdp
->rgdispidNamedArgs
[0]);
809 ok(!pvarRes
, "pvarRes != NULL\n");
810 ok(pei
!= NULL
, "pei == NULL\n");
812 ok(V_VT(pdp
->rgvarg
) == VT_I2
, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp
->rgvarg
));
813 ok(V_I2(pdp
->rgvarg
) == 0, "V_I2(psp->rgvargs) = %d\n", V_I2(pdp
->rgvarg
));
815 ok(V_VT(pdp
->rgvarg
+1) == VT_I2
, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp
->rgvarg
+1));
816 ok(V_I2(pdp
->rgvarg
+1) == 2, "V_I2(psp->rgvargs+1) = %d\n", V_I2(pdp
->rgvarg
+1));
818 ok(V_VT(pdp
->rgvarg
+2) == VT_I2
, "V_VT(psp->rgvargs+2) = %d\n", V_VT(pdp
->rgvarg
+2));
819 ok(V_I2(pdp
->rgvarg
+2) == 1, "V_I2(psp->rgvargs+2) = %d\n", V_I2(pdp
->rgvarg
+2));
822 case DISPID_GLOBAL_COUNTER
:
823 ok(pdp
!= NULL
, "pdp == NULL\n");
824 todo_wine
ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
825 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
826 ok(!pdp
->cArgs
, "cArgs = %d\n", pdp
->cArgs
);
827 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
828 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
829 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pvarRes) = %d\n", V_VT(pvarRes
));
830 ok(pei
!= NULL
, "pei == NULL\n");
832 V_VT(pvarRes
) = VT_I2
;
833 V_I2(pvarRes
) = test_counter
++;
837 ok(0, "unexpected call %d\n", id
);
838 return DISP_E_MEMBERNOTFOUND
;
841 static IDispatchExVtbl GlobalVtbl
= {
842 DispatchEx_QueryInterface
,
845 DispatchEx_GetTypeInfoCount
,
846 DispatchEx_GetTypeInfo
,
847 DispatchEx_GetIDsOfNames
,
851 DispatchEx_DeleteMemberByName
,
852 DispatchEx_DeleteMemberByDispID
,
853 DispatchEx_GetMemberProperties
,
854 DispatchEx_GetMemberName
,
855 DispatchEx_GetNextDispID
,
856 DispatchEx_GetNameSpaceParent
859 static IDispatchEx Global
= { &GlobalVtbl
};
861 static HRESULT WINAPI
ActiveScriptSite_QueryInterface(IActiveScriptSite
*iface
, REFIID riid
, void **ppv
)
865 if(IsEqualGUID(&IID_IUnknown
, riid
))
867 else if(IsEqualGUID(&IID_IActiveScriptSite
, riid
))
870 return E_NOINTERFACE
;
872 IUnknown_AddRef((IUnknown
*)*ppv
);
876 static ULONG WINAPI
ActiveScriptSite_AddRef(IActiveScriptSite
*iface
)
881 static ULONG WINAPI
ActiveScriptSite_Release(IActiveScriptSite
*iface
)
886 static HRESULT WINAPI
ActiveScriptSite_GetLCID(IActiveScriptSite
*iface
, LCID
*plcid
)
888 *plcid
= GetUserDefaultLCID();
892 static HRESULT WINAPI
ActiveScriptSite_GetItemInfo(IActiveScriptSite
*iface
, LPCOLESTR pstrName
,
893 DWORD dwReturnMask
, IUnknown
**ppiunkItem
, ITypeInfo
**ppti
)
895 ok(dwReturnMask
== SCRIPTINFO_IUNKNOWN
, "unexpected dwReturnMask %x\n", dwReturnMask
);
896 ok(!ppti
, "ppti != NULL\n");
898 if(strcmp_wa(pstrName
, "test"))
899 ok(0, "unexpected pstrName %s\n", wine_dbgstr_w(pstrName
));
901 *ppiunkItem
= (IUnknown
*)&Global
;
905 static HRESULT WINAPI
ActiveScriptSite_GetDocVersionString(IActiveScriptSite
*iface
, BSTR
*pbstrVersion
)
910 static HRESULT WINAPI
ActiveScriptSite_OnScriptTerminate(IActiveScriptSite
*iface
,
911 const VARIANT
*pvarResult
, const EXCEPINFO
*pexcepinfo
)
916 static HRESULT WINAPI
ActiveScriptSite_OnStateChange(IActiveScriptSite
*iface
, SCRIPTSTATE ssScriptState
)
921 static HRESULT WINAPI
ActiveScriptSite_OnScriptError(IActiveScriptSite
*iface
, IActiveScriptError
*pscripterror
)
926 static HRESULT WINAPI
ActiveScriptSite_OnEnterScript(IActiveScriptSite
*iface
)
931 static HRESULT WINAPI
ActiveScriptSite_OnLeaveScript(IActiveScriptSite
*iface
)
936 #undef ACTSCPSITE_THIS
938 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl
= {
939 ActiveScriptSite_QueryInterface
,
940 ActiveScriptSite_AddRef
,
941 ActiveScriptSite_Release
,
942 ActiveScriptSite_GetLCID
,
943 ActiveScriptSite_GetItemInfo
,
944 ActiveScriptSite_GetDocVersionString
,
945 ActiveScriptSite_OnScriptTerminate
,
946 ActiveScriptSite_OnStateChange
,
947 ActiveScriptSite_OnScriptError
,
948 ActiveScriptSite_OnEnterScript
,
949 ActiveScriptSite_OnLeaveScript
952 static IActiveScriptSite ActiveScriptSite
= { &ActiveScriptSiteVtbl
};
954 static IActiveScript
*create_script(void)
956 IActiveScript
*script
;
959 hres
= CoCreateInstance(&CLSID_VBScript
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
960 &IID_IActiveScript
, (void**)&script
);
961 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
966 static HRESULT
parse_script(DWORD flags
, BSTR script_str
)
968 IActiveScriptParse
*parser
;
969 IActiveScript
*engine
;
970 IDispatch
*script_disp
;
974 engine
= create_script();
978 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptParse
, (void**)&parser
);
979 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
982 IActiveScript_Release(engine
);
986 hres
= IActiveScriptParse64_InitNew(parser
);
987 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
989 hres
= IActiveScript_SetScriptSite(engine
, &ActiveScriptSite
);
990 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
992 hres
= IActiveScript_AddNamedItem(engine
, testW
,
993 SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|flags
);
994 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
996 hres
= IActiveScript_SetScriptState(engine
, SCRIPTSTATE_STARTED
);
997 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
999 hres
= IActiveScript_GetScriptDispatch(engine
, NULL
, &script_disp
);
1000 ok(hres
== S_OK
, "GetScriptDispatch failed: %08x\n", hres
);
1001 ok(script_disp
!= NULL
, "script_disp == NULL\n");
1002 ok(script_disp
!= (IDispatch
*)&Global
, "script_disp == Global\n");
1006 hres
= IActiveScriptParse64_ParseScriptText(parser
, script_str
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
1008 IActiveScript_Close(engine
);
1010 IDispatch_Release(script_disp
);
1011 IActiveScript_Release(engine
);
1013 ref
= IUnknown_Release(parser
);
1014 ok(!ref
, "ref=%d\n", ref
);
1018 static void parse_script_af(DWORD flags
, const char *src
)
1024 hres
= parse_script(flags
, tmp
);
1026 ok(hres
== S_OK
, "parse_script failed: %08x\n", hres
);
1029 static void parse_script_a(const char *src
)
1031 parse_script_af(SCRIPTITEM_GLOBALMEMBERS
, src
);
1034 static void test_gc(void)
1036 IActiveScriptParse
*parser
;
1037 IActiveScript
*engine
;
1041 strict_dispid_check
= FALSE
;
1043 engine
= create_script();
1047 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptParse
, (void**)&parser
);
1048 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
1050 hres
= IActiveScriptParse64_InitNew(parser
);
1051 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
1053 hres
= IActiveScript_SetScriptSite(engine
, &ActiveScriptSite
);
1054 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1056 hres
= IActiveScript_AddNamedItem(engine
, testW
,
1057 SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|SCRIPTITEM_GLOBALMEMBERS
);
1058 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
1060 hres
= IActiveScript_SetScriptState(engine
, SCRIPTSTATE_STARTED
);
1061 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
1066 " Public Sub Class_Terminate\n"
1067 " Call reportSuccess()\n"
1073 "set x = nothing\n");
1075 hres
= IActiveScriptParse64_ParseScriptText(parser
, src
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
1076 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1079 SET_EXPECT(global_success_d
);
1080 SET_EXPECT(global_success_i
);
1081 IActiveScript_Close(engine
);
1082 CHECK_CALLED(global_success_d
);
1083 CHECK_CALLED(global_success_i
);
1085 IActiveScript_Release(engine
);
1086 IUnknown_Release(parser
);
1089 static HRESULT
test_global_vars_ref(BOOL use_close
)
1091 IActiveScriptParse
*parser
;
1092 IActiveScript
*engine
;
1097 engine
= create_script();
1101 hres
= IActiveScript_QueryInterface(engine
, &IID_IActiveScriptParse
, (void**)&parser
);
1102 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
1105 IActiveScript_Release(engine
);
1109 hres
= IActiveScriptParse64_InitNew(parser
);
1110 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
1112 hres
= IActiveScript_SetScriptSite(engine
, &ActiveScriptSite
);
1113 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1115 hres
= IActiveScript_AddNamedItem(engine
, testW
, SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|SCRIPTITEM_GLOBALMEMBERS
);
1116 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
1118 hres
= IActiveScript_SetScriptState(engine
, SCRIPTSTATE_STARTED
);
1119 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
1123 script_str
= a2bstr("Dim x\nset x = RefObj\n");
1124 hres
= IActiveScriptParse64_ParseScriptText(parser
, script_str
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
1125 SysFreeString(script_str
);
1127 ok(refobj_ref
, "refobj_ref = 0\n");
1130 hres
= IActiveScript_Close(engine
);
1131 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
1133 hres
= IActiveScript_SetScriptState(engine
, SCRIPTSTATE_UNINITIALIZED
);
1134 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
1137 ok(!refobj_ref
, "refobj_ref = %d\n", refobj_ref
);
1139 IActiveScript_Release(engine
);
1141 ref
= IUnknown_Release(parser
);
1142 ok(!ref
, "ref=%d\n", ref
);
1146 static BSTR
get_script_from_file(const char *filename
)
1150 const char *file_map
;
1153 file
= CreateFileA(filename
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_READONLY
, NULL
);
1154 if(file
== INVALID_HANDLE_VALUE
) {
1155 trace("Could not open file: %u\n", GetLastError());
1159 size
= GetFileSize(file
, NULL
);
1161 map
= CreateFileMapping(file
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
1163 if(map
== INVALID_HANDLE_VALUE
) {
1164 trace("Could not create file mapping: %u\n", GetLastError());
1168 file_map
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
1171 trace("MapViewOfFile failed: %u\n", GetLastError());
1175 len
= MultiByteToWideChar(CP_ACP
, 0, file_map
, size
, NULL
, 0);
1176 ret
= SysAllocStringLen(NULL
, len
);
1177 MultiByteToWideChar(CP_ACP
, 0, file_map
, size
, ret
, len
);
1179 UnmapViewOfFile(file_map
);
1184 static void run_from_file(const char *filename
)
1189 script_str
= get_script_from_file(filename
);
1193 strict_dispid_check
= FALSE
;
1194 hres
= parse_script(SCRIPTITEM_GLOBALMEMBERS
, script_str
);
1195 SysFreeString(script_str
);
1196 ok(hres
== S_OK
, "parse_script failed: %08x\n", hres
);
1199 static void run_from_res(const char *name
)
1207 strict_dispid_check
= FALSE
;
1210 src
= FindResourceA(NULL
, name
, (LPCSTR
)40);
1211 ok(src
!= NULL
, "Could not find resource %s\n", name
);
1213 size
= SizeofResource(NULL
, src
);
1214 data
= LoadResource(NULL
, src
);
1216 len
= MultiByteToWideChar(CP_ACP
, 0, data
, size
, NULL
, 0);
1217 str
= SysAllocStringLen(NULL
, len
);
1218 MultiByteToWideChar(CP_ACP
, 0, data
, size
, str
, len
);
1220 SET_EXPECT(global_success_d
);
1221 SET_EXPECT(global_success_i
);
1222 hres
= parse_script(SCRIPTITEM_GLOBALMEMBERS
, str
);
1223 CHECK_CALLED(global_success_d
);
1224 CHECK_CALLED(global_success_i
);
1226 ok(hres
== S_OK
, "parse_script failed: %08x\n", hres
);
1230 static void run_tests(void)
1232 strict_dispid_check
= TRUE
;
1235 parse_script_a("' empty ;");
1237 SET_EXPECT(global_success_d
);
1238 SET_EXPECT(global_success_i
);
1239 parse_script_a("reportSuccess");
1240 CHECK_CALLED(global_success_d
);
1241 CHECK_CALLED(global_success_i
);
1243 SET_EXPECT(global_success_d
);
1244 SET_EXPECT(global_success_i
);
1245 parse_script_a("reportSuccess()");
1246 CHECK_CALLED(global_success_d
);
1247 CHECK_CALLED(global_success_i
);
1249 SET_EXPECT(global_success_d
);
1250 SET_EXPECT(global_success_i
);
1251 parse_script_a("Call reportSuccess");
1252 CHECK_CALLED(global_success_d
);
1253 CHECK_CALLED(global_success_i
);
1255 SET_EXPECT(global_success_d
);
1256 SET_EXPECT(global_success_i
);
1257 parse_script_a("test.reportSuccess()");
1258 CHECK_CALLED(global_success_d
);
1259 CHECK_CALLED(global_success_i
);
1261 SET_EXPECT(global_vbvar_d
);
1262 SET_EXPECT(global_vbvar_i
);
1263 parse_script_a("Option Explicit\nvbvar = 3");
1264 CHECK_CALLED(global_vbvar_d
);
1265 CHECK_CALLED(global_vbvar_i
);
1267 SET_EXPECT(global_vbvar_d
);
1268 SET_EXPECT(global_vbvar_i
);
1269 parse_script_a("Option Explicit\nvbvar() = 3");
1270 CHECK_CALLED(global_vbvar_d
);
1271 CHECK_CALLED(global_vbvar_i
);
1273 SET_EXPECT(testobj_propget_d
);
1274 SET_EXPECT(testobj_propget_i
);
1275 parse_script_a("dim x\nx = testObj.propget");
1276 CHECK_CALLED(testobj_propget_d
);
1277 CHECK_CALLED(testobj_propget_i
);
1279 SET_EXPECT(testobj_propput_d
);
1280 SET_EXPECT(testobj_propput_i
);
1281 parse_script_a("testObj.propput = 1");
1282 CHECK_CALLED(testobj_propput_d
);
1283 CHECK_CALLED(testobj_propput_i
);
1285 SET_EXPECT(global_propargput_d
);
1286 SET_EXPECT(global_propargput_i
);
1287 parse_script_a("propargput(counter(), counter()) = counter()");
1288 CHECK_CALLED(global_propargput_d
);
1289 CHECK_CALLED(global_propargput_i
);
1291 SET_EXPECT(global_propargput_d
);
1292 SET_EXPECT(global_propargput_i
);
1293 parse_script_a("test.propargput(counter(), counter()) = counter()");
1294 CHECK_CALLED(global_propargput_d
);
1295 CHECK_CALLED(global_propargput_i
);
1297 parse_script_a("x = 1\n Call ok(x = 1, \"x = \" & x)");
1299 parse_script_a("x = _ \n3");
1301 test_global_vars_ref(TRUE
);
1302 test_global_vars_ref(FALSE
);
1304 strict_dispid_check
= FALSE
;
1306 parse_script_a("Sub testsub\n"
1308 "Call ok(x = 1, \"x = \" & x)\n"
1312 run_from_res("lang.vbs");
1313 run_from_res("api.vbs");
1318 static BOOL
check_vbscript(void)
1320 IActiveScript
*vbscript
;
1323 hres
= CoCreateInstance(&CLSID_VBScript
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1324 &IID_IActiveScript
, (void**)&vbscript
);
1326 IActiveScript_Release(vbscript
);
1328 return hres
== S_OK
;
1336 argc
= winetest_get_mainargs(&argv
);
1340 if(!check_vbscript()) {
1341 win_skip("Broken engine, probably too old\n");
1342 }else if(argc
> 2) {
1343 run_from_file(argv
[2]);