vbscript: Added beginning script running tests.
This commit is contained in:
parent
8906a4aa62
commit
c03cecab39
|
@ -1,7 +1,8 @@
|
|||
TESTDLL = vbscript.dll
|
||||
IMPORTS = ole32
|
||||
IMPORTS = oleaut32 ole32
|
||||
|
||||
C_SRCS = \
|
||||
run.c \
|
||||
vbscript.c
|
||||
|
||||
@MAKE_TEST_RULES@
|
||||
|
|
|
@ -0,0 +1,498 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define COBJMACROS
|
||||
#define CONST_VTABLE
|
||||
|
||||
#include <ole2.h>
|
||||
#include <dispex.h>
|
||||
#include <activscp.h>
|
||||
|
||||
#include "wine/test.h"
|
||||
|
||||
extern const CLSID CLSID_VBScript;
|
||||
|
||||
#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(global_success_d);
|
||||
DEFINE_EXPECT(global_success_i);
|
||||
|
||||
#define DISPID_GLOBAL_REPORTSUCCESS 1000
|
||||
|
||||
static const WCHAR testW[] = {'t','e','s','t',0};
|
||||
|
||||
static BOOL strict_dispid_check;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static int strcmp_wa(LPCWSTR strw, const char *stra)
|
||||
{
|
||||
CHAR buf[512];
|
||||
WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
|
||||
return lstrcmpA(buf, stra);
|
||||
}
|
||||
|
||||
|
||||
#define test_grfdex(a,b) _test_grfdex(__LINE__,a,b)
|
||||
static void _test_grfdex(unsigned line, DWORD grfdex, DWORD expect)
|
||||
{
|
||||
ok_(__FILE__,line)(grfdex == expect, "grfdex = %x, expected %x\n", grfdex, expect);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
|
||||
{
|
||||
*ppv = NULL;
|
||||
|
||||
if(IsEqualGUID(riid, &IID_IUnknown)
|
||||
|| IsEqualGUID(riid, &IID_IDispatch)
|
||||
|| IsEqualGUID(riid, &IID_IDispatchEx))
|
||||
*ppv = iface;
|
||||
else
|
||||
return E_NOINTERFACE;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
|
||||
{
|
||||
ok(0, "unexpected call\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
|
||||
LCID lcid, ITypeInfo **ppTInfo)
|
||||
{
|
||||
ok(0, "unexpected call\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
|
||||
LPOLESTR *rgszNames, UINT cNames,
|
||||
LCID lcid, DISPID *rgDispId)
|
||||
{
|
||||
ok(0, "unexpected call\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
|
||||
REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
|
||||
VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
|
||||
{
|
||||
ok(0, "unexpected call\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
|
||||
{
|
||||
ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
|
||||
{
|
||||
ok(0, "unexpected call\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
|
||||
{
|
||||
ok(0, "unexpected call\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
|
||||
{
|
||||
ok(0, "unexpected call\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
|
||||
{
|
||||
ok(0, "unexpected call\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
|
||||
{
|
||||
ok(0, "unexpected call\n");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
|
||||
static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
|
||||
{
|
||||
if(!strcmp_wa(bstrName, "reportSuccess")) {
|
||||
CHECK_EXPECT(global_success_d);
|
||||
test_grfdex(grfdex, fdexNameCaseInsensitive);
|
||||
*pid = DISPID_GLOBAL_REPORTSUCCESS;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
if(strict_dispid_check && strcmp_wa(bstrName, "x"))
|
||||
ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
|
||||
return DISP_E_UNKNOWNNAME;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
|
||||
VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
|
||||
{
|
||||
switch(id) {
|
||||
case DISPID_GLOBAL_REPORTSUCCESS:
|
||||
CHECK_EXPECT(global_success_i);
|
||||
|
||||
ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
|
||||
ok(pdp != NULL, "pdp == NULL\n");
|
||||
ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
|
||||
ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
|
||||
ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
|
||||
ok(!pvarRes, "pvarRes != NULL\n");
|
||||
ok(pei != NULL, "pei == NULL\n");
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
ok(0, "unexpected call %d\n", id);
|
||||
return DISP_E_MEMBERNOTFOUND;
|
||||
}
|
||||
|
||||
static IDispatchExVtbl GlobalVtbl = {
|
||||
DispatchEx_QueryInterface,
|
||||
DispatchEx_AddRef,
|
||||
DispatchEx_Release,
|
||||
DispatchEx_GetTypeInfoCount,
|
||||
DispatchEx_GetTypeInfo,
|
||||
DispatchEx_GetIDsOfNames,
|
||||
DispatchEx_Invoke,
|
||||
Global_GetDispID,
|
||||
Global_InvokeEx,
|
||||
DispatchEx_DeleteMemberByName,
|
||||
DispatchEx_DeleteMemberByDispID,
|
||||
DispatchEx_GetMemberProperties,
|
||||
DispatchEx_GetMemberName,
|
||||
DispatchEx_GetNextDispID,
|
||||
DispatchEx_GetNameSpaceParent
|
||||
};
|
||||
|
||||
static IDispatchEx Global = { &GlobalVtbl };
|
||||
|
||||
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)
|
||||
{
|
||||
*plcid = GetUserDefaultLCID();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
|
||||
DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
|
||||
{
|
||||
ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
|
||||
ok(!ppti, "ppti != NULL\n");
|
||||
|
||||
if(strcmp_wa(pstrName, "test"))
|
||||
ok(0, "unexpected pstrName %s\n", wine_dbgstr_w(pstrName));
|
||||
|
||||
*ppiunkItem = (IUnknown*)&Global;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
|
||||
const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
#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 };
|
||||
|
||||
static IActiveScript *create_script(void)
|
||||
{
|
||||
IActiveScript *script;
|
||||
HRESULT hres;
|
||||
|
||||
hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
|
||||
&IID_IActiveScript, (void**)&script);
|
||||
ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
|
||||
|
||||
return script;
|
||||
}
|
||||
|
||||
static HRESULT parse_script(DWORD flags, BSTR script_str)
|
||||
{
|
||||
IActiveScriptParse *parser;
|
||||
IActiveScript *engine;
|
||||
IDispatch *script_disp;
|
||||
HRESULT hres;
|
||||
|
||||
engine = create_script();
|
||||
if(!engine)
|
||||
return S_OK;
|
||||
|
||||
hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
|
||||
ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
|
||||
if (FAILED(hres))
|
||||
{
|
||||
IActiveScript_Release(engine);
|
||||
return hres;
|
||||
}
|
||||
|
||||
hres = IActiveScriptParse64_InitNew(parser);
|
||||
ok(hres == S_OK, "InitNew failed: %08x\n", hres);
|
||||
|
||||
hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
|
||||
ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
|
||||
|
||||
hres = IActiveScript_AddNamedItem(engine, testW,
|
||||
SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|flags);
|
||||
ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
|
||||
|
||||
hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
|
||||
ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
|
||||
|
||||
hres = IActiveScript_GetScriptDispatch(engine, NULL, &script_disp);
|
||||
ok(hres == S_OK, "GetScriptDispatch failed: %08x\n", hres);
|
||||
ok(script_disp != NULL, "script_disp == NULL\n");
|
||||
ok(script_disp != (IDispatch*)&Global, "script_disp == Global\n");
|
||||
|
||||
hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
|
||||
|
||||
IDispatch_Release(script_disp);
|
||||
IActiveScript_Release(engine);
|
||||
IUnknown_Release(parser);
|
||||
|
||||
return hres;
|
||||
}
|
||||
|
||||
static void parse_script_af(DWORD flags, const char *src)
|
||||
{
|
||||
BSTR tmp;
|
||||
HRESULT hres;
|
||||
|
||||
tmp = a2bstr(src);
|
||||
hres = parse_script(flags, tmp);
|
||||
SysFreeString(tmp);
|
||||
ok(hres == S_OK, "parse_script failed: %08x\n", hres);
|
||||
}
|
||||
|
||||
static void parse_script_a(const char *src)
|
||||
{
|
||||
parse_script_af(SCRIPTITEM_GLOBALMEMBERS, src);
|
||||
}
|
||||
|
||||
static BSTR get_script_from_file(const char *filename)
|
||||
{
|
||||
DWORD size, len;
|
||||
HANDLE file, map;
|
||||
const char *file_map;
|
||||
BSTR ret;
|
||||
|
||||
file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
|
||||
if(file == INVALID_HANDLE_VALUE) {
|
||||
trace("Could not open file: %u\n", GetLastError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size = GetFileSize(file, NULL);
|
||||
|
||||
map = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
|
||||
CloseHandle(file);
|
||||
if(map == INVALID_HANDLE_VALUE) {
|
||||
trace("Could not create file mapping: %u\n", GetLastError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
|
||||
CloseHandle(map);
|
||||
if(!file_map) {
|
||||
trace("MapViewOfFile failed: %u\n", GetLastError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = MultiByteToWideChar(CP_ACP, 0, file_map, size, NULL, 0);
|
||||
ret = SysAllocStringLen(NULL, len);
|
||||
MultiByteToWideChar(CP_ACP, 0, file_map, size, ret, len);
|
||||
|
||||
UnmapViewOfFile(file_map);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void run_from_file(const char *filename)
|
||||
{
|
||||
BSTR script_str;
|
||||
HRESULT hres;
|
||||
|
||||
script_str = get_script_from_file(filename);
|
||||
if(!script_str)
|
||||
return;
|
||||
|
||||
strict_dispid_check = FALSE;
|
||||
hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, script_str);
|
||||
SysFreeString(script_str);
|
||||
ok(hres == S_OK, "parse_script failed: %08x\n", hres);
|
||||
}
|
||||
|
||||
static void run_tests(void)
|
||||
{
|
||||
strict_dispid_check = TRUE;
|
||||
|
||||
parse_script_a("");
|
||||
}
|
||||
|
||||
static BOOL check_vbscript(void)
|
||||
{
|
||||
IActiveScript *vbscript;
|
||||
HRESULT hres;
|
||||
|
||||
hres = CoCreateInstance(&CLSID_VBScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
|
||||
&IID_IActiveScript, (void**)&vbscript);
|
||||
if(SUCCEEDED(hres))
|
||||
IActiveScript_Release(vbscript);
|
||||
|
||||
return hres == S_OK;
|
||||
}
|
||||
|
||||
START_TEST(run)
|
||||
{
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
argc = winetest_get_mainargs(&argv);
|
||||
|
||||
CoInitialize(NULL);
|
||||
|
||||
if(!check_vbscript()) {
|
||||
win_skip("Broken engine, probably too old\n");
|
||||
}else if(argc > 2) {
|
||||
run_from_file(argv[2]);
|
||||
}else {
|
||||
run_tests();
|
||||
}
|
||||
|
||||
CoUninitialize();
|
||||
}
|
Loading…
Reference in New Issue