vbscript: Implemented Oct.

This commit is contained in:
Shuai Meng 2015-03-28 17:24:46 +08:00 committed by Alexandre Julliard
parent 98186d42a5
commit 56ab12ccef
2 changed files with 67 additions and 2 deletions

View file

@ -584,8 +584,43 @@ static HRESULT Global_Hex(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIA
static HRESULT Global_Oct(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
{
FIXME("\n");
return E_NOTIMPL;
HRESULT hres;
WCHAR buf[23], *ptr;
DWORD n;
int ret;
TRACE("%s\n", debugstr_variant(arg));
switch(V_VT(arg)) {
case VT_I2:
n = (WORD)V_I2(arg);
break;
case VT_NULL:
if(res)
V_VT(res) = VT_NULL;
return S_OK;
default:
hres = to_int(arg, &ret);
if(FAILED(hres))
return hres;
else
n = ret;
}
buf[22] = 0;
ptr = buf + 21;
if(n) {
do {
*ptr-- = '0' + (n & 0x7);
n >>= 3;
}while(n);
ptr++;
}else {
*ptr = '0';
}
return return_string(res, ptr);
}
static HRESULT Global_VarType(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)

View file

@ -237,6 +237,36 @@ TestHex empty, "0"
Call ok(getVT(hex(null)) = "VT_NULL", "getVT(hex(null)) = " & getVT(hex(null)))
Call ok(getVT(hex(empty)) = "VT_BSTR", "getVT(hex(empty)) = " & getVT(hex(empty)))
Sub TestOct(x, ex, res_type)
Call ok(Oct(x) = ex, "Oct(" & x & ") = " & Oct(x) & " expected " & ex)
Call ok(getVT(Oct(x)) = res_type, "getVT(Oct(" &x & ")) = " & getVT(Oct(x)) & "expected " & res_type)
End Sub
Sub TestOctError(num, err_num)
On error resume next
Call Oct(num)
Call ok(Err.number = err_num, "Oct(" & num & ") error number is " & Err.number & " expected " & err_num)
End Sub
TestOct empty, "0", "VT_BSTR"
TestOct 0, "0", "VT_BSTR"
TestOct 9, "11", "VT_BSTR"
TestOct "9", "11", "VT_BSTR"
TestOct 8.5, "10", "VT_BSTR"
TestOct 9.5, "12", "VT_BSTR"
TestOct -1, "177777", "VT_BSTR"
TestOct -32767, "100001", "VT_BSTR"
TestOct -32768, "37777700000", "VT_BSTR"
TestOct 2147483647.49, "17777777777", "VT_BSTR"
TestOct -2147483648.5, "20000000000", "VT_BSTR"
Call ok(getVT(Oct(null)) = "VT_NULL", "getVT(Oct(null)) = " & getVT(Oct(null)))
newObject.myval = 5
TestOct newObject, "5", "VT_BSTR"
TestOctError 2147483647.5, 6
TestOctError -2147483648.51, 6
TestOctError "test", 13
x = InStr(1, "abcd", "bc")
Call ok(x = 2, "InStr returned " & x)