summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw@src.gnome.org>2018-04-29 02:04:01 +0800
committerPhilip Withnall <withnall@endlessm.com>2018-05-01 21:43:23 +0100
commita0c7f85437093b073b3e3b2c9cb337065b6ea896 (patch)
tree143c700e9b18f722e2e8a88d3350524257d7907c
parentc47cf7355c6bc7b874431f943cd14ff526c48fc5 (diff)
downloadglib-a0c7f85437093b073b3e3b2c9cb337065b6ea896.tar.gz
tests: Fix GDateTime format tests on non-English locales
It seems that the test expects g_date_time_format to return formatted results in English, and there is no setlocale (LC_ALL, "") call in the file so the test does run in the default C locale. However, gettext seems to read the value of LC_MESSAGES from the environment by itself. Even if the value of LC_MESSAGES locale is C because of not calling setlocale, gettext still translates the name of the month according to the LC_MESSAGES environment variable, causing g_date_time_format_locale to fail on the "%b" test case because it cannot convert UTF-8 text returned by get_month_name_with_day to ASCII. To avoid the test failure, we set the LC_MESSAGES environment variable to C before format tests and restore it at the end of the function. https://bugzilla.gnome.org/show_bug.cgi?id=795165
-rw-r--r--glib/tests/gdatetime.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
index b102205b9..79a131ab5 100644
--- a/glib/tests/gdatetime.c
+++ b/glib/tests/gdatetime.c
@@ -1324,6 +1324,7 @@ test_GDateTime_printf (void)
* that long, and it will cause the test to fail if dst isn't big
* enough.
*/
+ gchar *old_lc_messages;
gchar dst[64];
struct tm tt;
time_t t;
@@ -1353,6 +1354,9 @@ GDateTime *__dt = g_date_time_new_local (2009, 10, 24, 0, 0, 0);\
g_date_time_unref (dt); \
g_free (p); } G_STMT_END
+ old_lc_messages = g_strdup (g_getenv ("LC_MESSAGES"));
+ g_setenv ("LC_MESSAGES", "C", TRUE);
+
/*
* This is a little helper to make sure we can compare timezones to
* that of the generated timezone.
@@ -1420,6 +1424,12 @@ GDateTime *__dt = g_date_time_new_local (2009, 10, 24, 0, 0, 0);\
#elif defined G_OS_WIN32
TEST_PRINTF ("%Z", "Pacific Standard Time");
#endif
+
+ if (old_lc_messages != NULL)
+ g_setenv ("LC_MESSAGES", old_lc_messages, TRUE);
+ else
+ g_unsetenv ("LC_MESSAGES");
+ g_free (old_lc_messages);
}
static void