1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
* Copyright (C) 2009 Intel Corporation
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of version 2 of the GNU Lesser General Public
7
* License as published by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
19
* Author: Travis Reitter (travis.reitter@collabora.co.uk)
25
#include <libecal/e-cal.h>
27
#include "ecal-test-utils.h"
30
test_print (const gchar *format,
34
const gchar *debug_string;
35
static gboolean debug_set = FALSE;
36
static gboolean debug = FALSE;
39
debug_string = g_getenv ("EDS_TEST_DEBUG");
41
debug = (g_ascii_strtoll (debug_string, NULL, 10) >= 1);
47
va_start (args, format);
48
vprintf (format, args);
54
ecal_test_utils_cal_new_from_uri (const gchar *uri,
59
test_print ("loading calendar '%s'\n", uri);
60
cal = e_cal_new_from_uri (uri, type);
62
g_error ("failed to create calendar: `%s'", uri);
68
ecal_test_utils_cal_new_temp (gchar **uri,
76
file_template = g_build_filename (g_get_tmp_dir (),
77
"ecal-test-XXXXXX/", NULL);
78
g_mkstemp (file_template);
80
uri_result = g_filename_to_uri (file_template, NULL, &error);
82
g_error ("failed to convert %s to an URI: %s", file_template,
85
g_free (file_template);
87
cal = ecal_test_utils_cal_new_from_uri (uri_result, type);
90
*uri = g_strdup (uri_result);
98
ecal_test_utils_cal_open (ECal *cal,
99
gboolean only_if_exists)
101
GError *error = NULL;
103
if (!e_cal_open (cal, only_if_exists, &error)) {
106
uri = e_cal_get_uri (cal);
108
g_warning ("failed to open calendar: `%s': %s", uri,
116
ECalendarStatus status,
117
ECalTestClosure *closure)
120
} else if (status == E_CALENDAR_STATUS_BUSY) {
121
test_print ("calendar server is busy; waiting...");
123
} else if (status != E_CALENDAR_STATUS_OK) {
124
g_warning ("failed to asynchronously remove the calendar: "
125
"status %d", status);
131
test_print ("successfully asynchronously removed the temporary "
134
(*closure->cb) (closure);
136
g_signal_handlers_disconnect_by_func (cal, open_cb, closure);
141
ecal_test_utils_cal_async_open (ECal *cal,
142
gboolean only_if_exists,
143
GSourceFunc callback,
146
ECalTestClosure *closure;
148
closure = g_new0 (ECalTestClosure, 1);
149
closure->cb = callback;
150
closure->user_data = user_data;
152
g_signal_connect (G_OBJECT (cal), "cal_opened", G_CALLBACK (open_cb), closure);
153
e_cal_open_async (cal, only_if_exists);
157
ecal_test_utils_cal_remove (ECal *cal)
159
GError *error = NULL;
161
if (!e_cal_remove (cal, &error)) {
162
g_warning ("failed to remove calendar; %s\n", error->message);
165
test_print ("successfully removed the temporary calendar\n");
167
g_object_unref (cal);
171
ecal_test_utils_cal_get_alarm_email_address (ECal *cal)
173
GError *error = NULL;
174
gchar *address = NULL;
176
if (!e_cal_get_alarm_email_address (cal, &address, &error)) {
177
g_warning ("failed to get alarm email address; %s\n", error->message);
180
test_print ("successfully got the alarm email address\n");
186
ecal_test_utils_cal_get_cal_address (ECal *cal)
188
GError *error = NULL;
189
gchar *address = NULL;
191
if (!e_cal_get_cal_address (cal, &address, &error)) {
192
g_warning ("failed to get calendar address; %s\n", error->message);
195
test_print ("successfully got the calendar address\n");
201
ecal_test_utils_cal_get_ldap_attribute (ECal *cal)
203
GError *error = NULL;
206
if (!e_cal_get_ldap_attribute (cal, &attr, &error)) {
207
g_warning ("failed to get ldap attribute; %s\n", error->message);
210
test_print ("successfully got the ldap attribute\n");
218
return value ? "true" : "false";
222
ecal_test_utils_cal_get_capabilities (ECal *cal)
224
test_print ("calendar capabilities:\n");
225
test_print (" One alarm only: %s\n"
226
" Organizers must attend meetings: %s\n"
227
" Organizers must accept meetings: %s\n"
228
" Master object for recurrences: %s\n"
229
" Can save schedules: %s\n"
230
" No alarm repeat: %s\n"
231
" No audio alarms: %s\n"
232
" No display alarms: %s\n"
233
" No email alarms: %s\n"
234
" No procedure alarms: %s\n"
235
" No task assignment: %s\n"
236
" No 'this and future': %s\n"
237
" No 'this and prior': %s\n"
238
" No transparency: %s\n"
239
" Organizer not email address: %s\n"
240
" Remove alarms: %s\n"
241
" Create messages: %s\n"
242
" No conv. to assigned task: %s\n"
243
" No conv. to recurring: %s\n"
244
" No general options: %s\n"
245
" Requires send options: %s\n"
246
" Delegate supported: %s\n"
247
" No organizer required: %s\n"
248
" Delegate to many: %s\n"
249
" Has unaccepted meeting: %s\n"
251
b2s (e_cal_get_one_alarm_only (cal)),
252
b2s (e_cal_get_organizer_must_attend (cal)),
253
b2s (e_cal_get_organizer_must_accept (cal)),
254
b2s (e_cal_get_recurrences_no_master (cal)),
255
b2s (e_cal_get_save_schedules (cal)),
256
b2s (e_cal_get_static_capability (cal,
257
CAL_STATIC_CAPABILITY_NO_ALARM_REPEAT)),
258
b2s (e_cal_get_static_capability (cal,
259
CAL_STATIC_CAPABILITY_NO_AUDIO_ALARMS)),
260
b2s (e_cal_get_static_capability (cal,
261
CAL_STATIC_CAPABILITY_NO_DISPLAY_ALARMS)),
262
b2s (e_cal_get_static_capability (cal,
263
CAL_STATIC_CAPABILITY_NO_EMAIL_ALARMS)),
264
b2s (e_cal_get_static_capability (cal,
265
CAL_STATIC_CAPABILITY_NO_PROCEDURE_ALARMS)),
266
b2s (e_cal_get_static_capability (cal,
267
CAL_STATIC_CAPABILITY_NO_TASK_ASSIGNMENT)),
268
b2s (e_cal_get_static_capability (cal,
269
CAL_STATIC_CAPABILITY_NO_THISANDFUTURE)),
270
b2s (e_cal_get_static_capability (cal,
271
CAL_STATIC_CAPABILITY_NO_THISANDPRIOR)),
272
b2s (e_cal_get_static_capability (cal,
273
CAL_STATIC_CAPABILITY_NO_TRANSPARENCY)),
274
b2s (e_cal_get_static_capability (cal,
275
CAL_STATIC_CAPABILITY_ORGANIZER_NOT_EMAIL_ADDRESS)),
276
b2s (e_cal_get_static_capability (cal,
277
CAL_STATIC_CAPABILITY_REMOVE_ALARMS)),
278
b2s (e_cal_get_static_capability (cal,
279
CAL_STATIC_CAPABILITY_CREATE_MESSAGES)),
280
b2s (e_cal_get_static_capability (cal,
281
CAL_STATIC_CAPABILITY_NO_CONV_TO_ASSIGN_TASK)),
282
b2s (e_cal_get_static_capability (cal,
283
CAL_STATIC_CAPABILITY_NO_CONV_TO_RECUR)),
284
b2s (e_cal_get_static_capability (cal,
285
CAL_STATIC_CAPABILITY_NO_GEN_OPTIONS)),
286
b2s (e_cal_get_static_capability (cal,
287
CAL_STATIC_CAPABILITY_REQ_SEND_OPTIONS)),
288
b2s (e_cal_get_static_capability (cal,
289
CAL_STATIC_CAPABILITY_DELEGATE_SUPPORTED)),
290
b2s (e_cal_get_static_capability (cal,
291
CAL_STATIC_CAPABILITY_NO_ORGANIZER)),
292
b2s (e_cal_get_static_capability (cal,
293
CAL_STATIC_CAPABILITY_DELEGATE_TO_MANY)),
294
b2s (e_cal_get_static_capability (cal,
295
CAL_STATIC_CAPABILITY_HAS_UNACCEPTED_MEETING))
300
ecal_test_utils_cal_assert_objects_equal_shallow (icalcomponent *a,
303
const gchar *uid_a, *uid_b;
305
if (!icalcomponent_is_valid (a) && !icalcomponent_is_valid (b)) {
306
g_warning ("both components invalid");
310
if (!icalcomponent_is_valid (a) || !icalcomponent_is_valid (b)) {
311
g_error ("exactly one of the components being compared is invalid");
314
uid_a = icalcomponent_get_uid (a);
315
uid_b = icalcomponent_get_uid (b);
316
if (g_strcmp0 (uid_a, uid_b)) {
317
g_error ("icomponents not equal:\n"
325
ecal_test_utils_cal_assert_e_cal_components_equal (ECalComponent *a,
328
icalcomponent *ical_a, *ical_b;
329
ECalComponentTransparency transp_a, transp_b;
331
ical_a = e_cal_component_get_icalcomponent (a);
332
ical_b = e_cal_component_get_icalcomponent (b);
333
ecal_test_utils_cal_assert_objects_equal_shallow (ical_a, ical_b);
335
/* Dumping icalcomp into a string is not useful as the retrieved object
336
* has some generated information like timestamps. We compare
337
* member values we set during creation*/
338
g_assert (e_cal_component_event_dates_match (a, b));
340
e_cal_component_get_transparency (a, &transp_a);
341
e_cal_component_get_transparency (b, &transp_b);
342
g_assert (transp_a == transp_b);
346
ecal_test_utils_cal_get_object (ECal *cal,
349
GError *error = NULL;
350
icalcomponent *component = NULL;
352
if (!e_cal_get_object (cal, uid, NULL, &component, &error)) {
353
g_warning ("failed to get icalcomponent object '%s'; %s\n", uid, error->message);
356
if (!icalcomponent_is_valid (component)) {
357
g_warning ("retrieved icalcomponent is invalid\n");
360
test_print ("successfully got the icalcomponent object '%s'\n", uid);
366
ecal_test_utils_cal_modify_object (ECal *cal,
367
icalcomponent *component,
368
CalObjModType mod_type)
370
GError *error = NULL;
372
if (!icalcomponent_is_valid (component)) {
373
g_warning (G_STRLOC ": icalcomponent argument is invalid\n");
376
if (!e_cal_modify_object (cal, component, mod_type, &error)) {
377
g_warning ("failed to modify icalcomponent object; %s\n", error->message);
380
test_print ("successfully modified the icalcomponent object\n");
384
ecal_test_utils_cal_remove_object (ECal *cal,
387
GError *error = NULL;
389
if (!e_cal_remove_object (cal, uid, &error)) {
390
g_warning ("failed to remove icalcomponent object '%s'; %s\n", uid, error->message);
393
test_print ("successfully remoed the icalcomponent object '%s'\n", uid);
397
ecal_test_utils_cal_get_default_object (ECal *cal)
399
GError *error = NULL;
400
icalcomponent *component = NULL;
402
if (!e_cal_get_default_object (cal, &component, &error)) {
403
g_warning ("failed to get default icalcomponent object; %s\n", error->message);
406
if (!icalcomponent_is_valid (component)) {
407
g_warning ("default icalcomponent is invalid\n");
410
test_print ("successfully got the default icalcomponent object\n");
416
ecal_test_utils_cal_get_object_list (ECal *cal,
419
GError *error = NULL;
420
GList *objects = NULL;
422
if (!e_cal_get_object_list (cal, query, &objects, &error)) {
423
g_warning ("failed to get list of icalcomponent objects for query '%s'; %s\n", query, error->message);
426
test_print ("successfully got list of icalcomponent objects for the query '%s'\n", query);
432
ecal_test_utils_cal_get_objects_for_uid (ECal *cal,
435
GError *error = NULL;
436
GList *objects = NULL;
438
if (!e_cal_get_objects_for_uid (cal, uid, &objects, &error)) {
439
g_warning ("failed to get icalcomponent objects for UID '%s'; %s\n", uid, error->message);
442
test_print ("successfully got objects for the icalcomponent with UID '%s'\n", uid);
448
ecal_test_utils_cal_create_object (ECal *cal,
449
icalcomponent *component)
451
GError *error = NULL;
453
gchar *ical_string = NULL;
455
if (!icalcomponent_is_valid (component)) {
456
g_warning ("supplied icalcomponent is invalid\n");
460
if (!e_cal_create_object (cal, component, &uid, &error)) {
461
g_warning ("failed to get create an icalcomponent object; %s\n", error->message);
465
ical_string = icalcomponent_as_ical_string (component);
466
test_print ("successfully created icalcomponent object '%s'\n%s\n", uid,
468
g_free (ical_string);
474
cal_set_mode_cb (ECal *cal,
475
ECalendarStatus status,
477
ECalTestClosure *closure)
480
} else if (status == E_CALENDAR_STATUS_BUSY) {
481
test_print ("calendar server is busy; waiting...");
483
} else if (status != E_CALENDAR_STATUS_OK) {
484
g_warning ("failed to asynchronously remove the calendar: "
485
"status %d", status);
489
closure->mode = mode;
491
test_print ("successfully set the calendar mode to %d\n", mode);
493
(*closure->cb) (closure);
495
g_signal_handlers_disconnect_by_func (cal, cal_set_mode_cb, closure);
500
ecal_test_utils_cal_set_mode (ECal *cal,
502
GSourceFunc callback,
505
ECalTestClosure *closure;
507
closure = g_new0 (ECalTestClosure, 1);
508
closure->cb = callback;
509
closure->user_data = user_data;
511
g_signal_connect (G_OBJECT (cal), "cal_set_mode", G_CALLBACK (cal_set_mode_cb), closure);
512
e_cal_set_mode (cal, mode);
516
ecal_test_utils_create_component (ECal *cal,
517
const gchar *dtstart,
518
const gchar *dtstart_tzid,
520
const gchar *dtend_tzid,
521
const gchar *summary,
522
ECalComponent **comp_out,
526
icalcomponent *icalcomp;
527
struct icaltimetype tt;
528
ECalComponentText text;
529
ECalComponentDateTime dt;
532
comp = e_cal_component_new ();
534
e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT);
535
text.value = summary;
537
e_cal_component_set_summary (comp, &text);
538
tt = icaltime_from_string (dtstart);
540
dt.tzid = dtstart_tzid;
541
e_cal_component_set_dtstart (comp, &dt);
542
tt = icaltime_from_string (dtend);
544
dt.tzid = dtend_tzid;
545
e_cal_component_set_dtend (comp, &dt);
546
e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_OPAQUE);
548
e_cal_component_commit_sequence (comp);
549
icalcomp = e_cal_component_get_icalcomponent (comp);
551
uid = ecal_test_utils_cal_create_object (cal, icalcomp);
552
e_cal_component_commit_sequence (comp);
559
ecal_test_utils_cal_component_set_icalcomponent (ECalComponent *e_component,
560
icalcomponent *component)
562
if (!e_cal_component_set_icalcomponent (e_component, component)) {
563
g_error ("Could not set icalcomponent\n");
568
ecal_test_utils_cal_get_timezone (ECal *cal,
571
GError *error = NULL;
572
icaltimezone *zone = NULL;
574
if (!e_cal_get_timezone (cal, tzid, &zone, &error)) {
575
g_warning ("failed to get icaltimezone* for ID '%s'; %s\n", tzid, error->message);
578
test_print ("successfully got icaltimezone* for ID '%s'\n", tzid);
584
ecal_test_utils_cal_add_timezone (ECal *cal,
587
GError *error = NULL;
590
name = icaltimezone_get_display_name (zone);
592
if (!e_cal_add_timezone (cal, zone, &error)) {
593
g_warning ("failed to add icaltimezone '%s'; %s\n", name, error->message);
596
test_print ("successfully added icaltimezone '%s'\n", name);
600
ecal_test_utils_cal_set_default_timezone (ECal *cal,
603
GError *error = NULL;
606
name = icaltimezone_get_display_name (zone);
608
if (!e_cal_set_default_timezone (cal, zone, &error)) {
609
g_warning ("failed to set default icaltimezone '%s'; %s\n", name, error->message);
612
test_print ("successfully set default icaltimezone '%s'\n", name);
616
ecal_test_utils_cal_get_free_busy (ECal *cal,
621
GList *free_busy = NULL;
623
GError *error = NULL;
625
if (!e_cal_get_free_busy (cal, users, start, end, &free_busy, &error)) {
626
g_error ("Test free/busy : Could not retrieve free busy information : %s\n", error->message);
629
test_print ("Printing free/busy information\n");
631
for (l = free_busy; l; l = l->next) {
633
ECalComponent *comp = E_CAL_COMPONENT (l->data);
635
comp_string = e_cal_component_get_as_string (comp);
636
test_print ("%s\n", comp_string);
637
g_object_unref (comp);
638
g_free (comp_string);
641
g_error ("got empty free/busy information");
648
ecal_test_utils_cal_send_objects (ECal *cal,
649
icalcomponent *component,
651
icalcomponent **component_final)
654
GError *error = NULL;
656
if (!e_cal_send_objects (cal, component, users, component_final, &error)) {
657
g_error ("sending objects: %s\n", error->message);
660
test_print ("successfully sent the objects to the following users:\n");
661
if (g_list_length (*users) <= 0) {
662
test_print (" (none)\n");
665
for (l = *users; l; l = l->next) {
666
test_print (" %s\n", (const gchar *) l->data);
671
ecal_test_utils_cal_receive_objects (ECal *cal,
672
icalcomponent *component)
674
GError *error = NULL;
676
if (!e_cal_receive_objects (cal, component, &error)) {
677
g_error ("receiving objects: %s\n", error->message);
680
test_print ("successfully received the objects\n");
684
ecal_test_utils_get_query (ECal *cal,
687
GError *error = NULL;
688
ECalView *query = NULL;
690
if (!e_cal_get_query (cal, sexp, &query, &error)) {
691
g_error (G_STRLOC ": Unable to obtain calendar view: %s\n",
694
test_print ("successfully retrieved calendar view for query '%s'", sexp);