diff options
author | Bastien Nocera <hadess@hadess.net> | 2018-06-13 14:20:23 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2018-06-13 14:25:04 +0200 |
commit | bbc31e662146370dd4c96727381b22beb58e3782 (patch) | |
tree | 14cbb993a2483bcbc31492c933dfb937251860a2 | |
parent | 097870d91f41e1cc358c281f3b672bcadf6da3f5 (diff) | |
download | libgweather-bbc31e662146370dd4c96727381b22beb58e3782.tar.gz |
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
-rw-r--r-- | libgweather/test_libgweather.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/libgweather/test_libgweather.c b/libgweather/test_libgweather.c index a897cac..1760171 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) { @@ -444,6 +533,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); |