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, because on Windows the actual result will be
dependent on which timezone the system running the test program is in.

https://bugzilla.gnome.org/show_bug.cgi?id=719344
This commit is contained in:
Chun-wei Fan 2014-02-20 11:48:00 +08:00
parent 2e5d3aa911
commit 5ca4ac16ef

View File

@ -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);
@ -1333,6 +1346,11 @@ test_GDateTime_printf (void)
struct tm tt;
time_t t;
#ifdef G_OS_WIN32
gchar *current_tz = NULL;
DYNAMIC_TIME_ZONE_INFORMATION dtz_info;
#endif
#define TEST_PRINTF(f,o) G_STMT_START { \
GDateTime *__dt = g_date_time_new_local (2009, 10, 24, 0, 0, 0);\
gchar *__p = g_date_time_format (__dt, (f)); \
@ -1430,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);
#endif
if (old_lc_messages != NULL)