From: Francis De Brabandere <francisdb@gmail.com> --- dlls/vbscript/global.c | 53 ++++++++++++++++++++++++++++++++++--- dlls/vbscript/tests/api.vbs | 35 ++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 54a24115744..b32104a4e6b 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -2055,14 +2055,59 @@ static HRESULT Global_InStrB(BuiltinDisp *This, VARIANT *args, unsigned args_cnt static HRESULT Global_AscB(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) { - FIXME("\n"); - return E_NOTIMPL; + BSTR conv_str = NULL, str; + HRESULT hres = S_OK; + + TRACE("(%s)\n", debugstr_variant(arg)); + + switch(V_VT(arg)) { + case VT_NULL: + return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE); + case VT_EMPTY: + return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL); + case VT_BSTR: + str = V_BSTR(arg); + break; + default: + hres = to_string(This->ctx->lcid, arg, &conv_str); + if(FAILED(hres)) + return hres; + str = conv_str; + } + + if(!SysStringByteLen(str)) + hres = MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL); + else if(res) { + V_VT(res) = VT_UI1; + V_UI1(res) = *(const BYTE*)str; + } + + SysFreeString(conv_str); + return hres; } static HRESULT Global_ChrB(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) { - FIXME("\n"); - return E_NOTIMPL; + int c; + HRESULT hres; + + TRACE("%s\n", debugstr_variant(arg)); + + hres = to_int(arg, &c); + if(FAILED(hres)) + return hres; + + if(c < 0 || c > 255) + return MAKE_VBSERROR(VBSE_OVERFLOW); + + if(res) { + BYTE b = c; + V_VT(res) = VT_BSTR; + V_BSTR(res) = SysAllocStringByteLen((const char*)&b, 1); + if(!V_BSTR(res)) + return E_OUTOFMEMORY; + } + return S_OK; } static HRESULT Global_Asc(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index 306be2c49ff..79c4c212871 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -2999,4 +2999,39 @@ Call ok(InStrB("ABC", "D") = 0, "InStrB(""ABC"", ""D"") = " & InStrB("ABC", "D") Call ok(InStrB("ABC", "A") = 1, "InStrB(""ABC"", ""A"") = " & InStrB("ABC", "A")) Call ok(InStrB("ABCABC", "B") = 3, "InStrB(""ABCABC"", ""B"") = " & InStrB("ABCABC", "B")) +' AscB tests +Call ok(AscB("A") = 65, "AscB(""A"") = " & AscB("A")) +Call ok(AscB("a") = 97, "AscB(""a"") = " & AscB("a")) +Call ok(AscB("ABC") = 65, "AscB(""ABC"") = " & AscB("ABC")) +Call ok(getVT(AscB("A")) = "VT_UI1", "getVT(AscB) = " & getVT(AscB("A"))) + +' ChrB tests +Call ok(AscB(ChrB(65)) = 65, "AscB(ChrB(65)) roundtrip = " & AscB(ChrB(65))) +Call ok(LenB(ChrB(65)) = 1, "LenB(ChrB(65)) = " & LenB(ChrB(65))) +Call ok(AscB(ChrB(0)) = 0, "AscB(ChrB(0)) = " & AscB(ChrB(0))) +Call ok(AscB(ChrB(255)) = 255, "AscB(ChrB(255)) = " & AscB(ChrB(255))) + +sub testByteCharErrors() + on error resume next + dim r + + call Err.clear() + r = AscB("") + Call ok(Err.number = 5, "AscB("""") Err.number = " & Err.number) + + call Err.clear() + r = AscB(Null) + Call ok(Err.number = 94, "AscB(Null) Err.number = " & Err.number) + + call Err.clear() + r = ChrB(256) + Call ok(Err.number = 6, "ChrB(256) Err.number = " & Err.number) + + call Err.clear() + r = ChrB(-1) + Call ok(Err.number = 6, "ChrB(-1) Err.number = " & Err.number) +end sub + +call testByteCharErrors() + Call reportSuccess() -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10510