[glib/win32-enhance-gtimezone: 2/2] Update the gdatetime Test Program for Windows



commit 6f02f8efd89f39ee354d5b35c98dd96354003a65
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Thu Feb 20 11:48:00 2014 +0800

    Update the gdatetime Test Program for Windows
    
    Update the gdatetime test program to make use of the updates that was
    done in gtimezone.c in the previous commit, so that we don't have to
    worry what language version of Windows the tests are being run in, but
    instead be assured that we produce and check for the English-language
    time zone name strings.
    
    Also, instead of testing for "Pacific Standard Time" in
    test_GDAteTime_printf(), use GetDynamicTimeZoneInformation() to get the
    actual time zone string (where the system running the test program is)
    we want to check for.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=719344

 glib/tests/gdatetime.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
---
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
index 00e22181e..4e6559ad8 100644
--- a/glib/tests/gdatetime.c
+++ b/glib/tests/gdatetime.c
@@ -25,6 +25,11 @@
 #include <glib/gstdio.h>
 #include <locale.h>
 
+#ifdef G_OS_WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#endif
+
 #define ASSERT_DATE(dt,y,m,d) G_STMT_START { \
   g_assert_nonnull ((dt)); \
   g_assert_cmpint ((y), ==, g_date_time_get_year ((dt))); \
@@ -1029,6 +1034,13 @@ test_GDateTime_new_full (void)
   GTimeZone *tz, *dt_tz;
   GDateTime *dt;
 
+#ifdef G_OS_WIN32
+  LCID currLcid = GetThreadLocale ();
+  LANGID currLangId = LANGIDFROMLCID (currLcid);
+  LANGID en = MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US);
+  SetThreadUILanguage (en);
+#endif
+
   dt = g_date_time_new_utc (2009, 12, 11, 12, 11, 10);
   g_assert_cmpint (2009, ==, g_date_time_get_year (dt));
   g_assert_cmpint (12, ==, g_date_time_get_month (dt));
@@ -1063,6 +1075,7 @@ test_GDateTime_new_full (void)
                     g_date_time_get_timezone_abbreviation (dt));
   g_assert_cmpstr ("Pacific Standard Time", ==,
                    g_time_zone_get_identifier (dt_tz));
+  SetThreadUILanguage (currLangId);
 #endif
   g_assert (!g_date_time_is_daylight_savings (dt));
   g_date_time_unref (dt);
@@ -1331,6 +1344,15 @@ test_GDateTime_printf (void)
   gchar dst[64];
   struct tm tt;
   time_t t;
+#ifdef G_OS_WIN32
+  gchar *current_tz = NULL;
+  DYNAMIC_TIME_ZONE_INFORMATION dtz_info;
+  LCID currLcid = GetThreadLocale ();
+  LANGID currLangId = LANGIDFROMLCID (currLcid);
+  LANGID en = MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US);
+
+  SetThreadUILanguage (en);
+#endif
 
 #define TEST_PRINTF(f,o)                        G_STMT_START {  \
 GDateTime *__dt = g_date_time_new_local (2009, 10, 24, 0, 0, 0);\
@@ -1426,7 +1448,14 @@ GDateTime *__dt = g_date_time_new_local (2009, 10, 24, 0, 0, 0);\
 #ifdef G_OS_UNIX
   TEST_PRINTF ("%Z", dst);
 #elif defined G_OS_WIN32
-  TEST_PRINTF ("%Z", "Pacific Standard Time");
+  g_assert (GetDynamicTimeZoneInformation (&dtz_info) != TIME_ZONE_ID_INVALID);
+  if (wcscmp (dtz_info.StandardName, L"") != 0)
+    current_tz = g_utf16_to_utf8 (dtz_info.StandardName, -1, NULL, NULL, NULL);
+  else
+    current_tz = g_utf16_to_utf8 (dtz_info.DaylightName, -1, NULL, NULL, NULL);
+  TEST_PRINTF ("%Z", current_tz);
+  g_free (current_tz);
+  SetThreadUILanguage (currLangId);
 #endif
 
   if (old_lc_messages != NULL)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]