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 =
15 { E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
18 add_attach (icalcomponent *icalcomp,
26 g_return_if_fail (icalcomp != NULL);
27 g_return_if_fail (uri != NULL);
29 buf_size = 2 * strlen (uri);
30 buf = g_malloc0 (buf_size);
31 icalvalue_encode_ical_string (uri, buf, buf_size);
32 attach = icalattach_new_from_url (uri);
33 prop = icalproperty_new_attach (attach);
34 icalcomponent_add_property (icalcomp, prop);
35 icalattach_unref (attach);
40 setup_cal (ECalClient *cal_client)
42 icalcomponent *icalcomp;
43 struct icaltimetype now;
47 now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
48 icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
49 icalcomponent_set_summary (icalcomp, "Test event summary");
50 icalcomponent_set_dtstart (icalcomp, now);
51 icalcomponent_set_dtend (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
52 add_attach (icalcomp, ATTACH1);
53 add_attach (icalcomp, ATTACH2);
54 add_attach (icalcomp, ATTACH3);
56 if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error))
57 g_error ("create object sync: %s", error->message);
59 icalcomponent_free (icalcomp);
60 g_object_set_data_full (G_OBJECT (cal_client), "use-uid", uid, g_free);
66 manage_result (GSList *attachment_uris)
70 g_assert (attachment_uris != NULL);
71 g_assert_cmpint (g_slist_length (attachment_uris), ==, 3);
73 res = g_slist_find_custom (attachment_uris, ATTACH1, g_str_equal)
74 && g_slist_find_custom (attachment_uris, ATTACH2, g_str_equal)
75 && g_slist_find_custom (attachment_uris, ATTACH3, g_str_equal);
80 g_printerr ("Failed: didn't return same three attachment uris, got instead:\n");
81 for (au = attachment_uris; au; au = au->next)
82 g_printerr ("\t'%s'\n", (const gchar *) au->data);
84 g_assert_not_reached ();
87 e_client_util_free_string_slist (attachment_uris);
91 test_get_attachment_uris_sync (ETestServerFixture *fixture,
92 gconstpointer user_data)
94 ECalClient *cal_client;
96 GSList *attachment_uris = NULL;
99 cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
100 uid = setup_cal (cal_client);
102 if (!e_cal_client_get_attachment_uris_sync (cal_client, uid, NULL, &attachment_uris, NULL, &error))
103 g_error ("get attachment uris sync: %s", error->message);
105 manage_result (attachment_uris);
109 async_attachment_uris_result_ready (GObject *source_object,
110 GAsyncResult *result,
113 ECalClient *cal_client;
114 GError *error = NULL;
115 GSList *attachment_uris = NULL;
116 GMainLoop *loop = (GMainLoop *)user_data;
118 cal_client = E_CAL_CLIENT (source_object);
120 if (!e_cal_client_get_attachment_uris_finish (cal_client, result, &attachment_uris, &error))
121 g_error ("get attachment uris finish: %s", error->message);
123 manage_result (attachment_uris);
125 g_main_loop_quit (loop);
129 test_get_attachment_uris_async (ETestServerFixture *fixture,
130 gconstpointer user_data)
132 ECalClient *cal_client;
135 cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
136 uid = setup_cal (cal_client);
138 e_cal_client_get_attachment_uris (cal_client, uid, NULL, NULL, async_attachment_uris_result_ready, fixture->loop);
139 g_main_loop_run (fixture->loop);
146 #if !GLIB_CHECK_VERSION (2, 35, 1)
149 g_test_init (&argc, &argv, NULL);
151 g_test_add ("/ECalClient/GetAttachmentUris/Sync", ETestServerFixture, &cal_closure,
152 e_test_server_utils_setup, test_get_attachment_uris_sync, e_test_server_utils_teardown);
153 g_test_add ("/ECalClient/GetAttachmentUris/Async", ETestServerFixture, &cal_closure,
154 e_test_server_utils_setup, test_get_attachment_uris_async, e_test_server_utils_teardown);
156 return e_test_server_utils_run ();