[evolution-data-server/openismus-work] Ported all tests in tests/ebook/client to use new test framework



commit ade044886c2127e8f4df3ce7754eeefd30f7446c
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Wed Dec 12 19:35:59 2012 +0900

    Ported all tests in tests/ebook/client to use new test framework
    
    'make check' now passes in ebook except for a few cases which geniunely fail.
    
    Includes porting of test-client-upgrade-addressbook.c
    
    Conflicts:
    
    	tests/libebook/client/Makefile.am
    	tests/libebook/client/test-client-custom-summary.c

 tests/libebook/client/Makefile.am                  |   24 +-
 tests/libebook/client/test-client-add-contact.c    |  100 ++++-----
 tests/libebook/client/test-client-async.c          |   90 +++-----
 tests/libebook/client/test-client-custom-summary.c |  240 ++++++++------------
 .../libebook/client/test-client-get-contact-uids.c |  118 ++++++-----
 tests/libebook/client/test-client-get-contact.c    |   97 +++++----
 tests/libebook/client/test-client-get-revision.c   |   46 ++--
 tests/libebook/client/test-client-get-view.c       |  147 +++++-------
 tests/libebook/client/test-client-modify-contact.c |  166 ++++++--------
 tests/libebook/client/test-client-photo-is-uri.c   |   68 ++----
 tests/libebook/client/test-client-refresh.c        |  112 ++++------
 .../client/test-client-remove-contact-by-uid.c     |  159 ++++++--------
 tests/libebook/client/test-client-remove-contact.c |  159 ++++++--------
 .../libebook/client/test-client-remove-contacts.c  |  158 ++++++--------
 tests/libebook/client/test-client-remove.c         |   72 ------
 tests/libebook/client/test-client-revision-view.c  |  150 +++++-------
 .../client/test-client-suppress-notifications.c    |  156 +++++--------
 tests/libebook/client/test-client-uid-only-view.c  |  213 ++++++------------
 .../client/test-client-upgrade-addressbook.c       |  230 ++++++++-----------
 tests/libebook/client/test-client.c                |   63 +++---
 tests/test-server-utils/Makefile.am                |    2 -
 tests/test-server-utils/e-test-server-utils.c      |    8 +-
 22 files changed, 1057 insertions(+), 1521 deletions(-)
---
diff --git a/tests/libebook/client/Makefile.am b/tests/libebook/client/Makefile.am
index 9c5399a..537152e 100644
--- a/tests/libebook/client/Makefile.am
+++ b/tests/libebook/client/Makefile.am
@@ -3,8 +3,6 @@ noinst_LTLIBRARIES = libclient-test-utils.la
 libclient_test_utils_la_SOURCES =				\
 	client-test-utils.c					\
 	client-test-utils.h					\
-	$(top_srcdir)/tests/libedataserver/e-test-dbus-utils.c	\
-	$(top_srcdir)/tests/libedataserver/e-test-dbus-utils.h	\
 	$(NULL)
 
 libclient_test_utils_la_CPPFLAGS =				\
@@ -30,14 +28,13 @@ libclient_test_utils_la_CPPFLAGS =				\
 libclient_test_utils_la_LIBADD = 				\
 	$(top_builddir)/addressbook/libebook-contacts/libebook-contacts-1.2.la		\
 	$(top_builddir)/addressbook/libebook/libebook-1.2.la	\
+	$(top_builddir)/tests/test-server-utils/libetestserverutils.la	\
 	$(EVOLUTION_ADDRESSBOOK_LIBS)				\
 	$(CAMEL_LIBS)						\
 	$(NULL)
 
 # Should be kept ordered approximately from least to most difficult/complex
 TESTS =								\
-	test-client-remove					\
-	test-client-examine					\
 	test-client-refresh					\
 	test-client-add-contact					\
 	test-client-get-contact					\
@@ -56,20 +53,25 @@ TESTS =								\
 	test-client-photo-is-uri				\
 	test-client-change-country-code				\
 	test-client-upgrade-addressbook				\
-	test-client-write-write					\
-	test-client-stress-factory--serial			\
-	test-client-stress-factory--fifo			\
-	test-client-stress-factory--single-book			\
+	test-client-async					\
 	$(NULL)
 
+# The noinst tests are functional tests, not unit tests.
+#
+# Either they were designed as functional tests or have
+# not been ported to use ETestServerFixture yet.
 noinst_PROGRAMS =						\
 	$(TESTS)						\
+	test-client-write-write					\
+	test-client-examine					\
 	test-client						\
-	test-client-async					\
 	test-client-nonexistent-id				\
 	test-client-search					\
 	test-client-self					\
 	test-client-stress-views				\
+	test-client-stress-factory--serial			\
+	test-client-stress-factory--fifo			\
+	test-client-stress-factory--single-book			\
 	$(NULL)
 
 TEST_CPPFLAGS =							\
@@ -78,7 +80,7 @@ TEST_CPPFLAGS =							\
 	$(NULL)
 
 TEST_LIBS =							\
-	$(libclient_test_utils_la_LIBS)				\
+	$(libclient_test_utils_la_LIBADD)			\
 	libclient-test-utils.la					\
 	$(top_builddir)/addressbook/libebook/libebook-1.2.la	\
 	$(EVOLUTION_ADDRESSBOOK_LIBS)				\
@@ -114,8 +116,6 @@ test_client_modify_contact_LDADD=$(TEST_LIBS)
 test_client_modify_contact_CPPFLAGS=$(TEST_CPPFLAGS)
 test_client_refresh_LDADD=$(TEST_LIBS)
 test_client_refresh_CPPFLAGS=$(TEST_CPPFLAGS)
-test_client_remove_LDADD=$(TEST_LIBS)
-test_client_remove_CPPFLAGS=$(TEST_CPPFLAGS)
 test_client_remove_contact_LDADD=$(TEST_LIBS)
 test_client_remove_contact_CPPFLAGS=$(TEST_CPPFLAGS)
 test_client_remove_contact_by_uid_LDADD=$(TEST_LIBS)
diff --git a/tests/libebook/client/test-client-add-contact.c b/tests/libebook/client/test-client-add-contact.c
index fc784e2..1a07fbc 100644
--- a/tests/libebook/client/test-client-add-contact.c
+++ b/tests/libebook/client/test-client-add-contact.c
@@ -4,95 +4,77 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
+
+static void
+test_add_contact_sync (ETestServerFixture *fixture,
+		       gconstpointer       user_data)
+{
+	EBookClient *book_client;
+	EContact *contact;
+
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
+		g_error ("Failed to add contact sync");
+	}
+	g_object_unref (contact);
+}
 
 static void
 add_contact_cb (GObject *source_object,
                 GAsyncResult *result,
                 gpointer user_data)
 {
+	GMainLoop *loop = (GMainLoop *)user_data;
 	GError *error = NULL;
 	gchar *uid;
 
 	if (!e_book_client_add_contact_finish (E_BOOK_CLIENT (source_object), result, &uid, &error)) {
-		report_error ("add contact finish", &error);
-		stop_main_loop (1);
-		return;
+		g_error ("add contact finish: %s", error->message);
 	}
 
 	printf ("Contact added as '%s'\n", uid);
 	g_free (uid);
-	stop_main_loop (0);
+	g_main_loop_quit (loop);
 }
 
-gint
-main (gint argc,
-      gchar **argv)
+static void
+test_add_contact_async (ETestServerFixture *fixture,
+			gconstpointer       user_data)
 {
 	EBookClient *book_client;
-	GError *error = NULL;
 	EContact *contact;
 	gchar *vcard;
 
-	main_initialize ();
-
-	/*
-	 * Setup
-	 */
-	book_client = new_temp_client (NULL);
-	g_return_val_if_fail (book_client != NULL, 1);
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
-
-	/*
-	 * Sync version
-	 */
-	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
-		g_object_unref (book_client);
-		return 1;
-	}
-
-	g_object_unref (contact);
-
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
-
-	g_object_unref (book_client);
-
-	/*
-	 * Async version
-	 */
-	book_client = new_temp_client (NULL);
-	g_return_val_if_fail (book_client != NULL, 1);
-
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
 
 	vcard = new_vcard_from_test_case ("simple-1");
 	contact = e_contact_new_from_vcard (vcard);
 	g_free (vcard);
 
-	e_book_client_add_contact (book_client, contact, NULL, add_contact_cb, NULL);
+	e_book_client_add_contact (book_client, contact, NULL, add_contact_cb, fixture->loop);
 	g_object_unref (contact);
 
-	start_main_loop (NULL, NULL);
+	g_main_loop_run (fixture->loop);
+}
 
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+gint
+main (gint argc,
+      gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	g_object_unref (book_client);
+	g_test_add ("/EBookClient/AddContact/Sync", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_add_contact_sync, e_test_server_utils_teardown);
+	g_test_add ("/EBookClient/AddContact/Async", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_add_contact_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-async.c b/tests/libebook/client/test-client-async.c
index f43e050..0568517 100644
--- a/tests/libebook/client/test-client-async.c
+++ b/tests/libebook/client/test-client-async.c
@@ -4,6 +4,9 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 
 static void
 print_all_uids_cb (GObject *source_object,
@@ -13,15 +16,13 @@ print_all_uids_cb (GObject *source_object,
 	EBookClient *book_client;
 	GSList *uids = NULL, *u;
 	GError *error = NULL;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
 	book_client = E_BOOK_CLIENT (source_object);
 	g_return_if_fail (book_client != NULL);
 
-	if (!e_book_client_get_contacts_uids_finish (book_client, result, &uids, &error)) {
-		report_error ("get contacts uids finish", &error);
-		stop_main_loop (1);
-		return;
-	}
+	if (!e_book_client_get_contacts_uids_finish (book_client, result, &uids, &error))
+		g_error ("get contacts uids finish: %s", error->message);
 
 	for (u = uids; u; u = u->next) {
 		const gchar *uid = u->data;
@@ -32,7 +33,7 @@ print_all_uids_cb (GObject *source_object,
 	g_slist_foreach (uids, (GFunc) g_free, NULL);
 	g_slist_free (uids);
 
-	stop_main_loop (0);
+	g_main_loop_quit (loop);
 }
 
 static void
@@ -45,15 +46,13 @@ print_all_emails_cb (GObject *source_object,
 	gchar *sexp;
 	GSList *contacts = NULL, *c;
 	GError *error = NULL;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
 	book_client = E_BOOK_CLIENT (source_object);
 	g_return_if_fail (book_client != NULL);
 
-	if (!e_book_client_get_contacts_finish (book_client, result, &contacts, &error)) {
-		report_error ("get contacts finish", &error);
-		stop_main_loop (1);
-		return;
-	}
+	if (!e_book_client_get_contacts_finish (book_client, result, &contacts, &error))
+		g_error ("get contacts finish: %s", error->message);
 
 	for (c = contacts; c; c = c->next) {
 		EContact *contact = E_CONTACT (c->data);
@@ -68,13 +67,14 @@ print_all_emails_cb (GObject *source_object,
 	sexp = e_book_query_to_string (query);
 	e_book_query_unref (query);
 
-	e_book_client_get_contacts_uids (book_client, sexp, NULL, print_all_uids_cb, NULL);
+	e_book_client_get_contacts_uids (book_client, sexp, NULL, print_all_uids_cb, loop);
 
 	g_free (sexp);
 }
 
 static void
-print_all_emails (EBookClient *book_client)
+print_all_emails (EBookClient *book_client,
+		  GMainLoop *loop)
 {
 	EBookQuery *query;
 	gchar *sexp;
@@ -83,7 +83,7 @@ print_all_emails (EBookClient *book_client)
 	sexp = e_book_query_to_string (query);
 	e_book_query_unref (query);
 
-	e_book_client_get_contacts (book_client, sexp, NULL, print_all_emails_cb, NULL);
+	e_book_client_get_contacts (book_client, sexp, NULL, print_all_emails_cb, loop);
 
 	g_free (sexp);
 }
@@ -96,27 +96,28 @@ print_email_cb (GObject *source_object,
 	EBookClient *book_client;
 	EContact *contact = NULL;
 	GError *error = NULL;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
 	book_client = E_BOOK_CLIENT (source_object);
 	g_return_if_fail (book_client != NULL);
 
 	if (!e_book_client_get_contact_finish (book_client, result, &contact, &error)) {
-		report_error ("get contact finish", &error);
+		g_error ("get contact finish: %s", error->message);
 	} else {
 		print_email (contact);
 		g_object_unref (contact);
 	}
 
 	printf ("printing all contacts\n");
-	print_all_emails (book_client);
+	print_all_emails (book_client, loop);
 }
 
 static void
-print_one_email (EBookClient *book_client, GSList *uids)
+print_one_email (EBookClient *book_client, GSList *uids, GMainLoop *loop)
 {
 	const gchar *uid = uids->data;
 
-	e_book_client_get_contact (book_client, uid, NULL, print_email_cb, NULL);
+	e_book_client_get_contact (book_client, uid, NULL, print_email_cb, loop);
 
 	e_util_free_string_slist (uids);
 }
@@ -129,14 +130,12 @@ contacts_added_cb (GObject *source_object,
 	EBookClient *book_client;
 	GError *error = NULL;
 	GSList *uids = NULL, *l;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
 	book_client = E_BOOK_CLIENT (source_object);
 
-	if (!e_book_client_add_contacts_finish (book_client, result, &uids, &error)) {
-		report_error ("client open finish", &error);
-		stop_main_loop (1);
-		return;
-	}
+	if (!e_book_client_add_contacts_finish (book_client, result, &uids, &error))
+		g_error ("client open finish: %s", error->message);
 
 	printf ("Added contacts uids are:\n");
 	for (l = uids; l; l = l->next) {
@@ -147,11 +146,12 @@ contacts_added_cb (GObject *source_object,
 	printf ("\n");
 
 	printf ("printing one contact\n");
-	print_one_email (book_client, uids);
+	print_one_email (book_client, uids, loop);
 }
 
 static void
-add_contacts (EBookClient *book_client)
+add_contacts (EBookClient *book_client,
+	      GMainLoop *loop)
 {
 	GSList *contacts = NULL;
 	EContact *contact;
@@ -182,49 +182,35 @@ add_contacts (EBookClient *book_client)
 	g_free (vcard);
 	contacts = g_slist_prepend (contacts, contact);
 
-	e_book_client_add_contacts (book_client, contacts, NULL, contacts_added_cb, NULL);
+	e_book_client_add_contacts (book_client, contacts, NULL, contacts_added_cb, loop);
 
 	e_util_free_object_slist (contacts);
 }
 
 static void
-client_loaded_cb (GObject *source_object,
-                  GAsyncResult *result,
-                  gpointer user_data)
+test_async (ETestServerFixture *fixture,
+	    gconstpointer       user_data)
 {
 	EBookClient *book_client;
-	GError *error = NULL;
 
-	book_client = E_BOOK_CLIENT (source_object);
-	g_return_if_fail (book_client != NULL);
-
-	if (!e_client_open_finish (E_CLIENT (book_client), result, &error)) {
-		report_error ("client open finish", &error);
-		stop_main_loop (1);
-		return;
-	}
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
 	printf ("Adding contacts\n");
-	add_contacts (book_client);
+	add_contacts (book_client, fixture->loop);
+	g_main_loop_run (fixture->loop);
 }
 
 gint
 main (gint argc,
       gchar **argv)
 {
-	EBookClient *book_client;
-
-	main_initialize ();
-
-	book_client = new_temp_client (NULL);
-
-	printf ("loading addressbook\n");
-
-	e_client_open (E_CLIENT (book_client), FALSE, NULL, client_loaded_cb, NULL);
-
-	start_main_loop (NULL, NULL);
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	g_object_unref (book_client);
+	g_test_add ("/EBookClient/AsyncTest", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-custom-summary.c b/tests/libebook/client/test-client-custom-summary.c
index ebe2fc9..dc0abd0 100644
--- a/tests/libebook/client/test-client-custom-summary.c
+++ b/tests/libebook/client/test-client-custom-summary.c
@@ -24,20 +24,35 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
 
 
-/* This forces the GType to be registered in a way that
- * avoids a "statement with no effect" compiler warning.
- * FIXME Use g_type_ensure() once we require GLib 2.34. */
-#define REGISTER_TYPE(type) \
-	(g_type_class_unref (g_type_class_ref (type)))
+typedef struct {
+	ETestServerClosure closure;
+	EBookQuery *query;
+	gint num_contacts;
+} ClientTestData;
+
+/* Cleanup the closures, just for the hell of it... */
+static GList *closures = NULL;
+
+static void
+client_test_data_free (gpointer p)
+{
+	ClientTestData *data = (ClientTestData *)p;
+
+	if (data->query)
+		e_book_query_unref (data->query);
+	g_slice_free (ClientTestData, data);
+}
 
 static void
-setup_custom_summary (ESource *scratch)
+setup_custom_book (ESource            *scratch,
+		   ETestServerClosure *closure)
 {
 	ESourceBackendSummarySetup *setup;
 
-	REGISTER_TYPE (E_TYPE_SOURCE_BACKEND_SUMMARY_SETUP);
+	g_type_ensure (E_TYPE_SOURCE_BACKEND_SUMMARY_SETUP);
 	setup = e_source_get_extension (scratch, E_SOURCE_EXTENSION_BACKEND_SUMMARY_SETUP);
 	e_source_backend_summary_setup_set_summary_fields (setup,
 							   E_CONTACT_FULL_NAME,
@@ -48,7 +63,6 @@ setup_custom_summary (ESource *scratch)
 							   0);
 	e_source_backend_summary_setup_set_indexed_fields (setup,
 							   E_CONTACT_TEL, E_BOOK_INDEX_SUFFIX,
-							   E_CONTACT_TEL, E_BOOK_INDEX_PHONE,
 							   E_CONTACT_FULL_NAME, E_BOOK_INDEX_PREFIX,
 							   E_CONTACT_FULL_NAME, E_BOOK_INDEX_SUFFIX,
 							   E_CONTACT_FAMILY_NAME, E_BOOK_INDEX_PREFIX,
@@ -56,38 +70,54 @@ setup_custom_summary (ESource *scratch)
 							   0);
 }
 
-typedef struct {
-	GTestDataFunc func;
-	EBookClient *client;
-	EBookQuery *query;
-	gint num_contacts;
-} ClientTestData;
-
 static void
-client_test_data_free (gpointer p)
+add_client_test (const gchar *path,
+                 gpointer func,
+                 EBookQuery *query,
+                 gint num_contacts)
 {
-	ClientTestData *const data = p;
-	g_object_unref (data->client);
+	ClientTestData *data = g_slice_new0 (ClientTestData);
 
-	if (data->query)
-		e_book_query_unref (data->query);
-	g_slice_free (ClientTestData, data);
+	data->closure.type = E_TEST_SERVER_ADDRESS_BOOK;
+	data->closure.customize = setup_custom_book;
+	data->query = query;
+	data->num_contacts = num_contacts;
+
+	g_test_add (path, ETestServerFixture, data, e_test_server_utils_setup, func, e_test_server_utils_teardown);
+	closures = g_list_prepend (closures, data);
+}
+
+static void
+setup_book (EBookClient *book_client)
+{
+	/* Add contacts */
+	if (!add_contact_from_test_case_verify (book_client, "custom-1", NULL) ||
+	    !add_contact_from_test_case_verify (book_client, "custom-2", NULL) ||
+	    !add_contact_from_test_case_verify (book_client, "custom-3", NULL) ||
+	    !add_contact_from_test_case_verify (book_client, "custom-4", NULL) ||
+	    !add_contact_from_test_case_verify (book_client, "custom-5", NULL) ||
+	    !add_contact_from_test_case_verify (book_client, "custom-6", NULL)) {
+		g_error ("Failed to add contacts");
+	}
 }
 
 static void
-search_test (gconstpointer p)
+search_test (ETestServerFixture *fixture,
+	     gconstpointer       user_data)
 {
-	const ClientTestData *const data = p;
+	EBookClient *book_client;
 	GSList *results = NULL;
 	GError *error = NULL;
 	gchar *sexp;
+	const ClientTestData *const data = user_data;
+
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+	setup_book (book_client);
 
 	sexp = e_book_query_to_string (data->query);
 
-	if (!e_book_client_get_contacts_sync (data->client, sexp, &results, NULL, &error)) {
-		report_error ("get contacts", &error);
-		g_test_fail ();
-		return;
+	if (!e_book_client_get_contacts_sync (book_client, sexp, &results, NULL, &error)) {
+		g_error ("get contacts: %s", error->message);
 	}
 
 	g_assert_cmpint (g_slist_length (results), ==, data->num_contacts);
@@ -96,19 +126,22 @@ search_test (gconstpointer p)
 }
 
 static void
-uid_test (gconstpointer p)
+uid_test (ETestServerFixture *fixture,
+	  gconstpointer       user_data)
 {
-	const ClientTestData *const data = p;
+	EBookClient *book_client;
 	GSList *results = NULL;
 	GError *error = NULL;
 	gchar *sexp;
+	const ClientTestData *const data = user_data;
+
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+	setup_book (book_client);
 
 	sexp = e_book_query_to_string (data->query);
 
-	if (!e_book_client_get_contacts_uids_sync (data->client, sexp, &results, NULL, &error)) {
-		report_error ("get contact uids", &error);
-		g_test_fail ();
-		return;
+	if (!e_book_client_get_contacts_uids_sync (book_client, sexp, &results, NULL, &error)) {
+		g_error ("get contact uids: %s", error->message);
 	}
 
 	g_assert_cmpint (g_slist_length (results), ==, data->num_contacts);
@@ -116,138 +149,61 @@ uid_test (gconstpointer p)
 	g_free (sexp);
 }
 
-static void
-remove_test (gconstpointer p)
-{
-	const ClientTestData *const data = p;
-	GError *error = NULL;
-
-	if (!e_client_remove_sync (E_CLIENT (data->client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_test_fail ();
-		return;
-	}
-}
-
-/* Temporary hack not in master, we need to support
- * earlier versions of GLib (< 2.34) without g_test_add_data_func_full()
- *
- *
- */
-static void
-test_and_free (gconstpointer p)
-{
-	ClientTestData *data = (ClientTestData *)p;
-
-	data->func (p);
-	client_test_data_free (data);
-}
-
-static void
-add_client_test (const gchar *path,
-                 GTestDataFunc func,
-                 EBookClient *client,
-                 EBookQuery *query,
-                 gint num_contacts)
-{
-	ClientTestData *data = g_slice_new (ClientTestData);
-
-	data->func = func;
-	data->client = g_object_ref (client);
-	data->query = query;
-	data->num_contacts = num_contacts;
-
-	g_test_add_data_func (path, data, test_and_free);
-}
-
 gint
 main (gint argc,
       gchar **argv)
 {
-	EBookClient *book_client;
-	EContact *contact_final;
-	GError *error = NULL;
+	gint ret;
 
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
 	g_test_init (&argc, &argv, NULL);
-	main_initialize ();
-
-	/* Setup */
-	book_client = new_custom_temp_client (NULL, setup_custom_summary);
-	g_return_val_if_fail (book_client != NULL, 1);
-
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
 
-	/* Add contacts */
-	if (!add_contact_from_test_case_verify (book_client, "custom-1", &contact_final)) {
-		g_object_unref (book_client);
-		return 1;
-	}
-	if (!add_contact_from_test_case_verify (book_client, "custom-2", &contact_final)) {
-		g_object_unref (book_client);
-		return 1;
-	}
-	if (!add_contact_from_test_case_verify (book_client, "custom-3", &contact_final)) {
-		g_object_unref (book_client);
-		return 1;
-	}
-	if (!add_contact_from_test_case_verify (book_client, "custom-4", &contact_final)) {
-		g_object_unref (book_client);
-		return 1;
-	}
-	if (!add_contact_from_test_case_verify (book_client, "custom-5", &contact_final)) {
-		g_object_unref (book_client);
-		return 1;
-	}
 
 	/* Add search tests that fetch contacts */
-	add_client_test ("/client/search/exact/fn", search_test, book_client,
+	add_client_test ("/client/search/exact/fn", search_test,
 	                 e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, "James Brown"),
 	                 1);
-	add_client_test ("/client/search/prefix/fn", search_test, book_client,
+	add_client_test ("/client/search/exact/name", search_test,
+	                 e_book_query_vcard_field_test(EVC_N, E_BOOK_QUERY_IS, "Janet"),
+	                 1);
+	add_client_test ("/client/search/prefix/fn", search_test,
 	                 e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_BEGINS_WITH, "B"),
 	                 2);
-	add_client_test ("/client/search/suffix/phone", search_test, book_client,
+	add_client_test ("/client/search/prefix/fn/percent", search_test,
+	                 e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_BEGINS_WITH, "%"),
+	                 1);
+	add_client_test ("/client/search/suffix/phone", search_test,
 	                 e_book_query_field_test (E_CONTACT_TEL, E_BOOK_QUERY_ENDS_WITH, "999"),
 	                 2);
-	add_client_test ("/client/search/suffix/email", search_test, book_client,
+	add_client_test ("/client/search/suffix/email", search_test,
 	                 e_book_query_field_test (E_CONTACT_EMAIL, E_BOOK_QUERY_ENDS_WITH, "jackson.com"),
 	                 2);
-	add_client_test ("/client/search/exact/name", search_test, book_client,
-	                 e_book_query_vcard_field_test(EVC_N, E_BOOK_QUERY_IS, "Janet"),
-	                 1);
-	add_client_test ("/client/search/eqphone/exact/phone", search_test, book_client,
-	                 e_book_query_field_test(E_CONTACT_TEL, E_BOOK_QUERY_EQUALS_PHONE_NUMBER, "+1 221.542.3789"),
-	                 1);
-	add_client_test ("/client/search/eqphone/national/phone", search_test, book_client,
-	                 e_book_query_field_test(E_CONTACT_TEL, E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER, "221.542.3789"),
-	                 1);
-	add_client_test ("/client/search/eqphone/short/phone", search_test, book_client,
-	                 e_book_query_field_test(E_CONTACT_TEL, E_BOOK_QUERY_EQUALS_SHORT_PHONE_NUMBER, "5423789"),
-	                 1);
-	add_client_test ("/client/search/eqphone/exact/tel", search_test, book_client,
-	                 e_book_query_vcard_field_test(EVC_TEL, E_BOOK_QUERY_EQUALS_PHONE_NUMBER, "+1 221.542.3789"),
+
+	/* Add search tests that fetch uids */
+	add_client_test ("/client/search-uid/exact/fn", uid_test,
+	                 e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, "James Brown"),
 	                 1);
-	add_client_test ("/client/search/eqphone/national/tel", search_test, book_client,
-	                 e_book_query_vcard_field_test(EVC_TEL, E_BOOK_QUERY_EQUALS_NATIONAL_PHONE_NUMBER, "221.542.3789"),
+	add_client_test ("/client/search-uid/exact/name", uid_test,
+	                 e_book_query_vcard_field_test(EVC_N, E_BOOK_QUERY_IS, "Janet"),
 	                 1);
-	add_client_test ("/client/search/eqphone/short/tel", search_test, book_client,
-	                 e_book_query_vcard_field_test(EVC_TEL, E_BOOK_QUERY_EQUALS_SHORT_PHONE_NUMBER, "5423789"),
+	add_client_test ("/client/search-uid/prefix/fn", uid_test,
+	                 e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_BEGINS_WITH, "B"),
+	                 2);
+	add_client_test ("/client/search-uid/prefix/fn/percent", uid_test,
+	                 e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_BEGINS_WITH, "%"),
 	                 1);
-
-	/* Add search tests that fetch uids */
-	add_client_test ("/client/search-uid/exact/name", uid_test, book_client,
+	add_client_test ("/client/search-uid/suffix/phone", uid_test,
+	                 e_book_query_field_test (E_CONTACT_TEL, E_BOOK_QUERY_ENDS_WITH, "999"),
+	                 2);
+	add_client_test ("/client/search-uid/suffix/email", uid_test,
 	                 e_book_query_field_test (E_CONTACT_EMAIL, E_BOOK_QUERY_ENDS_WITH, "jackson.com"),
 	                 2);
 
-	/* Test remove operation */
-	add_client_test ("/client/remove", remove_test, book_client, NULL, 0);
+	ret = e_test_server_utils_run ();
 
-	/* Roll dices */
-	g_object_unref (book_client);
+	g_list_free_full (closures, client_test_data_free);
 
-	return g_test_run ();
+	return ret;
 }
diff --git a/tests/libebook/client/test-client-get-contact-uids.c b/tests/libebook/client/test-client-get-contact-uids.c
index a2edcb3..51bfd1c 100644
--- a/tests/libebook/client/test-client-get-contact-uids.c
+++ b/tests/libebook/client/test-client-get-contact-uids.c
@@ -4,91 +4,105 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
+
+
+static void
+test_get_contact_uids_sync (ETestServerFixture *fixture,
+			    gconstpointer       user_data)
+{
+	EBookClient *book_client;
+	EContact *contact = NULL;
+	EBookQuery *query;
+	gchar *sexp;
+	GSList *contacts = NULL;
+	GError *error = NULL;
+
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
+		g_error ("Failed to add contact");
+	}
+	g_object_unref (contact);
+
+	query = e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, "Foo Bar");
+	sexp = e_book_query_to_string (query);
+
+	if (!e_book_client_get_contacts_uids_sync (book_client, sexp, &contacts, NULL, &error)) {
+		g_error ("get contacts uids: %s", error->message);
+	}
+
+	g_assert_cmpint (g_slist_length (contacts), ==, 1);
+	e_util_free_string_slist (contacts);
+
+	e_book_query_unref (query);
+	g_free (sexp);
+
+}
 
 static void
 contacts_ready_cb (GObject *source_object,
 		   GAsyncResult *result,
 		   gpointer user_data)
 {
+	GMainLoop *loop = (GMainLoop *)user_data;
 	GError *error = NULL;
 	GSList *contacts = NULL;
 
 	if (!e_book_client_get_contacts_uids_finish (E_BOOK_CLIENT (source_object), result, &contacts, &error)) {
-		report_error ("get contact finish", &error);
+		g_error ("get contact finish: %s", error->message);
 		stop_main_loop (1);
 	} else {
 
-		g_assert (g_slist_length (contacts) == 1);
+		g_assert_cmpint (g_slist_length (contacts), ==, 1);
 		e_util_free_string_slist (contacts);
-
-		stop_main_loop (0);
 	}
+
+	g_main_loop_quit (loop);
 }
 
-gint
-main (gint argc,
-      gchar **argv)
+static void
+test_get_contact_uids_async (ETestServerFixture *fixture,
+			     gconstpointer       user_data)
 {
 	EBookClient *book_client;
-	EContact *contact_final;
-	GError *error = NULL;
+	EContact *contact = NULL;
 	EBookQuery *query;
 	gchar *sexp;
-	GSList *contacts = NULL;
-
-	main_initialize ();
-
-	/*
-	 * Setup
-	 */
-	book_client = new_temp_client (NULL);
-	g_return_val_if_fail (book_client != NULL, 1);
 
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
-	/* Add contact */
-	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact_final)) {
-		g_object_unref (book_client);
-		return 1;
+	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
+		g_error ("Failed to add contact");
 	}
-	g_object_unref (contact_final);
+	g_object_unref (contact);
 
-	/*
-	 * Sync version
-	 */
 	query = e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, "Foo Bar");
 	sexp = e_book_query_to_string (query);
 
-	if (!e_book_client_get_contacts_uids_sync (book_client, sexp, &contacts, NULL, &error)) {
-		report_error ("get contacts uids", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
-
-	g_assert (g_slist_length (contacts) == 1);
-	e_util_free_string_slist (contacts);
-
-	/*
-	 * Async version
-	 */
-	e_book_client_get_contacts_uids (book_client, sexp, NULL, contacts_ready_cb, NULL);
+	e_book_client_get_contacts_uids (book_client, sexp, NULL, contacts_ready_cb, fixture->loop);
 
 	e_book_query_unref (query);
 	g_free (sexp);
 
-	start_main_loop (NULL, NULL);
+	g_main_loop_run (fixture->loop);
+}
 
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+gint
+main (gint argc,
+      gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	g_object_unref (book_client);
+	g_test_add ("/EBookClient/GetContactUids/Sync", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_get_contact_uids_sync, e_test_server_utils_teardown);
+	g_test_add ("/EBookClient/GetContactUids/Async", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_get_contact_uids_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-get-contact.c b/tests/libebook/client/test-client-get-contact.c
index 8c27483..e19ff94 100644
--- a/tests/libebook/client/test-client-get-contact.c
+++ b/tests/libebook/client/test-client-get-contact.c
@@ -4,70 +4,79 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
+
+
+static void
+test_get_contact_sync (ETestServerFixture *fixture,
+		       gconstpointer       user_data)
+{
+	EBookClient *book_client;
+	EContact *contact = NULL;
+
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
+		g_error ("Failed to get contact");
+	}
+
+	g_assert (contact != NULL);
+	g_object_unref (contact);
+}
 
 static void
 contact_ready_cb (GObject *source_object,
                   GAsyncResult *result,
                   gpointer user_data)
 {
+	GMainLoop *loop = (GMainLoop *)user_data;
 	EContact *contact;
 	GError *error = NULL;
 
 	if (!e_book_client_get_contact_finish (E_BOOK_CLIENT (source_object), result, &contact, &error)) {
-		report_error ("get contact finish", &error);
-		stop_main_loop (1);
-	} else {
-		g_object_unref (contact);
-		stop_main_loop (0);
-	}
+		g_error ("get contact finish: %s", error->message);
+	} 
+
+	g_object_unref (contact);
+	g_main_loop_quit (loop);
 }
 
-gint
-main (gint argc,
-      gchar **argv)
+static void
+test_get_contact_async (ETestServerFixture *fixture,
+			gconstpointer       user_data)
 {
 	EBookClient *book_client;
-	EContact *contact_final;
-	GError *error = NULL;
+	EContact *contact = NULL;
 
-	main_initialize ();
-
-	/*
-	 * Setup
-	 */
-	book_client = new_temp_client (NULL);
-	g_return_val_if_fail (book_client != NULL, 1);
-
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
-	/*
-	 * Sync version
-	 */
-	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact_final)) {
-		g_object_unref (book_client);
-		return 1;
+	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
+		g_error ("Failed to get contact");
 	}
 
-	/*
-	 * Async version
-	 */
-	e_book_client_get_contact (book_client, e_contact_get_const (contact_final, E_CONTACT_UID), NULL, contact_ready_cb, NULL);
-
-	g_object_unref (contact_final);
+	e_book_client_get_contact (book_client,
+				   e_contact_get_const (contact, E_CONTACT_UID),
+				   NULL, contact_ready_cb, fixture->loop);
+	g_object_unref (contact);
+	g_main_loop_run (fixture->loop);
+}
 
-	start_main_loop (NULL, NULL);
 
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+gint
+main (gint argc,
+      gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	g_object_unref (book_client);
+	g_test_add ("/EBookClient/GetContact/Sync", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_get_contact_sync, e_test_server_utils_teardown);
+	g_test_add ("/EBookClient/GetContact/Async", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_get_contact_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-get-revision.c b/tests/libebook/client/test-client-get-revision.c
index adac4ed..6bc2970 100644
--- a/tests/libebook/client/test-client-get-revision.c
+++ b/tests/libebook/client/test-client-get-revision.c
@@ -5,6 +5,9 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 
 #define CYCLES 10
 
@@ -42,40 +45,31 @@ get_revision_compare_cycle (EBookClient *client)
        g_free (revision_after);
 }
 
-gint
-main (gint argc,
-      gchar **argv)
+static void
+test_get_revision (ETestServerFixture *fixture,
+		   gconstpointer       user_data)
 {
 	EBookClient *book_client;
-	GError      *error = NULL;
-	gint         i;
+	gint i;
 
-	g_type_init ();
-
-	/*
-	 * Setup
-	 */
-	book_client = new_temp_client (NULL);
-
-	g_return_val_if_fail (book_client != NULL, 1);
-
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
 	/* Test that modifications make the revisions increment */
 	for (i = 0; i < CYCLES; i++)
 		get_revision_compare_cycle (book_client);
+}
 
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+gint
+main (gint argc,
+      gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	g_object_unref (book_client);
+	g_test_add ("/EBookClient/GetRevision", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_get_revision, e_test_server_utils_teardown);
 
-	return 0;
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-get-view.c b/tests/libebook/client/test-client-get-view.c
index 55cafae..e4c9f3a 100644
--- a/tests/libebook/client/test-client-get-view.c
+++ b/tests/libebook/client/test-client-get-view.c
@@ -4,6 +4,9 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 
 static void
 objects_added (EBookClientView *view,
@@ -29,30 +32,34 @@ objects_removed (EBookClientView *view,
 
 static void
 complete (EBookClientView *view,
-          const GError *error)
+          const GError *error,
+	  gpointer user_data)
 {
+	GMainLoop *loop = (GMainLoop *)user_data;
+
 	e_book_client_view_stop (view, NULL);
 	g_object_unref (view);
 
-	stop_main_loop (0);
+	g_main_loop_quit (loop);
 }
 
 static void
-setup_and_start_view (EBookClientView *view)
+setup_and_start_view (EBookClientView *view,
+		      GMainLoop       *loop)
 {
 	GError *error = NULL;
 
 	g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), NULL);
 	g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), NULL);
-	g_signal_connect (view, "complete", G_CALLBACK (complete), NULL);
+	g_signal_connect (view, "complete", G_CALLBACK (complete), loop);
 
 	e_book_client_view_set_fields_of_interest (view, NULL, &error);
 	if (error)
-		report_error ("set fields of interest", &error);
+		g_error ("set fields of interest: %s", error->message);
 
 	e_book_client_view_start (view, &error);
 	if (error)
-		report_error ("start view", &error);
+		g_error ("start view: %s", error->message);
 }
 
 static void
@@ -60,126 +67,90 @@ get_view_cb (GObject *source_object,
              GAsyncResult *result,
              gpointer user_data)
 {
+	GMainLoop *loop = (GMainLoop *)user_data;
 	EBookClientView *view;
 	GError *error = NULL;
 
 	if (!e_book_client_get_view_finish (E_BOOK_CLIENT (source_object), result, &view, &error)) {
-		report_error ("get view finish", &error);
-		stop_main_loop (1);
-
-		return;
+		g_error ("get view finish: %s", error->message);
 	}
 
-	setup_and_start_view (view);
+	setup_and_start_view (view, loop);
 }
 
-static gboolean
-setup_book (EBookClient **book_client)
+static void
+setup_book (EBookClient *book_client)
 {
-	GError *error = NULL;
-
-	g_return_val_if_fail (book_client != NULL, FALSE);
-
-	*book_client = new_temp_client (NULL);
-	g_return_val_if_fail (*book_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (*book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (*book_client);
-		return FALSE;
-	}
-
-	if (!add_contact_from_test_case_verify (*book_client, "simple-1", NULL) ||
-	    !add_contact_from_test_case_verify (*book_client, "simple-2", NULL) ||
-	    !add_contact_from_test_case_verify (*book_client, "name-only", NULL)) {
-		g_object_unref (*book_client);
-		return FALSE;
+	if (!add_contact_from_test_case_verify (book_client, "simple-1", NULL) ||
+	    !add_contact_from_test_case_verify (book_client, "simple-2", NULL) ||
+	    !add_contact_from_test_case_verify (book_client, "name-only", NULL)) {
+		g_error ("Failed to add contacts");
 	}
-
-	return TRUE;
 }
 
-static gpointer
-call_get_view (gpointer user_data)
+static void
+test_get_view_sync (ETestServerFixture *fixture,
+		    gconstpointer       user_data)
 {
+	EBookClient *book_client;
 	EBookQuery *query;
-	EBookClient *book_client = user_data;
+	EBookClientView *view;
 	gchar *sexp;
+	GError *error = NULL;
+
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
-	g_return_val_if_fail (book_client != NULL, NULL);
-	g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), NULL);
+	setup_book (book_client);
 
 	query = e_book_query_any_field_contains ("");
 	sexp = e_book_query_to_string (query);
 	e_book_query_unref (query);
-
-	e_book_client_get_view (book_client, sexp, NULL, get_view_cb, NULL);
+	if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
+		g_error ("get book view sync: %s", error->message);
+		g_free (sexp);
+		g_object_unref (book_client);
+	}
 
 	g_free (sexp);
 
-	return NULL;
+	setup_and_start_view (view, fixture->loop);
+	g_main_loop_run (fixture->loop);
 }
 
-gint
-main (gint argc,
-      gchar **argv)
+static void
+test_get_view_async (ETestServerFixture *fixture,
+		     gconstpointer       user_data)
 {
 	EBookClient *book_client;
 	EBookQuery *query;
-	EBookClientView *view;
 	gchar *sexp;
-	GError *error = NULL;
-
-	main_initialize ();
 
-	/*
-	 * Sync version
-	 */
-	if (!setup_book (&book_client))
-		return 1;
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
+	setup_book (book_client);
 	query = e_book_query_any_field_contains ("");
 	sexp = e_book_query_to_string (query);
 	e_book_query_unref (query);
-	if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
-		report_error ("get book view sync", &error);
-		g_free (sexp);
-		g_object_unref (book_client);
 
-		return 1;
-	}
+	e_book_client_get_view (book_client, sexp, NULL, get_view_cb, fixture->loop);
 
 	g_free (sexp);
+	g_main_loop_run (fixture->loop);
+}
 
-	setup_and_start_view (view);
-
-	start_main_loop (NULL, NULL);
-
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-
-		return 1;
-	}
-
-	g_object_unref (book_client);
-
-	/*
-	 * Async version
-	 */
-	if (!setup_book (&book_client))
-		return 1;
-
-	start_in_idle_with_main_loop (call_get_view, book_client);
-
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-
-		return 1;
-	}
+gint
+main (gint argc,
+      gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	g_object_unref (book_client);
+	g_test_add ("/EBookClient/GetBookClientView/Sync", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_get_view_sync, e_test_server_utils_teardown);
+	g_test_add ("/EBookClient/GetBookClientView/Async", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_get_view_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-modify-contact.c b/tests/libebook/client/test-client-modify-contact.c
index d9d0aae..10817d4 100644
--- a/tests/libebook/client/test-client-modify-contact.c
+++ b/tests/libebook/client/test-client-modify-contact.c
@@ -4,6 +4,9 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 
 #define EMAIL_ADD "foo bar com"
 
@@ -32,24 +35,55 @@ verify_modify (EContact *contact)
 }
 
 static void
+test_modify_contact_sync (ETestServerFixture *fixture,
+			  gconstpointer       user_data)
+{
+	EBookClient *book_client;
+	GError *error = NULL;
+	EContact *contact, *book_contact;
+
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+	if (!add_contact_from_test_case_verify (book_client, "name-only", &contact))
+		g_error ("Failed to add contact");
+
+	verify_premodify_and_prepare_contact (contact);
+
+	if (!e_book_client_modify_contact_sync (book_client, contact, NULL, &error))
+		g_error ("modify contact sync: %s", error->message);
+
+	if (!e_book_client_get_contact_sync (book_client, e_contact_get_const (contact, E_CONTACT_UID),
+					     &book_contact, NULL, &error))
+		g_error ("get contact sync: %s", error->message);
+
+	verify_modify (book_contact);
+	g_object_unref (book_contact);
+	g_object_unref (contact);
+}
+
+
+typedef struct {
+	EContact *contact;
+	GMainLoop *loop;
+} ModifyData;
+
+
+static void
 contact_ready_cb (GObject *source_object,
                   GAsyncResult *result,
                   gpointer user_data)
 {
 	EContact *contact;
 	GError *error = NULL;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
-	if (!e_book_client_get_contact_finish (E_BOOK_CLIENT (source_object), result, &contact, &error)) {
-		report_error ("get contact finish", &error);
-		stop_main_loop (1);
-		return;
-	}
+	if (!e_book_client_get_contact_finish (E_BOOK_CLIENT (source_object), result, &contact, &error))
+		g_error ("get contact finish: %s", error->message);
 
 	verify_modify (contact);
 
 	g_object_unref (contact);
-
-	stop_main_loop (0);
+	g_main_loop_quit (loop);
 }
 
 static void
@@ -57,108 +91,54 @@ contact_modified_cb (GObject *source_object,
                      GAsyncResult *result,
                      gpointer user_data)
 {
-	EContact *contact = user_data;
+	ModifyData *data = (ModifyData *)user_data;
 	GError *error = NULL;
 
-	if (!e_book_client_modify_contact_finish (E_BOOK_CLIENT (source_object), result, &error)) {
-		report_error ("modify contact finish", &error);
-		stop_main_loop (1);
-		return;
-	}
+	if (!e_book_client_modify_contact_finish (E_BOOK_CLIENT (source_object), result, &error))
+		g_error ("modify contact finish: %s", error->message);
 
-	e_book_client_get_contact (E_BOOK_CLIENT (source_object), e_contact_get_const (contact, E_CONTACT_UID), NULL, contact_ready_cb, NULL);
+	e_book_client_get_contact (E_BOOK_CLIENT (source_object),
+				   e_contact_get_const (data->contact, E_CONTACT_UID),
+				   NULL, contact_ready_cb, data->loop);
 }
 
-gint
-main (gint argc,
-      gchar **argv)
+static void
+test_modify_contact_async (ETestServerFixture *fixture,
+			  gconstpointer       user_data)
 {
 	EBookClient *book_client;
-	GError *error = NULL;
-	EContact *contact, *book_contact;
-
-	main_initialize ();
-
-	/*
-	 * Setup
-	 */
-	book_client = new_temp_client (NULL);
-	g_return_val_if_fail (book_client != NULL, 1);
-
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
-
-	/*
-	 * Sync version
-	 */
-	if (!add_contact_from_test_case_verify (book_client, "name-only", &contact)) {
-		g_object_unref (book_client);
-		return 1;
-	}
-
-	verify_premodify_and_prepare_contact (contact);
-
-	if (!e_book_client_modify_contact_sync (book_client, contact, NULL, &error)) {
-		report_error ("modify contact sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
-
-	if (!e_book_client_get_contact_sync (book_client, e_contact_get_const (contact, E_CONTACT_UID), &book_contact, NULL, &error)) {
-		report_error ("get contact sync", &error);
-		g_object_unref (contact);
-		g_object_unref (book_client);
-		return 1;
-	}
-
-	verify_modify (book_contact);
-
-	g_object_unref (book_contact);
-	g_object_unref (contact);
-
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
-
-	g_object_unref (book_client);
-
-	/*
-	 * Async version
-	 */
-	book_client = new_temp_client (NULL);
-	g_return_val_if_fail (book_client != NULL, 1);
+	EContact *contact;
+	ModifyData data;
 
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
-	if (!add_contact_from_test_case_verify (book_client, "name-only", &contact)) {
-		g_object_unref (book_client);
-		return 1;
-	}
+	if (!add_contact_from_test_case_verify (book_client, "name-only", &contact))
+		g_error ("Failed to add contact");
 
 	verify_premodify_and_prepare_contact (contact);
 
-	e_book_client_modify_contact (book_client, contact, NULL, contact_modified_cb, contact);
+	data.contact = contact;
+	data.loop = fixture->loop;
+	e_book_client_modify_contact (book_client, contact, NULL, contact_modified_cb, &data);
 
-	start_main_loop (NULL, NULL);
+	g_main_loop_run (fixture->loop);
 
 	g_object_unref (contact);
+}
 
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+gint
+main (gint argc,
+      gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	g_object_unref (book_client);
+	g_test_add ("/EBookClient/ModifyContact/Sync", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_modify_contact_sync, e_test_server_utils_teardown);
+	g_test_add ("/EBookClient/ModifyContact/Async", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_modify_contact_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-photo-is-uri.c b/tests/libebook/client/test-client-photo-is-uri.c
index ea4ba20..1621e26 100644
--- a/tests/libebook/client/test-client-photo-is-uri.c
+++ b/tests/libebook/client/test-client-photo-is-uri.c
@@ -3,6 +3,9 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 
 static const gchar *photo_data =
 "/9j / 4AAQSkZJRgABAQEARwBHAAD//gAXQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q / 9sAQwAIBgYHB\
@@ -238,11 +241,11 @@ setup_and_start_view (EBookClientView *view)
 
 	e_book_client_view_set_fields_of_interest (view, NULL, &error);
 	if (error)
-		report_error ("set fields of interest", &error);
+		g_error ("set fields of interest: %s", error->message);
 
 	e_book_client_view_start (view, &error);
 	if (error)
-		report_error ("start view", &error);
+		g_error ("start view: %s", error->message);
 }
 
 static void
@@ -296,64 +299,45 @@ add_contact_uri (EBookClient *book)
 }
 
 static void
-setup_book (EBookClient **book_out)
-{
-	EBookClient *book;
-	GError      *error = NULL;
-
-	book = new_temp_client (NULL);
-	g_assert (book != NULL);
-
-	if (!e_client_open_sync (E_CLIENT (book), FALSE, NULL, &error)) {
-		g_error ("failed to open client: %s", error->message);
-	}
-
-	add_contact_inline (book);
-	add_contact_uri (book);
-
-	*book_out = book;
-}
-
-gint
-main (gint argc,
-      gchar **argv)
+test_photo_is_uri (ETestServerFixture *fixture,
+		   gconstpointer       user_data)
 {
-	EBookClient *book;
+	EBookClient *book_client;
 	EBookClientView *view;
 	EBookQuery *query;
 	GError     *error = NULL;
 	gchar      *sexp;
 
-	g_type_init ();
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
-	setup_book (&book);
+	add_contact_inline (book_client);
+	add_contact_uri (book_client);
 
 	query = e_book_query_any_field_contains ("");
 	sexp = e_book_query_to_string (query);
 	e_book_query_unref (query);
-	if (!e_book_client_get_view_sync (book, sexp, &view, NULL, &error)) {
-		report_error ("get book view sync", &error);
-		g_free (sexp);
-		g_object_unref (book);
-
-		return 1;
-	}
+	if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error))
+		g_error ("get book view sync: %s", error->message);
 
 	g_free (sexp);
 
 	setup_and_start_view (view);
 
-	loop = g_main_loop_new (NULL, TRUE);
+	loop = fixture->loop;
 	g_main_loop_run (loop);
+}
 
-	if (!e_client_remove_sync (E_CLIENT (book), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book);
-
-		return 1;
-	}
+gint
+main (gint argc,
+      gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	g_object_unref (book);
+	g_test_add ("/EBookClient/PhotoIsUri", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_photo_is_uri, e_test_server_utils_teardown);
 
-	return 0;
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-refresh.c b/tests/libebook/client/test-client-refresh.c
index 9ffaef3..8ef2385 100644
--- a/tests/libebook/client/test-client-refresh.c
+++ b/tests/libebook/client/test-client-refresh.c
@@ -5,21 +5,9 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
 
-static gboolean
-test_sync (EBookClient *book_client)
-{
-	GError *error = NULL;
-
-	g_print ("Refresh supported: %s\n", e_client_check_refresh_supported (E_CLIENT (book_client)) ? "yes" : "no");
-
-	if (!e_client_refresh_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("refresh sync", &error);
-		return FALSE;
-	}
-
-	return TRUE;
-}
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 
 /* asynchronous callback with a main-loop running */
 static void
@@ -29,89 +17,73 @@ async_refresh_result_ready (GObject *source_object,
 {
 	EBookClient *book_client;
 	GError *error = NULL;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
 	book_client = E_BOOK_CLIENT (source_object);
 
 	if (!e_client_refresh_finish (E_CLIENT (book_client), result, &error)) {
-		report_error ("refresh finish", &error);
-		stop_main_loop (1);
+		g_error ("refresh finish: %s", error->message);
 		return;
 	}
 
-	stop_main_loop (0);
+	g_main_loop_quit (loop);	
 }
 
-/* synchronously in idle with main-loop running */
-static gboolean
-test_sync_in_idle (gpointer user_data)
+static void
+test_refresh_sync (ETestServerFixture *fixture,
+		   gconstpointer       user_data)
 {
-	EBookClient *book_client = user_data;
-
-	g_return_val_if_fail (book_client != NULL, FALSE);
-	g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), FALSE);
+	EBookClient *book_client;
+	GError *error = NULL;
 
-	if (!test_sync (book_client)) {
-		stop_main_loop (1);
-		return FALSE;
-	}
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
 	g_print ("Refresh supported: %s\n", e_client_check_refresh_supported (E_CLIENT (book_client)) ? "yes" : "no");
+	if (!e_client_check_refresh_supported (E_CLIENT (book_client)))
+		return;
 
-	e_client_refresh (E_CLIENT (book_client), NULL, async_refresh_result_ready, NULL);
+	if (!e_client_refresh_sync (E_CLIENT (book_client), NULL, &error)) {
+		g_error ("Error in refresh: %s", error->message);
+	}
+}
 
+static gboolean
+main_loop_fail_timeout (gpointer unused)
+{
+	g_error ("Failed to refresh, async call timed out");
 	return FALSE;
 }
 
-/* synchronously in a dedicated thread with main-loop running */
-static gpointer
-test_sync_in_thread (gpointer user_data)
+static void
+test_refresh_async (ETestServerFixture *fixture,
+		    gconstpointer       user_data)
 {
-	if (!test_sync (user_data)) {
-		stop_main_loop (1);
-		return NULL;
-	}
+	EBookClient *book_client;
 
-	g_idle_add (test_sync_in_idle, user_data);
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
-	return NULL;
+	g_print ("Refresh supported: %s\n", e_client_check_refresh_supported (E_CLIENT (book_client)) ? "yes" : "no");
+	if (!e_client_check_refresh_supported (E_CLIENT (book_client)))
+		return;
+
+	e_client_refresh (E_CLIENT (book_client), NULL, async_refresh_result_ready, fixture->loop);
+	g_timeout_add (5 * 1000, (GSourceFunc)main_loop_fail_timeout, NULL);
+	g_main_loop_run (fixture->loop);
 }
 
 gint
 main (gint argc,
       gchar **argv)
 {
-	EBookClient *book_client;
-	GError *error = NULL;
-
-	main_initialize ();
-
-	book_client = new_temp_client (NULL);
-	g_return_val_if_fail (book_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
-
-	/* synchronously without main-loop */
-	if (!test_sync (book_client)) {
-		g_object_unref (book_client);
-		return 1;
-	}
-
-	start_in_thread_with_main_loop (test_sync_in_thread, book_client);
-
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
-
-	g_object_unref (book_client);
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	if (get_main_loop_stop_result () == 0)
-		g_print ("Test finished successfully.\n");
+	g_test_add ("/EBookClient/Refresh/Sync", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_refresh_sync, e_test_server_utils_teardown);
+	g_test_add ("/EBookClient/Refresh/Async", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_refresh_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-remove-contact-by-uid.c b/tests/libebook/client/test-client-remove-contact-by-uid.c
index bc1c5c5..a9dd9cc 100644
--- a/tests/libebook/client/test-client-remove-contact-by-uid.c
+++ b/tests/libebook/client/test-client-remove-contact-by-uid.c
@@ -3,128 +3,103 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
 
-static void
-remove_contact_by_uid_cb (GObject *source_object,
-                          GAsyncResult *result,
-                          gpointer uid)
-{
-	GError *error = NULL;
-	EContact *contact = NULL;
-
-	if (!e_book_client_remove_contact_by_uid_finish (E_BOOK_CLIENT (source_object), result, &error)) {
-		report_error ("remove contact by uid finish", &error);
-		stop_main_loop (1);
-		return;
-	}
-
-	if (!e_book_client_get_contact_sync (E_BOOK_CLIENT (source_object), uid, &contact, NULL, &error) &&
-	    g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
-		g_clear_error (&error);
-		stop_main_loop (0);
-	} else {
-		report_error ("fail with get contact on removed contact", &error);
-		if (contact)
-			g_object_unref (contact);
-		stop_main_loop (1);
-	}
-}
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 
-gint
-main (gint argc,
-      gchar **argv)
+static void
+test_remove_contact_by_uid_sync (ETestServerFixture *fixture,
+				 gconstpointer       user_data)
 {
 	EBookClient *book_client;
 	GError *error = NULL;
 	EContact *contact;
 	gchar *uid;
 
-	main_initialize ();
-
-        /*
-         * Setup
-         */
-	book_client = new_temp_client (NULL);
-	g_return_val_if_fail (book_client != NULL, 1);
-
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
-        /*
-         * Sync version
-         */
-	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
-		g_object_unref (book_client);
-		return 1;
-	}
+	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact))
+		g_error ("Failed to add contact");
 
 	uid = e_contact_get (contact, E_CONTACT_UID);
-	g_object_unref (contact);
 
-	if (!e_book_client_remove_contact_by_uid_sync (book_client, uid, NULL, &error)) {
-		report_error ("remove contact sync", &error);
-		g_object_unref (book_client);
-		g_free (uid);
-		return 1;
-	}
+	if (!e_book_client_remove_contact_by_uid_sync (book_client, uid, NULL, &error))
+		g_error ("remove contact sync: %s", error->message);
 
 	if (!e_book_client_get_contact_sync (book_client, uid, &contact, NULL, &error) &&
 	    g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
 		g_clear_error (&error);
-	} else {
-		report_error ("fail with get contact sync on removed contact", &error);
-		g_object_unref (book_client);
-		g_free (uid);
-		return 1;
-	}
+	} else
+		g_error ("fail with get contact sync on removed contact: %s", error->message);
 
 	g_free (uid);
+}
 
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+typedef struct {
+	const gchar *uid;
+	GMainLoop *loop;
+} RemoveData;
 
-	g_object_unref (book_client);
+static void
+remove_contact_by_uid_cb (GObject *source_object,
+                          GAsyncResult *result,
+                          gpointer user_data)
+{
+	RemoveData *data = (RemoveData *)user_data;
+	GError *error = NULL;
+	EContact *contact = NULL;
 
-        /*
-         * Async version
-         */
-	book_client = new_temp_client (NULL);
-	g_return_val_if_fail (book_client != NULL, 1);
+	if (!e_book_client_remove_contact_by_uid_finish (E_BOOK_CLIENT (source_object), result, &error))
+		g_error ("remove contact by uid finish: %s", error->message);
 
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+	if (!e_book_client_get_contact_sync (E_BOOK_CLIENT (source_object), data->uid, &contact, NULL, &error) &&
+	    g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
+		g_clear_error (&error);
+	} else
+		g_error ("fail with get contact on removed contact: %s", error->message);
 
-	contact = NULL;
+	g_main_loop_quit (data->loop);
+}
 
-	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
-		g_object_unref (book_client);
-		return 1;
-	}
+static void
+test_remove_contact_by_uid_async (ETestServerFixture *fixture,
+				  gconstpointer       user_data)
+{
+	EBookClient *book_client;
+	EContact *contact = NULL;
+	gchar *uid;
+	RemoveData data;
+
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact))
+		g_error ("Failed to add contact");
 
 	uid = e_contact_get (contact, E_CONTACT_UID);
-	g_object_unref (contact);
-	e_book_client_remove_contact_by_uid (book_client, uid, NULL, remove_contact_by_uid_cb, uid);
 
-	start_main_loop (NULL, NULL);
+	data.uid = uid;
+	data.loop = fixture->loop;
+	e_book_client_remove_contact_by_uid (book_client, uid, NULL, remove_contact_by_uid_cb, &data);
+
+	g_object_unref (contact);
 
+	g_main_loop_run (fixture->loop);
 	g_free (uid);
+}
 
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+gint
+main (gint argc,
+      gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	g_object_unref (book_client);
+	g_test_add ("/EBookClient/RemoveContactByUid/Sync", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_remove_contact_by_uid_sync, e_test_server_utils_teardown);
+	g_test_add ("/EBookClient/RemoveContactByUid/Async", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_remove_contact_by_uid_async, e_test_server_utils_teardown);
 
-	return 0;
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-remove-contact.c b/tests/libebook/client/test-client-remove-contact.c
index a945d75..23bd215 100644
--- a/tests/libebook/client/test-client-remove-contact.c
+++ b/tests/libebook/client/test-client-remove-contact.c
@@ -3,131 +3,106 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
 
-static void
-remove_contact_cb (GObject *source_object,
-                   GAsyncResult *result,
-                   gpointer uid)
-{
-	GError *error = NULL;
-	EContact *contact = NULL;
-
-	if (!e_book_client_remove_contact_finish (E_BOOK_CLIENT (source_object), result, &error)) {
-		report_error ("remove contact finish", &error);
-		stop_main_loop (1);
-		return;
-	}
-
-	if (!e_book_client_get_contact_sync (E_BOOK_CLIENT (source_object), uid, &contact, NULL, &error) &&
-	    g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
-		g_clear_error (&error);
-		stop_main_loop (0);
-	} else {
-		report_error ("fail with get contact on removed contact", &error);
-		if (contact)
-			g_object_unref (contact);
-		stop_main_loop (1);
-	}
-}
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 
-gint
-main (gint argc,
-      gchar **argv)
+static void
+test_remove_contact_sync (ETestServerFixture *fixture,
+			  gconstpointer       user_data)
 {
 	EBookClient *book_client;
 	GError *error = NULL;
 	EContact *contact;
 	gchar *uid;
 
-	main_initialize ();
-
-        /*
-         * Setup
-         */
-	book_client = new_temp_client (NULL);
-	g_return_val_if_fail (book_client != NULL, 1);
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
-
-        /*
-         * Sync version
-         */
-	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
-		g_object_unref (book_client);
-		return 1;
-	}
+	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact))
+		g_error ("Failed to add contact");
 
 	uid = e_contact_get (contact, E_CONTACT_UID);
 
-	if (!e_book_client_remove_contact_sync (book_client, contact, NULL, &error)) {
-		report_error ("remove contact sync", &error);
-		g_object_unref (contact);
-		g_object_unref (book_client);
-		g_free (uid);
-		return 1;
-	}
+	if (!e_book_client_remove_contact_sync (book_client, contact, NULL, &error))
+		g_error ("remove contact sync: %s", error->message);
 
 	g_object_unref (contact);
 
 	if (!e_book_client_get_contact_sync (book_client, uid, &contact, NULL, &error) &&
 	    g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
 		g_clear_error (&error);
-	} else {
-		report_error ("fail with get contact sync on removed contact", &error);
-		g_object_unref (book_client);
-		g_free (uid);
-		return 1;
-	}
+	} else
+		g_error ("fail with get contact sync on removed contact: %s", error->message);
 
 	g_free (uid);
+}
+
+typedef struct {
+	const gchar *uid;
+	GMainLoop *loop;
+} RemoveData;
+
+static void
+remove_contact_cb (GObject *source_object,
+                   GAsyncResult *result,
+                   gpointer user_data)
+{
+	RemoveData *data = (RemoveData *)user_data;
+	GError *error = NULL;
+	EContact *contact = NULL;
 
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+	if (!e_book_client_remove_contact_finish (E_BOOK_CLIENT (source_object), result, &error))
+		g_error ("remove contact finish: %s", error->message);
 
-	g_object_unref (book_client);
+	if (!e_book_client_get_contact_sync (E_BOOK_CLIENT (source_object), data->uid, &contact, NULL, &error) &&
+	    g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
+		g_clear_error (&error);
+	} else
+		g_error ("fail with get contact on removed contact: %s", error->message);
 
-        /*
-         * Async version
-         */
-	book_client = new_temp_client (NULL);
-	g_return_val_if_fail (book_client != NULL, 1);
+	g_main_loop_quit (data->loop);
+}
 
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+static void
+test_remove_contact_async (ETestServerFixture *fixture,
+			   gconstpointer       user_data)
+{
+	EBookClient *book_client;
+	EContact *contact = NULL;
+	gchar *uid;
+	RemoveData data;
 
-	contact = NULL;
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
-	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
-		g_object_unref (book_client);
-		return 1;
-	}
+	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact))
+		g_error ("Failed to add contact");
 
 	uid = e_contact_get (contact, E_CONTACT_UID);
-	e_book_client_remove_contact (book_client, contact, NULL, remove_contact_cb, uid);
 
-	g_object_unref (contact);
+	data.uid = uid;
+	data.loop = fixture->loop;
+	e_book_client_remove_contact (book_client, contact, NULL, remove_contact_cb, &data);
 
-	start_main_loop (NULL, NULL);
+	g_object_unref (contact);
 
+	g_main_loop_run (fixture->loop);
 	g_free (uid);
+}
 
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
 
-	g_object_unref (book_client);
+gint
+main (gint argc,
+      gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
+
+	g_test_add ("/EBookClient/RemoveContact/Sync", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_remove_contact_sync, e_test_server_utils_teardown);
+	g_test_add ("/EBookClient/RemoveContact/Async", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_remove_contact_async, e_test_server_utils_teardown);
 
-	return 0;
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-remove-contacts.c b/tests/libebook/client/test-client-remove-contacts.c
index cdba188..bc9a3be 100644
--- a/tests/libebook/client/test-client-remove-contacts.c
+++ b/tests/libebook/client/test-client-remove-contacts.c
@@ -3,13 +3,16 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
 
-static gboolean
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
+
+static void
 check_removed (EBookClient *book_client,
                const GSList *uids)
 {
-	g_return_val_if_fail (book_client != NULL, FALSE);
-	g_return_val_if_fail (uids != NULL, FALSE);
+	g_return_if_fail (book_client != NULL);
+	g_return_if_fail (uids != NULL);
 
 	while (uids) {
 		GError *error = NULL;
@@ -18,17 +21,11 @@ check_removed (EBookClient *book_client,
 		if (!e_book_client_get_contact_sync (book_client, uids->data, &contact, NULL, &error) &&
 		    g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
 			g_clear_error (&error);
-		} else {
-			report_error ("fail with get contact on removed contact", &error);
-			if (contact)
-				g_object_unref (contact);
-			return FALSE;
-		}
+		} else
+			g_error ("fail with get contact on removed contact: %s", error->message);
 
 		uids = uids->next;
 	}
-
-	return TRUE;
 }
 
 static gboolean
@@ -58,108 +55,83 @@ fill_book_client (EBookClient *book_client,
 }
 
 static void
-remove_contacts_cb (GObject *source_object,
-                    GAsyncResult *result,
-                    gpointer uids)
-{
-	GError *error = NULL;
-
-	if (!e_book_client_remove_contacts_finish (E_BOOK_CLIENT (source_object), result, &error)) {
-		report_error ("remove contacts finish", &error);
-		stop_main_loop (1);
-		return;
-	}
-
-	stop_main_loop (check_removed (E_BOOK_CLIENT (source_object), uids) ? 0 : 1);
-}
-
-gint
-main (gint argc,
-      gchar **argv)
+test_remove_contacts_sync (ETestServerFixture *fixture,
+			   gconstpointer       user_data)
 {
 	EBookClient *book_client;
 	GError *error = NULL;
-	GSList *uids;
-
-	main_initialize ();
-
-        /*
-         * Setup
-         */
-	book_client = new_temp_client (NULL);
-	g_return_val_if_fail (book_client != NULL, 1);
+	GSList *uids = NULL;
 
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
-        /*
-         * Sync version
-         */
-	if (!fill_book_client (book_client, &uids)) {
-		g_object_unref (book_client);
-		return 1;
-	}
+	if (!fill_book_client (book_client, &uids))
+		g_error ("Failed to add contacts");
 
-	if (!e_book_client_remove_contacts_sync (book_client, uids, NULL, &error)) {
-		report_error ("remove contact sync", &error);
-		g_object_unref (book_client);
-		g_slist_foreach (uids, (GFunc) g_free, NULL);
-		g_slist_free (uids);
-		return 1;
-	}
-
-	if (!check_removed (book_client, uids)) {
-		g_object_unref (book_client);
-		g_slist_foreach (uids, (GFunc) g_free, NULL);
-		g_slist_free (uids);
-		return 1;
-	}
+	if (!e_book_client_remove_contacts_sync (book_client, uids, NULL, &error))
+		g_error ("remove contact sync: %s", error->message);
 
+	/* This will assert they are actually removed */
+	check_removed (book_client, uids);
 	g_slist_foreach (uids, (GFunc) g_free, NULL);
 	g_slist_free (uids);
+}
 
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+typedef struct {
+	GSList *uids;
+	GMainLoop *loop;
+} RemoveData;
 
-	g_object_unref (book_client);
+static void
+remove_contacts_cb (GObject *source_object,
+                    GAsyncResult *result,
+                    gpointer user_data)
+{
+	GError *error = NULL;
+	RemoveData *data = (RemoveData *)user_data;
 
-        /*
-         * Async version
-         */
-	book_client = new_temp_client (NULL);
-	g_return_val_if_fail (book_client != NULL, 1);
+	if (!e_book_client_remove_contacts_finish (E_BOOK_CLIENT (source_object), result, &error))
+		g_error ("remove contacts finish: %s", error->message);
 
-	if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+	check_removed (E_BOOK_CLIENT (source_object), data->uids);
+	g_main_loop_quit (data->loop);
+}
 
-	if (!fill_book_client (book_client, &uids)) {
-		g_object_unref (book_client);
-		return 1;
-	}
+static void
+test_remove_contacts_async (ETestServerFixture *fixture,
+			    gconstpointer       user_data)
+{
+	EBookClient *book_client;
+	GSList *uids = NULL;
+	RemoveData data;
+
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+	if (!fill_book_client (book_client, &uids))
+		g_error ("Failed to add contacts");
 
-	e_book_client_remove_contacts (book_client, uids, NULL, remove_contacts_cb, uids);
+	data.uids = uids;
+	data.loop = fixture->loop;
+	e_book_client_remove_contacts (book_client, uids, NULL, remove_contacts_cb, &data);
 
-	start_main_loop (NULL, NULL);
+	g_main_loop_run (fixture->loop);
 
 	g_slist_foreach (uids, (GFunc) g_free, NULL);
 	g_slist_free (uids);
+}
 
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-		return 1;
-	}
+gint
+main (gint argc,
+      gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	g_object_unref (book_client);
+	g_test_add ("/EBookClient/RemoveContacts/Sync", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_remove_contacts_sync, e_test_server_utils_teardown);
+	g_test_add ("/EBookClient/RemoveContacts/Async", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_remove_contacts_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-revision-view.c b/tests/libebook/client/test-client-revision-view.c
index 5a3abba..2301a69 100644
--- a/tests/libebook/client/test-client-revision-view.c
+++ b/tests/libebook/client/test-client-revision-view.c
@@ -4,6 +4,9 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 
 #define N_TEST_CONTACTS 4
 
@@ -25,23 +28,11 @@ add_contact (EBookClient *client)
 	g_object_unref (contact);
 }
 
-static gboolean
-setup_book (EBookClient **book_out)
+static void
+setup_book (EBookClient *book_client)
 {
-	GError *error = NULL;
 	gint    i;
 
-	g_return_val_if_fail (book_out != NULL, FALSE);
-
-	*book_out = new_temp_client (NULL);
-	g_return_val_if_fail (*book_out != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (*book_out), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (*book_out);
-		return FALSE;
-	}
-
 	for (i = 0; i < N_TEST_CONTACTS; i++)
 	{
 		EContact *contact = e_contact_new ();
@@ -51,18 +42,16 @@ setup_book (EBookClient **book_out)
 		e_contact_set (contact, E_CONTACT_NICKNAME, name);
 
 		/* verify the contact was added "successfully" (not thorough) */
-		if (!add_contact_verify (*book_out, contact))
+		if (!add_contact_verify (book_client, contact))
 			g_error ("Failed to add contact");
 
 		g_free (name);
 		g_object_unref (contact);
 	}
-
-	return TRUE;
 }
 
 /****************************************************************
- *                 Handle EClientBookView notifications               *
+ *                 Handle EClientBookView notifications         *
  ****************************************************************/
 static void
 print_contact (EContact *contact)
@@ -74,18 +63,21 @@ print_contact (EContact *contact)
 }
 
 static void
-finish_test (EBookClientView *view)
+finish_test (EBookClientView *view,
+	     GMainLoop *loop)
 {
 	e_book_client_view_stop (view, NULL);
 	g_object_unref (view);
 
-	stop_main_loop (0);
+	g_main_loop_quit (loop);
 }
 
 static void
 objects_added (EBookClientView *view,
-               const GSList *contacts)
+               const GSList *contacts,
+	       gpointer user_data)
 {
+	GMainLoop *loop = (GMainLoop *)user_data;
 	const GSList *l;
 
 	for (l = contacts; l; l = l->next) {
@@ -100,7 +92,7 @@ objects_added (EBookClientView *view,
 	}
 
 	if (!loading_view)
-		finish_test (view);
+		finish_test (view, loop);
 
 }
 
@@ -125,14 +117,15 @@ complete (EBookClientView *view,
 }
 
 static void
-setup_and_start_view (EBookClientView *view)
+setup_and_start_view (EBookClientView *view,
+		      GMainLoop *loop)
 {
 	GError *error = NULL;
 	GSList *field_list;
 
-	g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), NULL);
-	g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), NULL);
-	g_signal_connect (view, "complete", G_CALLBACK (complete), NULL);
+	g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), loop);
+	g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), loop);
+	g_signal_connect (view, "complete", G_CALLBACK (complete), loop);
 
 	field_list = g_slist_prepend (NULL, (gpointer) e_contact_field_name (E_CONTACT_UID));
 	field_list = g_slist_prepend (field_list, (gpointer) e_contact_field_name (E_CONTACT_REV));
@@ -141,13 +134,13 @@ setup_and_start_view (EBookClientView *view)
 	g_slist_free (field_list);
 
 	if (error)
-		report_error ("set fields of interest", &error);
+		g_error ("set fields of interest: %s", error->message);
 
 	loading_view = TRUE;
 
 	e_book_client_view_start (view, &error);
 	if (error)
-		report_error ("start view", &error);
+		g_error ("start view: %s", error->message);
 
 }
 
@@ -158,96 +151,77 @@ get_view_cb (GObject *source_object,
 {
 	EBookClientView *view;
 	GError *error = NULL;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
-	if (!e_book_client_get_view_finish (E_BOOK_CLIENT (source_object), result, &view, &error)) {
-		report_error ("get view finish", &error);
-		stop_main_loop (1);
-
-		return;
-	}
+	if (!e_book_client_get_view_finish (E_BOOK_CLIENT (source_object), result, &view, &error))
+		g_error ("get view finish: %s", error->message);
 
-	setup_and_start_view (view);
+	setup_and_start_view (view, loop);
 }
 
-static gpointer
-call_get_view (gpointer user_data)
+static void
+test_revision_view_sync (ETestServerFixture *fixture,
+			 gconstpointer       user_data)
 {
+	EBookClient *book_client;
 	EBookQuery *query;
-	EBookClient *book_client = user_data;
+	EBookClientView *view;
 	gchar *sexp;
+	GError *error = NULL;
 
-	g_return_val_if_fail (book_client != NULL, NULL);
-	g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), NULL);
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+	setup_book (book_client);
 
 	query = e_book_query_any_field_contains ("");
 	sexp = e_book_query_to_string (query);
 	e_book_query_unref (query);
-
-	e_book_client_get_view (book_client, sexp, NULL, get_view_cb, NULL);
+	if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
+		g_error ("get book view sync: %s", error->message);
+		g_free (sexp);
+		g_object_unref (book_client);
+	}
 
 	g_free (sexp);
 
-	return NULL;
+	setup_and_start_view (view, fixture->loop);
+	g_main_loop_run (fixture->loop);
 }
 
-gint
-main (gint argc,
-      gchar **argv)
+static void
+test_revision_view_async (ETestServerFixture *fixture,
+			  gconstpointer       user_data)
 {
 	EBookClient *book_client;
 	EBookQuery *query;
-	EBookClientView *view;
 	gchar *sexp;
-	GError *error = NULL;
 
-	main_initialize ();
-
-	/*
-	 * Sync version
-	 */
-	if (!setup_book (&book_client))
-		return 1;
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
+	setup_book (book_client);
 	query = e_book_query_any_field_contains ("");
 	sexp = e_book_query_to_string (query);
 	e_book_query_unref (query);
-	if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
-		report_error ("get book view sync", &error);
-		g_free (sexp);
-		g_object_unref (book_client);
 
-		return 1;
-	}
+	e_book_client_get_view (book_client, sexp, NULL, get_view_cb, fixture->loop);
 
 	g_free (sexp);
+	g_main_loop_run (fixture->loop);
+}
 
-	setup_and_start_view (view);
-	start_main_loop (NULL, NULL);
-
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-
-		return 1;
-	}
-	g_object_unref (book_client);
-
-	/*
-	 * Async version uids only
-	 */
-	if (!setup_book (&book_client))
-		return 1;
-
-	start_in_idle_with_main_loop (call_get_view, book_client);
-
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-
-		return 1;
-	}
+gint
+main (gint argc,
+      gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	g_object_unref (book_client);
+	g_test_add ("/EBookClient/RevisionView/Sync", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_revision_view_sync, e_test_server_utils_teardown);
+	g_test_add ("/EBookClient/RevisionView/Async", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_revision_view_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-suppress-notifications.c b/tests/libebook/client/test-client-suppress-notifications.c
index 7a83811..1bae38b 100644
--- a/tests/libebook/client/test-client-suppress-notifications.c
+++ b/tests/libebook/client/test-client-suppress-notifications.c
@@ -4,6 +4,9 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 
 #define NOTIFICATION_WAIT 2000
 
@@ -15,45 +18,31 @@ add_contact (EBookClient *book_client)
 	g_return_if_fail (add_contact_from_test_case_verify (book_client, "name-only", NULL));
 }
 
-static gboolean
-setup_book (EBookClient **book_client)
+static void
+setup_book (EBookClient *book_client)
 {
-	GError *error = NULL;
-
-	g_return_val_if_fail (book_client != NULL, FALSE);
-
-	*book_client = new_temp_client (NULL);
-	g_return_val_if_fail (*book_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (*book_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (*book_client);
-		return FALSE;
-	}
-
-	if (!add_contact_from_test_case_verify (*book_client, "simple-1", NULL) ||
-	    !add_contact_from_test_case_verify (*book_client, "simple-2", NULL)) {
-		g_object_unref (*book_client);
-		return FALSE;
-	}
-
-	return TRUE;
+	if (!add_contact_from_test_case_verify (book_client, "simple-1", NULL) ||
+	    !add_contact_from_test_case_verify (book_client, "simple-2", NULL))
+		g_error ("Failed to add contacts");
 }
 
 static void
-finish_test (EBookClientView *view)
+finish_test (EBookClientView *view,
+	     GMainLoop *loop)
 {
 	e_book_client_view_stop (view, NULL);
 	g_object_unref (view);
 
-	stop_main_loop (0);
+	g_main_loop_quit (loop);
 }
 
 static void
 objects_added (EBookClientView *view,
-               const GSList *contacts)
+               const GSList *contacts,
+	       gpointer user_data)
 {
 	const GSList *l;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
 	/* We quit the mainloop and the test succeeds if we get the notification
 	 * for the contact we add after loading the view completes */
@@ -64,7 +53,7 @@ objects_added (EBookClientView *view,
 	if (loading_view)
 		g_error ("Expected no contact additions while loading the view");
 	else {
-		finish_test (view);
+		finish_test (view, loop);
 	}
 
 }
@@ -93,27 +82,28 @@ complete (EBookClientView *view,
 }
 
 static void
-setup_and_start_view (EBookClientView *view)
+setup_and_start_view (EBookClientView *view,
+		      GMainLoop *loop)
 {
 	GError *error = NULL;
 
-	g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), NULL);
-	g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), NULL);
-	g_signal_connect (view, "complete", G_CALLBACK (complete), NULL);
+	g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), loop);
+	g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), loop);
+	g_signal_connect (view, "complete", G_CALLBACK (complete), loop);
 
 	e_book_client_view_set_fields_of_interest (view, NULL, &error);
 	if (error)
-		report_error ("set fields of interest", &error);
+		g_error ("set fields of interest: %s", error->message);
 
 	/* Set flags to 0, i.e. unflag E_BOOK_VIEW_NOTIFY_INITIAL */
 	e_book_client_view_set_flags (view, 0, &error);
 	if (error)
-		report_error ("set view flags", &error);
+		g_error ("set view flags: %s", error->message);
 	loading_view = TRUE;
 
 	e_book_client_view_start (view, &error);
 	if (error)
-		report_error ("start view", &error);
+		g_error ("start view: %s", error->message);
 
 }
 
@@ -122,100 +112,80 @@ get_view_cb (GObject *source_object,
              GAsyncResult *result,
              gpointer user_data)
 {
+	GMainLoop *loop = (GMainLoop *)user_data;
 	EBookClientView *view;
 	GError *error = NULL;
 
 	if (!e_book_client_get_view_finish (E_BOOK_CLIENT (source_object), result, &view, &error)) {
-		report_error ("get view finish", &error);
-		stop_main_loop (1);
-
-		return;
+		g_error ("get view finish: %s", error->message);
 	}
 
-	setup_and_start_view (view);
+	setup_and_start_view (view, loop);
 }
 
-static gpointer
-call_get_view (gpointer user_data)
+static void
+test_suppress_notifications_sync (ETestServerFixture *fixture,
+				  gconstpointer       user_data)
 {
+	EBookClient *book_client;
 	EBookQuery *query;
-	EBookClient *book_client = user_data;
+	EBookClientView *view;
 	gchar *sexp;
+	GError *error = NULL;
+
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
-	g_return_val_if_fail (book_client != NULL, NULL);
-	g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), NULL);
+	setup_book (book_client);
 
 	query = e_book_query_any_field_contains ("");
 	sexp = e_book_query_to_string (query);
 	e_book_query_unref (query);
-
-	e_book_client_get_view (book_client, sexp, NULL, get_view_cb, NULL);
+	if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
+		g_error ("get book view sync: %s", error->message);
+		g_free (sexp);
+		g_object_unref (book_client);
+	}
 
 	g_free (sexp);
 
-	return NULL;
+	setup_and_start_view (view, fixture->loop);
+	g_main_loop_run (fixture->loop);
 }
 
-gint
-main (gint argc,
-      gchar **argv)
+static void
+test_suppress_notifications_async (ETestServerFixture *fixture,
+				   gconstpointer       user_data)
 {
 	EBookClient *book_client;
 	EBookQuery *query;
-	EBookClientView *view;
 	gchar *sexp;
-	GError *error = NULL;
-
-	main_initialize ();
 
-	/*
-	 * Sync version
-	 */
-	if (!setup_book (&book_client))
-		return 1;
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
+	setup_book (book_client);
 	query = e_book_query_any_field_contains ("");
 	sexp = e_book_query_to_string (query);
 	e_book_query_unref (query);
-	if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
-		report_error ("get book view sync", &error);
-		g_free (sexp);
-		g_object_unref (book_client);
 
-		return 1;
-	}
+	e_book_client_get_view (book_client, sexp, NULL, get_view_cb, fixture->loop);
 
 	g_free (sexp);
+	g_main_loop_run (fixture->loop);
+}
 
-	setup_and_start_view (view);
-
-	start_main_loop (NULL, NULL);
-
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-
-		return 1;
-	}
-
-	g_object_unref (book_client);
-
-	/*
-	 * Async version
-	 */
-	if (!setup_book (&book_client))
-		return 1;
-
-	start_in_idle_with_main_loop (call_get_view, book_client);
-
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-
-		return 1;
-	}
+gint
+main (gint argc,
+      gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	g_object_unref (book_client);
+	g_test_add ("/EBookClient/SuppressNotifications/Sync", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_suppress_notifications_sync, e_test_server_utils_teardown);
+	g_test_add ("/EBookClient/SuppressNotifications/Async", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_suppress_notifications_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-uid-only-view.c b/tests/libebook/client/test-client-uid-only-view.c
index 9b3c5af..0332740 100644
--- a/tests/libebook/client/test-client-uid-only-view.c
+++ b/tests/libebook/client/test-client-uid-only-view.c
@@ -4,6 +4,15 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+typedef struct {
+	ETestServerClosure closure;
+	gboolean uids_only;
+} UIDOnlyClosure;
+
+static UIDOnlyClosure book_closure_all_data = { { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 }, FALSE };
+static UIDOnlyClosure book_closure_uids_only = { { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 }, TRUE };
 
 #define N_TEST_CONTACTS 4
 
@@ -44,22 +53,10 @@ add_contact (EBookClient *client)
 }
 
 static gboolean
-setup_book (EBookClient **book_out)
+setup_book (EBookClient *book_client)
 {
-	GError *error = NULL;
 	gint   i, j;
 
-	g_return_val_if_fail (book_out != NULL, FALSE);
-
-	*book_out = new_temp_client (NULL);
-	g_return_val_if_fail (*book_out != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (*book_out), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (*book_out);
-		return FALSE;
-	}
-
 	for (i = 0; i < N_TEST_CONTACTS; i++)
 	{
 		EContact *contact = e_contact_new ();
@@ -100,7 +97,7 @@ setup_book (EBookClient **book_out)
 #endif
 
 		/* verify the contact was added "successfully" (not thorough) */
-		if (!add_contact_verify (*book_out, contact))
+		if (!add_contact_verify (book_client, contact))
 			g_error ("Failed to add contact");
 
 		g_free (name);
@@ -138,19 +135,22 @@ print_contact (EContact *contact)
 #endif
 
 static void
-finish_test (EBookClientView *view)
+finish_test (EBookClientView *view,
+	     GMainLoop *loop)
 {
 	e_book_client_view_stop (view, NULL);
 	g_object_unref (view);
 
-	stop_main_loop (0);
+	g_main_loop_quit (loop);
 }
 
 static void
 objects_added (EBookClientView *view,
-               const GSList *contacts)
+               const GSList *contacts,
+	       gpointer user_data)
 {
 	const GSList *l;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
 	for (l = contacts; l; l = l->next) {
 		EContact *contact = l->data;
@@ -168,7 +168,7 @@ objects_added (EBookClientView *view,
 	}
 
 	if (!loading_view)
-		finish_test (view);
+		finish_test (view, loop);
 
 }
 
@@ -193,14 +193,15 @@ complete (EBookClientView *view,
 }
 
 static void
-setup_and_start_view (EBookClientView *view)
+setup_and_start_view (EBookClientView *view,
+		      GMainLoop *loop)
 {
 	GError *error = NULL;
 	GSList  uid_field_list = { 0, };
 
-	g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), NULL);
-	g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), NULL);
-	g_signal_connect (view, "complete", G_CALLBACK (complete), NULL);
+	g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), loop);
+	g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), loop);
+	g_signal_connect (view, "complete", G_CALLBACK (complete), loop);
 
 	uid_field_list.data = (gpointer) e_contact_field_name (E_CONTACT_UID);
 
@@ -210,13 +211,13 @@ setup_and_start_view (EBookClientView *view)
 		e_book_client_view_set_fields_of_interest (view, NULL, &error);
 
 	if (error)
-		report_error ("set fields of interest", &error);
+		g_error ("set fields of interest: %s", error->message);
 
 	loading_view = TRUE;
 
 	e_book_client_view_start (view, &error);
 	if (error)
-		report_error ("start view", &error);
+		g_error ("start view: %s", error->message);
 
 }
 
@@ -227,164 +228,90 @@ get_view_cb (GObject *source_object,
 {
 	EBookClientView *view;
 	GError *error = NULL;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
 	if (!e_book_client_get_view_finish (E_BOOK_CLIENT (source_object), result, &view, &error)) {
-		report_error ("get view finish", &error);
-		stop_main_loop (1);
-
-		return;
+		g_error ("get view finish: %s", error->message);
 	}
 
-	setup_and_start_view (view);
-}
-
-static gpointer
-call_get_view (gpointer user_data)
-{
-	EBookQuery *query;
-	EBookClient *book_client = user_data;
-	gchar *sexp;
-
-	g_return_val_if_fail (book_client != NULL, NULL);
-	g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), NULL);
-
-	query = e_book_query_any_field_contains ("");
-	sexp = e_book_query_to_string (query);
-	e_book_query_unref (query);
-
-	e_book_client_get_view (book_client, sexp, NULL, get_view_cb, NULL);
-
-	g_free (sexp);
-
-	return NULL;
+	setup_and_start_view (view, loop);
 }
 
-gint
-main (gint argc,
-      gchar **argv)
+static void
+test_get_view_sync (ETestServerFixture *fixture,
+		    gconstpointer       user_data)
 {
 	EBookClient *book_client;
 	EBookQuery *query;
 	EBookClientView *view;
 	gchar *sexp;
 	GError *error = NULL;
-	SETUP_TIMER (timer);
+	UIDOnlyClosure *closure = (UIDOnlyClosure *)user_data;
 
-	main_initialize ();
+	uids_only = closure->uids_only;
 
-	/*
-	 * Sync version all data
-	 */
-	uids_only = FALSE;
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
-	if (!setup_book (&book_client))
-		return 1;
+	setup_book (book_client);
 
 	query = e_book_query_any_field_contains ("");
 	sexp = e_book_query_to_string (query);
 	e_book_query_unref (query);
 	if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
-		report_error ("get book view sync", &error);
+		g_error ("get book view sync: %s", error->message);
 		g_free (sexp);
 		g_object_unref (book_client);
-
-		return 1;
 	}
 
 	g_free (sexp);
 
-	START_TIMER (timer);
-	setup_and_start_view (view);
-	start_main_loop (NULL, NULL);
-	STOP_TIMER (timer);
-	PRINT_TIMER (timer, "Loading all data from book view synchronously");
-
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
+	setup_and_start_view (view, fixture->loop);
+	g_main_loop_run (fixture->loop);
+}
 
-		return 1;
-	}
-	g_object_unref (book_client);
+static void
+test_get_view_async (ETestServerFixture *fixture,
+		     gconstpointer       user_data)
+{
+	EBookClient *book_client;
+	EBookQuery *query;
+	gchar *sexp;
+	UIDOnlyClosure *closure = (UIDOnlyClosure *)user_data;
 
-	/*
-	 * Sync version uids only
-	 */
-	uids_only = TRUE;
+	uids_only = closure->uids_only;
 
-	if (!setup_book (&book_client))
-		return 1;
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
+	setup_book (book_client);
 	query = e_book_query_any_field_contains ("");
 	sexp = e_book_query_to_string (query);
 	e_book_query_unref (query);
-	if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
-		report_error ("get book view sync", &error);
-		g_free (sexp);
-		g_object_unref (book_client);
 
-		return 1;
-	}
+	e_book_client_get_view (book_client, sexp, NULL, get_view_cb, fixture->loop);
 
 	g_free (sexp);
+	g_main_loop_run (fixture->loop);
+}
 
-	START_TIMER (timer);
-	setup_and_start_view (view);
-	start_main_loop (NULL, NULL);
-	STOP_TIMER (timer);
-	PRINT_TIMER (timer, "Loading uids only from book view synchronously");
-
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-
-		return 1;
-	}
-	g_object_unref (book_client);
-
-	/*
-	 * Async version all data
-	 */
-	uids_only = FALSE;
-
-	if (!setup_book (&book_client))
-		return 1;
-
-	START_TIMER (timer);
-	start_in_idle_with_main_loop (call_get_view, book_client);
-	STOP_TIMER (timer);
-	PRINT_TIMER (timer, "Loading all data from book view asynchronously");
-
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
-
-		return 1;
-	}
-
-	g_object_unref (book_client);
-
-	/*
-	 * Async version uids only
-	 */
-	uids_only = TRUE;
-
-	if (!setup_book (&book_client))
-		return 1;
-
-	START_TIMER (timer);
-	start_in_idle_with_main_loop (call_get_view, book_client);
-	STOP_TIMER (timer);
-	PRINT_TIMER (timer, "Loading uids only from book view asynchronously");
 
-	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (book_client);
+gint
+main (gint argc,
+      gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-		return 1;
-	}
+	g_test_add ("/EBookClient/UidOnlyView/Sync/AllData", ETestServerFixture, &book_closure_all_data,
+		    e_test_server_utils_setup, test_get_view_sync, e_test_server_utils_teardown);
+	g_test_add ("/EBookClient/UidOnlyView/Sync/UidsOnly", ETestServerFixture, &book_closure_uids_only,
+		    e_test_server_utils_setup, test_get_view_sync, e_test_server_utils_teardown);
 
-	g_object_unref (book_client);
+	g_test_add ("/EBookClient/UidOnlyView/Async/AllData", ETestServerFixture, &book_closure_all_data,
+		    e_test_server_utils_setup, test_get_view_async, e_test_server_utils_teardown);
+	g_test_add ("/EBookClient/UidOnlyView/Async/UidsOnly", ETestServerFixture, &book_closure_uids_only,
+		    e_test_server_utils_setup, test_get_view_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-upgrade-addressbook.c b/tests/libebook/client/test-client-upgrade-addressbook.c
index e4f3f47..9ba5834 100644
--- a/tests/libebook/client/test-client-upgrade-addressbook.c
+++ b/tests/libebook/client/test-client-upgrade-addressbook.c
@@ -29,7 +29,7 @@
 #include <libebook/libebook.h>
 #include <glib/gstdio.h>
 
-#include "client-test-utils.h"
+#include "e-test-server-utils.h"
 
 typedef struct _TestFixture TestFixture;
 typedef struct _TestParams TestParams;
@@ -43,29 +43,95 @@ typedef void (* TestFunc)(TestFixture   *fixture,
                           gconstpointer  params);
 
 struct _TestFixture {
-	GMainLoop *loop;
-	ESourceRegistry *registry;
-	EBookClient *client;
+	ETestServerFixture base_fixture;
 	GSList *contacts;
 };
 
 struct _TestParams {
-	gchar      *db_version;
-	AccessMode  access_mode;
+	ETestServerClosure base_closure;
+	gchar             *db_version;
+	AccessMode         access_mode;
 };
 
+static void setup_book_directory (ESource            *scratch,
+				  ETestServerClosure *closure);
+
+
 /****************************************************************
- *                      Addressbook mocking                     *
+ *                       Fixture handling                       *
  ****************************************************************/
+static TestParams *
+create_params (const gchar *db_version,
+	       AccessMode   access_mode)
+{
+	TestParams *params = g_slice_new0 (TestParams);
+
+	params->base_closure.type      = E_TEST_SERVER_ADDRESS_BOOK;
+	params->base_closure.customize = setup_book_directory;
+
+	params->access_mode = access_mode;
+	params->db_version  = g_strdup (db_version);
+
+	return params;
+}
+
+static void
+free_params (TestParams *params)
+{
+	g_free (params->db_version);
+	g_slice_free (TestParams, params);
+}
+
+static void
+setup (TestFixture    *fixture,
+       gconstpointer   data)
+{
+	e_test_server_utils_setup ((ETestServerFixture *)fixture, data);
+}
+
+static void
+teardown (TestFixture   *fixture,
+          gconstpointer  data)
+{
+	TestParams *params = (TestParams *)data;
+
+	e_test_server_utils_teardown ((ETestServerFixture *)fixture, data);
+
+	g_slist_free_full (fixture->contacts, g_object_unref);
+	fixture->contacts = NULL;
+	free_params (params);
+}
 
 static void
-create_bookdir (const gchar *const uid,
-                const gchar *const db_version)
+add_test (const gchar *path,
+          const gchar *db_version,
+          AccessMode   access_mode,
+          TestFunc     test_func)
 {
-	gchar *const bookdir = g_build_filename (g_get_user_data_dir (), "evolution", "addressbook", uid, NULL);
+	TestParams *params;
+
+	params = create_params (db_version, access_mode);
+	g_test_add (path, TestFixture, params, setup, test_func, teardown);
+}
+
+/****************************************************************
+ *                      Addressbook mocking                     *
+ ****************************************************************/
+static void
+setup_book_directory (ESource            *scratch,
+		      ETestServerClosure *closure)
+{
+	TestParams *params = (TestParams *)closure;
+
+	if (params->access_mode == DIRECT_ACCESS)
+		g_setenv ("DEBUG_DIRECT", "1", TRUE);
+	else
+		g_unsetenv ("DEBUG_DIRECT");
+
+	gchar *const bookdir = g_build_filename (g_get_user_data_dir (), "evolution", "addressbook", "test-address-book", NULL);
 	gchar *const photodir = g_build_filename (bookdir, "photos", NULL);
 
-	gchar *const datadir = g_build_filename (SRCDIR, "../data/dumps", db_version, NULL);
+	gchar *const datadir = g_build_filename (SRCDIR, "../data/dumps", params->db_version, NULL);
 	gchar *const bdb_filename = g_build_filename (datadir, "addressbook.db_dump", NULL);
 	gchar *const sqlite_filename = g_build_filename (datadir, "contacts.sql", NULL);
 
@@ -114,117 +180,7 @@ create_bookdir (const gchar *const uid,
 
 	g_free (photodir);
 	g_free (bookdir);
-}
-
-static gboolean
-wait_cb (gpointer data)
-{
-	TestFixture *fixture = data;
-	g_main_loop_quit (fixture->loop);
-	return FALSE;
-}
-
-static void
-create_source (TestFixture *fixture,
-               const gchar *uid)
-{
-	GError *error = NULL;
-	ESourceBackend  *backend;
-	ESource *scratch;
 
-	fixture->registry = e_source_registry_new_sync (NULL, &error);
-
-	if (!fixture->registry)
-		g_error ("Unable to create the registry: %s", error->message);
-
-	scratch = e_source_new_with_uid (uid, NULL, &error);
-
-	if (!scratch)
-		g_error ("Failed to create source with uid \"%s\": %s", uid, error->message);
-
-	e_source_set_display_name (scratch, "Mock Addressbook");
-
-	backend = e_source_get_extension (scratch, E_SOURCE_EXTENSION_ADDRESS_BOOK);
-	e_source_backend_set_backend_name (backend, "local");
-
-	if (!e_source_registry_commit_source_sync (fixture->registry, scratch, NULL, &error))
-		g_error ("Unable to add new source to the registry for uid \"%s\": %s", uid, error->message);
-
-	g_object_unref (scratch);
-
-	/* Give the backend a chance to see the source */
-	g_timeout_add (250, wait_cb, fixture);
-	g_main_loop_run (fixture->loop);
-}
-
-/****************************************************************
- *                       Fixture handling                       *
- ****************************************************************/
-
-static void
-setup (TestFixture    *fixture,
-       gconstpointer   data)
-{
-	const TestParams *params = data;
-
-	guint64 now = g_get_real_time ();
-	gchar *const uid = g_strdup_printf ("mock-book-%" G_GINT64_FORMAT, now);
-	GError *error = NULL;
-	ESource *source;
-
-	fixture->loop = g_main_loop_new (NULL, FALSE);
-
-	create_bookdir (uid, params->db_version);
-	create_source (fixture, uid);
-
-	source = e_source_new_with_uid (uid, NULL, &error);
-
-	if (!source)
-		g_error ("Failed to create source with uid \"%s\": %s", uid, error->message);
-
-	if (params->access_mode == DIRECT_ACCESS) {
-		fixture->client = e_book_client_new_direct (fixture->registry, source, &error);
-	} else {
-		fixture->client = e_book_client_new (source, &error);
-	}
-
-	if (!fixture->client)
-		g_error ("Failed to create addressbook client: %s", error->message);
-	if (!e_client_open_sync (E_CLIENT (fixture->client), TRUE, NULL, &error))
-		g_error ("Failed to open addressbook client: %s", error->message);
-
-	g_object_unref (source);
-	g_free (uid);
-}
-
-static void
-teardown (TestFixture   *fixture,
-          gconstpointer  data)
-{
-	const TestParams *const params = data;
-
-	if (fixture->client)
-		g_object_unref (fixture->client);
-	if (fixture->registry)
-		g_object_unref (fixture->registry);
-
-	g_slist_free_full (fixture->contacts, g_object_unref);
-	g_main_loop_unref (fixture->loop);
-
-	g_free (params->db_version);
-	g_slice_free (TestParams, (TestParams *) params);
-}
-
-static void
-add_test (const gchar *path,
-          const gchar *db_version,
-          AccessMode   access_mode,
-          TestFunc     test_func)
-{
-	TestParams *params = g_slice_new0 (TestParams);
-	params->db_version = g_strdup (db_version);
-	params->access_mode = access_mode;
-	g_test_add (path, TestFixture, params, setup, test_func, teardown);
 }
 
 /****************************************************************
@@ -259,13 +215,14 @@ contacts_added_cb (EBookClientView *view,
                    GSList          *contacts,
                    TestFixture     *fixture)
 {
+	ETestServerFixture *base = (ETestServerFixture *)fixture;
 	GSList *l;
 
 	for (l = contacts; l; l = l->next)
 		fixture->contacts = g_slist_prepend (fixture->contacts, g_object_ref (l->data));
 
 	if (g_slist_length (fixture->contacts) >= 5)
-		g_main_loop_quit (fixture->loop);
+		g_main_loop_quit (base->loop);
 }
 
 static void
@@ -273,16 +230,18 @@ view_complete_cb (EBookClientView *view,
                   const GError    *error,
                   TestFixture     *fixture)
 {
+	ETestServerFixture *base = (ETestServerFixture *)fixture;
+
 	if (error)
 		g_error ("View failed: %s", error->message);
 
-	g_main_loop_quit (fixture->loop);
+	g_main_loop_quit (base->loop);
 }
 
 static gboolean
 timeout_cb (gpointer data)
 {
-	TestFixture *fixture = data;
+	ETestServerFixture *fixture = data;
 
 	g_assert_not_reached ();
 	g_main_loop_quit (fixture->loop);
@@ -296,10 +255,14 @@ test_book_client_view (TestFixture   *fixture,
 {
 	GError *error = NULL;
 	EBookClientView *view;
+	EBookClient *client;
 	guint timeout_id;
 	GSList *fields;
+	ETestServerFixture *base = (ETestServerFixture *)fixture;
 
-	if (!e_book_client_get_view_sync (fixture->client,
+	client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+	if (!e_book_client_get_view_sync (client,
 	                                  "(contains \"x-evolution-any-field\" \"\")",
 	                                  &view, NULL, &error))
 		g_error ("Failed to create the view: %s", error->message);
@@ -322,7 +285,7 @@ test_book_client_view (TestFixture   *fixture,
 	if (error)
 		g_error ("Failed to start view: %s", error->message);
 
-	g_main_loop_run (fixture->loop);
+	g_main_loop_run (base->loop);
 	g_source_remove (timeout_id);
 
 	g_signal_handlers_disconnect_by_data (view, fixture);
@@ -341,8 +304,11 @@ test_book_client (TestFixture   *fixture,
                   gconstpointer  params)
 {
 	GError *error = NULL;
+	EBookClient *client;
 
-	if (!e_book_client_get_contacts_sync (fixture->client,
+	client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+	if (!e_book_client_get_contacts_sync (client,
 	                                      "(contains \"x-evolution-any-field\" \"\")",
 	                                      &fixture->contacts, NULL, &error))
 		g_error ("Failed to read contacts: %s", error->message);
@@ -350,19 +316,21 @@ test_book_client (TestFixture   *fixture,
 	verify_contacts (fixture->contacts);
 }
 
+
 gint
-main (gint    argc,
+main (gint argc,
       gchar **argv)
 {
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
 	g_test_init (&argc, &argv, NULL);
 
-	main_initialize ();
-
 	add_test ("/upgrade/0.2/dbus/book-client", "0.2", INDIRECT_ACCESS, test_book_client);
 	add_test ("/upgrade/0.2/dbus/book-client-view", "0.2", INDIRECT_ACCESS, test_book_client_view);
 	add_test ("/upgrade/0.2/direct/book-client", "0.2", DIRECT_ACCESS, test_book_client);
 	add_test ("/upgrade/0.2/direct/book-client-view", "0.2", DIRECT_ACCESS, test_book_client_view);
 
-	return g_test_run ();
+	return e_test_server_utils_run ();
 }
 
diff --git a/tests/libebook/client/test-client.c b/tests/libebook/client/test-client.c
index 0de6380..69e2a03 100644
--- a/tests/libebook/client/test-client.c
+++ b/tests/libebook/client/test-client.c
@@ -4,6 +4,9 @@
 #include <libebook/libebook.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 
 static void
 print_all_uids (EBookClient *book)
@@ -75,51 +78,43 @@ print_all_emails (EBookClient *book)
 }
 
 static void
-print_one_email (EBookClient *book_client)
+test_client (ETestServerFixture *fixture,
+	     gconstpointer       user_data)
 {
-	EContact *contact;
-	GError *error = NULL;
+	EBookClient *book_client;
 
-	if (!e_book_client_get_contact_sync (book_client, "pas-id-0002023", &contact, NULL, &error)) {
-		report_error ("get_contact_sync", &error);
-		return;
+	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+	/* Add some contacts */
+	if (!add_contact_from_test_case_verify (book_client, "custom-1", NULL) ||
+	    !add_contact_from_test_case_verify (book_client, "custom-2", NULL) ||
+	    !add_contact_from_test_case_verify (book_client, "custom-3", NULL) ||
+	    !add_contact_from_test_case_verify (book_client, "custom-4", NULL) ||
+	    !add_contact_from_test_case_verify (book_client, "custom-5", NULL) ||
+	    !add_contact_from_test_case_verify (book_client, "custom-6", NULL)) {
+		g_object_unref (book_client);
+		g_error ("Failed to add contacts");
 	}
 
-	print_email (contact);
+	printf ("printing all contacts\n");
+	print_all_emails (book_client);
 
-	g_object_unref (contact);
+	printf ("printing all uids\n");
+	print_all_uids (book_client);
 }
 
+
 gint
 main (gint argc,
       gchar **argv)
 {
-	EBookClient *book_client;
-	ESourceRegistry *registry;
-	GError *error = NULL;
-
-	main_initialize ();
-
-	registry = e_source_registry_new_sync (NULL, &error);
-	if (error != NULL)
-		g_error ("%s", error->message);
-
-	printf ("loading addressbook\n");
-
-	book_client = open_system_book (registry, FALSE);
-	if (!book_client)
-		return 1;
-
-	printf ("printing one contact\n");
-	print_one_email (book_client);
-
-	printf ("printing all contacts\n");
-	print_all_emails (book_client);
-
-	printf ("printing all uids\n");
-	print_all_uids (book_client);
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	g_object_unref (book_client);
+	g_test_add ("/EBookClient/BasicTest", ETestServerFixture, &book_closure,
+		    e_test_server_utils_setup, test_client, e_test_server_utils_teardown);
 
-	return 0;
+	return e_test_server_utils_run ();
 }
diff --git a/tests/test-server-utils/Makefile.am b/tests/test-server-utils/Makefile.am
index 34fe539..4d7f33b 100644
--- a/tests/test-server-utils/Makefile.am
+++ b/tests/test-server-utils/Makefile.am
@@ -1,7 +1,5 @@
 NULL =
 
- GNOME_CODE_COVERAGE_RULES@
-
 common_cflags = \
 	$(AM_CPPFLAGS) \
 	-I$(top_srcdir) \
diff --git a/tests/test-server-utils/e-test-server-utils.c b/tests/test-server-utils/e-test-server-utils.c
index 99c5347..5f30ade 100644
--- a/tests/test-server-utils/e-test-server-utils.c
+++ b/tests/test-server-utils/e-test-server-utils.c
@@ -86,7 +86,13 @@ e_test_server_utils_bootstrap_timeout (FixturePair *pair)
 		if (!source)
 			g_error ("Unable to fetch newly created addressbook source from the registry");
 
-		pair->fixture->service.book_client = e_book_client_new (source, &error);
+		if (g_getenv ("DEBUG_DIRECT") != NULL)
+			pair->fixture->service.book_client =
+				e_book_client_new_direct (pair->fixture->registry, source, &error);
+		else
+			pair->fixture->service.book_client =
+				e_book_client_new (source, &error);
+
 		if (!pair->fixture->service.book_client)
 			g_error ("Unable to create the test book: %s", error->message);
 



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