Jacek Caban : vbscript: Added Round implementation.

Alexandre Julliard julliard at winehq.org
Wed Sep 26 14:06:51 CDT 2012


Module: wine
Branch: master
Commit: 5c211059a0fa52c508bc7e9e0c67bb782655e339
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=5c211059a0fa52c508bc7e9e0c67bb782655e339

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Sep 26 14:36:01 2012 +0200

vbscript: Added Round implementation.

---

 dlls/vbscript/global.c      |   71 +++++++++++++++++++++++++++++++++++++++++-
 dlls/vbscript/tests/api.vbs |   15 +++++++++
 2 files changed, 84 insertions(+), 2 deletions(-)

diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c
index f7d8efe..0facdf0 100644
--- a/dlls/vbscript/global.c
+++ b/dlls/vbscript/global.c
@@ -17,6 +17,7 @@
  */
 
 #include <assert.h>
+#include <math.h>
 
 #include "vbscript.h"
 #include "vbscript_defs.h"
@@ -98,6 +99,16 @@ static HRESULT return_int(VARIANT *res, int val)
     return S_OK;
 }
 
+static inline HRESULT return_double(VARIANT *res, double val)
+{
+    if(res) {
+        V_VT(res) = VT_R8;
+        V_R8(res) = val;
+    }
+
+    return S_OK;
+}
+
 static inline HRESULT return_null(VARIANT *res)
 {
     if(res)
@@ -122,6 +133,40 @@ static HRESULT to_int(VARIANT *v, int *ret)
     return S_OK;
 }
 
+static HRESULT to_double(VARIANT *v, double *ret)
+{
+    switch(V_VT(v)) {
+    case VT_I2:
+        *ret = V_I2(v);
+        break;
+    case VT_I4:
+        *ret = V_I4(v);
+        break;
+    case VT_R4:
+        *ret = V_R4(v);
+        break;
+    case VT_R8:
+        *ret = V_R8(v);
+        break;
+    case VT_BSTR: {
+        VARIANT dst;
+        HRESULT hres;
+
+        V_VT(&dst) = VT_EMPTY;
+        hres = VariantChangeType(&dst, v, VARIANT_LOCALBOOL, VT_R8);
+        if(FAILED(hres))
+            return hres;
+        *ret = V_R8(&dst);
+        break;
+    }
+    default:
+        FIXME("arg %s not supported\n", debugstr_variant(v));
+        return E_NOTIMPL;
+    }
+
+    return S_OK;
+}
+
 static HRESULT to_string(VARIANT *v, BSTR *ret)
 {
     VARIANT dst;
@@ -1110,8 +1155,30 @@ static HRESULT Global_MonthName(vbdisp_t *This, VARIANT *arg, unsigned args_cnt,
 
 static HRESULT Global_Round(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    double n;
+    HRESULT hres;
+
+    TRACE("%s\n", debugstr_variant(arg));
+
+    if(!res)
+        return S_OK;
+
+    switch(V_VT(arg)) {
+    case VT_I2:
+    case VT_I4:
+    case VT_BOOL:
+        *res = *arg;
+        return S_OK;
+    case VT_R8:
+        n = V_R8(arg);
+        break;
+    default:
+        hres = to_double(arg, &n);
+        if(FAILED(hres))
+            return hres;
+    }
+
+    return return_double(res, round(n));
 }
 
 static HRESULT Global_Escape(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 2ad9404..f7b4295 100644
--- a/dlls/vbscript/tests/api.vbs
+++ b/dlls/vbscript/tests/api.vbs
@@ -183,4 +183,19 @@ Call ok(Space(1) = " ", "Space(1) = " & Space(1) & """")
 Call ok(Space(0) = "", "Space(0) = " & Space(0) & """")
 Call ok(Space(5) = "     ", "Space(5) = " & Space(5) & """")
 
+Sub TestRound(val, exval, vt)
+    Call ok(Round(val) = exval, "Round(" & val & ") = " & Round(val))
+    Call ok(getVT(Round(val)) = vt, "getVT(Round(" & val & ")) = " & getVT(Round(val)))
+End Sub
+
+TestRound 3, 3, "VT_I2"
+TestRound 3.3, 3, "VT_R8"
+TestRound 3.8, 4, "VT_R8"
+TestRound 3.5, 4, "VT_R8"
+TestRound -3.3, -3, "VT_R8"
+TestRound -3.5, -4, "VT_R8"
+TestRound "2", 2, "VT_R8"
+TestRound true, true, "VT_BOOL"
+TestRound false, false, "VT_BOOL"
+
 Call reportSuccess()




More information about the wine-cvs mailing list