1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
4 #include <libecal/e-cal.h>
5 #include <libical/ical.h>
7 #include "ecal-test-utils.h"
9 #define COMPLETE_TIMEOUT 30
11 #define EVENT_SUMMARY "Creation of the initial test event"
12 #define INITIAL_BEGIN_TIME "20040109T090000Z"
13 #define INITIAL_BEGIN_TIMEZONE "UTC"
14 #define INITIAL_END_TIME "20040109T103000"
15 #define INITIAL_END_TIMEZONE "UTC"
16 #define FINAL_BEGIN_TIME "20091221T090000Z"
17 #define FINAL_BEGIN_TIMEZONE "UTC"
19 static void complete_timeout_cb (gpointer user_data) __attribute__ ((noreturn));
21 static GMainLoop *loop;
22 static guint complete_timeout_id;
23 static guint alter_cal_id;
26 SUBTEST_OBJECTS_ADDED,
27 SUBTEST_OBJECTS_MODIFIED,
28 SUBTEST_OBJECTS_REMOVED,
34 subtest_passed (SubTestId id)
36 static guint subtests_complete = 0;
38 subtests_complete |= (1 << id);
40 if (subtests_complete == ((1 << NUM_SUBTESTS) - 1))
41 g_main_loop_quit (loop);
45 objects_added_cb (GObject *object, GList *objects, gpointer data)
49 for (l = objects; l; l = l->next)
50 test_print ("Object added %s\n", icalcomponent_get_uid (l->data));
52 subtest_passed (SUBTEST_OBJECTS_ADDED);
56 objects_modified_cb (GObject *object, GList *objects, gpointer data)
60 for (l = objects; l; l = l->next)
61 test_print ("Object modified %s\n", icalcomponent_get_uid (l->data));
63 subtest_passed (SUBTEST_OBJECTS_MODIFIED);
67 objects_removed_cb (GObject *object, GList *objects, gpointer data)
71 for (l = objects; l; l = l->next) {
72 ECalComponentId *id = l->data;
74 test_print ("Object removed: uid: %s, rid: %s\n", id->uid,
78 subtest_passed (SUBTEST_OBJECTS_REMOVED);
82 view_complete_cb (GObject *object, ECalendarStatus status, const gchar *error_msg, gpointer data)
84 test_print ("View complete (status: %d, error_msg:%s\n", status, error_msg ? error_msg : "NULL");
86 g_source_remove (complete_timeout_id);
88 subtest_passed (SUBTEST_VIEW_DONE);
92 complete_timeout_cb (gpointer user_data)
94 g_error ("failed to complete all the pieces of the test in time");
98 alter_cal_cb (ECal *cal)
100 ECalComponent *e_component;
101 ECalComponent *e_component_final;
102 icalcomponent *component;
103 icalcomponent *component_final;
104 struct icaltimetype icaltime;
107 /* create a calendar object */
108 ecal_test_utils_create_component (cal, INITIAL_BEGIN_TIME,
109 INITIAL_BEGIN_TIMEZONE, INITIAL_END_TIME,
110 INITIAL_END_TIMEZONE, EVENT_SUMMARY, &e_component,
112 component = e_cal_component_get_icalcomponent (e_component);
114 component_final = ecal_test_utils_cal_get_object (cal, uid);
115 ecal_test_utils_cal_assert_objects_equal_shallow (component,
117 icalcomponent_free (component_final);
119 /* make and commit changes to the object */
120 icaltime = icaltime_from_string (FINAL_BEGIN_TIME);
121 icalcomponent_set_dtstart (component, icaltime);
122 ecal_test_utils_cal_component_set_icalcomponent (e_component,
124 ecal_test_utils_cal_modify_object (cal, component, CALOBJ_MOD_ALL);
126 /* verify the modification */
127 component_final = ecal_test_utils_cal_get_object (cal, uid);
128 e_component_final = e_cal_component_new ();
129 ecal_test_utils_cal_component_set_icalcomponent (e_component_final,
132 ecal_test_utils_cal_assert_e_cal_components_equal (e_component,
135 /* remove the object */
136 ecal_test_utils_cal_remove_object (cal, uid);
139 ecal_test_utils_cal_remove (cal);
141 g_object_unref (e_component_final);
143 icalcomponent_free (component);
149 main (gint argc, gchar **argv)
153 ECalView *view = NULL;
157 cal = ecal_test_utils_cal_new_temp (&uri, E_CAL_SOURCE_TYPE_EVENT);
158 ecal_test_utils_cal_open (cal, FALSE);
160 view = ecal_test_utils_get_query (cal, "(contains? \"any\" \"event\")");
162 /* monitor changes to the calendar */
163 g_signal_connect (G_OBJECT (view), "objects_added",
164 G_CALLBACK (objects_added_cb), cal);
165 g_signal_connect (G_OBJECT (view), "objects_modified",
166 G_CALLBACK (objects_modified_cb), cal);
167 g_signal_connect (G_OBJECT (view), "objects_removed",
168 G_CALLBACK (objects_removed_cb), cal);
169 g_signal_connect (G_OBJECT (view), "view_complete",
170 G_CALLBACK (view_complete_cb), cal);
172 e_cal_view_start (view);
174 loop = g_main_loop_new (NULL, TRUE);
175 alter_cal_id = g_idle_add ((GSourceFunc) alter_cal_cb, cal);
176 complete_timeout_id = g_timeout_add_seconds (COMPLETE_TIMEOUT,
177 (GSourceFunc) complete_timeout_cb, cal);
179 g_main_loop_run (loop);
181 g_object_unref (view);