~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to calendar/tests/ecal/ecal-test-utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/*
 
3
 * Copyright (C) 2009 Intel Corporation
 
4
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
19
 * Author: Travis Reitter (travis.reitter@collabora.co.uk)
 
20
 */
 
21
 
 
22
#include <stdlib.h>
 
23
#include <glib.h>
 
24
#include <gio/gio.h>
 
25
#include <libecal/e-cal.h>
 
26
 
 
27
#include "ecal-test-utils.h"
 
28
 
 
29
void
 
30
test_print (const gchar *format,
 
31
            ...)
 
32
{
 
33
        va_list args;
 
34
        const gchar *debug_string;
 
35
        static gboolean debug_set = FALSE;
 
36
        static gboolean debug = FALSE;
 
37
 
 
38
        if (!debug_set) {
 
39
                debug_string = g_getenv ("EDS_TEST_DEBUG");
 
40
                if (debug_string) {
 
41
                        debug = (g_ascii_strtoll (debug_string, NULL, 10) >= 1);
 
42
                }
 
43
                debug_set = TRUE;
 
44
        }
 
45
 
 
46
        if (debug) {
 
47
                va_start (args, format);
 
48
                vprintf (format, args);
 
49
                va_end (args);
 
50
        }
 
51
}
 
52
 
 
53
ECal*
 
54
ecal_test_utils_cal_new_from_uri (const gchar     *uri,
 
55
                                  ECalSourceType  type)
 
56
{
 
57
        ECal *cal;
 
58
 
 
59
        test_print ("loading calendar '%s'\n", uri);
 
60
        cal = e_cal_new_from_uri (uri, type);
 
61
        if (!cal)
 
62
                g_error ("failed to create calendar: `%s'", uri);
 
63
 
 
64
        return cal;
 
65
}
 
66
 
 
67
ECal*
 
68
ecal_test_utils_cal_new_temp (gchar           **uri,
 
69
                              ECalSourceType   type)
 
70
{
 
71
        ECal *cal;
 
72
        GError *error = NULL;
 
73
        gchar *file_template;
 
74
        gchar *uri_result;
 
75
 
 
76
        file_template = g_build_filename (g_get_tmp_dir (),
 
77
                        "ecal-test-XXXXXX/", NULL);
 
78
        g_mkstemp (file_template);
 
79
 
 
80
        uri_result = g_filename_to_uri (file_template, NULL, &error);
 
81
        if (!uri_result) {
 
82
                g_error ("failed to convert %s to an URI: %s", file_template,
 
83
                                error->message);
 
84
        }
 
85
        g_free (file_template);
 
86
 
 
87
        cal = ecal_test_utils_cal_new_from_uri (uri_result, type);
 
88
 
 
89
        if (uri)
 
90
                *uri = g_strdup (uri_result);
 
91
 
 
92
        g_free (uri_result);
 
93
 
 
94
        return cal;
 
95
}
 
96
 
 
97
void
 
98
ecal_test_utils_cal_open (ECal     *cal,
 
99
                          gboolean  only_if_exists)
 
100
{
 
101
        GError *error = NULL;
 
102
 
 
103
        if (!e_cal_open (cal, only_if_exists, &error)) {
 
104
                const gchar *uri;
 
105
 
 
106
                uri = e_cal_get_uri (cal);
 
107
 
 
108
                g_warning ("failed to open calendar: `%s': %s", uri,
 
109
                                error->message);
 
110
                exit(1);
 
111
        }
 
112
}
 
113
 
 
114
static void
 
115
open_cb (ECal            *cal,
 
116
         ECalendarStatus  status,
 
117
         ECalTestClosure *closure)
 
118
{
 
119
        if (FALSE) {
 
120
        } else if (status == E_CALENDAR_STATUS_BUSY) {
 
121
                test_print ("calendar server is busy; waiting...");
 
122
                return;
 
123
        } else if (status != E_CALENDAR_STATUS_OK) {
 
124
                g_warning ("failed to asynchronously remove the calendar: "
 
125
                                "status %d", status);
 
126
                exit (1);
 
127
        }
 
128
 
 
129
        closure->cal = cal;
 
130
 
 
131
        test_print ("successfully asynchronously removed the temporary "
 
132
                        "calendar\n");
 
133
        if (closure)
 
134
                (*closure->cb) (closure);
 
135
 
 
136
        g_signal_handlers_disconnect_by_func (cal, open_cb, closure);
 
137
        g_free (closure);
 
138
}
 
139
 
 
140
void
 
141
ecal_test_utils_cal_async_open (ECal        *cal,
 
142
                                gboolean     only_if_exists,
 
143
                                GSourceFunc  callback,
 
144
                                gpointer     user_data)
 
145
{
 
146
        ECalTestClosure *closure;
 
147
 
 
148
        closure = g_new0 (ECalTestClosure, 1);
 
149
        closure->cb = callback;
 
150
        closure->user_data = user_data;
 
151
 
 
152
        g_signal_connect (G_OBJECT (cal), "cal_opened", G_CALLBACK (open_cb), closure);
 
153
        e_cal_open_async (cal, only_if_exists);
 
154
}
 
155
 
 
156
void
 
157
ecal_test_utils_cal_remove (ECal *cal)
 
158
{
 
159
        GError *error = NULL;
 
160
 
 
161
        if (!e_cal_remove (cal, &error)) {
 
162
                g_warning ("failed to remove calendar; %s\n", error->message);
 
163
                exit(1);
 
164
        }
 
165
        test_print ("successfully removed the temporary calendar\n");
 
166
 
 
167
        g_object_unref (cal);
 
168
}
 
169
 
 
170
gchar *
 
171
ecal_test_utils_cal_get_alarm_email_address (ECal *cal)
 
172
{
 
173
        GError *error = NULL;
 
174
        gchar *address = NULL;
 
175
 
 
176
        if (!e_cal_get_alarm_email_address (cal, &address, &error)) {
 
177
                g_warning ("failed to get alarm email address; %s\n", error->message);
 
178
                exit(1);
 
179
        }
 
180
        test_print ("successfully got the alarm email address\n");
 
181
 
 
182
        return address;
 
183
}
 
184
 
 
185
gchar *
 
186
ecal_test_utils_cal_get_cal_address (ECal *cal)
 
187
{
 
188
        GError *error = NULL;
 
189
        gchar *address = NULL;
 
190
 
 
191
        if (!e_cal_get_cal_address (cal, &address, &error)) {
 
192
                g_warning ("failed to get calendar address; %s\n", error->message);
 
193
                exit(1);
 
194
        }
 
195
        test_print ("successfully got the calendar address\n");
 
196
 
 
197
        return address;
 
198
}
 
199
 
 
200
gchar *
 
201
ecal_test_utils_cal_get_ldap_attribute (ECal *cal)
 
202
{
 
203
        GError *error = NULL;
 
204
        gchar *attr = NULL;
 
205
 
 
206
        if (!e_cal_get_ldap_attribute (cal, &attr, &error)) {
 
207
                g_warning ("failed to get ldap attribute; %s\n", error->message);
 
208
                exit(1);
 
209
        }
 
210
        test_print ("successfully got the ldap attribute\n");
 
211
 
 
212
        return attr;
 
213
}
 
214
 
 
215
static const gchar *
 
216
b2s (gboolean value)
 
217
{
 
218
        return value ? "true" : "false";
 
219
}
 
220
 
 
221
void
 
222
ecal_test_utils_cal_get_capabilities (ECal *cal)
 
223
{
 
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"
 
250
                 ,
 
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))
 
296
                 );
 
297
}
 
298
 
 
299
void
 
300
ecal_test_utils_cal_assert_objects_equal_shallow (icalcomponent *a,
 
301
                                                  icalcomponent *b)
 
302
{
 
303
        const gchar *uid_a, *uid_b;
 
304
 
 
305
        if (!icalcomponent_is_valid (a) && !icalcomponent_is_valid (b)) {
 
306
                g_warning ("both components invalid");
 
307
                return;
 
308
        }
 
309
 
 
310
        if (!icalcomponent_is_valid (a) || !icalcomponent_is_valid (b)) {
 
311
                g_error ("exactly one of the components being compared is invalid");
 
312
        }
 
313
 
 
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"
 
318
                         "        uid A: '%s'\n"
 
319
                         "        uid b: '%s'\n",
 
320
                         uid_a, uid_b);
 
321
        }
 
322
}
 
323
 
 
324
void
 
325
ecal_test_utils_cal_assert_e_cal_components_equal (ECalComponent *a,
 
326
                                                   ECalComponent *b)
 
327
{
 
328
        icalcomponent *ical_a, *ical_b;
 
329
        ECalComponentTransparency transp_a, transp_b;
 
330
 
 
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);
 
334
 
 
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));
 
339
 
 
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);
 
343
}
 
344
 
 
345
icalcomponent*
 
346
ecal_test_utils_cal_get_object (ECal       *cal,
 
347
                                const gchar *uid)
 
348
{
 
349
        GError *error = NULL;
 
350
        icalcomponent *component = NULL;
 
351
 
 
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);
 
354
                exit(1);
 
355
        }
 
356
        if (!icalcomponent_is_valid (component)) {
 
357
                g_warning ("retrieved icalcomponent is invalid\n");
 
358
                exit(1);
 
359
        }
 
360
        test_print ("successfully got the icalcomponent object '%s'\n", uid);
 
361
 
 
362
        return component;
 
363
}
 
364
 
 
365
void
 
366
ecal_test_utils_cal_modify_object (ECal          *cal,
 
367
                                   icalcomponent *component,
 
368
                                   CalObjModType  mod_type)
 
369
{
 
370
        GError *error = NULL;
 
371
 
 
372
        if (!icalcomponent_is_valid (component)) {
 
373
                g_warning (G_STRLOC ": icalcomponent argument is invalid\n");
 
374
                exit(1);
 
375
        }
 
376
        if (!e_cal_modify_object (cal, component, mod_type, &error)) {
 
377
                g_warning ("failed to modify icalcomponent object; %s\n", error->message);
 
378
                exit(1);
 
379
        }
 
380
        test_print ("successfully modified the icalcomponent object\n");
 
381
}
 
382
 
 
383
void
 
384
ecal_test_utils_cal_remove_object (ECal       *cal,
 
385
                                   const gchar *uid)
 
386
{
 
387
        GError *error = NULL;
 
388
 
 
389
        if (!e_cal_remove_object (cal, uid, &error)) {
 
390
                g_warning ("failed to remove icalcomponent object '%s'; %s\n", uid, error->message);
 
391
                exit(1);
 
392
        }
 
393
        test_print ("successfully remoed the icalcomponent object '%s'\n", uid);
 
394
}
 
395
 
 
396
icalcomponent*
 
397
ecal_test_utils_cal_get_default_object (ECal *cal)
 
398
{
 
399
        GError *error = NULL;
 
400
        icalcomponent *component = NULL;
 
401
 
 
402
        if (!e_cal_get_default_object (cal, &component, &error)) {
 
403
                g_warning ("failed to get default icalcomponent object; %s\n", error->message);
 
404
                exit(1);
 
405
        }
 
406
        if (!icalcomponent_is_valid (component)) {
 
407
                g_warning ("default icalcomponent is invalid\n");
 
408
                exit(1);
 
409
        }
 
410
        test_print ("successfully got the default icalcomponent object\n");
 
411
 
 
412
        return component;
 
413
}
 
414
 
 
415
GList*
 
416
ecal_test_utils_cal_get_object_list (ECal       *cal,
 
417
                                     const gchar *query)
 
418
{
 
419
        GError *error = NULL;
 
420
        GList *objects = NULL;
 
421
 
 
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);
 
424
                exit(1);
 
425
        }
 
426
        test_print ("successfully got list of icalcomponent objects for the query '%s'\n", query);
 
427
 
 
428
        return objects;
 
429
}
 
430
 
 
431
GList*
 
432
ecal_test_utils_cal_get_objects_for_uid (ECal       *cal,
 
433
                                         const gchar *uid)
 
434
{
 
435
        GError *error = NULL;
 
436
        GList *objects = NULL;
 
437
 
 
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);
 
440
                exit(1);
 
441
        }
 
442
        test_print ("successfully got objects for the icalcomponent with UID '%s'\n", uid);
 
443
 
 
444
        return objects;
 
445
}
 
446
 
 
447
gchar *
 
448
ecal_test_utils_cal_create_object (ECal          *cal,
 
449
                                   icalcomponent *component)
 
450
{
 
451
        GError *error = NULL;
 
452
        gchar *uid = NULL;
 
453
        gchar *ical_string = NULL;
 
454
 
 
455
        if (!icalcomponent_is_valid (component)) {
 
456
                g_warning ("supplied icalcomponent is invalid\n");
 
457
                exit(1);
 
458
        }
 
459
 
 
460
        if (!e_cal_create_object (cal, component, &uid, &error)) {
 
461
                g_warning ("failed to get create an icalcomponent object; %s\n", error->message);
 
462
                exit(1);
 
463
        }
 
464
 
 
465
        ical_string = icalcomponent_as_ical_string (component);
 
466
        test_print ("successfully created icalcomponent object '%s'\n%s\n", uid,
 
467
                        ical_string);
 
468
        g_free (ical_string);
 
469
 
 
470
        return uid;
 
471
}
 
472
 
 
473
static void
 
474
cal_set_mode_cb (ECal            *cal,
 
475
                 ECalendarStatus  status,
 
476
                 CalMode          mode,
 
477
                 ECalTestClosure *closure)
 
478
{
 
479
        if (FALSE) {
 
480
        } else if (status == E_CALENDAR_STATUS_BUSY) {
 
481
                test_print ("calendar server is busy; waiting...");
 
482
                return;
 
483
        } else if (status != E_CALENDAR_STATUS_OK) {
 
484
                g_warning ("failed to asynchronously remove the calendar: "
 
485
                                "status %d", status);
 
486
                exit (1);
 
487
        }
 
488
 
 
489
        closure->mode = mode;
 
490
 
 
491
        test_print ("successfully set the calendar mode to %d\n", mode);
 
492
        if (closure)
 
493
                (*closure->cb) (closure);
 
494
 
 
495
        g_signal_handlers_disconnect_by_func (cal, cal_set_mode_cb, closure);
 
496
        g_free (closure);
 
497
}
 
498
 
 
499
void
 
500
ecal_test_utils_cal_set_mode (ECal        *cal,
 
501
                              CalMode      mode,
 
502
                              GSourceFunc  callback,
 
503
                              gpointer     user_data)
 
504
{
 
505
        ECalTestClosure *closure;
 
506
 
 
507
        closure = g_new0 (ECalTestClosure, 1);
 
508
        closure->cb = callback;
 
509
        closure->user_data = user_data;
 
510
 
 
511
        g_signal_connect (G_OBJECT (cal), "cal_set_mode", G_CALLBACK (cal_set_mode_cb), closure);
 
512
        e_cal_set_mode (cal, mode);
 
513
}
 
514
 
 
515
void
 
516
ecal_test_utils_create_component (ECal           *cal,
 
517
                                  const gchar     *dtstart,
 
518
                                  const gchar     *dtstart_tzid,
 
519
                                  const gchar     *dtend,
 
520
                                  const gchar     *dtend_tzid,
 
521
                                  const gchar     *summary,
 
522
                                  ECalComponent **comp_out,
 
523
                                  gchar          **uid_out)
 
524
{
 
525
        ECalComponent *comp;
 
526
        icalcomponent *icalcomp;
 
527
        struct icaltimetype tt;
 
528
        ECalComponentText text;
 
529
        ECalComponentDateTime dt;
 
530
        gchar *uid;
 
531
 
 
532
        comp = e_cal_component_new ();
 
533
        /* set fields */
 
534
        e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT);
 
535
        text.value = summary;
 
536
        text.altrep = NULL;
 
537
        e_cal_component_set_summary (comp, &text);
 
538
        tt = icaltime_from_string (dtstart);
 
539
        dt.value = &tt;
 
540
        dt.tzid = dtstart_tzid;
 
541
        e_cal_component_set_dtstart (comp, &dt);
 
542
        tt = icaltime_from_string (dtend);
 
543
        dt.value = &tt;
 
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);
 
547
 
 
548
        e_cal_component_commit_sequence (comp);
 
549
        icalcomp = e_cal_component_get_icalcomponent (comp);
 
550
 
 
551
        uid = ecal_test_utils_cal_create_object (cal, icalcomp);
 
552
        e_cal_component_commit_sequence (comp);
 
553
 
 
554
        *comp_out = comp;
 
555
        *uid_out = uid;
 
556
}
 
557
 
 
558
void
 
559
ecal_test_utils_cal_component_set_icalcomponent (ECalComponent *e_component,
 
560
                                                 icalcomponent *component)
 
561
{
 
562
        if (!e_cal_component_set_icalcomponent (e_component, component)) {
 
563
                g_error ("Could not set icalcomponent\n");
 
564
        }
 
565
}
 
566
 
 
567
icaltimezone*
 
568
ecal_test_utils_cal_get_timezone (ECal       *cal,
 
569
                                  const gchar *tzid)
 
570
{
 
571
        GError *error = NULL;
 
572
        icaltimezone *zone = NULL;
 
573
 
 
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);
 
576
                exit(1);
 
577
        }
 
578
        test_print ("successfully got icaltimezone* for ID '%s'\n", tzid);
 
579
 
 
580
        return zone;
 
581
}
 
582
 
 
583
void
 
584
ecal_test_utils_cal_add_timezone (ECal         *cal,
 
585
                                  icaltimezone *zone)
 
586
{
 
587
        GError *error = NULL;
 
588
        const gchar *name;
 
589
 
 
590
        name = icaltimezone_get_display_name (zone);
 
591
 
 
592
        if (!e_cal_add_timezone (cal, zone, &error)) {
 
593
                g_warning ("failed to add icaltimezone '%s'; %s\n", name, error->message);
 
594
                exit(1);
 
595
        }
 
596
        test_print ("successfully added icaltimezone '%s'\n", name);
 
597
}
 
598
 
 
599
void
 
600
ecal_test_utils_cal_set_default_timezone (ECal         *cal,
 
601
                                          icaltimezone *zone)
 
602
{
 
603
        GError *error = NULL;
 
604
        const gchar *name;
 
605
 
 
606
        name = icaltimezone_get_display_name (zone);
 
607
 
 
608
        if (!e_cal_set_default_timezone (cal, zone, &error)) {
 
609
                g_warning ("failed to set default icaltimezone '%s'; %s\n", name, error->message);
 
610
                exit(1);
 
611
        }
 
612
        test_print ("successfully set default icaltimezone '%s'\n", name);
 
613
}
 
614
 
 
615
GList*
 
616
ecal_test_utils_cal_get_free_busy (ECal   *cal,
 
617
                                   GList  *users,
 
618
                                   time_t  start,
 
619
                                   time_t  end)
 
620
{
 
621
        GList *free_busy = NULL;
 
622
        GList *l = NULL;
 
623
        GError *error = NULL;
 
624
 
 
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);
 
627
        }
 
628
        if (free_busy) {
 
629
                test_print ("Printing free/busy information\n");
 
630
 
 
631
                for (l = free_busy; l; l = l->next) {
 
632
                        gchar *comp_string;
 
633
                        ECalComponent *comp = E_CAL_COMPONENT (l->data);
 
634
 
 
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);
 
639
                }
 
640
        } else {
 
641
                g_error ("got empty free/busy information");
 
642
        }
 
643
 
 
644
        return free_busy;
 
645
}
 
646
 
 
647
void
 
648
ecal_test_utils_cal_send_objects (ECal           *cal,
 
649
                                  icalcomponent  *component,
 
650
                                  GList         **users,
 
651
                                  icalcomponent **component_final)
 
652
{
 
653
        GList *l = NULL;
 
654
        GError *error = NULL;
 
655
 
 
656
        if (!e_cal_send_objects (cal, component, users, component_final, &error)) {
 
657
                g_error ("sending objects: %s\n", error->message);
 
658
        }
 
659
 
 
660
        test_print ("successfully sent the objects to the following users:\n");
 
661
        if (g_list_length (*users) <= 0) {
 
662
                test_print ("        (none)\n");
 
663
                return;
 
664
        }
 
665
        for (l = *users; l; l = l->next) {
 
666
                test_print ("        %s\n", (const gchar *) l->data);
 
667
        }
 
668
}
 
669
 
 
670
void
 
671
ecal_test_utils_cal_receive_objects (ECal          *cal,
 
672
                                     icalcomponent *component)
 
673
{
 
674
        GError *error = NULL;
 
675
 
 
676
        if (!e_cal_receive_objects (cal, component, &error)) {
 
677
                g_error ("receiving objects: %s\n", error->message);
 
678
        }
 
679
 
 
680
        test_print ("successfully received the objects\n");
 
681
}
 
682
 
 
683
ECalView*
 
684
ecal_test_utils_get_query (ECal       *cal,
 
685
                           const gchar *sexp)
 
686
{
 
687
        GError *error = NULL;
 
688
        ECalView *query = NULL;
 
689
 
 
690
        if (!e_cal_get_query (cal, sexp, &query, &error)) {
 
691
                g_error (G_STRLOC ": Unable to obtain calendar view: %s\n",
 
692
                                error->message);
 
693
        }
 
694
        test_print ("successfully retrieved calendar view for query '%s'", sexp);
 
695
 
 
696
        return query;
 
697
}