summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Reitter <treitter@gmail.com>2009-12-11 11:58:55 -0800
committerTravis Reitter <treitter@gmail.com>2009-12-11 16:32:07 -0800
commit73639097cca498c10ca3d9a805c8b923b1e8091c (patch)
treeb7559459c8759184bae28f7f859349d28d8873fa
parentab30df78aebea4b2ee8400b0ae60a9f0ea1b524f (diff)
downloadevolution-data-server-73639097cca498c10ca3d9a805c8b923b1e8091c.tar.gz
Port the e-book 'getBookView' method to gdbus and clean up its regression test to fit the other well-formed tests.
-rw-r--r--addressbook/libebook/e-book.c13
-rw-r--r--addressbook/libebook/e-data-book-gdbus-bindings.h56
-rw-r--r--addressbook/tests/ebook/Makefile.am6
-rw-r--r--addressbook/tests/ebook/ebook-test-utils.c54
-rw-r--r--addressbook/tests/ebook/ebook-test-utils.h11
-rw-r--r--addressbook/tests/ebook/test-ebook-get-book-view.c129
-rw-r--r--addressbook/tests/ebook/test-ebook-view.c99
7 files changed, 261 insertions, 107 deletions
diff --git a/addressbook/libebook/e-book.c b/addressbook/libebook/e-book.c
index 8f55cc55e..5c48b7e54 100644
--- a/addressbook/libebook/e-book.c
+++ b/addressbook/libebook/e-book.c
@@ -1263,12 +1263,12 @@ e_book_get_book_view (EBook *book,
gboolean ret = TRUE;
e_return_error_if_fail (E_IS_BOOK (book), E_BOOK_ERROR_INVALID_ARG);
- e_return_error_if_fail (book->priv->proxy, E_BOOK_ERROR_REPOSITORY_OFFLINE);
+ e_return_error_if_fail (book->priv->gdbus_proxy, E_BOOK_ERROR_REPOSITORY_OFFLINE);
sexp = e_book_query_to_string (query);
LOCK_CONN ();
- if (!org_gnome_evolution_dataserver_addressbook_Book_get_book_view (book->priv->proxy, sexp, max_results, &view_path, &err)) {
+ if (!e_data_book_gdbus_get_book_view_sync (book->priv->gdbus_proxy, sexp, max_results, &view_path, &err)) {
UNLOCK_CONN ();
*book_view = NULL;
g_free (sexp);
@@ -1295,7 +1295,10 @@ e_book_get_book_view (EBook *book,
}
static void
-get_book_view_reply (DBusGProxy *proxy, gchar *view_path, GError *error, gpointer user_data)
+get_book_view_reply (GDBusProxy *proxy,
+ gchar *view_path,
+ GError *error,
+ gpointer user_data)
{
AsyncData *data = user_data;
GError *err = NULL;
@@ -1354,7 +1357,7 @@ e_book_async_get_book_view (EBook *book,
gchar *sexp;
e_return_async_error_val_if_fail (E_IS_BOOK (book), E_BOOK_ERROR_INVALID_ARG);
- e_return_async_error_val_if_fail (book->priv->proxy, E_BOOK_ERROR_REPOSITORY_OFFLINE);
+ e_return_async_error_val_if_fail (book->priv->gdbus_proxy, E_BOOK_ERROR_REPOSITORY_OFFLINE);
e_return_async_error_val_if_fail (query, E_BOOK_ERROR_INVALID_ARG);
data = g_slice_new0 (AsyncData);
@@ -1365,7 +1368,7 @@ e_book_async_get_book_view (EBook *book,
sexp = e_book_query_to_string (query);
LOCK_CONN ();
- org_gnome_evolution_dataserver_addressbook_Book_get_book_view_async (book->priv->proxy, sexp, max_results, get_book_view_reply, data);
+ e_data_book_gdbus_get_book_view (book->priv->gdbus_proxy, sexp, max_results, get_book_view_reply, data);
UNLOCK_CONN ();
g_free (sexp);
diff --git a/addressbook/libebook/e-data-book-gdbus-bindings.h b/addressbook/libebook/e-data-book-gdbus-bindings.h
index 248bb8a91..6d12559e6 100644
--- a/addressbook/libebook/e-data-book-gdbus-bindings.h
+++ b/addressbook/libebook/e-data-book-gdbus-bindings.h
@@ -586,4 +586,60 @@ e_data_book_gdbus_remove_contacts (GDBusProxy *proxy,
g_dbus_proxy_invoke_method (proxy, "removeContacts", parameters, -1, NULL, (GAsyncReadyCallback) remove_contacts_cb, closure);
}
+static gboolean
+e_data_book_gdbus_get_book_view_sync (GDBusProxy *proxy,
+ const char *IN_query,
+ const guint IN_max_results,
+ char **OUT_view,
+ GError **error)
+{
+ GVariant *parameters;
+ GVariant *retvals;
+
+ parameters = g_variant_new ("(su)", IN_query, IN_max_results);
+ retvals = g_dbus_proxy_invoke_method_sync (proxy, "getBookView", parameters, -1, NULL, error);
+
+ return demarshal_retvals__OBJPATH (retvals, OUT_view);
+}
+
+static void
+get_book_view_cb (GDBusProxy *proxy,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ Closure *closure = user_data;
+ GVariant *retvals;
+ GError *error = NULL;
+ char *OUT_view = NULL;
+
+ retvals = g_dbus_proxy_invoke_method_finish (proxy, result, &error);
+ if (retvals) {
+ if (!demarshal_retvals__OBJPATH (retvals, &OUT_view)) {
+ error = g_error_new (E_BOOK_ERROR, E_BOOK_ERROR_CORBA_EXCEPTION, "demarshalling results for Book method 'getBookView'");
+ }
+ }
+
+ (*(reply__STRING) closure->cb) (proxy, OUT_view, error, closure->user_data);
+ closure_free (closure);
+}
+
+static void
+e_data_book_gdbus_get_book_view (GDBusProxy *proxy,
+ const char *IN_query,
+ const guint IN_max_results,
+ reply__STRING callback,
+ gpointer user_data)
+{
+ GVariant *parameters;
+ Closure *closure;
+
+ parameters = g_variant_new ("(su)", IN_query, IN_max_results);
+
+ closure = g_slice_new (Closure);
+ closure->cb = G_CALLBACK (callback);
+ closure->user_data = user_data;
+
+ g_dbus_proxy_invoke_method (proxy, "getBookView", parameters, -1, NULL, (GAsyncReadyCallback) get_book_view_cb, closure);
+}
+
G_END_DECLS
diff --git a/addressbook/tests/ebook/Makefile.am b/addressbook/tests/ebook/Makefile.am
index 262b02172..5a476dedf 100644
--- a/addressbook/tests/ebook/Makefile.am
+++ b/addressbook/tests/ebook/Makefile.am
@@ -30,6 +30,7 @@ TESTS = \
test-ebook-get-supported-auth-methods \
test-ebook-add-contact \
test-ebook-get-contact \
+ test-ebook-get-book-view \
test-ebook-commit-contact \
test-ebook-remove-contact \
test-ebook-remove-contact-by-id \
@@ -43,7 +44,6 @@ noinst_PROGRAMS = \
test-date \
test-ebook \
test-ebook-async \
- test-ebook-view \
test-nonexistent-id \
test-photo \
test-query \
@@ -71,6 +71,8 @@ test_ebook_add_contact_LDADD=$(TEST_LIBS)
test_ebook_add_contact_CPPFLAGS=$(TEST_CPPFLAGS)
test_ebook_commit_contact_LDADD=$(TEST_LIBS)
test_ebook_commit_contact_CPPFLAGS=$(TEST_CPPFLAGS)
+test_ebook_get_book_view_LDADD=$(TEST_LIBS)
+test_ebook_get_book_view_CPPFLAGS=$(TEST_CPPFLAGS)
test_ebook_get_contact_LDADD=$(TEST_LIBS)
test_ebook_get_contact_CPPFLAGS=$(TEST_CPPFLAGS)
test_ebook_get_required_fields_LDADD=$(TEST_LIBS)
@@ -89,8 +91,6 @@ test_ebook_remove_contact_by_id_LDADD=$(TEST_LIBS)
test_ebook_remove_contact_by_id_CPPFLAGS=$(TEST_CPPFLAGS)
test_ebook_remove_contacts_LDADD=$(TEST_LIBS)
test_ebook_remove_contacts_CPPFLAGS=$(TEST_CPPFLAGS)
-test_ebook_view_LDADD=$(TEST_LIBS)
-test_ebook_view_CPPFLAGS=$(TEST_CPPFLAGS)
test_changes_LDADD=$(TEST_LIBS)
test_changes_CPPFLAGS=$(TEST_CPPFLAGS)
test_categories_LDADD=$(TEST_LIBS)
diff --git a/addressbook/tests/ebook/ebook-test-utils.c b/addressbook/tests/ebook/ebook-test-utils.c
index 46dada9ac..dc8d57158 100644
--- a/addressbook/tests/ebook/ebook-test-utils.c
+++ b/addressbook/tests/ebook/ebook-test-utils.c
@@ -697,3 +697,57 @@ ebook_test_utils_book_async_remove (EBook *book,
exit(1);
}
}
+
+void
+ebook_test_utils_book_get_book_view (EBook *book,
+ EBookQuery *query,
+ EBookView **view)
+{
+ GError *error = NULL;
+
+ if (!e_book_get_book_view (book, query, NULL, -1, view, &error)) {
+ const char *uri;
+
+ uri = e_book_get_uri (book);
+
+ g_warning ("failed to get view for addressbook: `%s': %s", uri,
+ error->message);
+ exit(1);
+ }
+}
+
+static void
+get_book_view_cb (EBook *book,
+ EBookStatus status,
+ EBookView *view,
+ EBookTestClosure *closure)
+{
+ if (status != E_BOOK_ERROR_OK) {
+ g_warning ("failed to asynchronously get book view for the "
+ "book: status %d", status);
+ exit (1);
+ }
+
+ closure->view = view;
+
+ g_print ("successfully asynchronously retrieved the book view\n");
+ if (closure)
+ (*closure->cb) (closure);
+}
+
+void
+ebook_test_utils_book_async_get_book_view (EBook *book,
+ EBookQuery *query,
+ GSourceFunc callback,
+ gpointer user_data)
+{
+ EBookTestClosure *closure;
+
+ closure = g_new0 (EBookTestClosure, 1);
+ closure->cb = callback;
+ closure->user_data = user_data;
+ if (e_book_async_get_book_view (book, query, NULL, -1, (EBookBookViewCallback) get_book_view_cb, closure)) {
+ g_warning ("failed to set up book view retrieval");
+ exit(1);
+ }
+}
diff --git a/addressbook/tests/ebook/ebook-test-utils.h b/addressbook/tests/ebook/ebook-test-utils.h
index c6d9d088d..e1d12b378 100644
--- a/addressbook/tests/ebook/ebook-test-utils.h
+++ b/addressbook/tests/ebook/ebook-test-utils.h
@@ -31,6 +31,7 @@
typedef struct {
GSourceFunc cb;
gpointer user_data;
+ EBookView *view;
EList *list;
} EBookTestClosure;
@@ -137,4 +138,14 @@ ebook_test_utils_book_async_remove (EBook *book,
GSourceFunc callback,
gpointer user_data);
+void
+ebook_test_utils_book_get_book_view (EBook *book,
+ EBookQuery *query,
+ EBookView **view);
+void
+ebook_test_utils_book_async_get_book_view (EBook *book,
+ EBookQuery *query,
+ GSourceFunc callback,
+ gpointer user_data);
+
#endif /* _EBOOK_TEST_UTILS_H */
diff --git a/addressbook/tests/ebook/test-ebook-get-book-view.c b/addressbook/tests/ebook/test-ebook-get-book-view.c
new file mode 100644
index 000000000..8fa1ba7df
--- /dev/null
+++ b/addressbook/tests/ebook/test-ebook-get-book-view.c
@@ -0,0 +1,129 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libebook/e-book.h>
+
+#include "ebook-test-utils.h"
+
+static GMainLoop *loop;
+
+static void
+print_contact (EContact *contact)
+{
+ GList *emails, *e;
+
+ g_print ("Contact: %s\n", (gchar *)e_contact_get_const (contact, E_CONTACT_FULL_NAME));
+ g_print ("UID: %s\n", (gchar *)e_contact_get_const (contact, E_CONTACT_UID));
+ g_print ("Email addresses:\n");
+
+ emails = e_contact_get (contact, E_CONTACT_EMAIL);
+ for (e = emails; e; e = e->next) {
+ g_print ("\t%s\n", (gchar *)e->data);
+ }
+ g_list_foreach (emails, (GFunc)g_free, NULL);
+ g_list_free (emails);
+
+ g_print ("\n");
+}
+
+static void
+contacts_added (EBookView *book_view, const GList *contacts)
+{
+ GList *l;
+
+ for (l = (GList*)contacts; l; l = l->next) {
+ print_contact (l->data);
+ }
+}
+
+static void
+contacts_removed (EBookView *book_view, const GList *ids)
+{
+ GList *l;
+
+ for (l = (GList*)ids; l; l = l->next) {
+ g_print ("Removed contact: %s\n", (gchar *)l->data);
+ }
+}
+
+static void
+sequence_complete (EBookView *book_view, EBookViewStatus status)
+{
+ g_main_loop_quit (loop);
+}
+
+static void
+setup_and_start_view (EBookView *view)
+{
+ g_signal_connect (view, "contacts_added", G_CALLBACK (contacts_added), NULL);
+ g_signal_connect (view, "contacts_removed", G_CALLBACK (contacts_removed), NULL);
+ g_signal_connect (view, "sequence_complete", G_CALLBACK (sequence_complete), NULL);
+
+ e_book_view_start (view);
+}
+
+static void
+get_book_view_cb (EBookTestClosure *closure)
+{
+ g_assert (closure->view);
+
+ setup_and_start_view (closure->view);
+}
+
+static void
+setup_book (EBook **book_out)
+{
+ EBook *book;
+
+ book = ebook_test_utils_book_new_temp (NULL);
+ ebook_test_utils_book_open (book, FALSE);
+
+ ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-1", NULL);
+ ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-2", NULL);
+ ebook_test_utils_book_add_contact_from_test_case_verify (book, "name-only", NULL);
+
+ *book_out = book;
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ EBook *book;
+ EBookQuery *query;
+ EBookView *view;
+
+ g_type_init ();
+
+ /*
+ * Sync version
+ */
+ setup_book (&book);
+ query = e_book_query_any_field_contains ("");
+ ebook_test_utils_book_get_book_view (book, query, &view);
+ setup_and_start_view (view);
+
+ g_print ("successfully set up the book view\n");
+
+ loop = g_main_loop_new (NULL, TRUE);
+ g_main_loop_run (loop);
+
+ e_book_query_unref (query);
+ ebook_test_utils_book_remove (book);
+
+ /*
+ * Async version
+ */
+ setup_book (&book);
+ query = e_book_query_any_field_contains ("");
+
+ loop = g_main_loop_new (NULL, TRUE);
+ ebook_test_utils_book_async_get_book_view (book, query,
+ (GSourceFunc) get_book_view_cb, loop);
+
+ g_main_loop_run (loop);
+
+ e_book_query_unref (query);
+ ebook_test_utils_book_remove (book);
+
+ return 0;
+}
diff --git a/addressbook/tests/ebook/test-ebook-view.c b/addressbook/tests/ebook/test-ebook-view.c
deleted file mode 100644
index d511c6379..000000000
--- a/addressbook/tests/ebook/test-ebook-view.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-
-#include <stdio.h>
-#include <libebook/e-book.h>
-
-static GMainLoop *loop;
-
-static void
-print_contact (EContact *contact)
-{
- GList *emails, *e;
-
- printf ("Contact: %s\n", (gchar *)e_contact_get_const (contact, E_CONTACT_FILE_AS));
- printf ("UID: %s\n", (gchar *)e_contact_get_const (contact, E_CONTACT_UID));
- printf ("Email addresses:\n");
-
- emails = e_contact_get (contact, E_CONTACT_EMAIL);
- for (e = emails; e; e = e->next) {
- printf ("\t%s\n", (gchar *)e->data);
- }
- g_list_foreach (emails, (GFunc)g_free, NULL);
- g_list_free (emails);
-
- printf ("\n");
-}
-
-static void
-contacts_added (EBookView *book_view, const GList *contacts)
-{
- GList *l;
-
- for (l = (GList*)contacts; l; l = l->next) {
- print_contact (l->data);
- }
-}
-
-static void
-contacts_removed (EBookView *book_view, const GList *ids)
-{
- GList *l;
-
- for (l = (GList*)ids; l; l = l->next) {
- printf ("Removed contact: %s\n", (gchar *)l->data);
- }
-}
-
-static void
-sequence_complete (EBookView *book_view, EBookViewStatus status)
-{
- printf ("sequence_complete (status == %d)\n", status);
-
- g_main_loop_quit (loop);
-}
-
-gint
-main (gint argc, gchar **argv)
-{
- EBook *book;
- gboolean status;
- EBookQuery *query;
- EBookView *view;
-
- g_type_init ();
- loop = g_main_loop_new (NULL, TRUE);
-
- /*
- ** the actual ebook foo
- */
-
- printf ("loading addressbook\n");
- book = e_book_new_system_addressbook (NULL);
- if (book == NULL) {
- printf ("failed to create local addressbook\n");
- exit(0);
- }
-
- status = e_book_open (book, FALSE, NULL);
- if (status == FALSE) {
- printf ("failed to open local addressbook\n");
- exit(0);
- }
-
- printf ("populating view\n");
- query = e_book_query_any_field_contains ("");
-
- status = e_book_get_book_view (book, query, NULL, -1, &view, NULL);
-
- e_book_query_unref (query);
-
- g_signal_connect (view, "contacts_added", G_CALLBACK (contacts_added), NULL);
- g_signal_connect (view, "contacts_removed", G_CALLBACK (contacts_removed), NULL);
- g_signal_connect (view, "sequence_complete", G_CALLBACK (sequence_complete), NULL);
-
- e_book_view_start (view);
-
- g_main_loop_run (loop);
-
- return 0;
-}