1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
5
#include <libecal/libecal.h>
6
#include <libical/ical.h>
8
#include "e-test-server-utils.h"
10
#define ATTACH1 "file:///tmp/file1.x"
11
#define ATTACH2 "file:///tmp/file2"
12
#define ATTACH3 "file:///tmp/dir/fileěščřžýáíé3"
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 };
20
add_attach (icalcomponent *icalcomp,
28
g_return_if_fail (icalcomp != NULL);
29
g_return_if_fail (uri != NULL);
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);
42
setup_cal (ECalClient *cal_client)
44
icalcomponent *icalcomp;
45
struct icaltimetype now;
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);
58
if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error))
59
g_error ("create object sync: %s", error->message);
61
icalcomponent_free (icalcomp);
62
g_object_set_data_full (G_OBJECT (cal_client), "use-uid", uid, g_free);
68
manage_result (GSList *attachment_uris)
72
g_assert (attachment_uris != NULL);
73
g_assert_cmpint (g_slist_length (attachment_uris), ==, 3);
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);
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);
86
g_assert_not_reached ();
89
e_client_util_free_string_slist (attachment_uris);
93
test_get_attachment_uris_sync (ETestServerFixture *fixture,
94
gconstpointer user_data)
96
ECalClient *cal_client;
98
GSList *attachment_uris = NULL;
101
cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
102
uid = setup_cal (cal_client);
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);
107
manage_result (attachment_uris);
111
async_attachment_uris_result_ready (GObject *source_object,
112
GAsyncResult *result,
115
ECalClient *cal_client;
116
GError *error = NULL;
117
GSList *attachment_uris = NULL;
118
GMainLoop *loop = (GMainLoop *) user_data;
120
cal_client = E_CAL_CLIENT (source_object);
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);
125
manage_result (attachment_uris);
127
g_main_loop_quit (loop);
131
test_get_attachment_uris_async (ETestServerFixture *fixture,
132
gconstpointer user_data)
134
ECalClient *cal_client;
137
cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
138
uid = setup_cal (cal_client);
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);
148
g_test_init (&argc, &argv, NULL);
149
g_test_bug_base ("http://bugzilla.gnome.org/");
152
"/ECalClient/GetAttachmentUris/Sync",
155
e_test_server_utils_setup,
156
test_get_attachment_uris_sync,
157
e_test_server_utils_teardown);
159
"/ECalClient/GetAttachmentUris/Async",
162
e_test_server_utils_setup,
163
test_get_attachment_uris_async,
164
e_test_server_utils_teardown);
166
return e_test_server_utils_run ();