Shuai Meng : vbscript: Implemented Oct.
Alexandre Julliard
julliard at wine.codeweavers.com
Wed Apr 1 10:40:59 CDT 2015
Module: wine
Branch: master
Commit: 56ab12ccef84b0e42cddd03a85815beb323ee393
URL: http://source.winehq.org/git/wine.git/?a=commit;h=56ab12ccef84b0e42cddd03a85815beb323ee393
Author: Shuai Meng <mengshuaicalendr at gmail.com>
Date: Sat Mar 28 17:24:46 2015 +0800
vbscript: Implemented Oct.
---
dlls/vbscript/global.c | 39 +++++++++++++++++++++++++++++++++++++--
dlls/vbscript/tests/api.vbs | 30 ++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c
index 74acff7..ee9168b 100644
--- a/dlls/vbscript/global.c
+++ b/dlls/vbscript/global.c
@@ -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)
diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs
index 8c92cf5..7b97df4 100644
--- a/dlls/vbscript/tests/api.vbs
+++ b/dlls/vbscript/tests/api.vbs
@@ -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)
More information about the wine-cvs
mailing list