[evolution-data-server/treitter-client-gdbus] Port the e-book 'removeContacts' method to gdbus and add regression tests
- From: Travis Reitter <treitter src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-data-server/treitter-client-gdbus] Port the e-book 'removeContacts' method to gdbus and add regression tests
- Date: Thu, 10 Dec 2009 16:37:22 +0000 (UTC)
commit dba0083622a2a7a15d9a0d99efb26ba86ee1a997
Author: Travis Reitter <treitter gmail com>
Date: Wed Dec 9 09:45:58 2009 -0800
Port the e-book 'removeContacts' method to gdbus and add regression tests
addressbook/libebook/e-book.c | 17 ++--
addressbook/libebook/e-data-book-gdbus-bindings.h | 70 ++++++++++++++
addressbook/tests/ebook/Makefile.am | 3 +
addressbook/tests/ebook/data/vcards/name-only.vcf | 3 +
addressbook/tests/ebook/ebook-test-utils.c | 55 +++++++++++
addressbook/tests/ebook/ebook-test-utils.h | 9 ++
.../tests/ebook/test-ebook-commit-contact.c | 97 ++++++++++++++++++++
7 files changed, 247 insertions(+), 7 deletions(-)
---
diff --git a/addressbook/libebook/e-book.c b/addressbook/libebook/e-book.c
index e615697..cf96430 100644
--- a/addressbook/libebook/e-book.c
+++ b/addressbook/libebook/e-book.c
@@ -465,14 +465,17 @@ e_book_commit_contact (EBook *book,
vcard = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
LOCK_CONN ();
- org_gnome_evolution_dataserver_addressbook_Book_modify_contact (book->priv->proxy, vcard, &err);
+ e_data_book_gdbus_modify_contact_sync (book->priv->gdbus_proxy, vcard, &err);
+
UNLOCK_CONN ();
g_free (vcard);
return unwrap_gerror (err, error);
}
static void
-modify_contact_reply (DBusGProxy *proxy, GError *error, gpointer user_data)
+modify_contact_reply (GDBusProxy *proxy,
+ GError *error,
+ gpointer user_data)
{
AsyncData *data = user_data;
EBookCallback cb = data->callback;
@@ -497,10 +500,10 @@ modify_contact_reply (DBusGProxy *proxy, GError *error, gpointer user_data)
* Return value: %TRUE if the operation was started, %FALSE otherwise.
**/
guint
-e_book_async_commit_contact (EBook *book,
- EContact *contact,
- EBookCallback cb,
- gpointer closure)
+e_book_async_commit_contact (EBook *book,
+ EContact *contact,
+ EBookCallback cb,
+ gpointer closure)
{
gchar *vcard;
AsyncData *data;
@@ -517,7 +520,7 @@ e_book_async_commit_contact (EBook *book,
data->closure = closure;
LOCK_CONN ();
- org_gnome_evolution_dataserver_addressbook_Book_modify_contact_async (book->priv->proxy, vcard, modify_contact_reply, data);
+ e_data_book_gdbus_modify_contact (book->priv->gdbus_proxy, vcard, modify_contact_reply, data);
UNLOCK_CONN ();
g_free (vcard);
return 0;
diff --git a/addressbook/libebook/e-data-book-gdbus-bindings.h b/addressbook/libebook/e-data-book-gdbus-bindings.h
index e75c10e..1f4a7f8 100644
--- a/addressbook/libebook/e-data-book-gdbus-bindings.h
+++ b/addressbook/libebook/e-data-book-gdbus-bindings.h
@@ -415,6 +415,76 @@ e_data_book_gdbus_add_contact (GDBusProxy *proxy,
}
static gboolean
+modify_contact_demarshal_retvals (GVariant *retvals)
+{
+ gboolean success = TRUE;
+
+ if (retvals)
+ g_variant_unref (retvals);
+ else
+ success = FALSE;
+
+ return success;
+}
+
+static gboolean
+e_data_book_gdbus_modify_contact_sync (GDBusProxy *proxy,
+ const char *IN_vcard,
+ GError **error)
+
+{
+ GVariant *parameters;
+ GVariant *retvals;
+
+ parameters = g_variant_new ("(s)", IN_vcard);
+ retvals = g_dbus_proxy_invoke_method_sync (proxy, "modifyContact", parameters, -1, NULL, error);
+
+ return modify_contact_demarshal_retvals (retvals);
+}
+
+typedef void (*e_data_book_gdbus_modify_contact_reply) (GDBusProxy *proxy,
+ GError *error,
+ gpointer user_data);
+
+static void
+modify_contact_cb (GDBusProxy *proxy,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ Closure *closure = user_data;
+ GVariant *retvals;
+ GError *error = NULL;
+
+ retvals = g_dbus_proxy_invoke_method_finish (proxy, result, &error);
+ if (retvals) {
+ if (!modify_contact_demarshal_retvals (retvals)) {
+ error = g_error_new (E_BOOK_ERROR, E_BOOK_ERROR_CORBA_EXCEPTION, "demarshalling results for Book method 'modifyContact'");
+ }
+ }
+
+ (*(e_data_book_gdbus_modify_contact_reply) closure->cb) (proxy, error, closure->user_data);
+ closure_free (closure);
+}
+
+static void
+e_data_book_gdbus_modify_contact (GDBusProxy *proxy,
+ const char *IN_vcard,
+ e_data_book_gdbus_modify_contact_reply callback,
+ gpointer user_data)
+{
+ GVariant *parameters;
+ Closure *closure;
+
+ parameters = g_variant_new ("(s)", IN_vcard);
+
+ closure = g_slice_new (Closure);
+ closure->cb = G_CALLBACK (callback);
+ closure->user_data = user_data;
+
+ g_dbus_proxy_invoke_method (proxy, "modifyContact", parameters, -1, NULL, (GAsyncReadyCallback) modify_contact_cb, closure);
+}
+
+static gboolean
remove_contacts_demarshal_retvals (GVariant *retvals)
{
gboolean success = TRUE;
diff --git a/addressbook/tests/ebook/Makefile.am b/addressbook/tests/ebook/Makefile.am
index 48b29a8..171b5f3 100644
--- a/addressbook/tests/ebook/Makefile.am
+++ b/addressbook/tests/ebook/Makefile.am
@@ -28,6 +28,7 @@ noinst_PROGRAMS = \
test-ebook \
test-ebook-async \
test-ebook-add-contact \
+ test-ebook-commit-contact \
test-ebook-get-contact \
test-ebook-remove \
test-ebook-remove-contact \
@@ -59,6 +60,8 @@ test_ebook_async_LDADD=$(TEST_LIBS)
test_ebook_async_CPPFLAGS=$(TEST_CPPFLAGS)
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_contact_LDADD=$(TEST_LIBS)
test_ebook_get_contact_CPPFLAGS=$(TEST_CPPFLAGS)
test_ebook_remove_LDADD=$(TEST_LIBS)
diff --git a/addressbook/tests/ebook/data/vcards/name-only.vcf b/addressbook/tests/ebook/data/vcards/name-only.vcf
new file mode 100644
index 0000000..0566d7c
--- /dev/null
+++ b/addressbook/tests/ebook/data/vcards/name-only.vcf
@@ -0,0 +1,3 @@
+BEGIN:VCARD
+FN:John Doe
+END:VCARD
diff --git a/addressbook/tests/ebook/ebook-test-utils.c b/addressbook/tests/ebook/ebook-test-utils.c
index 5f37989..8efb722 100644
--- a/addressbook/tests/ebook/ebook-test-utils.c
+++ b/addressbook/tests/ebook/ebook-test-utils.c
@@ -134,6 +134,61 @@ ebook_test_utils_book_async_add_contact (EBook *book,
}
}
+void
+ebook_test_utils_book_commit_contact (EBook *book,
+ EContact *contact)
+{
+ GError *error = NULL;
+
+ if (!e_book_commit_contact (book, contact, &error)) {
+ const char *uid;
+ const char *uri;
+
+ uid = (const char*) e_contact_get_const (contact, E_CONTACT_UID);
+ uri = e_book_get_uri (book);
+ g_warning ("failed to commit changes to contact '%s' to addressbook: `%s': %s",
+ uid, uri, error->message);
+ exit(1);
+ }
+}
+
+static void
+commit_contact_cb (EBook *book,
+ EBookStatus status,
+ EBookTestClosure *closure)
+{
+ if (status != E_BOOK_ERROR_OK) {
+ g_warning ("failed to asynchronously commit the contact: "
+ "status %d", status);
+ exit (1);
+ }
+
+ g_print ("successfully asynchronously committed the contact to the "
+ "addressbook\n");
+ if (closure) {
+ (*closure->cb) (closure);
+ g_free (closure);
+ }
+}
+
+void
+ebook_test_utils_book_async_commit_contact (EBook *book,
+ EContact *contact,
+ GSourceFunc callback,
+ gpointer user_data)
+{
+ EBookTestClosure *closure;
+
+ closure = g_new0 (EBookTestClosure, 1);
+ closure->cb = callback;
+ closure->user_data = user_data;
+ if (e_book_async_commit_contact (book, contact,
+ (EBookCallback) commit_contact_cb, closure)) {
+ g_warning ("failed to set up contact commit");
+ exit(1);
+ }
+}
+
EContact*
ebook_test_utils_book_get_contact (EBook *book,
const char *uid)
diff --git a/addressbook/tests/ebook/ebook-test-utils.h b/addressbook/tests/ebook/ebook-test-utils.h
index 497109e..74dd96f 100644
--- a/addressbook/tests/ebook/ebook-test-utils.h
+++ b/addressbook/tests/ebook/ebook-test-utils.h
@@ -57,6 +57,15 @@ ebook_test_utils_book_async_add_contact (EBook *book,
GSourceFunc callback,
gpointer user_data);
+void
+ebook_test_utils_book_commit_contact (EBook *book,
+ EContact *contact);
+void
+ebook_test_utils_book_async_commit_contact (EBook *book,
+ EContact *contact,
+ GSourceFunc callback,
+ gpointer user_data);
+
EContact*
ebook_test_utils_book_get_contact (EBook *book,
const char *uid);
diff --git a/addressbook/tests/ebook/test-ebook-commit-contact.c b/addressbook/tests/ebook/test-ebook-commit-contact.c
new file mode 100644
index 0000000..fe181e8
--- /dev/null
+++ b/addressbook/tests/ebook/test-ebook-commit-contact.c
@@ -0,0 +1,97 @@
+/* -*- 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"
+
+#define EMAIL_ADD "foo bar com"
+
+static EBook *book;
+static char *uid;
+
+static void
+verify_precommit_and_prepare_contact (EContact *contact)
+{
+ EVCardAttribute *attr;
+
+ /* ensure there is no email address to begin with, then add one */
+ g_assert (!e_vcard_get_attribute (E_VCARD (contact), EVC_EMAIL));
+ attr = e_vcard_attribute_new (NULL, EVC_EMAIL);
+ e_vcard_add_attribute_with_value (E_VCARD (contact), attr, EMAIL_ADD);
+}
+
+static void
+verify_commit (EContact *contact)
+{
+ EVCardAttribute *attr;
+ char *email_value;
+
+ g_assert ((attr = e_vcard_get_attribute (E_VCARD (contact), EVC_EMAIL)));
+ g_assert (e_vcard_attribute_is_single_valued (attr));
+ email_value = e_vcard_attribute_get_value (attr);
+ g_assert (!g_strcmp0 (email_value, EMAIL_ADD));
+}
+
+static gboolean
+commit_verify_cb (EBookTestClosure *closure)
+{
+ EContact *contact;
+
+ contact = ebook_test_utils_book_get_contact (book, uid);
+ verify_commit (contact);
+
+ g_main_loop_quit ((GMainLoop*) (closure->user_data));
+
+ return FALSE;
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ GMainLoop *loop;
+ EContact *contact;
+
+ g_type_init ();
+
+ /*
+ * Setup
+ */
+ book = ebook_test_utils_book_new_temp (NULL);
+ ebook_test_utils_book_open (book, FALSE);
+
+ /*
+ * Sync version
+ */
+ uid = ebook_test_utils_book_add_contact_from_test_case_verify (book, "name-only", &contact);
+ verify_precommit_and_prepare_contact (contact);
+ ebook_test_utils_book_commit_contact (book, contact);
+
+ verify_commit (contact);
+
+ g_print ("successfully committed changes to contact contact '%s'\n", uid);
+ g_object_unref (contact);
+ g_free (uid);
+
+ ebook_test_utils_book_remove (book);
+
+ /*
+ * Async version
+ */
+ book = ebook_test_utils_book_new_temp (NULL);
+ ebook_test_utils_book_open (book, FALSE);
+ uid = ebook_test_utils_book_add_contact_from_test_case_verify (book, "name-only", &contact);
+
+ verify_precommit_and_prepare_contact (contact);
+
+ loop = g_main_loop_new (NULL, TRUE);
+ ebook_test_utils_book_async_commit_contact (book, contact,
+ (GSourceFunc) commit_verify_cb, loop);
+
+ g_main_loop_run (loop);
+
+ g_free (uid);
+ ebook_test_utils_book_remove (book);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]