[gnome-desktop: 4/6] tests: Adjust test conditions to ensure assumptions



commit 7ceb5f1745b8935c37934c1964b34c5aa41312e0
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Aug 1 18:21:00 2018 +0200

    tests: Adjust test conditions to ensure assumptions
    
    In order to test that date and time are separated by the correct
    UTF-8 character on UTF-8 locales, the clock needs to show the date
    in the first place.
    
    In order to correctly test that the returned string doesn't contain
    the non-UTF-8 fallback of two spaces, we need to make sure that the
    date itself doesn't inject any extra spaces itself ("Aug  1").
    
    https://gitlab.gnome.org/GNOME/gnome-desktop/issues/8

 tests/wall-clock.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/tests/wall-clock.c b/tests/wall-clock.c
index 5200cf89..17a29bf9 100644
--- a/tests/wall-clock.c
+++ b/tests/wall-clock.c
@@ -34,10 +34,16 @@ static void
 test_utf8_character (const char *utf8_char,
                      const char *non_utf8_fallback)
 {
+       GDateTime  *datetime;
        GnomeWallClock *clock;
        const char *save_locale;
        const char *str;
 
+       /* When testing that UTF8 locales don't use double spaces
+          to separate date and time, make sure the date itself
+          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);
 
@@ -45,7 +51,10 @@ test_utf8_character (const char *utf8_char,
          * colons */
        setlocale (LC_ALL, "C");
        clock = gnome_wall_clock_new ();
-       str = gnome_wall_clock_get_clock (clock);
+       str = gnome_wall_clock_string_for_datetime (clock,
+                                                   datetime,
+                                                   G_DESKTOP_CLOCK_FORMAT_24H,
+                                                   TRUE, TRUE, TRUE);
        g_assert (strstr (str, non_utf8_fallback) != NULL);
        g_assert (strstr (str, utf8_char) == NULL);
        g_object_unref (clock);
@@ -53,7 +62,10 @@ test_utf8_character (const char *utf8_char,
        /* In a UTF8 locale, we want ratio characters and no colons */
        setlocale (LC_ALL, "en_US.utf8");
        clock = gnome_wall_clock_new ();
-       str = gnome_wall_clock_get_clock (clock);
+       str = gnome_wall_clock_string_for_datetime (clock,
+                                                   datetime,
+                                                   G_DESKTOP_CLOCK_FORMAT_24H,
+                                                   TRUE, TRUE, TRUE);
        g_assert (strstr (str, non_utf8_fallback) == NULL);
        g_assert (strstr (str, utf8_char) != NULL);
        g_object_unref (clock);
@@ -62,11 +74,16 @@ test_utf8_character (const char *utf8_char,
          * ratio characters */
        setlocale (LC_ALL, "he_IL.utf8");
        clock = gnome_wall_clock_new ();
-       str = gnome_wall_clock_get_clock (clock);
+       str = gnome_wall_clock_string_for_datetime (clock,
+                                                   datetime,
+                                                   G_DESKTOP_CLOCK_FORMAT_24H,
+                                                   TRUE, TRUE, TRUE);
        g_assert (strstr (str, non_utf8_fallback) == NULL);
        g_assert (strstr (str, utf8_char) != NULL);
        g_object_unref (clock);
 
+       g_date_time_unref (datetime);
+
        /* Restore previous locale */
        setlocale (LC_ALL, save_locale);
 }


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