~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to addressbook/tests/ebook/test-ebook-get-book-view.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

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 <stdlib.h>
 
4
#include <libebook/e-book.h>
 
5
 
 
6
#include "ebook-test-utils.h"
 
7
 
 
8
static GMainLoop *loop;
 
9
 
 
10
static void
 
11
print_contact (EContact *contact)
 
12
{
 
13
        GList *emails, *e;
 
14
 
 
15
        test_print ("Contact: %s\n", (gchar *)e_contact_get_const (contact, E_CONTACT_FULL_NAME));
 
16
        test_print ("UID: %s\n", (gchar *)e_contact_get_const (contact, E_CONTACT_UID));
 
17
        test_print ("Email addresses:\n");
 
18
 
 
19
        emails = e_contact_get (contact, E_CONTACT_EMAIL);
 
20
        for (e = emails; e; e = e->next) {
 
21
                test_print ("\t%s\n",  (gchar *)e->data);
 
22
        }
 
23
        g_list_foreach (emails, (GFunc)g_free, NULL);
 
24
        g_list_free (emails);
 
25
 
 
26
        test_print ("\n");
 
27
}
 
28
 
 
29
static void
 
30
contacts_added (EBookView *book_view, const GList *contacts)
 
31
{
 
32
        GList *l;
 
33
 
 
34
        for (l = (GList*)contacts; l; l = l->next) {
 
35
                print_contact (l->data);
 
36
        }
 
37
}
 
38
 
 
39
static void
 
40
contacts_removed (EBookView *book_view, const GList *ids)
 
41
{
 
42
        GList *l;
 
43
 
 
44
        for (l = (GList*)ids; l; l = l->next) {
 
45
                test_print ("Removed contact: %s\n", (gchar *)l->data);
 
46
        }
 
47
}
 
48
 
 
49
static void
 
50
sequence_complete (EBookView *book_view, EBookViewStatus status)
 
51
{
 
52
        e_book_view_stop (book_view);
 
53
        g_object_unref (book_view);
 
54
        g_main_loop_quit (loop);
 
55
}
 
56
 
 
57
static void
 
58
setup_and_start_view (EBookView *view)
 
59
{
 
60
        g_signal_connect (view, "contacts_added", G_CALLBACK (contacts_added), NULL);
 
61
        g_signal_connect (view, "contacts_removed", G_CALLBACK (contacts_removed), NULL);
 
62
        g_signal_connect (view, "sequence_complete", G_CALLBACK (sequence_complete), NULL);
 
63
 
 
64
        e_book_view_start (view);
 
65
}
 
66
 
 
67
static void
 
68
get_book_view_cb (EBookTestClosure *closure)
 
69
{
 
70
        g_assert (closure->view);
 
71
 
 
72
        setup_and_start_view (closure->view);
 
73
}
 
74
 
 
75
static void
 
76
setup_book (EBook     **book_out)
 
77
{
 
78
        EBook *book;
 
79
 
 
80
        book = ebook_test_utils_book_new_temp (NULL);
 
81
        ebook_test_utils_book_open (book, FALSE);
 
82
 
 
83
        ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-1", NULL);
 
84
        ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-2", NULL);
 
85
        ebook_test_utils_book_add_contact_from_test_case_verify (book, "name-only", NULL);
 
86
 
 
87
        *book_out = book;
 
88
}
 
89
 
 
90
gint
 
91
main (gint argc, gchar **argv)
 
92
{
 
93
        EBook *book;
 
94
        EBookQuery *query;
 
95
        EBookView *view;
 
96
 
 
97
        g_type_init ();
 
98
 
 
99
        /*
 
100
         * Sync version
 
101
         */
 
102
        setup_book (&book);
 
103
        query = e_book_query_any_field_contains ("");
 
104
        ebook_test_utils_book_get_book_view (book, query, &view);
 
105
        setup_and_start_view (view);
 
106
 
 
107
        test_print ("successfully set up the book view\n");
 
108
 
 
109
        loop = g_main_loop_new (NULL, TRUE);
 
110
        g_main_loop_run (loop);
 
111
 
 
112
        e_book_query_unref (query);
 
113
        ebook_test_utils_book_remove (book);
 
114
 
 
115
        /*
 
116
         * Async version
 
117
         */
 
118
        setup_book (&book);
 
119
        query = e_book_query_any_field_contains ("");
 
120
 
 
121
        loop = g_main_loop_new (NULL, TRUE);
 
122
        ebook_test_utils_book_async_get_book_view (book, query,
 
123
                        (GSourceFunc) get_book_view_cb, loop);
 
124
 
 
125
        g_main_loop_run (loop);
 
126
 
 
127
        e_book_query_unref (query);
 
128
        ebook_test_utils_book_remove (book);
 
129
 
 
130
        return 0;
 
131
}