aaaa7891e3bf2160d03d14c4ed044a6294e6bf5e
[platform/upstream/evolution-data-server.git] / tests / libecal / client / test-client-receive-objects.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 #include <stdlib.h>
4 #include <libecal/libecal.h>
5 #include <libical/ical.h>
6
7 #include "e-test-server-utils.h"
8
9 static ETestServerClosure cal_closure =
10         { E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
11
12 static icalcomponent *
13 create_object (void)
14 {
15         icalcomponent *icalcomp;
16         struct icaltimetype now;
17
18         now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
19         icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
20         icalcomponent_set_summary (icalcomp, "To-be-received event summary");
21         icalcomponent_set_dtstart (icalcomp, now);
22         icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
23
24         return icalcomp;
25 }
26
27 static void
28 test_receive_objects_sync (ETestServerFixture *fixture,
29                            gconstpointer user_data)
30 {
31         ECalClient *cal_client;
32         GError *error = NULL;
33         icalcomponent *icalcomp;
34
35         cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
36
37         icalcomp = create_object ();
38         g_assert (icalcomp != NULL);
39
40         if (!e_cal_client_receive_objects_sync (cal_client, icalcomp, NULL, &error))
41                 g_error ("receive objects sync: %s", error->message);
42
43         icalcomponent_free (icalcomp);
44 }
45
46 static void
47 async_receive_result_ready (GObject *source_object,
48                             GAsyncResult *result,
49                             gpointer user_data)
50 {
51         ECalClient *cal_client;
52         GError *error = NULL;
53         GMainLoop *loop = (GMainLoop *) user_data;
54
55         cal_client = E_CAL_CLIENT (source_object);
56
57         if (!e_cal_client_receive_objects_finish (cal_client, result, &error))
58                 g_error ("receive objects finish: %s", error->message);
59
60         g_main_loop_quit (loop);
61 }
62
63 static void
64 test_receive_objects_async (ETestServerFixture *fixture,
65                             gconstpointer user_data)
66 {
67         ECalClient *cal_client;
68         icalcomponent *icalcomp;
69
70         cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
71
72         icalcomp = create_object ();
73         g_assert (icalcomp != NULL);
74
75         e_cal_client_receive_objects (cal_client, icalcomp, NULL, async_receive_result_ready, fixture->loop);
76         icalcomponent_free (icalcomp);
77
78         g_main_loop_run (fixture->loop);
79 }
80
81 gint
82 main (gint argc,
83       gchar **argv)
84 {
85 #if !GLIB_CHECK_VERSION (2, 35, 1)
86         g_type_init ();
87 #endif
88         g_test_init (&argc, &argv, NULL);
89         g_test_bug_base ("http://bugzilla.gnome.org/");
90
91         g_test_add (
92                 "/ECalClient/ReceiveObjects/Sync",
93                 ETestServerFixture,
94                 &cal_closure,
95                 e_test_server_utils_setup,
96                 test_receive_objects_sync,
97                 e_test_server_utils_teardown);
98         g_test_add (
99                 "/ECalClient/ReceiveObjects/Async",
100                 ETestServerFixture,
101                 &cal_closure,
102                 e_test_server_utils_setup,
103                 test_receive_objects_async,
104                 e_test_server_utils_teardown);
105
106         return e_test_server_utils_run ();
107 }