[libgweather/gnome-3-28] tests: Add a test replicating gnome-shell's world clock usage



commit bfb0d6b55774298e9bc212584367f4fa735344b5
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Jun 13 14:20:23 2018 +0200

    tests: Add a test replicating gnome-shell's world clock usage
    
    This will crash when the timezones are listed as the UTC named timezone
    from the global_world tree variable will have been freed, and then
    accessed again.
    
    See https://bugzilla.redhat.com/show_bug.cgi?id=1577561

 libgweather/test_libgweather.c | 90 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
---
diff --git a/libgweather/test_libgweather.c b/libgweather/test_libgweather.c
index 4623850..82a5c9b 100644
--- a/libgweather/test_libgweather.c
+++ b/libgweather/test_libgweather.c
@@ -58,6 +58,95 @@ test_named_timezones (void)
     }
 }
 
+static GList *
+get_list_from_configuration (GWeatherLocation *world,
+                             const char *str,
+                             gsize n_expected_items)
+{
+    GList *list;
+    GVariant *v;
+    guint i;
+
+    /* The format of the CONFIGURATION is "aa{sv}" */
+    v = g_variant_parse (NULL,
+                         str,
+                         NULL,
+                         NULL,
+                         NULL);
+    g_assert_cmpint (g_variant_n_children (v), ==, n_expected_items);
+
+    list = NULL;
+
+    for (i = 0; i < g_variant_n_children (v); i++) {
+        GVariantIter iteri;
+        GVariant *child;
+        char *key;
+        GVariant *value;
+
+        child = g_variant_get_child_value (v, i);
+        g_variant_iter_init (&iteri, child);
+        while (g_variant_iter_next (&iteri, "{sv}", &key, &value)) {
+            GWeatherLocation *loc;
+
+            if (g_strcmp0 (key, "location") != 0) {
+                g_variant_unref (value);
+                g_free (key);
+                continue;
+            }
+
+            loc = gweather_location_deserialize (world, value);
+            g_assert_nonnull (loc);
+            list = g_list_prepend (list, loc);
+
+            g_variant_unref (value);
+            g_free (key);
+        }
+    }
+
+    g_variant_unref (v);
+
+    g_assert_cmpint (g_list_length (list), ==, n_expected_items);
+
+    return list;
+}
+
+#define CONFIGURATION "[{'location': <(uint32 2, <('Rio de Janeiro', 'SBES', false, [(-0.39822596348113698, 
-0.73478361508961265)], [(-0.39822596348113698, -0.73478361508961265)])>)>}, {'location': <(uint32 2, 
<('Coordinated Universal Time (UTC)', '@UTC', false, @a(dd) [], @a(dd) [])>)>}]"
+
+static void test_timezones (void);
+
+static void
+test_named_timezones_deserialized (void)
+{
+    GWeatherLocation *world;
+    GList *list, *l;
+
+    world = gweather_location_get_world ();
+    g_assert (world);
+
+    list = get_list_from_configuration (world, CONFIGURATION, 2);
+    for (l = list; l != NULL; l = l->next)
+        gweather_location_unref (l->data);
+    g_list_free (list);
+
+    list = get_list_from_configuration (world, CONFIGURATION, 2);
+    for (l = list; l != NULL; l = l->next) {
+        GWeatherLocation *loc = l->data;
+        GWeatherTimezone *tz;
+        const char *tzid;
+
+        tz = gweather_location_get_timezone (loc);
+        g_assert_nonnull (tz);
+        tzid = gweather_timezone_get_tzid (tz);
+        g_assert_nonnull (tzid);
+        gweather_location_get_level (loc);
+
+        gweather_location_unref (loc);
+    }
+    g_list_free (list);
+
+    test_timezones ();
+}
+
 static void
 test_timezone (GWeatherLocation *location)
 {
@@ -388,6 +477,7 @@ main (int argc, char *argv[])
                  FALSE);
 
        g_test_add_func ("/weather/named-timezones", test_named_timezones);
+       g_test_add_func ("/weather/named-timezones-deserialized", test_named_timezones_deserialized);
        g_test_add_func ("/weather/timezones", test_timezones);
        g_test_add_func ("/weather/airport_distance_sanity", test_airport_distance_sanity);
        g_test_add_func ("/weather/metar_weather_stations", test_metar_weather_stations);


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