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_temp (gchar **uri,
60 file_template = g_build_filename (g_get_tmp_dir (),
61 "ecal-test-XXXXXX/", NULL);
62 g_mkstemp (file_template);
64 uri_result = g_strconcat ("local:", file_template, NULL);
66 g_error ("failed to convert %s to a 'local:' URI", file_template);
68 g_free (file_template);
70 /* FIXME We don't build ECals from URIs anymore. */
71 /* cal = ecal_test_utils_cal_new_from_uri (uri_result, type); */
75 *uri = g_strdup (uri_result);
83 ecal_test_utils_cal_open (ECal *cal,
84 gboolean only_if_exists)
88 if (!e_cal_open (cal, only_if_exists, &error)) {
92 source = e_cal_get_source (cal);
93 uid = e_source_get_uid (source);
95 g_warning ("failed to open calendar: `%s': %s", uid,
102 open_ex_cb (ECal *cal,
104 ECalTestClosure *closure)
107 } else if (error && error->code == E_CALENDAR_STATUS_BUSY) {
108 test_print ("calendar server is busy; waiting...");
111 g_warning ("failed to asynchronously remove the calendar: "
112 "status %d (%s)", error->code, error->message);
118 test_print ("successfully asynchronously removed the temporary "
121 (*closure->cb) (closure);
123 g_signal_handlers_disconnect_by_func (cal, open_ex_cb, closure);
128 ecal_test_utils_cal_async_open (ECal *cal,
129 gboolean only_if_exists,
130 GSourceFunc callback,
133 ECalTestClosure *closure;
135 closure = g_new0 (ECalTestClosure, 1);
136 closure->cb = callback;
137 closure->user_data = user_data;
139 g_signal_connect (G_OBJECT (cal), "cal_opened_ex", G_CALLBACK (open_ex_cb), closure);
140 e_cal_open_async (cal, only_if_exists);
144 ecal_test_utils_cal_get_alarm_email_address (ECal *cal)
146 GError *error = NULL;
147 gchar *address = NULL;
149 if (!e_cal_get_alarm_email_address (cal, &address, &error)) {
150 g_warning ("failed to get alarm email address; %s\n", error->message);
153 test_print ("successfully got the alarm email address\n");
159 ecal_test_utils_cal_get_cal_address (ECal *cal)
161 GError *error = NULL;
162 gchar *address = NULL;
164 if (!e_cal_get_cal_address (cal, &address, &error)) {
165 g_warning ("failed to get calendar address; %s\n", error->message);
168 test_print ("successfully got the calendar address\n");
174 ecal_test_utils_cal_get_ldap_attribute (ECal *cal)
176 GError *error = NULL;
179 if (!e_cal_get_ldap_attribute (cal, &attr, &error)) {
180 g_warning ("failed to get ldap attribute; %s\n", error->message);
183 test_print ("successfully got the ldap attribute\n");
191 return value ? "true" : "false";
195 ecal_test_utils_cal_get_capabilities (ECal *cal)
197 test_print ("calendar capabilities:\n");
198 test_print (" One alarm only: %s\n"
199 " Organizers must attend meetings: %s\n"
200 " Organizers must accept meetings: %s\n"
201 " Master object for recurrences: %s\n"
202 " Can save schedules: %s\n"
203 " No alarm repeat: %s\n"
204 " No audio alarms: %s\n"
205 " No display alarms: %s\n"
206 " No email alarms: %s\n"
207 " No procedure alarms: %s\n"
208 " No task assignment: %s\n"
209 " No 'this and future': %s\n"
210 " No 'this and prior': %s\n"
211 " No transparency: %s\n"
212 " Organizer not email address: %s\n"
213 " Remove alarms: %s\n"
214 " Create messages: %s\n"
215 " No conv. to assigned task: %s\n"
216 " No conv. to recurring: %s\n"
217 " No general options: %s\n"
218 " Requires send options: %s\n"
219 " Delegate supported: %s\n"
220 " No organizer required: %s\n"
221 " Delegate to many: %s\n"
222 " Has unaccepted meeting: %s\n"
224 b2s (e_cal_get_one_alarm_only (cal)),
225 b2s (e_cal_get_organizer_must_attend (cal)),
226 b2s (e_cal_get_organizer_must_accept (cal)),
227 b2s (e_cal_get_recurrences_no_master (cal)),
228 b2s (e_cal_get_save_schedules (cal)),
229 b2s (e_cal_get_static_capability (cal,
230 CAL_STATIC_CAPABILITY_NO_ALARM_REPEAT)),
231 b2s (e_cal_get_static_capability (cal,
232 CAL_STATIC_CAPABILITY_NO_AUDIO_ALARMS)),
233 b2s (e_cal_get_static_capability (cal,
234 CAL_STATIC_CAPABILITY_NO_DISPLAY_ALARMS)),
235 b2s (e_cal_get_static_capability (cal,
236 CAL_STATIC_CAPABILITY_NO_EMAIL_ALARMS)),
237 b2s (e_cal_get_static_capability (cal,
238 CAL_STATIC_CAPABILITY_NO_PROCEDURE_ALARMS)),
239 b2s (e_cal_get_static_capability (cal,
240 CAL_STATIC_CAPABILITY_NO_TASK_ASSIGNMENT)),
241 b2s (e_cal_get_static_capability (cal,
242 CAL_STATIC_CAPABILITY_NO_THISANDFUTURE)),
243 b2s (e_cal_get_static_capability (cal,
244 CAL_STATIC_CAPABILITY_NO_THISANDPRIOR)),
245 b2s (e_cal_get_static_capability (cal,
246 CAL_STATIC_CAPABILITY_NO_TRANSPARENCY)),
247 b2s (e_cal_get_static_capability (cal,
248 CAL_STATIC_CAPABILITY_ORGANIZER_NOT_EMAIL_ADDRESS)),
249 b2s (e_cal_get_static_capability (cal,
250 CAL_STATIC_CAPABILITY_REMOVE_ALARMS)),
251 b2s (e_cal_get_static_capability (cal,
252 CAL_STATIC_CAPABILITY_CREATE_MESSAGES)),
253 b2s (e_cal_get_static_capability (cal,
254 CAL_STATIC_CAPABILITY_NO_CONV_TO_ASSIGN_TASK)),
255 b2s (e_cal_get_static_capability (cal,
256 CAL_STATIC_CAPABILITY_NO_CONV_TO_RECUR)),
257 b2s (e_cal_get_static_capability (cal,
258 CAL_STATIC_CAPABILITY_NO_GEN_OPTIONS)),
259 b2s (e_cal_get_static_capability (cal,
260 CAL_STATIC_CAPABILITY_REQ_SEND_OPTIONS)),
261 b2s (e_cal_get_static_capability (cal,
262 CAL_STATIC_CAPABILITY_DELEGATE_SUPPORTED)),
263 b2s (e_cal_get_static_capability (cal,
264 CAL_STATIC_CAPABILITY_NO_ORGANIZER)),
265 b2s (e_cal_get_static_capability (cal,
266 CAL_STATIC_CAPABILITY_DELEGATE_TO_MANY)),
267 b2s (e_cal_get_static_capability (cal,
268 CAL_STATIC_CAPABILITY_HAS_UNACCEPTED_MEETING))
273 ecal_test_utils_cal_assert_objects_equal_shallow (icalcomponent *a,
276 const gchar *uid_a, *uid_b;
278 if (!icalcomponent_is_valid (a) && !icalcomponent_is_valid (b)) {
279 g_warning ("both components invalid");
283 if (!icalcomponent_is_valid (a) || !icalcomponent_is_valid (b)) {
284 g_error ("exactly one of the components being compared is invalid");
287 uid_a = icalcomponent_get_uid (a);
288 uid_b = icalcomponent_get_uid (b);
289 if (g_strcmp0 (uid_a, uid_b)) {
290 g_error ("icomponents not equal:\n"
298 ecal_test_utils_cal_assert_e_cal_components_equal (ECalComponent *a,
301 icalcomponent *ical_a, *ical_b;
302 ECalComponentTransparency transp_a, transp_b;
304 ical_a = e_cal_component_get_icalcomponent (a);
305 ical_b = e_cal_component_get_icalcomponent (b);
306 ecal_test_utils_cal_assert_objects_equal_shallow (ical_a, ical_b);
308 /* Dumping icalcomp into a string is not useful as the retrieved object
309 * has some generated information like timestamps. We compare
310 * member values we set during creation*/
311 g_assert (e_cal_component_event_dates_match (a, b));
313 e_cal_component_get_transparency (a, &transp_a);
314 e_cal_component_get_transparency (b, &transp_b);
315 g_assert (transp_a == transp_b);
319 ecal_test_utils_cal_get_object (ECal *cal,
322 GError *error = NULL;
323 icalcomponent *component = NULL;
325 if (!e_cal_get_object (cal, uid, NULL, &component, &error)) {
326 g_warning ("failed to get icalcomponent object '%s'; %s\n", uid, error->message);
329 if (!icalcomponent_is_valid (component)) {
330 g_warning ("retrieved icalcomponent is invalid\n");
333 test_print ("successfully got the icalcomponent object '%s'\n", uid);
339 ecal_test_utils_cal_modify_object (ECal *cal,
340 icalcomponent *component,
341 CalObjModType mod_type)
343 GError *error = NULL;
345 if (!icalcomponent_is_valid (component)) {
346 g_warning (G_STRLOC ": icalcomponent argument is invalid\n");
349 if (!e_cal_modify_object (cal, component, mod_type, &error)) {
350 g_warning ("failed to modify icalcomponent object; %s\n", error->message);
353 test_print ("successfully modified the icalcomponent object\n");
357 ecal_test_utils_cal_remove_object (ECal *cal,
360 GError *error = NULL;
362 if (!e_cal_remove_object (cal, uid, &error)) {
363 g_warning ("failed to remove icalcomponent object '%s'; %s\n", uid, error->message);
366 test_print ("successfully remoed the icalcomponent object '%s'\n", uid);
370 ecal_test_utils_cal_get_default_object (ECal *cal)
372 GError *error = NULL;
373 icalcomponent *component = NULL;
375 if (!e_cal_get_default_object (cal, &component, &error)) {
376 g_warning ("failed to get default icalcomponent object; %s\n", error->message);
379 if (!icalcomponent_is_valid (component)) {
380 g_warning ("default icalcomponent is invalid\n");
383 test_print ("successfully got the default icalcomponent object\n");
389 ecal_test_utils_cal_get_object_list (ECal *cal,
392 GError *error = NULL;
393 GList *objects = NULL;
395 if (!e_cal_get_object_list (cal, query, &objects, &error)) {
396 g_warning ("failed to get list of icalcomponent objects for query '%s'; %s\n", query, error->message);
399 test_print ("successfully got list of icalcomponent objects for the query '%s'\n", query);
405 ecal_test_utils_cal_get_objects_for_uid (ECal *cal,
408 GError *error = NULL;
409 GList *objects = NULL;
411 if (!e_cal_get_objects_for_uid (cal, uid, &objects, &error)) {
412 g_warning ("failed to get icalcomponent objects for UID '%s'; %s\n", uid, error->message);
415 test_print ("successfully got objects for the icalcomponent with UID '%s'\n", uid);
421 ecal_test_utils_cal_create_object (ECal *cal,
422 icalcomponent *component)
424 GError *error = NULL;
426 gchar *ical_string = NULL;
428 if (!icalcomponent_is_valid (component)) {
429 g_warning ("supplied icalcomponent is invalid\n");
433 if (!e_cal_create_object (cal, component, &uid, &error)) {
434 g_warning ("failed to get create an icalcomponent object; %s\n", error->message);
438 ical_string = icalcomponent_as_ical_string (component);
439 test_print ("successfully created icalcomponent object '%s'\n%s\n", uid,
441 g_free (ical_string);
447 cal_set_mode_cb (ECal *cal,
448 ECalendarStatus status,
450 ECalTestClosure *closure)
453 } else if (status == E_CALENDAR_STATUS_BUSY) {
454 test_print ("calendar server is busy; waiting...");
456 } else if (status != E_CALENDAR_STATUS_OK) {
457 g_warning ("failed to asynchronously remove the calendar: "
458 "status %d", status);
462 closure->mode = mode;
464 test_print ("successfully set the calendar mode to %d\n", mode);
466 (*closure->cb) (closure);
468 g_signal_handlers_disconnect_by_func (cal, cal_set_mode_cb, closure);
473 ecal_test_utils_cal_set_mode (ECal *cal,
475 GSourceFunc callback,
478 ECalTestClosure *closure;
480 closure = g_new0 (ECalTestClosure, 1);
481 closure->cb = callback;
482 closure->user_data = user_data;
484 g_signal_connect (G_OBJECT (cal), "cal_set_mode", G_CALLBACK (cal_set_mode_cb), closure);
485 e_cal_set_mode (cal, mode);
489 ecal_test_utils_create_component (ECal *cal,
490 const gchar *dtstart,
491 const gchar *dtstart_tzid,
493 const gchar *dtend_tzid,
494 const gchar *summary,
495 ECalComponent **comp_out,
499 icalcomponent *icalcomp;
500 struct icaltimetype tt;
501 ECalComponentText text;
502 ECalComponentDateTime dt;
505 comp = e_cal_component_new ();
507 e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT);
508 text.value = summary;
510 e_cal_component_set_summary (comp, &text);
511 tt = icaltime_from_string (dtstart);
513 dt.tzid = dtstart_tzid;
514 e_cal_component_set_dtstart (comp, &dt);
515 tt = icaltime_from_string (dtend);
517 dt.tzid = dtend_tzid;
518 e_cal_component_set_dtend (comp, &dt);
519 e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_OPAQUE);
521 e_cal_component_commit_sequence (comp);
522 icalcomp = e_cal_component_get_icalcomponent (comp);
524 uid = ecal_test_utils_cal_create_object (cal, icalcomp);
525 e_cal_component_commit_sequence (comp);
532 ecal_test_utils_cal_component_set_icalcomponent (ECalComponent *e_component,
533 icalcomponent *component)
535 if (!e_cal_component_set_icalcomponent (e_component, component)) {
536 g_error ("Could not set icalcomponent\n");
541 ecal_test_utils_cal_get_timezone (ECal *cal,
544 GError *error = NULL;
545 icaltimezone *zone = NULL;
547 if (!e_cal_get_timezone (cal, tzid, &zone, &error)) {
548 g_warning ("failed to get icaltimezone* for ID '%s'; %s\n", tzid, error->message);
551 test_print ("successfully got icaltimezone* for ID '%s'\n", tzid);
557 ecal_test_utils_cal_add_timezone (ECal *cal,
560 GError *error = NULL;
563 name = icaltimezone_get_display_name (zone);
565 if (!e_cal_add_timezone (cal, zone, &error)) {
566 g_warning ("failed to add icaltimezone '%s'; %s\n", name, error->message);
569 test_print ("successfully added icaltimezone '%s'\n", name);
573 ecal_test_utils_cal_set_default_timezone (ECal *cal,
576 GError *error = NULL;
579 name = icaltimezone_get_display_name (zone);
581 if (!e_cal_set_default_timezone (cal, zone, &error)) {
582 g_warning ("failed to set default icaltimezone '%s'; %s\n", name, error->message);
585 test_print ("successfully set default icaltimezone '%s'\n", name);
589 ecal_test_utils_cal_get_free_busy (ECal *cal,
594 GList *free_busy = NULL;
596 GError *error = NULL;
598 if (!e_cal_get_free_busy (cal, users, start, end, &free_busy, &error)) {
599 g_error ("Test free/busy : Could not retrieve free busy information : %s\n", error->message);
602 test_print ("Printing free/busy information\n");
604 for (l = free_busy; l; l = l->next) {
606 ECalComponent *comp = E_CAL_COMPONENT (l->data);
608 comp_string = e_cal_component_get_as_string (comp);
609 test_print ("%s\n", comp_string);
610 g_free (comp_string);
613 g_error ("got empty free/busy information");
620 ecal_test_utils_cal_send_objects (ECal *cal,
621 icalcomponent *component,
623 icalcomponent **component_final)
626 GError *error = NULL;
628 if (!e_cal_send_objects (cal, component, users, component_final, &error)) {
629 g_error ("sending objects: %s\n", error->message);
632 test_print ("successfully sent the objects to the following users:\n");
633 if (g_list_length (*users) <= 0) {
634 test_print (" (none)\n");
637 for (l = *users; l; l = l->next) {
638 test_print (" %s\n", (const gchar *) l->data);
643 ecal_test_utils_cal_receive_objects (ECal *cal,
644 icalcomponent *component)
646 GError *error = NULL;
648 if (!e_cal_receive_objects (cal, component, &error)) {
649 g_error ("receiving objects: %s\n", error->message);
652 test_print ("successfully received the objects\n");
656 ecal_test_utils_get_query (ECal *cal,
659 GError *error = NULL;
660 ECalView *query = NULL;
662 if (!e_cal_get_query (cal, sexp, &query, &error)) {
663 g_error (G_STRLOC ": Unable to obtain calendar view: %s\n",
666 test_print ("successfully retrieved calendar view for query '%s'", sexp);