1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
4 #include <libebook/libebook.h>
6 #include "client-test-utils.h"
7 #include "e-test-server-utils.h"
9 static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
10 static ETestServerClosure direct_book_closure = { E_TEST_SERVER_DIRECT_ADDRESS_BOOK, NULL, 0 };
12 #define NOTIFICATION_WAIT 2000
14 static gboolean loading_view;
17 add_contact (EBookClient *book_client)
19 g_return_if_fail (add_contact_from_test_case_verify (book_client, "name-only", NULL));
23 setup_book (EBookClient *book_client)
25 if (!add_contact_from_test_case_verify (book_client, "simple-1", NULL) ||
26 !add_contact_from_test_case_verify (book_client, "simple-2", NULL))
27 g_error ("Failed to add contacts");
31 finish_test (EBookClientView *view,
34 e_book_client_view_stop (view, NULL);
35 g_object_unref (view);
37 g_main_loop_quit (loop);
41 objects_added (EBookClientView *view,
42 const GSList *contacts,
46 GMainLoop *loop = (GMainLoop *) user_data;
48 /* We quit the mainloop and the test succeeds if we get the notification
49 * for the contact we add after loading the view completes */
50 for (l = contacts; l; l = l->next) {
51 print_email (l->data);
55 g_error ("Expected no contact additions while loading the view");
57 finish_test (view, loop);
63 objects_removed (EBookClientView *view,
69 g_error ("Expected no contact removals while loading the view");
71 for (l = ids; l; l = l->next) {
72 printf (" Removed contact: %s\n", (gchar *) l->data);
77 complete (EBookClientView *view,
82 client = e_book_client_view_ref_client (view);
84 /* Now add a contact and assert that we received notification */
88 g_object_unref (client);
92 setup_and_start_view (EBookClientView *view,
97 g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), loop);
98 g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), loop);
99 g_signal_connect (view, "complete", G_CALLBACK (complete), loop);
101 e_book_client_view_set_fields_of_interest (view, NULL, &error);
103 g_error ("set fields of interest: %s", error->message);
105 /* Set flags to 0, i.e. unflag E_BOOK_VIEW_NOTIFY_INITIAL */
106 e_book_client_view_set_flags (view, 0, &error);
108 g_error ("set view flags: %s", error->message);
111 e_book_client_view_start (view, &error);
113 g_error ("start view: %s", error->message);
118 get_view_cb (GObject *source_object,
119 GAsyncResult *result,
122 GMainLoop *loop = (GMainLoop *) user_data;
123 EBookClientView *view;
124 GError *error = NULL;
126 if (!e_book_client_get_view_finish (E_BOOK_CLIENT (source_object), result, &view, &error)) {
127 g_error ("get view finish: %s", error->message);
130 setup_and_start_view (view, loop);
134 test_suppress_notifications_sync (ETestServerFixture *fixture,
135 gconstpointer user_data)
137 EBookClient *book_client;
139 EBookClientView *view;
141 GError *error = NULL;
143 book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
145 setup_book (book_client);
147 query = e_book_query_any_field_contains ("");
148 sexp = e_book_query_to_string (query);
149 e_book_query_unref (query);
150 if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
151 g_error ("get book view sync: %s", error->message);
153 g_object_unref (book_client);
158 setup_and_start_view (view, fixture->loop);
159 g_main_loop_run (fixture->loop);
163 test_suppress_notifications_async (ETestServerFixture *fixture,
164 gconstpointer user_data)
166 EBookClient *book_client;
170 book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
172 setup_book (book_client);
173 query = e_book_query_any_field_contains ("");
174 sexp = e_book_query_to_string (query);
175 e_book_query_unref (query);
177 e_book_client_get_view (book_client, sexp, NULL, get_view_cb, fixture->loop);
180 g_main_loop_run (fixture->loop);
187 #if !GLIB_CHECK_VERSION (2, 35, 1)
190 g_test_init (&argc, &argv, NULL);
193 "/EBookClient/SuppressNotifications/Sync", ETestServerFixture, &book_closure,
194 e_test_server_utils_setup, test_suppress_notifications_sync, e_test_server_utils_teardown);
196 "/EBookClient/SuppressNotifications/Async", ETestServerFixture, &book_closure,
197 e_test_server_utils_setup, test_suppress_notifications_async, e_test_server_utils_teardown);
199 "/EBookClient/DirectAccess/SuppressNotifications/Sync", ETestServerFixture, &direct_book_closure,
200 e_test_server_utils_setup, test_suppress_notifications_sync, e_test_server_utils_teardown);
202 "/EBookClient/DirectAccess/SuppressNotifications/Async", ETestServerFixture, &direct_book_closure,
203 e_test_server_utils_setup, test_suppress_notifications_async, e_test_server_utils_teardown);
205 return e_test_server_utils_run ();