From: Alex Henrie alexhenrie24@gmail.com
--- dlls/vbscript/tests/createobj.c | 17 ++----- dlls/vbscript/tests/run.c | 89 +++++++++++++++------------------ dlls/vbscript/tests/vbscript.c | 25 +++------ 3 files changed, 49 insertions(+), 82 deletions(-)
diff --git a/dlls/vbscript/tests/createobj.c b/dlls/vbscript/tests/createobj.c index 552a849ea27..e1a453414f7 100644 --- a/dlls/vbscript/tests/createobj.c +++ b/dlls/vbscript/tests/createobj.c @@ -27,6 +27,7 @@ #include <objsafe.h> #include <urlmon.h> #include <mshtmhst.h> +#include <atlconv.h>
#include "wine/test.h"
@@ -117,18 +118,6 @@ const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
#define VB_E_CANNOT_CREATE_OBJ 0x800a01ad
-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 HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID riid, void **ppv) { ok(0, "unexpected call\n"); @@ -699,7 +688,7 @@ static void _parse_script_a(unsigned line, IActiveScriptParse *parser, const cha BSTR str; HRESULT hres;
- str = a2bstr(script); + str = A2BSTR(script); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); SysFreeString(str); ok_(__FILE__,line)(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); @@ -710,7 +699,7 @@ static HRESULT parse_script_ae(IActiveScriptParse *parser, const char *script) BSTR str; HRESULT hres;
- str = a2bstr(script); + str = A2BSTR(script); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); SysFreeString(str);
diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c index 65459711061..ef04e275d46 100644 --- a/dlls/vbscript/tests/run.c +++ b/dlls/vbscript/tests/run.c @@ -24,6 +24,7 @@ #include <ole2.h> #include <dispex.h> #include <activscp.h> +#include <atlconv.h>
#include "vbsregexp55.h"
@@ -168,18 +169,6 @@ static IDispatchEx testObj; static HRESULT onerror_hres = E_NOTIMPL; static BOOL strict_enter_script;
-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 const char *vt2a(VARIANT *v) { if(V_VT(v) == (VT_BYREF|VT_VARIANT)) { @@ -303,35 +292,35 @@ static void test_disp(IDispatch *disp) hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex); ok(hres == S_OK, "Could not get IDispatchEx iface: %08lx\n", hres);
- str = a2bstr("publicProp"); + str = A2BSTR("publicProp"); hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_prop_id); SysFreeString(str); ok(hres == S_OK, "GetDispID(publicProp) failed: %08lx\n", hres);
- str = a2bstr("PUBLICPROP"); + str = A2BSTR("PUBLICPROP"); hres = IDispatchEx_GetDispID(dispex, str, 0, &id); SysFreeString(str); ok(hres == S_OK, "GetDispID(PUBLICPROP) failed: %08lx\n", hres); ok(public_prop_id == id, "id = %ld\n", public_prop_id);
- str = a2bstr("publicPROP2"); + str = A2BSTR("publicPROP2"); hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_prop2_id); SysFreeString(str); ok(hres == S_OK, "GetDispID(publicProp2) failed: %08lx\n", hres);
- str = a2bstr("defValGet"); + str = A2BSTR("defValGet"); hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &defvalget_id); SysFreeString(str); ok(hres == S_OK, "GetDispID(defValGet) failed: %08lx\n", hres); ok(defvalget_id == DISPID_VALUE, "id = %ld\n", defvalget_id);
- str = a2bstr("privateProp"); + str = A2BSTR("privateProp"); hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &id); SysFreeString(str); ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateProp) failed: %08lx, expected DISP_E_UNKNOWNNAME\n", hres); ok(id == -1, "id = %ld\n", id);
- str = a2bstr("class_initialize"); + str = A2BSTR("class_initialize"); hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &id); SysFreeString(str); ok(hres == S_OK, "GetDispID(publicProp2) failed: %08lx\n", hres); @@ -429,13 +418,13 @@ static void test_disp(IDispatch *disp) hres = IDispatchEx_InvokeEx(dispex, public_prop_id, 0, DISPATCH_PROPERTYPUT, &dp, NULL, &ei, NULL); ok(hres == DISP_E_PARAMNOTOPTIONAL, "InvokeEx failed: %08lx, expected DISP_E_PARAMNOTOPTIONAL\n", hres);
- str = a2bstr("publicFunction"); + str = A2BSTR("publicFunction"); hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_func_id); SysFreeString(str); ok(hres == S_OK, "GetDispID(publicFunction) failed: %08lx\n", hres); ok(public_func_id != -1, "public_func_id = -1\n");
- str = a2bstr("publicSub"); + str = A2BSTR("publicSub"); hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &public_sub_id); SysFreeString(str); ok(hres == S_OK, "GetDispID(publicSub) failed: %08lx\n", hres); @@ -507,13 +496,13 @@ static void test_disp(IDispatch *disp) ok(hres == S_OK, "InvokeEx failed: %08lx\n", hres); ok(V_VT(&v) == VT_EMPTY, "V_VT(v) = %d\n", V_VT(&v));
- str = a2bstr("privateSub"); + str = A2BSTR("privateSub"); hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &id); SysFreeString(str); ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateSub) failed: %08lx, expected DISP_E_UNKNOWNNAME\n", hres); ok(id == -1, "id = %ld\n", id);
- str = a2bstr("dynprop"); + str = A2BSTR("dynprop"); hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive|fdexNameEnsure, &id); ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(privateProp) failed: %08lx, expected DISP_E_UNKNOWNNAME\n", hres); ok(id == -1, "id = %ld\n", id); @@ -522,26 +511,26 @@ static void test_disp(IDispatch *disp) ok(id == -1, "id = %ld\n", id); SysFreeString(str);
- str = a2bstr("publicProp"); + str = A2BSTR("publicProp"); hres = IDispatchEx_GetDispID(dispex, str, 0x80000000|fdexNameCaseInsensitive, &public_prop_id); SysFreeString(str); ok(hres == S_OK, "GetDispID(publicProp) failed: %08lx\n", hres);
id = 0xdeadbeef; - str = a2bstr("publicProp"); + str = A2BSTR("publicProp"); hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id); SysFreeString(str); ok(hres == S_OK, "GetDispID(publicProp) failed: %08lx\n", hres); ok(id == public_prop_id, "id = %ld, expected %ld\n", id, public_prop_id);
id = 0xdeadbeef; - str = a2bstr("publicprop"); + str = A2BSTR("publicprop"); hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseSensitive, &id); SysFreeString(str); ok(hres == S_OK, "GetDispID(publicProp) failed: %08lx\n", hres); ok(id == public_prop_id, "id = %ld, expected %ld\n", id, public_prop_id);
- str = a2bstr("gsGetProp"); + str = A2BSTR("gsGetProp"); hres = IDispatchEx_GetDispID(dispex, str, fdexNameCaseInsensitive, &gs_getter_id); SysFreeString(str); ok(hres == S_OK, "GetDispID(publicFunction) failed: %08lx\n", hres); @@ -1265,7 +1254,7 @@ static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, ok(pei != NULL, "pei == NULL\n");
V_VT(pvarRes) = VT_BSTR; - V_BSTR(pvarRes) = a2bstr(vt2a(pdp->rgvarg)); + V_BSTR(pvarRes) = A2BSTR(vt2a(pdp->rgvarg)); return S_OK;
case DISPID_GLOBAL_ISENGLANG: @@ -2123,7 +2112,7 @@ static void parse_script_af(DWORD flags, const char *src) BSTR tmp; HRESULT hres;
- tmp = a2bstr(src); + tmp = A2BSTR(src); hres = parse_script(flags, tmp, NULL); SysFreeString(tmp); ok(hres == S_OK, "parse_script failed: %08lx\n", hres); @@ -2134,7 +2123,7 @@ static HRESULT parse_script_ar(const char *src) BSTR tmp; HRESULT hres;
- tmp = a2bstr(src); + tmp = A2BSTR(src); hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, tmp, NULL); SysFreeString(tmp); return hres; @@ -2160,12 +2149,12 @@ static void test_parse_context(void) ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres);
/* unknown identifier context is not a valid argument */ - str = a2bstr("Call reportSuccess()\n"); + str = A2BSTR("Call reportSuccess()\n"); hres = IActiveScriptParse_ParseScriptText(parser, str, L"y", NULL, NULL, 0, 0, 0, NULL, NULL); ok(hres == E_INVALIDARG, "ParseScriptText failed: %08lx\n", hres); SysFreeString(str);
- str = a2bstr("class Cl\n" + str = A2BSTR("class Cl\n" " Public Sub ClMethod\n" " Call reportSuccess()\n" " End Sub\n" @@ -2177,14 +2166,14 @@ static void test_parse_context(void) SysFreeString(str);
/* known global variable is not a valid context */ - str = a2bstr("Call reportSuccess()\n"); + str = A2BSTR("Call reportSuccess()\n"); hres = IActiveScriptParse_ParseScriptText(parser, str, L"x", NULL, NULL, 0, 0, 0, NULL, NULL); ok(hres == E_INVALIDARG, "ParseScriptText failed: %08lx\n", hres); SysFreeString(str);
SET_EXPECT(global_success_d); SET_EXPECT(global_success_i); - str = a2bstr("Call reportSuccess()\n"); + str = A2BSTR("Call reportSuccess()\n"); hres = IActiveScriptParse_ParseScriptText(parser, str, L"test", NULL, NULL, 0, 0, 0, NULL, NULL); ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); SysFreeString(str); @@ -2207,7 +2196,7 @@ static void _parse_htmlscript_a(unsigned line, const char *src) BSTR tmp; HRESULT hres;
- tmp = a2bstr(src); + tmp = A2BSTR(src); hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, tmp, L"</SCRIPT>"); SysFreeString(tmp); ok_(__FILE__,line)(hres == S_OK, "parse_script failed: %08lx\n", hres); @@ -2220,7 +2209,7 @@ static IDispatchEx *parse_procedure(IActiveScriptParseProcedure2 *parse_proc, co BSTR str; HRESULT hres;
- str = a2bstr(src); + str = A2BSTR(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); @@ -2613,7 +2602,7 @@ static void test_gc(void) hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08lx\n", hres);
- src = a2bstr( + src = A2BSTR( "class C\n" " Public ref\n" " Public Sub Class_Terminate\n" @@ -2872,7 +2861,7 @@ static HRESULT test_global_vars_ref(BOOL use_close)
refobj_ref = 0;
- script_str = a2bstr("Dim x\nset x = RefObj\n"); + script_str = A2BSTR("Dim x\nset x = RefObj\n"); hres = IActiveScriptParse_ParseScriptText(parser, script_str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); SysFreeString(script_str);
@@ -2921,7 +2910,7 @@ static void test_isexpression(void) ok(hres == S_OK, "GetScriptState failed: %08lx\n", hres); ok(ss == SCRIPTSTATE_INITIALIZED, "Wrong script state %u\n", ss);
- str = a2bstr("13"); + str = A2BSTR("13"); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); ok(V_VT(&var) == VT_I2, "Expected VT_I2, got %s\n", vt2a(&var)); @@ -2934,7 +2923,7 @@ static void test_isexpression(void)
/* Empty expressions */ V_VT(&var) = VT_I2; - str = a2bstr(""); + str = A2BSTR(""); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); ok(V_VT(&var) == VT_EMPTY, "Expected VT_EMPTY, got %s\n", vt2a(&var)); @@ -2942,7 +2931,7 @@ static void test_isexpression(void) SysFreeString(str);
/* Two expressions fail */ - str = a2bstr("1\n3"); + str = A2BSTR("1\n3"); SET_EXPECT(OnScriptError); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); ok(FAILED(hres), "ParseScriptText did not fail: %08lx\n", hres); @@ -2951,7 +2940,7 @@ static void test_isexpression(void) SysFreeString(str);
/* Simple numerical expression */ - str = a2bstr("(1 + 7) * 2 - 3"); + str = A2BSTR("(1 + 7) * 2 - 3"); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, NULL, NULL); ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres);
@@ -2965,7 +2954,7 @@ static void test_isexpression(void) /* Without a global host or named item context, "me" returns the script dispatch */ hres = IActiveScript_GetScriptDispatch(engine, NULL, &disp); ok(hres == S_OK, "GetScriptDispatch failed: %08lx\n", hres); - str = a2bstr("me"); + str = A2BSTR("me"); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); ok(V_VT(&var) == VT_DISPATCH, "Expected VT_DISPATCH, got %s\n", vt2a(&var)); @@ -2976,14 +2965,14 @@ static void test_isexpression(void)
/* An expression can also refer to a variable, function, class, etc previously set */ V_VT(&var) = VT_I2; - str = a2bstr("If True Then foo = 42 Else foo = 0\n"); + str = A2BSTR("If True Then foo = 42 Else foo = 0\n"); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, &var, NULL); ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); ok(V_VT(&var) == VT_EMPTY, "Expected VT_EMPTY, got %s\n", vt2a(&var)); VariantClear(&var); SysFreeString(str);
- str = a2bstr("foo\n\n"); + str = A2BSTR("foo\n\n"); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); ok(V_VT(&var) == VT_I2, "Expected VT_I2, got %s\n", vt2a(&var)); @@ -2991,7 +2980,7 @@ static void test_isexpression(void) VariantClear(&var); SysFreeString(str);
- str = a2bstr("foo : "); + str = A2BSTR("foo : "); SET_EXPECT(OnScriptError); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); ok(FAILED(hres), "ParseScriptText did not fail: %08lx\n", hres); @@ -2999,7 +2988,7 @@ static void test_isexpression(void) VariantClear(&var); SysFreeString(str);
- str = a2bstr(""foo is " & CStr(foo) \n \n\n "); + str = A2BSTR(""foo is " & CStr(foo) \n \n\n "); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); ok(V_VT(&var) == VT_BSTR, "Expected VT_BSTR, got %s\n", vt2a(&var)); @@ -3007,14 +2996,14 @@ static void test_isexpression(void) VariantClear(&var); SysFreeString(str);
- str = a2bstr("Function test(x)\n" + str = A2BSTR("Function test(x)\n" " test = x + 0.5\n" "End Function\n"); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); SysFreeString(str);
- str = a2bstr("test(4) * 3\n"); + str = A2BSTR("test(4) * 3\n"); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); ok(V_VT(&var) == VT_R8, "Expected VT_R8, got %s\n", vt2a(&var)); @@ -3022,7 +3011,7 @@ static void test_isexpression(void) VariantClear(&var); SysFreeString(str);
- str = a2bstr("Class C\n" + str = A2BSTR("Class C\n" " Public x\n" "End Class\n" "Set obj = New C\n" @@ -3031,7 +3020,7 @@ static void test_isexpression(void) ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); SysFreeString(str);
- str = a2bstr("obj.x"); + str = A2BSTR("obj.x"); hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); ok(V_VT(&var) == VT_BOOL, "Expected VT_BOOL, got %s\n", vt2a(&var)); diff --git a/dlls/vbscript/tests/vbscript.c b/dlls/vbscript/tests/vbscript.c index 65134fef1af..fbb69809d3c 100644 --- a/dlls/vbscript/tests/vbscript.c +++ b/dlls/vbscript/tests/vbscript.c @@ -25,6 +25,7 @@ #include <activscp.h> #include <objsafe.h> #include <dispex.h> +#include <atlconv.h>
#include "vbsregexp55.h"
@@ -109,18 +110,6 @@ DEFINE_EXPECT(testCall); DEFINE_GUID(CLSID_VBScript, 0xb54f3741, 0x5b07, 0x11cf, 0xa4,0xb0, 0x00,0xaa,0x00,0x4a,0x55,0xe8); DEFINE_GUID(CLSID_VBScriptRegExp, 0x3f4daca4, 0x160d, 0x11d2, 0xa8,0xe9, 0x00,0x10,0x4b,0x36,0x5c,0x9f);
-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; -} - #define test_state(s,ss) _test_state(__LINE__,s,ss) static void _test_state(unsigned line, IActiveScript *script, SCRIPTSTATE exstate) { @@ -574,7 +563,7 @@ static void parse_script(IActiveScriptParse *parse, const char *src) SET_EXPECT(OnEnterScript); SET_EXPECT(OnLeaveScript);
- str = a2bstr(src); + str = A2BSTR(src); hres = IActiveScriptParse_ParseScriptText(parse, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL); SysFreeString(str); ok(hres == S_OK, "ParseScriptText failed: %08lx\n", hres); @@ -590,7 +579,7 @@ static void _get_disp_id(unsigned line, IDispatchEx *dispex, const char *name, H BSTR str; HRESULT hres;
- str = a2bstr(name); + str = A2BSTR(name); hres = IDispatchEx_GetDispID(dispex, str, 0, id); ok_(__FILE__,line)(hres == exhres, "GetDispID(%s) returned %08lx, expected %08lx\n", name, hres, exhres);
@@ -2665,17 +2654,17 @@ static void test_RegExp_Replace(void) hr = IRegExp2_put_Global(regexp, test[i].global ? VARIANT_TRUE : VARIANT_FALSE); ok(hr == S_OK, "got %#lx\n", hr);
- str = a2bstr(test[i].pattern); + str = A2BSTR(test[i].pattern); hr = IRegExp2_put_Pattern(regexp, str); ok(hr == S_OK, "got %#lx\n", hr); SysFreeString(str);
- str = a2bstr(test[i].source); + str = A2BSTR(test[i].source); V_VT(&var) = VT_BSTR; - V_BSTR(&var) = a2bstr(test[i].replace); + V_BSTR(&var) = A2BSTR(test[i].replace); hr = IRegExp2_Replace(regexp, str, var, &ret); ok(hr == S_OK, "got %#lx\n", hr); - result = a2bstr(test[i].result); + result = A2BSTR(test[i].result); ok(!wcscmp(ret, result), "got %s, expected %s\n", wine_dbgstr_w(ret), wine_dbgstr_w(result)); SysFreeString(result); SysFreeString(ret);