423ceb6a8a21ea64744f70e7bad184dad2e680fb
[platform/upstream/evolution-data-server.git] / tests / libecal / test-ecal.c
1 /* Evolution calendar client - test program
2  *
3  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
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
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include <stdlib.h>
24 #include <string.h>
25 #include <glib/gi18n.h>
26 #include <libecal/e-cal.h>
27 #include <libecal/e-cal-component.h>
28 #include <libecal/e-cal-time-util.h>
29 #include <libedataserver/e-data-server-util.h>
30 #include <libical/ical.h>
31
32 /* start_testing_scaffold */
33 #define mu_assert(message, test) do { if (!(test)) return message; else { tests_passed++; return NULL;}} while (0)
34 #define mu_run_test(test) do { const gchar *message = test; tests_run++; \
35                                 if (message) { cl_printf (client, "***Error***\n%s\n", message); break;} } while (0)
36
37 static gint tests_run = 0;
38 static gint tests_passed = 0;
39 /* end_testing_scaffold */
40
41 static ECal *client1;
42 static ECal *client2;
43
44 static GMainLoop *loop;
45
46 /* Prints a message with a client identifier */
47 static void
48 cl_printf (ECal *client,
49            const gchar *format,
50            ...)
51 {
52         va_list args;
53
54         if (client != client1)
55                 return;
56
57         va_start (args, format);
58         printf ("Client %s: ", "Test");
59         vprintf (format, args);
60         va_end (args);
61 }
62
63 static void
64 objects_added_cb (GObject *object,
65                   GList *objects,
66                   gpointer data)
67 {
68         GList *l;
69
70         for (l = objects; l; l = l->next)
71                 cl_printf (data, "Object added %s\n", icalcomponent_get_uid (l->data));
72 }
73
74 static void
75 objects_modified_cb (GObject *object,
76                      GList *objects,
77                      gpointer data)
78 {
79         GList *l;
80
81         for (l = objects; l; l = l->next)
82                 cl_printf (data, "Object modified %s\n", icalcomponent_get_uid (l->data));
83 }
84
85 static void
86 objects_removed_cb (GObject *object,
87                     GList *objects,
88                     gpointer data)
89 {
90         GList *l;
91
92         for (l = objects; l; l = l->next)
93                 cl_printf (data, "Object removed %s\n", icalcomponent_get_uid (l->data));
94 }
95
96 static void
97 view_complete_cb (GObject *object,
98                   ECalendarStatus status,
99                   const gchar *error_msg,
100                   gpointer data)
101 {
102         cl_printf (data, "View complete (status:%d, error_msg:%s)\n", status, error_msg ? error_msg : "NULL");
103 }
104
105 static gboolean
106 list_uids (ECal *client)
107 {
108         GList *objects = NULL;
109         GList *l;
110
111         if (!e_cal_get_object_list (client, "(contains? \"any\" \"test\")", &objects, NULL))
112                 return FALSE;
113
114         cl_printf (client, "UIDS: ");
115
116         cl_printf (client, "\nGot %d objects\n", g_list_length (objects));
117         if (!objects)
118                 printf ("none\n");
119         else {
120                 for (l = objects; l; l = l->next) {
121                         const gchar *uid;
122
123                         uid = icalcomponent_get_uid (l->data);
124                         printf ("`%s' ", uid);
125                 }
126
127                 printf ("\n");
128
129                 for (l = objects; l; l = l->next) {
130                         gchar *obj = icalcomponent_as_ical_string_r (l->data);
131                         printf ("------------------------------\n");
132                         printf ("%s", obj);
133                         printf ("------------------------------\n");
134                         free (obj);
135                 }
136         }
137
138         e_cal_free_object_list (objects);
139
140         return FALSE;
141 }
142
143 /* Callback used when a client is destroyed */
144 static void
145 client_destroy_cb (gpointer data,
146                    GObject *object)
147 {
148         if (E_CAL (object) == client1)
149                 client1 = NULL;
150         else if (E_CAL (object) == client2)
151                 client2 = NULL;
152
153         if (!client1 && !client2)
154                 g_main_loop_quit (loop);
155 }
156
157 static const gchar *
158 test_object_creation (ECal *client,
159                       gchar **uid)
160 {
161         ECalComponent *comp, *comp_retrieved;
162         icalcomponent *icalcomp, *icalcomp_retrieved;
163         struct icaltimetype tt;
164         ECalComponentText text;
165         ECalComponentDateTime dt;
166         ECalComponentTransparency transp;
167         gboolean compare;
168         GError *error = NULL;
169
170         comp = e_cal_component_new ();
171         /* set fields */
172         e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT);
173         text.value = "Creation of new test event";
174         text.altrep = NULL;
175         e_cal_component_set_summary (comp, &text);
176         tt = icaltime_from_string ("20040109T090000Z");
177         dt.value = &tt;
178         dt.tzid ="UTC";
179         e_cal_component_set_dtstart (comp, &dt);
180         tt = icaltime_from_string ("20040109T103000");
181         dt.value = &tt;
182         dt.tzid ="UTC";
183         e_cal_component_set_dtend (comp, &dt);
184         e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_OPAQUE);
185
186         e_cal_component_commit_sequence (comp);
187         icalcomp = e_cal_component_get_icalcomponent (comp);
188         if (!e_cal_create_object (client, icalcomp, uid, &error)) {
189                 cl_printf (client, "Object creation:  %s\n", error->message);
190                 g_free (comp);
191                 g_free (icalcomp);
192                 return "Test Object Creation failed";
193         }
194         e_cal_component_commit_sequence (comp);
195         if (!e_cal_get_object (client, *uid, NULL, &icalcomp_retrieved, &error)) {
196                 cl_printf (client, "Object retrieval:  %s\n", error->message);
197                 g_free (uid);
198                 g_free (comp);
199                 g_free (icalcomp);
200                 return "Test Object Creation failed";
201
202         }
203
204         comp_retrieved = e_cal_component_new ();
205         if (!e_cal_component_set_icalcomponent (comp_retrieved, icalcomp_retrieved)) {
206                 cl_printf (client, "Could not set icalcomponent\n");
207                 g_free (uid);
208                 g_free (comp);
209                 g_free (icalcomp);
210                 g_free (icalcomp_retrieved);
211                 return "Test Object Creation failed";
212
213         }
214         /* Dumping icalcomp into a string is not useful as the retrieved object
215          * has some generated information like timestamps. We compare
216          * member values we set during creation*/
217         compare = e_cal_component_event_dates_match (comp, comp_retrieved);
218
219         if (compare) {
220                 e_cal_component_get_transparency (comp_retrieved, &transp);
221                 compare = (transp == E_CAL_COMPONENT_TRANSP_OPAQUE);
222         }
223
224         g_free (comp_retrieved);
225         g_free (comp);
226         g_free (icalcomp);
227         g_free (icalcomp_retrieved);
228
229         mu_assert ("Test Object creation : Created object does not match retrieved data\n", compare);
230         return NULL;
231 }
232
233 static const gchar *
234 test_object_modification (ECal *client,
235                           gchar *uid)
236 {
237         const gchar *summary = "This summary was modified";
238         icalcomponent *icalcomp, *icalcomp_modified;
239         gboolean compare;
240         GError *error = NULL;
241
242         if (!e_cal_get_object (client, uid, NULL, &icalcomp, &error)) {
243                 cl_printf (client, "Test Modify object : Could not get the object: %s\n", error->message);
244                 g_free (uid);
245                 return error->message;
246         }
247
248         /* Modify one property of the icalcomp and save it.
249          * Now retrieve it and check the field. */
250         icalcomponent_set_summary (icalcomp, summary);
251         if (!e_cal_modify_object  (client, icalcomp, CALOBJ_MOD_THIS, &error)) {
252                 cl_printf (client, "Test Modify object : Could not modify the object: %s\n", error->message);
253                 g_free (uid);
254                 g_free (icalcomp);
255                 return error->message;
256         }
257
258         if (!e_cal_get_object (client, uid, NULL, &icalcomp_modified, &error)) {
259                 cl_printf (client, "Test Modify object : Could not get the modified object: %s\n", error->message);
260                 g_free (uid);
261                 g_free (icalcomp);
262                 return "Test Object Creation failed";
263         }
264
265         compare = !strcmp ( icalcomponent_get_summary (icalcomp_modified), summary);
266
267         g_free (uid);
268         g_free (icalcomp);
269         g_free (icalcomp_modified);
270
271         mu_assert ("Test Modify object : Modification failed\n", compare);
272         return NULL;
273 }
274
275 #if 0
276 static gchar *
277 test_object_removal (ECal *client)
278 {
279
280         gchar *uid;
281         ECalComponent *comp;
282         icalcomponent *icalcomp;
283         gboolean compare = 1;
284         GError *error = NULL;
285
286         comp = e_cal_component_new ();
287         e_cal_component_commit_sequence (comp);
288         icalcomp = e_cal_component_get_icalcomponent (comp);
289         if (!e_cal_create_object (client, icalcomp, &uid, &error)) {
290                 cl_printf (client, "Test object removal - Object creation:  %s\n", error->message);
291                 g_object_unref (comp);
292                 g_object_unref (icalcomp);
293                 return "Test Object Removal failed\n";
294         }
295
296         if (!e_cal_remove_object (client, uid, &error)) {
297                 cl_printf (client, "Test object removal - Could not remove the object\n");
298                 g_free (uid);
299                 g_object_unref (comp);
300                 g_object_unref (icalcomp);
301                 return "Test Object Removal failed\n";
302
303         }
304
305         compare =  e_cal_get_object (client, uid, NULL, &icalcomp, &error);
306
307         g_free (uid);
308         g_object_unref (comp);
309         g_object_unref (icalcomp);
310
311         mu_assert ("Test object removal - Failed\n", compare);
312         return NULL;
313 }
314 #endif
315
316 static const gchar *
317 test_get_alarms_in_range (ECal *client)
318 {
319         GSList *alarms;
320         icaltimezone *utc;
321         time_t start, end;
322         gboolean compare;
323
324         utc = icaltimezone_get_utc_timezone ();
325         start = time_from_isodate ("20040212T000000Z");
326         end = time_add_day_with_zone (start, 2, utc);
327
328         alarms = e_cal_get_alarms_in_range (client, start, end);
329         compare = (g_slist_length (alarms) == 3);
330
331         e_cal_free_alarms (alarms);
332         mu_assert ("Test getting alarms in range\n", compare);
333
334         return NULL;
335 }
336
337 static const gchar *
338 test_set_uri (ECal *client,
339               const gchar *uri)
340 {
341         /* The uri is set as part of create_client call. This method merely
342          * verifies it was done correctly.
343          */
344         gchar *cal_uri;
345         gboolean compare = 0;
346         cal_uri = g_strconcat ("file://", uri, NULL);
347         compare = !strcmp (e_cal_get_uri (client), cal_uri);
348
349         g_free (cal_uri);
350         mu_assert ("Test set_uri : uri was not set correctly\n", compare);
351
352         return NULL;
353 }
354
355 static const gchar *
356 test_cal_loaded (ECal *client)
357 {
358         /* Test one loaded calendar and another that is not loaded. */
359         mu_assert ("Test get_cal_load_state : Failed \n",
360                         (E_CAL_LOAD_LOADED == e_cal_get_load_state (client)) &&
361                         (E_CAL_LOAD_NOT_LOADED == e_cal_get_load_state (NULL)));
362
363         return NULL;
364 }
365
366 static const gchar *
367 test_get_source (ECal *client,
368                  const gchar *expected)
369 {
370         ESource *source;
371         gchar *uri;
372         gchar *cal_uri;
373         gboolean compare = 0;
374
375         source = e_cal_get_source (client);
376         uri = e_source_get_uri (source);
377         cal_uri = g_strconcat ("file://", expected, NULL);
378         compare = !strcmp (expected, uri);
379
380         g_free (cal_uri);
381         mu_assert ("Test get_source : Failed\n", compare);
382
383         return NULL;
384 }
385
386 static const gchar *
387 test_query (ECal *client,
388             const gchar *query,
389             gint expected)
390 {
391         /* This uses pre-loaded data. Hence its results are valid only
392          * when called before any write operation is performed.
393          */
394         gint i = 0;
395         GList *objects = NULL;
396
397         if (!e_cal_get_object_list (client, query, &objects, NULL))
398                 return "Could not get the list of objects";
399         i = g_list_length (objects);
400         e_cal_free_object_list (objects);
401
402         mu_assert ("Test get_object_list : Expected number of objects not found", i == expected);
403
404         return NULL;
405 }
406
407 #if 0
408 static gchar *
409 test_e_cal_new (ECal **cal,
410                 const gchar *uri)
411 {
412         GError *error = NULL;
413         gchar *cal_uri, *cal_file;
414         gboolean created = 0;
415
416         cal_uri = g_strconcat ("file://", uri, NULL);
417         *cal = e_cal_new_from_uri (cal_uri, E_CAL_SOURCE_TYPE_EVENT);
418         if (!*cal) {
419                 g_message (G_STRLOC ": could not create the client");
420                 g_free (cal_uri);
421                 return "Test Creation of new calendar : Failed";
422         }
423         g_object_weak_ref (G_OBJECT (*cal), client_destroy_cb, NULL);
424
425         cl_printf (*cal, "Calendar loading `%s'...\n", uri);
426
427         if (!e_cal_open (*cal, FALSE, &error)) {
428                 cl_printf (*cal, "Load/create %s\n", error->message);
429                 g_free (cal_uri);
430                 return "Test creation of new calendar : Failed";
431         }
432
433         cal_file = g_strconcat (uri, "/calendar.ics", NULL);
434
435         created = g_file_test (cal_file, G_FILE_TEST_EXISTS);
436         g_free (cal_uri);
437         g_free (cal_file);
438
439         mu_assert ("Test creation of new calendar : Failed", created);
440
441         return NULL;
442 }
443
444 static gchar *
445 test_e_cal_remove (ECal *ecal,
446                    const gchar *uri)
447 {
448         gchar *cal_uri;
449         GError *error = NULL;
450         gboolean removed = 0;
451
452         cal_uri = g_strconcat (uri, "/calendar.ics", NULL);
453         if (!e_cal_remove (ecal, &error)) {
454                 cl_printf (ecal, "Test Calendar removal : Could not remove the Calendar : %s\n", error->message);
455         }
456
457         removed = !g_file_test (uri, G_FILE_TEST_EXISTS);
458         g_free (cal_uri);
459
460         mu_assert ("Test Remove calendar : Failed ", removed);
461
462         return NULL;
463 }
464 #endif
465
466 static const gchar *
467 test_new_system_calendar (void)
468 {
469         const gchar *user_data_dir;
470         gchar *filename;
471         gboolean created;
472
473         e_cal_new_system_calendar ();
474
475         user_data_dir = e_get_user_data_dir ();
476         filename = g_build_filename (
477                 user_data_dir, "calendar", "system", "calendar.ics", NULL);
478         created = g_file_test (filename, G_FILE_TEST_EXISTS);
479         g_free (filename);
480
481         mu_assert ("Test creation of default system calendar : Failed", created);
482
483         return NULL;
484 }
485
486 static const gchar *
487 test_new_system_tasks (void)
488 {
489         const gchar *user_data_dir;
490         gchar *filename;
491         gboolean created;
492
493         e_cal_new_system_tasks ();
494
495         user_data_dir = e_get_user_data_dir ();
496         filename = g_build_filename (
497                 user_data_dir, "tasks", "system", "tasks.ics", NULL);
498         created = g_file_test (filename, G_FILE_TEST_EXISTS);
499         g_free (filename);
500
501         mu_assert ("Test creation of default system tasks : Failed", created);
502
503         return NULL;
504 }
505
506 static const gchar *
507 test_new_system_memos (void)
508 {
509         const gchar *user_data_dir;
510         gchar *filename;
511         gboolean created;
512
513         e_cal_new_system_memos ();
514
515         user_data_dir = e_get_user_data_dir ();
516         filename = g_build_filename (
517                 user_data_dir, "memos", "system", "journal.ics", NULL);
518         created = g_file_test (filename, G_FILE_TEST_EXISTS);
519         g_free (filename);
520
521         mu_assert ("Test creation of default system memos : Failed", created);
522
523         return NULL;
524 }
525
526 static gchar *
527 test_get_free_busy (ECal *client)
528 {
529         /* TODO uses NULL for users and currently specific to file backend. */
530         GList *l, *freebusy = NULL;
531         GError *error = NULL;
532         icaltimezone *utc;
533         time_t start, end;
534
535         utc = icaltimezone_get_utc_timezone ();
536         start = time_from_isodate ("20040212T000000Z");
537         end = time_add_day_with_zone (start, 2, utc);
538
539         if (!e_cal_get_free_busy (client, NULL, start, end, &freebusy, &error)) {
540                 cl_printf (client, "Test free/busy : Could not retrieve free busy information :  %s\n", error->message);
541                 return error->message;
542         }
543         if (freebusy) {
544                 cl_printf (client, "Printing free busy information\n");
545                 for (l = freebusy; l; l = l->next) {
546                         gchar *comp_string;
547                         ECalComponent *comp = E_CAL_COMPONENT (l->data);
548
549                         comp_string = e_cal_component_get_as_string (comp);
550                         cl_printf (client, "%s\n\n", comp_string);
551                         g_object_unref (comp);
552                         g_free (comp_string);
553                 }
554         }
555         else {
556                 cl_printf (client, "free_busy was returned but NULL");
557         }
558         return NULL;
559 }
560
561 static gchar *
562 test_get_default_object (ECal *client)
563 {
564         icalcomponent *icalcomp;
565         GError *error = NULL;
566         gchar *ical_string;
567         if (e_cal_get_default_object (client, &icalcomp, &error)) {
568                 ical_string = icalcomponent_as_ical_string_r (icalcomp);
569                 cl_printf (client, "Obtained default object: %s\n", ical_string);
570                 g_free (ical_string);
571                 tests_passed++;
572                 return NULL;
573
574         } else
575                 cl_printf (client, "Test Get default object : Could not get the default object: %s\n", error->message);
576         return error->message;
577 }
578
579 /* XXX The string pasted below is *really* ugly. Alternatively, it could be
580  * read from a file at run-time. Not sure if it is an elegant solution when
581  * multiple clients try to load the same file during stress testing.
582  * how can this be done better ?
583  */
584 #define EXPECTED \
585 "BEGIN : VEVENT\
586 UID : 20040213T055519Z - 15802 - 500 - 1 - 3@testcal\
587 DTSTAMP : 20040213T055519Z\
588 DTSTART; TZID=/softwarestudio.org / Olson_20011030_5 / Asia / Calcutta:\
589  20040213T130000\
590 DTEND; TZID=/softwarestudio.org / Olson_20011030_5 / Asia / Calcutta:\
591  20040213T133000\
592 TRANSP : OPAQUE\
593 SEQUENCE : 3\
594 SUMMARY : Test - Travel plans to Kansas\
595 LOCATION : Yellow Brick road\
596 CLASS : PUBLIC\
597 ORGANIZER; CN = dorothy : MAILTO : dorothy@oz\
598 DESCRIPTION: Discuss way to home\
599 ATTENDEE; CUTYPE = INDIVIDUAL; ROLE = REQ - PARTICIPANT; PARTSTAT = ACCEPTED;\
600  RSVP = TRUE; CN = dorothy; LANGUAGE = en : MAILTO : dorothy@oz\
601 ATTENDEE; CUTYPE = INDIVIDUAL; ROLE = REQ - PARTICIPANT; PARTSTAT = NEEDS - ACTION;\
602  RSVP = TRUE; CN = tinman; LANGUAGE = en : MAILTO : tinman@oz\
603 ATTENDEE; CUTYPE = INDIVIDUAL; ROLE = REQ - PARTICIPANT; PARTSTAT = NEEDS - ACTION;\
604  RSVP = TRUE; CN = toto; LANGUAGE = en : MAILTO : toto@oz\
605 ATTENDEE; CUTYPE = INDIVIDUAL; ROLE = OPT - PARTICIPANT; PARTSTAT = NEEDS - ACTION;\
606  RSVP = TRUE; CN = scarecrow; LANGUAGE = en : MAILTO : scarecrow@oz\
607 LAST - MODIFIED : 20040213T055647Z\
608 END : VEVENT"
609
610 static const gchar *
611 test_get_object (ECal *client)
612 {
613         const gchar *uid = "20040213T055519Z-15802-500-1-3@testcal";
614         gchar *actual;
615         icalcomponent *icalcomp;
616         gboolean compare;
617         GError *error = NULL;
618
619         if (!e_cal_get_object (client, uid, NULL, &icalcomp, &error)) {
620                 cl_printf (client, "Test Get object : Could not get the object: %s\n", error->message);
621                 return error->message;
622         }
623
624         actual = icalcomponent_as_ical_string_r (icalcomp);
625         compare = !strcmp (actual, EXPECTED);
626
627         g_free (actual);
628
629         mu_assert ("Test : get_object does not match the expected output", compare);
630         return NULL;
631 }
632
633 static gchar *
634 test_timezones (ECal *client)
635 {
636         icaltimezone *zone;
637         GError *error = NULL;
638         if (!e_cal_get_timezone (client, "UTC", &zone, &error))
639         {
640                 cl_printf (client, "Could not get the timezone\n");
641         }
642
643         printf ("\n\nTime Zones : \n%s *** %s", icaltimezone_get_display_name (zone), icaltimezone_get_tzid (zone));
644         printf ("\n\nTime Zones : \n%s", icaltimezone_get_location (zone));
645
646         return NULL;
647 }
648
649 static const gchar *
650 all_tests (ECal *client,
651            const gchar *uri)
652 {
653         gchar *uid;
654
655         mu_run_test (test_new_system_calendar ());
656         mu_run_test (test_new_system_tasks ());
657         mu_run_test (test_new_system_memos ());
658         mu_run_test (test_set_uri (client, uri));
659         mu_run_test (test_get_source (client, uri));
660         mu_run_test (test_cal_loaded (client));
661
662         /* test_query acts on pre-loaded data. Hence it must executed before
663          * any writes are made */
664         mu_run_test (test_query (client, "(contains? \"any\" \"test\")", 2));
665         mu_run_test (test_query (client, "(contains? \"summary\" \"Kansas\")", 1));
666         mu_run_test (test_query (client, "(contains? \"any\" \"gibberish\")", 0));
667
668         mu_run_test (test_get_default_object (client));
669         mu_run_test (test_get_object (client));
670         mu_run_test (test_get_free_busy (client));
671         mu_run_test (test_object_creation (client, &uid));
672         mu_run_test (test_object_modification (client, uid));
673         /* mu_run_test (test_object_removal (client)); */
674         mu_run_test (test_get_alarms_in_range (client));
675
676 #if 0
677         tmp = g_strconcat (uri, "_tmp", NULL);
678         mu_run_test (test_e_cal_new (&ecal, tmp));
679         mu_run_test (test_e_cal_remove (ecal, tmp));
680         g_free (tmp);
681 #endif
682
683         test_timezones (client);
684
685         return NULL;
686 }
687
688 /* Creates a calendar client and tries to load the specified URI into it */
689 static void
690 create_client (ECal **client,
691                const gchar *uri,
692                ECalSourceType type,
693                gboolean only_if_exists)
694 {
695         const gchar *results;
696         ECalView *query;
697         gchar *cal_uri;
698         GError *error = NULL;
699
700         cal_uri = g_strconcat ("file://", uri, NULL);
701         *client = e_cal_new_from_uri (cal_uri, type);
702         if (!*client) {
703                 g_message (G_STRLOC ": could not create the client");
704                 exit (1);
705         }
706
707         g_object_weak_ref (G_OBJECT (*client), client_destroy_cb, NULL);
708
709         cl_printf (*client, "Calendar loading `%s'...\n", uri);
710
711         if (!e_cal_open (*client, only_if_exists, &error)) {
712                 cl_printf (*client, "Load/create %s\n", error->message);
713                 exit (1);
714         }
715         g_clear_error (&error);
716
717         if (!e_cal_get_query (*client, "(contains? \"any\" \"Event\")", &query, NULL)) {
718                 cl_printf (*client, G_STRLOC ": Unable to obtain query");
719                 exit (1);
720         }
721
722         g_signal_connect (G_OBJECT (query), "objects_added",
723                           G_CALLBACK (objects_added_cb), client);
724         g_signal_connect (G_OBJECT (query), "objects_modified",
725                           G_CALLBACK (objects_modified_cb), client);
726         g_signal_connect (G_OBJECT (query), "objects_removed",
727                           G_CALLBACK (objects_removed_cb), client);
728         g_signal_connect (G_OBJECT (query), "view_complete",
729                           G_CALLBACK (view_complete_cb), client);
730
731         e_cal_view_start (query);
732
733         results = all_tests (*client, uri);
734         cl_printf (*client, "\n\n\n*************Tests run: %d****************\n\n", tests_run);
735         cl_printf (*client, "*************Tests passed: %d*************\n\n\n", tests_passed);
736         if (results != NULL)
737                 cl_printf (*client, "***Failures********%s\n", results);
738
739         cl_printf (*client, "dump of the test calendar data");
740         list_uids (*client);
741         g_free (cal_uri);
742
743 }
744
745 gint
746 main (gint argc,
747       gchar **argv)
748 {
749         gchar *uri;
750         bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
751         textdomain (GETTEXT_PACKAGE);
752
753         g_type_init ();
754         loop = g_main_loop_new (NULL, TRUE);
755
756         /* arg1- file name; arg2- client suffix */
757         uri = g_strconcat (argv[1], argv[2], NULL);
758         create_client (&client1, uri, E_CAL_SOURCE_TYPE_EVENT, FALSE);
759
760         g_free (uri);
761         g_main_loop_run (loop);
762         return 0;
763 }