vbscript: Added WeekDayName implementation.

This commit is contained in:
Jacek Caban 2012-09-27 13:10:49 +02:00 committed by Alexandre Julliard
parent 5f5f20d6cf
commit a42f3cb45e
3 changed files with 66 additions and 10 deletions

View File

@ -63,7 +63,7 @@ static IInternetHostSecurityManager *get_sec_mgr(script_ctx_t *ctx)
return ctx->secmgr = secmgr;
}
static HRESULT return_bstr(VARIANT *res, const WCHAR *str)
static HRESULT return_string(VARIANT *res, const WCHAR *str)
{
BSTR ret;
@ -79,6 +79,17 @@ static HRESULT return_bstr(VARIANT *res, const WCHAR *str)
return S_OK;
}
static HRESULT return_bstr(VARIANT *res, BSTR str)
{
if(res) {
V_VT(res) = VT_BSTR;
V_BSTR(res) = str;
}else {
SysFreeString(str);
}
return S_OK;
}
static HRESULT return_short(VARIANT *res, short val)
{
if(res) {
@ -137,6 +148,9 @@ static HRESULT to_int(VARIANT *v, int *ret)
*ret = n;
break;
}
case VT_BOOL:
*ret = V_BOOL(v) ? -1 : 0;
break;
default:
FIXME("not supported %s\n", debugstr_variant(v));
return E_NOTIMPL;
@ -427,7 +441,7 @@ static HRESULT Global_Hex(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIA
*ptr = '0';
}
return return_bstr(res, ptr);
return return_string(res, ptr);
}
static HRESULT Global_Oct(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
@ -1224,8 +1238,35 @@ static HRESULT Global_FormatDateTime(vbdisp_t *This, VARIANT *arg, unsigned args
static HRESULT Global_WeekdayName(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
{
FIXME("\n");
return E_NOTIMPL;
int weekday, first_day = 0, abbrev = 0;
BSTR ret;
HRESULT hres;
TRACE("\n");
assert(1 <= args_cnt && args_cnt <= 3);
hres = to_int(arg+args_cnt-1, &weekday);
if(FAILED(hres))
return hres;
if(args_cnt > 1) {
hres = to_int(arg+args_cnt-2, &abbrev);
if(FAILED(hres))
return hres;
if(args_cnt == 3) {
hres = to_int(arg, &first_day);
if(FAILED(hres))
return hres;
}
}
hres = VarWeekdayName(weekday, abbrev, first_day, 0, &ret);
if(FAILED(hres))
return hres;
return return_bstr(res, ret);
}
static HRESULT Global_MonthName(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
@ -1988,7 +2029,7 @@ static const builtin_prop_t global_props[] = {
{DISPID_GLOBAL_FORMATCURRENCY, Global_FormatCurrency, 0, 1, 5},
{DISPID_GLOBAL_FORMATPERCENT, Global_FormatPercent, 0, 1, 5},
{DISPID_GLOBAL_FORMATDATETIME, Global_FormatDateTime, 0, 1, 2},
{DISPID_GLOBAL_WEEKDAYNAME, Global_WeekdayName, 0, 3},
{DISPID_GLOBAL_WEEKDAYNAME, Global_WeekdayName, 0, 1, 3},
{DISPID_GLOBAL_MONTHNAME, Global_MonthName, 0, 1, 2},
{DISPID_GLOBAL_ROUND, Global_Round, 0, 1, 2},
{DISPID_GLOBAL_ESCAPE, Global_Escape, 0, 1},

View File

@ -190,6 +190,7 @@ Call ok(Len(empty) = 0, "Len(empty) = " & Len(empty))
Call ok(Space(1) = " ", "Space(1) = " & Space(1) & """")
Call ok(Space(0) = "", "Space(0) = " & Space(0) & """")
Call ok(Space(false) = "", "Space(false) = " & Space(false) & """")
Call ok(Space(5) = " ", "Space(5) = " & Space(5) & """")
Call ok(Space(5.2) = " ", "Space(5.2) = " & Space(5.2) & """")
Call ok(Space(5.8) = " ", "Space(5.8) = " & Space(5.8) & """")
@ -210,4 +211,18 @@ TestRound "2", 2, "VT_R8"
TestRound true, true, "VT_BOOL"
TestRound false, false, "VT_BOOL"
if isEnglishLang then
Call ok(WeekDayName(1) = "Sunday", "WeekDayName(1) = " & WeekDayName(1))
Call ok(WeekDayName(3) = "Tuesday", "WeekDayName(3) = " & WeekDayName(3))
Call ok(WeekDayName(7) = "Saturday", "WeekDayName(7) = " & WeekDayName(7))
Call ok(WeekDayName(1.1) = "Sunday", "WeekDayName(1.1) = " & WeekDayName(1.1))
Call ok(WeekDayName(1, false) = "Sunday", "WeekDayName(1, false) = " & WeekDayName(1, false))
Call ok(WeekDayName(1, true) = "Sun", "WeekDayName(1, true) = " & WeekDayName(1, true))
Call ok(WeekDayName(1, 10) = "Sun", "WeekDayName(1, 10) = " & WeekDayName(1, 10))
Call ok(WeekDayName(1, true, 0) = "Sun", "WeekDayName(1, true, 0) = " & WeekDayName(1, true, 0))
Call ok(WeekDayName(1, true, 2) = "Mon", "WeekDayName(1, true, 2) = " & WeekDayName(1, true, 2))
Call ok(WeekDayName(1, true, 7) = "Sat", "WeekDayName(1, true, 7) = " & WeekDayName(1, true, 7))
Call ok(WeekDayName(1, true, 7.1) = "Sat", "WeekDayName(1, true, 7.1) = " & WeekDayName(1, true, 7.1))
end if
Call reportSuccess()

View File

@ -202,10 +202,10 @@ static BOOL is_lang_english(void)
pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
}
if (pGetThreadUILanguage)
return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH;
if (pGetUserDefaultUILanguage)
return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH;
if (pGetThreadUILanguage && PRIMARYLANGID(pGetThreadUILanguage()) != LANG_ENGLISH)
return FALSE;
if (pGetUserDefaultUILanguage && PRIMARYLANGID(pGetUserDefaultUILanguage()) != LANG_ENGLISH)
return FALSE;
return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
}
@ -1906,7 +1906,7 @@ START_TEST(run)
is_english = is_lang_english();
if(!is_english)
skip("Skipping some tests in non-English UIs\n");
skip("Skipping some tests in non-English locale\n");
argc = winetest_get_mainargs(&argv);