2011-07-19 13:46:50 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#define CONST_VTABLE
|
|
|
|
|
|
|
|
#include <initguid.h>
|
|
|
|
#include <ole2.h>
|
|
|
|
#include <activscp.h>
|
2011-09-02 13:16:18 +02:00
|
|
|
#include <objsafe.h>
|
2011-09-05 11:14:29 +02:00
|
|
|
#include <dispex.h>
|
2011-07-19 13:46:50 +02:00
|
|
|
|
2013-02-15 15:09:57 +01:00
|
|
|
#include "vbsregexp55.h"
|
|
|
|
|
2011-07-19 13:46:50 +02:00
|
|
|
#include "wine/test.h"
|
|
|
|
|
2012-07-31 13:21:18 +02:00
|
|
|
#ifdef _WIN64
|
|
|
|
|
|
|
|
#define IActiveScriptParse_QueryInterface IActiveScriptParse64_QueryInterface
|
|
|
|
#define IActiveScriptParse_Release IActiveScriptParse64_Release
|
|
|
|
#define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
|
|
|
|
#define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
|
2012-08-13 11:04:31 +02:00
|
|
|
#define IActiveScriptParseProcedure2_Release \
|
|
|
|
IActiveScriptParseProcedure2_64_Release
|
2012-07-31 13:21:18 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define IActiveScriptParse_QueryInterface IActiveScriptParse32_QueryInterface
|
|
|
|
#define IActiveScriptParse_Release IActiveScriptParse32_Release
|
|
|
|
#define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
|
|
|
|
#define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
|
2012-08-13 11:04:31 +02:00
|
|
|
#define IActiveScriptParseProcedure2_Release \
|
|
|
|
IActiveScriptParseProcedure2_32_Release
|
2012-07-31 13:21:18 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-09-02 13:16:18 +02:00
|
|
|
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
|
|
|
|
|
2011-08-31 11:22:33 +02:00
|
|
|
#define DEFINE_EXPECT(func) \
|
|
|
|
static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
|
|
|
|
|
|
|
|
#define SET_EXPECT(func) \
|
|
|
|
expect_ ## func = TRUE
|
|
|
|
|
|
|
|
#define CHECK_EXPECT2(func) \
|
|
|
|
do { \
|
|
|
|
ok(expect_ ##func, "unexpected call " #func "\n"); \
|
|
|
|
called_ ## func = TRUE; \
|
|
|
|
}while(0)
|
|
|
|
|
|
|
|
#define CHECK_EXPECT(func) \
|
|
|
|
do { \
|
|
|
|
CHECK_EXPECT2(func); \
|
|
|
|
expect_ ## func = FALSE; \
|
|
|
|
}while(0)
|
|
|
|
|
|
|
|
#define CHECK_CALLED(func) \
|
|
|
|
do { \
|
|
|
|
ok(called_ ## func, "expected " #func "\n"); \
|
|
|
|
expect_ ## func = called_ ## func = FALSE; \
|
|
|
|
}while(0)
|
|
|
|
|
|
|
|
DEFINE_EXPECT(GetLCID);
|
|
|
|
DEFINE_EXPECT(OnStateChange_UNINITIALIZED);
|
|
|
|
DEFINE_EXPECT(OnStateChange_STARTED);
|
|
|
|
DEFINE_EXPECT(OnStateChange_CONNECTED);
|
|
|
|
DEFINE_EXPECT(OnStateChange_DISCONNECTED);
|
|
|
|
DEFINE_EXPECT(OnStateChange_CLOSED);
|
|
|
|
DEFINE_EXPECT(OnStateChange_INITIALIZED);
|
|
|
|
DEFINE_EXPECT(OnEnterScript);
|
|
|
|
DEFINE_EXPECT(OnLeaveScript);
|
|
|
|
|
2011-07-19 13:46:50 +02:00
|
|
|
DEFINE_GUID(CLSID_VBScript, 0xb54f3741, 0x5b07, 0x11cf, 0xa4,0xb0, 0x00,0xaa,0x00,0x4a,0x55,0xe8);
|
2013-02-15 15:09:57 +01:00
|
|
|
DEFINE_GUID(CLSID_VBScriptRegExp, 0x3f4daca4, 0x160d, 0x11d2, 0xa8,0xe9, 0x00,0x10,0x4b,0x36,0x5c,0x9f);
|
2011-07-19 13:46:50 +02:00
|
|
|
|
2012-09-07 15:10:38 +02:00
|
|
|
static BSTR a2bstr(const char *str)
|
|
|
|
{
|
|
|
|
BSTR ret;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
|
|
|
|
ret = SysAllocStringLen(NULL, len-1);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-08-31 11:22:44 +02:00
|
|
|
#define test_state(s,ss) _test_state(__LINE__,s,ss)
|
|
|
|
static void _test_state(unsigned line, IActiveScript *script, SCRIPTSTATE exstate)
|
|
|
|
{
|
|
|
|
SCRIPTSTATE state = -1;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IActiveScript_GetScriptState(script, &state);
|
|
|
|
ok_(__FILE__,line) (hres == S_OK, "GetScriptState failed: %08x\n", hres);
|
|
|
|
ok_(__FILE__,line) (state == exstate, "state=%d, expected %d\n", state, exstate);
|
|
|
|
}
|
|
|
|
|
2011-08-31 11:22:33 +02:00
|
|
|
static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid))
|
|
|
|
*ppv = iface;
|
|
|
|
else if(IsEqualGUID(&IID_IActiveScriptSite, riid))
|
|
|
|
*ppv = iface;
|
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
|
|
|
|
{
|
|
|
|
CHECK_EXPECT(GetLCID);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
|
|
|
|
DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
|
|
|
|
{
|
|
|
|
ok(0, "unexpected call\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
|
|
|
|
{
|
|
|
|
ok(0, "unexpected call\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
|
|
|
|
const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
|
|
|
|
{
|
|
|
|
ok(0, "unexpected call\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
|
|
|
|
{
|
|
|
|
switch(ssScriptState) {
|
|
|
|
case SCRIPTSTATE_UNINITIALIZED:
|
|
|
|
CHECK_EXPECT(OnStateChange_UNINITIALIZED);
|
|
|
|
return S_OK;
|
|
|
|
case SCRIPTSTATE_STARTED:
|
|
|
|
CHECK_EXPECT(OnStateChange_STARTED);
|
|
|
|
return S_OK;
|
|
|
|
case SCRIPTSTATE_CONNECTED:
|
|
|
|
CHECK_EXPECT(OnStateChange_CONNECTED);
|
|
|
|
return S_OK;
|
|
|
|
case SCRIPTSTATE_DISCONNECTED:
|
|
|
|
CHECK_EXPECT(OnStateChange_DISCONNECTED);
|
|
|
|
return S_OK;
|
|
|
|
case SCRIPTSTATE_CLOSED:
|
|
|
|
CHECK_EXPECT(OnStateChange_CLOSED);
|
|
|
|
return S_OK;
|
|
|
|
case SCRIPTSTATE_INITIALIZED:
|
|
|
|
CHECK_EXPECT(OnStateChange_INITIALIZED);
|
|
|
|
return S_OK;
|
|
|
|
default:
|
|
|
|
ok(0, "unexpected call %d\n", ssScriptState);
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
|
|
|
|
{
|
|
|
|
ok(0, "unexpected call\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
|
|
|
|
{
|
|
|
|
CHECK_EXPECT(OnEnterScript);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
|
|
|
|
{
|
|
|
|
CHECK_EXPECT(OnLeaveScript);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
|
|
|
|
ActiveScriptSite_QueryInterface,
|
|
|
|
ActiveScriptSite_AddRef,
|
|
|
|
ActiveScriptSite_Release,
|
|
|
|
ActiveScriptSite_GetLCID,
|
|
|
|
ActiveScriptSite_GetItemInfo,
|
|
|
|
ActiveScriptSite_GetDocVersionString,
|
|
|
|
ActiveScriptSite_OnScriptTerminate,
|
|
|
|
ActiveScriptSite_OnStateChange,
|
|
|
|
ActiveScriptSite_OnScriptError,
|
|
|
|
ActiveScriptSite_OnEnterScript,
|
|
|
|
ActiveScriptSite_OnLeaveScript
|
|
|
|
};
|
|
|
|
|
|
|
|
static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
|
|
|
|
|
2011-09-02 13:16:18 +02:00
|
|
|
static void test_safety(IActiveScript *script)
|
|
|
|
{
|
|
|
|
IObjectSafety *safety;
|
|
|
|
DWORD supported, enabled;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IActiveScript_QueryInterface(script, &IID_IObjectSafety, (void**)&safety);
|
|
|
|
ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return;
|
|
|
|
|
|
|
|
hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, &supported, NULL);
|
|
|
|
ok(hres == E_POINTER, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres);
|
|
|
|
hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, NULL, &enabled);
|
|
|
|
ok(hres == E_POINTER, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres);
|
|
|
|
|
|
|
|
supported = enabled = 0xdeadbeef;
|
|
|
|
hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, &supported, &enabled);
|
|
|
|
ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
|
|
|
|
ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
|
|
|
|
"supported=%x\n", supported);
|
|
|
|
ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
|
|
|
|
|
|
|
|
supported = enabled = 0xdeadbeef;
|
|
|
|
hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScript, &supported, &enabled);
|
|
|
|
ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
|
|
|
|
ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
|
|
|
|
"supported=%x\n", supported);
|
|
|
|
ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
|
|
|
|
|
|
|
|
supported = enabled = 0xdeadbeef;
|
|
|
|
hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
|
|
|
|
ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
|
|
|
|
ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
|
|
|
|
"supported=%x\n", supported);
|
|
|
|
ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
|
|
|
|
|
|
|
|
hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
|
|
|
|
INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER
|
|
|
|
|INTERFACESAFE_FOR_UNTRUSTED_CALLER,
|
|
|
|
INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
|
|
|
|
ok(hres == E_FAIL, "SetInterfaceSafetyOptions failed: %08x, expected E_FAIL\n", hres);
|
|
|
|
|
|
|
|
hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
|
|
|
|
INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER,
|
|
|
|
INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
|
|
|
|
ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
|
|
|
|
|
|
|
|
supported = enabled = 0xdeadbeef;
|
|
|
|
hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
|
|
|
|
ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
|
|
|
|
ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
|
|
|
|
"supported=%x\n", supported);
|
|
|
|
ok(enabled == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
|
|
|
|
"enabled=%x\n", enabled);
|
|
|
|
|
|
|
|
hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, INTERFACESAFE_FOR_UNTRUSTED_DATA, 0);
|
|
|
|
ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
|
|
|
|
|
|
|
|
supported = enabled = 0xdeadbeef;
|
|
|
|
hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
|
|
|
|
ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
|
|
|
|
ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
|
|
|
|
"supported=%x\n", supported);
|
|
|
|
ok(enabled == (INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER), "enabled=%x\n", enabled);
|
|
|
|
|
|
|
|
hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
|
|
|
|
INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER, 0);
|
|
|
|
ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
|
|
|
|
|
|
|
|
supported = enabled = 0xdeadbeef;
|
|
|
|
hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
|
|
|
|
ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
|
|
|
|
ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
|
|
|
|
"supported=%x\n", supported);
|
|
|
|
ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
|
|
|
|
|
|
|
|
hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
|
|
|
|
INTERFACE_USES_DISPEX, 0);
|
|
|
|
ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
|
|
|
|
|
|
|
|
supported = enabled = 0xdeadbeef;
|
|
|
|
hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
|
|
|
|
ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
|
|
|
|
ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
|
|
|
|
"supported=%x\n", supported);
|
|
|
|
ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
|
|
|
|
|
|
|
|
IObjectSafety_Release(safety);
|
|
|
|
}
|
|
|
|
|
2011-09-05 11:14:29 +02:00
|
|
|
static IDispatchEx *get_script_dispatch(IActiveScript *script)
|
|
|
|
{
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
IDispatch *disp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
disp = (void*)0xdeadbeef;
|
|
|
|
hres = IActiveScript_GetScriptDispatch(script, NULL, &disp);
|
|
|
|
ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
|
|
|
|
return dispex;
|
|
|
|
}
|
|
|
|
|
2012-09-07 15:10:38 +02:00
|
|
|
static void parse_script(IActiveScriptParse *parse, const char *src)
|
|
|
|
{
|
|
|
|
BSTR str;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
SET_EXPECT(OnEnterScript);
|
|
|
|
SET_EXPECT(OnLeaveScript);
|
|
|
|
|
|
|
|
str = a2bstr(src);
|
|
|
|
hres = IActiveScriptParse_ParseScriptText(parse, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
|
|
|
|
SysFreeString(str);
|
|
|
|
ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
|
|
|
|
|
|
|
|
CHECK_CALLED(OnEnterScript);
|
|
|
|
CHECK_CALLED(OnLeaveScript);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define get_disp_id(a,b,c,d) _get_disp_id(__LINE__,a,b,c,d)
|
|
|
|
static void _get_disp_id(unsigned line, IDispatchEx *dispex, const char *name, HRESULT exhres, DISPID *id)
|
|
|
|
{
|
2012-09-18 12:26:03 +02:00
|
|
|
DISPID id2;
|
2012-09-07 15:10:38 +02:00
|
|
|
BSTR str;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
str = a2bstr(name);
|
|
|
|
hres = IDispatchEx_GetDispID(dispex, str, 0, id);
|
|
|
|
ok_(__FILE__,line)(hres == exhres, "GetDispID(%s) returned %08x, expected %08x\n", name, hres, exhres);
|
2012-09-18 12:26:03 +02:00
|
|
|
|
|
|
|
hres = IDispatchEx_GetIDsOfNames(dispex, &IID_NULL, &str, 1, 0, &id2);
|
|
|
|
SysFreeString(str);
|
|
|
|
ok_(__FILE__,line)(hres == exhres, "GetIDsOfNames(%s) returned %08x, expected %08x\n", name, hres, exhres);
|
|
|
|
ok_(__FILE__,line)(*id == id2, "GetIDsOfNames(%s) id != id2\n", name);
|
2012-09-07 15:10:38 +02:00
|
|
|
}
|
|
|
|
|
2011-09-05 11:14:14 +02:00
|
|
|
static void test_no_script_dispatch(IActiveScript *script)
|
|
|
|
{
|
|
|
|
IDispatch *disp;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
disp = (void*)0xdeadbeef;
|
|
|
|
hres = IActiveScript_GetScriptDispatch(script, NULL, &disp);
|
|
|
|
ok(hres == E_UNEXPECTED, "hres = %08x, expected E_UNEXPECTED\n", hres);
|
|
|
|
ok(!disp, "disp != NULL\n");
|
|
|
|
}
|
|
|
|
|
2011-08-31 11:22:33 +02:00
|
|
|
static IActiveScript *create_vbscript(void)
|
|
|
|
{
|
|
|
|
IActiveScript *ret;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
|
|
|
|
&IID_IActiveScript, (void**)&ret);
|
|
|
|
ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-07 15:10:38 +02:00
|
|
|
static void test_scriptdisp(void)
|
|
|
|
{
|
|
|
|
IActiveScriptParse *parser;
|
|
|
|
IDispatchEx *script_disp;
|
|
|
|
IActiveScript *vbscript;
|
|
|
|
DISPID id, id2;
|
|
|
|
DISPPARAMS dp;
|
|
|
|
EXCEPINFO ei;
|
|
|
|
VARIANT v;
|
|
|
|
ULONG ref;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
vbscript = create_vbscript();
|
|
|
|
|
|
|
|
hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParse, (void**)&parser);
|
|
|
|
ok(hres == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hres);
|
|
|
|
|
|
|
|
test_state(vbscript, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
test_safety(vbscript);
|
|
|
|
|
|
|
|
SET_EXPECT(GetLCID);
|
|
|
|
hres = IActiveScript_SetScriptSite(vbscript, &ActiveScriptSite);
|
|
|
|
ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(GetLCID);
|
|
|
|
|
|
|
|
test_state(vbscript, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_INITIALIZED);
|
|
|
|
hres = IActiveScriptParse_InitNew(parser);
|
|
|
|
ok(hres == S_OK, "InitNew failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_INITIALIZED);
|
|
|
|
|
|
|
|
test_state(vbscript, SCRIPTSTATE_INITIALIZED);
|
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_CONNECTED);
|
|
|
|
hres = IActiveScript_SetScriptState(vbscript, SCRIPTSTATE_CONNECTED);
|
|
|
|
ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_CONNECTED);
|
|
|
|
|
|
|
|
test_state(vbscript, SCRIPTSTATE_CONNECTED);
|
|
|
|
|
|
|
|
script_disp = get_script_dispatch(vbscript);
|
|
|
|
|
|
|
|
id = 100;
|
|
|
|
get_disp_id(script_disp, "LCase", DISP_E_UNKNOWNNAME, &id);
|
|
|
|
ok(id == -1, "id = %d, expected -1\n", id);
|
|
|
|
|
|
|
|
get_disp_id(script_disp, "globalVariable", DISP_E_UNKNOWNNAME, &id);
|
|
|
|
parse_script(parser, "dim globalVariable\nglobalVariable = 3");
|
|
|
|
get_disp_id(script_disp, "globalVariable", S_OK, &id);
|
|
|
|
|
|
|
|
memset(&dp, 0, sizeof(dp));
|
|
|
|
memset(&ei, 0, sizeof(ei));
|
|
|
|
V_VT(&v) = VT_EMPTY;
|
|
|
|
hres = IDispatchEx_InvokeEx(script_disp, id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
|
|
|
|
ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
|
|
|
|
ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
|
|
|
|
ok(V_I2(&v) == 3, "V_I2(v) = %d\n", V_I2(&v));
|
|
|
|
|
|
|
|
get_disp_id(script_disp, "globalVariable2", DISP_E_UNKNOWNNAME, &id);
|
|
|
|
parse_script(parser, "globalVariable2 = 4");
|
|
|
|
get_disp_id(script_disp, "globalVariable2", S_OK, &id);
|
|
|
|
|
|
|
|
get_disp_id(script_disp, "globalFunction", DISP_E_UNKNOWNNAME, &id);
|
|
|
|
parse_script(parser, "function globalFunction()\nglobalFunction=5\nend function");
|
|
|
|
get_disp_id(script_disp, "globalFunction", S_OK, &id);
|
|
|
|
|
|
|
|
SET_EXPECT(OnEnterScript);
|
|
|
|
SET_EXPECT(OnLeaveScript);
|
|
|
|
|
|
|
|
memset(&dp, 0, sizeof(dp));
|
|
|
|
memset(&ei, 0, sizeof(ei));
|
|
|
|
V_VT(&v) = VT_EMPTY;
|
|
|
|
hres = IDispatchEx_InvokeEx(script_disp, id, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
|
|
|
|
ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
|
|
|
|
ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
|
|
|
|
ok(V_I2(&v) == 5, "V_I2(v) = %d\n", V_I2(&v));
|
|
|
|
|
|
|
|
CHECK_CALLED(OnEnterScript);
|
|
|
|
CHECK_CALLED(OnLeaveScript);
|
|
|
|
|
2012-09-18 12:26:16 +02:00
|
|
|
SET_EXPECT(OnEnterScript);
|
|
|
|
SET_EXPECT(OnLeaveScript);
|
|
|
|
|
|
|
|
memset(&dp, 0, sizeof(dp));
|
|
|
|
memset(&ei, 0, sizeof(ei));
|
|
|
|
V_VT(&v) = VT_EMPTY;
|
|
|
|
hres = IDispatchEx_Invoke(script_disp, id, &IID_NULL, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dp, &v, &ei, NULL);
|
|
|
|
ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
|
|
|
|
ok(V_VT(&v) == VT_I2, "V_VT(v) = %d\n", V_VT(&v));
|
|
|
|
ok(V_I2(&v) == 5, "V_I2(v) = %d\n", V_I2(&v));
|
|
|
|
|
|
|
|
CHECK_CALLED(OnEnterScript);
|
|
|
|
CHECK_CALLED(OnLeaveScript);
|
|
|
|
|
2012-09-07 15:10:38 +02:00
|
|
|
get_disp_id(script_disp, "globalSub", DISP_E_UNKNOWNNAME, &id);
|
|
|
|
parse_script(parser, "sub globalSub()\nend sub");
|
|
|
|
get_disp_id(script_disp, "globalSub", S_OK, &id);
|
|
|
|
get_disp_id(script_disp, "globalSub", S_OK, &id2);
|
|
|
|
ok(id == id2, "id != id2\n");
|
|
|
|
|
|
|
|
get_disp_id(script_disp, "constVariable", DISP_E_UNKNOWNNAME, &id);
|
|
|
|
parse_script(parser, "const constVariable = 6");
|
|
|
|
get_disp_id(script_disp, "ConstVariable", S_OK, &id);
|
|
|
|
get_disp_id(script_disp, "Constvariable", S_OK, &id2);
|
|
|
|
ok(id == id2, "id != id2\n");
|
|
|
|
|
|
|
|
IDispatchEx_Release(script_disp);
|
|
|
|
|
|
|
|
IActiveScriptParse_Release(parser);
|
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_DISCONNECTED);
|
|
|
|
SET_EXPECT(OnStateChange_INITIALIZED);
|
|
|
|
SET_EXPECT(OnStateChange_CLOSED);
|
|
|
|
hres = IActiveScript_Close(vbscript);
|
|
|
|
ok(hres == S_OK, "Close failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_DISCONNECTED);
|
|
|
|
CHECK_CALLED(OnStateChange_INITIALIZED);
|
|
|
|
CHECK_CALLED(OnStateChange_CLOSED);
|
|
|
|
|
|
|
|
ref = IActiveScript_Release(vbscript);
|
|
|
|
ok(!ref, "ref = %d\n", ref);
|
|
|
|
}
|
|
|
|
|
2011-07-19 13:46:50 +02:00
|
|
|
static void test_vbscript(void)
|
|
|
|
{
|
2012-08-13 11:04:31 +02:00
|
|
|
IActiveScriptParseProcedure2 *parse_proc;
|
2011-07-19 13:46:50 +02:00
|
|
|
IActiveScriptParse *parser;
|
|
|
|
IActiveScript *vbscript;
|
2011-08-31 11:22:33 +02:00
|
|
|
ULONG ref;
|
2011-07-19 13:46:50 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-08-31 11:22:33 +02:00
|
|
|
vbscript = create_vbscript();
|
2011-07-19 13:46:50 +02:00
|
|
|
|
|
|
|
hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParse, (void**)&parser);
|
|
|
|
ok(hres == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hres);
|
|
|
|
|
2011-08-31 11:22:44 +02:00
|
|
|
test_state(vbscript, SCRIPTSTATE_UNINITIALIZED);
|
2011-09-02 13:16:18 +02:00
|
|
|
test_safety(vbscript);
|
2011-08-31 11:22:44 +02:00
|
|
|
|
2011-08-31 11:22:33 +02:00
|
|
|
SET_EXPECT(GetLCID);
|
|
|
|
hres = IActiveScript_SetScriptSite(vbscript, &ActiveScriptSite);
|
|
|
|
ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(GetLCID);
|
|
|
|
|
2011-08-31 11:22:44 +02:00
|
|
|
test_state(vbscript, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
|
2011-08-31 11:22:33 +02:00
|
|
|
SET_EXPECT(OnStateChange_INITIALIZED);
|
2012-07-31 13:21:18 +02:00
|
|
|
hres = IActiveScriptParse_InitNew(parser);
|
2011-08-31 11:22:33 +02:00
|
|
|
ok(hres == S_OK, "InitNew failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_INITIALIZED);
|
|
|
|
|
2011-08-31 11:22:44 +02:00
|
|
|
test_state(vbscript, SCRIPTSTATE_INITIALIZED);
|
|
|
|
|
2012-07-31 13:21:18 +02:00
|
|
|
hres = IActiveScriptParse_InitNew(parser);
|
2011-08-31 11:22:33 +02:00
|
|
|
ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres);
|
|
|
|
|
2011-09-05 11:13:54 +02:00
|
|
|
SET_EXPECT(OnStateChange_CONNECTED);
|
|
|
|
hres = IActiveScript_SetScriptState(vbscript, SCRIPTSTATE_CONNECTED);
|
|
|
|
ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_CONNECTED);
|
|
|
|
|
|
|
|
test_state(vbscript, SCRIPTSTATE_CONNECTED);
|
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_DISCONNECTED);
|
|
|
|
SET_EXPECT(OnStateChange_INITIALIZED);
|
2011-08-31 11:22:33 +02:00
|
|
|
SET_EXPECT(OnStateChange_CLOSED);
|
|
|
|
hres = IActiveScript_Close(vbscript);
|
|
|
|
ok(hres == S_OK, "Close failed: %08x\n", hres);
|
2011-09-05 11:13:54 +02:00
|
|
|
CHECK_CALLED(OnStateChange_DISCONNECTED);
|
|
|
|
CHECK_CALLED(OnStateChange_INITIALIZED);
|
2011-08-31 11:22:33 +02:00
|
|
|
CHECK_CALLED(OnStateChange_CLOSED);
|
|
|
|
|
2011-08-31 11:22:44 +02:00
|
|
|
test_state(vbscript, SCRIPTSTATE_CLOSED);
|
2011-09-05 11:14:14 +02:00
|
|
|
test_no_script_dispatch(vbscript);
|
2011-08-31 11:22:44 +02:00
|
|
|
|
2012-07-31 13:21:18 +02:00
|
|
|
IActiveScriptParse_Release(parser);
|
2011-08-31 11:22:33 +02:00
|
|
|
|
2012-08-13 11:04:31 +02:00
|
|
|
hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParseProcedure, (void**)&parse_proc);
|
|
|
|
ok(hres == E_NOINTERFACE, "Got IActiveScriptParseProcedure interface, expected E_NOTIMPL\n");
|
|
|
|
|
|
|
|
hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc);
|
|
|
|
ok(hres == S_OK, "Could not get IActiveScriptParseProcedure2 interface\n");
|
|
|
|
IActiveScriptParseProcedure2_Release(parse_proc);
|
|
|
|
|
2011-08-31 11:22:33 +02:00
|
|
|
ref = IActiveScript_Release(vbscript);
|
|
|
|
ok(!ref, "ref = %d\n", ref);
|
2011-07-19 13:46:50 +02:00
|
|
|
}
|
|
|
|
|
2011-09-05 11:14:29 +02:00
|
|
|
static void test_vbscript_uninitializing(void)
|
|
|
|
{
|
|
|
|
IActiveScriptParse *parse;
|
|
|
|
IActiveScript *script;
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
ULONG ref;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
static const WCHAR script_textW[] =
|
|
|
|
{'F','u','n','c','t','i','o','n',' ','f','\n','E','n','d',' ','F','u','n','c','t','i','o','n','\n',0};
|
|
|
|
|
|
|
|
script = create_vbscript();
|
|
|
|
|
|
|
|
hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
|
|
|
|
ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
|
2012-07-31 13:21:18 +02:00
|
|
|
hres = IActiveScriptParse_InitNew(parse);
|
2011-09-05 11:14:29 +02:00
|
|
|
ok(hres == S_OK, "InitNew failed: %08x\n", hres);
|
|
|
|
|
|
|
|
SET_EXPECT(GetLCID);
|
|
|
|
SET_EXPECT(OnStateChange_INITIALIZED);
|
|
|
|
hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
|
|
|
|
ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(GetLCID);
|
|
|
|
CHECK_CALLED(OnStateChange_INITIALIZED);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_INITIALIZED);
|
|
|
|
|
2012-07-31 13:21:18 +02:00
|
|
|
hres = IActiveScriptParse_ParseScriptText(parse, script_textW, NULL, NULL, NULL, 0, 1, 0x42, NULL, NULL);
|
2011-09-05 11:14:29 +02:00
|
|
|
ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
|
|
|
|
|
|
|
|
hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
|
|
|
|
ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres);
|
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_UNINITIALIZED);
|
|
|
|
hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_UNINITIALIZED);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
|
|
|
|
hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
|
|
|
|
|
|
|
|
SET_EXPECT(GetLCID);
|
|
|
|
SET_EXPECT(OnStateChange_INITIALIZED);
|
|
|
|
hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
|
|
|
|
ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(GetLCID);
|
|
|
|
CHECK_CALLED(OnStateChange_INITIALIZED);
|
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_CONNECTED);
|
|
|
|
SET_EXPECT(OnEnterScript);
|
|
|
|
SET_EXPECT(OnLeaveScript);
|
|
|
|
hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
|
|
|
|
ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_CONNECTED);
|
|
|
|
CHECK_CALLED(OnEnterScript);
|
|
|
|
CHECK_CALLED(OnLeaveScript);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_CONNECTED);
|
|
|
|
|
|
|
|
dispex = get_script_dispatch(script);
|
|
|
|
ok(dispex != NULL, "dispex == NULL\n");
|
|
|
|
if(dispex)
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_DISCONNECTED);
|
|
|
|
SET_EXPECT(OnStateChange_INITIALIZED);
|
|
|
|
SET_EXPECT(OnStateChange_UNINITIALIZED);
|
|
|
|
hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_DISCONNECTED);
|
|
|
|
CHECK_CALLED(OnStateChange_INITIALIZED);
|
|
|
|
CHECK_CALLED(OnStateChange_UNINITIALIZED);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
|
|
|
|
hres = IActiveScript_Close(script);
|
|
|
|
ok(hres == S_OK, "Close failed: %08x\n", hres);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_CLOSED);
|
|
|
|
|
|
|
|
hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
ok(hres == E_UNEXPECTED, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x, expected E_UNEXPECTED\n", hres);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_CLOSED);
|
|
|
|
|
2011-10-14 16:22:04 +02:00
|
|
|
SET_EXPECT(GetLCID);
|
|
|
|
SET_EXPECT(OnStateChange_INITIALIZED);
|
|
|
|
hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
|
|
|
|
ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(GetLCID);
|
|
|
|
CHECK_CALLED(OnStateChange_INITIALIZED);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_INITIALIZED);
|
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_CLOSED);
|
|
|
|
hres = IActiveScript_Close(script);
|
|
|
|
ok(hres == S_OK, "Close failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_CLOSED);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_CLOSED);
|
|
|
|
|
2012-07-31 13:21:18 +02:00
|
|
|
IActiveScriptParse_Release(parse);
|
2011-09-05 11:14:29 +02:00
|
|
|
|
|
|
|
ref = IActiveScript_Release(script);
|
|
|
|
ok(!ref, "ref = %d\n", ref);
|
|
|
|
}
|
|
|
|
|
2011-10-14 16:22:04 +02:00
|
|
|
static void test_vbscript_release(void)
|
|
|
|
{
|
|
|
|
IActiveScriptParse *parser;
|
|
|
|
IActiveScript *vbscript;
|
|
|
|
ULONG ref;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
vbscript = create_vbscript();
|
|
|
|
|
|
|
|
hres = IActiveScript_QueryInterface(vbscript, &IID_IActiveScriptParse, (void**)&parser);
|
|
|
|
ok(hres == S_OK, "Could not get IActiveScriptParse iface: %08x\n", hres);
|
|
|
|
|
|
|
|
test_state(vbscript, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
test_safety(vbscript);
|
|
|
|
|
|
|
|
SET_EXPECT(GetLCID);
|
|
|
|
hres = IActiveScript_SetScriptSite(vbscript, &ActiveScriptSite);
|
|
|
|
ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(GetLCID);
|
|
|
|
|
|
|
|
test_state(vbscript, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_INITIALIZED);
|
2012-07-31 13:21:18 +02:00
|
|
|
hres = IActiveScriptParse_InitNew(parser);
|
2011-10-14 16:22:04 +02:00
|
|
|
ok(hres == S_OK, "InitNew failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_INITIALIZED);
|
|
|
|
|
|
|
|
test_state(vbscript, SCRIPTSTATE_INITIALIZED);
|
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_CONNECTED);
|
|
|
|
hres = IActiveScript_SetScriptState(vbscript, SCRIPTSTATE_CONNECTED);
|
|
|
|
ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_CONNECTED);
|
|
|
|
|
|
|
|
test_state(vbscript, SCRIPTSTATE_CONNECTED);
|
|
|
|
|
2012-07-31 13:21:18 +02:00
|
|
|
IActiveScriptParse_Release(parser);
|
2011-10-14 16:22:04 +02:00
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_DISCONNECTED);
|
|
|
|
SET_EXPECT(OnStateChange_INITIALIZED);
|
|
|
|
SET_EXPECT(OnStateChange_CLOSED);
|
|
|
|
ref = IActiveScript_Release(vbscript);
|
|
|
|
ok(!ref, "ref = %d\n", ref);
|
|
|
|
CHECK_CALLED(OnStateChange_DISCONNECTED);
|
|
|
|
CHECK_CALLED(OnStateChange_INITIALIZED);
|
|
|
|
CHECK_CALLED(OnStateChange_CLOSED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_vbscript_simplecreate(void)
|
|
|
|
{
|
|
|
|
IActiveScript *script;
|
|
|
|
ULONG ref;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
script = create_vbscript();
|
|
|
|
|
|
|
|
hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_UNINITIALIZED) failed: %08x\n", hres);
|
|
|
|
|
|
|
|
ref = IActiveScript_Release(script);
|
|
|
|
ok(!ref, "ref = %d\n", ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_vbscript_initializing(void)
|
|
|
|
{
|
|
|
|
IActiveScriptParse *parse;
|
|
|
|
IActiveScript *script;
|
|
|
|
ULONG ref;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
script = create_vbscript();
|
|
|
|
|
|
|
|
hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
|
|
|
|
ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
|
|
|
|
SET_EXPECT(GetLCID);
|
|
|
|
hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
|
|
|
|
ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(GetLCID);
|
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_INITIALIZED);
|
2012-07-31 13:21:18 +02:00
|
|
|
hres = IActiveScriptParse_InitNew(parse);
|
2011-10-14 16:22:04 +02:00
|
|
|
ok(hres == S_OK, "InitNew failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_INITIALIZED);
|
|
|
|
|
|
|
|
hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
|
|
|
|
ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres);
|
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_CLOSED);
|
|
|
|
hres = IActiveScript_Close(script);
|
|
|
|
ok(hres == S_OK, "Close failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_CLOSED);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_CLOSED);
|
|
|
|
|
2012-07-31 13:21:18 +02:00
|
|
|
IActiveScriptParse_Release(parse);
|
2011-10-14 16:22:04 +02:00
|
|
|
|
|
|
|
ref = IActiveScript_Release(script);
|
|
|
|
ok(!ref, "ref = %d\n", ref);
|
|
|
|
}
|
2011-09-05 11:14:29 +02:00
|
|
|
|
2013-02-15 15:09:57 +01:00
|
|
|
static void test_RegExp(void)
|
|
|
|
{
|
|
|
|
IRegExp2 *regexp;
|
2013-02-19 12:42:41 +01:00
|
|
|
IMatchCollection2 *mc;
|
|
|
|
IMatch2 *match;
|
|
|
|
ISubMatches *sm;
|
2013-02-19 12:42:56 +01:00
|
|
|
IEnumVARIANT *ev;
|
2013-02-15 15:09:57 +01:00
|
|
|
IUnknown *unk;
|
2013-02-19 12:42:41 +01:00
|
|
|
IDispatch *disp;
|
2013-02-15 15:09:57 +01:00
|
|
|
HRESULT hres;
|
2013-02-19 12:42:41 +01:00
|
|
|
BSTR bstr;
|
|
|
|
LONG count;
|
|
|
|
VARIANT v;
|
2013-02-19 12:42:56 +01:00
|
|
|
ULONG fetched;
|
2013-02-15 15:09:57 +01:00
|
|
|
|
|
|
|
hres = CoCreateInstance(&CLSID_VBScriptRegExp, NULL,
|
|
|
|
CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
|
|
|
|
&IID_IUnknown, (void**)&unk);
|
|
|
|
if(hres == REGDB_E_CLASSNOTREG) {
|
|
|
|
win_skip("VBScriptRegExp is not registered\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(hres == S_OK, "CoCreateInstance(CLSID_VBScriptRegExp) failed: %x\n", hres);
|
|
|
|
|
|
|
|
hres = IUnknown_QueryInterface(unk, &IID_IRegExp2, (void**)®exp);
|
|
|
|
if(hres == E_NOINTERFACE) {
|
|
|
|
win_skip("IRegExp2 interface is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(hres == S_OK, "QueryInterface(IID_IRegExp2) failed: %x\n", hres);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
|
|
|
|
hres = IRegExp2_QueryInterface(regexp, &IID_IRegExp, (void**)&unk);
|
|
|
|
ok(hres == S_OK, "QueryInterface(IID_IRegExp) returned %x\n", hres);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
|
|
|
|
hres = IRegExp2_QueryInterface(regexp, &IID_IDispatchEx, (void**)&unk);
|
|
|
|
ok(hres == E_NOINTERFACE, "QueryInterface(IID_IDispatchEx) returned %x\n", hres);
|
|
|
|
|
2013-02-19 12:42:41 +01:00
|
|
|
hres = IRegExp2_get_Pattern(regexp, &bstr);
|
|
|
|
ok(bstr == NULL, "bstr != NULL\n");
|
|
|
|
ok(hres == S_OK, "get_Pattern returned %x, expected S_OK\n", hres);
|
|
|
|
|
|
|
|
hres = IRegExp2_get_Pattern(regexp, NULL);
|
|
|
|
ok(hres == E_POINTER, "get_Pattern returned %x, expected E_POINTER\n", hres);
|
|
|
|
|
|
|
|
hres = IRegExp2_get_IgnoreCase(regexp, NULL);
|
|
|
|
ok(hres == E_POINTER, "get_IgnoreCase returned %x, expected E_POINTER\n", hres);
|
|
|
|
|
|
|
|
hres = IRegExp2_get_Global(regexp, NULL);
|
|
|
|
ok(hres == E_POINTER, "get_Global returned %x, expected E_POINTER\n", hres);
|
|
|
|
|
|
|
|
hres = IRegExp2_Execute(regexp, NULL, &disp);
|
|
|
|
ok(hres == S_OK, "Execute returned %x, expected S_OK\n", hres);
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IMatchCollection2, (void**)&mc);
|
|
|
|
ok(hres == S_OK, "QueryInterface(IID_IMatchCollection2) returned %x\n", hres);
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
|
2013-03-25 12:34:38 +01:00
|
|
|
hres = IMatchCollection2_QueryInterface(mc, &IID_IMatchCollection, (void**)&unk);
|
|
|
|
ok(hres == S_OK, "QueryInterface(IID_IMatchCollection) returned %x\n", hres);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
|
2013-02-19 12:42:41 +01:00
|
|
|
hres = IMatchCollection2_get_Count(mc, NULL);
|
|
|
|
ok(hres == E_POINTER, "get_Count returned %x, expected E_POINTER\n", hres);
|
|
|
|
|
|
|
|
hres = IMatchCollection2_get_Count(mc, &count);
|
|
|
|
ok(hres == S_OK, "get_Count returned %x, expected S_OK\n", hres);
|
|
|
|
ok(count == 1, "count = %d\n", count);
|
|
|
|
|
|
|
|
hres = IMatchCollection2_get_Item(mc, 1, &disp);
|
|
|
|
ok(hres == E_INVALIDARG, "get_Item returned %x, expected E_INVALIDARG\n", hres);
|
|
|
|
|
|
|
|
hres = IMatchCollection2_get_Item(mc, 1, NULL);
|
|
|
|
ok(hres == E_POINTER, "get_Item returned %x, expected E_POINTER\n", hres);
|
|
|
|
|
|
|
|
hres = IMatchCollection2_get_Item(mc, 0, &disp);
|
|
|
|
ok(hres == S_OK, "get_Item returned %x, expected S_OK\n", hres);
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IMatch2, (void**)&match);
|
|
|
|
ok(hres == S_OK, "QueryInterface(IID_IMatch2) returned %x\n", hres);
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
|
2013-03-25 12:34:49 +01:00
|
|
|
hres = IMatch2_QueryInterface(match, &IID_IMatch, (void**)&unk);
|
|
|
|
ok(hres == S_OK, "QueryInterface(IID_IMatch) returned %x\n", hres);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
|
2013-02-19 12:42:41 +01:00
|
|
|
hres = IMatch2_get_Value(match, NULL);
|
|
|
|
ok(hres == E_POINTER, "get_Value returned %x, expected E_POINTER\n", hres);
|
|
|
|
|
|
|
|
hres = IMatch2_get_FirstIndex(match, NULL);
|
|
|
|
ok(hres == E_POINTER, "get_FirstIndex returned %x, expected E_POINTER\n", hres);
|
|
|
|
|
|
|
|
hres = IMatch2_get_Length(match, NULL);
|
|
|
|
ok(hres == E_POINTER, "get_Length returned %x, expected E_POINTER\n", hres);
|
|
|
|
|
|
|
|
hres = IMatch2_get_SubMatches(match, NULL);
|
|
|
|
ok(hres == E_POINTER, "get_SubMatches returned %x, expected E_POINTER\n", hres);
|
|
|
|
|
|
|
|
hres = IMatch2_get_SubMatches(match, &disp);
|
|
|
|
ok(hres == S_OK, "get_SubMatches returned %x, expected S_OK\n", hres);
|
|
|
|
IMatch2_Release(match);
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_ISubMatches, (void**)&sm);
|
|
|
|
ok(hres == S_OK, "QueryInterface(IID_ISubMatches) returned %x\n", hres);
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
|
|
|
|
hres = ISubMatches_get_Item(sm, 0, &v);
|
|
|
|
ok(hres == E_INVALIDARG, "get_Item returned %x, expected E_INVALIDARG\n", hres);
|
|
|
|
|
|
|
|
hres = ISubMatches_get_Item(sm, 0, NULL);
|
|
|
|
ok(hres == E_POINTER, "get_Item returned %x, expected E_POINTER\n", hres);
|
|
|
|
|
|
|
|
hres = ISubMatches_get_Count(sm, NULL);
|
|
|
|
ok(hres == E_POINTER, "get_Count returned %x, expected E_POINTER\n", hres);
|
|
|
|
ISubMatches_Release(sm);
|
|
|
|
|
2013-02-19 12:42:56 +01:00
|
|
|
hres = IMatchCollection2_get__NewEnum(mc, &unk);
|
|
|
|
ok(hres == S_OK, "get__NewEnum returned %x, expected S_OK\n", hres);
|
|
|
|
hres = IUnknown_QueryInterface(unk, &IID_IEnumVARIANT, (void**)&ev);
|
|
|
|
ok(hres == S_OK, "QueryInterface(IID_IEnumVARIANT) returned %x\n", hres);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
IMatchCollection2_Release(mc);
|
|
|
|
|
|
|
|
hres = IEnumVARIANT_Skip(ev, 2);
|
|
|
|
ok(hres == S_OK, "Skip returned %x\n", hres);
|
|
|
|
|
|
|
|
hres = IEnumVARIANT_Next(ev, 1, &v, &fetched);
|
|
|
|
ok(hres == S_FALSE, "Next returned %x, expected S_FALSE\n", hres);
|
|
|
|
ok(fetched == 0, "fetched = %d\n", fetched);
|
|
|
|
|
|
|
|
hres = IEnumVARIANT_Skip(ev, -1);
|
|
|
|
ok(hres == S_OK, "Skip returned %x\n", hres);
|
|
|
|
|
|
|
|
hres = IEnumVARIANT_Next(ev, 1, &v, &fetched);
|
|
|
|
ok(hres == S_OK, "Next returned %x\n", hres);
|
|
|
|
ok(fetched == 1, "fetched = %d\n", fetched);
|
|
|
|
VariantClear(&v);
|
|
|
|
IEnumVARIANT_Release(ev);
|
|
|
|
|
2013-02-15 15:09:57 +01:00
|
|
|
IRegExp2_Release(regexp);
|
|
|
|
}
|
|
|
|
|
2011-07-19 13:46:50 +02:00
|
|
|
static BOOL check_vbscript(void)
|
|
|
|
{
|
2012-09-12 09:35:57 +02:00
|
|
|
IActiveScriptParseProcedure2 *vbscript;
|
2011-07-19 13:46:50 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
|
2012-09-12 09:35:57 +02:00
|
|
|
&IID_IActiveScriptParseProcedure2, (void**)&vbscript);
|
2011-07-19 13:46:50 +02:00
|
|
|
if(SUCCEEDED(hres))
|
2012-09-12 09:35:57 +02:00
|
|
|
IActiveScriptParseProcedure2_Release(vbscript);
|
2011-07-19 13:46:50 +02:00
|
|
|
|
|
|
|
return hres == S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(vbscript)
|
|
|
|
{
|
|
|
|
CoInitialize(NULL);
|
|
|
|
|
2011-09-05 11:14:29 +02:00
|
|
|
if(check_vbscript()) {
|
2011-07-19 13:46:50 +02:00
|
|
|
test_vbscript();
|
2011-09-05 11:14:29 +02:00
|
|
|
test_vbscript_uninitializing();
|
2011-10-14 16:22:04 +02:00
|
|
|
test_vbscript_release();
|
|
|
|
test_vbscript_simplecreate();
|
|
|
|
test_vbscript_initializing();
|
2012-09-07 15:10:38 +02:00
|
|
|
test_scriptdisp();
|
2013-02-15 15:09:57 +01:00
|
|
|
test_RegExp();
|
2011-09-05 11:14:29 +02:00
|
|
|
}else {
|
2012-09-12 09:35:57 +02:00
|
|
|
win_skip("VBScript engine not available or too old\n");
|
2011-09-05 11:14:29 +02:00
|
|
|
}
|
2011-07-19 13:46:50 +02:00
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|