Commit fd6cf181 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

vbscript: Implement FormatPercent().

parent d273247e
...@@ -2983,10 +2983,36 @@ static HRESULT Global_FormatCurrency(BuiltinDisp *This, VARIANT *args, unsigned ...@@ -2983,10 +2983,36 @@ static HRESULT Global_FormatCurrency(BuiltinDisp *This, VARIANT *args, unsigned
return return_bstr(res, str); return return_bstr(res, str);
} }
static HRESULT Global_FormatPercent(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) static HRESULT Global_FormatPercent(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
{ {
FIXME("\n"); union
return E_NOTIMPL; {
struct
{
int num_dig, inc_lead, use_parens, group;
} s;
int val[4];
} int_args = { .s.num_dig = -1, .s.inc_lead = -2, .s.use_parens = -2, .s.group = -2 };
HRESULT hres;
BSTR str;
int i;
TRACE("\n");
assert(1 <= args_cnt && args_cnt <= 5);
for (i = 1; i < args_cnt; ++i)
{
if (V_VT(args+i) == VT_ERROR) continue;
if (V_VT(args+i) == VT_NULL) return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE);
if (FAILED(hres = to_int(args+i, &int_args.val[i-1]))) return hres;
}
hres = VarFormatPercent(args, int_args.s.num_dig, int_args.s.inc_lead, int_args.s.use_parens,
int_args.s.group, 0, &str);
if (FAILED(hres)) return hres;
return return_bstr(res, str);
} }
static HRESULT Global_FormatDateTime(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) static HRESULT Global_FormatDateTime(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
......
...@@ -2375,4 +2375,40 @@ end sub ...@@ -2375,4 +2375,40 @@ end sub
call testFormatCurrency() call testFormatCurrency()
call testFormatCurrencyError() call testFormatCurrencyError()
sub testFormatPercentError()
on error resume next
dim x
call Err.clear()
x = FormatPercent(null)
call ok(Err.number = 13, "Err.number = " & Err.number)
call ok(getVT(x) = "VT_EMPTY*", "getVT = " & getVT(x))
call Err.clear()
x = FormatPercent(.10,null)
call ok(Err.number = 94, "Err.number = " & Err.number)
call ok(getVT(x) = "VT_EMPTY*", "getVT = " & getVT(x))
call Err.clear()
x = FormatPercent(.10,0,null)
call ok(Err.number = 94, "Err.number = " & Err.number)
call ok(getVT(x) = "VT_EMPTY*", "getVT = " & getVT(x))
call Err.clear()
x = FormatPercent(.10,0,0,null)
call ok(Err.number = 94, "Err.number = " & Err.number)
call ok(getVT(x) = "VT_EMPTY*", "getVT = " & getVT(x))
call Err.clear()
x = FormatPercent(.10,0,0,0,null)
call ok(Err.number = 94, "Err.number = " & Err.number)
call ok(getVT(x) = "VT_EMPTY*", "getVT = " & getVT(x))
end sub
sub testFormatPercent()
dim x
x = FormatPercent(0)
x = FormatPercent(.12,,,-1)
call ok(getVT(x) = "VT_BSTR*", "getVT = " & getVT(x))
end sub
call testFormatPercent()
call testFormatPercentError()
Call reportSuccess() Call reportSuccess()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment