[evolution-data-server/treitter-client-gdbus] Port the e-book 'removeContacts' method to gdbus and add regression tests



commit dc61592a790d2f1463d5b0f5dce8f46fb5a65da8
Author: Travis Reitter <treitter gmail com>
Date:   Tue Dec 8 12:48:26 2009 -0800

    Port the e-book 'removeContacts' method to gdbus and add regression tests

 addressbook/libebook/e-book.c                      |   24 ++-
 addressbook/libebook/e-data-book-gdbus-bindings.h  |   72 ++++++++
 addressbook/tests/ebook/Makefile.am                |    9 +
 addressbook/tests/ebook/data/vcards/simple-1.vcf   |    4 +
 addressbook/tests/ebook/data/vcards/simple-2.vcf   |    4 +
 addressbook/tests/ebook/ebook-test-utils.c         |  192 ++++++++++++++++++++
 addressbook/tests/ebook/ebook-test-utils.h         |   32 ++++
 addressbook/tests/ebook/test-ebook-add-contact.c   |   23 +--
 addressbook/tests/ebook/test-ebook-get-contact.c   |   25 +---
 .../tests/ebook/test-ebook-remove-contact-by-id.c  |   40 ++++
 .../tests/ebook/test-ebook-remove-contact.c        |   59 ++++++
 .../tests/ebook/test-ebook-remove-contacts.c       |   71 +++++++
 12 files changed, 501 insertions(+), 54 deletions(-)
---
diff --git a/addressbook/libebook/e-book.c b/addressbook/libebook/e-book.c
index fb1db0c..e615697 100644
--- a/addressbook/libebook/e-book.c
+++ b/addressbook/libebook/e-book.c
@@ -1012,14 +1012,16 @@ e_book_remove_contact (EBook       *book,
 	l[1] = NULL;
 
 	LOCK_CONN ();
-	org_gnome_evolution_dataserver_addressbook_Book_remove_contacts (book->priv->proxy, l, &err);
+	e_data_book_gdbus_remove_contacts_sync (book->priv->gdbus_proxy, l, &err);
 	UNLOCK_CONN ();
 
 	return unwrap_gerror (err, error);
 }
 
 static void
-remove_contact_reply (DBusGProxy *proxy, GError *error, gpointer user_data)
+remove_contact_reply (GDBusProxy *proxy,
+		      GError     *error,
+		      gpointer    user_data)
 {
 	AsyncData *data = user_data;
 	EBookCallback cb = data->callback;
@@ -1059,7 +1061,7 @@ e_book_remove_contacts (EBook    *book,
 	l = flatten_stringlist (ids);
 
 	LOCK_CONN ();
-	org_gnome_evolution_dataserver_addressbook_Book_remove_contacts (book->priv->proxy, (const gchar **) l, &err);
+	e_data_book_gdbus_remove_contacts_sync (book->priv->gdbus_proxy, (const gchar **) l, &err);
 	UNLOCK_CONN ();
 
 	g_free (l);
@@ -1100,14 +1102,16 @@ e_book_async_remove_contact (EBook                 *book,
 	data->closure = closure;
 
 	LOCK_CONN ();
-	org_gnome_evolution_dataserver_addressbook_Book_remove_contacts_async (book->priv->proxy, l, remove_contact_reply, data);
+	e_data_book_gdbus_remove_contacts (book->priv->gdbus_proxy, l, remove_contact_reply, data);
 	UNLOCK_CONN ();
 
 	return 0;
  }
 
 static void
-remove_contact_by_id_reply (DBusGProxy *proxy, GError *error, gpointer user_data)
+remove_contact_by_id_reply (GDBusProxy *proxy,
+		            GError     *error,
+			    gpointer    user_data)
 {
 	AsyncData *data = user_data;
 	EBookCallback cb = data->callback;
@@ -1152,14 +1156,16 @@ e_book_async_remove_contact_by_id (EBook                 *book,
 	data->closure = closure;
 
 	LOCK_CONN ();
-	org_gnome_evolution_dataserver_addressbook_Book_remove_contacts_async (book->priv->proxy, l, remove_contact_by_id_reply, data);
+	e_data_book_gdbus_remove_contacts (book->priv->gdbus_proxy, l, remove_contact_by_id_reply, data);
 	UNLOCK_CONN ();
 
 	return 0;
 }
 
 static void
-remove_contacts_reply (DBusGProxy *proxy, GError *error, gpointer user_data)
+remove_contacts_reply (GDBusProxy *proxy,
+		       GError     *error,
+		       gpointer    user_data)
 {
 	AsyncData *data = user_data;
 	EBookCallback cb = data->callback;
@@ -1195,7 +1201,7 @@ e_book_async_remove_contacts (EBook                 *book,
 	gchar **l;
 
 	e_return_async_error_if_fail (E_IS_BOOK (book), E_BOOK_ERROR_INVALID_ARG);
-	e_return_async_error_if_fail (book->priv->proxy, E_BOOK_ERROR_REPOSITORY_OFFLINE);
+	e_return_async_error_if_fail (book->priv->gdbus_proxy, E_BOOK_ERROR_REPOSITORY_OFFLINE);
 
 	if (ids == NULL) {
 		if (cb)
@@ -1211,7 +1217,7 @@ e_book_async_remove_contacts (EBook                 *book,
 	data->closure = closure;
 
 	LOCK_CONN ();
-	org_gnome_evolution_dataserver_addressbook_Book_remove_contacts_async (book->priv->proxy, (const gchar **) l, remove_contacts_reply, data);
+	e_data_book_gdbus_remove_contacts (book->priv->gdbus_proxy, (const gchar **) l, remove_contacts_reply, data);
 	UNLOCK_CONN ();
 
 	g_free (l);
diff --git a/addressbook/libebook/e-data-book-gdbus-bindings.h b/addressbook/libebook/e-data-book-gdbus-bindings.h
index f097fd3..e75c10e 100644
--- a/addressbook/libebook/e-data-book-gdbus-bindings.h
+++ b/addressbook/libebook/e-data-book-gdbus-bindings.h
@@ -414,5 +414,77 @@ e_data_book_gdbus_add_contact (GDBusProxy                          *proxy,
         g_dbus_proxy_invoke_method (proxy, "addContact", parameters, -1, NULL, (GAsyncReadyCallback) add_contact_cb, closure);
 }
 
+static gboolean
+remove_contacts_demarshal_retvals (GVariant *retvals)
+{
+	gboolean success = TRUE;
+
+	if (retvals)
+		g_variant_unref (retvals);
+	else
+		success = FALSE;
+
+	return success;
+}
+
+static gboolean
+e_data_book_gdbus_remove_contacts_sync (GDBusProxy  *proxy,
+					const char **IN_uids,
+					GError     **error)
+
+{
+	GVariant *parameters;
+	GVariant *retvals;
+
+	g_return_val_if_fail (IN_uids && IN_uids[0], FALSE);
+
+	parameters = g_variant_new ("(^as)", IN_uids);
+
+	retvals = g_dbus_proxy_invoke_method_sync (proxy, "removeContacts", parameters, -1, NULL, error);
+
+	return remove_contacts_demarshal_retvals (retvals);
+}
+
+typedef void (*e_data_book_gdbus_remove_contacts_reply) (GDBusProxy *proxy,
+						         GError     *error,
+						         gpointer    user_data);
+
+static void
+remove_contacts_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 (!remove_contacts_demarshal_retvals (retvals)) {
+                        error = g_error_new (E_BOOK_ERROR, E_BOOK_ERROR_CORBA_EXCEPTION, "demarshalling results for Book method 'removeContacts'");
+                }
+        }
+
+        (*(e_data_book_gdbus_remove_contacts_reply) closure->cb) (proxy,  error, closure->user_data);
+        closure_free (closure);
+}
+
+static void
+e_data_book_gdbus_remove_contacts (GDBusProxy                               *proxy,
+			           const char                              **IN_uids,
+			           e_data_book_gdbus_remove_contacts_reply   callback,
+			           gpointer                                  user_data)
+{
+        GVariant *parameters;
+        Closure *closure;
+
+        parameters = g_variant_new ("(^as)", IN_uids);
+
+        closure = g_slice_new (Closure);
+        closure->cb = G_CALLBACK (callback);
+        closure->user_data = user_data;
+
+        g_dbus_proxy_invoke_method (proxy, "removeContacts", parameters, -1, NULL, (GAsyncReadyCallback) remove_contacts_cb, closure);
+}
 
 G_END_DECLS
diff --git a/addressbook/tests/ebook/Makefile.am b/addressbook/tests/ebook/Makefile.am
index cd7c7f2..48b29a8 100644
--- a/addressbook/tests/ebook/Makefile.am
+++ b/addressbook/tests/ebook/Makefile.am
@@ -30,6 +30,9 @@ noinst_PROGRAMS = \
 	test-ebook-add-contact               \
 	test-ebook-get-contact               \
 	test-ebook-remove                    \
+	test-ebook-remove-contact            \
+	test-ebook-remove-contact-by-id      \
+	test-ebook-remove-contacts           \
 	test-ebook-view                      \
 	test-nonexistent-id                  \
 	test-photo                           \
@@ -60,6 +63,12 @@ test_ebook_get_contact_LDADD=$(TEST_LIBS)
 test_ebook_get_contact_CPPFLAGS=$(TEST_CPPFLAGS)
 test_ebook_remove_LDADD=$(TEST_LIBS)
 test_ebook_remove_CPPFLAGS=$(TEST_CPPFLAGS)
+test_ebook_remove_contact_LDADD=$(TEST_LIBS)
+test_ebook_remove_contact_CPPFLAGS=$(TEST_CPPFLAGS)
+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)
diff --git a/addressbook/tests/ebook/data/vcards/simple-1.vcf b/addressbook/tests/ebook/data/vcards/simple-1.vcf
new file mode 100644
index 0000000..ea6383c
--- /dev/null
+++ b/addressbook/tests/ebook/data/vcards/simple-1.vcf
@@ -0,0 +1,4 @@
+BEGIN:VCARD
+FN:Foo Bar
+EMAIL;INTERNET:foo bar example org
+END:VCARD
diff --git a/addressbook/tests/ebook/data/vcards/simple-2.vcf b/addressbook/tests/ebook/data/vcards/simple-2.vcf
new file mode 100644
index 0000000..4fa3707
--- /dev/null
+++ b/addressbook/tests/ebook/data/vcards/simple-2.vcf
@@ -0,0 +1,4 @@
+BEGIN:VCARD
+FN:Baz Qux
+EMAIL;INTERNET:baz qux example com
+END:VCARD
diff --git a/addressbook/tests/ebook/ebook-test-utils.c b/addressbook/tests/ebook/ebook-test-utils.c
index 649ee11..5f37989 100644
--- a/addressbook/tests/ebook/ebook-test-utils.c
+++ b/addressbook/tests/ebook/ebook-test-utils.c
@@ -32,6 +32,52 @@ ebook_test_utils_new_vcard_from_test_case (const char *case_name)
         return vcard;
 }
 
+char*
+ebook_test_utils_book_add_contact_from_test_case_verify (EBook       *book,
+                                                         const char  *case_name,
+                                                         EContact   **contact)
+{
+        char *vcard;
+        EContact *contact_orig;
+        EContact *contact_final;
+        char *uid;
+
+        vcard = ebook_test_utils_new_vcard_from_test_case (case_name);
+        contact_orig = e_contact_new_from_vcard (vcard);
+        uid = g_strdup (ebook_test_utils_book_add_contact (book, contact_orig));
+        contact_final = ebook_test_utils_book_get_contact (book, uid);
+
+        /* verify the contact was added "successfully" (not thorough) */
+        g_assert (ebook_test_utils_contacts_are_equal_shallow (contact_orig, contact_final));
+
+        if (contact)
+                *contact = g_object_ref (contact_final);
+
+        return uid;
+}
+
+/* This is not a thorough comparison (which is difficult, assuming we give the
+ * back-ends leniency in implementation) and is best suited for simple tests */
+gboolean
+ebook_test_utils_contacts_are_equal_shallow (EContact *a,
+                                             EContact *b)
+
+{
+        const char *uid_a, *uid_b;
+
+        /* Avoid warnings if one or more are NULL, to make this function
+         * "NULL-friendly" */
+        if (!a && !b)
+                return TRUE;
+        if (!E_IS_CONTACT (a) || !E_IS_CONTACT (b))
+                return FALSE;
+
+        uid_a = e_contact_get_const (a, E_CONTACT_UID);
+        uid_b = e_contact_get_const (b, E_CONTACT_UID);
+
+        return g_strcmp0 (uid_a, uid_b) == 0;
+}
+
 const char*
 ebook_test_utils_book_add_contact (EBook    *book,
                                    EContact *contact)
@@ -150,6 +196,152 @@ ebook_test_utils_book_async_get_contact (EBook       *book,
         }
 }
 
+void
+ebook_test_utils_book_remove_contact (EBook      *book,
+                                      const char *uid)
+{
+        GError *error = NULL;
+
+        if (!e_book_remove_contact (book, uid, &error)) {
+                const char *uri;
+
+                uri = e_book_get_uri (book);
+                g_warning ("failed to remove contact '%s' from addressbook: `%s': %s",
+                                uid, uri, error->message);
+                exit(1);
+        }
+}
+
+static void
+remove_contact_cb (EBook            *book,
+                   EBookStatus       status,
+                   EBookTestClosure *closure)
+{
+        if (status != E_BOOK_ERROR_OK) {
+                g_warning ("failed to asynchronously remove the contact: "
+                                "status %d", status);
+                exit (1);
+        }
+
+        g_print ("successfully asynchronously removed the contact\n");
+
+        if (closure) {
+                (*closure->cb) (closure->user_data);
+                g_free (closure);
+        }
+}
+
+void
+ebook_test_utils_book_async_remove_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_remove_contact (book, contact,
+                                (EBookCallback) remove_contact_cb,
+                                closure)) {
+                g_warning ("failed to set up async removeContacts (for a single contact)");
+                exit(1);
+        }
+}
+
+static void
+remove_contact_by_id_cb (EBook            *book,
+                         EBookStatus       status,
+                         EBookTestClosure *closure)
+{
+        if (status != E_BOOK_ERROR_OK) {
+                g_warning ("failed to asynchronously remove the contact by id: "
+                                "status %d", status);
+                exit (1);
+        }
+
+        g_print ("successfully asynchronously removed the contact by id\n");
+
+        if (closure) {
+                (*closure->cb) (closure->user_data);
+                g_free (closure);
+        }
+}
+
+void
+ebook_test_utils_book_async_remove_contact_by_id (EBook       *book,
+                                                  const char  *uid,
+                                                  GSourceFunc  callback,
+                                                  gpointer     user_data)
+{
+        EBookTestClosure *closure;
+
+        closure = g_new0 (EBookTestClosure, 1);
+        closure->cb = callback;
+        closure->user_data = user_data;
+        if (e_book_async_remove_contact_by_id (book, uid,
+                                (EBookCallback) remove_contact_by_id_cb,
+                                closure)) {
+                g_warning ("failed to set up async removeContacts (by id)");
+                exit(1);
+        }
+}
+
+void
+ebook_test_utils_book_remove_contacts (EBook *book,
+                                       GList *ids)
+{
+        GError *error = NULL;
+
+        if (!e_book_remove_contacts (book, ids, &error)) {
+                const char *uri;
+
+                uri = e_book_get_uri (book);
+                g_warning ("failed to remove contacts from addressbook: `%s': %s",
+                                uri, error->message);
+                exit(1);
+        }
+}
+
+static void
+remove_contacts_cb (EBook            *book,
+                    EBookStatus       status,
+                    EBookTestClosure *closure)
+{
+        if (status != E_BOOK_ERROR_OK) {
+                g_warning ("failed to asynchronously remove the contacts: "
+                                "status %d", status);
+                exit (1);
+        }
+
+        g_print ("successfully asynchronously removed the contacts\n");
+
+        if (closure) {
+                (*closure->cb) (closure->user_data);
+                g_free (closure);
+        }
+}
+
+void
+ebook_test_utils_book_async_remove_contacts (EBook       *book,
+                                             GList       *uids,
+                                             GSourceFunc  callback,
+                                             gpointer     user_data)
+{
+        EBookTestClosure *closure;
+
+        closure = g_new0 (EBookTestClosure, 1);
+        closure->cb = callback;
+        closure->user_data = user_data;
+        if (e_book_async_remove_contacts (book, uids,
+                                (EBookCallback) remove_contacts_cb,
+                                closure)) {
+                g_warning ("failed to set up async removeContacts");
+                exit(1);
+        }
+}
+
 EBook*
 ebook_test_utils_book_new_temp (char **uri)
 {
diff --git a/addressbook/tests/ebook/ebook-test-utils.h b/addressbook/tests/ebook/ebook-test-utils.h
index 6a0f58f..497109e 100644
--- a/addressbook/tests/ebook/ebook-test-utils.h
+++ b/addressbook/tests/ebook/ebook-test-utils.h
@@ -36,6 +36,15 @@ typedef struct {
 char*
 ebook_test_utils_new_vcard_from_test_case (const char *case_name);
 
+char*
+ebook_test_utils_book_add_contact_from_test_case_verify (EBook       *book,
+                                                         const char  *case_name,
+							 EContact   **contact);
+
+gboolean
+ebook_test_utils_contacts_are_equal_shallow (EContact *a,
+                                             EContact *b);
+
 EBook*
 ebook_test_utils_book_new_temp (char **uri);
 
@@ -58,6 +67,29 @@ ebook_test_utils_book_async_get_contact (EBook       *book,
                                          gpointer     user_data);
 
 void
+ebook_test_utils_book_remove_contact (EBook      *book,
+                                      const char *uid);
+void
+ebook_test_utils_book_async_remove_contact (EBook       *book,
+					    EContact    *contact,
+					    GSourceFunc  callback,
+					    gpointer     user_data);
+void
+ebook_test_utils_book_async_remove_contact_by_id (EBook       *book,
+                                                  const char  *uid,
+                                                  GSourceFunc  callback,
+                                                  gpointer     user_data);
+
+void
+ebook_test_utils_book_remove_contacts (EBook *book,
+                                       GList *ids);
+void
+ebook_test_utils_book_async_remove_contacts (EBook       *book,
+                                             GList       *uids,
+                                             GSourceFunc  callback,
+                                             gpointer     user_data);
+
+void
 ebook_test_utils_book_open (EBook    *book,
                             gboolean  only_if_exists);
 
diff --git a/addressbook/tests/ebook/test-ebook-add-contact.c b/addressbook/tests/ebook/test-ebook-add-contact.c
index 4297c93..b352057 100644
--- a/addressbook/tests/ebook/test-ebook-add-contact.c
+++ b/addressbook/tests/ebook/test-ebook-add-contact.c
@@ -14,7 +14,6 @@ main (gint argc, gchar **argv)
 	EContact *contact;
 	EContact *contact_final;
 	char *uid;
-	const char *contact_final_uid;
 
 	g_type_init ();
 
@@ -24,31 +23,12 @@ main (gint argc, gchar **argv)
 	book = ebook_test_utils_book_new_temp (NULL);
 	ebook_test_utils_book_open (book, FALSE);
 
-	vcard = ebook_test_utils_new_vcard_from_test_case ("simple-1");
-	contact = e_contact_new_from_vcard (vcard);
-	uid = g_strdup (ebook_test_utils_book_add_contact (book, contact));
-
 	/*
 	 * Sync version
 	 */
-	contact_final = ebook_test_utils_book_get_contact (book, uid);
-	contact_final_uid = e_contact_get_const (contact_final, E_CONTACT_UID);
-
-	/* This is not a thorough comparison (which is difficult, assuming we
-	 * give the back-ends leniency in implementation), since that's better
-	 * suited to more advanced tests */
-	if (g_strcmp0 (uid, contact_final_uid)) {
-		const char *uri;
-
-		uri = e_book_get_uri (book);
-
-		g_warning ("retrieved contact uid '%s' does not match added "
-				"contact uid '%s'", contact_final_uid, uid);
-		exit(1);
-	}
+	uid = ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-1", &contact_final);
 
 	g_print ("successfully added and retrieved contact '%s'\n", uid);
-	g_object_unref (contact);
 	g_object_unref (contact_final);
 
 	ebook_test_utils_book_remove (book);
@@ -58,6 +38,7 @@ main (gint argc, gchar **argv)
 	 */
 	book = ebook_test_utils_book_new_temp (NULL);
 	ebook_test_utils_book_open (book, FALSE);
+	vcard = ebook_test_utils_new_vcard_from_test_case ("simple-1");
 	contact = e_contact_new_from_vcard (vcard);
 
 	loop = g_main_loop_new (NULL, TRUE);
diff --git a/addressbook/tests/ebook/test-ebook-get-contact.c b/addressbook/tests/ebook/test-ebook-get-contact.c
index ff3dcda..6bcce72 100644
--- a/addressbook/tests/ebook/test-ebook-get-contact.c
+++ b/addressbook/tests/ebook/test-ebook-get-contact.c
@@ -10,11 +10,8 @@ main (gint argc, gchar **argv)
 {
 	EBook *book;
 	GMainLoop *loop;
-	char *vcard;
-	EContact *contact;
 	EContact *contact_final;
 	const char *uid;
-	const char *contact_final_uid;
 
 	g_type_init ();
 
@@ -24,31 +21,12 @@ main (gint argc, gchar **argv)
 	book = ebook_test_utils_book_new_temp (NULL);
 	ebook_test_utils_book_open (book, FALSE);
 
-	vcard = ebook_test_utils_new_vcard_from_test_case ("simple-1");
-	contact = e_contact_new_from_vcard (vcard);
-	uid = ebook_test_utils_book_add_contact (book, contact);
-
 	/*
 	 * Sync version
 	 */
-	contact_final = ebook_test_utils_book_get_contact (book, uid);
-	contact_final_uid = e_contact_get_const (contact_final, E_CONTACT_UID);
-
-	/* This is not a thorough comparison (which is difficult, assuming we
-	 * give the back-ends leniency in implementation), since that's better
-	 * suited to more advanced tests */
-	if (g_strcmp0 (uid, contact_final_uid)) {
-		const char *uri;
-
-		uri = e_book_get_uri (book);
-
-		g_warning ("retrieved contact uid '%s' does not match added "
-				"contact uid '%s'", contact_final_uid, uid);
-		exit(1);
-	}
+	uid = ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-1", &contact_final);
 
 	g_print ("successfully added and retrieved contact '%s'\n", uid);
-	g_object_unref (contact);
 	g_object_unref (contact_final);
 
 	/*
@@ -60,7 +38,6 @@ main (gint argc, gchar **argv)
 	g_main_loop_run (loop);
 
 	ebook_test_utils_book_remove (book);
-	g_free (vcard);
 
 	return 0;
 }
diff --git a/addressbook/tests/ebook/test-ebook-remove-contact-by-id.c b/addressbook/tests/ebook/test-ebook-remove-contact-by-id.c
new file mode 100644
index 0000000..8b99cf0
--- /dev/null
+++ b/addressbook/tests/ebook/test-ebook-remove-contact-by-id.c
@@ -0,0 +1,40 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <libebook/e-book.h>
+
+#include "ebook-test-utils.h"
+
+gint 
+main (gint argc, gchar **argv)
+{       
+        EBook *book;
+        GMainLoop *loop;
+        char *uid; 
+        
+        g_type_init ();
+        
+        /*
+         * Setup
+         */
+        book = ebook_test_utils_book_new_temp (NULL);
+        ebook_test_utils_book_open (book, FALSE);
+
+        /*
+         * 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, "simple-1", NULL);
+
+        loop = g_main_loop_new (NULL, TRUE);
+        ebook_test_utils_book_async_remove_contact_by_id (book, uid,
+                        (GSourceFunc) g_main_loop_quit, loop);
+        
+        g_main_loop_run (loop);
+        
+        ebook_test_utils_book_remove (book);
+	g_free (uid);
+        
+        return 0;
+}
diff --git a/addressbook/tests/ebook/test-ebook-remove-contact.c b/addressbook/tests/ebook/test-ebook-remove-contact.c
new file mode 100644
index 0000000..b307280
--- /dev/null
+++ b/addressbook/tests/ebook/test-ebook-remove-contact.c
@@ -0,0 +1,59 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <libebook/e-book.h>
+
+#include "ebook-test-utils.h"
+
+gint
+main (gint argc, gchar **argv)
+{
+        EBook *book;
+        GMainLoop *loop;
+        EContact *contact_final;
+        char *uid;
+
+        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, "simple-1", NULL);
+        ebook_test_utils_book_remove_contact (book, uid);
+	contact_final = NULL;
+	e_book_get_contact (book, uid, &contact_final, NULL);
+
+        g_assert (contact_final == NULL);
+        g_print ("successfully added and removed contact '%s'\n", uid);
+
+        ebook_test_utils_book_remove (book);
+        g_free (uid);
+
+        /*
+         * Async version
+         */
+        book = ebook_test_utils_book_new_temp (NULL);
+        ebook_test_utils_book_open (book, FALSE);
+
+	contact_final = NULL;
+	/* contact_final has 2 refs by the end of this */
+	uid = ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-1", &contact_final);
+
+        loop = g_main_loop_new (NULL, TRUE);
+	/* contact_final is unref'd by e_book_remove_contact() here */
+        ebook_test_utils_book_async_remove_contact (book, contact_final,
+                        (GSourceFunc) g_main_loop_quit, loop);
+
+        g_main_loop_run (loop);
+
+        ebook_test_utils_book_remove (book);
+	g_object_unref (contact_final);
+	g_free (uid);
+
+        return 0;
+}
diff --git a/addressbook/tests/ebook/test-ebook-remove-contacts.c b/addressbook/tests/ebook/test-ebook-remove-contacts.c
new file mode 100644
index 0000000..369050a
--- /dev/null
+++ b/addressbook/tests/ebook/test-ebook-remove-contacts.c
@@ -0,0 +1,71 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <libebook/e-book.h>
+
+#include "ebook-test-utils.h"
+
+gint 
+main (gint argc, gchar **argv)
+{       
+        EBook *book;
+        GMainLoop *loop;
+        EContact *contact_final;
+        char *uid_1, *uid_2; 
+	GList *uids = NULL;
+        
+        g_type_init ();
+        
+        /*
+         * Setup
+         */
+        book = ebook_test_utils_book_new_temp (NULL);
+        ebook_test_utils_book_open (book, FALSE);
+
+        /*
+         * Sync version
+         */
+	uid_1 = ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-1", NULL);
+	uid_2 = ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-2", NULL);
+	uids = g_list_prepend (uids, uid_1);
+	uids = g_list_prepend (uids, uid_2);
+        ebook_test_utils_book_remove_contacts (book, uids);
+
+	contact_final = NULL;
+	e_book_get_contact (book, uid_1, &contact_final, NULL);
+        g_assert (contact_final == NULL);
+
+	e_book_get_contact (book, uid_2, &contact_final, NULL);
+        g_assert (contact_final == NULL);
+
+        g_print ("successfully added and removed contacts\n");
+
+        ebook_test_utils_book_remove (book);
+        g_free (uid_1);
+        g_free (uid_2);
+	g_list_free (uids);
+        
+        /*
+         * Async version
+         */
+        book = ebook_test_utils_book_new_temp (NULL);
+        ebook_test_utils_book_open (book, FALSE);
+
+	uid_1 = ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-1", NULL);
+	uid_2 = ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-2", NULL);
+	uids = NULL;
+	uids = g_list_prepend (uids, uid_1);
+	uids = g_list_prepend (uids, uid_2);
+
+        loop = g_main_loop_new (NULL, TRUE);
+        ebook_test_utils_book_async_remove_contacts (book, uids,
+                        (GSourceFunc) g_main_loop_quit, loop);
+        
+        g_main_loop_run (loop);
+
+        ebook_test_utils_book_remove (book);
+        g_free (uid_1);
+        g_free (uid_2);
+	g_list_free (uids);
+
+        return 0;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]