1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
#include <libebook/e-book-client.h>
5
#include "client-test-utils.h"
8
check_removed (EBookClient *book_client, const GSList *uids)
10
g_return_val_if_fail (book_client != NULL, FALSE);
11
g_return_val_if_fail (uids != NULL, FALSE);
15
EContact *contact = NULL;
17
if (!e_book_client_get_contact_sync (book_client, uids->data, &contact, NULL, &error) &&
18
g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
19
g_clear_error (&error);
21
report_error ("fail with get contact on removed contact", &error);
23
g_object_unref (contact);
34
fill_book_client (EBookClient *book_client, GSList **uids)
38
g_return_val_if_fail (book_client != NULL, FALSE);
39
g_return_val_if_fail (uids != NULL, FALSE);
43
if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact))
46
*uids = g_slist_append (*uids, e_contact_get (contact, E_CONTACT_UID));
47
g_object_unref (contact);
49
if (!add_contact_from_test_case_verify (book_client, "simple-2", &contact))
52
*uids = g_slist_append (*uids, e_contact_get (contact, E_CONTACT_UID));
53
g_object_unref (contact);
59
remove_contacts_cb (GObject *source_object, GAsyncResult *result, gpointer uids)
63
if (!e_book_client_remove_contacts_finish (E_BOOK_CLIENT (source_object), result, &error)) {
64
report_error ("remove contacts finish", &error);
69
stop_main_loop (check_removed (E_BOOK_CLIENT (source_object), uids) ? 0 : 1);
73
main (gint argc, gchar **argv)
75
EBookClient *book_client;
84
book_client = new_temp_client (NULL);
85
g_return_val_if_fail (book_client != NULL, 1);
87
if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
88
report_error ("client open sync", &error);
89
g_object_unref (book_client);
96
if (!fill_book_client (book_client, &uids)) {
97
g_object_unref (book_client);
101
if (!e_book_client_remove_contacts_sync (book_client, uids, NULL, &error)) {
102
report_error ("remove contact sync", &error);
103
g_object_unref (book_client);
104
g_slist_foreach (uids, (GFunc) g_free, NULL);
109
if (!check_removed (book_client, uids)) {
110
g_object_unref (book_client);
111
g_slist_foreach (uids, (GFunc) g_free, NULL);
116
g_slist_foreach (uids, (GFunc) g_free, NULL);
119
if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
120
report_error ("client remove sync", &error);
121
g_object_unref (book_client);
125
g_object_unref (book_client);
130
book_client = new_temp_client (NULL);
131
g_return_val_if_fail (book_client != NULL, 1);
133
if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
134
report_error ("client open sync", &error);
135
g_object_unref (book_client);
139
if (!fill_book_client (book_client, &uids)) {
140
g_object_unref (book_client);
144
e_book_client_remove_contacts (book_client, uids, NULL, remove_contacts_cb, uids);
146
start_main_loop (NULL, NULL);
148
g_slist_foreach (uids, (GFunc) g_free, NULL);
151
if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
152
report_error ("client remove sync", &error);
153
g_object_unref (book_client);
157
g_object_unref (book_client);
159
return get_main_loop_stop_result ();