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"
8 #include "client-test-utils.h" /* For print_icomp() */
10 static ETestServerClosure cal_closure =
11 { E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
13 static icalcomponent *
16 icalcomponent *icalcomp;
17 struct icaltimetype now;
19 now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
20 icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
21 icalcomponent_set_summary (icalcomp, "To-be-sent event summary");
22 icalcomponent_set_dtstart (icalcomp, now);
23 icalcomponent_set_dtend (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
29 manage_result (GSList *users,
30 icalcomponent *modified_icalcomp)
32 g_print ("Wishes to send to %d users", g_slist_length (users));
38 for (u = users; u; u = u->next)
39 g_print ("%s%s", u == users ? "" : ", ", (const gchar *) u->data);
43 if (!modified_icalcomp)
44 g_print ("No modified icalcomp, would send the same\n");
46 print_icomp (modified_icalcomp);
48 e_client_util_free_string_slist (users);
49 if (modified_icalcomp)
50 icalcomponent_free (modified_icalcomp);
54 test_send_objects_sync (ETestServerFixture *fixture,
55 gconstpointer user_data)
57 ECalClient *cal_client;
59 icalcomponent *icalcomp, *modified_icalcomp = NULL;
62 cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
64 icalcomp = create_object ();
65 if (!e_cal_client_send_objects_sync (cal_client, icalcomp, &users, &modified_icalcomp, NULL, &error))
66 g_error ("send objects sync: %s", error->message);
68 icalcomponent_free (icalcomp);
69 manage_result (users, modified_icalcomp);
73 async_send_result_ready (GObject *source_object,
77 ECalClient *cal_client;
80 icalcomponent *modified_icalcomp = NULL;
81 GMainLoop *loop = (GMainLoop *)user_data;
83 cal_client = E_CAL_CLIENT (source_object);
85 if (!e_cal_client_send_objects_finish (cal_client, result, &users, &modified_icalcomp, &error))
86 g_error ("send objects finish: %s", error->message);
88 manage_result (users, modified_icalcomp);
89 g_main_loop_quit (loop);
93 test_send_objects_async (ETestServerFixture *fixture,
94 gconstpointer user_data)
96 ECalClient *cal_client;
97 icalcomponent *icalcomp;
99 cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
101 icalcomp = create_object ();
104 e_cal_client_send_objects (cal_client, icalcomp, NULL, async_send_result_ready, fixture->loop);
105 icalcomponent_free (icalcomp);
107 g_main_loop_run (fixture->loop);
114 #if !GLIB_CHECK_VERSION (2, 35, 1)
117 g_test_init (&argc, &argv, NULL);
119 g_test_add ("/ECalClient/SendObjects/Sync", ETestServerFixture, &cal_closure,
120 e_test_server_utils_setup, test_send_objects_sync, e_test_server_utils_teardown);
121 g_test_add ("/ECalClient/SendObjects/Async", ETestServerFixture, &cal_closure,
122 e_test_server_utils_setup, test_send_objects_async, e_test_server_utils_teardown);
124 return e_test_server_utils_run ();