1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
4 #include <libecal/libecal.h>
5 #include <libical/ical.h>
7 #include "e-test-server-utils.h"
9 static ETestServerClosure cal_closure =
10 { E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
12 #define EVENT_SUMMARY "Creation of new test event"
15 setup_cal (ECalClient *cal_client)
17 struct icaltimetype now;
18 icalcomponent *icalcomp;
22 now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
23 icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
24 icalcomponent_set_summary (icalcomp, "Initial" EVENT_SUMMARY);
25 icalcomponent_set_dtstart (icalcomp, now);
26 icalcomponent_set_dtend (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
28 if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error))
29 g_error ("create object sync: %s", error->message);
31 icalcomponent_free (icalcomp);
32 g_object_set_data_full (G_OBJECT (cal_client), "use-uid", uid, g_free);
36 test_result (icalcomponent *icalcomp)
38 g_assert (icalcomp != NULL);
39 g_assert_cmpstr (icalcomponent_get_summary (icalcomp), ==, EVENT_SUMMARY);
43 test_modify_object_sync (ETestServerFixture *fixture,
44 gconstpointer user_data)
46 ECalClient *cal_client;
48 icalcomponent *icalcomp = NULL;
51 cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
53 setup_cal (cal_client);
54 uid = g_object_get_data (G_OBJECT (cal_client), "use-uid");
55 g_assert (uid != NULL);
57 if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp, NULL, &error))
58 g_error ("get object sync: %s", error->message);
60 icalcomponent_set_summary (icalcomp, EVENT_SUMMARY);
62 if (!e_cal_client_modify_object_sync (cal_client, icalcomp, CALOBJ_MOD_ALL, NULL, &error))
63 g_error ("modify object sync: %s", error->message);
65 icalcomponent_free (icalcomp);
67 if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp, NULL, &error))
68 g_error ("get object sync after modification: %s", error->message);
70 test_result (icalcomp);
71 icalcomponent_free (icalcomp);
75 async_modify_result_ready (GObject *source_object,
79 ECalClient *cal_client;
81 icalcomponent *icalcomp = NULL;
83 GMainLoop *loop = (GMainLoop *)user_data;
85 cal_client = E_CAL_CLIENT (source_object);
86 uid = g_object_get_data (G_OBJECT (cal_client), "use-uid");
88 if (!e_cal_client_modify_object_finish (cal_client, result, &error))
89 g_error ("modify object finish: %s", error->message);
91 if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp, NULL, &error))
92 g_error ("get object sync after async modification: %s", error->message);
94 test_result (icalcomp);
95 icalcomponent_free (icalcomp);
97 g_main_loop_quit (loop);
101 test_modify_object_async (ETestServerFixture *fixture,
102 gconstpointer user_data)
104 ECalClient *cal_client;
105 GError *error = NULL;
106 icalcomponent *icalcomp = NULL;
109 cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
111 setup_cal (cal_client);
112 uid = g_object_get_data (G_OBJECT (cal_client), "use-uid");
113 g_assert (uid != NULL);
115 if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp, NULL, &error))
116 g_error ("get object sync: %s", error->message);
118 icalcomponent_set_summary (icalcomp, EVENT_SUMMARY);
120 e_cal_client_modify_object (cal_client, icalcomp, CALOBJ_MOD_ALL, NULL, async_modify_result_ready, fixture->loop);
121 icalcomponent_free (icalcomp);
123 g_main_loop_run (fixture->loop);
130 #if !GLIB_CHECK_VERSION (2, 35, 1)
133 g_test_init (&argc, &argv, NULL);
135 g_test_add ("/ECalClient/ModifyObject/Sync", ETestServerFixture, &cal_closure,
136 e_test_server_utils_setup, test_modify_object_sync, e_test_server_utils_teardown);
137 g_test_add ("/ECalClient/ModifyObject/Async", ETestServerFixture, &cal_closure,
138 e_test_server_utils_setup, test_modify_object_async, e_test_server_utils_teardown);
140 return e_test_server_utils_run ();