2 * Copyright 2011 Jacek Caban for CodeWeavers
3 * Copyright 2019 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "vbsregexp55.h"
31 #include "wine/test.h"
35 #define IActiveScriptParse_QueryInterface IActiveScriptParse64_QueryInterface
36 #define IActiveScriptParse_Release IActiveScriptParse64_Release
37 #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
38 #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
39 #define IActiveScriptParseProcedure2_Release \
40 IActiveScriptParseProcedure2_64_Release
44 #define IActiveScriptParse_QueryInterface IActiveScriptParse32_QueryInterface
45 #define IActiveScriptParse_Release IActiveScriptParse32_Release
46 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
47 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
48 #define IActiveScriptParseProcedure2_Release \
49 IActiveScriptParseProcedure2_32_Release
53 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
54 DEFINE_GUID(IID_IScriptTypeInfo
, 0xc59c6b12, 0xf6c1, 0x11cf, 0x88,0x35, 0x00,0xa0,0xc9,0x11,0xe8,0xb2);
56 #define DEFINE_EXPECT(func) \
57 static int expect_ ## func = 0, called_ ## func = 0
59 #define SET_EXPECT(func) \
62 #define SET_EXPECT_MULTI(func, num) \
65 #define CHECK_EXPECT2(func) \
67 ok(expect_ ##func, "unexpected call " #func "\n"); \
71 #define CHECK_EXPECT(func) \
73 CHECK_EXPECT2(func); \
77 #define CHECK_CALLED(func) \
79 ok(called_ ## func, "expected " #func "\n"); \
80 expect_ ## func = called_ ## func = 0; \
83 #define CHECK_CALLED_MULTI(func, num) \
85 ok(called_ ## func == num, "expected " #func " %d times (got %d)\n", num, called_ ## func); \
86 expect_ ## func = called_ ## func = 0; \
89 DEFINE_EXPECT(GetLCID
);
90 DEFINE_EXPECT(OnStateChange_UNINITIALIZED
);
91 DEFINE_EXPECT(OnStateChange_STARTED
);
92 DEFINE_EXPECT(OnStateChange_CONNECTED
);
93 DEFINE_EXPECT(OnStateChange_DISCONNECTED
);
94 DEFINE_EXPECT(OnStateChange_CLOSED
);
95 DEFINE_EXPECT(OnStateChange_INITIALIZED
);
96 DEFINE_EXPECT(OnEnterScript
);
97 DEFINE_EXPECT(OnLeaveScript
);
98 DEFINE_EXPECT(OnScriptError
);
99 DEFINE_EXPECT(GetIDsOfNames
);
100 DEFINE_EXPECT(GetIDsOfNames_visible
);
101 DEFINE_EXPECT(GetIDsOfNames_persistent
);
102 DEFINE_EXPECT(GetItemInfo_global
);
103 DEFINE_EXPECT(GetItemInfo_global_code
);
104 DEFINE_EXPECT(GetItemInfo_visible
);
105 DEFINE_EXPECT(GetItemInfo_visible_code
);
106 DEFINE_EXPECT(GetItemInfo_persistent
);
107 DEFINE_EXPECT(testCall
);
109 DEFINE_GUID(CLSID_VBScript
, 0xb54f3741, 0x5b07, 0x11cf, 0xa4,0xb0, 0x00,0xaa,0x00,0x4a,0x55,0xe8);
110 DEFINE_GUID(CLSID_VBScriptRegExp
, 0x3f4daca4, 0x160d, 0x11d2, 0xa8,0xe9, 0x00,0x10,0x4b,0x36,0x5c,0x9f);
112 static BSTR
a2bstr(const char *str
)
117 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
118 ret
= SysAllocStringLen(NULL
, len
-1);
119 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
124 #define test_state(s,ss) _test_state(__LINE__,s,ss)
125 static void _test_state(unsigned line
, IActiveScript
*script
, SCRIPTSTATE exstate
)
127 SCRIPTSTATE state
= -1;
130 hres
= IActiveScript_GetScriptState(script
, &state
);
131 ok_(__FILE__
,line
) (hres
== S_OK
, "GetScriptState failed: %08x\n", hres
);
132 ok_(__FILE__
,line
) (state
== exstate
, "state=%d, expected %d\n", state
, exstate
);
135 static HRESULT WINAPI
Dispatch_QueryInterface(IDispatch
*iface
, REFIID riid
, void **ppv
)
137 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IDispatch
, riid
)) {
139 IDispatch_AddRef(iface
);
144 return E_NOINTERFACE
;
147 static ULONG WINAPI
Dispatch_AddRef(IDispatch
*iface
)
152 static ULONG WINAPI
Dispatch_Release(IDispatch
*iface
)
157 static ULONG global_named_item_ref
, visible_named_item_ref
, visible_code_named_item_ref
, persistent_named_item_ref
;
159 static ULONG WINAPI
global_AddRef(IDispatch
*iface
)
161 return ++global_named_item_ref
;
164 static ULONG WINAPI
global_Release(IDispatch
*iface
)
166 return --global_named_item_ref
;
169 static ULONG WINAPI
visible_AddRef(IDispatch
*iface
)
171 return ++visible_named_item_ref
;
174 static ULONG WINAPI
visible_Release(IDispatch
*iface
)
176 return --visible_named_item_ref
;
179 static ULONG WINAPI
visible_code_AddRef(IDispatch
*iface
)
181 return ++visible_code_named_item_ref
;
184 static ULONG WINAPI
visible_code_Release(IDispatch
*iface
)
186 return --visible_code_named_item_ref
;
189 static ULONG WINAPI
persistent_AddRef(IDispatch
*iface
)
191 return ++persistent_named_item_ref
;
194 static ULONG WINAPI
persistent_Release(IDispatch
*iface
)
196 return --persistent_named_item_ref
;
199 static HRESULT WINAPI
Dispatch_GetTypeInfoCount(IDispatch
*iface
, UINT
*pctinfo
)
201 ok(0, "unexpected call\n");
205 static HRESULT WINAPI
Dispatch_GetTypeInfo(IDispatch
*iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
207 return DISP_E_BADINDEX
;
210 static HRESULT WINAPI
Dispatch_GetIDsOfNames(IDispatch
*iface
, REFIID riid
, LPOLESTR
*names
, UINT name_cnt
,
211 LCID lcid
, DISPID
*ids
)
213 ok(name_cnt
== 1, "name_cnt = %u\n", name_cnt
);
214 if(!wcscmp(names
[0], L
"testCall")) {
219 CHECK_EXPECT2(GetIDsOfNames
);
220 return DISP_E_UNKNOWNNAME
;
223 static HRESULT WINAPI
visible_GetIDsOfNames(IDispatch
*iface
, REFIID riid
, LPOLESTR
*names
, UINT name_cnt
,
224 LCID lcid
, DISPID
*ids
)
226 ok(name_cnt
== 1, "name_cnt = %u\n", name_cnt
);
227 if(!wcscmp(names
[0], L
"testCall")) {
232 CHECK_EXPECT2(GetIDsOfNames_visible
);
233 return DISP_E_UNKNOWNNAME
;
236 static HRESULT WINAPI
persistent_GetIDsOfNames(IDispatch
*iface
, REFIID riid
, LPOLESTR
*names
, UINT name_cnt
,
237 LCID lcid
, DISPID
*ids
)
239 ok(name_cnt
== 1, "name_cnt = %u\n", name_cnt
);
241 CHECK_EXPECT2(GetIDsOfNames_persistent
);
242 return DISP_E_UNKNOWNNAME
;
245 static HRESULT WINAPI
Dispatch_Invoke(IDispatch
*iface
, DISPID id
, REFIID riid
, LCID lcid
, WORD flags
,
246 DISPPARAMS
*dp
, VARIANT
*res
, EXCEPINFO
*ei
, UINT
*err
)
248 CHECK_EXPECT(testCall
);
249 ok(id
== 1, "id = %u\n", id
);
250 ok(flags
== DISPATCH_METHOD
, "flags = %x\n", flags
);
251 ok(!dp
->cArgs
, "cArgs = %u\n", dp
->cArgs
);
252 ok(!res
, "res = %p\n", res
);
256 static const IDispatchVtbl dispatch_vtbl
= {
257 Dispatch_QueryInterface
,
260 Dispatch_GetTypeInfoCount
,
261 Dispatch_GetTypeInfo
,
262 Dispatch_GetIDsOfNames
,
266 static IDispatch dispatch_object
= { &dispatch_vtbl
};
268 static const IDispatchVtbl global_named_item_vtbl
= {
269 Dispatch_QueryInterface
,
272 Dispatch_GetTypeInfoCount
,
273 Dispatch_GetTypeInfo
,
274 Dispatch_GetIDsOfNames
,
278 static IDispatch global_named_item
= { &global_named_item_vtbl
};
280 static const IDispatchVtbl visible_named_item_vtbl
= {
281 Dispatch_QueryInterface
,
284 Dispatch_GetTypeInfoCount
,
285 Dispatch_GetTypeInfo
,
286 visible_GetIDsOfNames
,
290 static IDispatch visible_named_item
= { &visible_named_item_vtbl
};
292 static const IDispatchVtbl visible_code_named_item_vtbl
= {
293 Dispatch_QueryInterface
,
295 visible_code_Release
,
296 Dispatch_GetTypeInfoCount
,
297 Dispatch_GetTypeInfo
,
298 Dispatch_GetIDsOfNames
,
302 static IDispatch visible_code_named_item
= { &visible_code_named_item_vtbl
};
304 static const IDispatchVtbl persistent_named_item_vtbl
= {
305 Dispatch_QueryInterface
,
308 Dispatch_GetTypeInfoCount
,
309 Dispatch_GetTypeInfo
,
310 persistent_GetIDsOfNames
,
314 static IDispatch persistent_named_item
= { &persistent_named_item_vtbl
};
316 static HRESULT WINAPI
ActiveScriptSite_QueryInterface(IActiveScriptSite
*iface
, REFIID riid
, void **ppv
)
320 if(IsEqualGUID(&IID_IUnknown
, riid
))
322 else if(IsEqualGUID(&IID_IActiveScriptSite
, riid
))
325 return E_NOINTERFACE
;
327 IUnknown_AddRef((IUnknown
*)*ppv
);
331 static ULONG WINAPI
ActiveScriptSite_AddRef(IActiveScriptSite
*iface
)
336 static ULONG WINAPI
ActiveScriptSite_Release(IActiveScriptSite
*iface
)
341 static HRESULT WINAPI
ActiveScriptSite_GetLCID(IActiveScriptSite
*iface
, LCID
*plcid
)
343 CHECK_EXPECT(GetLCID
);
347 static HRESULT WINAPI
ActiveScriptSite_GetItemInfo(IActiveScriptSite
*iface
, LPCOLESTR name
,
348 DWORD return_mask
, IUnknown
**item_unk
, ITypeInfo
**item_ti
)
350 ok(return_mask
== SCRIPTINFO_IUNKNOWN
, "return_mask = %x\n", return_mask
);
351 if(!wcscmp(name
, L
"globalItem")) {
352 CHECK_EXPECT(GetItemInfo_global
);
353 IDispatch_AddRef(&global_named_item
);
354 *item_unk
= (IUnknown
*)&global_named_item
;
357 if(!wcscmp(name
, L
"globalCodeItem")) {
358 CHECK_EXPECT(GetItemInfo_global_code
);
359 IDispatch_AddRef(&dispatch_object
);
360 *item_unk
= (IUnknown
*)&dispatch_object
;
363 if(!wcscmp(name
, L
"visibleItem")) {
364 CHECK_EXPECT(GetItemInfo_visible
);
365 IDispatch_AddRef(&visible_named_item
);
366 *item_unk
= (IUnknown
*)&visible_named_item
;
369 if(!wcscmp(name
, L
"visibleCodeItem")) {
370 CHECK_EXPECT(GetItemInfo_visible_code
);
371 IDispatch_AddRef(&visible_code_named_item
);
372 *item_unk
= (IUnknown
*)&visible_code_named_item
;
375 if(!wcscmp(name
, L
"persistent")) {
376 CHECK_EXPECT(GetItemInfo_persistent
);
377 IDispatch_AddRef(&persistent_named_item
);
378 *item_unk
= (IUnknown
*)&persistent_named_item
;
381 ok(0, "unexpected call %s\n", wine_dbgstr_w(name
));
385 static HRESULT WINAPI
ActiveScriptSite_GetDocVersionString(IActiveScriptSite
*iface
, BSTR
*pbstrVersion
)
387 ok(0, "unexpected call\n");
391 static HRESULT WINAPI
ActiveScriptSite_OnScriptTerminate(IActiveScriptSite
*iface
,
392 const VARIANT
*pvarResult
, const EXCEPINFO
*pexcepinfo
)
394 ok(0, "unexpected call\n");
398 static HRESULT WINAPI
ActiveScriptSite_OnStateChange(IActiveScriptSite
*iface
, SCRIPTSTATE ssScriptState
)
400 switch(ssScriptState
) {
401 case SCRIPTSTATE_UNINITIALIZED
:
402 CHECK_EXPECT(OnStateChange_UNINITIALIZED
);
404 case SCRIPTSTATE_STARTED
:
405 CHECK_EXPECT(OnStateChange_STARTED
);
407 case SCRIPTSTATE_CONNECTED
:
408 CHECK_EXPECT(OnStateChange_CONNECTED
);
410 case SCRIPTSTATE_DISCONNECTED
:
411 CHECK_EXPECT(OnStateChange_DISCONNECTED
);
413 case SCRIPTSTATE_CLOSED
:
414 CHECK_EXPECT(OnStateChange_CLOSED
);
416 case SCRIPTSTATE_INITIALIZED
:
417 CHECK_EXPECT(OnStateChange_INITIALIZED
);
420 ok(0, "unexpected call %d\n", ssScriptState
);
426 static HRESULT WINAPI
ActiveScriptSite_OnScriptError(IActiveScriptSite
*iface
, IActiveScriptError
*pscripterror
)
428 CHECK_EXPECT(OnScriptError
);
432 static HRESULT WINAPI
ActiveScriptSite_OnEnterScript(IActiveScriptSite
*iface
)
434 CHECK_EXPECT(OnEnterScript
);
438 static HRESULT WINAPI
ActiveScriptSite_OnLeaveScript(IActiveScriptSite
*iface
)
440 CHECK_EXPECT(OnLeaveScript
);
444 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl
= {
445 ActiveScriptSite_QueryInterface
,
446 ActiveScriptSite_AddRef
,
447 ActiveScriptSite_Release
,
448 ActiveScriptSite_GetLCID
,
449 ActiveScriptSite_GetItemInfo
,
450 ActiveScriptSite_GetDocVersionString
,
451 ActiveScriptSite_OnScriptTerminate
,
452 ActiveScriptSite_OnStateChange
,
453 ActiveScriptSite_OnScriptError
,
454 ActiveScriptSite_OnEnterScript
,
455 ActiveScriptSite_OnLeaveScript
458 static IActiveScriptSite ActiveScriptSite
= { &ActiveScriptSiteVtbl
};
460 static void test_safety(IActiveScript
*script
)
462 IObjectSafety
*safety
;
463 DWORD supported
, enabled
;
466 hres
= IActiveScript_QueryInterface(script
, &IID_IObjectSafety
, (void**)&safety
);
467 ok(hres
== S_OK
, "Could not get IObjectSafety: %08x\n", hres
);
471 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_NULL
, &supported
, NULL
);
472 ok(hres
== E_POINTER
, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres
);
473 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_NULL
, NULL
, &enabled
);
474 ok(hres
== E_POINTER
, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres
);
476 supported
= enabled
= 0xdeadbeef;
477 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_NULL
, &supported
, &enabled
);
478 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
479 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
480 "supported=%x\n", supported
);
481 ok(enabled
== INTERFACE_USES_DISPEX
, "enabled=%x\n", enabled
);
483 supported
= enabled
= 0xdeadbeef;
484 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScript
, &supported
, &enabled
);
485 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
486 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
487 "supported=%x\n", supported
);
488 ok(enabled
== INTERFACE_USES_DISPEX
, "enabled=%x\n", enabled
);
490 supported
= enabled
= 0xdeadbeef;
491 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, &supported
, &enabled
);
492 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
493 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
494 "supported=%x\n", supported
);
495 ok(enabled
== INTERFACE_USES_DISPEX
, "enabled=%x\n", enabled
);
497 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
,
498 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
499 |INTERFACESAFE_FOR_UNTRUSTED_CALLER
,
500 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
);
501 ok(hres
== E_FAIL
, "SetInterfaceSafetyOptions failed: %08x, expected E_FAIL\n", hres
);
503 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
,
504 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
,
505 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
);
506 ok(hres
== S_OK
, "SetInterfaceSafetyOptions failed: %08x\n", hres
);
508 supported
= enabled
= 0xdeadbeef;
509 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, &supported
, &enabled
);
510 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
511 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
512 "supported=%x\n", supported
);
513 ok(enabled
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
514 "enabled=%x\n", enabled
);
516 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, INTERFACESAFE_FOR_UNTRUSTED_DATA
, 0);
517 ok(hres
== S_OK
, "SetInterfaceSafetyOptions failed: %08x\n", hres
);
519 supported
= enabled
= 0xdeadbeef;
520 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, &supported
, &enabled
);
521 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
522 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
523 "supported=%x\n", supported
);
524 ok(enabled
== (INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
), "enabled=%x\n", enabled
);
526 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
,
527 INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
, 0);
528 ok(hres
== S_OK
, "SetInterfaceSafetyOptions failed: %08x\n", hres
);
530 supported
= enabled
= 0xdeadbeef;
531 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, &supported
, &enabled
);
532 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
533 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
534 "supported=%x\n", supported
);
535 ok(enabled
== INTERFACE_USES_DISPEX
, "enabled=%x\n", enabled
);
537 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
,
538 INTERFACE_USES_DISPEX
, 0);
539 ok(hres
== S_OK
, "SetInterfaceSafetyOptions failed: %08x\n", hres
);
541 supported
= enabled
= 0xdeadbeef;
542 hres
= IObjectSafety_GetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, &supported
, &enabled
);
543 ok(hres
== S_OK
, "GetInterfaceSafetyOptions failed: %08x\n", hres
);
544 ok(supported
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
545 "supported=%x\n", supported
);
546 ok(enabled
== INTERFACE_USES_DISPEX
, "enabled=%x\n", enabled
);
548 IObjectSafety_Release(safety
);
551 static IDispatchEx
*get_script_dispatch(IActiveScript
*script
, const WCHAR
*item_name
)
557 disp
= (void*)0xdeadbeef;
558 hres
= IActiveScript_GetScriptDispatch(script
, item_name
, &disp
);
559 ok(hres
== S_OK
, "GetScriptDispatch failed: %08x\n", hres
);
563 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
564 IDispatch_Release(disp
);
565 ok(hres
== S_OK
, "Could not get IDispatchEx iface: %08x\n", hres
);
569 static void parse_script(IActiveScriptParse
*parse
, const char *src
)
574 SET_EXPECT(OnEnterScript
);
575 SET_EXPECT(OnLeaveScript
);
578 hres
= IActiveScriptParse_ParseScriptText(parse
, str
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
580 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
582 CHECK_CALLED(OnEnterScript
);
583 CHECK_CALLED(OnLeaveScript
);
586 #define get_disp_id(a,b,c,d) _get_disp_id(__LINE__,a,b,c,d)
587 static void _get_disp_id(unsigned line
, IDispatchEx
*dispex
, const char *name
, HRESULT exhres
, DISPID
*id
)
594 hres
= IDispatchEx_GetDispID(dispex
, str
, 0, id
);
595 ok_(__FILE__
,line
)(hres
== exhres
, "GetDispID(%s) returned %08x, expected %08x\n", name
, hres
, exhres
);
597 hres
= IDispatchEx_GetIDsOfNames(dispex
, &IID_NULL
, &str
, 1, 0, &id2
);
599 ok_(__FILE__
,line
)(hres
== exhres
, "GetIDsOfNames(%s) returned %08x, expected %08x\n", name
, hres
, exhres
);
600 ok_(__FILE__
,line
)(*id
== id2
, "GetIDsOfNames(%s) id != id2\n", name
);
603 static void test_no_script_dispatch(IActiveScript
*script
)
608 disp
= (void*)0xdeadbeef;
609 hres
= IActiveScript_GetScriptDispatch(script
, NULL
, &disp
);
610 ok(hres
== E_UNEXPECTED
, "hres = %08x, expected E_UNEXPECTED\n", hres
);
611 ok(!disp
, "disp != NULL\n");
614 static IActiveScript
*create_vbscript(void)
619 hres
= CoCreateInstance(&CLSID_VBScript
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
620 &IID_IActiveScript
, (void**)&ret
);
621 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
626 static void test_scriptdisp(void)
628 IDispatchEx
*script_disp
, *script_disp2
;
629 IActiveScriptParse
*parser
;
630 IActiveScript
*vbscript
;
638 vbscript
= create_vbscript();
640 hres
= IActiveScript_QueryInterface(vbscript
, &IID_IActiveScriptParse
, (void**)&parser
);
641 ok(hres
== S_OK
, "Could not get IActiveScriptParse iface: %08x\n", hres
);
643 test_state(vbscript
, SCRIPTSTATE_UNINITIALIZED
);
644 test_safety(vbscript
);
647 hres
= IActiveScript_SetScriptSite(vbscript
, &ActiveScriptSite
);
648 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
649 CHECK_CALLED(GetLCID
);
651 script_disp2
= get_script_dispatch(vbscript
, NULL
);
653 test_state(vbscript
, SCRIPTSTATE_UNINITIALIZED
);
655 SET_EXPECT(OnStateChange_INITIALIZED
);
656 hres
= IActiveScriptParse_InitNew(parser
);
657 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
658 CHECK_CALLED(OnStateChange_INITIALIZED
);
660 test_state(vbscript
, SCRIPTSTATE_INITIALIZED
);
662 SET_EXPECT(OnStateChange_CONNECTED
);
663 hres
= IActiveScript_SetScriptState(vbscript
, SCRIPTSTATE_CONNECTED
);
664 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres
);
665 CHECK_CALLED(OnStateChange_CONNECTED
);
667 test_state(vbscript
, SCRIPTSTATE_CONNECTED
);
669 script_disp
= get_script_dispatch(vbscript
, NULL
);
670 ok(script_disp
== script_disp2
, "script_disp != script_disp2\n");
671 IDispatchEx_Release(script_disp2
);
674 get_disp_id(script_disp
, "LCase", DISP_E_UNKNOWNNAME
, &id
);
675 ok(id
== -1, "id = %d, expected -1\n", id
);
677 get_disp_id(script_disp
, "globalVariable", DISP_E_UNKNOWNNAME
, &id
);
678 parse_script(parser
, "dim globalVariable\nglobalVariable = 3");
679 get_disp_id(script_disp
, "globalVariable", S_OK
, &id
);
681 memset(&dp
, 0, sizeof(dp
));
682 memset(&ei
, 0, sizeof(ei
));
684 hres
= IDispatchEx_InvokeEx(script_disp
, id
, 0, DISPATCH_PROPERTYGET
|DISPATCH_METHOD
, &dp
, &v
, &ei
, NULL
);
685 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
686 ok(V_VT(&v
) == VT_I2
, "V_VT(v) = %d\n", V_VT(&v
));
687 ok(V_I2(&v
) == 3, "V_I2(v) = %d\n", V_I2(&v
));
689 get_disp_id(script_disp
, "globalVariable2", DISP_E_UNKNOWNNAME
, &id
);
690 parse_script(parser
, "globalVariable2 = 4");
691 get_disp_id(script_disp
, "globalVariable2", S_OK
, &id
);
693 get_disp_id(script_disp
, "globalFunction", DISP_E_UNKNOWNNAME
, &id
);
694 parse_script(parser
, "function globalFunction()\nglobalFunction=5\nend function");
695 get_disp_id(script_disp
, "globalFunction", S_OK
, &id
);
697 SET_EXPECT(OnEnterScript
);
698 SET_EXPECT(OnLeaveScript
);
700 memset(&dp
, 0, sizeof(dp
));
701 memset(&ei
, 0, sizeof(ei
));
703 hres
= IDispatchEx_InvokeEx(script_disp
, id
, 0, DISPATCH_PROPERTYGET
|DISPATCH_METHOD
, &dp
, &v
, &ei
, NULL
);
704 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
705 ok(V_VT(&v
) == VT_I2
, "V_VT(v) = %d\n", V_VT(&v
));
706 ok(V_I2(&v
) == 5, "V_I2(v) = %d\n", V_I2(&v
));
708 CHECK_CALLED(OnEnterScript
);
709 CHECK_CALLED(OnLeaveScript
);
711 SET_EXPECT(OnEnterScript
);
712 SET_EXPECT(OnLeaveScript
);
714 memset(&dp
, 0, sizeof(dp
));
715 memset(&ei
, 0, sizeof(ei
));
717 hres
= IDispatchEx_Invoke(script_disp
, id
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
|DISPATCH_METHOD
, &dp
, &v
, &ei
, NULL
);
718 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
719 ok(V_VT(&v
) == VT_I2
, "V_VT(v) = %d\n", V_VT(&v
));
720 ok(V_I2(&v
) == 5, "V_I2(v) = %d\n", V_I2(&v
));
722 CHECK_CALLED(OnEnterScript
);
723 CHECK_CALLED(OnLeaveScript
);
725 get_disp_id(script_disp
, "globalSub", DISP_E_UNKNOWNNAME
, &id
);
726 parse_script(parser
, "sub globalSub()\nend sub");
727 get_disp_id(script_disp
, "globalSub", S_OK
, &id
);
728 get_disp_id(script_disp
, "globalSub", S_OK
, &id2
);
729 ok(id
== id2
, "id != id2\n");
731 get_disp_id(script_disp
, "constVariable", DISP_E_UNKNOWNNAME
, &id
);
732 parse_script(parser
, "const constVariable = 6");
733 get_disp_id(script_disp
, "ConstVariable", S_OK
, &id
);
734 get_disp_id(script_disp
, "Constvariable", S_OK
, &id2
);
735 ok(id
== id2
, "id != id2\n");
737 IDispatchEx_Release(script_disp
);
739 IActiveScriptParse_Release(parser
);
741 SET_EXPECT(OnStateChange_DISCONNECTED
);
742 SET_EXPECT(OnStateChange_INITIALIZED
);
743 SET_EXPECT(OnStateChange_CLOSED
);
744 hres
= IActiveScript_Close(vbscript
);
745 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
746 CHECK_CALLED(OnStateChange_DISCONNECTED
);
747 CHECK_CALLED(OnStateChange_INITIALIZED
);
748 CHECK_CALLED(OnStateChange_CLOSED
);
750 ref
= IActiveScript_Release(vbscript
);
751 ok(!ref
, "ref = %d\n", ref
);
754 static void test_code_persistence(void)
756 IActiveScriptParse
*parser
;
757 IDispatchEx
*script_disp
;
758 IActiveScript
*vbscript
;
764 vbscript
= create_vbscript();
766 hr
= IActiveScript_QueryInterface(vbscript
, &IID_IActiveScriptParse
, (void**)&parser
);
767 ok(hr
== S_OK
, "Could not get IActiveScriptParse iface: %08x\n", hr
);
768 test_state(vbscript
, SCRIPTSTATE_UNINITIALIZED
);
769 test_safety(vbscript
);
772 hr
= IActiveScript_SetScriptSite(vbscript
, &ActiveScriptSite
);
773 ok(hr
== S_OK
, "SetScriptSite failed: %08x\n", hr
);
774 CHECK_CALLED(GetLCID
);
776 SET_EXPECT(OnStateChange_INITIALIZED
);
777 hr
= IActiveScriptParse_InitNew(parser
);
778 ok(hr
== S_OK
, "InitNew failed: %08x\n", hr
);
779 CHECK_CALLED(OnStateChange_INITIALIZED
);
780 test_state(vbscript
, SCRIPTSTATE_INITIALIZED
);
782 hr
= IActiveScriptParse_ParseScriptText(parser
, L
""
785 NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
786 ok(hr
== S_OK
, "ParseScriptText failed: %08x\n", hr
);
788 hr
= IActiveScriptParse_ParseScriptText(parser
, L
""
792 NULL
, NULL
, NULL
, 0, 0, SCRIPTTEXT_ISPERSISTENT
, NULL
, NULL
);
793 ok(hr
== S_OK
, "ParseScriptText failed: %08x\n", hr
);
795 /* Pending code does not add identifiers to the global scope */
796 script_disp
= get_script_dispatch(vbscript
, NULL
);
798 get_disp_id(script_disp
, "x", DISP_E_UNKNOWNNAME
, &id
);
799 ok(id
== -1, "id = %d, expected -1\n", id
);
801 get_disp_id(script_disp
, "y", DISP_E_UNKNOWNNAME
, &id
);
802 ok(id
== -1, "id = %d, expected -1\n", id
);
804 get_disp_id(script_disp
, "z", DISP_E_UNKNOWNNAME
, &id
);
805 ok(id
== -1, "id = %d, expected -1\n", id
);
806 IDispatchEx_Release(script_disp
);
808 /* Uninitialized state removes code without SCRIPTTEXT_ISPERSISTENT */
809 SET_EXPECT(OnStateChange_UNINITIALIZED
);
810 hr
= IActiveScript_SetScriptState(vbscript
, SCRIPTSTATE_UNINITIALIZED
);
811 ok(hr
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hr
);
812 CHECK_CALLED(OnStateChange_UNINITIALIZED
);
813 test_no_script_dispatch(vbscript
);
816 SET_EXPECT(OnStateChange_INITIALIZED
);
817 hr
= IActiveScript_SetScriptSite(vbscript
, &ActiveScriptSite
);
818 ok(hr
== S_OK
, "SetScriptSite failed: %08x\n", hr
);
819 CHECK_CALLED(GetLCID
);
820 CHECK_CALLED(OnStateChange_INITIALIZED
);
822 hr
= IActiveScriptParse_ParseScriptText(parser
, L
"var = 20\n", NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
823 ok(hr
== S_OK
, "ParseScriptText failed: %08x\n", hr
);
825 SET_EXPECT(OnStateChange_CONNECTED
);
826 SET_EXPECT_MULTI(OnEnterScript
, 2);
827 SET_EXPECT_MULTI(OnLeaveScript
, 2);
828 hr
= IActiveScript_SetScriptState(vbscript
, SCRIPTSTATE_CONNECTED
);
829 ok(hr
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hr
);
830 CHECK_CALLED(OnStateChange_CONNECTED
);
831 CHECK_CALLED_MULTI(OnEnterScript
, 2);
832 CHECK_CALLED_MULTI(OnLeaveScript
, 2);
833 test_state(vbscript
, SCRIPTSTATE_CONNECTED
);
835 script_disp
= get_script_dispatch(vbscript
, NULL
);
837 get_disp_id(script_disp
, "x", DISP_E_UNKNOWNNAME
, &id
);
838 ok(id
== -1, "id = %d, expected -1\n", id
);
840 get_disp_id(script_disp
, "y", S_OK
, &id
);
841 ok(id
!= -1, "id = -1\n");
843 get_disp_id(script_disp
, "z", S_OK
, &id
);
844 ok(id
!= -1, "id = -1\n");
845 IDispatchEx_Release(script_disp
);
847 SET_EXPECT(OnEnterScript
);
848 SET_EXPECT(OnLeaveScript
);
849 hr
= IActiveScriptParse_ParseScriptText(parser
, L
"y", NULL
, NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
850 ok(hr
== S_OK
, "ParseScriptText failed: %08x\n", hr
);
851 ok(V_VT(&var
) == VT_I2
&& V_I2(&var
) == 42, "V_VT(y) = %d, V_I2(y) = %d\n", V_VT(&var
), V_I2(&var
));
852 CHECK_CALLED(OnEnterScript
);
853 CHECK_CALLED(OnLeaveScript
);
855 SET_EXPECT(OnEnterScript
);
856 SET_EXPECT(OnLeaveScript
);
857 hr
= IActiveScriptParse_ParseScriptText(parser
, L
"var", NULL
, NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
858 ok(hr
== S_OK
, "ParseScriptText failed: %08x\n", hr
);
859 ok(V_VT(&var
) == VT_I2
&& V_I2(&var
) == 20, "V_VT(var) = %d, V_I2(var) = %d\n", V_VT(&var
), V_I2(&var
));
860 CHECK_CALLED(OnEnterScript
);
861 CHECK_CALLED(OnLeaveScript
);
863 /* Uninitialized state does not remove persistent code, even if it was executed */
864 SET_EXPECT(OnStateChange_DISCONNECTED
);
865 SET_EXPECT(OnStateChange_INITIALIZED
);
866 SET_EXPECT(OnStateChange_UNINITIALIZED
);
867 hr
= IActiveScript_SetScriptState(vbscript
, SCRIPTSTATE_UNINITIALIZED
);
868 ok(hr
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hr
);
869 CHECK_CALLED(OnStateChange_DISCONNECTED
);
870 CHECK_CALLED(OnStateChange_INITIALIZED
);
871 CHECK_CALLED(OnStateChange_UNINITIALIZED
);
872 test_no_script_dispatch(vbscript
);
875 SET_EXPECT(OnStateChange_INITIALIZED
);
876 hr
= IActiveScript_SetScriptSite(vbscript
, &ActiveScriptSite
);
877 ok(hr
== S_OK
, "SetScriptSite failed: %08x\n", hr
);
878 CHECK_CALLED(GetLCID
);
879 CHECK_CALLED(OnStateChange_INITIALIZED
);
881 script_disp
= get_script_dispatch(vbscript
, NULL
);
883 get_disp_id(script_disp
, "z", DISP_E_UNKNOWNNAME
, &id
);
884 ok(id
== -1, "id = %d, expected -1\n", id
);
885 IDispatchEx_Release(script_disp
);
887 SET_EXPECT(OnStateChange_CONNECTED
);
888 SET_EXPECT(OnEnterScript
);
889 SET_EXPECT(OnLeaveScript
);
890 hr
= IActiveScript_SetScriptState(vbscript
, SCRIPTSTATE_CONNECTED
);
891 ok(hr
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hr
);
892 CHECK_CALLED(OnStateChange_CONNECTED
);
893 CHECK_CALLED(OnEnterScript
);
894 CHECK_CALLED(OnLeaveScript
);
895 test_state(vbscript
, SCRIPTSTATE_CONNECTED
);
897 script_disp
= get_script_dispatch(vbscript
, NULL
);
899 get_disp_id(script_disp
, "z", S_OK
, &id
);
900 ok(id
!= -1, "id = -1\n");
901 IDispatchEx_Release(script_disp
);
903 SET_EXPECT(OnEnterScript
);
904 SET_EXPECT(OnLeaveScript
);
905 hr
= IActiveScriptParse_ParseScriptText(parser
, L
"y", NULL
, NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
906 ok(hr
== S_OK
, "ParseScriptText failed: %08x\n", hr
);
907 ok(V_VT(&var
) == VT_I2
&& V_I2(&var
) == 42, "V_VT(y) = %d, V_I2(y) = %d\n", V_VT(&var
), V_I2(&var
));
908 CHECK_CALLED(OnEnterScript
);
909 CHECK_CALLED(OnLeaveScript
);
911 SET_EXPECT(OnEnterScript
);
912 SET_EXPECT(OnLeaveScript
);
913 hr
= IActiveScriptParse_ParseScriptText(parser
, L
"var", NULL
, NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
914 ok(hr
== S_OK
, "ParseScriptText failed: %08x\n", hr
);
915 ok(V_VT(&var
) == VT_I2
&& V_I2(&var
) == 10, "V_VT(var) = %d, V_I2(var) = %d\n", V_VT(&var
), V_I2(&var
));
916 CHECK_CALLED(OnEnterScript
);
917 CHECK_CALLED(OnLeaveScript
);
919 SET_EXPECT(OnStateChange_DISCONNECTED
);
920 SET_EXPECT(OnStateChange_INITIALIZED
);
921 SET_EXPECT(OnStateChange_UNINITIALIZED
);
922 hr
= IActiveScript_SetScriptState(vbscript
, SCRIPTSTATE_UNINITIALIZED
);
923 ok(hr
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hr
);
924 CHECK_CALLED(OnStateChange_DISCONNECTED
);
925 CHECK_CALLED(OnStateChange_INITIALIZED
);
926 CHECK_CALLED(OnStateChange_UNINITIALIZED
);
929 SET_EXPECT(OnStateChange_INITIALIZED
);
930 hr
= IActiveScript_SetScriptSite(vbscript
, &ActiveScriptSite
);
931 ok(hr
== S_OK
, "SetScriptSite failed: %08x\n", hr
);
932 CHECK_CALLED(GetLCID
);
933 CHECK_CALLED(OnStateChange_INITIALIZED
);
935 hr
= IActiveScriptParse_ParseScriptText(parser
, L
"dim y\ny = 2\n", NULL
, NULL
, NULL
, 0, 0, SCRIPTTEXT_ISPERSISTENT
, NULL
, NULL
);
936 ok(hr
== S_OK
, "ParseScriptText failed: %08x\n", hr
);
938 /* Closing the script engine removes all code (even if it's pending and persistent) */
939 SET_EXPECT(OnStateChange_CLOSED
);
940 hr
= IActiveScript_Close(vbscript
);
941 ok(hr
== S_OK
, "Close failed: %08x\n", hr
);
942 CHECK_CALLED(OnStateChange_CLOSED
);
943 test_state(vbscript
, SCRIPTSTATE_CLOSED
);
944 test_no_script_dispatch(vbscript
);
946 SET_EXPECT(OnStateChange_INITIALIZED
);
948 hr
= IActiveScript_SetScriptSite(vbscript
, &ActiveScriptSite
);
949 ok(hr
== S_OK
, "SetScriptSite failed: %08x\n", hr
);
950 CHECK_CALLED(OnStateChange_INITIALIZED
);
951 CHECK_CALLED(GetLCID
);
952 test_state(vbscript
, SCRIPTSTATE_INITIALIZED
);
954 SET_EXPECT(OnStateChange_CONNECTED
);
955 hr
= IActiveScript_SetScriptState(vbscript
, SCRIPTSTATE_CONNECTED
);
956 ok(hr
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hr
);
957 CHECK_CALLED(OnStateChange_CONNECTED
);
958 test_state(vbscript
, SCRIPTSTATE_CONNECTED
);
960 script_disp
= get_script_dispatch(vbscript
, NULL
);
962 get_disp_id(script_disp
, "y", DISP_E_UNKNOWNNAME
, &id
);
963 ok(id
== -1, "id = %d, expected -1\n", id
);
965 get_disp_id(script_disp
, "z", DISP_E_UNKNOWNNAME
, &id
);
966 ok(id
== -1, "id = %d, expected -1\n", id
);
967 IDispatchEx_Release(script_disp
);
969 IActiveScriptParse_Release(parser
);
971 SET_EXPECT(OnStateChange_DISCONNECTED
);
972 SET_EXPECT(OnStateChange_INITIALIZED
);
973 SET_EXPECT(OnStateChange_CLOSED
);
974 ref
= IActiveScript_Release(vbscript
);
975 ok(!ref
, "ref = %d\n", ref
);
976 CHECK_CALLED(OnStateChange_DISCONNECTED
);
977 CHECK_CALLED(OnStateChange_INITIALIZED
);
978 CHECK_CALLED(OnStateChange_CLOSED
);
981 static void test_script_typeinfo(void)
990 { L
"foobar", VT_VARIANT
, 0 },
991 { L
"test", VT_VOID
, 0 },
992 { L
"subtract", VT_VARIANT
, 2 },
993 { L
"emptyfn", VT_VARIANT
, 0 }
1005 ITypeInfo
*typeinfo
, *typeinfo2
;
1006 ITypeComp
*typecomp
, *typecomp2
;
1007 IActiveScriptParse
*parser
;
1008 IDispatchEx
*script_disp
;
1009 IActiveScript
*vbscript
;
1020 WCHAR str
[64], *names
= str
;
1021 BSTR bstr
, bstrs
[5];
1025 vbscript
= create_vbscript();
1027 hr
= IActiveScript_QueryInterface(vbscript
, &IID_IActiveScriptParse
, (void**)&parser
);
1028 ok(hr
== S_OK
, "Could not get IActiveScriptParse iface: %08x\n", hr
);
1030 SET_EXPECT(GetLCID
);
1031 hr
= IActiveScript_SetScriptSite(vbscript
, &ActiveScriptSite
);
1032 ok(hr
== S_OK
, "SetScriptSite failed: %08x\n", hr
);
1033 CHECK_CALLED(GetLCID
);
1035 SET_EXPECT(OnStateChange_INITIALIZED
);
1036 hr
= IActiveScriptParse_InitNew(parser
);
1037 ok(hr
== S_OK
, "InitNew failed: %08x\n", hr
);
1038 CHECK_CALLED(OnStateChange_INITIALIZED
);
1040 SET_EXPECT(OnStateChange_CONNECTED
);
1041 hr
= IActiveScript_SetScriptState(vbscript
, SCRIPTSTATE_CONNECTED
);
1042 ok(hr
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hr
);
1043 CHECK_CALLED(OnStateChange_CONNECTED
);
1045 parse_script(parser
,
1047 "const const_var = 1337\n"
1050 " foobar = \"foobar\"\n"
1053 "sub test\nend sub\n"
1054 "private sub private_sub\nend sub\n"
1056 "function subtract(byref x, byval y)\n"
1057 " subtract = x - y\n"
1060 "function emptyfn\nend function\n"
1064 " public sub method\nend sub\n"
1065 " private function strret\n"
1066 " strret = \"ret\"\n"
1071 "dim obj\nset obj = new C\n");
1073 script_disp
= get_script_dispatch(vbscript
, NULL
);
1074 hr
= IDispatchEx_QueryInterface(script_disp
, &IID_ITypeInfo
, (void**)&typeinfo
);
1075 ok(hr
== E_NOINTERFACE
, "QueryInterface(IID_ITypeInfo) returned: %08x\n", hr
);
1076 hr
= IDispatchEx_GetTypeInfo(script_disp
, 1, LOCALE_USER_DEFAULT
, &typeinfo
);
1077 ok(hr
== DISP_E_BADINDEX
, "GetTypeInfo returned: %08x\n", hr
);
1078 hr
= IDispatchEx_GetTypeInfo(script_disp
, 0, LOCALE_USER_DEFAULT
, &typeinfo
);
1079 ok(hr
== S_OK
, "GetTypeInfo failed: %08x\n", hr
);
1080 hr
= IDispatchEx_GetTypeInfo(script_disp
, 0, LOCALE_USER_DEFAULT
, &typeinfo2
);
1081 ok(hr
== S_OK
, "GetTypeInfo failed: %08x\n", hr
);
1082 ok(typeinfo
!= typeinfo2
, "TypeInfo was not supposed to be shared.\n");
1083 ITypeInfo_Release(typeinfo2
);
1085 obj
= (void*)0xdeadbeef;
1086 hr
= ITypeInfo_CreateInstance(typeinfo
, NULL
, NULL
, NULL
);
1087 ok(hr
== E_INVALIDARG
, "CreateInstance returned: %08x\n", hr
);
1088 hr
= ITypeInfo_CreateInstance(typeinfo
, NULL
, NULL
, &obj
);
1089 ok(hr
== TYPE_E_BADMODULEKIND
, "CreateInstance returned: %08x\n", hr
);
1090 hr
= ITypeInfo_CreateInstance(typeinfo
, NULL
, &IID_IDispatch
, &obj
);
1091 ok(hr
== TYPE_E_BADMODULEKIND
, "CreateInstance returned: %08x\n", hr
);
1092 ok(!obj
, "Unexpected non-null obj %p.\n", obj
);
1094 hr
= ITypeInfo_GetDocumentation(typeinfo
, MEMBERID_NIL
, &bstr
, NULL
, NULL
, NULL
);
1095 ok(hr
== S_OK
, "GetDocumentation(MEMBERID_NIL) failed: %08x\n", hr
);
1096 ok(!lstrcmpW(bstr
, L
"VBScriptTypeInfo"), "Unexpected TypeInfo name %s\n", wine_dbgstr_w(bstr
));
1097 SysFreeString(bstr
);
1099 hr
= ITypeInfo_GetTypeAttr(typeinfo
, &attr
);
1100 ok(hr
== S_OK
, "GetTypeAttr failed: %08x\n", hr
);
1101 ok(IsEqualGUID(&attr
->guid
, &IID_IScriptTypeInfo
), "Unexpected GUID %s\n", wine_dbgstr_guid(&attr
->guid
));
1102 ok(attr
->lcid
== LOCALE_USER_DEFAULT
, "Unexpected LCID %u\n", attr
->lcid
);
1103 ok(attr
->memidConstructor
== MEMBERID_NIL
, "Unexpected constructor memid %u\n", attr
->memidConstructor
);
1104 ok(attr
->memidDestructor
== MEMBERID_NIL
, "Unexpected destructor memid %u\n", attr
->memidDestructor
);
1105 ok(attr
->cbSizeInstance
== 4, "Unexpected cbSizeInstance %u\n", attr
->cbSizeInstance
);
1106 ok(attr
->typekind
== TKIND_DISPATCH
, "Unexpected typekind %u\n", attr
->typekind
);
1107 ok(attr
->cFuncs
== ARRAY_SIZE(func
), "Unexpected cFuncs %u\n", attr
->cFuncs
);
1108 ok(attr
->cVars
== ARRAY_SIZE(var
), "Unexpected cVars %u\n", attr
->cVars
);
1109 ok(attr
->cImplTypes
== 1, "Unexpected cImplTypes %u\n", attr
->cImplTypes
);
1110 ok(attr
->cbSizeVft
== sizeof(IDispatchVtbl
), "Unexpected cbSizeVft %u\n", attr
->cbSizeVft
);
1111 ok(attr
->cbAlignment
== 4, "Unexpected cbAlignment %u\n", attr
->cbAlignment
);
1112 ok(attr
->wTypeFlags
== TYPEFLAG_FDISPATCHABLE
, "Unexpected wTypeFlags 0x%x\n", attr
->wTypeFlags
);
1113 ok(attr
->tdescAlias
.vt
== VT_EMPTY
, "Unexpected tdescAlias.vt %d\n", attr
->tdescAlias
.vt
);
1114 ok(attr
->idldescType
.wIDLFlags
== IDLFLAG_NONE
, "Unexpected idldescType.wIDLFlags 0x%x\n", attr
->idldescType
.wIDLFlags
);
1115 ITypeInfo_ReleaseTypeAttr(typeinfo
, attr
);
1117 /* The type inherits from IDispatch */
1118 hr
= ITypeInfo_GetImplTypeFlags(typeinfo
, 0, NULL
);
1119 ok(hr
== E_INVALIDARG
, "GetImplTypeFlags returned: %08x\n", hr
);
1120 hr
= ITypeInfo_GetImplTypeFlags(typeinfo
, 1, &implTypeFlags
);
1121 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "GetImplTypeFlags returned: %08x\n", hr
);
1122 hr
= ITypeInfo_GetImplTypeFlags(typeinfo
, -1, &implTypeFlags
);
1123 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "GetImplTypeFlags returned: %08x\n", hr
);
1124 hr
= ITypeInfo_GetImplTypeFlags(typeinfo
, 0, &implTypeFlags
);
1125 ok(hr
== S_OK
, "GetImplTypeFlags failed: %08x\n", hr
);
1126 ok(implTypeFlags
== 0, "Unexpected implTypeFlags 0x%x\n", implTypeFlags
);
1128 hr
= ITypeInfo_GetRefTypeOfImplType(typeinfo
, 0, NULL
);
1129 ok(hr
== E_INVALIDARG
, "GetRefTypeOfImplType returned: %08x\n", hr
);
1130 hr
= ITypeInfo_GetRefTypeOfImplType(typeinfo
, 1, &reftype
);
1131 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "GetRefTypeOfImplType returned: %08x\n", hr
);
1132 hr
= ITypeInfo_GetRefTypeOfImplType(typeinfo
, -1, &reftype
);
1133 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "GetRefTypeOfImplType failed: %08x\n", hr
);
1134 hr
= ITypeInfo_GetRefTypeOfImplType(typeinfo
, 0, &reftype
);
1135 ok(hr
== S_OK
, "GetRefTypeOfImplType failed: %08x\n", hr
);
1136 ok(reftype
== 1, "Unexpected reftype %d\n", reftype
);
1138 hr
= ITypeInfo_GetRefTypeInfo(typeinfo
, reftype
, NULL
);
1139 ok(hr
== E_INVALIDARG
, "GetRefTypeInfo returned: %08x\n", hr
);
1140 hr
= ITypeInfo_GetRefTypeInfo(typeinfo
, -1, &typeinfo2
);
1141 ok(hr
== E_INVALIDARG
, "GetRefTypeInfo returned: %08x\n", hr
);
1142 hr
= ITypeInfo_GetRefTypeInfo(typeinfo
, 4, &typeinfo2
);
1143 ok(hr
== E_FAIL
, "GetRefTypeInfo returned: %08x\n", hr
);
1144 hr
= ITypeInfo_GetRefTypeInfo(typeinfo
, 0, &typeinfo2
);
1145 ok(hr
== S_OK
, "GetRefTypeInfo failed: %08x\n", hr
);
1146 ok(typeinfo
== typeinfo2
, "Unexpected TypeInfo %p (expected %p)\n", typeinfo2
, typeinfo
);
1147 ITypeInfo_Release(typeinfo2
);
1148 hr
= ITypeInfo_GetRefTypeInfo(typeinfo
, reftype
, &typeinfo2
);
1149 ok(hr
== S_OK
, "GetRefTypeInfo failed: %08x\n", hr
);
1150 hr
= ITypeInfo_GetDocumentation(typeinfo2
, MEMBERID_NIL
, &bstr
, NULL
, NULL
, NULL
);
1151 ok(hr
== S_OK
, "GetDocumentation(MEMBERID_NIL) failed: %08x\n", hr
);
1152 ok(!lstrcmpW(bstr
, L
"IDispatch"), "Unexpected TypeInfo name %s\n", wine_dbgstr_w(bstr
));
1153 ITypeInfo_Release(typeinfo2
);
1154 SysFreeString(bstr
);
1156 /* GetIDsOfNames looks into the inherited types as well */
1157 wcscpy(str
, L
"queryinterface");
1158 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, NULL
, 1, &memid
);
1159 ok(hr
== E_INVALIDARG
, "GetIDsOfNames returned: %08x\n", hr
);
1160 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, &names
, 1, NULL
);
1161 ok(hr
== E_INVALIDARG
, "GetIDsOfNames returned: %08x\n", hr
);
1162 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, &names
, 0, &memid
);
1163 ok(hr
== E_INVALIDARG
, "GetIDsOfNames returned: %08x\n", hr
);
1164 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, &names
, 1, &memid
);
1165 ok(hr
== S_OK
, "GetIDsOfNames failed: %08x\n", hr
);
1166 ok(!lstrcmpW(str
, L
"queryinterface"), "Unexpected string %s\n", wine_dbgstr_w(str
));
1168 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, &names
, 1, &memid
);
1169 ok(hr
== DISP_E_UNKNOWNNAME
, "GetIDsOfNames returned: %08x\n", hr
);
1170 wcscpy(str
, L
"SUBtract");
1171 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, &names
, 1, &memid
);
1172 ok(hr
== S_OK
, "GetIDsOfNames failed: %08x\n", hr
);
1173 ok(!lstrcmpW(str
, L
"SUBtract"), "Unexpected string %s\n", wine_dbgstr_w(str
));
1175 hr
= ITypeInfo_GetNames(typeinfo
, memid
, NULL
, 1, &count
);
1176 ok(hr
== E_INVALIDARG
, "GetNames returned: %08x\n", hr
);
1177 hr
= ITypeInfo_GetNames(typeinfo
, memid
, bstrs
, 1, NULL
);
1178 ok(hr
== E_INVALIDARG
, "GetNames returned: %08x\n", hr
);
1179 hr
= ITypeInfo_GetNames(typeinfo
, memid
, bstrs
, 0, &count
);
1180 ok(hr
== S_OK
, "GetNames failed: %08x\n", hr
);
1181 ok(count
== 0, "Unexpected count %u\n", count
);
1182 hr
= ITypeInfo_GetNames(typeinfo
, memid
, bstrs
, ARRAY_SIZE(bstrs
), &count
);
1183 ok(hr
== S_OK
, "GetNames failed: %08x\n", hr
);
1184 ok(count
== 3, "Unexpected count %u\n", count
);
1185 ok(!lstrcmpW(bstrs
[0], L
"subtract"), "Unexpected function name %s\n", wine_dbgstr_w(bstrs
[0]));
1186 ok(!lstrcmpW(bstrs
[1], L
"x"), "Unexpected function first param name %s\n", wine_dbgstr_w(bstrs
[1]));
1187 ok(!lstrcmpW(bstrs
[2], L
"y"), "Unexpected function second param name %s\n", wine_dbgstr_w(bstrs
[2]));
1188 for (i
= 0; i
< count
; i
++) SysFreeString(bstrs
[i
]);
1190 hr
= ITypeInfo_GetMops(typeinfo
, memid
, NULL
);
1191 ok(hr
== E_INVALIDARG
, "GetMops returned: %08x\n", hr
);
1192 hr
= ITypeInfo_GetMops(typeinfo
, memid
, &bstr
);
1193 ok(hr
== S_OK
, "GetMops failed: %08x\n", hr
);
1194 ok(!bstr
, "Unexpected non-null string %s\n", wine_dbgstr_w(bstr
));
1195 hr
= ITypeInfo_GetMops(typeinfo
, MEMBERID_NIL
, &bstr
);
1196 ok(hr
== S_OK
, "GetMops failed: %08x\n", hr
);
1197 ok(!bstr
, "Unexpected non-null string %s\n", wine_dbgstr_w(bstr
));
1199 /* These always fail */
1200 obj
= (void*)0xdeadbeef;
1201 hr
= ITypeInfo_AddressOfMember(typeinfo
, memid
, INVOKE_FUNC
, NULL
);
1202 ok(hr
== E_INVALIDARG
, "AddressOfMember returned: %08x\n", hr
);
1203 hr
= ITypeInfo_AddressOfMember(typeinfo
, memid
, INVOKE_FUNC
, &obj
);
1204 ok(hr
== TYPE_E_BADMODULEKIND
, "AddressOfMember returned: %08x\n", hr
);
1205 ok(!obj
, "Unexpected non-null obj %p.\n", obj
);
1206 bstr
= (BSTR
)0xdeadbeef;
1207 hr
= ITypeInfo_GetDllEntry(typeinfo
, memid
, INVOKE_FUNC
, &bstr
, NULL
, NULL
);
1208 ok(hr
== TYPE_E_BADMODULEKIND
, "GetDllEntry returned: %08x\n", hr
);
1209 ok(!bstr
, "Unexpected non-null str %p.\n", bstr
);
1210 wcscpy(str
, L
"Invoke");
1211 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, &names
, 1, &memid
);
1212 ok(hr
== S_OK
, "GetIDsOfNames failed: %08x\n", hr
);
1213 obj
= (void*)0xdeadbeef;
1214 hr
= ITypeInfo_AddressOfMember(typeinfo
, memid
, INVOKE_FUNC
, &obj
);
1215 ok(hr
== TYPE_E_BADMODULEKIND
, "AddressOfMember returned: %08x\n", hr
);
1216 ok(!obj
, "Unexpected non-null obj %p.\n", obj
);
1217 bstr
= (BSTR
)0xdeadbeef;
1218 hr
= ITypeInfo_GetDllEntry(typeinfo
, memid
, INVOKE_FUNC
, &bstr
, NULL
, NULL
);
1219 ok(hr
== TYPE_E_BADMODULEKIND
, "GetDllEntry returned: %08x\n", hr
);
1220 ok(!bstr
, "Unexpected non-null str %p.\n", bstr
);
1222 /* Check variable descriptions */
1223 hr
= ITypeInfo_GetVarDesc(typeinfo
, 0, NULL
);
1224 ok(hr
== E_INVALIDARG
, "GetVarDesc returned: %08x\n", hr
);
1225 hr
= ITypeInfo_GetVarDesc(typeinfo
, 1337, &vardesc
);
1226 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "GetVarDesc returned: %08x\n", hr
);
1227 for (i
= 0; i
< ARRAY_SIZE(var
); i
++)
1229 hr
= ITypeInfo_GetVarDesc(typeinfo
, i
, &vardesc
);
1230 ok(hr
== S_OK
, "GetVarDesc(%u) failed: %08x\n", i
, hr
);
1231 hr
= ITypeInfo_GetDocumentation(typeinfo
, vardesc
->memid
, &bstr
, &bstrs
[0], NULL
, NULL
);
1232 ok(hr
== S_OK
, "[%u] GetDocumentation failed: %08x\n", i
, hr
);
1233 ok(!lstrcmpW(bstr
, var
[i
].name
), "[%u] Unexpected variable name %s (expected %s)\n",
1234 i
, wine_dbgstr_w(bstr
), wine_dbgstr_w(var
[i
].name
));
1235 ok(!bstrs
[0], "[%u] Unexpected doc string %s\n", i
, wine_dbgstr_w(bstrs
[0]));
1236 SysFreeString(bstr
);
1237 ok(vardesc
->lpstrSchema
== NULL
, "[%u] Unexpected lpstrSchema %p\n", i
, vardesc
->lpstrSchema
);
1238 ok(vardesc
->oInst
== 0, "[%u] Unexpected oInst %u\n", i
, vardesc
->oInst
);
1239 ok(vardesc
->varkind
== VAR_DISPATCH
, "[%u] Unexpected varkind %d\n", i
, vardesc
->varkind
);
1240 ok(vardesc
->wVarFlags
== 0, "[%u] Unexpected wVarFlags 0x%x\n", i
, vardesc
->wVarFlags
);
1241 ok(vardesc
->elemdescVar
.tdesc
.vt
== VT_VARIANT
,
1242 "[%u] Unexpected variable type vt %d (expected %d)\n", i
, vardesc
->elemdescVar
.tdesc
.vt
, 0);
1243 ok(vardesc
->elemdescVar
.paramdesc
.pparamdescex
== NULL
,
1244 "[%u] Unexpected variable type pparamdescex %p\n", i
, vardesc
->elemdescVar
.paramdesc
.pparamdescex
);
1245 ok(vardesc
->elemdescVar
.paramdesc
.wParamFlags
== PARAMFLAG_NONE
,
1246 "[%u] Unexpected variable type wParamFlags 0x%x\n", i
, vardesc
->elemdescVar
.paramdesc
.wParamFlags
);
1247 ITypeInfo_ReleaseVarDesc(typeinfo
, vardesc
);
1250 /* Check function descriptions */
1251 hr
= ITypeInfo_GetFuncDesc(typeinfo
, 0, NULL
);
1252 ok(hr
== E_INVALIDARG
, "GetFuncDesc returned: %08x\n", hr
);
1253 hr
= ITypeInfo_GetFuncDesc(typeinfo
, 1337, &funcdesc
);
1254 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "GetFuncDesc returned: %08x\n", hr
);
1255 for (i
= 0; i
< ARRAY_SIZE(func
); i
++)
1257 hr
= ITypeInfo_GetFuncDesc(typeinfo
, i
, &funcdesc
);
1258 ok(hr
== S_OK
, "GetFuncDesc(%u) failed: %08x\n", i
, hr
);
1259 hr
= ITypeInfo_GetDocumentation(typeinfo
, funcdesc
->memid
, &bstr
, &bstrs
[0], NULL
, NULL
);
1260 ok(hr
== S_OK
, "[%u] GetDocumentation failed: %08x\n", i
, hr
);
1261 ok(!lstrcmpW(bstr
, func
[i
].name
), "[%u] Unexpected function name %s (expected %s)\n",
1262 i
, wine_dbgstr_w(bstr
), wine_dbgstr_w(func
[i
].name
));
1263 ok(!bstrs
[0], "[%u] Unexpected doc string %s\n", i
, wine_dbgstr_w(bstrs
[0]));
1264 SysFreeString(bstr
);
1265 ok(funcdesc
->lprgscode
== NULL
, "[%u] Unexpected lprgscode %p\n", i
, funcdesc
->lprgscode
);
1266 ok(func
[i
].num_args
? (funcdesc
->lprgelemdescParam
!= NULL
) : (funcdesc
->lprgelemdescParam
== NULL
),
1267 "[%u] Unexpected lprgelemdescParam %p\n", i
, funcdesc
->lprgelemdescParam
);
1268 ok(funcdesc
->funckind
== FUNC_DISPATCH
, "[%u] Unexpected funckind %u\n", i
, funcdesc
->funckind
);
1269 ok(funcdesc
->invkind
== INVOKE_FUNC
, "[%u] Unexpected invkind %u\n", i
, funcdesc
->invkind
);
1270 ok(funcdesc
->callconv
== CC_STDCALL
, "[%u] Unexpected callconv %u\n", i
, funcdesc
->callconv
);
1271 ok(funcdesc
->cParams
== func
[i
].num_args
, "[%u] Unexpected cParams %d (expected %d)\n",
1272 i
, funcdesc
->cParams
, func
[i
].num_args
);
1273 ok(funcdesc
->cParamsOpt
== 0, "[%u] Unexpected cParamsOpt %d\n", i
, funcdesc
->cParamsOpt
);
1274 ok(funcdesc
->cScodes
== 0, "[%u] Unexpected cScodes %d\n", i
, funcdesc
->cScodes
);
1275 ok(funcdesc
->wFuncFlags
== 0, "[%u] Unexpected wFuncFlags 0x%x\n", i
, funcdesc
->wFuncFlags
);
1276 ok(funcdesc
->elemdescFunc
.tdesc
.vt
== func
[i
].ret_type
,
1277 "[%u] Unexpected return type vt %d (expected %d)\n", i
, funcdesc
->elemdescFunc
.tdesc
.vt
, func
[i
].ret_type
);
1278 ok(funcdesc
->elemdescFunc
.paramdesc
.pparamdescex
== NULL
,
1279 "[%u] Unexpected return type pparamdescex %p\n", i
, funcdesc
->elemdescFunc
.paramdesc
.pparamdescex
);
1280 ok(funcdesc
->elemdescFunc
.paramdesc
.wParamFlags
== PARAMFLAG_NONE
,
1281 "[%u] Unexpected return type wParamFlags 0x%x\n", i
, funcdesc
->elemdescFunc
.paramdesc
.wParamFlags
);
1282 if (funcdesc
->lprgelemdescParam
)
1283 for (index
= 0; index
< funcdesc
->cParams
; index
++)
1285 ok(funcdesc
->lprgelemdescParam
[index
].tdesc
.vt
== VT_VARIANT
,
1286 "[%u] Unexpected parameter %u vt %d\n", i
, index
, funcdesc
->lprgelemdescParam
[index
].tdesc
.vt
);
1287 ok(funcdesc
->lprgelemdescParam
[index
].paramdesc
.pparamdescex
== NULL
,
1288 "[%u] Unexpected parameter %u pparamdescex %p\n", i
, index
, funcdesc
->lprgelemdescParam
[index
].paramdesc
.pparamdescex
);
1289 ok(funcdesc
->lprgelemdescParam
[index
].paramdesc
.wParamFlags
== PARAMFLAG_NONE
,
1290 "[%u] Unexpected parameter %u wParamFlags 0x%x\n", i
, index
, funcdesc
->lprgelemdescParam
[index
].paramdesc
.wParamFlags
);
1292 ITypeInfo_ReleaseFuncDesc(typeinfo
, funcdesc
);
1295 /* Test TypeComp Binds */
1296 hr
= ITypeInfo_QueryInterface(typeinfo
, &IID_ITypeComp
, (void**)&typecomp
);
1297 ok(hr
== S_OK
, "QueryInterface(IID_ITypeComp) failed: %08x\n", hr
);
1298 hr
= ITypeInfo_GetTypeComp(typeinfo
, NULL
);
1299 ok(hr
== E_INVALIDARG
, "GetTypeComp returned: %08x\n", hr
);
1300 hr
= ITypeInfo_GetTypeComp(typeinfo
, &typecomp2
);
1301 ok(hr
== S_OK
, "GetTypeComp failed: %08x\n", hr
);
1302 ok(typecomp
== typecomp2
, "QueryInterface(IID_ITypeComp) and GetTypeComp returned different TypeComps\n");
1303 ITypeComp_Release(typecomp2
);
1304 wcscpy(str
, L
"not_found");
1305 hr
= ITypeComp_Bind(typecomp
, NULL
, 0, 0, &typeinfo2
, &desckind
, &bindptr
);
1306 ok(hr
== E_INVALIDARG
, "Bind returned: %08x\n", hr
);
1307 hr
= ITypeComp_Bind(typecomp
, str
, 0, 0, NULL
, &desckind
, &bindptr
);
1308 ok(hr
== E_INVALIDARG
, "Bind returned: %08x\n", hr
);
1309 hr
= ITypeComp_Bind(typecomp
, str
, 0, 0, &typeinfo2
, NULL
, &bindptr
);
1310 ok(hr
== E_INVALIDARG
, "Bind returned: %08x\n", hr
);
1311 hr
= ITypeComp_Bind(typecomp
, str
, 0, 0, &typeinfo2
, &desckind
, NULL
);
1312 ok(hr
== E_INVALIDARG
, "Bind returned: %08x\n", hr
);
1314 hr
= ITypeComp_Bind(typecomp
, str
, 0, 0, &typeinfo2
, &desckind
, &bindptr
);
1315 ok(hr
== S_OK
, "Bind failed: %08x\n", hr
);
1316 ok(desckind
== DESCKIND_NONE
, "Unexpected desckind %u\n", desckind
);
1317 wcscpy(str
, L
"GLOBAL_VAR");
1318 hr
= ITypeComp_Bind(typecomp
, str
, 0, INVOKE_FUNC
, &typeinfo2
, &desckind
, &bindptr
);
1319 ok(hr
== TYPE_E_TYPEMISMATCH
, "Bind returned: %08x\n", hr
);
1320 ok(!lstrcmpW(str
, L
"GLOBAL_VAR"), "Unexpected string %s\n", wine_dbgstr_w(str
));
1322 hr
= ITypeComp_Bind(typecomp
, str
, 0, 0, &typeinfo2
, &desckind
, &bindptr
);
1323 ok(hr
== S_OK
, "Bind failed: %08x\n", hr
);
1324 ok(desckind
== DESCKIND_NONE
, "Unexpected desckind %u\n", desckind
);
1325 wcscpy(str
, L
"addRef");
1326 hr
= ITypeComp_Bind(typecomp
, str
, 0, 0, &typeinfo2
, &desckind
, &bindptr
);
1327 ok(hr
== S_OK
, "Bind failed: %08x\n", hr
);
1328 ok(desckind
== DESCKIND_FUNCDESC
, "Unexpected desckind %u\n", desckind
);
1329 ok(!lstrcmpW(str
, L
"addRef"), "Unexpected string %s\n", wine_dbgstr_w(str
));
1330 ITypeInfo_ReleaseFuncDesc(typeinfo2
, bindptr
.lpfuncdesc
);
1331 ITypeInfo_Release(typeinfo2
);
1332 for (i
= 0; i
< ARRAY_SIZE(var
); i
++)
1334 wcscpy(str
, var
[i
].name
);
1335 hr
= ITypeComp_Bind(typecomp
, str
, 0, INVOKE_PROPERTYGET
, &typeinfo2
, &desckind
, &bindptr
);
1336 ok(hr
== S_OK
, "Bind failed: %08x\n", hr
);
1337 ok(desckind
== DESCKIND_VARDESC
, "Unexpected desckind %u\n", desckind
);
1338 ITypeInfo_ReleaseVarDesc(typeinfo2
, bindptr
.lpvardesc
);
1339 ITypeInfo_Release(typeinfo2
);
1341 for (i
= 0; i
< ARRAY_SIZE(func
); i
++)
1343 wcscpy(str
, func
[i
].name
);
1344 hr
= ITypeComp_Bind(typecomp
, str
, 0, INVOKE_FUNC
, &typeinfo2
, &desckind
, &bindptr
);
1345 ok(hr
== S_OK
, "Bind failed: %08x\n", hr
);
1346 ok(desckind
== DESCKIND_FUNCDESC
, "Unexpected desckind %u\n", desckind
);
1347 ITypeInfo_ReleaseFuncDesc(typeinfo2
, bindptr
.lpfuncdesc
);
1348 ITypeInfo_Release(typeinfo2
);
1350 wcscpy(str
, L
"VBScriptTypeInfo");
1351 hr
= ITypeComp_BindType(typecomp
, NULL
, 0, &typeinfo2
, &typecomp2
);
1352 ok(hr
== E_INVALIDARG
, "BindType returned: %08x\n", hr
);
1353 hr
= ITypeComp_BindType(typecomp
, str
, 0, NULL
, &typecomp2
);
1354 ok(hr
== E_INVALIDARG
, "BindType returned: %08x\n", hr
);
1355 hr
= ITypeComp_BindType(typecomp
, str
, 0, &typeinfo2
, NULL
);
1356 ok(hr
== E_INVALIDARG
, "BindType returned: %08x\n", hr
);
1357 hr
= ITypeComp_BindType(typecomp
, str
, 0, &typeinfo2
, &typecomp2
);
1358 ok(hr
== S_OK
, "BindType failed: %08x\n", hr
);
1359 ok(!typeinfo2
, "Unexpected TypeInfo %p (expected null)\n", typeinfo2
);
1360 ok(!typecomp2
, "Unexpected TypeComp %p (expected null)\n", typecomp2
);
1362 hr
= ITypeComp_BindType(typecomp
, str
, 0, &typeinfo2
, &typecomp2
);
1363 ok(hr
== S_OK
, "BindType failed: %08x\n", hr
);
1364 ok(!typeinfo2
, "Unexpected TypeInfo %p (expected null)\n", typeinfo2
);
1365 ok(!typecomp2
, "Unexpected TypeComp %p (expected null)\n", typecomp2
);
1366 wcscpy(str
, L
"IDispatch");
1367 hr
= ITypeComp_BindType(typecomp
, str
, 0, &typeinfo2
, &typecomp2
);
1368 ok(hr
== S_OK
, "BindType failed: %08x\n", hr
);
1369 ok(!typeinfo2
, "Unexpected TypeInfo %p (expected null)\n", typeinfo2
);
1370 ok(!typecomp2
, "Unexpected TypeComp %p (expected null)\n", typecomp2
);
1372 ITypeComp_Release(typecomp
);
1374 /* Updating the script won't update the typeinfo obtained before,
1375 but it will be reflected in any typeinfo obtained afterwards. */
1376 parse_script(parser
,
1377 "dim new_var\nnew_var = 10\n"
1378 "sub new_sub\nend sub\n"
1380 /* Replace the function foobar with more args */
1381 "function foobar(x, y, z)\nend function\n");
1383 hr
= IDispatchEx_GetTypeInfo(script_disp
, 0, LOCALE_USER_DEFAULT
, &typeinfo2
);
1384 ok(hr
== S_OK
, "GetTypeInfo failed: %08x\n", hr
);
1385 hr
= ITypeInfo_GetTypeAttr(typeinfo
, &attr
);
1386 ok(hr
== S_OK
, "GetTypeAttr failed: %08x\n", hr
);
1387 ok(attr
->cFuncs
== ARRAY_SIZE(func
), "Unexpected cFuncs %u\n", attr
->cFuncs
);
1388 ok(attr
->cVars
== ARRAY_SIZE(var
), "Unexpected cVars %u\n", attr
->cVars
);
1389 ITypeInfo_ReleaseTypeAttr(typeinfo
, attr
);
1390 hr
= ITypeInfo_GetTypeAttr(typeinfo2
, &attr
);
1391 ok(hr
== S_OK
, "GetTypeAttr failed: %08x\n", hr
);
1392 ok(attr
->cFuncs
== ARRAY_SIZE(func
) + 1, "Unexpected cFuncs %u\n", attr
->cFuncs
);
1393 ok(attr
->cVars
== ARRAY_SIZE(var
) + 1, "Unexpected cVars %u\n", attr
->cVars
);
1394 ITypeInfo_ReleaseTypeAttr(typeinfo2
, attr
);
1395 hr
= ITypeInfo_GetVarDesc(typeinfo2
, ARRAY_SIZE(var
), &vardesc
);
1396 ok(hr
== S_OK
, "GetVarDesc failed: %08x\n", hr
);
1397 hr
= ITypeInfo_GetDocumentation(typeinfo2
, vardesc
->memid
, &bstr
, &bstrs
[0], NULL
, NULL
);
1398 ok(hr
== S_OK
, "GetDocumentation failed: %08x\n", hr
);
1399 ok(!lstrcmpW(bstr
, L
"new_var"), "Unexpected variable name %s\n", wine_dbgstr_w(bstr
));
1400 ok(!bstrs
[0], "Unexpected doc string %s\n", wine_dbgstr_w(bstrs
[0]));
1401 ITypeInfo_ReleaseVarDesc(typeinfo2
, vardesc
);
1402 SysFreeString(bstr
);
1403 hr
= ITypeInfo_GetFuncDesc(typeinfo
, 0, &funcdesc
);
1404 ok(hr
== S_OK
, "GetFuncDesc failed: %08x\n", hr
);
1405 ok(funcdesc
->cParams
== 0, "Unexpected cParams %d\n", funcdesc
->cParams
);
1406 ITypeInfo_ReleaseFuncDesc(typeinfo
, funcdesc
);
1407 hr
= ITypeInfo_GetFuncDesc(typeinfo2
, 0, &funcdesc
);
1408 ok(hr
== S_OK
, "GetFuncDesc failed: %08x\n", hr
);
1409 ok(funcdesc
->cParams
== 3, "Unexpected cParams %d\n", funcdesc
->cParams
);
1410 ITypeInfo_ReleaseFuncDesc(typeinfo2
, funcdesc
);
1411 ITypeInfo_Release(typeinfo2
);
1413 ITypeInfo_Release(typeinfo
);
1414 IDispatchEx_Release(script_disp
);
1415 IActiveScriptParse_Release(parser
);
1417 SET_EXPECT(OnStateChange_DISCONNECTED
);
1418 SET_EXPECT(OnStateChange_INITIALIZED
);
1419 SET_EXPECT(OnStateChange_CLOSED
);
1420 hr
= IActiveScript_Close(vbscript
);
1421 ok(hr
== S_OK
, "Close failed: %08x\n", hr
);
1422 CHECK_CALLED(OnStateChange_DISCONNECTED
);
1423 CHECK_CALLED(OnStateChange_INITIALIZED
);
1424 CHECK_CALLED(OnStateChange_CLOSED
);
1426 IActiveScript_Release(vbscript
);
1429 static void test_vbscript(void)
1431 IActiveScriptParseProcedure2
*parse_proc
;
1432 IActiveScriptParse
*parser
;
1433 IActiveScript
*vbscript
;
1437 vbscript
= create_vbscript();
1439 hres
= IActiveScript_QueryInterface(vbscript
, &IID_IActiveScriptParse
, (void**)&parser
);
1440 ok(hres
== S_OK
, "Could not get IActiveScriptParse iface: %08x\n", hres
);
1442 test_state(vbscript
, SCRIPTSTATE_UNINITIALIZED
);
1443 test_safety(vbscript
);
1444 test_no_script_dispatch(vbscript
);
1446 SET_EXPECT(GetLCID
);
1447 hres
= IActiveScript_SetScriptSite(vbscript
, &ActiveScriptSite
);
1448 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1449 CHECK_CALLED(GetLCID
);
1451 test_state(vbscript
, SCRIPTSTATE_UNINITIALIZED
);
1453 SET_EXPECT(OnStateChange_INITIALIZED
);
1454 hres
= IActiveScriptParse_InitNew(parser
);
1455 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
1456 CHECK_CALLED(OnStateChange_INITIALIZED
);
1458 test_state(vbscript
, SCRIPTSTATE_INITIALIZED
);
1460 hres
= IActiveScriptParse_InitNew(parser
);
1461 ok(hres
== E_UNEXPECTED
, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres
);
1463 SET_EXPECT(OnStateChange_CONNECTED
);
1464 hres
= IActiveScript_SetScriptState(vbscript
, SCRIPTSTATE_CONNECTED
);
1465 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres
);
1466 CHECK_CALLED(OnStateChange_CONNECTED
);
1468 test_state(vbscript
, SCRIPTSTATE_CONNECTED
);
1470 SET_EXPECT(OnStateChange_DISCONNECTED
);
1471 SET_EXPECT(OnStateChange_INITIALIZED
);
1472 SET_EXPECT(OnStateChange_CLOSED
);
1473 hres
= IActiveScript_Close(vbscript
);
1474 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
1475 CHECK_CALLED(OnStateChange_DISCONNECTED
);
1476 CHECK_CALLED(OnStateChange_INITIALIZED
);
1477 CHECK_CALLED(OnStateChange_CLOSED
);
1479 test_state(vbscript
, SCRIPTSTATE_CLOSED
);
1480 test_no_script_dispatch(vbscript
);
1482 IActiveScriptParse_Release(parser
);
1484 hres
= IActiveScript_QueryInterface(vbscript
, &IID_IActiveScriptParseProcedure
, (void**)&parse_proc
);
1485 ok(hres
== E_NOINTERFACE
, "Got IActiveScriptParseProcedure interface, expected E_NOTIMPL\n");
1487 hres
= IActiveScript_QueryInterface(vbscript
, &IID_IActiveScriptParseProcedure2
, (void**)&parse_proc
);
1488 ok(hres
== S_OK
, "Could not get IActiveScriptParseProcedure2 interface\n");
1489 IActiveScriptParseProcedure2_Release(parse_proc
);
1491 ref
= IActiveScript_Release(vbscript
);
1492 ok(!ref
, "ref = %d\n", ref
);
1495 static void test_vbscript_uninitializing(void)
1497 IActiveScriptParse
*parse
;
1498 IActiveScript
*script
;
1499 IDispatchEx
*dispex
;
1503 script
= create_vbscript();
1505 hres
= IActiveScript_QueryInterface(script
, &IID_IActiveScriptParse
, (void**)&parse
);
1506 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
1508 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
1510 hres
= IActiveScriptParse_InitNew(parse
);
1511 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
1513 test_no_script_dispatch(script
);
1515 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_STARTED
);
1516 ok(hres
== E_UNEXPECTED
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
1517 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_INITIALIZED
);
1518 ok(hres
== E_UNEXPECTED
, "SetScriptState(SCRIPTSTATE_INITIALIZED) failed: %08x\n", hres
);
1520 SET_EXPECT(GetLCID
);
1521 SET_EXPECT(OnStateChange_INITIALIZED
);
1522 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
1523 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1524 CHECK_CALLED(GetLCID
);
1525 CHECK_CALLED(OnStateChange_INITIALIZED
);
1527 test_state(script
, SCRIPTSTATE_INITIALIZED
);
1529 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"Function f\nEnd Function\n", NULL
, NULL
, NULL
, 0, 1, 0x42, NULL
, NULL
);
1530 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1532 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
1533 ok(hres
== E_UNEXPECTED
, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres
);
1535 SET_EXPECT(OnStateChange_UNINITIALIZED
);
1536 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
1537 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
1538 CHECK_CALLED(OnStateChange_UNINITIALIZED
);
1540 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
1542 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
1543 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
1545 SET_EXPECT(GetLCID
);
1546 SET_EXPECT(OnStateChange_INITIALIZED
);
1547 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
1548 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1549 CHECK_CALLED(GetLCID
);
1550 CHECK_CALLED(OnStateChange_INITIALIZED
);
1552 SET_EXPECT(OnStateChange_CONNECTED
);
1553 SET_EXPECT(OnEnterScript
);
1554 SET_EXPECT(OnLeaveScript
);
1555 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_CONNECTED
);
1556 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres
);
1557 CHECK_CALLED(OnStateChange_CONNECTED
);
1558 CHECK_CALLED(OnEnterScript
);
1559 CHECK_CALLED(OnLeaveScript
);
1561 test_state(script
, SCRIPTSTATE_CONNECTED
);
1563 dispex
= get_script_dispatch(script
, NULL
);
1564 ok(dispex
!= NULL
, "dispex == NULL\n");
1566 IDispatchEx_Release(dispex
);
1568 SET_EXPECT(OnStateChange_DISCONNECTED
);
1569 SET_EXPECT(OnStateChange_INITIALIZED
);
1570 SET_EXPECT(OnStateChange_UNINITIALIZED
);
1571 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
1572 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
1573 CHECK_CALLED(OnStateChange_DISCONNECTED
);
1574 CHECK_CALLED(OnStateChange_INITIALIZED
);
1575 CHECK_CALLED(OnStateChange_UNINITIALIZED
);
1577 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
1579 hres
= IActiveScript_Close(script
);
1580 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
1582 test_state(script
, SCRIPTSTATE_CLOSED
);
1584 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
1585 ok(hres
== E_UNEXPECTED
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x, expected E_UNEXPECTED\n", hres
);
1587 test_state(script
, SCRIPTSTATE_CLOSED
);
1589 SET_EXPECT(GetLCID
);
1590 SET_EXPECT(OnStateChange_INITIALIZED
);
1591 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
1592 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1593 CHECK_CALLED(GetLCID
);
1594 CHECK_CALLED(OnStateChange_INITIALIZED
);
1596 test_state(script
, SCRIPTSTATE_INITIALIZED
);
1598 SET_EXPECT(OnStateChange_STARTED
);
1599 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_STARTED
);
1600 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
1601 CHECK_CALLED(OnStateChange_STARTED
);
1603 SET_EXPECT(OnStateChange_INITIALIZED
);
1604 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_INITIALIZED
);
1605 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
1606 CHECK_CALLED(OnStateChange_INITIALIZED
);
1608 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_INITIALIZED
);
1609 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
1611 SET_EXPECT(OnStateChange_CLOSED
);
1612 hres
= IActiveScript_Close(script
);
1613 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
1614 CHECK_CALLED(OnStateChange_CLOSED
);
1616 test_state(script
, SCRIPTSTATE_CLOSED
);
1618 SET_EXPECT(GetLCID
);
1619 SET_EXPECT(OnStateChange_INITIALIZED
);
1620 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
1621 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1622 CHECK_CALLED(GetLCID
);
1623 CHECK_CALLED(OnStateChange_INITIALIZED
);
1625 test_state(script
, SCRIPTSTATE_INITIALIZED
);
1627 SET_EXPECT(OnStateChange_CLOSED
);
1628 hres
= IActiveScript_Close(script
);
1629 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
1630 CHECK_CALLED(OnStateChange_CLOSED
);
1632 test_state(script
, SCRIPTSTATE_CLOSED
);
1634 hres
= IActiveScriptParse_InitNew(parse
);
1635 ok(hres
== E_UNEXPECTED
, "InitNew failed: %08x\n", hres
);
1637 /* initialize again and use SetScriptState(SCRIPTSTATE_CLOSED) to uninitialize it */
1639 SET_EXPECT(GetLCID
);
1640 SET_EXPECT(OnStateChange_INITIALIZED
);
1641 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
1642 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1643 CHECK_CALLED(GetLCID
);
1644 CHECK_CALLED(OnStateChange_INITIALIZED
);
1646 SET_EXPECT(OnStateChange_CONNECTED
);
1647 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_CONNECTED
);
1648 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres
);
1649 CHECK_CALLED(OnStateChange_CONNECTED
);
1651 SET_EXPECT(OnStateChange_DISCONNECTED
);
1652 SET_EXPECT(OnStateChange_INITIALIZED
);
1653 SET_EXPECT(OnStateChange_CLOSED
);
1654 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_CLOSED
);
1655 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CLOSED) failed: %08x\n", hres
);
1656 CHECK_CALLED(OnStateChange_DISCONNECTED
);
1657 CHECK_CALLED(OnStateChange_INITIALIZED
);
1658 CHECK_CALLED(OnStateChange_CLOSED
);
1660 test_state(script
, SCRIPTSTATE_CLOSED
);
1662 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_CLOSED
);
1663 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CLOSED) failed: %08x\n", hres
);
1665 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_INITIALIZED
);
1666 ok(hres
== E_UNEXPECTED
, "SetScriptState(SCRIPTSTATE_INITIALIZED) failed: %08x\n", hres
);
1668 hres
= IActiveScript_Close(script
);
1669 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
1671 SET_EXPECT(GetLCID
);
1672 SET_EXPECT(OnStateChange_INITIALIZED
);
1673 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
1674 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1675 CHECK_CALLED(GetLCID
);
1676 CHECK_CALLED(OnStateChange_INITIALIZED
);
1678 SET_EXPECT(OnStateChange_CONNECTED
);
1679 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_CONNECTED
);
1680 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres
);
1681 CHECK_CALLED(OnStateChange_CONNECTED
);
1683 SET_EXPECT(OnStateChange_DISCONNECTED
);
1684 SET_EXPECT(OnStateChange_INITIALIZED
);
1685 SET_EXPECT(OnStateChange_CLOSED
);
1686 hres
= IActiveScript_Close(script
);
1687 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
1688 CHECK_CALLED(OnStateChange_DISCONNECTED
);
1689 CHECK_CALLED(OnStateChange_INITIALIZED
);
1690 CHECK_CALLED(OnStateChange_CLOSED
);
1692 test_state(script
, SCRIPTSTATE_CLOSED
);
1694 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_CLOSED
);
1695 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CLOSED) failed: %08x\n", hres
);
1697 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_INITIALIZED
);
1698 ok(hres
== E_UNEXPECTED
, "SetScriptState(SCRIPTSTATE_INITIALIZED) failed: %08x\n", hres
);
1700 IActiveScriptParse_Release(parse
);
1702 ref
= IActiveScript_Release(script
);
1703 ok(!ref
, "ref = %d\n", ref
);
1705 script
= create_vbscript();
1707 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_CLOSED
);
1708 ok(hres
== E_UNEXPECTED
, "SetScriptState(SCRIPTSTATE_CLOSED) failed: %08x\n", hres
);
1710 ref
= IActiveScript_Release(script
);
1711 ok(!ref
, "ref = %d\n", ref
);
1714 static void test_vbscript_release(void)
1716 IActiveScriptParse
*parser
;
1717 IActiveScript
*vbscript
;
1721 vbscript
= create_vbscript();
1723 hres
= IActiveScript_QueryInterface(vbscript
, &IID_IActiveScriptParse
, (void**)&parser
);
1724 ok(hres
== S_OK
, "Could not get IActiveScriptParse iface: %08x\n", hres
);
1726 test_state(vbscript
, SCRIPTSTATE_UNINITIALIZED
);
1727 test_safety(vbscript
);
1729 SET_EXPECT(GetLCID
);
1730 hres
= IActiveScript_SetScriptSite(vbscript
, &ActiveScriptSite
);
1731 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1732 CHECK_CALLED(GetLCID
);
1734 test_state(vbscript
, SCRIPTSTATE_UNINITIALIZED
);
1736 SET_EXPECT(OnStateChange_INITIALIZED
);
1737 hres
= IActiveScriptParse_InitNew(parser
);
1738 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
1739 CHECK_CALLED(OnStateChange_INITIALIZED
);
1741 test_state(vbscript
, SCRIPTSTATE_INITIALIZED
);
1743 SET_EXPECT(OnStateChange_CONNECTED
);
1744 hres
= IActiveScript_SetScriptState(vbscript
, SCRIPTSTATE_CONNECTED
);
1745 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres
);
1746 CHECK_CALLED(OnStateChange_CONNECTED
);
1748 test_state(vbscript
, SCRIPTSTATE_CONNECTED
);
1750 IActiveScriptParse_Release(parser
);
1752 SET_EXPECT(OnStateChange_DISCONNECTED
);
1753 SET_EXPECT(OnStateChange_INITIALIZED
);
1754 SET_EXPECT(OnStateChange_CLOSED
);
1755 ref
= IActiveScript_Release(vbscript
);
1756 ok(!ref
, "ref = %d\n", ref
);
1757 CHECK_CALLED(OnStateChange_DISCONNECTED
);
1758 CHECK_CALLED(OnStateChange_INITIALIZED
);
1759 CHECK_CALLED(OnStateChange_CLOSED
);
1762 static void test_vbscript_simplecreate(void)
1764 IActiveScript
*script
;
1768 script
= create_vbscript();
1770 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
1771 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
1773 ref
= IActiveScript_Release(script
);
1774 ok(!ref
, "ref = %d\n", ref
);
1777 static void test_vbscript_initializing(void)
1779 IActiveScriptParse
*parse
;
1780 IActiveScript
*script
;
1784 script
= create_vbscript();
1786 hres
= IActiveScript_QueryInterface(script
, &IID_IActiveScriptParse
, (void**)&parse
);
1787 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
1789 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
1791 SET_EXPECT(GetLCID
);
1792 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
1793 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1794 CHECK_CALLED(GetLCID
);
1796 SET_EXPECT(OnStateChange_INITIALIZED
);
1797 hres
= IActiveScriptParse_InitNew(parse
);
1798 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
1799 CHECK_CALLED(OnStateChange_INITIALIZED
);
1801 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
1802 ok(hres
== E_UNEXPECTED
, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres
);
1804 SET_EXPECT(OnStateChange_CLOSED
);
1805 hres
= IActiveScript_Close(script
);
1806 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
1807 CHECK_CALLED(OnStateChange_CLOSED
);
1809 test_state(script
, SCRIPTSTATE_CLOSED
);
1811 IActiveScriptParse_Release(parse
);
1813 ref
= IActiveScript_Release(script
);
1814 ok(!ref
, "ref = %d\n", ref
);
1817 static void test_named_items(void)
1819 static const WCHAR
*global_idents
[] =
1824 L
"testExplicitVar_global",
1827 static const WCHAR
*global_code_test
[] =
1829 L
"testSub_global\n",
1830 L
"if testExplicitVar_global <> 10 then err.raise 500\n",
1831 L
"if testVar_global <> 5 then err.raise 500\n",
1832 L
"set x = new testClass_global\n"
1834 static const WCHAR
*context_idents
[] =
1840 static const WCHAR
*context_code_test
[] =
1843 L
"if testExplicitVar <> 42 then err.raise 500\n",
1844 L
"if testVar <> 99 then err.raise 500\n",
1845 L
"set x = new testClass\n"
1847 IDispatchEx
*script_disp
, *script_disp2
;
1848 IActiveScriptParse
*parse
;
1849 IActiveScript
*script
;
1858 script
= create_vbscript();
1860 hres
= IActiveScript_QueryInterface(script
, &IID_IActiveScriptParse
, (void**)&parse
);
1861 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
1863 test_state(script
, SCRIPTSTATE_UNINITIALIZED
);
1865 hres
= IActiveScript_AddNamedItem(script
, L
"visibleItem", SCRIPTITEM_ISVISIBLE
);
1866 ok(hres
== E_UNEXPECTED
, "AddNamedItem returned: %08x\n", hres
);
1867 hres
= IActiveScript_AddNamedItem(script
, L
"globalItem", SCRIPTITEM_GLOBALMEMBERS
);
1868 ok(hres
== E_UNEXPECTED
, "AddNamedItem returned: %08x\n", hres
);
1869 hres
= IActiveScript_AddNamedItem(script
, L
"codeOnlyItem", SCRIPTITEM_CODEONLY
);
1870 ok(hres
== E_UNEXPECTED
, "AddNamedItem returned: %08x\n", hres
);
1871 hres
= IActiveScript_AddNamedItem(script
, L
"persistent", SCRIPTITEM_ISPERSISTENT
| SCRIPTITEM_CODEONLY
);
1872 ok(hres
== E_UNEXPECTED
, "AddNamedItem returned: %08x\n", hres
);
1874 SET_EXPECT(GetLCID
);
1875 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
1876 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
1877 CHECK_CALLED(GetLCID
);
1879 SET_EXPECT(GetItemInfo_global
);
1880 hres
= IActiveScript_AddNamedItem(script
, L
"globalItem", SCRIPTITEM_GLOBALMEMBERS
);
1881 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
1882 CHECK_CALLED(GetItemInfo_global
);
1884 hres
= IActiveScript_AddNamedItem(script
, L
"visibleItem", SCRIPTITEM_ISVISIBLE
);
1885 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
1886 hres
= IActiveScript_AddNamedItem(script
, L
"visibleCodeItem", SCRIPTITEM_ISVISIBLE
| SCRIPTITEM_CODEONLY
);
1887 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
1888 hres
= IActiveScript_AddNamedItem(script
, L
"codeOnlyItem", SCRIPTITEM_CODEONLY
);
1889 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
1890 hres
= IActiveScript_AddNamedItem(script
, L
"persistent", SCRIPTITEM_ISPERSISTENT
| SCRIPTITEM_CODEONLY
);
1891 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
1893 ok(global_named_item_ref
> 0, "global_named_item_ref = %u\n", global_named_item_ref
);
1894 ok(visible_named_item_ref
== 0, "visible_named_item_ref = %u\n", visible_named_item_ref
);
1895 ok(visible_code_named_item_ref
== 0, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref
);
1896 ok(persistent_named_item_ref
== 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref
);
1898 hres
= IActiveScript_GetScriptDispatch(script
, L
"noContext", &disp
);
1899 ok(hres
== E_INVALIDARG
, "GetScriptDispatch returned: %08x\n", hres
);
1901 SET_EXPECT(GetItemInfo_global_code
);
1902 hres
= IActiveScript_AddNamedItem(script
, L
"globalCodeItem", SCRIPTITEM_GLOBALMEMBERS
| SCRIPTITEM_CODEONLY
);
1903 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
1904 CHECK_CALLED(GetItemInfo_global_code
);
1906 script_disp
= get_script_dispatch(script
, NULL
);
1907 script_disp2
= get_script_dispatch(script
, L
"globalItem");
1908 ok(script_disp
== script_disp2
, "get_script_dispatch returned different dispatch objects.\n");
1909 IDispatchEx_Release(script_disp2
);
1910 script_disp2
= get_script_dispatch(script
, L
"globalCodeItem");
1911 ok(script_disp
== script_disp2
, "get_script_dispatch returned different dispatch objects.\n");
1912 IDispatchEx_Release(script_disp2
);
1913 script_disp2
= get_script_dispatch(script
, L
"codeONLYitem");
1914 ok(script_disp
!= script_disp2
, "get_script_dispatch returned same dispatch objects.\n");
1916 SET_EXPECT(OnStateChange_INITIALIZED
);
1917 hres
= IActiveScriptParse_InitNew(parse
);
1918 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
1919 CHECK_CALLED(OnStateChange_INITIALIZED
);
1921 SET_EXPECT(OnStateChange_CONNECTED
);
1922 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_CONNECTED
);
1923 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres
);
1924 CHECK_CALLED(OnStateChange_CONNECTED
);
1926 SET_EXPECT(testCall
);
1927 parse_script(parse
, "testCall\n");
1928 CHECK_CALLED(testCall
);
1930 SET_EXPECT(GetItemInfo_visible
);
1931 SET_EXPECT(testCall
);
1932 parse_script(parse
, "visibleItem.testCall\n");
1933 CHECK_CALLED(GetItemInfo_visible
);
1934 CHECK_CALLED(testCall
);
1936 SET_EXPECT(OnEnterScript
);
1937 SET_EXPECT(OnLeaveScript
);
1938 SET_EXPECT(testCall
);
1939 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"testCall\n", L
"visibleCodeItem", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
1940 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1941 CHECK_CALLED(OnEnterScript
);
1942 CHECK_CALLED(OnLeaveScript
);
1943 CHECK_CALLED(testCall
);
1945 SET_EXPECT(OnEnterScript
);
1946 SET_EXPECT(GetIDsOfNames
);
1947 SET_EXPECT(OnScriptError
);
1948 SET_EXPECT(OnLeaveScript
);
1949 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"codeOnlyItem\n", L
"codeOnlyItem", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
1950 ok(FAILED(hres
), "ParseScriptText returned: %08x\n", hres
);
1951 CHECK_CALLED(OnEnterScript
);
1952 CHECK_CALLED(GetIDsOfNames
);
1953 CHECK_CALLED(OnScriptError
);
1954 CHECK_CALLED(OnLeaveScript
);
1956 hres
= IActiveScript_GetScriptDispatch(script
, L
"visibleCodeItem", &disp
);
1957 ok(hres
== S_OK
, "GetScriptDispatch returned: %08x\n", hres
);
1958 SET_EXPECT(OnEnterScript
);
1959 SET_EXPECT(OnLeaveScript
);
1960 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"me", L
"visibleCodeItem", NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
1961 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1962 ok(V_VT(&var
) == VT_DISPATCH
&& V_DISPATCH(&var
) == disp
,
1963 "Unexpected 'me': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var
), V_DISPATCH(&var
));
1965 CHECK_CALLED(OnEnterScript
);
1966 CHECK_CALLED(OnLeaveScript
);
1967 IDispatch_Release(disp
);
1969 SET_EXPECT(GetItemInfo_visible_code
);
1970 SET_EXPECT(testCall
);
1971 parse_script(parse
, "visibleCodeItem.testCall\n");
1972 CHECK_CALLED(GetItemInfo_visible_code
);
1973 CHECK_CALLED(testCall
);
1975 ok(global_named_item_ref
> 0, "global_named_item_ref = %u\n", global_named_item_ref
);
1976 ok(visible_named_item_ref
== 1, "visible_named_item_ref = %u\n", visible_named_item_ref
);
1977 ok(visible_code_named_item_ref
== 1, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref
);
1978 ok(persistent_named_item_ref
== 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref
);
1980 SET_EXPECT(testCall
);
1981 parse_script(parse
, "visibleItem.testCall\n");
1982 CHECK_CALLED(testCall
);
1984 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"sub testSub\nend sub\n", L
"noContext", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
1985 ok(hres
== E_INVALIDARG
, "ParseScriptText returned: %08x\n", hres
);
1986 SET_EXPECT(OnEnterScript
);
1987 SET_EXPECT(GetIDsOfNames
);
1988 SET_EXPECT(OnLeaveScript
);
1989 hres
= IActiveScriptParse_ParseScriptText(parse
, L
""
1990 "dim global_me\nglobal_me = 0\n"
1991 "dim globalCode_me\nglobalCode_me = 0\n"
1992 "sub testSub_global\nend sub\n"
1993 "dim testExplicitVar_global\ntestExplicitVar_global = 10\n"
1994 "testVar_global = 10\n"
1995 "class testClass_global\nend class\n",
1996 NULL
, NULL
, NULL
, 0, 0, SCRIPTTEXT_ISPERSISTENT
, NULL
, NULL
);
1997 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
1998 CHECK_CALLED(OnEnterScript
);
1999 CHECK_CALLED(GetIDsOfNames
);
2000 CHECK_CALLED(OnLeaveScript
);
2001 SET_EXPECT(OnEnterScript
);
2002 SET_EXPECT(OnLeaveScript
);
2003 hres
= IActiveScriptParse_ParseScriptText(parse
, L
""
2004 "sub testSub\nend sub\n"
2005 "dim testExplicitVar\ntestExplicitVar = 42\n"
2006 "class testClass\nend class\n",
2007 L
"codeOnlyItem", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2008 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2009 CHECK_CALLED(OnEnterScript
);
2010 CHECK_CALLED(OnLeaveScript
);
2011 SET_EXPECT(OnEnterScript
);
2012 SET_EXPECT(GetIDsOfNames
);
2013 SET_EXPECT(OnLeaveScript
);
2014 hres
= IActiveScriptParse_ParseScriptText(parse
, L
""
2016 "testVar_global = 5\n",
2017 L
"CodeOnlyITEM", NULL
, NULL
, 0, 0, SCRIPTTEXT_ISPERSISTENT
, NULL
, NULL
);
2018 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2019 CHECK_CALLED(OnEnterScript
);
2020 CHECK_CALLED(GetIDsOfNames
);
2021 CHECK_CALLED(OnLeaveScript
);
2023 SET_EXPECT(OnEnterScript
);
2024 SET_EXPECT(GetItemInfo_visible
);
2025 SET_EXPECT(GetIDsOfNames_visible
);
2026 SET_EXPECT(OnLeaveScript
);
2027 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"dim abc\n", L
"visibleItem", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2028 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2029 CHECK_CALLED(OnEnterScript
);
2030 todo_wine
CHECK_CALLED(GetItemInfo_visible
);
2031 todo_wine
CHECK_CALLED(GetIDsOfNames_visible
);
2032 CHECK_CALLED(OnLeaveScript
);
2033 SET_EXPECT(OnEnterScript
);
2034 SET_EXPECT(OnLeaveScript
);
2035 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"abc = 5\n", L
"visibleItem", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2036 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2037 CHECK_CALLED(OnEnterScript
);
2038 CHECK_CALLED(OnLeaveScript
);
2039 SET_EXPECT(OnEnterScript
);
2040 SET_EXPECT(GetIDsOfNames_visible
);
2041 SET_EXPECT(OnLeaveScript
);
2042 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"testVar_global = 5\n", L
"visibleItem", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2043 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2044 CHECK_CALLED(OnEnterScript
);
2045 CHECK_CALLED(GetIDsOfNames_visible
);
2046 CHECK_CALLED(OnLeaveScript
);
2048 SET_EXPECT(OnEnterScript
);
2049 SET_EXPECT(OnLeaveScript
);
2050 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"dim abc\ntestVar_global = 5\n", L
"visibleCodeItem", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2051 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2052 CHECK_CALLED(OnEnterScript
);
2053 CHECK_CALLED(OnLeaveScript
);
2055 SET_EXPECT(OnEnterScript
);
2056 SET_EXPECT(OnLeaveScript
);
2057 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"set global_me = me\n", L
"globalItem", NULL
, NULL
, 0, 0, SCRIPTTEXT_ISPERSISTENT
, NULL
, NULL
);
2058 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2059 CHECK_CALLED(OnEnterScript
);
2060 CHECK_CALLED(OnLeaveScript
);
2061 SET_EXPECT(OnEnterScript
);
2062 SET_EXPECT(OnLeaveScript
);
2063 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"set globalCode_me = me\n", L
"globalCodeItem", NULL
, NULL
, 0, 0, SCRIPTTEXT_ISPERSISTENT
, NULL
, NULL
);
2064 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2065 CHECK_CALLED(OnEnterScript
);
2066 CHECK_CALLED(OnLeaveScript
);
2068 for (i
= 0; i
< ARRAY_SIZE(global_idents
); i
++)
2070 bstr
= SysAllocString(global_idents
[i
]);
2072 hres
= IDispatchEx_GetDispID(script_disp
, bstr
, 0, &id
);
2073 ok(hres
== S_OK
, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(global_idents
[i
]), hres
);
2074 ok(id
!= -1, "[%s] id = -1\n", wine_dbgstr_w(global_idents
[i
]));
2076 hres
= IDispatchEx_GetDispID(script_disp2
, bstr
, 0, &id
);
2077 ok(hres
== DISP_E_UNKNOWNNAME
, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(global_idents
[i
]), hres
);
2078 ok(id
== -1, "[%s] id = %d, expected -1\n", wine_dbgstr_w(global_idents
[i
]), id
);
2079 SysFreeString(bstr
);
2081 for (i
= 0; i
< ARRAY_SIZE(context_idents
); i
++)
2083 bstr
= SysAllocString(context_idents
[i
]);
2085 hres
= IDispatchEx_GetDispID(script_disp
, bstr
, 0, &id
);
2086 ok(hres
== DISP_E_UNKNOWNNAME
, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(context_idents
[i
]), hres
);
2087 ok(id
== -1, "[%s] id = %d, expected -1\n", wine_dbgstr_w(context_idents
[i
]), id
);
2089 hres
= IDispatchEx_GetDispID(script_disp2
, bstr
, 0, &id
);
2090 ok(hres
== S_OK
, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(context_idents
[i
]), hres
);
2091 ok(id
!= -1, "[%s] id = -1\n", wine_dbgstr_w(context_idents
[i
]));
2092 SysFreeString(bstr
);
2095 for (i
= 0; i
< ARRAY_SIZE(global_code_test
); i
++)
2097 SET_EXPECT(OnEnterScript
);
2098 SET_EXPECT(OnLeaveScript
);
2099 hres
= IActiveScriptParse_ParseScriptText(parse
, global_code_test
[i
], NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2100 ok(hres
== S_OK
, "ParseScriptText(%s) failed: %08x\n", wine_dbgstr_w(global_code_test
[i
]), hres
);
2101 CHECK_CALLED(OnEnterScript
);
2102 CHECK_CALLED(OnLeaveScript
);
2103 SET_EXPECT(OnEnterScript
);
2104 SET_EXPECT(GetIDsOfNames
);
2105 SET_EXPECT(OnLeaveScript
);
2106 hres
= IActiveScriptParse_ParseScriptText(parse
, global_code_test
[i
], L
"codeOnlyItem", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2107 ok(hres
== S_OK
, "ParseScriptText(%s) failed: %08x\n", wine_dbgstr_w(global_code_test
[i
]), hres
);
2108 CHECK_CALLED(OnEnterScript
);
2109 CHECK_CALLED(OnLeaveScript
);
2111 for (i
= 0; i
< ARRAY_SIZE(context_code_test
); i
++)
2113 SET_EXPECT(OnEnterScript
);
2114 SET_EXPECT(GetIDsOfNames
);
2115 SET_EXPECT(OnScriptError
);
2116 SET_EXPECT(OnLeaveScript
);
2117 hres
= IActiveScriptParse_ParseScriptText(parse
, context_code_test
[i
], NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2118 ok(FAILED(hres
), "ParseScriptText(%s) returned: %08x\n", wine_dbgstr_w(context_code_test
[i
]), hres
);
2119 CHECK_CALLED(OnEnterScript
);
2120 CHECK_CALLED(OnScriptError
);
2121 CHECK_CALLED(OnLeaveScript
);
2122 SET_EXPECT(OnEnterScript
);
2123 SET_EXPECT(GetIDsOfNames
);
2124 SET_EXPECT(OnLeaveScript
);
2125 hres
= IActiveScriptParse_ParseScriptText(parse
, context_code_test
[i
], L
"codeOnlyItem", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2126 ok(hres
== S_OK
, "ParseScriptText(%s) failed: %08x\n", wine_dbgstr_w(context_code_test
[i
]), hres
);
2127 CHECK_CALLED(OnEnterScript
);
2128 CHECK_CALLED(OnLeaveScript
);
2130 SET_EXPECT(OnScriptError
);
2131 SET_EXPECT(OnEnterScript
);
2132 SET_EXPECT(OnLeaveScript
);
2133 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"testSub_global = 10\n", L
"codeOnlyItem", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2134 ok(FAILED(hres
), "ParseScriptText returned: %08x\n", hres
);
2135 CHECK_CALLED(OnScriptError
);
2136 CHECK_CALLED(OnEnterScript
);
2137 CHECK_CALLED(OnLeaveScript
);
2139 SET_EXPECT(OnEnterScript
);
2140 SET_EXPECT(OnLeaveScript
);
2141 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"me", NULL
, NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
2142 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2143 ok(V_VT(&var
) == VT_DISPATCH
&& V_DISPATCH(&var
) == &global_named_item
,
2144 "Unexpected 'me': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var
), V_DISPATCH(&var
));
2146 CHECK_CALLED(OnEnterScript
);
2147 CHECK_CALLED(OnLeaveScript
);
2148 SET_EXPECT(OnEnterScript
);
2149 SET_EXPECT(OnLeaveScript
);
2150 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"me", L
"globalItem", NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
2151 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2152 ok(V_VT(&var
) == VT_DISPATCH
&& V_DISPATCH(&var
) == &global_named_item
,
2153 "Unexpected 'me': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var
), V_DISPATCH(&var
));
2155 CHECK_CALLED(OnEnterScript
);
2156 CHECK_CALLED(OnLeaveScript
);
2157 SET_EXPECT(OnEnterScript
);
2158 SET_EXPECT(OnLeaveScript
);
2159 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"me", L
"codeOnlyItem", NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
2160 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2161 ok(V_VT(&var
) == VT_DISPATCH
&& V_DISPATCH(&var
) == (IDispatch
*)script_disp2
,
2162 "Unexpected 'me': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var
), V_DISPATCH(&var
));
2164 CHECK_CALLED(OnEnterScript
);
2165 CHECK_CALLED(OnLeaveScript
);
2166 SET_EXPECT(OnEnterScript
);
2167 SET_EXPECT(OnLeaveScript
);
2168 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"globalCode_me", NULL
, NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
2169 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2170 ok(V_VT(&var
) == VT_DISPATCH
&& V_DISPATCH(&var
) == &global_named_item
,
2171 "Unexpected 'me': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var
), V_DISPATCH(&var
));
2173 CHECK_CALLED(OnEnterScript
);
2174 CHECK_CALLED(OnLeaveScript
);
2176 IDispatchEx_Release(script_disp2
);
2177 IDispatchEx_Release(script_disp
);
2179 script_disp
= get_script_dispatch(script
, L
"persistent");
2180 SET_EXPECT(OnEnterScript
);
2181 SET_EXPECT(OnLeaveScript
);
2182 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"me", L
"persistent", NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
2183 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2184 ok(V_VT(&var
) == VT_DISPATCH
&& V_DISPATCH(&var
) == (IDispatch
*)script_disp
,
2185 "Unexpected 'me': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var
), V_DISPATCH(&var
));
2187 CHECK_CALLED(OnEnterScript
);
2188 CHECK_CALLED(OnLeaveScript
);
2189 IDispatchEx_Release(script_disp
);
2191 SET_EXPECT(OnEnterScript
);
2192 SET_EXPECT(OnLeaveScript
);
2193 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"x = 13\n", L
"persistent", NULL
, NULL
, 0, 0, SCRIPTTEXT_ISPERSISTENT
, NULL
, NULL
);
2194 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2195 CHECK_CALLED(OnEnterScript
);
2196 CHECK_CALLED(OnLeaveScript
);
2197 SET_EXPECT(OnEnterScript
);
2198 SET_EXPECT(OnLeaveScript
);
2199 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"x = 10\n", L
"persistent", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2200 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2201 CHECK_CALLED(OnEnterScript
);
2202 CHECK_CALLED(OnLeaveScript
);
2203 SET_EXPECT(OnEnterScript
);
2204 SET_EXPECT(OnLeaveScript
);
2205 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"x", L
"persistent", NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
2206 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2207 ok(V_VT(&var
) == VT_I2
&& V_I2(&var
) == 10, "Unexpected 'x': V_VT = %d, V_I2 = %d\n", V_VT(&var
), V_I2(&var
));
2208 CHECK_CALLED(OnEnterScript
);
2209 CHECK_CALLED(OnLeaveScript
);
2211 script_disp
= get_script_dispatch(script
, L
"persistent");
2213 SET_EXPECT(OnStateChange_DISCONNECTED
);
2214 SET_EXPECT(OnStateChange_INITIALIZED
);
2215 SET_EXPECT(OnStateChange_UNINITIALIZED
);
2216 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_UNINITIALIZED
);
2217 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres
);
2218 CHECK_CALLED(OnStateChange_DISCONNECTED
);
2219 CHECK_CALLED(OnStateChange_INITIALIZED
);
2220 CHECK_CALLED(OnStateChange_UNINITIALIZED
);
2221 test_no_script_dispatch(script
);
2223 ok(global_named_item_ref
== 0, "global_named_item_ref = %u\n", global_named_item_ref
);
2224 ok(visible_named_item_ref
== 0, "visible_named_item_ref = %u\n", visible_named_item_ref
);
2225 ok(visible_code_named_item_ref
== 0, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref
);
2226 ok(persistent_named_item_ref
== 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref
);
2228 hres
= IActiveScript_GetScriptDispatch(script
, L
"codeOnlyItem", &disp
);
2229 ok(hres
== E_UNEXPECTED
, "hres = %08x, expected E_UNEXPECTED\n", hres
);
2231 SET_EXPECT(GetLCID
);
2232 SET_EXPECT(OnStateChange_INITIALIZED
);
2233 SET_EXPECT(GetItemInfo_persistent
);
2234 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
2235 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
2236 CHECK_CALLED(GetLCID
);
2237 CHECK_CALLED(OnStateChange_INITIALIZED
);
2238 CHECK_CALLED(GetItemInfo_persistent
);
2239 ok(persistent_named_item_ref
> 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref
);
2241 hres
= IActiveScript_AddNamedItem(script
, L
"codeOnlyItem", SCRIPTITEM_CODEONLY
);
2242 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
2244 SET_EXPECT(OnStateChange_CONNECTED
);
2245 SET_EXPECT_MULTI(OnEnterScript
, 5);
2246 SET_EXPECT_MULTI(OnLeaveScript
, 5);
2247 SET_EXPECT(GetIDsOfNames_persistent
);
2248 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_CONNECTED
);
2249 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres
);
2250 CHECK_CALLED(OnStateChange_CONNECTED
);
2251 CHECK_CALLED_MULTI(OnEnterScript
, 5);
2252 CHECK_CALLED_MULTI(OnLeaveScript
, 5);
2253 CHECK_CALLED(GetIDsOfNames_persistent
);
2254 test_state(script
, SCRIPTSTATE_CONNECTED
);
2256 script_disp2
= get_script_dispatch(script
, L
"persistent");
2257 ok(script_disp
!= script_disp2
, "Same script dispatch returned for \"persistent\" named item\n");
2258 IDispatchEx_Release(script_disp2
);
2259 IDispatchEx_Release(script_disp
);
2260 SET_EXPECT(OnEnterScript
);
2261 SET_EXPECT(OnLeaveScript
);
2262 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"x", L
"persistent", NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
2263 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2264 ok(V_VT(&var
) == VT_I2
&& V_I2(&var
) == 13, "Unexpected 'x': V_VT = %d, V_I2 = %d\n", V_VT(&var
), V_I2(&var
));
2265 CHECK_CALLED(OnEnterScript
);
2266 CHECK_CALLED(OnLeaveScript
);
2268 /* This object is set to named item when persistent items are re-initialized, even for CODEONLY items */
2269 SET_EXPECT(OnEnterScript
);
2270 SET_EXPECT(OnLeaveScript
);
2271 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"me", L
"persistent", NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
2272 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2273 ok(V_VT(&var
) == VT_DISPATCH
&& V_DISPATCH(&var
) == &persistent_named_item
,
2274 "Unexpected 'me': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var
), V_DISPATCH(&var
));
2276 CHECK_CALLED(OnEnterScript
);
2277 CHECK_CALLED(OnLeaveScript
);
2279 /* Lookups also query named items */
2280 SET_EXPECT(OnEnterScript
);
2281 SET_EXPECT(OnLeaveScript
);
2282 SET_EXPECT(GetIDsOfNames_persistent
);
2283 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"abc123 = 10\n", L
"persistent", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2284 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2285 CHECK_CALLED(OnEnterScript
);
2286 CHECK_CALLED(OnLeaveScript
);
2287 CHECK_CALLED(GetIDsOfNames_persistent
);
2289 SET_EXPECT(OnEnterScript
);
2290 SET_EXPECT(OnLeaveScript
);
2291 SET_EXPECT(GetIDsOfNames_persistent
);
2292 SET_EXPECT(OnScriptError
);
2293 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"testCall\n", L
"persistent", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2294 ok(FAILED(hres
), "ParseScriptText returned: %08x\n", hres
);
2295 CHECK_CALLED(OnEnterScript
);
2296 CHECK_CALLED(OnLeaveScript
);
2297 CHECK_CALLED(GetIDsOfNames_persistent
);
2298 CHECK_CALLED(OnScriptError
);
2300 script_disp
= get_script_dispatch(script
, NULL
);
2301 for (i
= 0; i
< ARRAY_SIZE(global_idents
); i
++)
2303 bstr
= SysAllocString(global_idents
[i
]);
2305 hres
= IDispatchEx_GetDispID(script_disp
, bstr
, 0, &id
);
2306 ok(hres
== S_OK
, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(global_idents
[i
]), hres
);
2307 ok(id
!= -1, "[%s] id = -1\n", wine_dbgstr_w(global_idents
[i
]));
2308 SysFreeString(bstr
);
2310 for (i
= 0; i
< ARRAY_SIZE(context_idents
); i
++)
2312 bstr
= SysAllocString(context_idents
[i
]);
2314 hres
= IDispatchEx_GetDispID(script_disp
, bstr
, 0, &id
);
2315 ok(hres
== DISP_E_UNKNOWNNAME
, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(context_idents
[i
]), hres
);
2316 ok(id
== -1, "[%s] id = %d, expected -1\n", wine_dbgstr_w(context_idents
[i
]), id
);
2317 SysFreeString(bstr
);
2319 SET_EXPECT(OnEnterScript
);
2320 SET_EXPECT(OnLeaveScript
);
2321 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"global_me", NULL
, NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
2322 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2323 ok(V_VT(&var
) == VT_DISPATCH
&& V_DISPATCH(&var
) == (IDispatch
*)script_disp
,
2324 "Unexpected 'me': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var
), V_DISPATCH(&var
));
2326 CHECK_CALLED(OnEnterScript
);
2327 CHECK_CALLED(OnLeaveScript
);
2328 SET_EXPECT(OnEnterScript
);
2329 SET_EXPECT(OnLeaveScript
);
2330 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"globalCode_me", NULL
, NULL
, NULL
, 0, 0, SCRIPTTEXT_ISEXPRESSION
, &var
, NULL
);
2331 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2332 ok(V_VT(&var
) == VT_DISPATCH
&& V_DISPATCH(&var
) == (IDispatch
*)script_disp
,
2333 "Unexpected 'me': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var
), V_DISPATCH(&var
));
2335 CHECK_CALLED(OnEnterScript
);
2336 CHECK_CALLED(OnLeaveScript
);
2337 SET_EXPECT(OnEnterScript
);
2338 SET_EXPECT(OnLeaveScript
);
2339 hres
= IActiveScriptParse_ParseScriptText(parse
, L
"global_me = 0\nglobalCode_me = 0\n", NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2340 ok(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
2341 CHECK_CALLED(OnEnterScript
);
2342 CHECK_CALLED(OnLeaveScript
);
2343 IDispatchEx_Release(script_disp
);
2345 script_disp
= get_script_dispatch(script
, L
"codeOnlyItem");
2346 for (i
= 0; i
< ARRAY_SIZE(global_idents
); i
++)
2348 bstr
= SysAllocString(global_idents
[i
]);
2350 hres
= IDispatchEx_GetDispID(script_disp
, bstr
, 0, &id
);
2351 ok(hres
== DISP_E_UNKNOWNNAME
, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(global_idents
[i
]), hres
);
2352 ok(id
== -1, "[%s] id = %d, expected -1\n", wine_dbgstr_w(global_idents
[i
]), id
);
2353 SysFreeString(bstr
);
2355 for (i
= 0; i
< ARRAY_SIZE(context_idents
); i
++)
2357 bstr
= SysAllocString(context_idents
[i
]);
2359 hres
= IDispatchEx_GetDispID(script_disp
, bstr
, 0, &id
);
2360 ok(hres
== DISP_E_UNKNOWNNAME
, "GetDispID(%s) returned %08x\n", wine_dbgstr_w(context_idents
[i
]), hres
);
2361 ok(id
== -1, "[%s] id = %d, expected -1\n", wine_dbgstr_w(context_idents
[i
]), id
);
2362 SysFreeString(bstr
);
2364 IDispatchEx_Release(script_disp
);
2366 for (i
= 0; i
< ARRAY_SIZE(global_code_test
); i
++)
2368 SET_EXPECT(OnEnterScript
);
2369 SET_EXPECT(OnLeaveScript
);
2370 hres
= IActiveScriptParse_ParseScriptText(parse
, global_code_test
[i
], NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2371 ok(hres
== S_OK
, "ParseScriptText(%s) failed: %08x\n", wine_dbgstr_w(global_code_test
[i
]), hres
);
2372 CHECK_CALLED(OnEnterScript
);
2373 CHECK_CALLED(OnLeaveScript
);
2374 SET_EXPECT(OnEnterScript
);
2375 SET_EXPECT(OnLeaveScript
);
2376 hres
= IActiveScriptParse_ParseScriptText(parse
, global_code_test
[i
], L
"codeOnlyItem", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2377 ok(hres
== S_OK
, "ParseScriptText(%s) failed: %08x\n", wine_dbgstr_w(global_code_test
[i
]), hres
);
2378 CHECK_CALLED(OnEnterScript
);
2379 CHECK_CALLED(OnLeaveScript
);
2381 for (i
= 0; i
< ARRAY_SIZE(context_code_test
); i
++)
2383 SET_EXPECT(OnScriptError
);
2384 SET_EXPECT(OnEnterScript
);
2385 SET_EXPECT(OnLeaveScript
);
2386 hres
= IActiveScriptParse_ParseScriptText(parse
, context_code_test
[i
], NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2387 ok(FAILED(hres
), "ParseScriptText(%s) returned: %08x\n", wine_dbgstr_w(context_code_test
[i
]), hres
);
2388 CHECK_CALLED(OnScriptError
);
2389 CHECK_CALLED(OnEnterScript
);
2390 CHECK_CALLED(OnLeaveScript
);
2391 SET_EXPECT(OnScriptError
);
2392 SET_EXPECT(OnEnterScript
);
2393 SET_EXPECT(OnLeaveScript
);
2394 hres
= IActiveScriptParse_ParseScriptText(parse
, context_code_test
[i
], L
"codeOnlyItem", NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
2395 ok(FAILED(hres
), "ParseScriptText(%s) returned: %08x\n", wine_dbgstr_w(context_code_test
[i
]), hres
);
2396 CHECK_CALLED(OnScriptError
);
2397 CHECK_CALLED(OnEnterScript
);
2398 CHECK_CALLED(OnLeaveScript
);
2401 SET_EXPECT(OnStateChange_DISCONNECTED
);
2402 SET_EXPECT(OnStateChange_INITIALIZED
);
2403 SET_EXPECT(OnStateChange_CLOSED
);
2404 hres
= IActiveScript_Close(script
);
2405 ok(hres
== S_OK
, "Close failed: %08x\n", hres
);
2406 CHECK_CALLED(OnStateChange_DISCONNECTED
);
2407 CHECK_CALLED(OnStateChange_INITIALIZED
);
2408 CHECK_CALLED(OnStateChange_CLOSED
);
2410 ok(global_named_item_ref
== 0, "global_named_item_ref = %u\n", global_named_item_ref
);
2411 ok(visible_named_item_ref
== 0, "visible_named_item_ref = %u\n", visible_named_item_ref
);
2412 ok(visible_code_named_item_ref
== 0, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref
);
2413 ok(persistent_named_item_ref
== 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref
);
2415 test_state(script
, SCRIPTSTATE_CLOSED
);
2417 IActiveScriptParse_Release(parse
);
2419 ref
= IActiveScript_Release(script
);
2420 ok(!ref
, "ref = %d\n", ref
);
2423 static void test_RegExp(void)
2426 IMatchCollection2
*mc
;
2438 hres
= CoCreateInstance(&CLSID_VBScriptRegExp
, NULL
,
2439 CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
2440 &IID_IUnknown
, (void**)&unk
);
2441 if(hres
== REGDB_E_CLASSNOTREG
) {
2442 win_skip("VBScriptRegExp is not registered\n");
2445 ok(hres
== S_OK
, "CoCreateInstance(CLSID_VBScriptRegExp) failed: %x\n", hres
);
2447 hres
= IUnknown_QueryInterface(unk
, &IID_IRegExp2
, (void**)®exp
);
2448 if(hres
== E_NOINTERFACE
) {
2449 win_skip("IRegExp2 interface is not available\n");
2452 ok(hres
== S_OK
, "QueryInterface(IID_IRegExp2) failed: %x\n", hres
);
2453 IUnknown_Release(unk
);
2455 hres
= IRegExp2_QueryInterface(regexp
, &IID_IRegExp
, (void**)&unk
);
2456 ok(hres
== S_OK
, "QueryInterface(IID_IRegExp) returned %x\n", hres
);
2457 IUnknown_Release(unk
);
2459 hres
= IRegExp2_QueryInterface(regexp
, &IID_IDispatchEx
, (void**)&unk
);
2460 ok(hres
== E_NOINTERFACE
, "QueryInterface(IID_IDispatchEx) returned %x\n", hres
);
2462 hres
= IRegExp2_get_Pattern(regexp
, &bstr
);
2463 ok(bstr
== NULL
, "bstr != NULL\n");
2464 ok(hres
== S_OK
, "get_Pattern returned %x, expected S_OK\n", hres
);
2466 hres
= IRegExp2_get_Pattern(regexp
, NULL
);
2467 ok(hres
== E_POINTER
, "get_Pattern returned %x, expected E_POINTER\n", hres
);
2469 hres
= IRegExp2_get_IgnoreCase(regexp
, NULL
);
2470 ok(hres
== E_POINTER
, "get_IgnoreCase returned %x, expected E_POINTER\n", hres
);
2472 hres
= IRegExp2_get_Global(regexp
, NULL
);
2473 ok(hres
== E_POINTER
, "get_Global returned %x, expected E_POINTER\n", hres
);
2475 hres
= IRegExp2_Execute(regexp
, NULL
, &disp
);
2476 ok(hres
== S_OK
, "Execute returned %x, expected S_OK\n", hres
);
2477 hres
= IDispatch_QueryInterface(disp
, &IID_IMatchCollection2
, (void**)&mc
);
2478 ok(hres
== S_OK
, "QueryInterface(IID_IMatchCollection2) returned %x\n", hres
);
2479 IDispatch_Release(disp
);
2481 hres
= IMatchCollection2_QueryInterface(mc
, &IID_IMatchCollection
, (void**)&unk
);
2482 ok(hres
== S_OK
, "QueryInterface(IID_IMatchCollection) returned %x\n", hres
);
2483 IUnknown_Release(unk
);
2485 hres
= IMatchCollection2_get_Count(mc
, NULL
);
2486 ok(hres
== E_POINTER
, "get_Count returned %x, expected E_POINTER\n", hres
);
2488 hres
= IMatchCollection2_get_Count(mc
, &count
);
2489 ok(hres
== S_OK
, "get_Count returned %x, expected S_OK\n", hres
);
2490 ok(count
== 1, "count = %d\n", count
);
2492 hres
= IMatchCollection2_get_Item(mc
, 1, &disp
);
2493 ok(hres
== E_INVALIDARG
, "get_Item returned %x, expected E_INVALIDARG\n", hres
);
2495 hres
= IMatchCollection2_get_Item(mc
, 1, NULL
);
2496 ok(hres
== E_POINTER
, "get_Item returned %x, expected E_POINTER\n", hres
);
2498 hres
= IMatchCollection2_get_Item(mc
, 0, &disp
);
2499 ok(hres
== S_OK
, "get_Item returned %x, expected S_OK\n", hres
);
2500 hres
= IDispatch_QueryInterface(disp
, &IID_IMatch2
, (void**)&match
);
2501 ok(hres
== S_OK
, "QueryInterface(IID_IMatch2) returned %x\n", hres
);
2502 IDispatch_Release(disp
);
2504 hres
= IMatch2_QueryInterface(match
, &IID_IMatch
, (void**)&unk
);
2505 ok(hres
== S_OK
, "QueryInterface(IID_IMatch) returned %x\n", hres
);
2506 IUnknown_Release(unk
);
2508 hres
= IMatch2_get_Value(match
, NULL
);
2509 ok(hres
== E_POINTER
, "get_Value returned %x, expected E_POINTER\n", hres
);
2511 hres
= IMatch2_get_FirstIndex(match
, NULL
);
2512 ok(hres
== E_POINTER
, "get_FirstIndex returned %x, expected E_POINTER\n", hres
);
2514 hres
= IMatch2_get_Length(match
, NULL
);
2515 ok(hres
== E_POINTER
, "get_Length returned %x, expected E_POINTER\n", hres
);
2517 hres
= IMatch2_get_SubMatches(match
, NULL
);
2518 ok(hres
== E_POINTER
, "get_SubMatches returned %x, expected E_POINTER\n", hres
);
2520 hres
= IMatch2_get_SubMatches(match
, &disp
);
2521 ok(hres
== S_OK
, "get_SubMatches returned %x, expected S_OK\n", hres
);
2522 IMatch2_Release(match
);
2523 hres
= IDispatch_QueryInterface(disp
, &IID_ISubMatches
, (void**)&sm
);
2524 ok(hres
== S_OK
, "QueryInterface(IID_ISubMatches) returned %x\n", hres
);
2525 IDispatch_Release(disp
);
2527 hres
= ISubMatches_get_Item(sm
, 0, &v
);
2528 ok(hres
== E_INVALIDARG
, "get_Item returned %x, expected E_INVALIDARG\n", hres
);
2530 hres
= ISubMatches_get_Item(sm
, 0, NULL
);
2531 ok(hres
== E_POINTER
, "get_Item returned %x, expected E_POINTER\n", hres
);
2533 hres
= ISubMatches_get_Count(sm
, NULL
);
2534 ok(hres
== E_POINTER
, "get_Count returned %x, expected E_POINTER\n", hres
);
2535 ISubMatches_Release(sm
);
2537 hres
= IMatchCollection2_get__NewEnum(mc
, &unk
);
2538 ok(hres
== S_OK
, "get__NewEnum returned %x, expected S_OK\n", hres
);
2539 hres
= IUnknown_QueryInterface(unk
, &IID_IEnumVARIANT
, (void**)&ev
);
2540 ok(hres
== S_OK
, "QueryInterface(IID_IEnumVARIANT) returned %x\n", hres
);
2541 IUnknown_Release(unk
);
2542 IMatchCollection2_Release(mc
);
2544 hres
= IEnumVARIANT_Skip(ev
, 2);
2545 ok(hres
== S_OK
, "Skip returned %x\n", hres
);
2547 hres
= IEnumVARIANT_Next(ev
, 1, &v
, &fetched
);
2548 ok(hres
== S_FALSE
, "Next returned %x, expected S_FALSE\n", hres
);
2549 ok(fetched
== 0, "fetched = %d\n", fetched
);
2551 hres
= IEnumVARIANT_Skip(ev
, -1);
2552 ok(hres
== S_OK
, "Skip returned %x\n", hres
);
2554 hres
= IEnumVARIANT_Next(ev
, 1, &v
, &fetched
);
2555 ok(hres
== S_OK
, "Next returned %x\n", hres
);
2556 ok(fetched
== 1, "fetched = %d\n", fetched
);
2558 IEnumVARIANT_Release(ev
);
2560 IRegExp2_Release(regexp
);
2563 static void test_RegExp_Replace(void)
2567 const char *pattern
;
2568 const char *replace
;
2574 { "abc", "", "123abc456", "123456", FALSE
},
2575 { "abc", "dcba", "123abc456", "123dcba456", FALSE
},
2576 { "[\r\n\t\f]+", " ", "\nHello\rNew\fWorld\t!", " Hello\rNew\fWorld\t!", FALSE
},
2577 { "[\r\n\t\f]+", " ", "\nHello\rNew\fWorld\t!", " Hello New World !", TRUE
},
2582 BSTR str
, ret
, result
;
2585 hr
= CoCreateInstance(&CLSID_VBScriptRegExp
, NULL
,
2586 CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
,
2587 &IID_IRegExp2
, (void **)®exp
);
2588 if (hr
== REGDB_E_CLASSNOTREG
)
2590 win_skip("VBScriptRegExp is not registered\n");
2593 ok(hr
== S_OK
, "got %#x\n", hr
);
2595 for (i
= 0; i
< ARRAY_SIZE(test
); i
++)
2597 hr
= IRegExp2_put_Global(regexp
, test
[i
].global
? VARIANT_TRUE
: VARIANT_FALSE
);
2598 ok(hr
== S_OK
, "got %#x\n", hr
);
2600 str
= a2bstr(test
[i
].pattern
);
2601 hr
= IRegExp2_put_Pattern(regexp
, str
);
2602 ok(hr
== S_OK
, "got %#x\n", hr
);
2605 str
= a2bstr(test
[i
].source
);
2606 V_VT(&var
) = VT_BSTR
;
2607 V_BSTR(&var
) = a2bstr(test
[i
].replace
);
2608 hr
= IRegExp2_Replace(regexp
, str
, var
, &ret
);
2609 ok(hr
== S_OK
, "got %#x\n", hr
);
2610 result
= a2bstr(test
[i
].result
);
2611 ok(!wcscmp(ret
, result
), "got %s, expected %s\n", wine_dbgstr_w(ret
), wine_dbgstr_w(result
));
2612 SysFreeString(result
);
2614 SysFreeString(V_BSTR(&var
));
2618 IRegExp2_Release(regexp
);
2621 static BOOL
check_vbscript(void)
2623 IActiveScriptParseProcedure2
*vbscript
;
2626 hres
= CoCreateInstance(&CLSID_VBScript
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
2627 &IID_IActiveScriptParseProcedure2
, (void**)&vbscript
);
2629 IActiveScriptParseProcedure2_Release(vbscript
);
2631 return hres
== S_OK
;
2634 START_TEST(vbscript
)
2638 if(check_vbscript()) {
2640 test_vbscript_uninitializing();
2641 test_vbscript_release();
2642 test_vbscript_simplecreate();
2643 test_vbscript_initializing();
2646 test_code_persistence();
2647 test_script_typeinfo();
2649 test_RegExp_Replace();
2651 win_skip("VBScript engine not available or too old\n");