1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#include <stdlib.h>
#include <libecal/libecal.h>
#include <libical/ical.h>
#include "e-test-server-utils.h"
static ETestServerClosure cal_closure =
{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
#define NB_COMPONENTS 5
static void
test_icalcomps (icalcomponent *icalcomp1,
icalcomponent *icalcomp2)
{
struct icaltimetype t1, t2;
if (!icalcomp2)
g_error ("Failure: get object returned NULL");
g_assert_cmpstr (icalcomponent_get_uid (icalcomp1), ==, icalcomponent_get_uid (icalcomp2));
g_assert_cmpstr (icalcomponent_get_summary (icalcomp1), ==, icalcomponent_get_summary (icalcomp2));
t1 = icalcomponent_get_dtstart (icalcomp1);
t2 = icalcomponent_get_dtstart (icalcomp2);
if (icaltime_compare (t1, t2) != 0)
g_error (
"Failure: dtend doesn't match, expected '%s', got '%s'\n",
icaltime_as_ical_string (t1), icaltime_as_ical_string (t2));
t1 = icalcomponent_get_dtend (icalcomp1);
t2 = icalcomponent_get_dtend (icalcomp2);
if (icaltime_compare (t1, t2) != 0)
g_error (
"Failure: dtend doesn't match, expected '%s', got '%s'\n",
icaltime_as_ical_string (t1), icaltime_as_ical_string (t2));
}
static void
check_removed (ECalClient *cal_client,
const GSList *uids)
{
g_assert (cal_client != NULL);
g_assert (uids != NULL);
while (uids) {
GError *error = NULL;
icalcomponent *icalcomp = NULL;
if (!e_cal_client_get_object_sync (cal_client, uids->data, NULL, &icalcomp, NULL, &error) &&
g_error_matches (error, E_CAL_CLIENT_ERROR, E_CAL_CLIENT_ERROR_OBJECT_NOT_FOUND)) {
g_clear_error (&error);
} else
g_error ("check objects removed sync: %s", error->message);
uids = uids->next;
}
}
static GSList *
uid_slist_to_ecalcomponentid_slist (GSList *uids)
{
GSList *ids = NULL;
const GSList *l;
for (l = uids; l; l = l->next) {
ECalComponentId *id = g_new0 (ECalComponentId, 1);
id->uid = g_strdup (l->data);
ids = g_slist_append (ids, id);
}
return ids;
}
static void
check_icalcomps_exist (ECalClient *cal_client,
GSList *icalcomps)
{
const GSList *l;
for (l = icalcomps; l; l = l->next) {
GError *error = NULL;
icalcomponent *icalcomp = l->data;
icalcomponent *icalcomp2 = NULL;
const gchar *uid = icalcomponent_get_uid (icalcomp);
if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp2, NULL, &error))
g_error ("get object sync: %s", error->message);
g_assert (icalcomp2 != NULL);
test_icalcomps (icalcomp, icalcomp2);
icalcomponent_free (icalcomp2);
}
}
static void
test_bulk_methods (ECalClient *cal_client,
GSList *icalcomps)
{
GError *error = NULL;
GSList *uids = NULL, *ids = NULL;
const GSList *lcomp, *luid;
gint i = 0;
g_assert (icalcomps != NULL);
/* Create all the objects in bulk */
if (!e_cal_client_create_objects_sync (cal_client, icalcomps, &uids, NULL, &error))
g_error ("create objects sync: %s", error->message);
g_assert (uids != NULL);
g_assert_cmpint (g_slist_length (uids), ==, NB_COMPONENTS);
/* Update icalcomponents uids */
luid = uids;
lcomp = icalcomps;
while (luid && lcomp) {
icalcomponent_set_uid (lcomp->data, luid->data);
luid = luid->next;
lcomp = lcomp->next;
}
/* Retrieve all the objects and check that they are the same */
check_icalcomps_exist (cal_client, icalcomps);
/* Modify the objects */
for (lcomp = icalcomps; lcomp; lcomp = lcomp->next) {
gchar *summary;
icalcomponent *icalcomp = lcomp->data;
summary = g_strdup_printf ("Edited test summary %d", i);
icalcomponent_set_summary (icalcomp, summary);
g_free (summary);
++i;
}
/* Save the modified objects in bulk */
if (!e_cal_client_modify_objects_sync (cal_client, icalcomps, E_CAL_OBJ_MOD_ALL, NULL, &error))
g_error ("modify objects sync: %s", error->message);
/* Retrieve all the objects and check that they have been modified */
check_icalcomps_exist (cal_client, icalcomps);
/* Remove all the objects in bulk */
ids = uid_slist_to_ecalcomponentid_slist (uids);
if (!e_cal_client_remove_objects_sync (cal_client, ids, E_CAL_OBJ_MOD_ALL, NULL, &error))
g_error ("remove objects sync: %s", error->message);
g_slist_free_full (ids, (GDestroyNotify) e_cal_component_free_id);
/* Check that the objects don't exist anymore */
check_removed (cal_client, uids);
g_slist_free_full (uids, g_free);
}
static void
run_test_bulk_methods (ETestServerFixture *fixture,
gconstpointer user_data)
{
ECalClient *cal_client;
GSList *icalcomps = NULL;
struct icaltimetype now;
gint i;
cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
/* Build up new components */
for (i = 0; i < NB_COMPONENTS; ++i) {
icalcomponent *icalcomp;
gchar *summary;
icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
summary = g_strdup_printf ("Test summary %d", i);
icalcomponent_set_summary (icalcomp, summary);
icalcomponent_set_dtstart (icalcomp, now);
icalcomponent_set_dtend (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
icalcomps = g_slist_append (icalcomps, icalcomp);
g_free (summary);
}
/* Test synchronous bulk methods */
test_bulk_methods (cal_client, icalcomps);
g_slist_free_full (icalcomps, (GDestroyNotify) icalcomponent_free);
}
gint
main (gint argc,
gchar **argv)
{
g_test_init (&argc, &argv, NULL);
g_test_bug_base ("http://bugzilla.gnome.org/");
g_test_add (
"/ECalClient/BulkMethods",
ETestServerFixture,
&cal_closure,
e_test_server_utils_setup,
run_test_bulk_methods,
e_test_server_utils_teardown);
return e_test_server_utils_run ();
}
|