jscript/tests: add tests for IActiveScriptSite_OnScriptError. [try 2]
Reece Dunn
msclrhd at googlemail.com
Thu Oct 7 17:25:41 CDT 2010
This adds the core logic to test IActiveScriptSite_OnScriptError and
IActiveScriptError.
- Reece
-------------- next part --------------
From f3176b69d4cb6e4e99842d7b3cb567c21a166b4e Mon Sep 17 00:00:00 2001
From: Reece Dunn <msclrhd at gmail.com>
Date: Thu, 7 Oct 2010 22:28:14 +0100
Subject: [PATCH] jscript/tests: add tests for IActiveScriptSite_OnScriptError.
---
dlls/jscript/tests/run.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 125 insertions(+), 0 deletions(-)
diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c
index 4df315c..d0067e6 100644
--- a/dlls/jscript/tests/run.c
+++ b/dlls/jscript/tests/run.c
@@ -69,6 +69,7 @@ DEFINE_EXPECT(testobj_value);
DEFINE_EXPECT(testobj_prop_d);
DEFINE_EXPECT(testobj_noprop_d);
DEFINE_EXPECT(GetItemInfo_testVal);
+DEFINE_EXPECT(ActiveScriptSite_OnScriptError);
#define DISPID_GLOBAL_TESTPROPGET 0x1000
#define DISPID_GLOBAL_TESTPROPPUT 0x1001
@@ -94,6 +95,7 @@ static BOOL strict_dispid_check;
static const char *test_name = "(null)";
static IDispatch *script_disp;
static int invoke_version;
+static IActiveScriptError *script_error;
static BSTR a2bstr(const char *str)
{
@@ -689,6 +691,34 @@ static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
+static HRESULT WINAPI ActiveScriptSite_OnScriptError_CheckError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
+{
+ ok(pscripterror != NULL, "ActiveScriptSite_OnScriptError -- expected pscripterror to be set, got NULL\n");
+
+ script_error = pscripterror;
+ IUnknown_AddRef(script_error);
+
+ CHECK_EXPECT(ActiveScriptSite_OnScriptError);
+
+ return S_OK;
+}
+
+static const IActiveScriptSiteVtbl ActiveScriptSite_CheckErrorVtbl = {
+ ActiveScriptSite_QueryInterface,
+ ActiveScriptSite_AddRef,
+ ActiveScriptSite_Release,
+ ActiveScriptSite_GetLCID,
+ ActiveScriptSite_GetItemInfo,
+ ActiveScriptSite_GetDocVersionString,
+ ActiveScriptSite_OnScriptTerminate,
+ ActiveScriptSite_OnStateChange,
+ ActiveScriptSite_OnScriptError_CheckError,
+ ActiveScriptSite_OnEnterScript,
+ ActiveScriptSite_OnLeaveScript
+};
+
+static IActiveScriptSite ActiveScriptSite_CheckError = { &ActiveScriptSite_CheckErrorVtbl };
+
static HRESULT set_script_prop(IActiveScript *engine, DWORD property, VARIANT *val)
{
IActiveScriptProperty *script_prop;
@@ -812,6 +842,87 @@ static HRESULT parse_htmlscript(BSTR script_str)
return hres;
}
+static void parse_script_with_error(DWORD flags, BSTR script_str, SCODE errorcode)
+{
+ IActiveScriptParse *parser;
+ IActiveScript *engine;
+ HRESULT hres;
+ EXCEPINFO excep;
+
+ engine = create_script();
+ if(!engine)
+ return;
+
+ 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 = IActiveScriptParse64_InitNew(parser);
+ ok(hres == S_OK, "InitNew failed: %08x\n", hres);
+
+ hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite_CheckError);
+ 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");
+
+ script_error = NULL;
+ SET_EXPECT(ActiveScriptSite_OnScriptError);
+ hres = IActiveScriptParse64_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
+ todo_wine ok(hres == 0x80020101, "parse_script_with_error should have returned 0x80020101, got: 0x%08x\n", hres);
+ todo_wine CHECK_CALLED(ActiveScriptSite_OnScriptError);
+ if (!script_error)
+ goto end;
+
+ /* IActiveScriptError_GetSourcePosition */
+
+ hres = IActiveScriptError_GetSourcePosition(script_error, NULL, NULL, NULL);
+ ok(hres == S_OK, "IActiveScriptError_GetSourcePosition -- hres: expected S_OK, got 0x%08x\n", hres);
+
+ /* IActiveScriptError_GetSourceLineText */
+
+ hres = IActiveScriptError_GetSourceLineText(script_error, NULL);
+ ok(hres == E_POINTER, "IActiveScriptError_GetSourceLineText -- hres: expected E_POINTER, got 0x%08x\n", hres);
+
+ /* IActiveScriptError_GetExceptionInfo */
+
+ hres = IActiveScriptError_GetExceptionInfo(script_error, NULL);
+ ok(hres == E_POINTER, "IActiveScriptError_GetExceptionInfo -- hres: expected E_POINTER, got 0x%08x\n", hres);
+
+ excep.wCode = 0xdead;
+ excep.scode = 0xdeadbeef;
+
+ hres = IActiveScriptError_GetExceptionInfo(script_error, &excep);
+ ok(hres == S_OK, "IActiveScriptError_GetExceptionInfo -- hres: expected S_OK, got 0x%08x\n", hres);
+
+ ok(excep.wCode == 0, "IActiveScriptError_GetExceptionInfo -- excep.wCode: expected 0, got 0x%08x\n", excep.wCode);
+ ok(excep.scode == errorcode, "IActiveScriptError_GetExceptionInfo -- excep.scode: expected 0x%08x, got 0x%08x\n", errorcode, excep.scode);
+
+ SysFreeString(excep.bstrSource);
+ SysFreeString(excep.bstrDescription);
+ SysFreeString(excep.bstrHelpFile);
+
+ IUnknown_Release(script_error);
+
+end:
+ IDispatch_Release(script_disp);
+ IActiveScript_Release(engine);
+ IUnknown_Release(parser);
+}
+
static void parse_script_af(DWORD flags, const char *src)
{
BSTR tmp;
@@ -828,6 +939,15 @@ static void parse_script_a(const char *src)
parse_script_af(SCRIPTITEM_GLOBALMEMBERS, src);
}
+static void parse_script_with_error_a(const char *src, SCODE errorcode)
+{
+ BSTR tmp;
+
+ tmp = a2bstr(src);
+ parse_script_with_error(SCRIPTITEM_GLOBALMEMBERS, tmp, errorcode);
+ SysFreeString(tmp);
+}
+
static HRESULT parse_htmlscript_a(const char *src)
{
HRESULT hres;
@@ -1086,6 +1206,11 @@ static void run_tests(void)
ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
hres = parse_htmlscript_a("var a=1;\nif(a\n-->0) a=5;\n");
ok(hres != S_OK, "ParseScriptText have not failed\n");
+
+ parse_script_with_error_a("?", 0x800a03ea);
+ parse_script_with_error_a("new 3;", 0x800a01bd);
+ parse_script_with_error_a("new null;", 0x800a138f);
+ parse_script_with_error_a("var a=1;\nif(a\n-->0) a=5;\n", 0x800a03ee);
}
static BOOL check_jscript(void)
--
1.7.0.4
More information about the wine-patches
mailing list