[gnome-desktop/mcatanzaro/uselocale: 4/5] tests: Convert second wall clock test to uselocale



commit 5804fa7c430ba2d2671678255719c1cd24bba5f3
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Wed Feb 20 21:57:00 2019 -0600

    tests: Convert second wall clock test to uselocale

 tests/wall-clock.c | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)
---
diff --git a/tests/wall-clock.c b/tests/wall-clock.c
index 62a1f3ba..4937ee66 100644
--- a/tests/wall-clock.c
+++ b/tests/wall-clock.c
@@ -36,7 +36,8 @@ test_utf8_character (const char *utf8_char,
 {
        GDateTime  *datetime;
        GnomeWallClock *clock;
-       const char *save_locale;
+       locale_t locale;
+       locale_t save_locale;
        const char *str;
 
        /* When testing that UTF8 locales don't use double spaces
@@ -44,12 +45,10 @@ test_utf8_character (const char *utf8_char,
           doesn't contain double spaces ("Aug  1") */
        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
          * colons */
-       setlocale (LC_ALL, "C");
+       locale = newlocale (LC_ALL_MASK, "C", (locale_t) 0);
+       save_locale = uselocale (locale);
        clock = gnome_wall_clock_new ();
        str = gnome_wall_clock_string_for_datetime (clock,
                                                    datetime,
@@ -59,8 +58,9 @@ test_utf8_character (const char *utf8_char,
        g_assert (strstr (str, utf8_char) == NULL);
        g_object_unref (clock);
 
-       /* In a UTF8 locale, we want ratio characters and no colons */
-       setlocale (LC_ALL, "en_US.utf8");
+       /* In a UTF8 locale, we want ratio characters and no colons. */
+       locale = newlocale (LC_ALL_MASK, "en_US.utf8", locale);
+       uselocale (locale);
        clock = gnome_wall_clock_new ();
        str = gnome_wall_clock_string_for_datetime (clock,
                                                    datetime,
@@ -72,7 +72,8 @@ test_utf8_character (const char *utf8_char,
 
        /* ... and same thing with an RTL locale: should be formatted with
          * ratio characters */
-       setlocale (LC_ALL, "he_IL.utf8");
+       locale = newlocale (LC_ALL_MASK, "he_IL.utf8", locale);
+       uselocale (locale);
        clock = gnome_wall_clock_new ();
        str = gnome_wall_clock_string_for_datetime (clock,
                                                    datetime,
@@ -85,7 +86,8 @@ test_utf8_character (const char *utf8_char,
        g_date_time_unref (datetime);
 
        /* Restore previous locale */
-       setlocale (LC_ALL, save_locale);
+       uselocale (save_locale);
+       freelocale (locale);
 }
 
 static void
@@ -105,13 +107,13 @@ test_clock_format_setting (void)
 {
        GnomeWallClock *clock;
        GSettings *settings;
-       const char *save_locale;
+       locale_t locale;
+       locale_t save_locale;
        const char *str;
 
-       /* Save current locale */
-       save_locale = setlocale (LC_ALL, NULL);
+       locale = newlocale (LC_ALL_MASK, "en_US.utf8", (locale_t) 0);
+       save_locale = uselocale (locale);
 
-       setlocale (LC_ALL, "en_US.utf8");
        settings = g_settings_new ("org.gnome.desktop.interface");
 
        /* In 12h format, the string ends with AM or PM */
@@ -131,7 +133,8 @@ test_clock_format_setting (void)
        g_object_unref (settings);
 
        /* Restore previous locale */
-       setlocale (LC_ALL, save_locale);
+       uselocale (save_locale);
+       freelocale (locale);
 }
 
 static gboolean
@@ -183,13 +186,13 @@ test_weekday_setting (void)
 {
        GnomeWallClock *clock;
        GSettings *settings;
-       const char *save_locale;
+       locale_t locale;
+       locale_t save_locale;
        const char *str, *ptr, *s;
 
        /* Save current locale */
-       save_locale = setlocale (LC_ALL, NULL);
-
-       setlocale (LC_ALL, "C");
+       locale = newlocale (LC_ALL_MASK, "C", (locale_t) 0);
+       save_locale = uselocale (locale);
        settings = g_settings_new ("org.gnome.desktop.interface");
 
        /* Set 24h format, so that the only alphabetical part will be the weekday */
@@ -225,7 +228,8 @@ test_weekday_setting (void)
        g_object_unref (settings);
 
        /* Restore previous locale */
-       setlocale (LC_ALL, save_locale);
+       uselocale (save_locale);
+       freelocale (locale);
 }
 
 int


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