Commit 5804fa7c authored by Michael Catanzaro's avatar Michael Catanzaro Committed by Michael Catanzaro

tests: Convert second wall clock test to uselocale

parent b87de749
...@@ -36,7 +36,8 @@ test_utf8_character (const char *utf8_char, ...@@ -36,7 +36,8 @@ test_utf8_character (const char *utf8_char,
{ {
GDateTime *datetime; GDateTime *datetime;
GnomeWallClock *clock; GnomeWallClock *clock;
const char *save_locale; locale_t locale;
locale_t save_locale;
const char *str; const char *str;
/* When testing that UTF8 locales don't use double spaces /* When testing that UTF8 locales don't use double spaces
...@@ -44,12 +45,10 @@ test_utf8_character (const char *utf8_char, ...@@ -44,12 +45,10 @@ test_utf8_character (const char *utf8_char,
doesn't contain double spaces ("Aug 1") */ doesn't contain double spaces ("Aug 1") */
datetime = g_date_time_new_local (2014, 5, 28, 23, 59, 59); datetime = g_date_time_new_local (2014, 5, 28, 23, 59, 59);
/* Save current locale */
save_locale = setlocale (LC_ALL, NULL);
/* In the C locale, make sure the time string is formatted with regular /* In the C locale, make sure the time string is formatted with regular
* colons */ * colons */
setlocale (LC_ALL, "C"); locale = newlocale (LC_ALL_MASK, "C", (locale_t) 0);
save_locale = uselocale (locale);
clock = gnome_wall_clock_new (); clock = gnome_wall_clock_new ();
str = gnome_wall_clock_string_for_datetime (clock, str = gnome_wall_clock_string_for_datetime (clock,
datetime, datetime,
...@@ -59,8 +58,9 @@ test_utf8_character (const char *utf8_char, ...@@ -59,8 +58,9 @@ test_utf8_character (const char *utf8_char,
g_assert (strstr (str, utf8_char) == NULL); g_assert (strstr (str, utf8_char) == NULL);
g_object_unref (clock); g_object_unref (clock);
/* In a UTF8 locale, we want ratio characters and no colons */ /* In a UTF8 locale, we want ratio characters and no colons. */
setlocale (LC_ALL, "en_US.utf8"); locale = newlocale (LC_ALL_MASK, "en_US.utf8", locale);
uselocale (locale);
clock = gnome_wall_clock_new (); clock = gnome_wall_clock_new ();
str = gnome_wall_clock_string_for_datetime (clock, str = gnome_wall_clock_string_for_datetime (clock,
datetime, datetime,
...@@ -72,7 +72,8 @@ test_utf8_character (const char *utf8_char, ...@@ -72,7 +72,8 @@ test_utf8_character (const char *utf8_char,
/* ... and same thing with an RTL locale: should be formatted with /* ... and same thing with an RTL locale: should be formatted with
* ratio characters */ * ratio characters */
setlocale (LC_ALL, "he_IL.utf8"); locale = newlocale (LC_ALL_MASK, "he_IL.utf8", locale);
uselocale (locale);
clock = gnome_wall_clock_new (); clock = gnome_wall_clock_new ();
str = gnome_wall_clock_string_for_datetime (clock, str = gnome_wall_clock_string_for_datetime (clock,
datetime, datetime,
...@@ -85,7 +86,8 @@ test_utf8_character (const char *utf8_char, ...@@ -85,7 +86,8 @@ test_utf8_character (const char *utf8_char,
g_date_time_unref (datetime); g_date_time_unref (datetime);
/* Restore previous locale */ /* Restore previous locale */
setlocale (LC_ALL, save_locale); uselocale (save_locale);
freelocale (locale);
} }
static void static void
...@@ -105,13 +107,13 @@ test_clock_format_setting (void) ...@@ -105,13 +107,13 @@ test_clock_format_setting (void)
{ {
GnomeWallClock *clock; GnomeWallClock *clock;
GSettings *settings; GSettings *settings;
const char *save_locale; locale_t locale;
locale_t save_locale;
const char *str; const char *str;
/* Save current locale */ locale = newlocale (LC_ALL_MASK, "en_US.utf8", (locale_t) 0);
save_locale = setlocale (LC_ALL, NULL); save_locale = uselocale (locale);
setlocale (LC_ALL, "en_US.utf8");
settings = g_settings_new ("org.gnome.desktop.interface"); settings = g_settings_new ("org.gnome.desktop.interface");
/* In 12h format, the string ends with AM or PM */ /* In 12h format, the string ends with AM or PM */
...@@ -131,7 +133,8 @@ test_clock_format_setting (void) ...@@ -131,7 +133,8 @@ test_clock_format_setting (void)
g_object_unref (settings); g_object_unref (settings);
/* Restore previous locale */ /* Restore previous locale */
setlocale (LC_ALL, save_locale); uselocale (save_locale);
freelocale (locale);
} }
static gboolean static gboolean
...@@ -183,13 +186,13 @@ test_weekday_setting (void) ...@@ -183,13 +186,13 @@ test_weekday_setting (void)
{ {
GnomeWallClock *clock; GnomeWallClock *clock;
GSettings *settings; GSettings *settings;
const char *save_locale; locale_t locale;
locale_t save_locale;
const char *str, *ptr, *s; const char *str, *ptr, *s;
/* Save current locale */ /* Save current locale */
save_locale = setlocale (LC_ALL, NULL); locale = newlocale (LC_ALL_MASK, "C", (locale_t) 0);
save_locale = uselocale (locale);
setlocale (LC_ALL, "C");
settings = g_settings_new ("org.gnome.desktop.interface"); settings = g_settings_new ("org.gnome.desktop.interface");
/* Set 24h format, so that the only alphabetical part will be the weekday */ /* Set 24h format, so that the only alphabetical part will be the weekday */
...@@ -225,7 +228,8 @@ test_weekday_setting (void) ...@@ -225,7 +228,8 @@ test_weekday_setting (void)
g_object_unref (settings); g_object_unref (settings);
/* Restore previous locale */ /* Restore previous locale */
setlocale (LC_ALL, save_locale); uselocale (save_locale);
freelocale (locale);
} }
int int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment