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,
51 for (l = objects; l; l = l->next)
52 test_print ("Object added %s\n", icalcomponent_get_uid (l->data));
54 subtest_passed (SUBTEST_OBJECTS_ADDED);
58 objects_modified_cb (GObject *object,
64 for (l = objects; l; l = l->next)
65 test_print ("Object modified %s\n", icalcomponent_get_uid (l->data));
67 subtest_passed (SUBTEST_OBJECTS_MODIFIED);
71 objects_removed_cb (GObject *object,
77 for (l = objects; l; l = l->next) {
78 ECalComponentId *id = l->data;
80 test_print ("Object removed: uid: %s, rid: %s\n", id->uid,
84 subtest_passed (SUBTEST_OBJECTS_REMOVED);
88 view_complete_cb (GObject *object,
89 ECalendarStatus status,
90 const gchar *error_msg,
93 test_print ("View complete (status: %d, error_msg:%s\n", status, error_msg ? error_msg : "NULL");
95 g_source_remove (complete_timeout_id);
97 subtest_passed (SUBTEST_VIEW_DONE);
101 complete_timeout_cb (gpointer user_data)
103 g_error ("failed to complete all the pieces of the test in time");
107 alter_cal_cb (ECal *cal)
109 ECalComponent *e_component;
110 ECalComponent *e_component_final;
111 icalcomponent *component;
112 icalcomponent *component_final;
113 struct icaltimetype icaltime;
116 /* create a calendar object */
117 ecal_test_utils_create_component (cal, INITIAL_BEGIN_TIME,
118 INITIAL_BEGIN_TIMEZONE, INITIAL_END_TIME,
119 INITIAL_END_TIMEZONE, EVENT_SUMMARY, &e_component,
121 component = e_cal_component_get_icalcomponent (e_component);
123 component_final = ecal_test_utils_cal_get_object (cal, uid);
124 ecal_test_utils_cal_assert_objects_equal_shallow (component,
126 icalcomponent_free (component_final);
128 /* make and commit changes to the object */
129 icaltime = icaltime_from_string (FINAL_BEGIN_TIME);
130 icalcomponent_set_dtstart (component, icaltime);
131 ecal_test_utils_cal_component_set_icalcomponent (e_component,
133 ecal_test_utils_cal_modify_object (cal, component, CALOBJ_MOD_ALL);
135 /* verify the modification */
136 component_final = ecal_test_utils_cal_get_object (cal, uid);
137 e_component_final = e_cal_component_new ();
138 ecal_test_utils_cal_component_set_icalcomponent (e_component_final,
141 ecal_test_utils_cal_assert_e_cal_components_equal (e_component,
144 /* remove the object */
145 ecal_test_utils_cal_remove_object (cal, uid);
147 g_object_unref (e_component_final);
149 icalcomponent_free (component);
160 ECalView *view = NULL;
164 cal = ecal_test_utils_cal_new_temp (&uri, E_CAL_SOURCE_TYPE_EVENT);
165 ecal_test_utils_cal_open (cal, FALSE);
167 view = ecal_test_utils_get_query (cal, "(contains? \"any\" \"event\")");
169 /* monitor changes to the calendar */
170 g_signal_connect (G_OBJECT (view), "objects_added",
171 G_CALLBACK (objects_added_cb), cal);
172 g_signal_connect (G_OBJECT (view), "objects_modified",
173 G_CALLBACK (objects_modified_cb), cal);
174 g_signal_connect (G_OBJECT (view), "objects_removed",
175 G_CALLBACK (objects_removed_cb), cal);
176 g_signal_connect (G_OBJECT (view), "view_complete",
177 G_CALLBACK (view_complete_cb), cal);
179 e_cal_view_start (view);
181 loop = g_main_loop_new (NULL, TRUE);
182 alter_cal_id = g_idle_add ((GSourceFunc) alter_cal_cb, cal);
183 complete_timeout_id = g_timeout_add_seconds (COMPLETE_TIMEOUT,
184 (GSourceFunc) complete_timeout_cb, cal);
186 g_main_loop_run (loop);
188 g_object_unref (view);