[PATCH 0/1] MR10503: vbscript: Implement AscW and ChrW functions.
From: Francis De Brabandere <francisdb@gmail.com> --- dlls/vbscript/global.c | 54 ++++++++++++++++++++++++++++++++++--- dlls/vbscript/tests/api.vbs | 53 ++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 4 deletions(-) diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 1d244b8207f..8f67160a1ac 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -1927,14 +1927,60 @@ static HRESULT Global_Chr(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VA static HRESULT Global_AscW(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(arg, &conv_str); + if(FAILED(hres)) + return hres; + str = conv_str; + } + + if(!SysStringLen(str)) + hres = MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL); + else + hres = return_short(res, *str); + + SysFreeString(conv_str); + return hres; } static HRESULT Global_ChrW(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) { - FIXME("\n"); - return E_NOTIMPL; + int c; + WCHAR ch; + HRESULT hres; + + TRACE("%s\n", debugstr_variant(arg)); + + hres = to_int(arg, &c); + if(FAILED(hres)) + return hres; + + if(c != (short)c && c != (unsigned short)c) { + WARN("invalid arg %d\n", c); + return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL); + } + + ch = c; + if(res) { + V_VT(res) = VT_BSTR; + V_BSTR(res) = SysAllocStringLen(&ch, 1); + if(!V_BSTR(res)) + return E_OUTOFMEMORY; + } + return S_OK; } static HRESULT Global_Abs(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index e18d887306b..a9b0aad5f96 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -2144,6 +2144,59 @@ if Asc(Chr(&h81)) = &h8145 then end if call testAscError() +sub testAscW(arg, expected) + dim x + x = AscW(arg) + call ok(x = expected, "AscW: x = " & x & " expected " & expected) + call ok(getVT(x) = "VT_I2*", "AscW: getVT = " & getVT(x)) +end sub + +call testAscW("T", 84) +call testAscW("test", 116) +call testAscW("3", 51) +call testAscW(3, 51) +call testAscW(Chr(0), 0) +call testAscW(Chr(255), 255) +if isEnglishLang then testAscW true, 84 + +sub testAscWError() + on error resume next + call Err.clear() + call AscW(null) + Call ok(Err.number = 94, "AscW null: Err.number = " & Err.number) + call Err.clear() + call AscW(empty) + Call ok(Err.number = 5, "AscW empty: Err.number = " & Err.number) + call Err.clear() + call AscW("") + Call ok(Err.number = 5, "AscW """": Err.number = " & Err.number) +end sub + +call testAscWError() + +Call ok(getVT(ChrW(120)) = "VT_BSTR", "getVT(ChrW(120)) = " & getVT(ChrW(120))) +Call ok(ChrW(120) = "x", "ChrW(120) = " & ChrW(120)) +Call ok(ChrW(0) <> "", "ChrW(0) = """"") +Call ok(ChrW(120.5) = "x", "ChrW(120.5) = " & ChrW(120.5)) +Call ok(ChrW(119.5) = "x", "ChrW(119.5) = " & ChrW(119.5)) +Call ok(ChrW("120") = "x", "ChrW(""120"") = " & ChrW("120")) +Call ok(ChrW(255) = Chr(255), "ChrW(255) <> Chr(255)") +Call ok(ChrW(0) = Chr(0), "ChrW(0) <> Chr(0)") +Call ok(AscW(ChrW(8364)) = 8364, "AscW(ChrW(8364)) = " & AscW(ChrW(8364))) +Call ok(AscW(ChrW(65535)) = -1, "AscW(ChrW(65535)) = " & AscW(ChrW(65535))) + +sub testChrWError() + on error resume next + call Err.clear() + call ChrW(65536) + call ok(Err.number = 5, "ChrW 65536: Err.number = " & Err.number) + call Err.clear() + call ChrW(-32769) + call ok(Err.number = 5, "ChrW -32769: Err.number = " & Err.number) +end sub + +call testChrWError() + sub testErrNumber(n) call ok(err.number = n, "err.number = " & err.number & " expected " & n) end sub -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10503
This merge request was approved by Jacek Caban. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10503
participants (3)
-
Francis De Brabandere -
Francis De Brabandere (@francisdb) -
Jacek Caban (@jacek)