summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2017-02-22 11:41:14 +0100
committerMilan Crha <mcrha@redhat.com>2017-03-21 18:20:16 +0100
commit11956500fbcc7ed996205d4be3dadbb89e9cec57 (patch)
treee50ab6c31c0021c9d0a41ab591dfe384b12e8538 /tests
parentfe5f2d199dfa77e3230a0670fe72b8001f0a9f35 (diff)
downloadevolution-data-server-11956500fbcc7ed996205d4be3dadbb89e9cec57.tar.gz
Add ECalCache getters test + some other minor changes
Diffstat (limited to 'tests')
-rw-r--r--tests/libedata-cal/CMakeLists.txt3
-rw-r--r--tests/libedata-cal/components/event-4.ics1
-rw-r--r--tests/libedata-cal/components/event-7.ics1
-rw-r--r--tests/libedata-cal/test-cal-cache-getters.c247
-rw-r--r--tests/libedata-cal/test-cal-cache-search.c4
5 files changed, 252 insertions, 4 deletions
diff --git a/tests/libedata-cal/CMakeLists.txt b/tests/libedata-cal/CMakeLists.txt
index 4f0b24edf..558012e82 100644
--- a/tests/libedata-cal/CMakeLists.txt
+++ b/tests/libedata-cal/CMakeLists.txt
@@ -78,8 +78,9 @@ set(extra_defines)
set(TESTS
test-cal-backend-sexp
test-intervaltree
- test-cal-cache-offline
+ test-cal-cache-getters
test-cal-cache-intervals
+ test-cal-cache-offline
test-cal-cache-search
)
diff --git a/tests/libedata-cal/components/event-4.ics b/tests/libedata-cal/components/event-4.ics
index eb409ff44..2fde42505 100644
--- a/tests/libedata-cal/components/event-4.ics
+++ b/tests/libedata-cal/components/event-4.ics
@@ -9,5 +9,4 @@ DTEND:20170102T180000Z
SUMMARY:After-party clean up
LOCATION:All around
CLASS:PUBLIC
-CATEGORIES:Holiday,Work
END:VEVENT
diff --git a/tests/libedata-cal/components/event-7.ics b/tests/libedata-cal/components/event-7.ics
index f1c052311..769b7ac24 100644
--- a/tests/libedata-cal/components/event-7.ics
+++ b/tests/libedata-cal/components/event-7.ics
@@ -10,4 +10,5 @@ ATTACH:file:///usr/share/icons/hicolor/48x48/apps/evolution.png
CLASS:PUBLIC
CREATED:20170221T125054Z
LAST-MODIFIED:20170221T125054Z
+CATEGORIES:Holiday,Work
END:VEVENT
diff --git a/tests/libedata-cal/test-cal-cache-getters.c b/tests/libedata-cal/test-cal-cache-getters.c
new file mode 100644
index 000000000..4c054133a
--- /dev/null
+++ b/tests/libedata-cal/test-cal-cache-getters.c
@@ -0,0 +1,247 @@
+/* -*- 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 <stdlib.h>
+#include <locale.h>
+#include <libecal/libecal.h>
+
+#include "test-cal-cache-utils.h"
+
+static ECalComponentId *
+extract_id_from_component (ECalComponent *component)
+{
+ ECalComponentId *id;
+
+ g_assert (component != NULL);
+
+ id = e_cal_component_get_id (component);
+ g_assert (id != NULL);
+ g_assert (id->uid != NULL);
+
+ return id;
+}
+
+static ECalComponentId *
+extract_id_from_string (const gchar *icalstring)
+{
+ ECalComponent *component;
+ ECalComponentId *id;
+
+ g_assert (icalstring != NULL);
+
+ component = e_cal_component_new_from_string (icalstring);
+ g_assert (component != NULL);
+
+ id = extract_id_from_component (component);
+
+ g_object_unref (component);
+
+ return id;
+}
+
+static void
+test_get_one (ECalCache *cal_cache,
+ const gchar *uid,
+ const gchar *rid,
+ gboolean expect_failure)
+{
+ ECalComponent *component = NULL;
+ ECalComponentId *id;
+ gchar *icalstring = NULL;
+ gboolean success;
+ GError *error = NULL;
+
+ success = e_cal_cache_get_component (cal_cache, uid, rid, &component, NULL, &error);
+ if (expect_failure) {
+ g_assert_error (error, E_CACHE_ERROR, E_CACHE_ERROR_NOT_FOUND);
+ g_assert (!success);
+ g_assert (!component);
+
+ g_clear_error (&error);
+ } else {
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_nonnull (component);
+
+ id = extract_id_from_component (component);
+
+ g_assert_cmpstr (id->uid, ==, uid);
+ g_assert_cmpstr (id->rid, ==, rid && *rid ? rid : NULL);
+
+ e_cal_component_free_id (id);
+ g_object_unref (component);
+ }
+
+ success = e_cal_cache_get_component_as_string (cal_cache, uid, rid, &icalstring, NULL, &error);
+ if (expect_failure) {
+ g_assert_error (error, E_CACHE_ERROR, E_CACHE_ERROR_NOT_FOUND);
+ g_assert (!success);
+ g_assert (!icalstring);
+
+ g_clear_error (&error);
+ } else {
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_nonnull (icalstring);
+
+ id = extract_id_from_string (icalstring);
+
+ g_assert_cmpstr (id->uid, ==, uid);
+ g_assert_cmpstr (id->rid, ==, rid && *rid ? rid : NULL);
+
+ e_cal_component_free_id (id);
+ g_free (icalstring);
+ }
+}
+
+static void
+test_getters_one (TCUFixture *fixture,
+ gconstpointer user_data)
+{
+ test_get_one (fixture->cal_cache, "unexistent-event", NULL, TRUE);
+ test_get_one (fixture->cal_cache, "unexistent-event", "", TRUE);
+ test_get_one (fixture->cal_cache, "event-2", NULL, FALSE);
+ test_get_one (fixture->cal_cache, "event-2", "", FALSE);
+ test_get_one (fixture->cal_cache, "event-5", NULL, FALSE);
+ test_get_one (fixture->cal_cache, "event-5", "", FALSE);
+ test_get_one (fixture->cal_cache, "event-5", "20131231T000000Z", TRUE);
+ test_get_one (fixture->cal_cache, "event-6", NULL, FALSE);
+ test_get_one (fixture->cal_cache, "event-6", "", FALSE);
+ test_get_one (fixture->cal_cache, "event-6", "20170225T134900", FALSE);
+}
+
+/* NULL-terminated list of pairs <uid, rid>, what to expect */
+static void
+test_get_all (ECalCache *cal_cache,
+ const gchar *uid,
+ ...)
+{
+ ECalComponentId *id;
+ GSList *items, *link;
+ va_list va;
+ const gchar *tmp;
+ GHashTable *expects;
+ gboolean success;
+ GError *error = NULL;
+
+ expects = g_hash_table_new_full ((GHashFunc) e_cal_component_id_hash, (GEqualFunc) e_cal_component_id_equal,
+ (GDestroyNotify) e_cal_component_free_id, NULL);
+
+ va_start (va, uid);
+ tmp = va_arg (va, const gchar *);
+ while (tmp) {
+ const gchar *rid = va_arg (va, const gchar *);
+ id = e_cal_component_id_new (tmp, rid);
+
+ g_hash_table_insert (expects, id, NULL);
+
+ tmp = va_arg (va, const gchar *);
+ }
+ va_end (va);
+
+ items = NULL;
+
+ success = e_cal_cache_get_components_by_uid (cal_cache, uid, &items, NULL, &error);
+ if (!g_hash_table_size (expects)) {
+ g_assert_error (error, E_CACHE_ERROR, E_CACHE_ERROR_NOT_FOUND);
+ g_assert (!success);
+ g_assert (!items);
+
+ g_clear_error (&error);
+ } else {
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_nonnull (items);
+
+ g_assert_cmpint (g_hash_table_size (expects), ==, g_slist_length (items));
+
+ for (link = items; link; link = g_slist_next (link)) {
+ id = extract_id_from_component (link->data);
+
+ g_assert_cmpstr (id->uid, ==, uid);
+ g_assert (g_hash_table_contains (expects, id));
+
+ e_cal_component_free_id (id);
+ }
+
+ g_slist_free_full (items, g_object_unref);
+ }
+
+ items = NULL;
+
+ success = e_cal_cache_get_components_by_uid_as_string (cal_cache, uid, &items, NULL, &error);
+ if (!g_hash_table_size (expects)) {
+ g_assert_error (error, E_CACHE_ERROR, E_CACHE_ERROR_NOT_FOUND);
+ g_assert (!success);
+ g_assert (!items);
+
+ g_clear_error (&error);
+ } else {
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert_nonnull (items);
+
+ g_assert_cmpint (g_hash_table_size (expects), ==, g_slist_length (items));
+
+ for (link = items; link; link = g_slist_next (link)) {
+ id = extract_id_from_string (link->data);
+
+ g_assert_cmpstr (id->uid, ==, uid);
+ g_assert (g_hash_table_contains (expects, id));
+
+ e_cal_component_free_id (id);
+ }
+
+ g_slist_free_full (items, g_free);
+ }
+
+ g_hash_table_destroy (expects);
+}
+
+static void
+test_getters_all (TCUFixture *fixture,
+ gconstpointer user_data)
+{
+ test_get_all (fixture->cal_cache, "unexistent-event", NULL);
+ test_get_all (fixture->cal_cache, "unexistent-event", NULL);
+ test_get_all (fixture->cal_cache, "event-2", "event-2", NULL, NULL);
+ test_get_all (fixture->cal_cache, "event-5", "event-5", NULL, NULL);
+ test_get_all (fixture->cal_cache, "event-6", "event-6", NULL, "event-6", "20170225T134900", NULL);
+}
+
+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, "");
+
+ g_test_add ("/ECalCache/Getters/One", TCUFixture, &closure_events,
+ tcu_fixture_setup, test_getters_one, tcu_fixture_teardown);
+ g_test_add ("/ECalCache/Getters/All", TCUFixture, &closure_events,
+ tcu_fixture_setup, test_getters_all, tcu_fixture_teardown);
+
+ return g_test_run ();
+}
diff --git a/tests/libedata-cal/test-cal-cache-search.c b/tests/libedata-cal/test-cal-cache-search.c
index 754aec49e..7373fa409 100644
--- a/tests/libedata-cal/test-cal-cache-search.c
+++ b/tests/libedata-cal/test-cal-cache-search.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * Copyright (C) 2016 Red Hat, Inc. (www.redhat.com)
+ * 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
@@ -356,7 +356,7 @@ test_search_has_categories (TCUFixture *fixture,
gconstpointer user_data)
{
test_search (fixture, "(has-categories? #f)", "!event-2");
- test_search (fixture, "(has-categories? \"Holiday\")", "event-4");
+ test_search (fixture, "(has-categories? \"Holiday\")", "event-7");
test_search (fixture, "(has-categories? \"Hard\" \"Work\")", "event-2");
test_search (fixture, "(has-categories? \"Hard\" \"Work\")", "!event-4");
}