[PATCH v4] 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.

v2: Stopped using GetProcAddress for GetThreadUILanguage and
GetUserDefaultUILanguage.

v3: Brought back GetProcAddress for GetThreadUILanguage and fixed the
calculation of first_day_of_week.

v4: Rely on GetUserDefaultUILanguage if GetThreadUILanguage is not
available, and don't try to close the kernel32 module handle.
---
 dlls/vbscript/tests/api.vbs |  4 +++-
 dlls/vbscript/tests/run.c   | 44 ++++++++++++++++++++++++++------------------
 2 files changed, 29 insertions(+), 19 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 81b1ced463..7c97db2a9b 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,27 +206,23 @@ 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.
+ * Sets first_day_of_week to 1 if Sunday, 2 if Monday, and so on.
  */
-static BOOL is_lang_english(void)
+static void detect_locale(void)
 {
-    static HMODULE hkernel32 = NULL;
-    static LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL;
-    static LANGID (WINAPI *pGetUserDefaultUILanguage)(void) = NULL;
+    HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
+    LANGID (WINAPI *pGetThreadUILanguage)(void) = (void*)GetProcAddress(kernel32, "GetThreadUILanguage");
 
-    if (!hkernel32)
-    {
-        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;
+    is_english = ((!pGetThreadUILanguage || PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH) &&
+                  PRIMARYLANGID(GetUserDefaultUILanguage()) == LANG_ENGLISH &&
+                  PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH);
 
-    return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
+    GetLocaleInfoA(pGetThreadUILanguage ? pGetThreadUILanguage() : GetUserDefaultUILanguage(),
+                   LOCALE_IFIRSTDAYOFWEEK | LOCALE_RETURN_NUMBER,
+                   (void*)&first_day_of_week, sizeof(first_day_of_week));
+    first_day_of_week = 1 + (first_day_of_week + 1) % 7;
 }
 
 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
@@ -1010,6 +1008,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;
@@ -1183,6 +1186,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);
 
@@ -2355,7 +2363,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.