[evolution-data-server/wip/offline-cache] Add few tests for ECalMetaBackend utility functions
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/wip/offline-cache] Add few tests for ECalMetaBackend utility functions
- Date: Thu, 23 Feb 2017 18:05:03 +0000 (UTC)
commit d4bee16ab9ec14267c86f29fa952c22ac5ecd044
Author: Milan Crha <mcrha redhat com>
Date: Thu Feb 23 19:04:23 2017 +0100
Add few tests for ECalMetaBackend utility functions
src/calendar/libedata-cal/e-cal-meta-backend.c | 38 ++-
src/calendar/libedata-cal/e-cal-meta-backend.h | 4 +-
tests/libedata-cal/CMakeLists.txt | 1 +
tests/libedata-cal/components/event-7.ics | 4 +-
tests/libedata-cal/test-cal-meta-backend.c | 496 ++++++++++++++++++++++++
5 files changed, 531 insertions(+), 12 deletions(-)
---
diff --git a/src/calendar/libedata-cal/e-cal-meta-backend.c b/src/calendar/libedata-cal/e-cal-meta-backend.c
index 504b9e5..7173b16 100644
--- a/src/calendar/libedata-cal/e-cal-meta-backend.c
+++ b/src/calendar/libedata-cal/e-cal-meta-backend.c
@@ -315,12 +315,12 @@ typedef struct {
static void
add_timezone_cb (icalparameter *param,
- gpointer data)
+ gpointer user_data)
{
icaltimezone *tz;
const gchar *tzid;
icalcomponent *vtz_comp;
- ForeachTzidData *f_data = (ForeachTzidData *) data;
+ ForeachTzidData *f_data = user_data;
tzid = icalparameter_get_tzid (param);
if (!tzid)
@@ -414,7 +414,6 @@ e_cal_meta_backend_merge_instances (ECalMetaBackend *meta_backend,
for (link = sorted; link; link = g_slist_next (link)) {
ECalComponent *comp = link->data;
icalcomponent *icalcomp;
- ForeachTzidData f_data;
if (!E_IS_CAL_COMPONENT (comp)) {
g_warn_if_reached ();
@@ -435,6 +434,24 @@ e_cal_meta_backend_merge_instances (ECalMetaBackend *meta_backend,
return vcalendar;
}
+static void
+ecmb_remove_all_but_filename_parameter (icalproperty *prop)
+{
+ icalparameter *param;
+
+ g_return_if_fail (prop != NULL);
+
+ while (param = icalproperty_get_first_parameter (prop, ICAL_ANY_PARAMETER), param) {
+ if (icalparameter_isa (param) == ICAL_FILENAME_PARAMETER) {
+ param = icalproperty_get_next_parameter (prop, ICAL_ANY_PARAMETER);
+ if (!param)
+ break;
+ }
+
+ icalproperty_remove_parameter_by_ref (prop, param);
+ }
+}
+
/**
* e_cal_meta_backend_inline_local_attachments_sync:
* @meta_backend: an #ECalMetaBackend
@@ -493,9 +510,7 @@ e_cal_meta_backend_inline_local_attachments_sync (ECalMetaBackend *meta_backend,
g_free (content);
g_free (base64);
- while (param = icalproperty_get_first_parameter (prop,
ICAL_ANY_PARAMETER), param) {
- icalproperty_remove_parameter_by_ref (prop, param);
- }
+ ecmb_remove_all_but_filename_parameter (prop);
icalproperty_set_attach (prop, new_attach);
icalattach_unref (new_attach);
@@ -506,8 +521,11 @@ e_cal_meta_backend_inline_local_attachments_sync (ECalMetaBackend *meta_backend,
param = icalparameter_new_encoding (ICAL_ENCODING_BASE64);
icalproperty_add_parameter (prop, param);
- param = icalparameter_new_filename (basename);
- icalproperty_add_parameter (prop, param);
+ /* Preserve existing FILENAME parameter */
+ if (!icalproperty_get_first_parameter (prop,
ICAL_FILENAME_PARAMETER)) {
+ param = icalparameter_new_filename (basename);
+ icalproperty_add_parameter (prop, param);
+ }
} else {
success = FALSE;
}
@@ -582,6 +600,8 @@ e_cal_meta_backend_store_inline_attachments_sync (ECalMetaBackend *meta_backend,
icalattach *new_attach;
gchar *url;
+ ecmb_remove_all_but_filename_parameter (prop);
+
url = g_filename_to_uri (local_filename, NULL, NULL);
new_attach = icalattach_new_from_url (url);
@@ -592,6 +612,8 @@ e_cal_meta_backend_store_inline_attachments_sync (ECalMetaBackend *meta_backend,
} else {
success = FALSE;
}
+
+ g_free (decoded);
}
g_free (local_filename);
diff --git a/src/calendar/libedata-cal/e-cal-meta-backend.h b/src/calendar/libedata-cal/e-cal-meta-backend.h
index 6d1103b..f1d64ae 100644
--- a/src/calendar/libedata-cal/e-cal-meta-backend.h
+++ b/src/calendar/libedata-cal/e-cal-meta-backend.h
@@ -80,7 +80,7 @@ typedef struct _ECalMetaBackendPrivate ECalMetaBackendPrivate;
**/
struct _ECalMetaBackend {
/*< private >*/
- ECache parent;
+ ECalBackend parent;
ECalMetaBackendPrivate *priv;
};
@@ -93,7 +93,7 @@ struct _ECalMetaBackend {
*/
struct _ECalMetaBackendClass {
/*< private >*/
- ECacheClass parent_class;
+ ECalBackendClass parent_class;
/* Virtual methods */
gboolean (* connect_sync) (ECalMetaBackend *meta_backend,
diff --git a/tests/libedata-cal/CMakeLists.txt b/tests/libedata-cal/CMakeLists.txt
index 558012e..d5f6145 100644
--- a/tests/libedata-cal/CMakeLists.txt
+++ b/tests/libedata-cal/CMakeLists.txt
@@ -82,6 +82,7 @@ set(TESTS
test-cal-cache-intervals
test-cal-cache-offline
test-cal-cache-search
+ test-cal-meta-backend
)
foreach(_test ${TESTS})
diff --git a/tests/libedata-cal/components/event-7.ics b/tests/libedata-cal/components/event-7.ics
index 769b7ac..b08d392 100644
--- a/tests/libedata-cal/components/event-7.ics
+++ b/tests/libedata-cal/components/event-7.ics
@@ -1,8 +1,8 @@
BEGIN:VEVENT
UID:event-7
DTSTAMP:20170221T121736Z
-DTSTART;TZID=America/New_York:20170221T135000
-DTEND;TZID=America/New_York:20170221T145000
+DTSTART;TZID=/freeassociation.sourceforge.net/America/New_York:20170221T135000
+DTEND;TZID=/freeassociation.sourceforge.net/America/New_York:20170221T145000
SEQUENCE:1
SUMMARY:With attachment
TRANSP:OPAQUE
diff --git a/tests/libedata-cal/test-cal-meta-backend.c b/tests/libedata-cal/test-cal-meta-backend.c
new file mode 100644
index 0000000..7d0c910
--- /dev/null
+++ b/tests/libedata-cal/test-cal-meta-backend.c
@@ -0,0 +1,496 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2017 Red Hat, Inc. (www.redhat.com)
+ *
+ * This library is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "evolution-data-server-config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
+#include <libecal/libecal.h>
+
+#include "test-cal-cache-utils.h"
+
+#define EXPECTED_TZID "/freeassociation.sourceforge.net/America/New_York"
+#define EXPECTED_LOCATION "America/New_York"
+#define REMOTE_URL "https://www.gnome.org/wp-content/themes/gnome-grass/images/gnome-logo.svg"
+
+typedef struct _ECalMetaBackendTest {
+ ECalMetaBackend parent;
+} ECalMetaBackendTest;
+
+typedef struct _ECalMetaBackendTestClass {
+ ECalMetaBackendClass parent_class;
+} ECalMetaBackendTestClass;
+
+#define E_TYPE_CAL_META_BACKEND_TEST (e_cal_meta_backend_test_get_type ())
+
+GType e_cal_meta_backend_test_get_type (void) G_GNUC_CONST;
+
+G_DEFINE_TYPE (ECalMetaBackendTest, e_cal_meta_backend_test, E_TYPE_CAL_META_BACKEND)
+
+static void
+e_cal_meta_backend_test_class_init (ECalMetaBackendTestClass *klass)
+{
+}
+
+static void
+e_cal_meta_backend_test_init (ECalMetaBackendTest *test)
+{
+}
+
+static ECalMetaBackend *
+e_cal_meta_backend_test_new (ECalCache *cache)
+{
+ ECalMetaBackend *meta_backend;
+ ESourceRegistry *registry;
+ ESource *scratch;
+ GError *error = NULL;
+
+ g_assert (E_IS_CAL_CACHE (cache));
+
+ registry = e_source_registry_new_sync (NULL, NULL);
+ g_assert_nonnull (registry);
+
+ scratch = e_source_new_with_uid ("test-source", NULL, &error);
+ g_assert_no_error (error);
+ g_assert_nonnull (scratch);
+
+ meta_backend = g_object_new (E_TYPE_CAL_META_BACKEND_TEST,
+ "source", scratch,
+ "registry", registry,
+ "kind", ICAL_VEVENT_COMPONENT,
+ NULL);
+ g_assert_nonnull (meta_backend);
+
+ g_object_unref (registry);
+ g_object_unref (scratch);
+
+ e_cal_meta_backend_set_cache (meta_backend, cache);
+
+ return meta_backend;
+}
+
+static void
+assert_tzid_matches_cb (icalparameter *param,
+ gpointer user_data)
+{
+ const gchar *expected_tzid = user_data;
+
+ g_assert_cmpstr (icalparameter_get_tzid (param), ==, expected_tzid);
+}
+
+static void
+test_merge_instances (TCUFixture *fixture,
+ gconstpointer user_data)
+{
+ ECalMetaBackend *meta_backend;
+ GSList *instances = NULL;
+ icalcomponent *icalcomp, *subcomp;
+ icalproperty *prop;
+ gboolean success;
+ GError *error = NULL;
+
+ meta_backend = e_cal_meta_backend_test_new (fixture->cal_cache);
+ g_assert_nonnull (meta_backend);
+
+ /* event-1 has only UTC times, with no TZID */
+ success = e_cal_cache_get_components_by_uid (fixture->cal_cache, "event-1", &instances, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_nonnull (instances);
+
+ /* TZID as is */
+ icalcomp = e_cal_meta_backend_merge_instances (meta_backend, instances, FALSE);
+ g_assert_nonnull (icalcomp);
+ g_assert_cmpint (icalcomponent_isa (icalcomp), ==, ICAL_VCALENDAR_COMPONENT);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_ANY_COMPONENT), ==, 1);
+
+ subcomp = icalcomponent_get_first_component (icalcomp, ICAL_ANY_COMPONENT);
+ g_assert_nonnull (subcomp);
+ g_assert_cmpint (icalcomponent_isa (subcomp), ==, ICAL_VEVENT_COMPONENT);
+
+ icalcomponent_free (icalcomp);
+
+ /* TZID as location */
+ icalcomp = e_cal_meta_backend_merge_instances (meta_backend, instances, TRUE);
+ g_assert_nonnull (icalcomp);
+ g_assert_cmpint (icalcomponent_isa (icalcomp), ==, ICAL_VCALENDAR_COMPONENT);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_ANY_COMPONENT), ==, 1);
+
+ subcomp = icalcomponent_get_first_component (icalcomp, ICAL_ANY_COMPONENT);
+ g_assert_nonnull (subcomp);
+ g_assert_cmpint (icalcomponent_isa (subcomp), ==, ICAL_VEVENT_COMPONENT);
+
+ icalcomponent_free (icalcomp);
+
+ g_slist_free_full (instances, g_object_unref);
+ instances = NULL;
+
+ /* event-7 has built-in TZID */
+ success = e_cal_cache_get_components_by_uid (fixture->cal_cache, "event-7", &instances, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_nonnull (instances);
+
+ /* TZID as is */
+ icalcomp = e_cal_meta_backend_merge_instances (meta_backend, instances, FALSE);
+ g_assert_nonnull (icalcomp);
+ g_assert_cmpint (icalcomponent_isa (icalcomp), ==, ICAL_VCALENDAR_COMPONENT);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_ANY_COMPONENT), ==, 2);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_VTIMEZONE_COMPONENT), ==, 1);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_VEVENT_COMPONENT), ==, 1);
+
+ subcomp = icalcomponent_get_first_component (icalcomp, ICAL_VTIMEZONE_COMPONENT);
+ g_assert_nonnull (subcomp);
+ g_assert_cmpint (icalcomponent_isa (subcomp), ==, ICAL_VTIMEZONE_COMPONENT);
+
+ prop = icalcomponent_get_first_property (subcomp, ICAL_TZID_PROPERTY);
+ g_assert_nonnull (prop);
+ g_assert_cmpstr (icalproperty_get_tzid (prop), ==, EXPECTED_TZID);
+
+ subcomp = icalcomponent_get_first_component (icalcomp, ICAL_VEVENT_COMPONENT);
+ g_assert_nonnull (subcomp);
+ icalcomponent_foreach_tzid (subcomp, assert_tzid_matches_cb, (gpointer) icalproperty_get_tzid (prop));
+
+ icalcomponent_free (icalcomp);
+
+ /* TZID to location */
+ icalcomp = e_cal_meta_backend_merge_instances (meta_backend, instances, TRUE);
+ g_assert_nonnull (icalcomp);
+ g_assert_cmpint (icalcomponent_isa (icalcomp), ==, ICAL_VCALENDAR_COMPONENT);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_ANY_COMPONENT), ==, 2);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_VTIMEZONE_COMPONENT), ==, 1);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_VEVENT_COMPONENT), ==, 1);
+
+ subcomp = icalcomponent_get_first_component (icalcomp, ICAL_VTIMEZONE_COMPONENT);
+ g_assert_nonnull (subcomp);
+ g_assert_cmpint (icalcomponent_isa (subcomp), ==, ICAL_VTIMEZONE_COMPONENT);
+
+ prop = icalcomponent_get_first_property (subcomp, ICAL_TZID_PROPERTY);
+ g_assert_nonnull (prop);
+ g_assert_cmpstr (icalproperty_get_tzid (prop), ==, EXPECTED_LOCATION);
+
+ subcomp = icalcomponent_get_first_component (icalcomp, ICAL_VEVENT_COMPONENT);
+ g_assert_nonnull (subcomp);
+ icalcomponent_foreach_tzid (subcomp, assert_tzid_matches_cb, (gpointer) icalproperty_get_tzid (prop));
+
+ icalcomponent_free (icalcomp);
+ g_slist_free_full (instances, g_object_unref);
+ instances = NULL;
+
+ /* event-6 has TZID-s as locations already and a detached instance */
+ success = e_cal_cache_get_components_by_uid (fixture->cal_cache, "event-6", &instances, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_nonnull (instances);
+
+ /* TZID as is */
+ icalcomp = e_cal_meta_backend_merge_instances (meta_backend, instances, FALSE);
+ g_assert_nonnull (icalcomp);
+ g_assert_cmpint (icalcomponent_isa (icalcomp), ==, ICAL_VCALENDAR_COMPONENT);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_ANY_COMPONENT), ==, 3);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_VTIMEZONE_COMPONENT), ==, 1);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_VEVENT_COMPONENT), ==, 2);
+
+ subcomp = icalcomponent_get_first_component (icalcomp, ICAL_VTIMEZONE_COMPONENT);
+ g_assert_nonnull (subcomp);
+ g_assert_cmpint (icalcomponent_isa (subcomp), ==, ICAL_VTIMEZONE_COMPONENT);
+
+ prop = icalcomponent_get_first_property (subcomp, ICAL_TZID_PROPERTY);
+ g_assert_nonnull (prop);
+ g_assert_cmpstr (icalproperty_get_tzid (prop), ==, EXPECTED_LOCATION);
+
+ subcomp = icalcomponent_get_first_component (icalcomp, ICAL_VEVENT_COMPONENT);
+ g_assert_nonnull (subcomp);
+ icalcomponent_foreach_tzid (subcomp, assert_tzid_matches_cb, (gpointer) icalproperty_get_tzid (prop));
+
+ subcomp = icalcomponent_get_next_component (icalcomp, ICAL_VEVENT_COMPONENT);
+ g_assert_nonnull (subcomp);
+ icalcomponent_foreach_tzid (subcomp, assert_tzid_matches_cb, (gpointer) icalproperty_get_tzid (prop));
+
+ icalcomponent_free (icalcomp);
+
+ /* TZID to location */
+ icalcomp = e_cal_meta_backend_merge_instances (meta_backend, instances, TRUE);
+ g_assert_nonnull (icalcomp);
+ g_assert_cmpint (icalcomponent_isa (icalcomp), ==, ICAL_VCALENDAR_COMPONENT);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_ANY_COMPONENT), ==, 3);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_VTIMEZONE_COMPONENT), ==, 1);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_VEVENT_COMPONENT), ==, 2);
+
+ subcomp = icalcomponent_get_first_component (icalcomp, ICAL_VTIMEZONE_COMPONENT);
+ g_assert_nonnull (subcomp);
+ g_assert_cmpint (icalcomponent_isa (subcomp), ==, ICAL_VTIMEZONE_COMPONENT);
+
+ prop = icalcomponent_get_first_property (subcomp, ICAL_TZID_PROPERTY);
+ g_assert_nonnull (prop);
+ g_assert_cmpstr (icalproperty_get_tzid (prop), ==, EXPECTED_LOCATION);
+
+ subcomp = icalcomponent_get_first_component (icalcomp, ICAL_VEVENT_COMPONENT);
+ g_assert_nonnull (subcomp);
+ icalcomponent_foreach_tzid (subcomp, assert_tzid_matches_cb, (gpointer) icalproperty_get_tzid (prop));
+
+ subcomp = icalcomponent_get_next_component (icalcomp, ICAL_VEVENT_COMPONENT);
+ g_assert_nonnull (subcomp);
+ icalcomponent_foreach_tzid (subcomp, assert_tzid_matches_cb, (gpointer) icalproperty_get_tzid (prop));
+
+ icalcomponent_free (icalcomp);
+ g_slist_free_full (instances, g_object_unref);
+
+ g_object_unref (meta_backend);
+}
+
+static void
+check_attachment_content (icalattach *attach,
+ const gchar *expected_content,
+ gsize expected_content_len)
+{
+ g_assert_nonnull (attach);
+ g_assert_nonnull (expected_content);
+ g_assert_cmpint (expected_content_len, >, 0);
+
+ if (icalattach_get_is_url (attach)) {
+ const gchar *url;
+ gboolean success;
+ gchar *filename;
+ gchar *content = NULL;
+ gsize content_len = -1;
+ GError *error = NULL;
+
+ url = icalattach_get_url (attach);
+ g_assert_nonnull (url);
+ g_assert (g_str_has_prefix (url, "file://"));
+
+ filename = g_filename_from_uri (icalattach_get_url (attach), NULL, &error);
+ g_assert_no_error (error);
+ g_assert_nonnull (filename);
+
+ success = g_file_get_contents (filename, &content, &content_len, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_nonnull (content);
+ g_assert_cmpint (content_len, >, 0);
+
+ g_assert_cmpmem (content, content_len, expected_content, expected_content_len);
+
+ g_free (filename);
+ g_free (content);
+ } else {
+ guchar *base64;
+ gsize base64_len;
+
+ base64 = g_base64_decode ((const gchar *) icalattach_get_data (attach), &base64_len);
+ g_assert_nonnull (base64);
+ g_assert_cmpmem (base64, base64_len, expected_content, expected_content_len);
+
+ g_free (base64);
+ }
+}
+
+static void
+test_attachments (TCUFixture *fixture,
+ gconstpointer user_data)
+{
+ ECalMetaBackend *meta_backend;
+ gchar *content = NULL;
+ gsize content_len = 0;
+ ECalComponent *comp = NULL;
+ icalcomponent *icalcomp;
+ icalproperty *prop;
+ icalparameter *param;
+ icalattach *attach;
+ gchar *filename;
+ const gchar *basename;
+ gboolean success;
+ GError *error = NULL;
+
+ meta_backend = e_cal_meta_backend_test_new (fixture->cal_cache);
+ g_assert_nonnull (meta_backend);
+
+ /* It has a URL attachment */
+ success = e_cal_cache_get_component (fixture->cal_cache, "event-7", NULL, &comp, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_nonnull (comp);
+
+ icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (comp));
+ g_assert_nonnull (icalcomp);
+ g_assert_cmpint (icalcomponent_count_properties (icalcomp, ICAL_ATTACH_PROPERTY), ==, 1);
+
+ prop = icalcomponent_get_first_property (icalcomp, ICAL_ATTACH_PROPERTY);
+ g_assert_nonnull (prop);
+ g_assert_null (icalproperty_get_first_parameter (prop, ICAL_FILENAME_PARAMETER));
+
+ attach = icalproperty_get_attach (prop);
+ g_assert_nonnull (attach);
+ g_assert (icalattach_get_is_url (attach));
+
+ filename = g_filename_from_uri (icalattach_get_url (attach), NULL, &error);
+ g_assert_no_error (error);
+ g_assert_nonnull (filename);
+
+ basename = strrchr (filename, '/');
+ g_assert_nonnull (basename);
+ basename++;
+
+ success = g_file_get_contents (filename, &content, &content_len, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_nonnull (content);
+ g_assert_cmpint (content_len, >, 0);
+
+ success = e_cal_meta_backend_inline_local_attachments_sync (meta_backend, icalcomp, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_cmpint (icalcomponent_count_properties (icalcomp, ICAL_ATTACH_PROPERTY), ==, 1);
+
+ prop = icalcomponent_get_first_property (icalcomp, ICAL_ATTACH_PROPERTY);
+ g_assert_nonnull (prop);
+ g_assert_nonnull (icalproperty_get_first_parameter (prop, ICAL_FILENAME_PARAMETER));
+ g_assert_nonnull (icalproperty_get_first_parameter (prop, ICAL_VALUE_PARAMETER));
+ g_assert_nonnull (icalproperty_get_first_parameter (prop, ICAL_ENCODING_PARAMETER));
+
+ param = icalproperty_get_first_parameter (prop, ICAL_FILENAME_PARAMETER);
+ g_assert_cmpstr (icalparameter_get_filename (param), ==, basename);
+
+ attach = icalproperty_get_attach (prop);
+ g_assert_nonnull (attach);
+ g_assert (!icalattach_get_is_url (attach));
+
+ check_attachment_content (attach, content, content_len);
+
+ success = e_cal_meta_backend_store_inline_attachments_sync (meta_backend, icalcomp, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_cmpint (icalcomponent_count_properties (icalcomp, ICAL_ATTACH_PROPERTY), ==, 1);
+
+ prop = icalcomponent_get_first_property (icalcomp, ICAL_ATTACH_PROPERTY);
+ g_assert_nonnull (prop);
+ g_assert_nonnull (icalproperty_get_first_parameter (prop, ICAL_FILENAME_PARAMETER));
+ g_assert_null (icalproperty_get_first_parameter (prop, ICAL_VALUE_PARAMETER));
+ g_assert_null (icalproperty_get_first_parameter (prop, ICAL_ENCODING_PARAMETER));
+
+ param = icalproperty_get_first_parameter (prop, ICAL_FILENAME_PARAMETER);
+ g_assert_cmpstr (icalparameter_get_filename (param), ==, basename);
+
+ attach = icalproperty_get_attach (prop);
+ g_assert_nonnull (attach);
+ g_assert (icalattach_get_is_url (attach));
+
+ check_attachment_content (attach, content, content_len);
+
+ /* Add a URL attachment which is not pointing to a local file */
+ attach = icalattach_new_from_url (REMOTE_URL);
+ prop = icalproperty_new_attach (attach);
+ icalattach_unref (attach);
+ icalcomponent_add_property (icalcomp, prop);
+
+ g_assert_cmpint (icalcomponent_count_properties (icalcomp, ICAL_ATTACH_PROPERTY), ==, 2);
+
+ success = e_cal_meta_backend_inline_local_attachments_sync (meta_backend, icalcomp, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_cmpint (icalcomponent_count_properties (icalcomp, ICAL_ATTACH_PROPERTY), ==, 2);
+
+ prop = icalcomponent_get_first_property (icalcomp, ICAL_ATTACH_PROPERTY);
+ g_assert_nonnull (prop);
+ g_assert_nonnull (icalproperty_get_first_parameter (prop, ICAL_FILENAME_PARAMETER));
+ g_assert_nonnull (icalproperty_get_first_parameter (prop, ICAL_VALUE_PARAMETER));
+ g_assert_nonnull (icalproperty_get_first_parameter (prop, ICAL_ENCODING_PARAMETER));
+
+ param = icalproperty_get_first_parameter (prop, ICAL_FILENAME_PARAMETER);
+ g_assert_cmpstr (icalparameter_get_filename (param), ==, basename);
+
+ attach = icalproperty_get_attach (prop);
+ g_assert_nonnull (attach);
+ g_assert (!icalattach_get_is_url (attach));
+
+ check_attachment_content (attach, content, content_len);
+
+ /* Verify the remote URL did not change */
+ prop = icalcomponent_get_next_property (icalcomp, ICAL_ATTACH_PROPERTY);
+ g_assert_nonnull (prop);
+ g_assert_null (icalproperty_get_first_parameter (prop, ICAL_FILENAME_PARAMETER));
+
+ attach = icalproperty_get_attach (prop);
+ g_assert_nonnull (attach);
+ g_assert (icalattach_get_is_url (attach));
+ g_assert_cmpstr (icalattach_get_url (attach), ==, REMOTE_URL);
+
+ success = e_cal_meta_backend_store_inline_attachments_sync (meta_backend, icalcomp, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_cmpint (icalcomponent_count_properties (icalcomp, ICAL_ATTACH_PROPERTY), ==, 2);
+
+ prop = icalcomponent_get_first_property (icalcomp, ICAL_ATTACH_PROPERTY);
+ g_assert_nonnull (prop);
+ g_assert_nonnull (icalproperty_get_first_parameter (prop, ICAL_FILENAME_PARAMETER));
+ g_assert_null (icalproperty_get_first_parameter (prop, ICAL_VALUE_PARAMETER));
+ g_assert_null (icalproperty_get_first_parameter (prop, ICAL_ENCODING_PARAMETER));
+
+ param = icalproperty_get_first_parameter (prop, ICAL_FILENAME_PARAMETER);
+ g_assert_cmpstr (icalparameter_get_filename (param), ==, basename);
+
+ attach = icalproperty_get_attach (prop);
+ g_assert_nonnull (attach);
+ g_assert (icalattach_get_is_url (attach));
+
+ check_attachment_content (attach, content, content_len);
+
+ /* Verify the remote URL did not change */
+ prop = icalcomponent_get_next_property (icalcomp, ICAL_ATTACH_PROPERTY);
+ g_assert_nonnull (prop);
+ g_assert_null (icalproperty_get_first_parameter (prop, ICAL_FILENAME_PARAMETER));
+
+ attach = icalproperty_get_attach (prop);
+ g_assert_nonnull (attach);
+ g_assert (icalattach_get_is_url (attach));
+ g_assert_cmpstr (icalattach_get_url (attach), ==, REMOTE_URL);
+
+ icalcomponent_free (icalcomp);
+ g_object_unref (meta_backend);
+ g_object_unref (comp);
+ g_free (filename);
+ g_free (content);
+}
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ TCUClosure closure_events = { TCU_LOAD_COMPONENT_SET_EVENTS };
+
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
+
+ /* Ensure that the client and server get the same locale */
+ g_assert (g_setenv ("LC_ALL", "en_US.UTF-8", TRUE));
+ setlocale (LC_ALL, "");
+
+#ifdef HAVE_ICALTZUTIL_SET_EXACT_VTIMEZONES_SUPPORT
+ icaltzutil_set_exact_vtimezones_support (0);
+#endif
+
+ g_test_add ("/ECalMetaBackend/MergeInstances", TCUFixture, &closure_events,
+ tcu_fixture_setup, test_merge_instances, tcu_fixture_teardown);
+ g_test_add ("/ECalMetaBackend/Attachments", TCUFixture, &closure_events,
+ tcu_fixture_setup, test_attachments, tcu_fixture_teardown);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]