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

« back to all changes in this revision

Viewing changes to calendar/tests/ecal/test-ecal-get-query.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
#include <stdlib.h>
 
4
#include <libecal/e-cal.h>
 
5
#include <libical/ical.h>
 
6
 
 
7
#include "ecal-test-utils.h"
 
8
 
 
9
#define COMPLETE_TIMEOUT 30
 
10
 
 
11
#define EVENT_SUMMARY "Creation of the initial test event"
 
12
#define INITIAL_BEGIN_TIME     "20040109T090000Z"
 
13
#define INITIAL_BEGIN_TIMEZONE "UTC"
 
14
#define INITIAL_END_TIME       "20040109T103000"
 
15
#define INITIAL_END_TIMEZONE   "UTC"
 
16
#define FINAL_BEGIN_TIME       "20091221T090000Z"
 
17
#define FINAL_BEGIN_TIMEZONE   "UTC"
 
18
 
 
19
static void complete_timeout_cb (gpointer user_data) __attribute__ ((noreturn));
 
20
 
 
21
static GMainLoop *loop;
 
22
static guint complete_timeout_id;
 
23
static guint alter_cal_id;
 
24
 
 
25
typedef enum {
 
26
        SUBTEST_OBJECTS_ADDED,
 
27
        SUBTEST_OBJECTS_MODIFIED,
 
28
        SUBTEST_OBJECTS_REMOVED,
 
29
        SUBTEST_VIEW_DONE,
 
30
        NUM_SUBTESTS,
 
31
} SubTestId;
 
32
 
 
33
static void
 
34
subtest_passed (SubTestId id)
 
35
{
 
36
        static guint subtests_complete = 0;
 
37
 
 
38
        subtests_complete |= (1 << id);
 
39
 
 
40
        if (subtests_complete == ((1 << NUM_SUBTESTS) - 1))
 
41
                g_main_loop_quit (loop);
 
42
}
 
43
 
 
44
static void
 
45
objects_added_cb (GObject *object, GList *objects, gpointer data)
 
46
{
 
47
        GList *l;
 
48
 
 
49
        for (l = objects; l; l = l->next)
 
50
                test_print ("Object added %s\n", icalcomponent_get_uid (l->data));
 
51
 
 
52
        subtest_passed (SUBTEST_OBJECTS_ADDED);
 
53
}
 
54
 
 
55
static void
 
56
objects_modified_cb (GObject *object, GList *objects, gpointer data)
 
57
{
 
58
        GList *l;
 
59
 
 
60
        for (l = objects; l; l = l->next)
 
61
                test_print ("Object modified %s\n", icalcomponent_get_uid (l->data));
 
62
 
 
63
        subtest_passed (SUBTEST_OBJECTS_MODIFIED);
 
64
}
 
65
 
 
66
static void
 
67
objects_removed_cb (GObject *object, GList *objects, gpointer data)
 
68
{
 
69
        GList *l;
 
70
 
 
71
        for (l = objects; l; l = l->next) {
 
72
                ECalComponentId *id = l->data;
 
73
 
 
74
                test_print ("Object removed: uid: %s, rid: %s\n", id->uid,
 
75
                                id->rid);
 
76
        }
 
77
 
 
78
        subtest_passed (SUBTEST_OBJECTS_REMOVED);
 
79
}
 
80
 
 
81
static void
 
82
view_done_cb (GObject *object, ECalendarStatus status, gpointer data)
 
83
{
 
84
        test_print ("View done\n");
 
85
 
 
86
        g_source_remove (complete_timeout_id);
 
87
 
 
88
        subtest_passed (SUBTEST_VIEW_DONE);
 
89
}
 
90
 
 
91
static void
 
92
complete_timeout_cb (gpointer user_data)
 
93
{
 
94
        g_error ("failed to complete all the pieces of the test in time");
 
95
}
 
96
 
 
97
static gboolean
 
98
alter_cal_cb (ECal *cal)
 
99
{
 
100
        ECalComponent *e_component;
 
101
        ECalComponent *e_component_final;
 
102
        icalcomponent *component;
 
103
        icalcomponent *component_final;
 
104
        struct icaltimetype icaltime;
 
105
        gchar *uid;
 
106
 
 
107
        /* create a calendar object */
 
108
        ecal_test_utils_create_component (cal, INITIAL_BEGIN_TIME,
 
109
                        INITIAL_BEGIN_TIMEZONE, INITIAL_END_TIME,
 
110
                        INITIAL_END_TIMEZONE, EVENT_SUMMARY, &e_component,
 
111
                        &uid);
 
112
        component = e_cal_component_get_icalcomponent (e_component);
 
113
 
 
114
        component_final = ecal_test_utils_cal_get_object (cal, uid);
 
115
        ecal_test_utils_cal_assert_objects_equal_shallow (component,
 
116
                        component_final);
 
117
        icalcomponent_free (component_final);
 
118
 
 
119
        /* make and commit changes to the object */
 
120
        icaltime = icaltime_from_string (FINAL_BEGIN_TIME);
 
121
        icalcomponent_set_dtstart (component, icaltime);
 
122
        ecal_test_utils_cal_component_set_icalcomponent (e_component,
 
123
                        component);
 
124
        ecal_test_utils_cal_modify_object (cal, component, CALOBJ_MOD_ALL);
 
125
 
 
126
        /* verify the modification */
 
127
        component_final = ecal_test_utils_cal_get_object (cal, uid);
 
128
        e_component_final = e_cal_component_new ();
 
129
        ecal_test_utils_cal_component_set_icalcomponent (e_component_final,
 
130
                                component_final);
 
131
 
 
132
        ecal_test_utils_cal_assert_e_cal_components_equal (e_component,
 
133
                        e_component_final);
 
134
 
 
135
        /* remove the object */
 
136
        ecal_test_utils_cal_remove_object (cal, uid);
 
137
 
 
138
        /* Clean-up */
 
139
        ecal_test_utils_cal_remove (cal);
 
140
 
 
141
        g_object_unref (e_component_final);
 
142
        g_free (uid);
 
143
        icalcomponent_free (component);
 
144
 
 
145
        return FALSE;
 
146
}
 
147
 
 
148
gint
 
149
main (gint argc, gchar **argv)
 
150
{
 
151
        ECal *cal;
 
152
        gchar *uri = NULL;
 
153
        ECalView *view = NULL;
 
154
 
 
155
        g_type_init ();
 
156
 
 
157
        cal = ecal_test_utils_cal_new_temp (&uri, E_CAL_SOURCE_TYPE_EVENT);
 
158
        ecal_test_utils_cal_open (cal, FALSE);
 
159
 
 
160
        view = ecal_test_utils_get_query (cal, "(contains? \"any\" \"event\")");
 
161
 
 
162
        /* monitor changes to the calendar */
 
163
        g_signal_connect (G_OBJECT (view), "objects_added",
 
164
                        G_CALLBACK (objects_added_cb), cal);
 
165
        g_signal_connect (G_OBJECT (view), "objects_modified",
 
166
                        G_CALLBACK (objects_modified_cb), cal);
 
167
        g_signal_connect (G_OBJECT (view), "objects_removed",
 
168
                        G_CALLBACK (objects_removed_cb), cal);
 
169
        g_signal_connect (G_OBJECT (view), "view_done",
 
170
                        G_CALLBACK (view_done_cb), cal);
 
171
 
 
172
        e_cal_view_start (view);
 
173
 
 
174
        loop = g_main_loop_new (NULL, TRUE);
 
175
        alter_cal_id = g_idle_add ((GSourceFunc) alter_cal_cb, cal);
 
176
        complete_timeout_id = g_timeout_add_seconds (COMPLETE_TIMEOUT,
 
177
                        (GSourceFunc) complete_timeout_cb, cal);
 
178
 
 
179
        g_main_loop_run (loop);
 
180
 
 
181
        g_object_unref (view);
 
182
 
 
183
        return 0;
 
184
}