[evolution-data-server/wip/offline-cache] Add ECalCache getters test + some other minor changes



commit 11956500fbcc7ed996205d4be3dadbb89e9cec57
Author: Milan Crha <mcrha redhat com>
Date:   Wed Feb 22 11:41:14 2017 +0100

    Add ECalCache getters test + some other minor changes

 src/calendar/libedata-cal/e-cal-cache.c     |    6 +-
 src/calendar/libedata-cal/e-cal-cache.h     |    6 +-
 tests/libedata-cal/CMakeLists.txt           |    3 +-
 tests/libedata-cal/components/event-4.ics   |    1 -
 tests/libedata-cal/components/event-7.ics   |    1 +
 tests/libedata-cal/test-cal-cache-getters.c |  247 +++++++++++++++++++++++++++
 tests/libedata-cal/test-cal-cache-search.c  |    4 +-
 7 files changed, 258 insertions(+), 10 deletions(-)
---
diff --git a/src/calendar/libedata-cal/e-cal-cache.c b/src/calendar/libedata-cal/e-cal-cache.c
index eff7407..d9b57b6 100644
--- a/src/calendar/libedata-cal/e-cal-cache.c
+++ b/src/calendar/libedata-cal/e-cal-cache.c
@@ -2253,7 +2253,7 @@ e_cal_cache_get_components_by_uid (ECalCache *cal_cache,
        g_return_val_if_fail (uid != NULL, FALSE);
        g_return_val_if_fail (out_components != NULL, FALSE);
 
-       success = e_cal_cache_get_components_by_uid_as_strings (cal_cache, uid, &icalstrings, cancellable, 
error);
+       success = e_cal_cache_get_components_by_uid_as_string (cal_cache, uid, &icalstrings, cancellable, 
error);
        if (success) {
                *out_components = ecc_icalstrings_to_components (icalstrings);
        }
@@ -2262,7 +2262,7 @@ e_cal_cache_get_components_by_uid (ECalCache *cal_cache,
 }
 
 /**
- * e_cal_cache_get_components_by_uid_as_strings:
+ * e_cal_cache_get_components_by_uid_as_string:
  * @cal_cache: an #ECalCache
  * @uid: a UID of the component
  * @out_icalstrings: (out) (transfer full) (element-type utf8): return location for the iCal strings
@@ -2278,7 +2278,7 @@ e_cal_cache_get_components_by_uid (ECalCache *cal_cache,
  * Since: 3.26
  **/
 gboolean
-e_cal_cache_get_components_by_uid_as_strings (ECalCache *cal_cache,
+e_cal_cache_get_components_by_uid_as_string (ECalCache *cal_cache,
                                              const gchar *uid,
                                              GSList **out_icalstrings,
                                              GCancellable *cancellable,
diff --git a/src/calendar/libedata-cal/e-cal-cache.h b/src/calendar/libedata-cal/e-cal-cache.h
index 661da19..b816289 100644
--- a/src/calendar/libedata-cal/e-cal-cache.h
+++ b/src/calendar/libedata-cal/e-cal-cache.h
@@ -188,14 +188,14 @@ gboolean  e_cal_cache_remove_components   (ECalCache *cal_cache,
 gboolean       e_cal_cache_get_component       (ECalCache *cal_cache,
                                                 const gchar *uid,
                                                 const gchar *rid,
-                                                ECalComponent **out_component, /* ECalComponent * */
+                                                ECalComponent **out_component,
                                                 GCancellable *cancellable,
                                                 GError **error);
 gboolean       e_cal_cache_get_component_as_string
                                                (ECalCache *cal_cache,
                                                 const gchar *uid,
                                                 const gchar *rid,
-                                                gchar **out_icalstring, /* gchar * */
+                                                gchar **out_icalstring,
                                                 GCancellable *cancellable,
                                                 GError **error);
 gboolean       e_cal_cache_set_component_extra (ECalCache *cal_cache,
@@ -216,7 +216,7 @@ gboolean    e_cal_cache_get_components_by_uid
                                                 GSList **out_components, /* ECalComponent * */
                                                 GCancellable *cancellable,
                                                 GError **error);
-gboolean       e_cal_cache_get_components_by_uid_as_strings
+gboolean       e_cal_cache_get_components_by_uid_as_string
                                                (ECalCache *cal_cache,
                                                 const gchar *uid,
                                                 GSList **out_icalstrings, /* gchar * */
diff --git a/tests/libedata-cal/CMakeLists.txt b/tests/libedata-cal/CMakeLists.txt
index 4f0b24e..558012e 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 eb409ff..2fde425 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 f1c0523..769b7ac 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 0000000..4c05413
--- /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 754aec4..7373fa4 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");
 }


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