2008-03-24 21:53:14 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2008 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
|
2008-09-01 01:19:25 +02:00
|
|
|
#define CONST_VTABLE
|
2008-03-24 21:53:14 +01:00
|
|
|
|
2008-07-08 16:17:17 +02:00
|
|
|
#include <initguid.h>
|
2008-03-24 21:53:14 +01:00
|
|
|
#include <ole2.h>
|
|
|
|
#include <activscp.h>
|
2008-04-10 10:37:17 +02:00
|
|
|
#include <objsafe.h>
|
2008-09-01 01:23:38 +02:00
|
|
|
#include <dispex.h>
|
2008-03-24 21:53:14 +01:00
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2008-07-08 16:17:17 +02:00
|
|
|
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
|
|
|
|
|
2008-03-24 21:53:14 +01:00
|
|
|
static const CLSID CLSID_JScript =
|
|
|
|
{0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
|
|
|
|
|
2008-09-01 01:19:25 +02:00
|
|
|
#define DEFINE_EXPECT(func) \
|
|
|
|
static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
|
|
|
|
|
|
|
|
#define SET_EXPECT(func) \
|
|
|
|
expect_ ## func = TRUE
|
|
|
|
|
|
|
|
#define SET_CALLED(func) \
|
|
|
|
called_ ## 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);
|
2011-02-21 17:49:32 +01:00
|
|
|
DEFINE_EXPECT(OnStateChange_UNINITIALIZED);
|
2008-09-01 01:19:25 +02:00
|
|
|
DEFINE_EXPECT(OnStateChange_STARTED);
|
2008-11-05 01:03:19 +01:00
|
|
|
DEFINE_EXPECT(OnStateChange_CONNECTED);
|
|
|
|
DEFINE_EXPECT(OnStateChange_DISCONNECTED);
|
2008-09-01 01:19:25 +02:00
|
|
|
DEFINE_EXPECT(OnStateChange_CLOSED);
|
|
|
|
DEFINE_EXPECT(OnStateChange_INITIALIZED);
|
|
|
|
DEFINE_EXPECT(OnEnterScript);
|
|
|
|
DEFINE_EXPECT(OnLeaveScript);
|
|
|
|
|
2009-09-27 20:59:28 +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;
|
|
|
|
}
|
|
|
|
|
2008-09-01 01:25:29 +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);
|
|
|
|
}
|
|
|
|
|
2008-09-01 01:19:25 +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) {
|
2011-02-21 17:49:32 +01:00
|
|
|
case SCRIPTSTATE_UNINITIALIZED:
|
|
|
|
CHECK_EXPECT(OnStateChange_UNINITIALIZED);
|
|
|
|
return S_OK;
|
2008-09-01 01:19:25 +02:00
|
|
|
case SCRIPTSTATE_STARTED:
|
|
|
|
CHECK_EXPECT(OnStateChange_STARTED);
|
|
|
|
return S_OK;
|
2008-11-05 01:03:19 +01:00
|
|
|
case SCRIPTSTATE_CONNECTED:
|
|
|
|
CHECK_EXPECT(OnStateChange_CONNECTED);
|
|
|
|
return S_OK;
|
|
|
|
case SCRIPTSTATE_DISCONNECTED:
|
|
|
|
CHECK_EXPECT(OnStateChange_DISCONNECTED);
|
|
|
|
return S_OK;
|
2008-09-01 01:19:25 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef ACTSCPSITE_THIS
|
|
|
|
|
|
|
|
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 };
|
|
|
|
|
2009-12-30 19:49:45 +01:00
|
|
|
static void test_script_dispatch(IDispatchEx *dispex)
|
2008-09-01 01:23:38 +02:00
|
|
|
{
|
2009-12-30 19:49:45 +01:00
|
|
|
DISPPARAMS dp = {NULL,NULL,0,0};
|
|
|
|
EXCEPINFO ei;
|
2009-09-27 20:59:28 +02:00
|
|
|
BSTR str;
|
|
|
|
DISPID id;
|
2009-12-30 19:49:45 +01:00
|
|
|
VARIANT v;
|
2008-09-01 01:23:38 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2009-12-30 19:49:45 +01:00
|
|
|
str = a2bstr("ActiveXObject");
|
|
|
|
hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
|
|
|
|
SysFreeString(str);
|
|
|
|
ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
|
2008-09-01 01:23:38 +02:00
|
|
|
|
2009-12-30 19:49:45 +01:00
|
|
|
str = a2bstr("Math");
|
|
|
|
hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
|
|
|
|
SysFreeString(str);
|
|
|
|
ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
|
2008-09-01 01:23:38 +02:00
|
|
|
|
2009-12-30 19:49:45 +01:00
|
|
|
memset(&ei, 0, sizeof(ei));
|
|
|
|
hres = IDispatchEx_InvokeEx(dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
|
|
|
|
ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
|
|
|
|
ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v));
|
|
|
|
ok(V_DISPATCH(&v) != NULL, "V_DISPATCH(v) = NULL\n");
|
|
|
|
VariantClear(&v);
|
2008-09-01 01:23:38 +02:00
|
|
|
|
2009-12-30 19:49:45 +01:00
|
|
|
str = a2bstr("String");
|
2009-09-27 20:59:28 +02:00
|
|
|
hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id);
|
|
|
|
SysFreeString(str);
|
|
|
|
ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
|
|
|
|
|
2009-12-30 19:49:45 +01:00
|
|
|
memset(&ei, 0, sizeof(ei));
|
|
|
|
hres = IDispatchEx_InvokeEx(dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &v, &ei, NULL);
|
|
|
|
ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
|
|
|
|
ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v));
|
|
|
|
ok(V_DISPATCH(&v) != NULL, "V_DISPATCH(v) = NULL\n");
|
|
|
|
VariantClear(&v);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
ok(hres == S_OK, "Could not get IDispatch iface: %08x\n", hres);
|
|
|
|
return dispex;
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2008-09-01 01:23:38 +02:00
|
|
|
}
|
|
|
|
|
2008-04-10 10:37:17 +02:00
|
|
|
static void test_safety(IUnknown *unk)
|
|
|
|
{
|
|
|
|
IObjectSafety *safety;
|
|
|
|
DWORD supported, enabled;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IUnknown_QueryInterface(unk, &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);
|
2008-04-14 01:02:13 +02:00
|
|
|
ok(hres == E_FAIL, "SetInterfaceSafetyOptions failed: %08x, expected E_FAIL\n", hres);
|
2008-04-10 10:37:17 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
IObjectSafety_Release(safety);
|
|
|
|
}
|
|
|
|
|
2009-10-19 20:39:24 +02:00
|
|
|
static HRESULT set_script_prop(IActiveScript *engine, DWORD property, VARIANT *val)
|
|
|
|
{
|
|
|
|
IActiveScriptProperty *script_prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptProperty,
|
|
|
|
(void**)&script_prop);
|
2010-09-21 15:58:48 +02:00
|
|
|
ok(hres == S_OK, "Could not get IActiveScriptProperty: %08x\n", hres);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2009-10-19 20:39:24 +02:00
|
|
|
|
|
|
|
hres = IActiveScriptProperty_SetProperty(script_prop, property, NULL, val);
|
|
|
|
IActiveScriptProperty_Release(script_prop);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_invoke_versioning(IActiveScript *script)
|
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
V_VT(&v) = VT_NULL;
|
|
|
|
hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
|
|
|
|
if(hres == E_NOTIMPL) {
|
|
|
|
win_skip("SCRIPTPROP_INVOKESTRING not supported\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(hres == E_INVALIDARG, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
|
|
|
|
|
|
|
|
V_VT(&v) = VT_I2;
|
|
|
|
V_I2(&v) = 0;
|
|
|
|
hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
|
|
|
|
ok(hres == E_INVALIDARG, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
|
|
|
|
|
|
|
|
V_VT(&v) = VT_I4;
|
|
|
|
V_I4(&v) = 16;
|
|
|
|
hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
|
|
|
|
ok(hres == E_INVALIDARG, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
|
|
|
|
|
|
|
|
V_VT(&v) = VT_I4;
|
|
|
|
V_I4(&v) = 2;
|
|
|
|
hres = set_script_prop(script, SCRIPTPROP_INVOKEVERSIONING, &v);
|
|
|
|
ok(hres == S_OK, "SetProperty(SCRIPTPROP_INVOKEVERSIONING) failed: %08x\n", hres);
|
|
|
|
}
|
|
|
|
|
2011-02-21 17:49:32 +01:00
|
|
|
static IActiveScript *create_jscript(void)
|
|
|
|
{
|
|
|
|
IActiveScript *ret;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
|
|
|
|
&IID_IActiveScript, (void**)&ret);
|
|
|
|
ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-03-24 21:53:14 +01:00
|
|
|
static void test_jscript(void)
|
|
|
|
{
|
|
|
|
IActiveScriptParse *parse;
|
|
|
|
IActiveScript *script;
|
2009-12-30 19:49:45 +01:00
|
|
|
IDispatchEx *dispex;
|
2008-09-01 01:19:25 +02:00
|
|
|
ULONG ref;
|
2008-03-24 21:53:14 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-02-21 17:49:32 +01:00
|
|
|
script = create_jscript();
|
2008-03-24 21:53:14 +01:00
|
|
|
|
2011-02-21 17:49:32 +01:00
|
|
|
hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
|
2008-03-24 21:53:14 +01:00
|
|
|
ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
|
|
|
|
|
2008-09-01 01:25:29 +02:00
|
|
|
test_state(script, SCRIPTSTATE_UNINITIALIZED);
|
2011-02-21 17:49:32 +01:00
|
|
|
test_safety((IUnknown*)script);
|
2009-10-19 20:39:24 +02:00
|
|
|
test_invoke_versioning(script);
|
2008-04-10 10:37:17 +02:00
|
|
|
|
2009-02-02 15:27:24 +01:00
|
|
|
hres = IActiveScriptParse64_InitNew(parse);
|
2008-09-01 01:23:16 +02:00
|
|
|
ok(hres == S_OK, "InitNew failed: %08x\n", hres);
|
|
|
|
|
2009-02-02 15:27:24 +01:00
|
|
|
hres = IActiveScriptParse64_InitNew(parse);
|
2008-09-01 01:23:16 +02:00
|
|
|
ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres);
|
|
|
|
|
2008-09-01 01:19:25 +02:00
|
|
|
hres = IActiveScript_SetScriptSite(script, NULL);
|
|
|
|
ok(hres == E_POINTER, "SetScriptSite failed: %08x, expected E_POINTER\n", hres);
|
|
|
|
|
2008-09-01 01:25:29 +02:00
|
|
|
test_state(script, SCRIPTSTATE_UNINITIALIZED);
|
2009-12-30 19:49:45 +01:00
|
|
|
test_no_script_dispatch(script);
|
2008-09-01 01:23:38 +02:00
|
|
|
|
2008-09-01 01:19:25 +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);
|
|
|
|
|
2008-09-01 01:25:29 +02:00
|
|
|
test_state(script, SCRIPTSTATE_INITIALIZED);
|
|
|
|
|
2008-09-01 01:19:25 +02:00
|
|
|
hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
|
|
|
|
ok(hres == E_UNEXPECTED, "SetScriptSite failed: %08x, expected E_UNEXPECTED\n", hres);
|
|
|
|
|
2009-12-30 19:49:45 +01:00
|
|
|
dispex = get_script_dispatch(script);
|
|
|
|
test_script_dispatch(dispex);
|
2008-09-01 01:23:38 +02:00
|
|
|
|
2008-09-05 02:38:17 +02:00
|
|
|
SET_EXPECT(OnStateChange_STARTED);
|
|
|
|
hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED);
|
|
|
|
ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_STARTED);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_STARTED);
|
|
|
|
|
2008-09-01 01:19:25 +02:00
|
|
|
SET_EXPECT(OnStateChange_CLOSED);
|
|
|
|
hres = IActiveScript_Close(script);
|
|
|
|
ok(hres == S_OK, "Close failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_CLOSED);
|
|
|
|
|
2008-09-01 01:25:29 +02:00
|
|
|
test_state(script, SCRIPTSTATE_CLOSED);
|
2009-12-30 19:49:45 +01:00
|
|
|
test_no_script_dispatch(script);
|
|
|
|
test_script_dispatch(dispex);
|
|
|
|
IDispatchEx_Release(dispex);
|
2008-09-01 01:23:38 +02:00
|
|
|
|
2009-02-02 15:27:24 +01:00
|
|
|
IUnknown_Release(parse);
|
2008-09-01 01:19:25 +02:00
|
|
|
|
2011-02-21 17:49:32 +01:00
|
|
|
ref = IActiveScript_Release(script);
|
2008-09-01 01:19:25 +02:00
|
|
|
ok(!ref, "ref = %d\n", ref);
|
2008-03-24 21:53:14 +01:00
|
|
|
}
|
|
|
|
|
2008-11-05 01:03:03 +01:00
|
|
|
static void test_jscript2(void)
|
|
|
|
{
|
|
|
|
IActiveScriptParse *parse;
|
|
|
|
IActiveScript *script;
|
|
|
|
ULONG ref;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-02-21 17:49:32 +01:00
|
|
|
script = create_jscript();
|
2008-11-05 01:03:03 +01:00
|
|
|
|
2011-02-21 17:49:32 +01:00
|
|
|
hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
|
2008-11-05 01:03:03 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_INITIALIZED);
|
2009-02-02 15:27:24 +01:00
|
|
|
hres = IActiveScriptParse64_InitNew(parse);
|
2008-11-05 01:03:03 +01:00
|
|
|
ok(hres == S_OK, "InitNew failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_INITIALIZED);
|
|
|
|
|
2009-02-02 15:27:24 +01:00
|
|
|
hres = IActiveScriptParse64_InitNew(parse);
|
2008-11-05 01:03:03 +01:00
|
|
|
ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres);
|
|
|
|
|
2008-11-05 01:03:19 +01:00
|
|
|
SET_EXPECT(OnStateChange_CONNECTED);
|
|
|
|
hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED);
|
|
|
|
ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres);
|
|
|
|
CHECK_CALLED(OnStateChange_CONNECTED);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_CONNECTED);
|
|
|
|
|
|
|
|
SET_EXPECT(OnStateChange_DISCONNECTED);
|
|
|
|
SET_EXPECT(OnStateChange_INITIALIZED);
|
2008-11-05 01:03:03 +01:00
|
|
|
SET_EXPECT(OnStateChange_CLOSED);
|
|
|
|
hres = IActiveScript_Close(script);
|
|
|
|
ok(hres == S_OK, "Close failed: %08x\n", hres);
|
2008-11-05 01:03:19 +01:00
|
|
|
CHECK_CALLED(OnStateChange_DISCONNECTED);
|
|
|
|
CHECK_CALLED(OnStateChange_INITIALIZED);
|
2008-11-05 01:03:03 +01:00
|
|
|
CHECK_CALLED(OnStateChange_CLOSED);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_CLOSED);
|
2009-12-30 19:49:45 +01:00
|
|
|
test_no_script_dispatch(script);
|
2008-11-05 01:03:03 +01:00
|
|
|
|
2009-02-02 15:27:24 +01:00
|
|
|
IUnknown_Release(parse);
|
2008-11-05 01:03:03 +01:00
|
|
|
|
2011-02-21 17:49:32 +01:00
|
|
|
ref = IActiveScript_Release(script);
|
|
|
|
ok(!ref, "ref = %d\n", ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_jscript_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','(',')',' ','{','}',0};
|
|
|
|
|
|
|
|
script = create_jscript();
|
|
|
|
|
|
|
|
hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parse);
|
|
|
|
ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
|
|
|
|
|
|
|
|
test_state(script, SCRIPTSTATE_UNINITIALIZED);
|
|
|
|
|
|
|
|
hres = IActiveScriptParse64_InitNew(parse);
|
|
|
|
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);
|
|
|
|
|
|
|
|
hres = IActiveScriptParse64_ParseScriptText(parse, script_textW, NULL, NULL, NULL, 0, 1, 0x42, NULL, NULL);
|
|
|
|
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");
|
|
|
|
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);
|
|
|
|
|
|
|
|
IUnknown_Release(parse);
|
|
|
|
|
|
|
|
ref = IActiveScript_Release(script);
|
2008-11-05 01:03:03 +01:00
|
|
|
ok(!ref, "ref = %d\n", ref);
|
|
|
|
}
|
|
|
|
|
2010-09-21 15:58:48 +02:00
|
|
|
static BOOL check_jscript(void)
|
|
|
|
{
|
|
|
|
IActiveScriptProperty *script_prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
|
|
|
|
&IID_IActiveScriptProperty, (void**)&script_prop);
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
IActiveScriptProperty_Release(script_prop);
|
|
|
|
|
|
|
|
return hres == S_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-24 21:53:14 +01:00
|
|
|
START_TEST(jscript)
|
|
|
|
{
|
|
|
|
CoInitialize(NULL);
|
|
|
|
|
2010-09-21 15:58:48 +02:00
|
|
|
if(check_jscript()) {
|
|
|
|
test_jscript();
|
|
|
|
test_jscript2();
|
2011-02-21 17:49:32 +01:00
|
|
|
test_jscript_uninitializing();
|
2010-09-21 15:58:48 +02:00
|
|
|
}else {
|
|
|
|
win_skip("Broken engine, probably too old\n");
|
|
|
|
}
|
2008-03-24 21:53:14 +01:00
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|