Signed-off-by: Jactry Zeng jzeng@codeweavers.com --- dlls/msscript.ocx/msscript.c | 41 ++++++----- dlls/msscript.ocx/tests/msscript.c | 105 +++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 17 deletions(-)
diff --git a/dlls/msscript.ocx/msscript.c b/dlls/msscript.ocx/msscript.c index 49040b9455..e8259f7d48 100644 --- a/dlls/msscript.ocx/msscript.c +++ b/dlls/msscript.ocx/msscript.c @@ -981,37 +981,44 @@ static HRESULT WINAPI ScriptControl_Reset(IScriptControl *iface) return set_script_state(This->host, SCRIPTSTATE_INITIALIZED, FALSE); }
+static HRESULT parse_script_text(ScriptControl *control, BSTR script_text, DWORD flag, VARIANT *res) +{ + EXCEPINFO excepinfo; + HRESULT hr; + + if (!control->host || control->state != Initialized) + return E_FAIL; + + hr = set_script_state(control->host, SCRIPTSTATE_STARTED, TRUE); + if (FAILED(hr)) + return hr; + + hr = IActiveScriptParse_ParseScriptText(control->host->parse, script_text, NULL, + NULL, NULL, 0, 1, flag, res, &excepinfo); + /* FIXME: more error handling */ + return hr; +} + static HRESULT WINAPI ScriptControl_AddCode(IScriptControl *iface, BSTR code) { ScriptControl *This = impl_from_IScriptControl(iface); - FIXME("(%p)->(%s)\n", This, debugstr_w(code)); - return E_NOTIMPL; + + TRACE("(%p)->(%s).\n", This, debugstr_w(code)); + + return parse_script_text(This, code, SCRIPTTEXT_ISVISIBLE, NULL); }
static HRESULT WINAPI ScriptControl_Eval(IScriptControl *iface, BSTR expression, VARIANT *res) { ScriptControl *This = impl_from_IScriptControl(iface); - EXCEPINFO excepinfo; - HRESULT hr;
- FIXME("(%p)->(%s %p)\n", This, debugstr_w(expression), res); + TRACE("(%p)->(%s %p).\n", This, debugstr_w(expression), res);
if (!res) return E_POINTER; V_VT(res) = VT_EMPTY;
- if (!This->host || This->state != Initialized) - return E_FAIL; - - hr = set_script_state(This->host, SCRIPTSTATE_STARTED, TRUE); - if (FAILED(hr)) - return hr; - - hr = IActiveScriptParse_ParseScriptText(This->host->parse, expression, NULL, NULL, NULL, - 0, 1, SCRIPTTEXT_ISEXPRESSION, res, &excepinfo); - /* FIXME: more error handling */ - - return hr; + return parse_script_text(This, expression, SCRIPTTEXT_ISEXPRESSION, res); }
static HRESULT WINAPI ScriptControl_ExecuteStatement(IScriptControl *iface, BSTR statement) diff --git a/dlls/msscript.ocx/tests/msscript.c b/dlls/msscript.ocx/tests/msscript.c index 8ed4af2e6f..0bdca22f43 100644 --- a/dlls/msscript.ocx/tests/msscript.c +++ b/dlls/msscript.ocx/tests/msscript.c @@ -1572,6 +1572,110 @@ static void test_IScriptControl_Eval(void) skip("Could not register TestScript engine.\n"); }
+static void test_IScriptControl_AddCode(void) +{ + BSTR code_str, language; + IScriptControl *sc; + VARIANT var; + HRESULT hr; + + hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, + &IID_IScriptControl, (void **)&sc); + ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr); + + code_str = a2bstr("1 + 1"); + hr = IScriptControl_AddCode(sc, code_str); + ok(hr == E_FAIL, "IScriptControl_AddCode returned: 0x%08x.\n", hr); + SysFreeString(code_str); + + hr = IScriptControl_AddCode(sc, NULL); + ok(hr == E_FAIL, "IScriptControl_AddCode returned: 0x%08x.\n", hr); + + language = a2bstr("jscript"); + hr = IScriptControl_put_Language(sc, language); + ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr); + SysFreeString(language); + + code_str = a2bstr("1 + 1"); + hr = IScriptControl_AddCode(sc, code_str); + ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr); + SysFreeString(code_str); + todo_wine CHECK_ERROR(sc, 0); + + code_str = a2bstr("invalid syntax"); + hr = IScriptControl_AddCode(sc, code_str); + todo_wine ok(hr == 0x800a03ec, "IScriptControl_AddCode returned: 0x%08x.\n", hr); + SysFreeString(code_str); + todo_wine CHECK_ERROR(sc, 1004); + + IScriptControl_Release(sc); + + /* custom script engine */ + if (register_script_engine()) + { + hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, + &IID_IScriptControl, (void **)&sc); + ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr); + + SET_EXPECT(CreateInstance); + SET_EXPECT(SetInterfaceSafetyOptions); + SET_EXPECT(SetScriptSite); + SET_EXPECT(QI_IActiveScriptParse); + SET_EXPECT(InitNew); + + language = a2bstr("testscript"); + hr = IScriptControl_put_Language(sc, language); + ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr); + SysFreeString(language); + + CHECK_CALLED(CreateInstance); + CHECK_CALLED(SetInterfaceSafetyOptions); + CHECK_CALLED(SetScriptSite); + CHECK_CALLED(QI_IActiveScriptParse); + CHECK_CALLED(InitNew); + + SET_EXPECT(SetScriptState_STARTED); + SET_EXPECT(ParseScriptText); + code_str = a2bstr("1 + 1"); + hr = IScriptControl_AddCode(sc, code_str); + ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr); + SysFreeString(code_str); + CHECK_CALLED(SetScriptState_STARTED); + CHECK_CALLED(ParseScriptText); + + SET_EXPECT(ParseScriptText); + code_str = a2bstr("0x100"); + hr = IScriptControl_AddCode(sc, code_str); + ok(hr == S_OK, "IScriptControl_AddCode failed: 0x%08x.\n", hr); + SysFreeString(code_str); + CHECK_CALLED(ParseScriptText); + + /* Call Eval() after AddCode() for checking if it will call SetScriptState() again. */ + SET_EXPECT(ParseScriptText); + code_str = a2bstr("var2 = 10 + var1"); + V_VT(&var) = VT_NULL; + V_I4(&var) = 0xdeadbeef; + hr = IScriptControl_Eval(sc, code_str, &var); + ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr); + ok((V_VT(&var) == VT_EMPTY) && (V_I4(&var) == 0xdeadbeef), "V_VT(var) = %d, V_I4(var) = %d.\n", + V_VT(&var), V_I4(&var)); + SysFreeString(code_str); + CHECK_CALLED(ParseScriptText); + + IActiveScriptSite_Release(site); + + init_registry(FALSE); + + SET_EXPECT(Close); + + IScriptControl_Release(sc); + + CHECK_CALLED(Close); + } + else + skip("Could not register TestScript engine.\n"); +} + START_TEST(msscript) { IUnknown *unk; @@ -1602,6 +1706,7 @@ START_TEST(msscript) test_UseSafeSubset(); test_State(); test_IScriptControl_Eval(); + test_IScriptControl_AddCode();
CoUninitialize(); }