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

« back to all changes in this revision

Viewing changes to tests/libecal/client/test-cal-client-get-attachment-uris.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-06-13 12:02:14 UTC
  • mfrom: (1.1.116) (1.2.35 sid)
  • Revision ID: package-import@ubuntu.com-20140613120214-1zx93d8jxwt093aw
Tags: 3.12.2-1ubuntu1
* Merge with Debian, remaining changes:
  - debian/control: build depend on hardening-wrapper
  - Add build-depends and pass configure flag to enable Ubuntu Online
    Accounts support.
  - Filter out -Bsymbolic-functions from LDFLAGS (for future people
    wondering about this change, see e.g. BGO #594473 and duplicates).
  - Enable Ubuntu Online Accounts and split it and GOA into a separate
    package

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 <string.h>
 
5
#include <libecal/libecal.h>
 
6
#include <libical/ical.h>
 
7
 
 
8
#include "e-test-server-utils.h"
 
9
 
 
10
#define ATTACH1 "file:///tmp/file1.x"
 
11
#define ATTACH2 "file:///tmp/file2"
 
12
#define ATTACH3 "file:///tmp/dir/fileěščřžýáíé3"
 
13
 
 
14
static ETestServerClosure cal_closure_sync =
 
15
        { E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, FALSE, NULL, FALSE };
 
16
static ETestServerClosure cal_closure_async =
 
17
        { E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, FALSE, NULL, TRUE };
 
18
 
 
19
static void
 
20
add_attach (icalcomponent *icalcomp,
 
21
            const gchar *uri)
 
22
{
 
23
        gsize buf_size;
 
24
        gchar *buf;
 
25
        icalproperty *prop;
 
26
        icalattach *attach;
 
27
 
 
28
        g_return_if_fail (icalcomp != NULL);
 
29
        g_return_if_fail (uri != NULL);
 
30
 
 
31
        buf_size = 2 * strlen (uri);
 
32
        buf = g_malloc0 (buf_size);
 
33
        icalvalue_encode_ical_string (uri, buf, buf_size);
 
34
        attach = icalattach_new_from_url (uri);
 
35
        prop = icalproperty_new_attach (attach);
 
36
        icalcomponent_add_property (icalcomp, prop);
 
37
        icalattach_unref (attach);
 
38
        g_free (buf);
 
39
}
 
40
 
 
41
static const gchar *
 
42
setup_cal (ECalClient *cal_client)
 
43
{
 
44
        icalcomponent *icalcomp;
 
45
        struct icaltimetype now;
 
46
        gchar *uid = NULL;
 
47
        GError *error = NULL;
 
48
 
 
49
        now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
 
50
        icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
 
51
        icalcomponent_set_summary (icalcomp, "Test event summary");
 
52
        icalcomponent_set_dtstart (icalcomp, now);
 
53
        icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
 
54
        add_attach (icalcomp, ATTACH1);
 
55
        add_attach (icalcomp, ATTACH2);
 
56
        add_attach (icalcomp, ATTACH3);
 
57
 
 
58
        if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error))
 
59
                g_error ("create object sync: %s", error->message);
 
60
 
 
61
        icalcomponent_free (icalcomp);
 
62
        g_object_set_data_full (G_OBJECT (cal_client), "use-uid", uid, g_free);
 
63
 
 
64
        return uid;
 
65
}
 
66
 
 
67
static void
 
68
manage_result (GSList *attachment_uris)
 
69
{
 
70
        gboolean res;
 
71
 
 
72
        g_assert (attachment_uris != NULL);
 
73
        g_assert_cmpint (g_slist_length (attachment_uris), ==, 3);
 
74
 
 
75
        res = g_slist_find_custom (attachment_uris, ATTACH1, g_str_equal)
 
76
           && g_slist_find_custom (attachment_uris, ATTACH2, g_str_equal)
 
77
           && g_slist_find_custom (attachment_uris, ATTACH3, g_str_equal);
 
78
 
 
79
        if (!res) {
 
80
                GSList *au;
 
81
 
 
82
                g_printerr ("Failed: didn't return same three attachment uris, got instead:\n");
 
83
                for (au = attachment_uris; au; au = au->next)
 
84
                        g_printerr ("\t'%s'\n", (const gchar *) au->data);
 
85
 
 
86
                g_assert_not_reached ();
 
87
        }
 
88
 
 
89
        e_client_util_free_string_slist (attachment_uris);
 
90
}
 
91
 
 
92
static void
 
93
test_get_attachment_uris_sync (ETestServerFixture *fixture,
 
94
                               gconstpointer user_data)
 
95
{
 
96
        ECalClient *cal_client;
 
97
        GError *error = NULL;
 
98
        GSList *attachment_uris = NULL;
 
99
        const gchar *uid;
 
100
 
 
101
        cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
102
        uid = setup_cal (cal_client);
 
103
 
 
104
        if (!e_cal_client_get_attachment_uris_sync (cal_client, uid, NULL, &attachment_uris, NULL, &error))
 
105
                g_error ("get attachment uris sync: %s", error->message);
 
106
 
 
107
        manage_result (attachment_uris);
 
108
}
 
109
 
 
110
static void
 
111
async_attachment_uris_result_ready (GObject *source_object,
 
112
                                    GAsyncResult *result,
 
113
                                    gpointer user_data)
 
114
{
 
115
        ECalClient *cal_client;
 
116
        GError *error = NULL;
 
117
        GSList *attachment_uris = NULL;
 
118
        GMainLoop *loop = (GMainLoop *) user_data;
 
119
 
 
120
        cal_client = E_CAL_CLIENT (source_object);
 
121
 
 
122
        if (!e_cal_client_get_attachment_uris_finish (cal_client, result, &attachment_uris, &error))
 
123
                g_error ("get attachment uris finish: %s", error->message);
 
124
 
 
125
        manage_result (attachment_uris);
 
126
 
 
127
        g_main_loop_quit (loop);
 
128
}
 
129
 
 
130
static void
 
131
test_get_attachment_uris_async (ETestServerFixture *fixture,
 
132
                                gconstpointer user_data)
 
133
{
 
134
        ECalClient *cal_client;
 
135
        const gchar *uid;
 
136
 
 
137
        cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
138
        uid = setup_cal (cal_client);
 
139
 
 
140
        e_cal_client_get_attachment_uris (cal_client, uid, NULL, NULL, async_attachment_uris_result_ready, fixture->loop);
 
141
        g_main_loop_run (fixture->loop);
 
142
}
 
143
 
 
144
gint
 
145
main (gint argc,
 
146
      gchar **argv)
 
147
{
 
148
        g_test_init (&argc, &argv, NULL);
 
149
        g_test_bug_base ("http://bugzilla.gnome.org/");
 
150
 
 
151
        g_test_add (
 
152
                "/ECalClient/GetAttachmentUris/Sync",
 
153
                ETestServerFixture,
 
154
                &cal_closure_sync,
 
155
                e_test_server_utils_setup,
 
156
                test_get_attachment_uris_sync,
 
157
                e_test_server_utils_teardown);
 
158
        g_test_add (
 
159
                "/ECalClient/GetAttachmentUris/Async",
 
160
                ETestServerFixture,
 
161
                &cal_closure_async,
 
162
                e_test_server_utils_setup,
 
163
                test_get_attachment_uris_async,
 
164
                e_test_server_utils_teardown);
 
165
 
 
166
        return e_test_server_utils_run ();
 
167
}