On 09/20/14 11:27, Shuai Meng wrote:
> diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c
> index 311c892..14276c5 100644
> --- a/dlls/vbscript/global.c
> +++ b/dlls/vbscript/global.c
> @@ -112,9 +112,6 @@ static HRESULT return_short(VARIANT *res, short val)
>
> static HRESULT return_int(VARIANT *res, int val)
> {
> - if((short)val == val)
> - return return_short(res, val);
This really needs tests. I wrote them to review your patch, so I may
submit them for you.
> -
> if(res) {
> V_VT(res) = VT_I4;
> V_I4(res) = val;
> @@ -783,8 +780,28 @@ static HRESULT Global_UBound(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VA
>
> static HRESULT Global_RGB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
> {
> - FIXME("\n");
> - return E_NOTIMPL;
> + HRESULT hres;
> + int i, total, color[3];/* color[0] for red, color[1] for green, color[2] for blue. */
> +
> + TRACE("%s %s %s\n", debugstr_variant(arg), debugstr_variant(arg + 1), debugstr_variant(arg + 2));
> +
> + assert(args_cnt == 3);
> +
> + for(i = 0; i < 3; i++) {
> + hres = to_int(arg + i, color + i);
> + if(FAILED(hres))
> + return hres;
> + }
> +
> + for(i = 0; i < 3;i++) {
Why do you need two loops? Can you do that in just one?
> + if(color[i] > 255)
> + color[i] = 255;
> + if(color[i] < 0)
> + return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
> + }
> + total = RGB(color[0], color[1], color[2]);
> +
> + return return_int(res, total);
> }
>
> static HRESULT Global_Len(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 d688e17..f9c86f8 100644
> --- a/dlls/vbscript/tests/api.vbs
> +++ b/dlls/vbscript/tests/api.vbs
> @@ -1240,4 +1240,40 @@ Call ok(getVT(Log(CByte(2))) = "VT_R8", "getVT(Log(CByte(2))) = " & getVT(Log(CB
> Call ok(getVT(Date) = "VT_DATE", "getVT(Date) = " & getVT(Date))
> Call ok(getVT(Time) = "VT_DATE", "getVT(Time) = " & getVT(Time))
>
> +Sub testRGBError(arg1, arg2, arg3, error_num1, error_num2)
> + on error resume next
> + Dim x
> +
> + Call Err.clear()
> + x = RGB(arg1, arg2, arg3)
> + Call ok(Err.number = error_num1, "Err.number1 = " & Err.number)
> +
> + Call Err.clear()
> + Call RGB(arg1, arg2, arg3)
> + Call ok(Err.number = error_num2, "Err.number2 = " & Err.number)
If error codes are equal in all cases, you don't need two separated
error_num* arguments.
> +End Sub
> +
> +Call ok(RGB(-0.5, -0.5, -0.5) = 0, "RGB(-0.5, -0.5, -0.5) = " & RGB(-0.5, -0.5, -0.5))
> +Call ok(getVT(RGB(-0.5, -0.5, -0.5)) = "VT_I4", "getVT(RGB(-0.5, -0.5, -0.5)) = " & getVT(RGB(-0.5, -0.5, -0.5)))
> +Call ok(RGB(0, 0, 0) = 0, "RGB(0, 0, 0) = " & RGB(0, 0, 0))
> +Call ok(getVT(RGB(0, 0, 0)) = "VT_I4", "getVT(RGB(0, 0, 0)) = " & getVT(RGB(0, 0, 0)))
> +Call ok(RGB(0.49, 0.49, 0.49) = 0, "RGB(0.49, 0.49, 0.49) = " & RGB(0.49, 0.49, 0.49))
> +Call ok(getVT(RGB(0.49, 0.49, 0.49)) = "VT_I4", "getVT(RGB(0.49, 0.49, 0.49)) = " & getVT(RGB(0.49, 0.49, 0.49)))
> +Call ok(RGB(0.5, 0.5, 0.5) = 0, "RGB(0.5, 0.5, 0.5) = " & RGB(0.5, 0.5, 0.5))
> +Call ok(getVT(RGB(0.5, 0.5, 0.5)) = "VT_I4", "getVT(RGB(0.5, 0.5, 0.5)) = " & getVT(RGB(0.5, 0.5, 0.5)))
> +Call ok(RGB(1, 1, 1) = 65793, "RGB(1, 1, 1) = " & RGB(1, 1, 1))
This would be a lot cleaner if you used hex constant (it's &hXXXX& in
vbscript).
> +Call ok(getVT(RGB(1, 1, 1)) = "VT_I4", "getVT(RGB(1, 1, 1)) = " & getVT(RGB(1, 1, 1)))
> +Call ok(RGB(1.49, 1.49, 1.49) = 65793, "RGB(1.49, 1.49, 1.49) = " & RGB(1.49, 1.49, 1.49))
> +Call ok(getVT(RGB(1.49, 1.49, 1.49)) = "VT_I4", "getVT(RGB(1.49, 1.49, 1.49)) = " & getVT(RGB(1.49, 1.49, 1.49)))
> +Call ok(RGB(2, 2, 2) = 131586, "RGB(2, 2, 2) = " & RGB(2, 2, 2))
> +Call ok(getVT(RGB(2, 2, 2)) = "VT_I4", "getVT(RGB(2, 2, 2)) = " & getVT(RGB(2, 2, 2)))
> +Call ok(RGB(255, 255, 255) = 16777215, "RGB(255, 255, 255) = " & RGB(255, 255, 255))
> +Call ok(getVT(RGB(255, 255, 255)) = "VT_I4", "getVT(RGB(255, 255, 255)) = " & getVT(RGB(255, 255, 255)))
> +Call ok(RGB(256, 256, 256) = 16777215, "RGB(256, 256, 256) = " & RGB(256, 256, 256))
> +Call ok(getVT(RGB(256, 256, 256)) = "VT_I4", "getVT(RGB(256, 256, 256)) = " & getVT(RGB(256, 256, 256)))
> +Call ok(RGB("255", "255", "255") = 16777215, "RGB(""255"", ""255"", ""255"") = " & RGB("255", "255", "255"))
> +Call ok(getVT(RGB("255", "255", "255")) = "VT_I4", "getVT(RGB(""255"", ""255"", ""255"")) = " & getVT(RGB("255", "255", "255")))
R=G=B in all your tests, so you don't really check if those are
correctly handled. Please add tests where all those are different.
Jacek