[evolution-data-server/wip/mcrha/libical-glib] Correct issues found with unit tests (requires libical-glib changes)



commit 40b4bc8cd02467cbe653987d5bbd565c07b2cc77
Author: Milan Crha <mcrha redhat com>
Date:   Fri Feb 15 09:12:53 2019 +0100

    Correct issues found with unit tests (requires libical-glib changes)

 src/calendar/libecal/e-cal-client.c            |  4 +++-
 src/calendar/libecal/e-cal-component.c         | 18 ++++++++++++++++++
 src/calendar/libecal/e-cal-recur.c             | 10 +++++++---
 src/calendar/libecal/e-cal-util.c              |  4 ----
 src/calendar/libedata-cal/e-cal-backend.c      |  8 +++-----
 src/calendar/libedata-cal/e-cal-cache.c        |  3 ++-
 src/calendar/libedata-cal/e-cal-meta-backend.c | 12 ++++++++----
 src/libebackend/e-server-side-source.c         |  1 +
 tests/libecal/test-cal-client-add-timezone.c   |  2 +-
 tests/libecal/test-cal-client-remove-object.c  |  1 +
 tests/libedata-cal/test-cal-backend-sexp.c     |  2 ++
 tests/libedata-cal/test-cal-meta-backend.c     |  5 +++--
 tests/test-server-utils/e-test-server-utils.c  | 11 +++--------
 13 files changed, 52 insertions(+), 29 deletions(-)
---
diff --git a/src/calendar/libecal/e-cal-client.c b/src/calendar/libecal/e-cal-client.c
index 6f5a1e9b8..fe63e5316 100644
--- a/src/calendar/libecal/e-cal-client.c
+++ b/src/calendar/libecal/e-cal-client.c
@@ -1455,10 +1455,10 @@ cal_client_get_cached_timezone (ETimezoneCache *cache,
                tzid = i_cal_timezone_get_tzid (zone);
                g_hash_table_insert (priv->zone_cache, g_strdup (tzid), zone);
        } else {
-               g_object_unref (icalcomp);
                g_object_unref (zone);
                zone = NULL;
        }
+       g_object_unref (icalcomp);
 
 exit:
        g_mutex_unlock (&priv->zone_cache_lock);
@@ -6248,6 +6248,8 @@ e_cal_client_get_attachment_uris_sync (ECalClient *client,
                }
 
                *out_attachment_uris = g_slist_reverse (tmp);
+
+               g_free (uris);
        }
 
        if (local_error != NULL) {
diff --git a/src/calendar/libecal/e-cal-component.c b/src/calendar/libecal/e-cal-component.c
index 2d2f129e8..5f6c1ccf5 100644
--- a/src/calendar/libecal/e-cal-component.c
+++ b/src/calendar/libecal/e-cal-component.c
@@ -428,6 +428,22 @@ ensure_mandatory_properties (ECalComponent *comp)
        }
 }
 
+static gboolean
+ensure_alarm_uid_cb (ICalComponent *icalcomp,
+                    ICalComponent *subcomp,
+                    gpointer user_data)
+{
+       if (!e_cal_util_component_has_x_property (subcomp, E_CAL_EVOLUTION_ALARM_UID_PROPERTY)) {
+               gchar *uid;
+
+               uid = e_util_generate_uid ();
+               e_cal_util_component_set_x_property (subcomp, E_CAL_EVOLUTION_ALARM_UID_PROPERTY, uid);
+               g_free (uid);
+       }
+
+       return TRUE;
+}
+
 /**
  * e_cal_component_set_new_vtype:
  * @comp: A calendar component object.
@@ -581,6 +597,8 @@ e_cal_component_set_icalcomponent (ECalComponent *comp,
 
        ensure_mandatory_properties (comp);
 
+       foreach_subcomponent (icalcomp, I_CAL_VALARM_COMPONENT, ensure_alarm_uid_cb, NULL);
+
        return TRUE;
 }
 
diff --git a/src/calendar/libecal/e-cal-recur.c b/src/calendar/libecal/e-cal-recur.c
index 77c0ec9f1..f544375ec 100644
--- a/src/calendar/libecal/e-cal-recur.c
+++ b/src/calendar/libecal/e-cal-recur.c
@@ -230,7 +230,7 @@ ensure_timezone (icalcomponent *comp,
                                if (!*pcached_zones)
                                        *pcached_zones = g_hash_table_new_full (g_str_hash, g_str_equal, 
g_free, g_object_unref);
 
-                               g_hash_table_insert (*pcached_zones, g_strdup (tzid), zone);
+                               g_hash_table_insert (*pcached_zones, g_strdup (tzid), g_object_ref (zone));
                        }
                }
 
@@ -1362,8 +1362,10 @@ e_cal_recur_generate_instances_of_rule (ECalComponent *comp,
         * TZID (i.e. floating times) we use the default timezone. */
        if (e_cal_component_datetime_get_tzid (dtstart) && !dtstarttt->is_date) {
                gstart_zone = (*tz_cb) (e_cal_component_datetime_get_tzid (dtstart), tz_cb_data, NULL, NULL);
-               if (gstart_zone)
+               if (gstart_zone) {
+                       g_object_ref (gstart_zone);
                        start_zone = i_cal_object_get_native (I_CAL_OBJECT (gstart_zone));
+               }
                if (!start_zone)
                        start_zone = default_timezone;
        } else {
@@ -1407,8 +1409,10 @@ e_cal_recur_generate_instances_of_rule (ECalComponent *comp,
 
        if (e_cal_component_datetime_get_tzid (dtend) && dtendtt && !dtendtt->is_date) {
                gend_zone = (*tz_cb) (e_cal_component_datetime_get_tzid (dtend), tz_cb_data, NULL, NULL);
-               if (gend_zone)
+               if (gend_zone) {
+                       g_object_ref (gend_zone);
                        end_zone = i_cal_object_get_native (I_CAL_OBJECT (gend_zone));
+               }
                if (!end_zone)
                        end_zone = default_timezone;
        } else {
diff --git a/src/calendar/libecal/e-cal-util.c b/src/calendar/libecal/e-cal-util.c
index 4b8914f8c..1d77fc297 100644
--- a/src/calendar/libecal/e-cal-util.c
+++ b/src/calendar/libecal/e-cal-util.c
@@ -1759,8 +1759,6 @@ componenttime_to_utc_timet (const ECalComponentDateTime *dt_time,
        ICalTimetype *value = NULL;
        time_t timet = -1;
 
-       g_return_val_if_fail (dt_time != NULL, -1);
-
        if (dt_time)
                value = e_cal_component_datetime_get_value (dt_time);
 
@@ -1772,8 +1770,6 @@ componenttime_to_utc_timet (const ECalComponentDateTime *dt_time,
                        zone = tz_cb (tzid, tz_cb_data, NULL, NULL);
 
                timet = i_cal_time_as_timet_with_zone (value, zone ? zone : (ICalTimezone *) default_zone);
-
-               g_clear_object (&zone);
        }
 
        return timet;
diff --git a/src/calendar/libedata-cal/e-cal-backend.c b/src/calendar/libedata-cal/e-cal-backend.c
index 525976d41..25e521cc0 100644
--- a/src/calendar/libedata-cal/e-cal-backend.c
+++ b/src/calendar/libedata-cal/e-cal-backend.c
@@ -194,9 +194,7 @@ static void
 signal_closure_free (SignalClosure *signal_closure)
 {
        g_weak_ref_clear (&signal_closure->backend);
-
-       /* The ICalTimezone is cached in ECalBackend's internal
-        * "zone_cache" hash table and must not be freed here. */
+       g_clear_object (&signal_closure->cached_zone);
 
        g_slice_free (SignalClosure, signal_closure);
 }
@@ -826,7 +824,7 @@ cal_backend_add_cached_timezone (ETimezoneCache *cache,
                 * duration of the idle callback. */
                signal_closure = g_slice_new0 (SignalClosure);
                g_weak_ref_init (&signal_closure->backend, cache);
-               signal_closure->cached_zone = cached_zone;
+               signal_closure->cached_zone = g_object_ref (cached_zone);
 
                main_context = e_backend_ref_main_context (E_BACKEND (cache));
 
@@ -907,9 +905,9 @@ cal_backend_get_cached_timezone (ETimezoneCache *cache,
                tzid = i_cal_timezone_get_tzid (zone);
                g_hash_table_insert (priv->zone_cache, g_strdup (tzid), zone);
        } else {
-               g_clear_object (&icomp);
                g_clear_object (&zone);
        }
+       g_clear_object (&icomp);
 
  exit:
        g_mutex_unlock (&priv->zone_cache_lock);
diff --git a/src/calendar/libedata-cal/e-cal-cache.c b/src/calendar/libedata-cal/e-cal-cache.c
index 0eb190e0d..0caf051d4 100644
--- a/src/calendar/libedata-cal/e-cal-cache.c
+++ b/src/calendar/libedata-cal/e-cal-cache.c
@@ -1855,6 +1855,7 @@ ecc_timezone_from_string (const gchar *icalstring)
                        g_object_unref (component);
                        g_object_unref (zone);
                } else {
+                       g_object_unref (component);
                        return zone;
                }
        }
@@ -4243,9 +4244,9 @@ ecc_get_cached_timezone (ETimezoneCache *cache,
                tzid = i_cal_timezone_get_tzid (zone);
                g_hash_table_insert (cal_cache->priv->modified_timezones, g_strdup (tzid), zone);
        } else {
-               g_clear_object (&icomp);
                g_clear_object (&zone);
        }
+       g_clear_object (&icomp);
 
  exit:
        g_rec_mutex_unlock (&cal_cache->priv->timezones_lock);
diff --git a/src/calendar/libedata-cal/e-cal-meta-backend.c b/src/calendar/libedata-cal/e-cal-meta-backend.c
index a1a327aad..3493d2b6a 100644
--- a/src/calendar/libedata-cal/e-cal-meta-backend.c
+++ b/src/calendar/libedata-cal/e-cal-meta-backend.c
@@ -1030,9 +1030,9 @@ ecmb_gather_timezones (ECalMetaBackend *meta_backend,
                if (i_cal_timezone_set_component (zone, clone)) {
                        if (i_cal_timezone_get_tzid (zone))
                                e_timezone_cache_add_timezone (timezone_cache, zone);
-               } else {
-                       g_object_unref (clone);
                }
+
+               g_object_unref (clone);
        }
 
        g_object_unref (zone);
@@ -2657,6 +2657,8 @@ ecmb_add_attachment_uris (ECalComponent *comp,
                                g_free (buf);
                        }
                }
+
+               g_clear_object (&attach);
        }
 }
 
@@ -3890,6 +3892,8 @@ add_timezone_cb (ICalParameter *param,
                }
 
                i_cal_component_take_component (f_data->vcalendar, clone);
+
+               g_object_unref (vtz_comp);
        }
 
        g_object_unref (tz);
@@ -4015,7 +4019,7 @@ e_cal_meta_backend_inline_local_attachments_sync (ECalMetaBackend *meta_backend,
                ICalAttach *attach;
 
                attach = i_cal_property_get_attach (prop);
-               if (i_cal_attach_get_is_url (attach)) {
+               if (attach && i_cal_attach_get_is_url (attach)) {
                        const gchar *url;
 
                        url = i_cal_attach_get_url (attach);
@@ -4116,7 +4120,7 @@ e_cal_meta_backend_store_inline_attachments_sync (ECalMetaBackend *meta_backend,
 
                attach = i_cal_property_get_attach (prop);
 
-               if (!i_cal_attach_get_is_url (attach)) {
+               if (attach && !i_cal_attach_get_is_url (attach)) {
                        ICalParameter *param;
                        const gchar *basename;
                        gsize len = -1;
diff --git a/src/libebackend/e-server-side-source.c b/src/libebackend/e-server-side-source.c
index 961660e3f..2c92d9fbf 100644
--- a/src/libebackend/e-server-side-source.c
+++ b/src/libebackend/e-server-side-source.c
@@ -2019,6 +2019,7 @@ e_server_side_source_load (EServerSideSource *source,
                return FALSE;
 
        } else {
+               g_free (source->priv->file_contents);
                source->priv->file_contents = g_strdup (data);
        }
 
diff --git a/tests/libecal/test-cal-client-add-timezone.c b/tests/libecal/test-cal-client-add-timezone.c
index b05bbbd57..7b7ecb69e 100644
--- a/tests/libecal/test-cal-client-add-timezone.c
+++ b/tests/libecal/test-cal-client-add-timezone.c
@@ -128,7 +128,7 @@ test_add_timezone_async (ETestServerFixture *fixture,
        property = i_cal_property_new_tzname (TZNAME_NEW);
        i_cal_component_take_property (component, property);
        zone = i_cal_timezone_new ();
-       i_cal_timezone_set_component (zone, component);
+       g_assert (i_cal_timezone_set_component (zone, component));
        g_object_unref (component);
 
        cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
diff --git a/tests/libecal/test-cal-client-remove-object.c b/tests/libecal/test-cal-client-remove-object.c
index 98902b0f0..9ce54e1f2 100644
--- a/tests/libecal/test-cal-client-remove-object.c
+++ b/tests/libecal/test-cal-client-remove-object.c
@@ -123,6 +123,7 @@ test_remove_object_empty_uid (ETestServerFixture *fixture,
        g_assert_error (
                error, E_CAL_CLIENT_ERROR,
                E_CAL_CLIENT_ERROR_OBJECT_NOT_FOUND);
+       g_clear_error (&error);
 }
 
 gint
diff --git a/tests/libedata-cal/test-cal-backend-sexp.c b/tests/libedata-cal/test-cal-backend-sexp.c
index db0d7a941..8e798f9be 100644
--- a/tests/libedata-cal/test-cal-backend-sexp.c
+++ b/tests/libedata-cal/test-cal-backend-sexp.c
@@ -28,6 +28,8 @@ test_query (const gchar *query)
        } else {
                printf ("%s: no time prunning possible\n", query);
        }
+
+       g_object_unref (sexp);
 }
 
 gint
diff --git a/tests/libedata-cal/test-cal-meta-backend.c b/tests/libedata-cal/test-cal-meta-backend.c
index 98c4899d4..6a528a45b 100644
--- a/tests/libedata-cal/test-cal-meta-backend.c
+++ b/tests/libedata-cal/test-cal-meta-backend.c
@@ -88,7 +88,7 @@ ecmb_test_add_test_case (ECalMetaBackendTest *test_backend,
 static gchar *
 ecmb_test_get_rid_as_string (ICalComponent *icomp)
 {
-       gchar *rid;
+       gchar *rid = NULL;
 
        g_assert_nonnull (icomp);
 
@@ -119,7 +119,7 @@ ecmb_test_remove_component (ECalMetaBackendTest *test_backend,
        for (icomp = i_cal_component_get_first_component (test_backend->vcalendar, I_CAL_VEVENT_COMPONENT);
             icomp;) {
                const gchar *server_uid;
-               gchar *server_rid = NULL;
+               gchar *server_rid;
 
                server_uid = i_cal_component_get_uid (icomp);
                g_assert_nonnull (server_uid);
@@ -2466,6 +2466,7 @@ test_receive_objects (ECalMetaBackend *meta_backend)
 
        i_cal_component_take_component (test_backend->vcalendar, i_cal_component_new_clone (firsticomp));
 
+       g_object_unref (firsticomp);
        g_object_unref (icomp);
 
        /* To get the 'invite' component into local cache */
diff --git a/tests/test-server-utils/e-test-server-utils.c b/tests/test-server-utils/e-test-server-utils.c
index 13da331d0..37ca5fbb6 100644
--- a/tests/test-server-utils/e-test-server-utils.c
+++ b/tests/test-server-utils/e-test-server-utils.c
@@ -816,14 +816,9 @@ e_test_server_utils_finish_run (void)
 {
 #if GLOBAL_DBUS_DAEMON
        if (!test_installed_services ()) {
-               /* Teardown the D-Bus Daemon
-                *
-                * Note that we intentionally leak the TestDBus daemon
-                * in this case, presumably this is due to some leaked
-                * GDBusConnection reference counting
-                */
-               g_test_dbus_stop (global_test_dbus);
-               /* g_object_unref (global_test_dbus); */
+               /* Teardown the D-Bus Daemon */
+               g_test_dbus_down (global_test_dbus);
+               g_object_unref (global_test_dbus);
                global_test_dbus = NULL;
        }
 #endif


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