Commit a489b7ef authored by Michael Stefaniuc's avatar Michael Stefaniuc Committed by Alexandre Julliard

vbscript/tests: Avoid using a2bstr() in the run.c helpers.

parent 23e2eb39
......@@ -2118,23 +2118,23 @@ static HRESULT parse_script(DWORD flags, BSTR script_str, const WCHAR *delim)
return hres;
}
static void parse_script_af(DWORD flags, const char *src)
static void parse_script_wf(DWORD flags, const WCHAR *src)
{
BSTR tmp;
HRESULT hres;
tmp = a2bstr(src);
tmp = SysAllocString(src);
hres = parse_script(flags, tmp, NULL);
SysFreeString(tmp);
ok(hres == S_OK, "parse_script failed: %08lx\n", hres);
}
static HRESULT parse_script_ar(const char *src)
static HRESULT parse_script_wr(const WCHAR *src)
{
BSTR tmp;
HRESULT hres;
tmp = a2bstr(src);
tmp = SysAllocString(src);
hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, tmp, NULL);
SysFreeString(tmp);
return hres;
......@@ -2196,31 +2196,31 @@ static void test_parse_context(void)
ok(global_ref == 1, "global_ref = %lu\n", global_ref);
}
static void parse_script_a(const char *src)
static void parse_script_w(const WCHAR *src)
{
parse_script_af(SCRIPTITEM_GLOBALMEMBERS, src);
parse_script_wf(SCRIPTITEM_GLOBALMEMBERS, src);
}
#define parse_htmlscript_a(a) _parse_htmlscript_a(__LINE__,a)
static void _parse_htmlscript_a(unsigned line, const char *src)
#define parse_htmlscript(a) _parse_htmlscript(__LINE__,a)
static void _parse_htmlscript(unsigned line, const WCHAR *src)
{
BSTR tmp;
HRESULT hres;
tmp = a2bstr(src);
tmp = SysAllocString(src);
hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, tmp, L"</SCRIPT>");
SysFreeString(tmp);
ok_(__FILE__,line)(hres == S_OK, "parse_script failed: %08lx\n", hres);
}
static IDispatchEx *parse_procedure(IActiveScriptParseProcedure2 *parse_proc, const char *src, DWORD flags)
static IDispatchEx *parse_procedure(IActiveScriptParseProcedure2 *parse_proc, const WCHAR *src, DWORD flags)
{
IDispatchEx *dispex;
IDispatch *disp;
BSTR str;
HRESULT hres;
str = a2bstr(src);
str = SysAllocString(src);
hres = IActiveScriptParseProcedure2_ParseProcedureText(parse_proc, str, NULL, L"", NULL, NULL, L"\"", 0, 0,
SCRIPTPROC_HOSTMANAGESSOURCE|SCRIPTPROC_IMPLICIT_THIS|SCRIPTPROC_IMPLICIT_PARENTS|flags, &disp);
SysFreeString(str);
......@@ -2256,7 +2256,7 @@ static void test_procedures(void)
ok(hres == S_OK, "ParseProcedureText failed: %08lx\n", hres);
IDispatch_Release(disp);
proc = parse_procedure(parse_proc, "dim x\nif true then x=false", 0);
proc = parse_procedure(parse_proc, L"dim x\nif true then x=false", 0);
SET_EXPECT(OnEnterScript);
SET_EXPECT(OnLeaveScript);
......@@ -2268,7 +2268,7 @@ static void test_procedures(void)
VariantClear(&v);
IDispatchEx_Release(proc);
proc = parse_procedure(parse_proc, "\"foobar\"", SCRIPTPROC_ISEXPRESSION);
proc = parse_procedure(parse_proc, L"\"foobar\"", SCRIPTPROC_ISEXPRESSION);
SET_EXPECT(OnEnterScript);
SET_EXPECT(OnLeaveScript);
......@@ -2458,7 +2458,7 @@ static void test_callbacks(void)
store_script_error = &error1;
SET_EXPECT(OnScriptError);
hres = parse_script_ar("throwException &h80004002&");
hres = parse_script_wr(L"throwException &h80004002&");
ok(hres == MAKE_VBSERROR(430), "got error: %08lx\n", hres);
CHECK_CALLED(OnScriptError);
......@@ -2484,7 +2484,7 @@ static void test_callbacks(void)
store_script_error = &error1;
SET_EXPECT(OnScriptError);
hres = parse_script_ar("throwException &h80004002&, \"test src\"");
hres = parse_script_wr(L"throwException &h80004002&, \"test src\"");
ok(hres == MAKE_VBSERROR(430), "got error: %08lx\n", hres);
CHECK_CALLED(OnScriptError);
......@@ -2509,7 +2509,7 @@ static void test_callbacks(void)
store_script_error = &error1;
SET_EXPECT(OnScriptError);
hres = parse_script_ar("throwException &h80004002&, , \"test desc\"");
hres = parse_script_wr(L"throwException &h80004002&, , \"test desc\"");
ok(hres == E_NOINTERFACE, "got error: %08lx\n", hres);
CHECK_CALLED(OnScriptError);
......@@ -2534,7 +2534,7 @@ static void test_callbacks(void)
store_script_error = &error1;
SET_EXPECT(OnScriptError);
hres = parse_script_ar("throwException &h80004002&, \"test src\", \"test desc\"");
hres = parse_script_wr(L"throwException &h80004002&, \"test src\", \"test desc\"");
ok(hres == E_NOINTERFACE, "got error: %08lx\n", hres);
CHECK_CALLED(OnScriptError);
......@@ -2559,7 +2559,7 @@ static void test_callbacks(void)
store_script_error = &error1;
SET_EXPECT(OnScriptError);
hres = parse_script_ar("throwException &h8000FFFF&");
hres = parse_script_wr(L"throwException &h8000FFFF&");
ok(hres == E_UNEXPECTED, "got error: %08lx\n", hres);
CHECK_CALLED(OnScriptError);
......@@ -2644,7 +2644,7 @@ static void test_parse_errors(void)
{
static const struct
{
const char *src;
const WCHAR *src;
unsigned error_line;
int error_char;
}
......@@ -2652,49 +2652,49 @@ static void test_parse_errors(void)
{
{
/* If...End If */
"If 0 > 1 Then\n"
L"If 0 > 1 Then\n"
" x = 0 End If\n",
1, 10
},
{
/* While...End While */
"While False\n"
L"While False\n"
" x = 0 End While\n",
1, 10
},
{
/* While...Wend */
"While False\n"
L"While False\n"
" x = 0 Wend\n",
1, 10
},
{
/* Do While...Loop */
"Do While False\n"
L"Do While False\n"
" x = 0 Loop\n",
1, 10
},
{
/* Do Until...Loop */
"Do Until True\n"
L"Do Until True\n"
" x = 0 Loop\n",
1, 10
},
{
/* Do...Loop While */
"Do\n"
L"Do\n"
" x = 0 Loop While False\n",
1, 10
},
{
/* Do...Loop Until */
"Do\n"
L"Do\n"
" x = 0 Loop Until True\n",
1, 10
},
{
/* Select...End Select */
"x = False\n"
L"x = False\n"
"Select Case 42\n"
" Case 0\n"
" Call ok(False, \"unexpected case\")\n"
......@@ -2705,35 +2705,35 @@ static void test_parse_errors(void)
},
{
/* Class...End Class (empty) */
"Class C End Class",
L"Class C End Class",
0, 8
},
{
/* Class...End Class (empty) */
"Class C _\nEnd Class",
L"Class C _\nEnd Class",
1, 0
},
{
/* invalid use of parentheses for call statement */
"strcomp(\"x\", \"y\")",
L"strcomp(\"x\", \"y\")",
0, -17
},
{
"\n\n\n cint _\n throwInt(&h80001234&)",
L"\n\n\n cint _\n throwInt(&h80001234&)",
3, 2
},
{
"dim x\n"
L"dim x\n"
"if true then throwInt(&h80001234&)",
1, 13
},
{
"dim x\n"
L"dim x\n"
"if x = throwInt(&h80001234&) then x = 1",
1, 0
},
{
"sub test\n"
L"sub test\n"
" dim x\n"
" if x = throwInt(&h80001234&) then x = 1\n"
"end sub\n"
......@@ -2741,14 +2741,14 @@ static void test_parse_errors(void)
2, 4
},
{
"dim x\n"
L"dim x\n"
"do\n"
" x = 1\n"
"loop until throwInt(&h80001234&)\n",
3, 0
},
{
"\n select case 3\n"
L"\n select case 3\n"
" case 2\n"
" ok false, \"unexpected case\"\n"
" case throwInt(&h80001234&)\n"
......@@ -2757,7 +2757,7 @@ static void test_parse_errors(void)
1, 2
},
{
"if false then\n"
L"if false then\n"
" ok false, \"unexpected case\"\n"
" elseif throwInt(&h80001234&) then\n"
" throwInt &h87001234&\n"
......@@ -2777,7 +2777,7 @@ static void test_parse_errors(void)
onerror_hres = S_OK;
SET_EXPECT(OnScriptError);
hres = parse_script_ar(invalid_scripts[i].src);
hres = parse_script_wr(invalid_scripts[i].src);
ok(hres == SCRIPT_E_REPORTED, "[%u] script returned: %08lx\n", i, hres);
CHECK_CALLED(OnScriptError);
......@@ -2798,7 +2798,7 @@ static void test_msgbox(void)
SET_EXPECT(GetUIBehavior);
SET_EXPECT(GetWindow);
SET_EXPECT(EnableModeless);
hres = parse_script_ar("MsgBox \"testing...\"");
hres = parse_script_wr(L"MsgBox \"testing...\"");
CLEAR_CALLED(GetUIBehavior);
CLEAR_CALLED(GetWindow);
CLEAR_CALLED(EnableModeless);
......@@ -2808,11 +2808,11 @@ static void test_msgbox(void)
}
SET_EXPECT(GetUIBehavior);
parse_script_a("dim r\n r=MsgBox(\"testing...\")\n Call ok(r=0, \"r=\"&r)");
parse_script_w(L"dim r\n r=MsgBox(\"testing...\")\n Call ok(r=0, \"r=\"&r)");
CHECK_CALLED(GetUIBehavior);
SET_EXPECT(GetUIBehavior);
parse_script_a("MsgBox 10");
parse_script_w(L"MsgBox 10");
CHECK_CALLED(GetUIBehavior);
uic_handling = SCRIPTUICHANDLING_ALLOW;
......@@ -2821,7 +2821,7 @@ static void test_msgbox(void)
SET_EXPECT(GetWindow);
SET_EXPECT(EnableModeless);
SET_EXPECT(OnScriptError);
hres = parse_script_ar("MsgBox \"testing...\"");
hres = parse_script_wr(L"MsgBox \"testing...\"");
ok(FAILED(hres), "script not failed\n");
CHECK_CALLED(GetUIBehavior);
CHECK_CALLED(GetWindow);
......@@ -2832,7 +2832,7 @@ static void test_msgbox(void)
SET_EXPECT(GetUIBehavior);
SET_EXPECT(OnScriptError);
hres = parse_script_ar("MsgBox \"testing...\"");
hres = parse_script_wr(L"MsgBox \"testing...\"");
ok(FAILED(hres), "script not failed\n");
CHECK_CALLED(GetUIBehavior);
CHECK_CALLED(OnScriptError);
......@@ -3175,210 +3175,210 @@ static void run_tests(void)
strict_dispid_check = TRUE;
parse_script_a("");
parse_script_a("' empty ;");
parse_script_w(L"");
parse_script_w(L"' empty ;");
SET_EXPECT(global_success_d);
SET_EXPECT(global_success_i);
parse_script_a("reportSuccess");
parse_script_w(L"reportSuccess");
CHECK_CALLED(global_success_d);
CHECK_CALLED(global_success_i);
SET_EXPECT(global_success_d);
SET_EXPECT(global_success_i);
parse_script_a("reportSuccess()");
parse_script_w(L"reportSuccess()");
CHECK_CALLED(global_success_d);
CHECK_CALLED(global_success_i);
SET_EXPECT(global_success_d);
SET_EXPECT(global_success_i);
parse_script_a("Call reportSuccess");
parse_script_w(L"Call reportSuccess");
CHECK_CALLED(global_success_d);
CHECK_CALLED(global_success_i);
SET_EXPECT(global_success_d);
SET_EXPECT(global_success_i);
parse_script_a("test.reportSuccess()");
parse_script_w(L"test.reportSuccess()");
CHECK_CALLED(global_success_d);
CHECK_CALLED(global_success_i);
SET_EXPECT(global_success_d);
SET_EXPECT(global_success_i);
parse_script_af(0, "TEST.reportSuccess()");
parse_script_wf(0, L"TEST.reportSuccess()");
CHECK_CALLED(global_success_d);
CHECK_CALLED(global_success_i);
SET_EXPECT(global_vbvar_d);
SET_EXPECT(global_vbvar_i);
parse_script_a("Option Explicit\nvbvar = 3");
parse_script_w(L"Option Explicit\nvbvar = 3");
CHECK_CALLED(global_vbvar_d);
CHECK_CALLED(global_vbvar_i);
SET_EXPECT(global_vbvar_d);
SET_EXPECT(global_vbvar_i);
parse_script_a("Option Explicit\nvbvar() = 3");
parse_script_w(L"Option Explicit\nvbvar() = 3");
CHECK_CALLED(global_vbvar_d);
CHECK_CALLED(global_vbvar_i);
SET_EXPECT(global_letobj_i);
parse_script_a("Option Explicit\nletobj = testObj");
parse_script_w(L"Option Explicit\nletobj = testObj");
CHECK_CALLED(global_letobj_i);
SET_EXPECT(global_letobj_i);
parse_script_a("Option Explicit\ntest.letobj = testObj");
parse_script_w(L"Option Explicit\ntest.letobj = testObj");
CHECK_CALLED(global_letobj_i);
SET_EXPECT(global_setobj_i);
parse_script_a("Option Explicit\nset setobj = testObj");
parse_script_w(L"Option Explicit\nset setobj = testObj");
CHECK_CALLED(global_setobj_i);
SET_EXPECT(global_setobj_i);
parse_script_a("Option Explicit\nset test.setobj = testObj");
parse_script_w(L"Option Explicit\nset test.setobj = testObj");
CHECK_CALLED(global_setobj_i);
hres = parse_script_ar("dim x\nx = testObj.rem");
hres = parse_script_wr(L"dim x\nx = testObj.rem");
ok(hres == S_OK, "use of 'rem' as dot identifier failed: %lx08\n", hres);
SET_EXPECT(testobj_propget_d);
SET_EXPECT(testobj_propget_i);
parse_script_a("dim x\nx = testObj.propget");
parse_script_w(L"dim x\nx = testObj.propget");
CHECK_CALLED(testobj_propget_d);
CHECK_CALLED(testobj_propget_i);
SET_EXPECT(testobj_propput_d);
SET_EXPECT(testobj_propput_i);
parse_script_a("testObj.propput = 1");
parse_script_w(L"testObj.propput = 1");
CHECK_CALLED(testobj_propput_d);
CHECK_CALLED(testobj_propput_i);
SET_EXPECT(global_propargput_d);
SET_EXPECT(global_propargput_i);
parse_script_a("propargput(counter(), counter()) = counter()");
parse_script_w(L"propargput(counter(), counter()) = counter()");
CHECK_CALLED(global_propargput_d);
CHECK_CALLED(global_propargput_i);
SET_EXPECT(global_propargput_d);
SET_EXPECT(global_propargput_i);
parse_script_a("test.propargput(counter(), counter()) = counter()");
parse_script_w(L"test.propargput(counter(), counter()) = counter()");
CHECK_CALLED(global_propargput_d);
CHECK_CALLED(global_propargput_i);
SET_EXPECT(global_propargput1_d);
SET_EXPECT(global_propargput1_i);
parse_script_a("propargput1 (counter()) = counter()");
parse_script_w(L"propargput1 (counter()) = counter()");
CHECK_CALLED(global_propargput1_d);
CHECK_CALLED(global_propargput1_i);
SET_EXPECT(global_propargput1_d);
SET_EXPECT(global_propargput1_i);
parse_script_a("test.propargput1(counter()) = counter()");
parse_script_w(L"test.propargput1(counter()) = counter()");
CHECK_CALLED(global_propargput1_d);
CHECK_CALLED(global_propargput1_i);
SET_EXPECT(global_propargset_d);
SET_EXPECT(global_propargset_i);
parse_script_a("set propargset (counter()) = testObj");
parse_script_w(L"set propargset (counter()) = testObj");
CHECK_CALLED(global_propargset_d);
CHECK_CALLED(global_propargset_i);
SET_EXPECT(testobj_propget_d);
SET_EXPECT(testobj_propget_i);
parse_script_a("dim x\nwith testObj\nx=1+.propget\nend with");
parse_script_w(L"dim x\nwith testObj\nx=1+.propget\nend with");
CHECK_CALLED(testobj_propget_d);
CHECK_CALLED(testobj_propget_i);
SET_EXPECT(testobj_propput_d);
SET_EXPECT(testobj_propput_i);
parse_script_a("with testObj\n.propput = 1\nend with");
parse_script_w(L"with testObj\n.propput = 1\nend with");
CHECK_CALLED(testobj_propput_d);
CHECK_CALLED(testobj_propput_i);
SET_EXPECT(testobj_valueput_i);
parse_script_a("dim x\n"
parse_script_w(L"dim x\n"
"set x = testObj\n"
"x(counter(), counter()) = counter\n");
CHECK_CALLED(testobj_valueput_i);
parse_script_a("dim x\nx = testObj.property(1)");
parse_script_w(L"dim x\nx = testObj.property(1)");
parse_htmlscript_a("<!--");
parse_htmlscript_a(" -->");
parse_htmlscript_a("<!--\ndim x\nx=1\n-->\n");
parse_htmlscript_a("<!--\ndim x\n-->\n<!--\nx=1\n-->\n");
parse_htmlscript(L"<!--");
parse_htmlscript(L" -->");
parse_htmlscript(L"<!--\ndim x\nx=1\n-->\n");
parse_htmlscript(L"<!--\ndim x\n-->\n<!--\nx=1\n-->\n");
SET_EXPECT(OnScriptError);
hres = parse_script_ar("<!--");
hres = parse_script_wr(L"<!--");
ok(FAILED(hres), "script didn't fail\n");
CHECK_CALLED(OnScriptError);
SET_EXPECT(global_success_d);
SET_EXPECT(global_success_i);
parse_htmlscript_a("<!--\n<!-- ignore this <> <>\n--> <>\nCall reportSuccess()\n-->\n");
parse_htmlscript(L"<!--\n<!-- ignore this <> <>\n--> <>\nCall reportSuccess()\n-->\n");
CHECK_CALLED(global_success_d);
CHECK_CALLED(global_success_i);
next_cnt = 0;
SET_EXPECT(collectionobj_newenum_i);
SET_EXPECT(Next);
parse_script_a("for each x in collectionObj\nnext");
parse_script_w(L"for each x in collectionObj\nnext");
CHECK_CALLED(collectionobj_newenum_i);
CHECK_CALLED(Next);
ok(next_cnt == 4, "next_cnt = %d\n", next_cnt);
parse_script_a("x = 1\n Call ok(x = 1, \"x = \" & x)");
parse_script_w(L"x = 1\n Call ok(x = 1, \"x = \" & x)");
parse_script_a("x = _ \n3");
parse_script_w(L"x = _ \n3");
test_global_vars_ref(TRUE);
test_global_vars_ref(FALSE);
SET_EXPECT(OnScriptError);
hres = parse_script_ar("throwInt(&h80080008&)");
hres = parse_script_wr(L"throwInt(&h80080008&)");
ok(hres == 0x80080008, "hres = %08lx\n", hres);
CHECK_CALLED(OnScriptError);
/* DISP_E_BADINDEX */
SET_EXPECT(OnScriptError);
hres = parse_script_ar("throwInt(&h8002000b&)");
hres = parse_script_wr(L"throwInt(&h8002000b&)");
ok(hres == MAKE_VBSERROR(9), "hres = %08lx\n", hres);
CHECK_CALLED(OnScriptError);
SET_EXPECT(OnScriptError);
hres = parse_script_ar("throwInt(&h800a0009&)");
hres = parse_script_wr(L"throwInt(&h800a0009&)");
ok(hres == MAKE_VBSERROR(9), "hres = %08lx\n", hres);
CHECK_CALLED(OnScriptError);
onerror_hres = S_OK;
SET_EXPECT(OnScriptError);
hres = parse_script_ar("throwInt(&h800a0009&)");
hres = parse_script_wr(L"throwInt(&h800a0009&)");
ok(hres == SCRIPT_E_REPORTED, "hres = %08lx\n", hres);
CHECK_CALLED(OnScriptError);
/* E_NOTIMPL */
SET_EXPECT(OnScriptError);
hres = parse_script_ar("throwInt(&h80004001&)");
hres = parse_script_wr(L"throwInt(&h80004001&)");
ok(hres == MAKE_VBSERROR(445), "hres = %08lx\n", hres);
CHECK_CALLED(OnScriptError);
onerror_hres = S_OK;
SET_EXPECT(OnScriptError);
hres = parse_script_ar("throwInt(&h80004001&)");
hres = parse_script_wr(L"throwInt(&h80004001&)");
ok(hres == SCRIPT_E_REPORTED, "hres = %08lx\n", hres);
CHECK_CALLED(OnScriptError);
SET_EXPECT(global_testoptionalarg_i);
parse_script_a("call testOptionalArg(1,,2)");
parse_script_w(L"call testOptionalArg(1,,2)");
CHECK_CALLED(global_testoptionalarg_i);
SET_EXPECT(global_testoptionalarg_i);
parse_script_a("call testOptionalArg(,1,1)");
parse_script_w(L"call testOptionalArg(,1,1)");
CHECK_CALLED(global_testoptionalarg_i);
SET_EXPECT(global_testoptionalarg_i);
parse_script_a("testOptionalArg 1,,2");
parse_script_w(L"testOptionalArg 1,,2");
CHECK_CALLED(global_testoptionalarg_i);
parse_script_a("sub x()\n"
parse_script_w(L"sub x()\n"
" dim y\n"
" y = cint(3)\n"
"end sub\n"
......@@ -3387,32 +3387,32 @@ static void run_tests(void)
strict_dispid_check = FALSE;
SET_EXPECT(testobj_value_i);
parse_script_a("dim n,o\n set o = testObj\n n = o(1,2)\n call ok(n=2, \"n = \" & n)\n");
parse_script_w(L"dim n,o\n set o = testObj\n n = o(1,2)\n call ok(n=2, \"n = \" & n)\n");
CHECK_CALLED(testobj_value_i);
SET_EXPECT(testobj_value_i);
parse_script_a("dim n,o\n set o = testObj\n n = o\n call ok(n=0, \"n = \" & n)\n");
parse_script_w(L"dim n,o\n set o = testObj\n n = o\n call ok(n=0, \"n = \" & n)\n");
CHECK_CALLED(testobj_value_i);
parse_script_a("Sub testsub\n"
parse_script_w(L"Sub testsub\n"
"x = 1\n"
"Call ok(x = 1, \"x = \" & x)\n"
"End Sub\n"
"Call testsub()");
parse_script_a("Call ok(getVT(x) = \"VT_EMPTY*\", \"getVT(x) = \" & getVT(x))\n");
parse_script_a("Call ok(x = \"\", \"x = \" & x)\n");
parse_script_a("x = y\n"
parse_script_w(L"Call ok(getVT(x) = \"VT_EMPTY*\", \"getVT(x) = \" & getVT(x))\n");
parse_script_w(L"Call ok(x = \"\", \"x = \" & x)\n");
parse_script_w(L"x = y\n"
"Call ok(getVT(x) = \"VT_EMPTY*\", \"getVT(x) = \" & getVT(x))\n"
"Call ok(getVT(y) = \"VT_EMPTY*\", \"getVT(y) = \" & getVT(y))");
SET_EXPECT(OnScriptError);
hres = parse_script_ar("x = y(\"a\")");
hres = parse_script_wr(L"x = y(\"a\")");
ok(FAILED(hres), "script didn't fail\n");
CHECK_CALLED(OnScriptError);
SET_EXPECT(global_success_d);
SET_EXPECT(global_success_i);
parse_script_a("' comment\r"
parse_script_w(L"' comment\r"
"x = _\r3\r"
"x = _\n3\r"
"x = _\r\n3\r"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment