jscript: Added infrastructure for test scripts.

This commit is contained in:
Jacek Caban 2008-09-09 01:25:23 +02:00 committed by Alexandre Julliard
parent a16f205382
commit b60898353c
4 changed files with 129 additions and 5 deletions

View File

@ -9,6 +9,8 @@ CTESTS = \
jscript.c \ jscript.c \
run.c run.c
RC_SRCS = rsrc.rc
@MAKE_TEST_RULES@ @MAKE_TEST_RULES@
@DEPENDENCIES@ # everything below this line is overwritten by make depend @DEPENDENCIES@ # everything below this line is overwritten by make depend

View File

@ -0,0 +1,21 @@
/*
* 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
*/
ok(true, "true is not true?");
reportSuccess();

View File

@ -0,0 +1,20 @@
/*
* 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
*/
/* @makedep: lang.js */
lang.js 40 "lang.js"

View File

@ -67,9 +67,14 @@ DEFINE_EXPECT(global_success_i);
#define DISPID_GLOBAL_TESTPROPGET 0x1000 #define DISPID_GLOBAL_TESTPROPGET 0x1000
#define DISPID_GLOBAL_TESTPROPPUT 0x1001 #define DISPID_GLOBAL_TESTPROPPUT 0x1001
#define DISPID_GLOBAL_REPORTSUCCESS 0x1002 #define DISPID_GLOBAL_REPORTSUCCESS 0x1002
#define DISPID_GLOBAL_TRACE 0x1003
#define DISPID_GLOBAL_OK 0x1004
static const WCHAR testW[] = {'t','e','s','t',0}; static const WCHAR testW[] = {'t','e','s','t',0};
static BOOL strict_dispid_check;
static const char *test_name = "(null)";
static const char *debugstr_w(LPCWSTR str) static const char *debugstr_w(LPCWSTR str)
{ {
static char buf[1024]; static char buf[1024];
@ -191,6 +196,16 @@ static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown
static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid) static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
{ {
if(!strcmp_wa(bstrName, "ok")) {
ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
*pid = DISPID_GLOBAL_OK;
return S_OK;
}
if(!strcmp_wa(bstrName, "trace")) {
ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
*pid = DISPID_GLOBAL_TRACE;
return S_OK;
}
if(!strcmp_wa(bstrName, "reportSuccess")) { if(!strcmp_wa(bstrName, "reportSuccess")) {
CHECK_EXPECT(global_success_d); CHECK_EXPECT(global_success_d);
ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex); ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
@ -210,16 +225,49 @@ static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD
return S_OK; return S_OK;
} }
ok(0, "unexpected call %s\n", debugstr_w(bstrName)); if(strict_dispid_check)
ok(0, "unexpected call %s\n", debugstr_w(bstrName));
return DISP_E_UNKNOWNNAME; return DISP_E_UNKNOWNNAME;
} }
static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp, static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller) VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
{ {
switch(id) { switch(id) {
case DISPID_GLOBAL_REPORTSUCCESS: case DISPID_GLOBAL_OK:
CHECK_EXPECT(global_success_i); ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
ok(pdp != NULL, "pdp == NULL\n");
ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
ok(!pvarRes, "pvarRes != NULL\n");
ok(pei != NULL, "pei == NULL\n");
ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
ok(V_BOOL(pdp->rgvarg+1), "%s: %s\n", test_name, debugstr_w(V_BSTR(pdp->rgvarg)));
return S_OK;
case DISPID_GLOBAL_TRACE:
ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
ok(pdp != NULL, "pdp == NULL\n");
ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
ok(!pvarRes, "pvarRes != NULL\n");
ok(pei != NULL, "pei == NULL\n");
ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
if(V_VT(pdp->rgvarg) == VT_BSTR)
trace("%s: %s\n", test_name, debugstr_w(V_BSTR(pdp->rgvarg)));
return S_OK;
case DISPID_GLOBAL_REPORTSUCCESS:
CHECK_EXPECT(global_success_i);
ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags); ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
ok(pdp != NULL, "pdp == NULL\n"); ok(pdp != NULL, "pdp == NULL\n");
@ -266,7 +314,7 @@ static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid,
return S_OK; return S_OK;
} }
ok(0, "unexpected call %x\n", id); ok(0, "unexpected call %x\n", id);
return DISP_E_MEMBERNOTFOUND; return DISP_E_MEMBERNOTFOUND;
} }
@ -433,8 +481,39 @@ static void parse_script_a(const char *src)
SysFreeString(tmp); SysFreeString(tmp);
} }
static void run_from_res(const char *name)
{
const char *data;
DWORD size, len;
BSTR str;
HRSRC src;
strict_dispid_check = FALSE;
test_name = name;
src = FindResourceA(NULL, name, (LPCSTR)40);
ok(src != NULL, "Could not find resource %s\n", name);
size = SizeofResource(NULL, src);
data = LoadResource(NULL, src);
len = MultiByteToWideChar(CP_ACP, 0, data, size, NULL, 0);
str = SysAllocStringLen(NULL, len-1);
len = MultiByteToWideChar(CP_ACP, 0, data, size, str, len);
SET_EXPECT(global_success_d);
SET_EXPECT(global_success_i);
parse_script(str);
CHECK_CALLED(global_success_d);
CHECK_CALLED(global_success_i);
SysFreeString(str);
}
static void run_tests(void) static void run_tests(void)
{ {
strict_dispid_check = TRUE;
parse_script_a(""); parse_script_a("");
parse_script_a("/* empty */ ;"); parse_script_a("/* empty */ ;");
@ -455,6 +534,8 @@ static void run_tests(void)
parse_script_a("reportSuccess();"); parse_script_a("reportSuccess();");
CHECK_CALLED(global_success_d); CHECK_CALLED(global_success_d);
CHECK_CALLED(global_success_i); CHECK_CALLED(global_success_i);
run_from_res("lang.js");
} }
START_TEST(run) START_TEST(run)