[PATCH 2/2] vbscript/tests: Fix test for WeekDayName(foo, bar, 0).

Alex Henrie <[email protected]>
Newsgroups gmane.comp.emulators.wine.patches
Message-ID <[email protected]>
Signed-off-by: Alex Henrie <[email protected]>
---
The original test failed on SUBLANG_ENGLISH_UK and SUBLANG_ENGLISH_AUS,
where the first day of the week is Monday. I changed the test to check
against the correct first day of the week no matter what the locale is.
---
 dlls/vbscript/tests/api.vbs |  4 +++-
 dlls/vbscript/tests/run.c   | 35 ++++++++++++++++++++++++++---------
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs
index 95ef84f6c9..baa0553225 100644
--- a/dlls/vbscript/tests/api.vbs
+++ b/dlls/vbscript/tests/api.vbs
@@ -594,7 +594,6 @@ if isEnglishLang then
     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, 2.5) = "Mon", "WeekDayName(1, true, 2.5) = " & WeekDayName(1, true, 2.5))
     Call ok(WeekDayName(1, true, 1.5) = "Mon", "WeekDayName(1, true, 1.5) = " & WeekDayName(1, true, 1.5))
@@ -609,6 +608,9 @@ if isEnglishLang then
     Call ok(MonthName(12, true) = "Dec", "MonthName(12, true) = " & MonthName(12, true))
 end if
 
+Call ok(WeekDayName(1, true, 0) = WeekDayName(1, true, firstDayOfWeek), _
+        "WeekDayName(1, true, 0) = " & WeekDayName(1, true, 0))
+
 Call ok(getVT(Now()) = "VT_DATE", "getVT(Now()) = " & getVT(Now()))
 
 Call ok(vbOKOnly = 0, "vbOKOnly = " & vbOKOnly)
diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c
index 8a6d7e321a..8e3eb8b99e 100644
--- a/dlls/vbscript/tests/run.c
+++ b/dlls/vbscript/tests/run.c
@@ -123,6 +123,7 @@ DEFINE_EXPECT(OnScriptError);
 #define DISPID_GLOBAL_LETOBJ        1018
 #define DISPID_GLOBAL_SETOBJ        1019
 #define DISPID_GLOBAL_TODO_WINE_OK  1020
+#define DISPID_GLOBAL_WEEKSTARTDAY  1021
 
 #define DISPID_TESTOBJ_PROPGET      2000
 #define DISPID_TESTOBJ_PROPPUT      2001
@@ -136,6 +137,7 @@ static const WCHAR testW[] = {'t','e','s','t',0};
 static const WCHAR emptyW[] = {0};
 
 static BOOL strict_dispid_check, is_english, allow_ui;
+static int first_day_of_week;
 static const char *test_name = "(null)";
 static int test_counter;
 static SCRIPTUICHANDLING uic_handling = SCRIPTUICHANDLING_NOUIERROR;
@@ -204,10 +206,11 @@ static const char *vt2a(VARIANT *v)
     }
 }
 
-/* Returns true if the user interface is in English. Note that this does not
- * presume of the formatting of dates, numbers, etc.
+/* Sets is_english to true if the user interface is in English. Note that this
+ * does not presume the formatting of dates, numbers, etc.
+ * Also sets first_day_of_week to 1 if Sunday or 2 if Monday.
  */
-static BOOL is_lang_english(void)
+static void detect_locale(void)
 {
     HMODULE hkernel32 = NULL;
     LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL;
@@ -216,12 +219,16 @@ static BOOL is_lang_english(void)
     hkernel32 = GetModuleHandleA("kernel32.dll");
     pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
     pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
-    if (pGetThreadUILanguage && PRIMARYLANGID(pGetThreadUILanguage()) != LANG_ENGLISH)
-        return FALSE;
-    if (pGetUserDefaultUILanguage && PRIMARYLANGID(pGetUserDefaultUILanguage()) != LANG_ENGLISH)
-        return FALSE;
+    if (!pGetThreadUILanguage || !pGetUserDefaultUILanguage)
+        return;
 
-    return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
+    is_english = (PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH &&
+                  PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH &&
+                  PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH);
+
+    GetLocaleInfoA(pGetThreadUILanguage(), LOCALE_IFIRSTDAYOFWEEK | LOCALE_RETURN_NUMBER,
+                   (void*)&first_day_of_week, sizeof(first_day_of_week));
+    first_day_of_week = (first_day_of_week + 2) % 7;
 }
 
 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
@@ -1007,6 +1014,11 @@ static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD
         *pid = DISPID_GLOBAL_ISENGLANG;
         return S_OK;
     }
+    if(!strcmp_wa(bstrName, "firstDayOfWeek")) {
+        test_grfdex(grfdex, fdexNameCaseInsensitive);
+        *pid = DISPID_GLOBAL_WEEKSTARTDAY;
+        return S_OK;
+    }
     if(!strcmp_wa(bstrName, "testObj")) {
         test_grfdex(grfdex, fdexNameCaseInsensitive);
         *pid = DISPID_GLOBAL_TESTOBJ;
@@ -1180,6 +1192,11 @@ static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid,
         V_BOOL(pvarRes) = is_english ? VARIANT_TRUE : VARIANT_FALSE;
         return S_OK;
 
+    case DISPID_GLOBAL_WEEKSTARTDAY:
+        V_VT(pvarRes) = VT_I4;
+        V_I4(pvarRes) = first_day_of_week;
+        return S_OK;
+
     case DISPID_GLOBAL_VBVAR:
         CHECK_EXPECT(global_vbvar_i);
 
@@ -2352,7 +2369,7 @@ START_TEST(run)
     int argc;
     char **argv;
 
-    is_english = is_lang_english();
+    detect_locale();
     if(!is_english)
         skip("Skipping some tests in non-English locale\n");
 
-- 
2.14.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.