[evolution-data-server/treitter-test-suites] Add test for EDataCal method 'getQuery' and the view's 'start' method.
- From: Travis Reitter <treitter src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-data-server/treitter-test-suites] Add test for EDataCal method 'getQuery' and the view's 'start' method.
- Date: Wed, 30 Dec 2009 00:57:57 +0000 (UTC)
commit e3fd7baeafafd93695e7f52cfaf51ab0af78359c
Author: Travis Reitter <treitter gmail com>
Date: Tue Dec 22 22:59:08 2009 -0800
Add test for EDataCal method 'getQuery' and the view's 'start' method.
calendar/tests/ecal/Makefile.am | 3 +
calendar/tests/ecal/ecal-test-utils.c | 16 +++
calendar/tests/ecal/ecal-test-utils.h | 4 +
calendar/tests/ecal/test-ecal-get-query.c | 184 +++++++++++++++++++++++++++++
4 files changed, 207 insertions(+), 0 deletions(-)
---
diff --git a/calendar/tests/ecal/Makefile.am b/calendar/tests/ecal/Makefile.am
index 38edcb8..34d7b67 100644
--- a/calendar/tests/ecal/Makefile.am
+++ b/calendar/tests/ecal/Makefile.am
@@ -52,6 +52,7 @@ TESTS = \
test-ecal-modify-object \
test-ecal-send-objects \
test-ecal-receive-objects \
+ test-ecal-get-query \
$(NULL)
# The test program
@@ -84,6 +85,8 @@ test_ecal_get_object_list_LDADD=$(TEST_ECAL_LIBS)
test_ecal_get_object_list_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
test_ecal_get_objects_for_uid_LDADD=$(TEST_ECAL_LIBS)
test_ecal_get_objects_for_uid_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
+test_ecal_get_query_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_get_query_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
test_ecal_get_timezone_LDADD=$(TEST_ECAL_LIBS)
test_ecal_get_timezone_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
test_ecal_modify_object_LDADD=$(TEST_ECAL_LIBS)
diff --git a/calendar/tests/ecal/ecal-test-utils.c b/calendar/tests/ecal/ecal-test-utils.c
index ea82c46..7602c6d 100644
--- a/calendar/tests/ecal/ecal-test-utils.c
+++ b/calendar/tests/ecal/ecal-test-utils.c
@@ -647,3 +647,19 @@ ecal_test_utils_cal_receive_objects (ECal *cal,
g_print ("successfully received the objects\n");
}
+
+ECalView*
+ecal_test_utils_get_query (ECal *cal,
+ const char *sexp)
+{
+ GError *error = NULL;
+ ECalView *query = NULL;
+
+ if (!e_cal_get_query (cal, sexp, &query, &error)) {
+ g_error (G_STRLOC ": Unable to obtain calendar view: %s\n",
+ error->message);
+ }
+ g_print ("successfully retrieved calendar view for query '%s'", sexp);
+
+ return query;
+}
diff --git a/calendar/tests/ecal/ecal-test-utils.h b/calendar/tests/ecal/ecal-test-utils.h
index ff3adaf..1f904b0 100644
--- a/calendar/tests/ecal/ecal-test-utils.h
+++ b/calendar/tests/ecal/ecal-test-utils.h
@@ -144,4 +144,8 @@ void
ecal_test_utils_cal_receive_objects (ECal *cal,
icalcomponent *component);
+ECalView*
+ecal_test_utils_get_query (ECal *cal,
+ const char *sexp);
+
#endif /* _ECAL_TEST_UTILS_H */
diff --git a/calendar/tests/ecal/test-ecal-get-query.c b/calendar/tests/ecal/test-ecal-get-query.c
new file mode 100644
index 0000000..6b5c375
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-get-query.c
@@ -0,0 +1,184 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libecal/e-cal.h>
+#include <libical/ical.h>
+
+#include "ecal-test-utils.h"
+
+#define COMPLETE_TIMEOUT 30
+
+#define EVENT_SUMMARY "Creation of the initial test event"
+#define INITIAL_BEGIN_TIME "20040109T090000Z"
+#define INITIAL_BEGIN_TIMEZONE "UTC"
+#define INITIAL_END_TIME "20040109T103000"
+#define INITIAL_END_TIMEZONE "UTC"
+#define FINAL_BEGIN_TIME "20091221T090000Z"
+#define FINAL_BEGIN_TIMEZONE "UTC"
+
+static void complete_timeout_cb (gpointer user_data) __attribute__ ((noreturn));
+
+static GMainLoop *loop;
+static guint complete_timeout_id;
+static guint alter_cal_id;
+
+typedef enum {
+ SUBTEST_OBJECTS_ADDED,
+ SUBTEST_OBJECTS_MODIFIED,
+ SUBTEST_OBJECTS_REMOVED,
+ SUBTEST_VIEW_DONE,
+ NUM_SUBTESTS,
+} SubTestId;
+
+static void
+subtest_passed (SubTestId id)
+{
+ static guint subtests_complete = 0;
+
+ subtests_complete |= (1 << id);
+
+ if (subtests_complete == ((1 << NUM_SUBTESTS) - 1))
+ g_main_loop_quit (loop);
+}
+
+static void
+objects_added_cb (GObject *object, GList *objects, gpointer data)
+{
+ GList *l;
+
+ for (l = objects; l; l = l->next)
+ g_print ("Object added %s\n", icalcomponent_get_uid (l->data));
+
+ subtest_passed (SUBTEST_OBJECTS_ADDED);
+}
+
+static void
+objects_modified_cb (GObject *object, GList *objects, gpointer data)
+{
+ GList *l;
+
+ for (l = objects; l; l = l->next)
+ g_print ("Object modified %s\n", icalcomponent_get_uid (l->data));
+
+ subtest_passed (SUBTEST_OBJECTS_MODIFIED);
+}
+
+static void
+objects_removed_cb (GObject *object, GList *objects, gpointer data)
+{
+ GList *l;
+
+ for (l = objects; l; l = l->next) {
+ ECalComponentId *id = l->data;
+
+ g_print ("Object removed: uid: %s, rid: %s\n", id->uid,
+ id->rid);
+ }
+
+ subtest_passed (SUBTEST_OBJECTS_REMOVED);
+}
+
+static void
+view_done_cb (GObject *object, ECalendarStatus status, gpointer data)
+{
+ g_print ("View done\n");
+
+ g_source_remove (complete_timeout_id);
+
+ subtest_passed (SUBTEST_VIEW_DONE);
+}
+
+static void
+complete_timeout_cb (gpointer user_data)
+{
+ g_error ("failed to complete all the pieces of the test in time");
+}
+
+static gboolean
+alter_cal_cb (ECal *cal)
+{
+ ECalComponent *e_component;
+ ECalComponent *e_component_final;
+ icalcomponent *component;
+ icalcomponent *component_final;
+ struct icaltimetype icaltime;
+ char *uid;
+
+ /* create a calendar object */
+ ecal_test_utils_create_component (cal, INITIAL_BEGIN_TIME,
+ INITIAL_BEGIN_TIMEZONE, INITIAL_END_TIME,
+ INITIAL_END_TIMEZONE, EVENT_SUMMARY, &e_component,
+ &uid);
+ component = e_cal_component_get_icalcomponent (e_component);
+
+ component_final = ecal_test_utils_cal_get_object (cal, uid);
+ ecal_test_utils_cal_assert_objects_equal_shallow (component,
+ component_final);
+ icalcomponent_free (component_final);
+
+ /* make and commit changes to the object */
+ icaltime = icaltime_from_string (FINAL_BEGIN_TIME);
+ icalcomponent_set_dtstart (component, icaltime);
+ ecal_test_utils_cal_component_set_icalcomponent (e_component,
+ component);
+ ecal_test_utils_cal_modify_object (cal, component, CALOBJ_MOD_ALL);
+
+ /* verify the modification */
+ component_final = ecal_test_utils_cal_get_object (cal, uid);
+ e_component_final = e_cal_component_new ();
+ ecal_test_utils_cal_component_set_icalcomponent (e_component_final,
+ component_final);
+
+ ecal_test_utils_cal_assert_e_cal_components_equal (e_component,
+ e_component_final);
+
+ /* remove the object */
+ ecal_test_utils_cal_remove_object (cal, uid);
+
+ /* Clean-up */
+ ecal_test_utils_cal_remove (cal);
+
+ g_object_unref (e_component_final);
+ g_free (uid);
+ icalcomponent_free (component);
+
+ return FALSE;
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ ECal *cal;
+ char *uri = NULL;
+ ECalView *view = NULL;
+
+ g_type_init ();
+
+ cal = ecal_test_utils_cal_new_temp (&uri, E_CAL_SOURCE_TYPE_EVENT);
+ ecal_test_utils_cal_open (cal, FALSE);
+
+ view = ecal_test_utils_get_query (cal, "(contains? \"any\" \"event\")");
+
+ /* monitor changes to the calendar */
+ g_signal_connect (G_OBJECT (view), "objects_added",
+ G_CALLBACK (objects_added_cb), cal);
+ g_signal_connect (G_OBJECT (view), "objects_modified",
+ G_CALLBACK (objects_modified_cb), cal);
+ g_signal_connect (G_OBJECT (view), "objects_removed",
+ G_CALLBACK (objects_removed_cb), cal);
+ g_signal_connect (G_OBJECT (view), "view_done",
+ G_CALLBACK (view_done_cb), cal);
+
+ e_cal_view_start (view);
+
+ loop = g_main_loop_new (NULL, TRUE);
+ alter_cal_id = g_idle_add ((GSourceFunc) alter_cal_cb, cal);
+ complete_timeout_id = g_timeout_add_seconds (COMPLETE_TIMEOUT,
+ (GSourceFunc) complete_timeout_cb, cal);
+
+ g_main_loop_run (loop);
+
+ g_object_unref (view);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]