shlwapi/tests: Some tests require that the user interface be in English. (try 2)

Francois Gouget fgouget at free.fr
Thu Sep 15 02:36:43 CDT 2011


With MUI versions of Windows checking for the default user language id or locale is insufficient.
---

The display of file sizes, such as '1,536 KB' is a combination of two 
parts: '1,536' the formatting of which depends on the locale picked for 
numbers, and 'KB' which corresponds to the user interface language. So 
one could also get '1,536 Ko' (English number formatting, French unit) 
or '1536 KB' (French number formatting, Englis unit).

So I added a function to check the locale that decides the number 
formatting, is_locale_english(), and another for the user interface 
language is_lang_english().

The reason why the previous patch failed on the testbot is that a number 
of its VMs are Dutch Windows versions with just the user interface 
language switched to English but not the number formatting. My Windows 7 
VM in contrast is the opposite: the number formatting is English but the 
user interface is in French.


 dlls/shlwapi/tests/string.c |   44 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/dlls/shlwapi/tests/string.c b/dlls/shlwapi/tests/string.c
index 4b984ce..5522137 100644
--- a/dlls/shlwapi/tests/string.c
+++ b/dlls/shlwapi/tests/string.c
@@ -197,6 +197,39 @@ static const StrFromTimeIntervalResult StrFromTimeInterval_results[] = {
   { 0, 0, NULL }
 };
 
+
+/* Returns true if the user interface is in English. Note that this does not
+ * presume of the formatting of dates, numbers, etc.
+ */
+static BOOL is_lang_english(void)
+{
+    static HMODULE hkernel32 = NULL;
+    static LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL;
+    static LANGID (WINAPI *pGetUserDefaultUILanguage)(void) = NULL;
+
+    if (!hkernel32)
+    {
+        hkernel32 = GetModuleHandleA("kernel32.dll");
+        pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
+        pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
+    }
+    if (pGetThreadUILanguage)
+        return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH;
+    if (pGetUserDefaultUILanguage)
+        return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH;
+
+    return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
+}
+
+/* Returns true if the dates, numbers, etc. are formatted using English
+ * conventions.
+ */
+static BOOL is_locale_english(void)
+{
+    /* Surprisingly GetThreadLocale() is irrelevant here */
+    return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
+}
+
 static void test_StrChrA(void)
 {
   char string[129];
@@ -1405,15 +1438,18 @@ START_TEST(string)
   test_StrDupA();
 
   /* language-dependent test */
-  if (PRIMARYLANGID(GetUserDefaultLangID()) != LANG_ENGLISH)
-    skip("English is required for StrFromTimeInterval and StrFormat*Size tests\n");
-  else
+  if (is_lang_english() && is_locale_english())
   {
     test_StrFormatByteSize64A();
     test_StrFormatKBSizeA();
     test_StrFormatKBSizeW();
-    test_StrFromTimeIntervalA();
   }
+  else
+    skip("An English UI and locale is required for the StrFormat*Size tests\n");
+  if (is_lang_english())
+    test_StrFromTimeIntervalA();
+  else
+    skip("An English UI is required for the StrFromTimeInterval tests\n");
 
   test_StrCmpA();
   test_StrCmpW();
-- 
1.7.5.4



More information about the wine-patches mailing list