~ubuntu-branches/ubuntu/precise/evolution-data-server/precise

« back to all changes in this revision

Viewing changes to tests/libebook/client/test-client-remove-contacts.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre, Ken VanDine, Mathieu Trudel-Lapierre
  • Date: 2011-06-23 17:40:41 UTC
  • mfrom: (1.1.88 upstream)
  • Revision ID: james.westby@ubuntu.com-20110623174041-4wd9jvs07wfinyet
Tags: 3.1.2-0ubuntu1
* New upstream version
  - bgo 589495 - Search folder by Size (KB) counts bytes, not KB (LP: #385859)
  - bgo 649757 - Filtering on a source account always succeeded (LP: #781391)
  - bgo 418954 - Add a separate entry combo for port numbers (LP: #160304)

[ Ken VanDine ]
* debian/libebook1.2-dev.install
  - Include EBook-1.2.gir
* debian/control
  - Added gir1.2-ebook-1.2 binary

[ Mathieu Trudel-Lapierre ]
* debian/control: drop libegroupwise1.2-13, libegroupwise-dev, they are now
  an independent module.
* debian/libegroupwise1.2-13.install,
  debian/libegroupwise1.2-dev.install,
  debian/lintian/libegroupwise1.2-13: dropped, see above.
* debian/control, debian/libe*.install, debian/lintian/libe*: rename and
  update files where needed to follow upstream soname changes.
* debian/control: bump evolution-data-server's Depends to libcamel-1.2-26.
* debian/rules: update to use makeshlibs with the new libcamel soname.

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 <libebook/e-book-client.h>
 
4
 
 
5
#include "client-test-utils.h"
 
6
 
 
7
static gboolean
 
8
check_removed (EBookClient *book_client, const GSList *uids)
 
9
{
 
10
        g_return_val_if_fail (book_client != NULL, FALSE);
 
11
        g_return_val_if_fail (uids != NULL, FALSE);
 
12
 
 
13
        while (uids) {
 
14
                GError *error = NULL;
 
15
                EContact *contact = NULL;
 
16
 
 
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);
 
20
                } else {
 
21
                        report_error ("fail with get contact on removed contact", &error);
 
22
                        if (contact)
 
23
                                g_object_unref (contact);
 
24
                        return FALSE;
 
25
                }
 
26
 
 
27
                uids = uids->next;
 
28
        }
 
29
 
 
30
        return TRUE;
 
31
}
 
32
 
 
33
static gboolean
 
34
fill_book_client (EBookClient *book_client, GSList **uids)
 
35
{
 
36
        EContact *contact;
 
37
 
 
38
        g_return_val_if_fail (book_client != NULL, FALSE);
 
39
        g_return_val_if_fail (uids != NULL, FALSE);
 
40
 
 
41
        *uids = NULL;
 
42
 
 
43
        if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact))
 
44
                return FALSE;
 
45
 
 
46
        *uids = g_slist_append (*uids, e_contact_get (contact, E_CONTACT_UID));
 
47
        g_object_unref (contact);
 
48
 
 
49
        if (!add_contact_from_test_case_verify (book_client, "simple-2", &contact))
 
50
                return FALSE;
 
51
 
 
52
        *uids = g_slist_append (*uids, e_contact_get (contact, E_CONTACT_UID));
 
53
        g_object_unref (contact);
 
54
 
 
55
        return TRUE;
 
56
}
 
57
 
 
58
static void
 
59
remove_contacts_cb (GObject *source_object, GAsyncResult *result, gpointer uids)
 
60
{
 
61
        GError *error = NULL;
 
62
 
 
63
        if (!e_book_client_remove_contacts_finish (E_BOOK_CLIENT (source_object), result, &error)) {
 
64
                report_error ("remove contacts finish", &error);
 
65
                stop_main_loop (1);
 
66
                return;
 
67
        }
 
68
 
 
69
        stop_main_loop (check_removed (E_BOOK_CLIENT (source_object), uids) ? 0 : 1);
 
70
}
 
71
 
 
72
gint
 
73
main (gint argc, gchar **argv)
 
74
{
 
75
        EBookClient *book_client;
 
76
        GError *error = NULL;
 
77
        GSList *uids;
 
78
 
 
79
        main_initialize ();
 
80
 
 
81
        /*
 
82
         * Setup
 
83
         */
 
84
        book_client = new_temp_client (NULL);
 
85
        g_return_val_if_fail (book_client != NULL, 1);
 
86
 
 
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);
 
90
                return 1;
 
91
        }
 
92
 
 
93
        /*
 
94
         * Sync version
 
95
         */
 
96
        if (!fill_book_client (book_client, &uids)) {
 
97
                g_object_unref (book_client);
 
98
                return 1;
 
99
        }
 
100
 
 
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);
 
105
                g_slist_free (uids);
 
106
                return 1;
 
107
        }
 
108
 
 
109
        if (!check_removed (book_client, uids)) {
 
110
                g_object_unref (book_client);
 
111
                g_slist_foreach (uids, (GFunc) g_free, NULL);
 
112
                g_slist_free (uids);
 
113
                return 1;
 
114
        }
 
115
 
 
116
        g_slist_foreach (uids, (GFunc) g_free, NULL);
 
117
        g_slist_free (uids);
 
118
 
 
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);
 
122
                return 1;
 
123
        }
 
124
 
 
125
        g_object_unref (book_client);
 
126
 
 
127
        /*
 
128
         * Async version
 
129
         */
 
130
        book_client = new_temp_client (NULL);
 
131
        g_return_val_if_fail (book_client != NULL, 1);
 
132
 
 
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);
 
136
                return 1;
 
137
        }
 
138
 
 
139
        if (!fill_book_client (book_client, &uids)) {
 
140
                g_object_unref (book_client);
 
141
                return 1;
 
142
        }
 
143
 
 
144
        e_book_client_remove_contacts (book_client, uids, NULL, remove_contacts_cb, uids);
 
145
 
 
146
        start_main_loop (NULL, NULL);
 
147
 
 
148
        g_slist_foreach (uids, (GFunc) g_free, NULL);
 
149
        g_slist_free (uids);
 
150
 
 
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);
 
154
                return 1;
 
155
        }
 
156
 
 
157
        g_object_unref (book_client);
 
158
 
 
159
        return get_main_loop_stop_result ();
 
160
}