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)
24 #include <libecal/e-cal.h>
26 #include "ecal-test-utils.h"
29 test_print (const gchar *format,
33 const gchar *debug_string;
34 static gboolean debug_set = FALSE;
35 static gboolean debug = FALSE;
38 debug_string = g_getenv ("EDS_TEST_DEBUG");
40 debug = (g_ascii_strtoll (debug_string, NULL, 10) >= 1);
46 va_start (args, format);
47 vprintf (format, args);
53 ecal_test_utils_cal_new_from_uri (const gchar *uri,
58 test_print ("loading calendar '%s'\n", uri);
59 cal = e_cal_new_from_uri (uri, type);
61 g_error ("failed to create calendar: `%s'", uri);
67 ecal_test_utils_cal_new_temp (gchar **uri,
74 file_template = g_build_filename (g_get_tmp_dir (),
75 "ecal-test-XXXXXX/", NULL);
76 g_mkstemp (file_template);
78 uri_result = g_strconcat ("local:", file_template, NULL);
80 g_error ("failed to convert %s to a 'local:' URI", file_template);
82 g_free (file_template);
84 cal = ecal_test_utils_cal_new_from_uri (uri_result, type);
87 *uri = g_strdup (uri_result);
95 ecal_test_utils_cal_open (ECal *cal,
96 gboolean only_if_exists)
100 if (!e_cal_open (cal, only_if_exists, &error)) {
103 uri = e_cal_get_uri (cal);
105 g_warning ("failed to open calendar: `%s': %s", uri,
112 open_ex_cb (ECal *cal,
114 ECalTestClosure *closure)
117 } else if (error && error->code == E_CALENDAR_STATUS_BUSY) {
118 test_print ("calendar server is busy; waiting...");
121 g_warning ("failed to asynchronously remove the calendar: "
122 "status %d (%s)", error->code, error->message);
128 test_print ("successfully asynchronously removed the temporary "
131 (*closure->cb) (closure);
133 g_signal_handlers_disconnect_by_func (cal, open_ex_cb, closure);
138 ecal_test_utils_cal_async_open (ECal *cal,
139 gboolean only_if_exists,
140 GSourceFunc callback,
143 ECalTestClosure *closure;
145 closure = g_new0 (ECalTestClosure, 1);
146 closure->cb = callback;
147 closure->user_data = user_data;
149 g_signal_connect (G_OBJECT (cal), "cal_opened_ex", G_CALLBACK (open_ex_cb), closure);
150 e_cal_open_async (cal, only_if_exists);
154 ecal_test_utils_cal_remove (ECal *cal)
156 GError *error = NULL;
158 if (!e_cal_remove (cal, &error)) {
159 g_warning ("failed to remove calendar; %s\n", error->message);
162 test_print ("successfully removed the temporary calendar\n");
164 g_object_unref (cal);
168 ecal_test_utils_cal_get_alarm_email_address (ECal *cal)
170 GError *error = NULL;
171 gchar *address = NULL;
173 if (!e_cal_get_alarm_email_address (cal, &address, &error)) {
174 g_warning ("failed to get alarm email address; %s\n", error->message);
177 test_print ("successfully got the alarm email address\n");
183 ecal_test_utils_cal_get_cal_address (ECal *cal)
185 GError *error = NULL;
186 gchar *address = NULL;
188 if (!e_cal_get_cal_address (cal, &address, &error)) {
189 g_warning ("failed to get calendar address; %s\n", error->message);
192 test_print ("successfully got the calendar address\n");
198 ecal_test_utils_cal_get_ldap_attribute (ECal *cal)
200 GError *error = NULL;
203 if (!e_cal_get_ldap_attribute (cal, &attr, &error)) {
204 g_warning ("failed to get ldap attribute; %s\n", error->message);
207 test_print ("successfully got the ldap attribute\n");
215 return value ? "true" : "false";
219 ecal_test_utils_cal_get_capabilities (ECal *cal)
221 test_print ("calendar capabilities:\n");
222 test_print (" One alarm only: %s\n"
223 " Organizers must attend meetings: %s\n"
224 " Organizers must accept meetings: %s\n"
225 " Master object for recurrences: %s\n"
226 " Can save schedules: %s\n"
227 " No alarm repeat: %s\n"
228 " No audio alarms: %s\n"
229 " No display alarms: %s\n"
230 " No email alarms: %s\n"
231 " No procedure alarms: %s\n"
232 " No task assignment: %s\n"
233 " No 'this and future': %s\n"
234 " No 'this and prior': %s\n"
235 " No transparency: %s\n"
236 " Organizer not email address: %s\n"
237 " Remove alarms: %s\n"
238 " Create messages: %s\n"
239 " No conv. to assigned task: %s\n"
240 " No conv. to recurring: %s\n"
241 " No general options: %s\n"
242 " Requires send options: %s\n"
243 " Delegate supported: %s\n"
244 " No organizer required: %s\n"
245 " Delegate to many: %s\n"
246 " Has unaccepted meeting: %s\n"
248 b2s (e_cal_get_one_alarm_only (cal)),
249 b2s (e_cal_get_organizer_must_attend (cal)),
250 b2s (e_cal_get_organizer_must_accept (cal)),
251 b2s (e_cal_get_recurrences_no_master (cal)),
252 b2s (e_cal_get_save_schedules (cal)),
253 b2s (e_cal_get_static_capability (cal,
254 CAL_STATIC_CAPABILITY_NO_ALARM_REPEAT)),
255 b2s (e_cal_get_static_capability (cal,
256 CAL_STATIC_CAPABILITY_NO_AUDIO_ALARMS)),
257 b2s (e_cal_get_static_capability (cal,
258 CAL_STATIC_CAPABILITY_NO_DISPLAY_ALARMS)),
259 b2s (e_cal_get_static_capability (cal,
260 CAL_STATIC_CAPABILITY_NO_EMAIL_ALARMS)),
261 b2s (e_cal_get_static_capability (cal,
262 CAL_STATIC_CAPABILITY_NO_PROCEDURE_ALARMS)),
263 b2s (e_cal_get_static_capability (cal,
264 CAL_STATIC_CAPABILITY_NO_TASK_ASSIGNMENT)),
265 b2s (e_cal_get_static_capability (cal,
266 CAL_STATIC_CAPABILITY_NO_THISANDFUTURE)),
267 b2s (e_cal_get_static_capability (cal,
268 CAL_STATIC_CAPABILITY_NO_THISANDPRIOR)),
269 b2s (e_cal_get_static_capability (cal,
270 CAL_STATIC_CAPABILITY_NO_TRANSPARENCY)),
271 b2s (e_cal_get_static_capability (cal,
272 CAL_STATIC_CAPABILITY_ORGANIZER_NOT_EMAIL_ADDRESS)),
273 b2s (e_cal_get_static_capability (cal,
274 CAL_STATIC_CAPABILITY_REMOVE_ALARMS)),
275 b2s (e_cal_get_static_capability (cal,
276 CAL_STATIC_CAPABILITY_CREATE_MESSAGES)),
277 b2s (e_cal_get_static_capability (cal,
278 CAL_STATIC_CAPABILITY_NO_CONV_TO_ASSIGN_TASK)),
279 b2s (e_cal_get_static_capability (cal,
280 CAL_STATIC_CAPABILITY_NO_CONV_TO_RECUR)),
281 b2s (e_cal_get_static_capability (cal,
282 CAL_STATIC_CAPABILITY_NO_GEN_OPTIONS)),
283 b2s (e_cal_get_static_capability (cal,
284 CAL_STATIC_CAPABILITY_REQ_SEND_OPTIONS)),
285 b2s (e_cal_get_static_capability (cal,
286 CAL_STATIC_CAPABILITY_DELEGATE_SUPPORTED)),
287 b2s (e_cal_get_static_capability (cal,
288 CAL_STATIC_CAPABILITY_NO_ORGANIZER)),
289 b2s (e_cal_get_static_capability (cal,
290 CAL_STATIC_CAPABILITY_DELEGATE_TO_MANY)),
291 b2s (e_cal_get_static_capability (cal,
292 CAL_STATIC_CAPABILITY_HAS_UNACCEPTED_MEETING))
297 ecal_test_utils_cal_assert_objects_equal_shallow (icalcomponent *a,
300 const gchar *uid_a, *uid_b;
302 if (!icalcomponent_is_valid (a) && !icalcomponent_is_valid (b)) {
303 g_warning ("both components invalid");
307 if (!icalcomponent_is_valid (a) || !icalcomponent_is_valid (b)) {
308 g_error ("exactly one of the components being compared is invalid");
311 uid_a = icalcomponent_get_uid (a);
312 uid_b = icalcomponent_get_uid (b);
313 if (g_strcmp0 (uid_a, uid_b)) {
314 g_error ("icomponents not equal:\n"
322 ecal_test_utils_cal_assert_e_cal_components_equal (ECalComponent *a,
325 icalcomponent *ical_a, *ical_b;
326 ECalComponentTransparency transp_a, transp_b;
328 ical_a = e_cal_component_get_icalcomponent (a);
329 ical_b = e_cal_component_get_icalcomponent (b);
330 ecal_test_utils_cal_assert_objects_equal_shallow (ical_a, ical_b);
332 /* Dumping icalcomp into a string is not useful as the retrieved object
333 * has some generated information like timestamps. We compare
334 * member values we set during creation*/
335 g_assert (e_cal_component_event_dates_match (a, b));
337 e_cal_component_get_transparency (a, &transp_a);
338 e_cal_component_get_transparency (b, &transp_b);
339 g_assert (transp_a == transp_b);
343 ecal_test_utils_cal_get_object (ECal *cal,
346 GError *error = NULL;
347 icalcomponent *component = NULL;
349 if (!e_cal_get_object (cal, uid, NULL, &component, &error)) {
350 g_warning ("failed to get icalcomponent object '%s'; %s\n", uid, error->message);
353 if (!icalcomponent_is_valid (component)) {
354 g_warning ("retrieved icalcomponent is invalid\n");
357 test_print ("successfully got the icalcomponent object '%s'\n", uid);
363 ecal_test_utils_cal_modify_object (ECal *cal,
364 icalcomponent *component,
365 CalObjModType mod_type)
367 GError *error = NULL;
369 if (!icalcomponent_is_valid (component)) {
370 g_warning (G_STRLOC ": icalcomponent argument is invalid\n");
373 if (!e_cal_modify_object (cal, component, mod_type, &error)) {
374 g_warning ("failed to modify icalcomponent object; %s\n", error->message);
377 test_print ("successfully modified the icalcomponent object\n");
381 ecal_test_utils_cal_remove_object (ECal *cal,
384 GError *error = NULL;
386 if (!e_cal_remove_object (cal, uid, &error)) {
387 g_warning ("failed to remove icalcomponent object '%s'; %s\n", uid, error->message);
390 test_print ("successfully remoed the icalcomponent object '%s'\n", uid);
394 ecal_test_utils_cal_get_default_object (ECal *cal)
396 GError *error = NULL;
397 icalcomponent *component = NULL;
399 if (!e_cal_get_default_object (cal, &component, &error)) {
400 g_warning ("failed to get default icalcomponent object; %s\n", error->message);
403 if (!icalcomponent_is_valid (component)) {
404 g_warning ("default icalcomponent is invalid\n");
407 test_print ("successfully got the default icalcomponent object\n");
413 ecal_test_utils_cal_get_object_list (ECal *cal,
416 GError *error = NULL;
417 GList *objects = NULL;
419 if (!e_cal_get_object_list (cal, query, &objects, &error)) {
420 g_warning ("failed to get list of icalcomponent objects for query '%s'; %s\n", query, error->message);
423 test_print ("successfully got list of icalcomponent objects for the query '%s'\n", query);
429 ecal_test_utils_cal_get_objects_for_uid (ECal *cal,
432 GError *error = NULL;
433 GList *objects = NULL;
435 if (!e_cal_get_objects_for_uid (cal, uid, &objects, &error)) {
436 g_warning ("failed to get icalcomponent objects for UID '%s'; %s\n", uid, error->message);
439 test_print ("successfully got objects for the icalcomponent with UID '%s'\n", uid);
445 ecal_test_utils_cal_create_object (ECal *cal,
446 icalcomponent *component)
448 GError *error = NULL;
450 gchar *ical_string = NULL;
452 if (!icalcomponent_is_valid (component)) {
453 g_warning ("supplied icalcomponent is invalid\n");
457 if (!e_cal_create_object (cal, component, &uid, &error)) {
458 g_warning ("failed to get create an icalcomponent object; %s\n", error->message);
462 ical_string = icalcomponent_as_ical_string (component);
463 test_print ("successfully created icalcomponent object '%s'\n%s\n", uid,
465 g_free (ical_string);
471 cal_set_mode_cb (ECal *cal,
472 ECalendarStatus status,
474 ECalTestClosure *closure)
477 } else if (status == E_CALENDAR_STATUS_BUSY) {
478 test_print ("calendar server is busy; waiting...");
480 } else if (status != E_CALENDAR_STATUS_OK) {
481 g_warning ("failed to asynchronously remove the calendar: "
482 "status %d", status);
486 closure->mode = mode;
488 test_print ("successfully set the calendar mode to %d\n", mode);
490 (*closure->cb) (closure);
492 g_signal_handlers_disconnect_by_func (cal, cal_set_mode_cb, closure);
497 ecal_test_utils_cal_set_mode (ECal *cal,
499 GSourceFunc callback,
502 ECalTestClosure *closure;
504 closure = g_new0 (ECalTestClosure, 1);
505 closure->cb = callback;
506 closure->user_data = user_data;
508 g_signal_connect (G_OBJECT (cal), "cal_set_mode", G_CALLBACK (cal_set_mode_cb), closure);
509 e_cal_set_mode (cal, mode);
513 ecal_test_utils_create_component (ECal *cal,
514 const gchar *dtstart,
515 const gchar *dtstart_tzid,
517 const gchar *dtend_tzid,
518 const gchar *summary,
519 ECalComponent **comp_out,
523 icalcomponent *icalcomp;
524 struct icaltimetype tt;
525 ECalComponentText text;
526 ECalComponentDateTime dt;
529 comp = e_cal_component_new ();
531 e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT);
532 text.value = summary;
534 e_cal_component_set_summary (comp, &text);
535 tt = icaltime_from_string (dtstart);
537 dt.tzid = dtstart_tzid;
538 e_cal_component_set_dtstart (comp, &dt);
539 tt = icaltime_from_string (dtend);
541 dt.tzid = dtend_tzid;
542 e_cal_component_set_dtend (comp, &dt);
543 e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_OPAQUE);
545 e_cal_component_commit_sequence (comp);
546 icalcomp = e_cal_component_get_icalcomponent (comp);
548 uid = ecal_test_utils_cal_create_object (cal, icalcomp);
549 e_cal_component_commit_sequence (comp);
556 ecal_test_utils_cal_component_set_icalcomponent (ECalComponent *e_component,
557 icalcomponent *component)
559 if (!e_cal_component_set_icalcomponent (e_component, component)) {
560 g_error ("Could not set icalcomponent\n");
565 ecal_test_utils_cal_get_timezone (ECal *cal,
568 GError *error = NULL;
569 icaltimezone *zone = NULL;
571 if (!e_cal_get_timezone (cal, tzid, &zone, &error)) {
572 g_warning ("failed to get icaltimezone* for ID '%s'; %s\n", tzid, error->message);
575 test_print ("successfully got icaltimezone* for ID '%s'\n", tzid);
581 ecal_test_utils_cal_add_timezone (ECal *cal,
584 GError *error = NULL;
587 name = icaltimezone_get_display_name (zone);
589 if (!e_cal_add_timezone (cal, zone, &error)) {
590 g_warning ("failed to add icaltimezone '%s'; %s\n", name, error->message);
593 test_print ("successfully added icaltimezone '%s'\n", name);
597 ecal_test_utils_cal_set_default_timezone (ECal *cal,
600 GError *error = NULL;
603 name = icaltimezone_get_display_name (zone);
605 if (!e_cal_set_default_timezone (cal, zone, &error)) {
606 g_warning ("failed to set default icaltimezone '%s'; %s\n", name, error->message);
609 test_print ("successfully set default icaltimezone '%s'\n", name);
613 ecal_test_utils_cal_get_free_busy (ECal *cal,
618 GList *free_busy = NULL;
620 GError *error = NULL;
622 if (!e_cal_get_free_busy (cal, users, start, end, &free_busy, &error)) {
623 g_error ("Test free/busy : Could not retrieve free busy information : %s\n", error->message);
626 test_print ("Printing free/busy information\n");
628 for (l = free_busy; l; l = l->next) {
630 ECalComponent *comp = E_CAL_COMPONENT (l->data);
632 comp_string = e_cal_component_get_as_string (comp);
633 test_print ("%s\n", comp_string);
634 g_free (comp_string);
637 g_error ("got empty free/busy information");
644 ecal_test_utils_cal_send_objects (ECal *cal,
645 icalcomponent *component,
647 icalcomponent **component_final)
650 GError *error = NULL;
652 if (!e_cal_send_objects (cal, component, users, component_final, &error)) {
653 g_error ("sending objects: %s\n", error->message);
656 test_print ("successfully sent the objects to the following users:\n");
657 if (g_list_length (*users) <= 0) {
658 test_print (" (none)\n");
661 for (l = *users; l; l = l->next) {
662 test_print (" %s\n", (const gchar *) l->data);
667 ecal_test_utils_cal_receive_objects (ECal *cal,
668 icalcomponent *component)
670 GError *error = NULL;
672 if (!e_cal_receive_objects (cal, component, &error)) {
673 g_error ("receiving objects: %s\n", error->message);
676 test_print ("successfully received the objects\n");
680 ecal_test_utils_get_query (ECal *cal,
683 GError *error = NULL;
684 ECalView *query = NULL;
686 if (!e_cal_get_query (cal, sexp, &query, &error)) {
687 g_error (G_STRLOC ": Unable to obtain calendar view: %s\n",
690 test_print ("successfully retrieved calendar view for query '%s'", sexp);