[evolution-data-server] Ported ECalClient tests to use ETestServerFixture framework



commit 49f857d01c08488122ab19e5c3dc8a1376b0afc1
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Thu Dec 13 22:22:19 2012 +0900

    Ported ECalClient tests to use ETestServerFixture framework
    
    Now the majority of ECalClient tests use the fixture, some tests
    have been moved out of the unit test targets instead and remain
    as functional tests (to be run manually)

 tests/libecal/client/Makefile.am                   |   18 +-
 tests/libecal/client/test-client-add-timezone.c    |  206 +++++----------
 tests/libecal/client/test-client-bulk-methods.c    |  174 +++++--------
 tests/libecal/client/test-client-create-object.c   |  275 +++++++-------------
 .../client/test-client-get-attachment-uris.c       |  216 +++++++---------
 tests/libecal/client/test-client-get-free-busy.c   |  119 +++-------
 tests/libecal/client/test-client-get-object-list.c |  212 ++++++----------
 tests/libecal/client/test-client-get-revision.c    |   48 ++--
 tests/libecal/client/test-client-get-view.c        |  161 +++++-------
 tests/libecal/client/test-client-modify-object.c   |  208 ++++++----------
 tests/libecal/client/test-client-receive-objects.c |  117 +++------
 tests/libecal/client/test-client-refresh.c         |  153 ++++-------
 tests/libecal/client/test-client-remove-object.c   |  127 +++-------
 tests/libecal/client/test-client-revision-view.c   |  179 ++++++--------
 tests/libecal/client/test-client-send-objects.c    |  122 +++------
 15 files changed, 840 insertions(+), 1495 deletions(-)
---
diff --git a/tests/libecal/client/Makefile.am b/tests/libecal/client/Makefile.am
index 1fa8ddc..e1da501 100644
--- a/tests/libecal/client/Makefile.am
+++ b/tests/libecal/client/Makefile.am
@@ -6,8 +6,12 @@ libclient_test_utils_la_CPPFLAGS =				\
 	$(AM_CPPFLAGS)						\
 	-I$(top_srcdir)						\
 	-I$(top_builddir)					\
+	-I$(top_srcdir)/addressbook     			\
+	-I$(top_builddir)/addressbook   			\
 	-I$(top_srcdir)/calendar				\
 	-I$(top_builddir)/calendar				\
+	-I$(top_srcdir)/tests/test-server-utils     		\
+	-I$(top_builddir)/tests/test-server-utils   		\
 	-DSRCDIR=\""$(abs_srcdir)"\"				\
 	$(EVOLUTION_CALENDAR_CFLAGS)				\
 	$(CAMEL_CFLAGS)						\
@@ -15,17 +19,16 @@ libclient_test_utils_la_CPPFLAGS =				\
 
 libclient_test_utils_la_LIBADD = 				\
 	$(top_builddir)/calendar/libecal/libecal-1.2.la		\
+	$(top_builddir)/tests/test-server-utils/libetestserverutils.la	\
 	$(EVOLUTION_CALENDAR_LIBS)				\
 	$(CAMEL_LIBS)						\
 	$(NULL)
 
 # ordered by relative complexity
 TESTS = 					\
-	test-client-open			\
 	test-client-refresh			\
 	test-client-get-free-busy		\
 	test-client-add-timezone		\
-	test-client-examine			\
 	test-client-create-object		\
 	test-client-remove-object		\
 	test-client-get-object-list		\
@@ -37,21 +40,24 @@ TESTS = 					\
 	test-client-get-attachment-uris		\
 	test-client-get-view			\
 	test-client-revision-view		\
+	$(NULL)
+
+# The test program
+noinst_PROGRAMS = $(TESTS)	\
+	test-client-open	\
+	test-client-examine			\
 	test-client-stress-views		\
 	test-client-stress-factory--serial	\
 	test-client-stress-factory--fifo	\
 	test-client-stress-factory--single-cal	\
 	$(NULL)
 
-# The test program
-noinst_PROGRAMS = $(TESTS)
-
 TEST_CPPFLAGS=					\
 	$(libclient_test_utils_la_CPPFLAGS)	\
 	$(NULL)
 
 TEST_LIBS =					\
-	$(libclient_test_utils_la_LIBS)		\
+	$(libclient_test_utils_la_LIBADD)	\
 	libclient-test-utils.la			\
 	$(NULL)
 
diff --git a/tests/libecal/client/test-client-add-timezone.c b/tests/libecal/client/test-client-add-timezone.c
index b191f9f..6325d92 100644
--- a/tests/libecal/client/test-client-add-timezone.c
+++ b/tests/libecal/client/test-client-add-timezone.c
@@ -5,77 +5,56 @@
 #include <libical/ical.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
 
 #define TZID_NEW "XYZ"
 #define TZNAME_NEW "Ex Wye Zee"
 
-static gboolean
-test_zones (icaltimezone *zone1,
-            icaltimezone *zone2)
-{
-	if (!zone2) {
-		g_printerr ("Failure: get timezone returned NULL\n");
-		return FALSE;
-	}
-
-	if (g_strcmp0 (icaltimezone_get_tzid (zone1), icaltimezone_get_tzid (zone2)) != 0) {
-		g_printerr ("Failure: tzid doesn't match, expected '%s', got '%s'\n", icaltimezone_get_tzid (zone1), icaltimezone_get_tzid (zone2));
-		return FALSE;
-	}
-
-	if (g_strcmp0 (icaltimezone_get_tznames (zone1), icaltimezone_get_tznames (zone2)) != 0) {
-		g_printerr ("Failure: tznames doesn't match, expected '%s', got '%s'\n", icaltimezone_get_tznames (zone1), icaltimezone_get_tznames (zone2));
-		return FALSE;
-	}
-
-	return TRUE;
-}
+static ETestServerClosure cal_closure =
+	{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
 
-static gboolean
-test_sync (icaltimezone *zone)
+static void
+test_add_timezone_sync (ETestServerFixture *fixture,
+			gconstpointer       user_data)
 {
 	ECalClient *cal_client;
+	icalproperty *property;
+	icalcomponent *component;
+	icaltimezone *zone;
 	icaltimezone *zone2 = NULL;
 	GError *error = NULL;
-	gboolean res;
-
-	g_return_val_if_fail (zone != NULL, FALSE);
 
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		return FALSE;
-	}
+	/* Build up new timezone */
+	component = icalcomponent_new_vtimezone ();
+	property = icalproperty_new_tzid (TZID_NEW);
+	icalcomponent_add_property (component, property);
+	property = icalproperty_new_tzname (TZNAME_NEW);
+	icalcomponent_add_property (component, property);
+	zone = icaltimezone_new ();
+	icaltimezone_set_component (zone, component);
 
-	if (!e_cal_client_add_timezone_sync (cal_client, zone, NULL, &error)) {
-		report_error ("add timezone sync", &error);
-		g_object_unref (cal_client);
-		return FALSE;
-	}
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
-	if (!e_cal_client_get_timezone_sync (cal_client, TZID_NEW, &zone2, NULL, &error)) {
-		report_error ("get timezone sync", &error);
-		g_object_unref (cal_client);
-		return FALSE;
-	}
+	if (!e_cal_client_add_timezone_sync (cal_client, zone, NULL, &error))
+		g_error ("add timezone sync: %s", error->message);
 
-	res = test_zones (zone, zone2);
+	if (!e_cal_client_get_timezone_sync (cal_client, TZID_NEW, &zone2, NULL, &error))
+		g_error ("get timezone sync: %s", error->message);
 
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (cal_client);
-		return FALSE;
-	}
+	if (!zone2)
+		g_error ("Failure: get timezone returned NULL");
 
-	g_object_unref (cal_client);
+	g_assert_cmpstr (icaltimezone_get_tzid (zone), ==, icaltimezone_get_tzid (zone2));
+	g_assert_cmpstr (icaltimezone_get_tznames (zone), ==, icaltimezone_get_tznames (zone2));
 
-	return res;
+	icaltimezone_free (zone, TRUE);
 }
 
-/* asynchronous read callback with a main-loop running */
+typedef struct {
+	icaltimezone *zone;
+	GMainLoop *loop;
+} AsyncData;
+
 static void
 async_read_result_ready (GObject *source_object,
                          GAsyncResult *result,
@@ -83,32 +62,23 @@ async_read_result_ready (GObject *source_object,
 {
 	ECalClient *cal_client;
 	GError *error = NULL;
-	icaltimezone *zone1 = user_data, *zone2 = NULL;
-	gboolean res;
-
-	g_return_if_fail (zone1 != NULL);
+	AsyncData *data = (AsyncData *)user_data;
+	icaltimezone *zone1 = data->zone, *zone2 = NULL;
 
 	cal_client = E_CAL_CLIENT (source_object);
 
-	if (!e_cal_client_get_timezone_finish (cal_client, result, &zone2, &error)) {
-		report_error ("get timezone finish", &error);
-		g_object_unref (cal_client);
-		stop_main_loop (1);
-		return;
-	}
-
-	res = test_zones (zone1, zone2);
+	if (!e_cal_client_get_timezone_finish (cal_client, result, &zone2, &error))
+		g_error ("get timezone finish: %s", error->message);
 
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-	}
+	if (!zone2)
+		g_error ("Failure: get timezone returned NULL");
 
-	g_object_unref (cal_client);
+	g_assert_cmpstr (icaltimezone_get_tzid (zone1), ==, icaltimezone_get_tzid (zone2));
+	g_assert_cmpstr (icaltimezone_get_tznames (zone1), ==, icaltimezone_get_tznames (zone2));
 
-	stop_main_loop (res ? 0 : 1);
+	g_main_loop_quit (data->loop);
 }
 
-/* asynchronous write callback with a main-loop running */
 static void
 async_write_result_ready (GObject *source_object,
                           GAsyncResult *result,
@@ -118,76 +88,23 @@ async_write_result_ready (GObject *source_object,
 	GError *error = NULL;
 
 	g_return_if_fail (user_data != NULL);
-
 	cal_client = E_CAL_CLIENT (source_object);
 
-	if (!e_cal_client_add_timezone_finish (cal_client, result, &error)) {
-		report_error ("add timezone finish", &error);
-		g_object_unref (cal_client);
-		stop_main_loop (1);
-		return;
-	}
+	if (!e_cal_client_add_timezone_finish (cal_client, result, &error))
+		g_error ("add timezone finish: %s", error->message);
 
 	e_cal_client_get_timezone (cal_client, TZID_NEW, NULL, async_read_result_ready, user_data);
 }
 
-/* synchronously in idle with main-loop running */
-static gboolean
-test_sync_in_idle (gpointer user_data)
+static void
+test_add_timezone_async (ETestServerFixture *fixture,
+			 gconstpointer       user_data)
 {
 	ECalClient *cal_client;
-	GError *error = NULL;
-	icaltimezone *zone = user_data;
-
-	g_return_val_if_fail (zone != NULL, FALSE);
-
-	if (!test_sync (zone)) {
-		stop_main_loop (1);
-		return FALSE;
-	}
-
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		stop_main_loop (1);
-		return FALSE;
-	}
-
-	e_cal_client_add_timezone (cal_client, zone, NULL, async_write_result_ready, zone);
-
-	return FALSE;
-}
-
-/* synchronously in a dedicated thread with main-loop running */
-static gpointer
-test_sync_in_thread (gpointer user_data)
-{
-	icaltimezone *zone = user_data;
-
-	g_return_val_if_fail (zone != NULL, NULL);
-
-	if (!test_sync (zone)) {
-		stop_main_loop (1);
-		return NULL;
-	}
-
-	g_idle_add (test_sync_in_idle, zone);
-
-	return NULL;
-}
-
-gint
-main (gint argc,
-      gchar **argv)
-{
 	icalproperty *property;
 	icalcomponent *component;
 	icaltimezone *zone;
-
-	main_initialize ();
+	AsyncData data;
 
 	/* Build up new timezone */
 	component = icalcomponent_new_vtimezone ();
@@ -198,18 +115,29 @@ main (gint argc,
 	zone = icaltimezone_new ();
 	icaltimezone_set_component (zone, component);
 
-	/* synchronously without main-loop */
-	if (!test_sync (zone)) {
-		icaltimezone_free (zone, TRUE);
-		return 1;
-	}
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
-	start_in_thread_with_main_loop (test_sync_in_thread, zone);
+	data.zone = zone;
+	data.loop = fixture->loop;
+	e_cal_client_add_timezone (cal_client, zone, NULL, async_write_result_ready, &data);
+	g_main_loop_run (fixture->loop);
 
 	icaltimezone_free (zone, TRUE);
+}
+
+gint
+main (gint argc,
+      gchar **argv)
+{
+#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 ("/ECalClient/AddTimezone/Sync", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_add_timezone_sync, e_test_server_utils_teardown);
+	g_test_add ("/ECalClient/AddTimezone/Async", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_add_timezone_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libecal/client/test-client-bulk-methods.c b/tests/libecal/client/test-client-bulk-methods.c
index 322a951..4cc67ab 100644
--- a/tests/libecal/client/test-client-bulk-methods.c
+++ b/tests/libecal/client/test-client-bulk-methods.c
@@ -4,56 +4,46 @@
 #include <libecal/libecal.h>
 #include <libical/ical.h>
 
-#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure cal_closure =
+	{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
 
 #define NB_COMPONENTS 5
 
-static gboolean
+static void
 test_icalcomps (icalcomponent *icalcomp1,
-                                icalcomponent *icalcomp2)
+		icalcomponent *icalcomp2)
 {
 	struct icaltimetype t1, t2;
 
-	if (!icalcomp2) {
-		g_printerr ("Failure: get object returned NULL\n");
-		return FALSE;
-	}
-
-	if (g_strcmp0 (icalcomponent_get_uid (icalcomp1), icalcomponent_get_uid (icalcomp2)) != 0) {
-		g_printerr ("Failure: uid doesn't match, expected '%s', got '%s'\n", icalcomponent_get_uid (icalcomp1), icalcomponent_get_uid (icalcomp2));
-		return FALSE;
-	}
-
-	if (g_strcmp0 (icalcomponent_get_summary (icalcomp1), icalcomponent_get_summary (icalcomp2)) != 0) {
-		g_printerr ("Failure: summary doesn't match, expected '%s', got '%s'\n", icalcomponent_get_summary (icalcomp1), icalcomponent_get_summary (icalcomp2));
-		return FALSE;
-	}
+	if (!icalcomp2)
+		g_error ("Failure: get object returned NULL");
+	
+	g_assert_cmpstr (icalcomponent_get_uid (icalcomp1), ==, icalcomponent_get_uid (icalcomp2));
+	g_assert_cmpstr (icalcomponent_get_summary (icalcomp1), ==, icalcomponent_get_summary (icalcomp2));
 
 	t1 = icalcomponent_get_dtstart (icalcomp1);
 	t2 = icalcomponent_get_dtstart (icalcomp2);
 
-	if (icaltime_compare (t1, t2) != 0) {
-		g_printerr ("Failure: dtend doesn't match, expected '%s', got '%s'\n", icaltime_as_ical_string (t1), icaltime_as_ical_string (t2));
-		return FALSE;
-	}
+	if (icaltime_compare (t1, t2) != 0)
+		g_error ("Failure: dtend doesn't match, expected '%s', got '%s'\n",
+			 icaltime_as_ical_string (t1), icaltime_as_ical_string (t2));
 
 	t1 = icalcomponent_get_dtend (icalcomp1);
 	t2 = icalcomponent_get_dtend (icalcomp2);
 
-	if (icaltime_compare (t1, t2) != 0) {
-		g_printerr ("Failure: dtend doesn't match, expected '%s', got '%s'\n", icaltime_as_ical_string (t1), icaltime_as_ical_string (t2));
-		return FALSE;
-	}
-
-	return TRUE;
+	if (icaltime_compare (t1, t2) != 0)
+		g_error ("Failure: dtend doesn't match, expected '%s', got '%s'\n",
+			 icaltime_as_ical_string (t1), icaltime_as_ical_string (t2));
 }
 
-static gboolean
+static void
 check_removed (ECalClient *cal_client,
-                           const GSList *uids)
+	       const GSList *uids)
 {
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-	g_return_val_if_fail (uids != NULL, FALSE);
+	g_assert (cal_client != NULL);
+	g_assert (uids != NULL);
 
 	while (uids) {
 		GError *error = NULL;
@@ -62,16 +52,11 @@ check_removed (ECalClient *cal_client,
 		if (!e_cal_client_get_object_sync (cal_client, uids->data, NULL, &icalcomp, NULL, &error) &&
 				g_error_matches (error, E_CAL_CLIENT_ERROR, E_CAL_CLIENT_ERROR_OBJECT_NOT_FOUND)) {
 			g_clear_error (&error);
-		} else {
-			report_error ("check objects removed sync", &error);
-			icalcomponent_free (icalcomp);
-			return FALSE;
-		}
+		} else
+			g_error ("check objects removed sync: %s", error->message);
 
 		uids = uids->next;
 	}
-
-	return TRUE;
 }
 
 static GSList *
@@ -89,9 +74,9 @@ uid_slist_to_ecalcomponentid_slist (GSList *uids)
 	return ids;
 }
 
-static gboolean
+static void
 check_icalcomps_exist (ECalClient *cal_client,
-                                           GSList *icalcomps)
+		       GSList *icalcomps)
 {
 	const GSList *l;
 
@@ -101,53 +86,33 @@ check_icalcomps_exist (ECalClient *cal_client,
 		icalcomponent *icalcomp2 = NULL;
 		const gchar *uid = icalcomponent_get_uid (icalcomp);
 
-		if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp2, NULL, &error)) {
-			report_error ("get object sync", &error);
-			return FALSE;
-		}
+		if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp2, NULL, &error))
+			g_error ("get object sync: %s", error->message);
 
-		g_return_val_if_fail (icalcomp2 != NULL, FALSE);
-
-		if (!test_icalcomps (icalcomp, icalcomp2)) {
-			icalcomponent_free (icalcomp2);
-			return FALSE;
-		}
+		g_assert (icalcomp2 != NULL);
 
+		test_icalcomps (icalcomp, icalcomp2);
 		icalcomponent_free (icalcomp2);
 	}
-
-	return TRUE;
 }
 
-static gboolean
-test_bulk_methods (GSList *icalcomps)
+static void
+test_bulk_methods (ECalClient *cal_client,
+		   GSList *icalcomps)
 {
-	ECalClient *cal_client;
 	GError *error = NULL;
 	GSList *uids = NULL, *ids = NULL;
 	const GSList *lcomp, *luid;
 	gint i = 0;
 
-	g_return_val_if_fail (icalcomps != NULL, FALSE);
-
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		return FALSE;
-	}
+	g_assert (icalcomps != NULL);
 
 	/* Create all the objects in bulk */
-	if (!e_cal_client_create_objects_sync (cal_client, icalcomps, &uids, NULL, &error)) {
-		report_error ("create objects sync", &error);
-		g_object_unref (cal_client);
-		return FALSE;
-	}
+	if (!e_cal_client_create_objects_sync (cal_client, icalcomps, &uids, NULL, &error))
+		g_error ("create objects sync: %s", error->message);
 
-	g_return_val_if_fail (uids != NULL, FALSE);
-	g_return_val_if_fail (g_slist_length (uids) == NB_COMPONENTS, FALSE);
+	g_assert (uids != NULL);
+	g_assert_cmpint (g_slist_length (uids), ==, NB_COMPONENTS);
 
 	/* Update icalcomponents uids */
 	luid = uids;
@@ -159,11 +124,7 @@ test_bulk_methods (GSList *icalcomps)
 	}
 
 	/* Retrieve all the objects and check that they are the same */
-	if (!check_icalcomps_exist (cal_client, icalcomps)) {
-		g_object_unref (cal_client);
-		g_slist_free_full (uids, g_free);
-		return FALSE;
-	}
+	check_icalcomps_exist (cal_client, icalcomps);
 
 	/* Modify the objects */
 	for (lcomp = icalcomps; lcomp; lcomp = lcomp->next) {
@@ -178,54 +139,36 @@ test_bulk_methods (GSList *icalcomps)
 	}
 
 	/* Save the modified objects in bulk */
-	if (!e_cal_client_modify_objects_sync (cal_client, icalcomps, CALOBJ_MOD_ALL, NULL, &error)) {
-		report_error ("modify objects sync", &error);
-		g_object_unref (cal_client);
-		g_slist_free_full (uids, g_free);
-		return FALSE;
-	}
+	if (!e_cal_client_modify_objects_sync (cal_client, icalcomps, CALOBJ_MOD_ALL, NULL, &error))
+		g_error ("modify objects sync: %s", error->message);
 
 	/* Retrieve all the objects and check that they have been modified */
-	if (!check_icalcomps_exist (cal_client, icalcomps)) {
-		g_object_unref (cal_client);
-		g_slist_free_full (uids, g_free);
-		return FALSE;
-	}
+	check_icalcomps_exist (cal_client, icalcomps);
 
 	/* Remove all the objects in bulk */
 	ids = uid_slist_to_ecalcomponentid_slist (uids);
 
-	if (!e_cal_client_remove_objects_sync (cal_client, ids, CALOBJ_MOD_ALL, NULL, &error)) {
-		report_error ("remove objects sync", &error);
-		g_object_unref (cal_client);
-		g_slist_free_full (ids, (GDestroyNotify) e_cal_component_free_id);
-		g_slist_free_full (uids, g_free);
-		return FALSE;
-	}
+	if (!e_cal_client_remove_objects_sync (cal_client, ids, CALOBJ_MOD_ALL, NULL, &error))
+		g_error ("remove objects sync: %s", error->message);
+
 	g_slist_free_full (ids, (GDestroyNotify) e_cal_component_free_id);
 
 	/* Check that the objects don't exist anymore */
-	if (!check_removed (cal_client, uids)) {
-		g_object_unref (cal_client);
-		g_slist_free_full (uids, g_free);
-		return FALSE;
-	}
+	check_removed (cal_client, uids);
 
 	g_slist_free_full (uids, g_free);
-	g_object_unref (cal_client);
-	return TRUE;
 }
 
-gint
-main (gint argc,
-          gchar **argv)
+static void
+run_test_bulk_methods (ETestServerFixture *fixture,
+		       gconstpointer       user_data)
 {
+	ECalClient *cal_client;
 	GSList *icalcomps = NULL;
 	struct icaltimetype now;
 	gint i;
-	gboolean res;
 
-	main_initialize ();
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
 	now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
 
@@ -245,9 +188,22 @@ main (gint argc,
 	}
 
 	/* Test synchronous bulk methods */
-	res = test_bulk_methods (icalcomps);
+	test_bulk_methods (cal_client, icalcomps);
 
 	g_slist_free_full (icalcomps, (GDestroyNotify) icalcomponent_free);
+}
+
+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 ("/ECalClient/BulkMethods", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, run_test_bulk_methods, e_test_server_utils_teardown);
 
-	return (res != TRUE);
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libecal/client/test-client-create-object.c b/tests/libecal/client/test-client-create-object.c
index 095a403..ea642af 100644
--- a/tests/libecal/client/test-client-create-object.c
+++ b/tests/libecal/client/test-client-create-object.c
@@ -4,123 +4,96 @@
 #include <libecal/libecal.h>
 #include <libical/ical.h>
 
-#include "client-test-utils.h"
+#include "e-test-server-utils.h"
 
-static gboolean
+static ETestServerClosure cal_closure =
+	{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
+
+static void
 test_icalcomps (icalcomponent *icalcomp1,
                 icalcomponent *icalcomp2)
 {
 	struct icaltimetype t1, t2;
 
-	if (!icalcomp2) {
-		g_printerr ("Failure: get object returned NULL\n");
-		return FALSE;
-	}
-
-	if (g_strcmp0 (icalcomponent_get_uid (icalcomp1), icalcomponent_get_uid (icalcomp2)) != 0) {
-		g_printerr ("Failure: uid doesn't match, expected '%s', got '%s'\n", icalcomponent_get_uid (icalcomp1), icalcomponent_get_uid (icalcomp2));
-		return FALSE;
-	}
+	if (!icalcomp2)
+		g_error ("Failure: get object returned NULL");
 
-	if (g_strcmp0 (icalcomponent_get_summary (icalcomp1), icalcomponent_get_summary (icalcomp2)) != 0) {
-		g_printerr ("Failure: summary doesn't match, expected '%s', got '%s'\n", icalcomponent_get_summary (icalcomp1), icalcomponent_get_summary (icalcomp2));
-		return FALSE;
-	}
+	g_assert_cmpstr (icalcomponent_get_uid (icalcomp1), ==, icalcomponent_get_uid (icalcomp2));
+	g_assert_cmpstr (icalcomponent_get_summary (icalcomp1), ==, icalcomponent_get_summary (icalcomp2));
 
 	t1 = icalcomponent_get_dtstart (icalcomp1);
 	t2 = icalcomponent_get_dtstart (icalcomp2);
 
-	if (icaltime_compare (t1, t2) != 0) {
-		g_printerr ("Failure: dtend doesn't match, expected '%s', got '%s'\n", icaltime_as_ical_string (t1), icaltime_as_ical_string (t2));
-		return FALSE;
-	}
+	if (icaltime_compare (t1, t2) != 0)
+		g_error ("Failure: dtend doesn't match, expected '%s', got '%s'\n",
+			 icaltime_as_ical_string (t1), icaltime_as_ical_string (t2));
 
 	t1 = icalcomponent_get_dtend (icalcomp1);
 	t2 = icalcomponent_get_dtend (icalcomp2);
 
-	if (icaltime_compare (t1, t2) != 0) {
-		g_printerr ("Failure: dtend doesn't match, expected '%s', got '%s'\n", icaltime_as_ical_string (t1), icaltime_as_ical_string (t2));
-		return FALSE;
-	}
-
-	return TRUE;
+	if (icaltime_compare (t1, t2) != 0)
+		g_error ("Failure: dtend doesn't match, expected '%s', got '%s'\n",
+			 icaltime_as_ical_string (t1), icaltime_as_ical_string (t2));
 }
 
-static gboolean
-test_sync (icalcomponent *icalcomp)
+static void
+test_create_object_sync (ETestServerFixture *fixture,
+			 gconstpointer       user_data)
 {
 	ECalClient *cal_client;
+	icalcomponent *icalcomp;
 	icalcomponent *icalcomp2 = NULL, *clone;
+	struct icaltimetype now;
 	GError *error = NULL;
+	GSList *ecalcomps = NULL;
 	gchar *uid = NULL;
-	gboolean res;
 
-	g_return_val_if_fail (icalcomp != NULL, FALSE);
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		return FALSE;
-	}
+	/* Build up new component */
+	now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
+	icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
+	icalcomponent_set_summary (icalcomp, "Test event summary");
+	icalcomponent_set_dtstart (icalcomp, now);
+	icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
 
-	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error)) {
-		report_error ("create object sync", &error);
-		g_object_unref (cal_client);
-		return FALSE;
-	}
+	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error))
+		g_error ("create object sync: %s", error->message);
 
-	if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp2, NULL, &error)) {
-		report_error ("get object sync", &error);
-		g_free (uid);
-		g_object_unref (cal_client);
-		return FALSE;
-	}
+	if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp2, NULL, &error))
+		g_error ("get object sync: %s", error->message);
 
 	clone = icalcomponent_new_clone (icalcomp);
 	icalcomponent_set_uid (clone, uid);
 
-	res = test_icalcomps (clone, icalcomp2);
+	test_icalcomps (clone, icalcomp2);
 
 	icalcomponent_free (icalcomp2);
 
-	if (res) {
-		GSList *ecalcomps = NULL;
-
-		if (!e_cal_client_get_objects_for_uid_sync (cal_client, uid, &ecalcomps, NULL, &error)) {
-			report_error ("get objects for uid sync", &error);
-			res = FALSE;
-		}
+	if (!e_cal_client_get_objects_for_uid_sync (cal_client, uid, &ecalcomps, NULL, &error))
+		g_error ("get objects for uid sync: %s", error->message);
 
-		if (g_slist_length (ecalcomps) != 1) {
-			g_printerr ("Failure: expected 1 component, bug got %d\n", g_slist_length (ecalcomps));
-			res = FALSE;
-		} else {
-			ECalComponent *ecalcomp = ecalcomps->data;
-
-			res = test_icalcomps (clone, e_cal_component_get_icalcomponent (ecalcomp));
-		}
+	if (g_slist_length (ecalcomps) != 1)
+		g_error ("Failure: expected 1 component, bug got %d", g_slist_length (ecalcomps));
+	else {
+		ECalComponent *ecalcomp = ecalcomps->data;
 
-		e_cal_client_free_ecalcomp_slist (ecalcomps);
+		test_icalcomps (clone, e_cal_component_get_icalcomponent (ecalcomp));
 	}
+	e_cal_client_free_ecalcomp_slist (ecalcomps);
 
 	icalcomponent_free (clone);
 	g_free (uid);
+	icalcomponent_free (icalcomp);
+}
 
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (cal_client);
-		return FALSE;
-	}
-
-	g_object_unref (cal_client);
 
-	return res;
-}
+typedef struct {
+	icalcomponent *icalcomp;
+	icalcomponent *clone;
+	GMainLoop *loop;
+} AsyncData;
 
-/* asynchronous read2 callback with a main-loop running */
 static void
 async_read2_result_ready (GObject *source_object,
                           GAsyncResult *result,
@@ -128,44 +101,31 @@ async_read2_result_ready (GObject *source_object,
 {
 	ECalClient *cal_client;
 	GError *error = NULL;
-	icalcomponent *icalcomp1 = user_data;
+	AsyncData *data = (AsyncData *)user_data;
+	icalcomponent *icalcomp1 = data->clone;
 	GSList *ecalcomps = NULL;
-	gboolean res;
 
 	g_return_if_fail (icalcomp1 != NULL);
 
 	cal_client = E_CAL_CLIENT (source_object);
 
-	if (!e_cal_client_get_objects_for_uid_finish (cal_client, result, &ecalcomps, &error)) {
-		report_error ("get objects for uid finish", &error);
-		g_object_unref (cal_client);
-		icalcomponent_free (icalcomp1);
-		stop_main_loop (1);
-		return;
-	}
+	if (!e_cal_client_get_objects_for_uid_finish (cal_client, result, &ecalcomps, &error))
+		g_error ("get objects for uid finish: %s", error->message);
 
-	if (g_slist_length (ecalcomps) != 1) {
-		g_printerr ("Failure: expected 1 component, bug got %d\n", g_slist_length (ecalcomps));
-		res = FALSE;
-	} else {
+	if (g_slist_length (ecalcomps) != 1)
+		g_error ("Failure: expected 1 component, bug got %d", g_slist_length (ecalcomps));
+	else {
 		ECalComponent *ecalcomp = ecalcomps->data;
 
-		res = test_icalcomps (icalcomp1, e_cal_component_get_icalcomponent (ecalcomp));
+		test_icalcomps (icalcomp1, e_cal_component_get_icalcomponent (ecalcomp));
 	}
-
 	e_cal_client_free_ecalcomp_slist (ecalcomps);
 
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-	}
-
-	g_object_unref (cal_client);
 	icalcomponent_free (icalcomp1);
-
-	stop_main_loop (res ? 0 : 1);
+	g_main_loop_quit (data->loop);
 }
 
-/* asynchronous read callback with a main-loop running */
+
 static void
 async_read_result_ready (GObject *source_object,
                          GAsyncResult *result,
@@ -173,28 +133,23 @@ async_read_result_ready (GObject *source_object,
 {
 	ECalClient *cal_client;
 	GError *error = NULL;
-	icalcomponent *icalcomp1 = user_data, *icalcomp2 = NULL;
+	AsyncData *data = (AsyncData *)user_data;
+	icalcomponent *icalcomp1 = data->clone, *icalcomp2 = NULL;
 
 	g_return_if_fail (icalcomp1 != NULL);
 
 	cal_client = E_CAL_CLIENT (source_object);
-
-	if (!e_cal_client_get_object_finish (cal_client, result, &icalcomp2, &error)) {
-		report_error ("get object finish", &error);
-		g_object_unref (cal_client);
-		icalcomponent_free (icalcomp1);
-		stop_main_loop (1);
-		return;
-	}
+	if (!e_cal_client_get_object_finish (cal_client, result, &icalcomp2, &error))
+		g_error ("get object finish: %s", error->message);
 
 	test_icalcomps (icalcomp1, icalcomp2);
-
 	icalcomponent_free (icalcomp2);
 
-	e_cal_client_get_objects_for_uid (cal_client, icalcomponent_get_uid (icalcomp1), NULL, async_read2_result_ready, icalcomp1);
+	e_cal_client_get_objects_for_uid (cal_client,
+					  icalcomponent_get_uid (icalcomp1), NULL,
+					  async_read2_result_ready, data);
 }
 
-/* asynchronous write callback with a main-loop running */
 static void
 async_write_result_ready (GObject *source_object,
                           GAsyncResult *result,
@@ -203,83 +158,34 @@ async_write_result_ready (GObject *source_object,
 	ECalClient *cal_client;
 	GError *error = NULL;
 	gchar *uid = NULL;
-	icalcomponent *clone, *icalcomp = user_data;
+	AsyncData *data = (AsyncData *)user_data;
+	icalcomponent *clone, *icalcomp = data->icalcomp;
 
 	g_return_if_fail (icalcomp != NULL);
 
 	cal_client = E_CAL_CLIENT (source_object);
 
-	if (!e_cal_client_create_object_finish (cal_client, result, &uid, &error)) {
-		report_error ("create object finish", &error);
-		g_object_unref (cal_client);
-		stop_main_loop (1);
-		return;
-	}
+	if (!e_cal_client_create_object_finish (cal_client, result, &uid, &error))
+		g_error ("create object finish: %s", error->message);
 
 	clone = icalcomponent_new_clone (icalcomp);
 	icalcomponent_set_uid (clone, uid);
 
-	e_cal_client_get_object (cal_client, uid, NULL, NULL, async_read_result_ready, clone);
-
+	data->clone = clone;
+	e_cal_client_get_object (cal_client, uid, NULL, NULL, async_read_result_ready, data);
 	g_free (uid);
 }
 
-/* synchronously in idle with main-loop running */
-static gboolean
-test_sync_in_idle (gpointer user_data)
+static void
+test_create_object_async (ETestServerFixture *fixture,
+			  gconstpointer       user_data)
 {
 	ECalClient *cal_client;
-	GError *error = NULL;
-	icalcomponent *icalcomp = user_data;
-
-	g_return_val_if_fail (icalcomp != NULL, FALSE);
-
-	if (!test_sync (icalcomp)) {
-		stop_main_loop (1);
-		return FALSE;
-	}
-
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		stop_main_loop (1);
-		return FALSE;
-	}
-
-	e_cal_client_create_object (cal_client, icalcomp, NULL, async_write_result_ready, icalcomp);
-
-	return FALSE;
-}
-
-/* synchronously in a dedicated thread with main-loop running */
-static gpointer
-test_sync_in_thread (gpointer user_data)
-{
-	icalcomponent *icalcomp = user_data;
-
-	g_return_val_if_fail (icalcomp != NULL, NULL);
-
-	if (!test_sync (icalcomp)) {
-		stop_main_loop (1);
-		return NULL;
-	}
-
-	g_idle_add (test_sync_in_idle, icalcomp);
-
-	return NULL;
-}
-
-gint
-main (gint argc,
-      gchar **argv)
-{
 	icalcomponent *icalcomp;
 	struct icaltimetype now;
+	AsyncData data = { 0, };
 
-	main_initialize ();
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
 	/* Build up new component */
 	now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
@@ -288,18 +194,27 @@ main (gint argc,
 	icalcomponent_set_dtstart (icalcomp, now);
 	icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
 
-	/* synchronously without main-loop */
-	if (!test_sync (icalcomp)) {
-		icalcomponent_free (icalcomp);
-		return 1;
-	}
-
-	start_in_thread_with_main_loop (test_sync_in_thread, icalcomp);
+	data.icalcomp = icalcomp;
+	data.loop = fixture->loop;
+	e_cal_client_create_object (cal_client, icalcomp, NULL, async_write_result_ready, &data);
+	g_main_loop_run (fixture->loop);
 
 	icalcomponent_free (icalcomp);
+}
+
+gint
+main (gint argc,
+      gchar **argv)
+{
+#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 ("/ECalClient/CreateObject/Sync", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_create_object_sync, e_test_server_utils_teardown);
+	g_test_add ("/ECalClient/CreateObject/Async", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_create_object_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libecal/client/test-client-get-attachment-uris.c b/tests/libecal/client/test-client-get-attachment-uris.c
index 6447c00..3f28627 100644
--- a/tests/libecal/client/test-client-get-attachment-uris.c
+++ b/tests/libecal/client/test-client-get-attachment-uris.c
@@ -5,19 +5,70 @@
 #include <libecal/libecal.h>
 #include <libical/ical.h>
 
-#include "client-test-utils.h"
+#include "e-test-server-utils.h"
 
 #define ATTACH1 "file:///tmp/file1.x"
 #define ATTACH2 "file:///tmp/file2"
 #define ATTACH3 "file:///tmp/dir/fileÄÅÄÅÅÃÃÃÃ3"
 
-static gboolean
+static ETestServerClosure cal_closure =
+	{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
+
+static void
+add_attach (icalcomponent *icalcomp,
+            const gchar *uri)
+{
+	gsize buf_size;
+	gchar *buf;
+	icalproperty *prop;
+	icalattach *attach;
+
+	g_return_if_fail (icalcomp != NULL);
+	g_return_if_fail (uri != NULL);
+
+	buf_size = 2 * strlen (uri);
+	buf = g_malloc0 (buf_size);
+	icalvalue_encode_ical_string (uri, buf, buf_size);
+	attach = icalattach_new_from_url (uri);
+	prop = icalproperty_new_attach (attach);
+	icalcomponent_add_property (icalcomp, prop);
+	icalattach_unref (attach);
+	g_free (buf);
+}
+
+static const gchar *
+setup_cal (ECalClient *cal_client)
+{
+	icalcomponent *icalcomp;
+	struct icaltimetype now;
+	gchar *uid = NULL;
+	GError *error = NULL;
+
+	now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
+	icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
+	icalcomponent_set_summary (icalcomp, "Test event summary");
+	icalcomponent_set_dtstart (icalcomp, now);
+	icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
+	add_attach (icalcomp, ATTACH1);
+	add_attach (icalcomp, ATTACH2);
+	add_attach (icalcomp, ATTACH3);
+
+	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error))
+		g_error ("create object sync: %s", error->message);
+
+	icalcomponent_free (icalcomp);
+	g_object_set_data_full (G_OBJECT (cal_client), "use-uid", uid, g_free);
+
+	return uid;
+}
+
+static void
 manage_result (GSList *attachment_uris)
 {
 	gboolean res;
 
-	g_return_val_if_fail (attachment_uris != NULL, FALSE);
-	g_return_val_if_fail (g_slist_length (attachment_uris) == 3, FALSE);
+	g_assert (attachment_uris != NULL);
+	g_assert_cmpint (g_slist_length (attachment_uris), ==, 3);
 
 	res = g_slist_find_custom (attachment_uris, ATTACH1, g_str_equal)
 	   && g_slist_find_custom (attachment_uris, ATTACH2, g_str_equal)
@@ -29,31 +80,31 @@ manage_result (GSList *attachment_uris)
 		g_printerr ("Failed: didn't return same three attachment uris, got instead:\n");
 		for (au = attachment_uris; au; au = au->next)
 			g_printerr ("\t'%s'\n", (const gchar *) au->data);
+
+		g_assert_not_reached ();
 	}
 
 	e_client_util_free_string_slist (attachment_uris);
-
-	return res;
 }
 
-static gboolean
-test_sync (ECalClient *cal_client)
+static void
+test_get_attachment_uris_sync (ETestServerFixture *fixture,
+			       gconstpointer       user_data)
 {
+	ECalClient *cal_client;
 	GError *error = NULL;
 	GSList *attachment_uris = NULL;
-	const gchar *uid = g_object_get_data (G_OBJECT (cal_client), "use-uid");
+	const gchar *uid;
 
-	g_return_val_if_fail (uid != NULL, FALSE);
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
+	uid = setup_cal (cal_client);
 
-	if (!e_cal_client_get_attachment_uris_sync (cal_client, uid, NULL, &attachment_uris, NULL, &error)) {
-		report_error ("get attachment uris sync", &error);
-		return FALSE;
-	}
+	if (!e_cal_client_get_attachment_uris_sync (cal_client, uid, NULL, &attachment_uris, NULL, &error))
+		g_error ("get attachment uris sync: %s", error->message);
 
-	return manage_result (attachment_uris);
+	manage_result (attachment_uris);
 }
 
-/* asynchronous callback with a main-loop running */
 static void
 async_attachment_uris_result_ready (GObject *source_object,
                                     GAsyncResult *result,
@@ -62,134 +113,45 @@ async_attachment_uris_result_ready (GObject *source_object,
 	ECalClient *cal_client;
 	GError *error = NULL;
 	GSList *attachment_uris = NULL;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
 	cal_client = E_CAL_CLIENT (source_object);
 
-	if (!e_cal_client_get_attachment_uris_finish (cal_client, result, &attachment_uris, &error)) {
-		report_error ("get attachment uris finish", &error);
-		stop_main_loop (1);
-		return;
-	}
-
-	stop_main_loop (manage_result (attachment_uris) ? 0 : 1);
-}
-
-/* synchronously in idle with main-loop running */
-static gboolean
-test_sync_in_idle (gpointer user_data)
-{
-	ECalClient *cal_client = user_data;
-	const gchar *uid;
-
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-	g_return_val_if_fail (E_IS_CAL_CLIENT (cal_client), FALSE);
-
-	if (!test_sync (cal_client)) {
-		stop_main_loop (1);
-		return FALSE;
-	}
-
-	uid = g_object_get_data (G_OBJECT (cal_client), "use-uid");
+	if (!e_cal_client_get_attachment_uris_finish (cal_client, result, &attachment_uris, &error))
+		g_error ("get attachment uris finish: %s", error->message);
 
-	e_cal_client_get_attachment_uris (cal_client, uid, NULL, NULL, async_attachment_uris_result_ready, NULL);
+	manage_result (attachment_uris);
 
-	return FALSE;
-}
-
-/* synchronously in a dedicated thread with main-loop running */
-static gpointer
-test_sync_in_thread (gpointer user_data)
-{
-	if (!test_sync (user_data)) {
-		stop_main_loop (1);
-		return NULL;
-	}
-
-	g_idle_add (test_sync_in_idle, user_data);
-
-	return NULL;
+	g_main_loop_quit (loop);
 }
 
 static void
-add_attach (icalcomponent *icalcomp,
-            const gchar *uri)
+test_get_attachment_uris_async (ETestServerFixture *fixture,
+				gconstpointer       user_data)
 {
-	gsize buf_size;
-	gchar *buf;
-	icalproperty *prop;
-	icalattach *attach;
+	ECalClient *cal_client;
+	const gchar *uid;
 
-	g_return_if_fail (icalcomp != NULL);
-	g_return_if_fail (uri != NULL);
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
+	uid = setup_cal (cal_client);
 
-	buf_size = 2 * strlen (uri);
-	buf = g_malloc0 (buf_size);
-	icalvalue_encode_ical_string (uri, buf, buf_size);
-	attach = icalattach_new_from_url (uri);
-	prop = icalproperty_new_attach (attach);
-	icalcomponent_add_property (icalcomp, prop);
-	icalattach_unref (attach);
-	g_free (buf);
+	e_cal_client_get_attachment_uris (cal_client, uid, NULL, NULL, async_attachment_uris_result_ready, fixture->loop);
+	g_main_loop_run (fixture->loop);
 }
 
 gint
 main (gint argc,
       gchar **argv)
 {
-	ECalClient *cal_client;
-	GError *error = NULL;
-	icalcomponent *icalcomp;
-	struct icaltimetype now;
-	gchar *uid = NULL;
-
-	main_initialize ();
-
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
-	icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
-	icalcomponent_set_summary (icalcomp, "Test event summary");
-	icalcomponent_set_dtstart (icalcomp, now);
-	icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
-	add_attach (icalcomp, ATTACH1);
-	add_attach (icalcomp, ATTACH2);
-	add_attach (icalcomp, ATTACH3);
-
-	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error)) {
-		report_error ("create object sync", &error);
-		icalcomponent_free (icalcomp);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	icalcomponent_free (icalcomp);
-	g_object_set_data_full (G_OBJECT (cal_client), "use-uid", uid, g_free);
-
-	/* synchronously without main-loop */
-	if (!test_sync (cal_client)) {
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	start_in_thread_with_main_loop (test_sync_in_thread, cal_client);
-
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	g_object_unref (cal_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 ("/ECalClient/GetAttachmentUris/Sync", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_get_attachment_uris_sync, e_test_server_utils_teardown);
+	g_test_add ("/ECalClient/GetAttachmentUris/Async", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_get_attachment_uris_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libecal/client/test-client-get-free-busy.c b/tests/libecal/client/test-client-get-free-busy.c
index 3c46ef0..6f9badd 100644
--- a/tests/libecal/client/test-client-get-free-busy.c
+++ b/tests/libecal/client/test-client-get-free-busy.c
@@ -5,6 +5,10 @@
 #include <libical/ical.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure cal_closure =
+	{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
 
 #define USER_EMAIL "user example com"
 
@@ -16,8 +20,9 @@ free_busy_data_cb (ECalClient *client,
 	g_print ("   Received %d Free/Busy components from %s\n", g_slist_length ((GSList *) free_busy), func_name);
 }
 
-static gboolean
-test_sync (void)
+static void
+test_get_free_busy_sync (ETestServerFixture *fixture,
+			 gconstpointer       user_data)
 {
 	ECalClient *cal_client;
 	GError *error = NULL;
@@ -26,14 +31,7 @@ test_sync (void)
 	time_t start, end;
 	gulong sig_id;
 
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		return FALSE;
-	}
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
 	utc = icaltimezone_get_utc_timezone ();
 	start = time_from_isodate ("20040212T000000Z");
@@ -42,30 +40,14 @@ test_sync (void)
 
 	sig_id = g_signal_connect (cal_client, "free-busy-data", G_CALLBACK (free_busy_data_cb), (gpointer) G_STRFUNC);
 
-	if (!e_cal_client_get_free_busy_sync (cal_client, start, end, users, NULL, &error)) {
-		report_error ("get free busy sync", &error);
-		g_signal_handler_disconnect (cal_client, sig_id);
-		g_object_unref (cal_client);
-		g_slist_free (users);
-		return FALSE;
-	}
+	if (!e_cal_client_get_free_busy_sync (cal_client, start, end, users, NULL, &error))
+		g_error ("get free busy sync: %s", error->message);
 
 	g_signal_handler_disconnect (cal_client, sig_id);
 
 	g_slist_free (users);
-
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (cal_client);
-		return FALSE;
-	}
-
-	g_object_unref (cal_client);
-
-	return TRUE;
 }
 
-/* asynchronous get_free_busy callback with a main-loop running */
 static void
 async_get_free_busy_result_ready (GObject *source_object,
                                   GAsyncResult *result,
@@ -73,52 +55,29 @@ async_get_free_busy_result_ready (GObject *source_object,
 {
 	ECalClient *cal_client;
 	GError *error = NULL;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
 	cal_client = E_CAL_CLIENT (source_object);
 
-	if (!e_cal_client_get_free_busy_finish (cal_client, result, &error)) {
-		report_error ("create object finish", &error);
-		g_object_unref (cal_client);
-		stop_main_loop (1);
-		return;
-	}
-
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (cal_client);
-		stop_main_loop (1);
-		return;
-	}
+	if (!e_cal_client_get_free_busy_finish (cal_client, result, &error))
+		g_error ("create object finish: %s", error->message);
 
-	g_object_unref (cal_client);
+	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error))
+		g_error ("client remove sync: %s", error->message);
 
-	stop_main_loop (0);
+	g_main_loop_quit (loop);
 }
 
-/* synchronously in idle with main-loop running */
-static gboolean
-test_async_in_idle (gpointer user_data)
+static void
+test_get_free_busy_async (ETestServerFixture *fixture,
+			  gconstpointer       user_data)
 {
 	ECalClient *cal_client;
-	GError *error = NULL;
 	icaltimezone *utc;
 	GSList *users = NULL;
 	time_t start, end;
 
-	if (!test_sync ()) {
-		stop_main_loop (1);
-		return FALSE;
-	}
-
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		stop_main_loop (1);
-		return FALSE;
-	}
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
 	utc = icaltimezone_get_utc_timezone ();
 	start = time_from_isodate ("20040212T000000Z");
@@ -128,41 +87,25 @@ test_async_in_idle (gpointer user_data)
 	/* here is all Free/Busy information received */
 	g_signal_connect (cal_client, "free-busy-data", G_CALLBACK (free_busy_data_cb), (gpointer) G_STRFUNC);
 
-	e_cal_client_get_free_busy (cal_client, start, end, users, NULL, async_get_free_busy_result_ready, NULL);
-
+	e_cal_client_get_free_busy (cal_client, start, end, users, NULL, async_get_free_busy_result_ready, fixture->loop);
 	g_slist_free (users);
 
-	return FALSE;
-}
-
-/* synchronously in a dedicated thread with main-loop running */
-static gpointer
-test_sync_in_thread (gpointer user_data)
-{
-	if (!test_sync ()) {
-		stop_main_loop (1);
-		return NULL;
-	}
-
-	g_idle_add (test_async_in_idle, NULL);
-
-	return NULL;
+	g_main_loop_run (fixture->loop);
 }
 
 gint
 main (gint argc,
       gchar **argv)
 {
-	main_initialize ();
-
-	/* synchronously without main-loop */
-	if (!test_sync ())
-		return 1;
-
-	start_in_thread_with_main_loop (test_sync_in_thread, NULL);
+#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 ("/ECalClient/GetFreeBusy/Sync", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_get_free_busy_sync, e_test_server_utils_teardown);
+	g_test_add ("/ECalClient/GetFreeBusy/Async", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_get_free_busy_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libecal/client/test-client-get-object-list.c b/tests/libecal/client/test-client-get-object-list.c
index 2144783..750cb85 100644
--- a/tests/libecal/client/test-client-get-object-list.c
+++ b/tests/libecal/client/test-client-get-object-list.c
@@ -4,89 +4,93 @@
 #include <libecal/libecal.h>
 #include <libical/ical.h>
 
-#include "client-test-utils.h"
+#include "e-test-server-utils.h"
 
 #define EVENT_SUMMARY "Creation of new test event"
 #define EVENT_QUERY "(contains? \"summary\" \"" EVENT_SUMMARY "\")"
 
-static gboolean
-test_result (icalcomponent *icalcomp)
+static ETestServerClosure cal_closure =
+	{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
+
+
+static void
+setup_cal (ECalClient *cal_client)
 {
-	g_return_val_if_fail (icalcomp != NULL, FALSE);
-	g_return_val_if_fail (g_strcmp0 (icalcomponent_get_summary (icalcomp), EVENT_SUMMARY) == 0, FALSE);
+	struct icaltimetype now;
+	icalcomponent *icalcomp;
+	gchar *uid = NULL;
+	GError *error = NULL;
+
+	now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
+	icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
+	icalcomponent_set_summary (icalcomp, EVENT_SUMMARY);
+	icalcomponent_set_dtstart (icalcomp, now);
+	icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
+
+	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error))
+		g_error ("create object sync: %s", error->message);
 
-	return TRUE;
+	icalcomponent_free (icalcomp);
+	g_free (uid);
 }
 
-static gboolean
-test_sync (ECalClient *cal_client)
+static void
+test_result (icalcomponent *icalcomp)
 {
-	GError *error = NULL;
+	g_assert (icalcomp != NULL);
+	g_assert_cmpstr (icalcomponent_get_summary (icalcomp), ==, EVENT_SUMMARY);
+}
+
+static void
+test_get_object_list_sync (ETestServerFixture *fixture,
+			   gconstpointer       user_data)
+{
+	ECalClient *cal_client;
 	GSList *icalcomps = NULL, *ecalcomps = NULL;
-	gboolean res = TRUE;
+	GError *error = NULL;
+
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
+	setup_cal (cal_client);
 
-	if (!e_cal_client_get_object_list_sync (cal_client, EVENT_QUERY, &icalcomps, NULL, &error)) {
-		report_error ("get object list sync", &error);
-		return FALSE;
-	}
+	if (!e_cal_client_get_object_list_sync (cal_client, EVENT_QUERY, &icalcomps, NULL, &error))
+		g_error ("get object list sync: %s", error->message);
 
-	if (g_slist_length (icalcomps) != 1) {
-		g_printerr ("Failure: expected 1 item returned in icalcomps, got %d\n", g_slist_length (icalcomps));
-		res = FALSE;
-	} else {
-		res = res && test_result (icalcomps->data);
-	}
+	g_assert_cmpint (g_slist_length (icalcomps), ==, 1);
+	test_result (icalcomps->data);
 
 	e_cal_client_free_icalcomp_slist (icalcomps);
 
-	if (!e_cal_client_get_object_list_as_comps_sync (cal_client, EVENT_QUERY, &ecalcomps, NULL, &error)) {
-		report_error ("get object list as comps sync", &error);
-		return FALSE;
-	}
+	if (!e_cal_client_get_object_list_as_comps_sync (cal_client, EVENT_QUERY, &ecalcomps, NULL, &error))
+		g_error ("get object list as comps sync: %s", error->message);
 
-	if (g_slist_length (ecalcomps) != 1) {
-		g_printerr ("Failure: expected 1 item returned in ecalcomps, got %d\n", g_slist_length (ecalcomps));
-		res = FALSE;
-	} else {
-		res = res && test_result (e_cal_component_get_icalcomponent (ecalcomps->data));
-	}
+	g_assert_cmpint (g_slist_length (ecalcomps), ==, 1);
+	test_result (e_cal_component_get_icalcomponent (ecalcomps->data));
 
 	e_cal_client_free_ecalcomp_slist (ecalcomps);
-
-	return res;
 }
 
-/* asynchronous callback with a main-loop running */
 static void
 async_get_object_list_as_comps_result_ready (GObject *source_object,
                                              GAsyncResult *result,
                                              gpointer user_data)
 {
 	ECalClient *cal_client;
+	GMainLoop *loop = (GMainLoop *)user_data;
 	GError *error = NULL;
 	GSList *ecalcomps = NULL;
-	gboolean res = TRUE;
 
 	cal_client = E_CAL_CLIENT (source_object);
 
-	if (!e_cal_client_get_object_list_as_comps_finish (cal_client, result, &ecalcomps, &error)) {
-		report_error ("get object list as comps finish", &error);
-		stop_main_loop (1);
-		return;
-	}
+	if (!e_cal_client_get_object_list_as_comps_finish (cal_client, result, &ecalcomps, &error))
+		g_error ("get object list as comps finish: %s", error->message);
 
-	if (g_slist_length (ecalcomps) != 1) {
-		g_printerr ("Failure: expected 1 item returned in ecalcomps, got %d\n", g_slist_length (ecalcomps));
-		res = FALSE;
-	} else {
-		res = res && test_result (e_cal_component_get_icalcomponent (ecalcomps->data));
-	}
+	g_assert_cmpint (g_slist_length (ecalcomps), ==, 1);
+	test_result (e_cal_component_get_icalcomponent (ecalcomps->data));
 
 	e_cal_client_free_ecalcomp_slist (ecalcomps);
-	stop_main_loop (res ? 0 : 1);
+	g_main_loop_quit (loop);
 }
 
-/* asynchronous callback with a main-loop running */
 static void
 async_get_object_list_result_ready (GObject *source_object,
                                     GAsyncResult *result,
@@ -98,111 +102,43 @@ async_get_object_list_result_ready (GObject *source_object,
 
 	cal_client = E_CAL_CLIENT (source_object);
 
-	if (!e_cal_client_get_object_list_finish (cal_client, result, &icalcomps, &error)) {
-		report_error ("get object list finish", &error);
-		stop_main_loop (1);
-		return;
-	}
-
-	if (g_slist_length (icalcomps) != 1) {
-		g_printerr ("Failure: expected 1 item returned in icalcomps, got %d\n", g_slist_length (icalcomps));
-	} else {
-		test_result (icalcomps->data);
-	}
+	if (!e_cal_client_get_object_list_finish (cal_client, result, &icalcomps, &error))
+		g_error ("get object list finish: %s", error->message);
 
+	g_assert_cmpint (g_slist_length (icalcomps), ==, 1);
+	test_result (icalcomps->data);
 	e_cal_client_free_icalcomp_slist (icalcomps);
 
-	e_cal_client_get_object_list_as_comps (cal_client, EVENT_QUERY, NULL, async_get_object_list_as_comps_result_ready, NULL);
-}
-
-/* synchronously in idle with main-loop running */
-static gboolean
-test_sync_in_idle (gpointer user_data)
-{
-	ECalClient *cal_client = user_data;
-
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-	g_return_val_if_fail (E_IS_CAL_CLIENT (cal_client), FALSE);
-
-	if (!test_sync (cal_client)) {
-		stop_main_loop (1);
-		return FALSE;
-	}
-
-	e_cal_client_get_object_list (cal_client, EVENT_QUERY, NULL, async_get_object_list_result_ready, NULL);
-
-	return FALSE;
+	e_cal_client_get_object_list_as_comps (cal_client, EVENT_QUERY, NULL,
+					       async_get_object_list_as_comps_result_ready, user_data);
 }
 
-/* synchronously in a dedicated thread with main-loop running */
-static gpointer
-test_sync_in_thread (gpointer user_data)
+static void
+test_get_object_list_async (ETestServerFixture *fixture,
+			    gconstpointer       user_data)
 {
-	if (!test_sync (user_data)) {
-		stop_main_loop (1);
-		return NULL;
-	}
+	ECalClient *cal_client;
 
-	g_idle_add (test_sync_in_idle, user_data);
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
+	setup_cal (cal_client);
 
-	return NULL;
+	e_cal_client_get_object_list (cal_client, EVENT_QUERY, NULL, async_get_object_list_result_ready, fixture->loop);
+	g_main_loop_run (fixture->loop);
 }
 
 gint
 main (gint argc,
       gchar **argv)
 {
-	ECalClient *cal_client;
-	GError *error = NULL;
-	icalcomponent *icalcomp;
-	struct icaltimetype now;
-	gchar *uid = NULL;
-
-	main_initialize ();
-
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
-	icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
-	icalcomponent_set_summary (icalcomp, EVENT_SUMMARY);
-	icalcomponent_set_dtstart (icalcomp, now);
-	icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
-
-	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error)) {
-		report_error ("create object sync", &error);
-		g_object_unref (cal_client);
-		icalcomponent_free (icalcomp);
-		return 1;
-	}
-
-	icalcomponent_free (icalcomp);
-	g_free (uid);
-
-	/* synchronously without main-loop */
-	if (!test_sync (cal_client)) {
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	start_in_thread_with_main_loop (test_sync_in_thread, cal_client);
-
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	g_object_unref (cal_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 ("/ECalClient/GetObjectList/Sync", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_get_object_list_sync, e_test_server_utils_teardown);
+	g_test_add ("/ECalClient/GetObjectList/Async", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_get_object_list_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libecal/client/test-client-get-revision.c b/tests/libecal/client/test-client-get-revision.c
index 4dab582..ef1e796 100644
--- a/tests/libecal/client/test-client-get-revision.c
+++ b/tests/libecal/client/test-client-get-revision.c
@@ -4,7 +4,10 @@
 #include <string.h>
 #include <libecal/libecal.h>
 
-#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure cal_closure =
+	{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
 
 #define CYCLES 10
 
@@ -48,40 +51,31 @@ get_revision_compare_cycle (ECalClient *client)
        icalcomponent_free (icalcomp);
 }
 
-gint
-main (gint argc,
-      gchar **argv)
+static void
+test_get_revision (ETestServerFixture *fixture,
+		   gconstpointer       user_data)
 {
 	ECalClient *cal_client;
-	GError      *error = NULL;
-	gint         i;
-
-	main_initialize ();
-
-	/*
-	 * Setup
-	 */
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
+	gint i;
 
-	g_return_val_if_fail (cal_client != NULL, 1);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
 	/* Test that modifications make the revisions increment */
 	for (i = 0; i < CYCLES; i++)
 		get_revision_compare_cycle (cal_client);
+}
 
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (cal_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 (cal_client);
+	g_test_add ("/ECalClient/GetRevision", ETestServerFixture, &cal_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/libecal/client/test-client-get-view.c b/tests/libecal/client/test-client-get-view.c
index 6d870e5..596cc4f 100644
--- a/tests/libecal/client/test-client-get-view.c
+++ b/tests/libecal/client/test-client-get-view.c
@@ -4,7 +4,10 @@
 #include <libecal/libecal.h>
 #include <libical/ical.h>
 
-#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure cal_closure =
+	{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
 
 typedef enum {
 	SUBTEST_OBJECTS_ADDED,
@@ -16,7 +19,8 @@ typedef enum {
 } SubTestId;
 
 static void
-subtest_passed (SubTestId id)
+subtest_passed (SubTestId id,
+		GMainLoop *loop)
 {
 	static guint subtests_complete = 0;
 
@@ -28,7 +32,7 @@ subtest_passed (SubTestId id)
 	subtests_complete |= (1 << id);
 
 	if (subtests_complete == ((1 << NUM_SUBTESTS) - 1))
-		stop_main_loop (0);
+		g_main_loop_quit (loop);
 }
 
 static void
@@ -36,12 +40,13 @@ objects_added_cb (GObject *object,
                   const GSList *objects,
                   gpointer data)
 {
+	GMainLoop *loop = (GMainLoop *)data;
 	const GSList *l;
 
 	for (l = objects; l; l = l->next)
 		g_print ("Object added %s (%s)\n", icalcomponent_get_uid (l->data), icalcomponent_get_summary (l->data));
 
-	subtest_passed (SUBTEST_OBJECTS_ADDED);
+	subtest_passed (SUBTEST_OBJECTS_ADDED, loop);
 }
 
 static void
@@ -49,12 +54,13 @@ objects_modified_cb (GObject *object,
                      const GSList *objects,
                      gpointer data)
 {
+	GMainLoop *loop = (GMainLoop *)data;
 	const GSList *l;
 
 	for (l = objects; l; l = l->next)
 		g_print ("Object modified %s (%s)\n", icalcomponent_get_uid (l->data), icalcomponent_get_summary (l->data));
 
-	subtest_passed (SUBTEST_OBJECTS_MODIFIED);
+	subtest_passed (SUBTEST_OBJECTS_MODIFIED, loop);
 }
 
 static void
@@ -62,6 +68,7 @@ objects_removed_cb (GObject *object,
                     const GSList *objects,
                     gpointer data)
 {
+	GMainLoop *loop = (GMainLoop *)data;
 	const GSList *l;
 
 	for (l = objects; l; l = l->next) {
@@ -70,7 +77,7 @@ objects_removed_cb (GObject *object,
 		g_print ("Object removed: uid: %s, rid: %s\n", id->uid, id->rid);
 	}
 
-	subtest_passed (SUBTEST_OBJECTS_REMOVED);
+	subtest_passed (SUBTEST_OBJECTS_REMOVED, loop);
 }
 
 static void
@@ -78,9 +85,11 @@ complete_cb (GObject *object,
              const GError *error,
              gpointer data)
 {
+	GMainLoop *loop = (GMainLoop *)data;
+
 	g_print ("View complete (status: %d, error_msg:%s)\n", error ? error->code : 0, error ? error->message : "NULL");
 
-	subtest_passed (SUBTEST_VIEW_DONE);
+	subtest_passed (SUBTEST_VIEW_DONE, loop);
 }
 
 static gpointer
@@ -100,36 +109,22 @@ alter_cal_client (gpointer user_data)
 	icalcomponent_set_dtstart (icalcomp, now);
 	icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
 
-	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error)) {
-		report_error ("create object sync", &error);
-		icalcomponent_free (icalcomp);
-		stop_main_loop (1);
-		return NULL;
-	}
+	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error))
+		g_error ("create object sync: %s", error->message);
 
 	icalcomponent_set_uid (icalcomp, uid);
 	icalcomponent_set_summary (icalcomp, "Modified event summary");
 
-	if (!e_cal_client_modify_object_sync (cal_client, icalcomp, CALOBJ_MOD_ALL, NULL, &error)) {
-		report_error ("modify object sync", &error);
-		icalcomponent_free (icalcomp);
-		g_free (uid);
-		stop_main_loop (1);
-		return NULL;
-	}
+	if (!e_cal_client_modify_object_sync (cal_client, icalcomp, CALOBJ_MOD_ALL, NULL, &error))
+		g_error ("modify object sync: %s", error->message);
 
-	if (!e_cal_client_remove_object_sync (cal_client, uid, NULL, CALOBJ_MOD_ALL, NULL, &error)) {
-		report_error ("remove object sync", &error);
-		icalcomponent_free (icalcomp);
-		g_free (uid);
-		stop_main_loop (1);
-		return NULL;
-	}
+	if (!e_cal_client_remove_object_sync (cal_client, uid, NULL, CALOBJ_MOD_ALL, NULL, &error))
+		g_error ("remove object sync: %s", error->message);
 
 	g_free (uid);
 	icalcomponent_free (icalcomp);
 
-	return NULL;
+	return FALSE;
 }
 
 static void
@@ -140,102 +135,84 @@ async_get_view_ready (GObject *source_object,
 	ECalClient *cal_client = E_CAL_CLIENT (source_object);
 	ECalClientView *view = NULL;
 	GError *error = NULL;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
 	g_return_if_fail (cal_client != NULL);
 
-	if (!e_cal_client_get_view_finish (cal_client, result, &view, &error)) {
-		report_error ("get view finish", &error);
-		stop_main_loop (1);
-		return;
-	}
-
-	subtest_passed (SUBTEST_RESET);
-	g_signal_connect (view, "objects_added", G_CALLBACK (objects_added_cb), cal_client);
-	g_signal_connect (view, "objects_modified", G_CALLBACK (objects_modified_cb), cal_client);
-	g_signal_connect (view, "objects_removed", G_CALLBACK (objects_removed_cb), cal_client);
-	g_signal_connect (view, "complete", G_CALLBACK (complete_cb), cal_client);
+	if (!e_cal_client_get_view_finish (cal_client, result, &view, &error))
+		g_error ("get view finish: %s", error->message);
 
 	g_object_set_data_full (G_OBJECT (cal_client), "cal-view", view, g_object_unref);
 
+	subtest_passed (SUBTEST_RESET, loop);
+	g_signal_connect (view, "objects_added", G_CALLBACK (objects_added_cb), loop);
+	g_signal_connect (view, "objects_modified", G_CALLBACK (objects_modified_cb), loop);
+	g_signal_connect (view, "objects_removed", G_CALLBACK (objects_removed_cb), loop);
+	g_signal_connect (view, "complete", G_CALLBACK (complete_cb), loop);
+
 	e_cal_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_cal_client_view_start (view, NULL);
 
 	alter_cal_client (cal_client);
 }
 
-static gpointer
-get_view_async (gpointer user_data)
+static void
+test_get_view_async (ETestServerFixture *fixture,
+		     gconstpointer       user_data)
 {
-	ECalClient *cal_client = user_data;
-
-	g_return_val_if_fail (user_data != NULL, NULL);
+	ECalClient *cal_client;
 
-	e_cal_client_get_view (cal_client, "(contains? \"any\" \"event\")", NULL, async_get_view_ready, NULL);
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
-	return NULL;
+	e_cal_client_get_view (cal_client, "(contains? \"any\" \"event\")", NULL, async_get_view_ready, fixture->loop);
+	g_main_loop_run (fixture->loop);
 }
 
-gint
-main (gint argc,
-      gchar **argv)
+static void
+test_get_view_sync (ETestServerFixture *fixture,
+		    gconstpointer       user_data)
 {
-	ECalClientView *view = NULL;
 	ECalClient *cal_client;
 	GError *error = NULL;
+	ECalClientView *view = NULL;
 
-	main_initialize ();
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
+	if (!e_cal_client_get_view_sync (cal_client, "(contains? \"any\" \"event\")", &view, NULL, &error))
+		g_error ("get view sync: %s", error->message);
 
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	if (!e_cal_client_get_view_sync (cal_client, "(contains? \"any\" \"event\")", &view, NULL, &error)) {
-		report_error ("get view sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	subtest_passed (SUBTEST_RESET);
-	g_signal_connect (view, "objects_added", G_CALLBACK (objects_added_cb), cal_client);
-	g_signal_connect (view, "objects_modified", G_CALLBACK (objects_modified_cb), cal_client);
-	g_signal_connect (view, "objects_removed", G_CALLBACK (objects_removed_cb), cal_client);
-	g_signal_connect (view, "complete", G_CALLBACK (complete_cb), cal_client);
+	subtest_passed (SUBTEST_RESET, fixture->loop);
+	g_signal_connect (view, "objects_added", G_CALLBACK (objects_added_cb), fixture->loop);
+	g_signal_connect (view, "objects_modified", G_CALLBACK (objects_modified_cb), fixture->loop);
+	g_signal_connect (view, "objects_removed", G_CALLBACK (objects_removed_cb), fixture->loop);
+	g_signal_connect (view, "complete", G_CALLBACK (complete_cb), NULL);
 
 	e_cal_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_cal_client_view_start (view, NULL);
 
-	start_in_thread_with_main_loop (alter_cal_client, cal_client);
+	g_idle_add ((GSourceFunc)alter_cal_client, cal_client);
+	g_main_loop_run (fixture->loop);
 
 	g_object_unref (view);
+}
 
-	if (get_main_loop_stop_result () != 0) {
-		g_object_unref (cal_client);
-		return get_main_loop_stop_result ();
-	}
-
-	start_in_idle_with_main_loop (get_view_async, cal_client);
-
-	g_object_set_data (G_OBJECT (cal_client), "cal-view", NULL);
-
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	g_object_unref (cal_client);
+gint
+main (gint argc,
+      gchar **argv)
+{
+#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 ("/ECalClient/GetView/Sync", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_get_view_sync, e_test_server_utils_teardown);
+	g_test_add ("/ECalClient/GetView/Async", ETestServerFixture, &cal_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/libecal/client/test-client-modify-object.c b/tests/libecal/client/test-client-modify-object.c
index 5305364..7eb2ff0 100644
--- a/tests/libecal/client/test-client-modify-object.c
+++ b/tests/libecal/client/test-client-modify-object.c
@@ -4,59 +4,73 @@
 #include <libecal/libecal.h>
 #include <libical/ical.h>
 
-#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure cal_closure =
+	{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
 
 #define EVENT_SUMMARY "Creation of new test event"
 
-static gboolean
-test_result (icalcomponent *icalcomp)
+static void
+setup_cal (ECalClient *cal_client)
 {
-	g_return_val_if_fail (icalcomp != NULL, FALSE);
-	g_return_val_if_fail (g_strcmp0 (icalcomponent_get_summary (icalcomp), EVENT_SUMMARY) == 0, FALSE);
+	struct icaltimetype now;
+	icalcomponent *icalcomp;
+	gchar *uid = NULL;
+	GError *error = NULL;
 
-	return TRUE;
+	now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
+	icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
+	icalcomponent_set_summary (icalcomp, "Initial" EVENT_SUMMARY);
+	icalcomponent_set_dtstart (icalcomp, now);
+	icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
+
+	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error))
+		g_error ("create object sync: %s", error->message);
+
+	icalcomponent_free (icalcomp);
+	g_object_set_data_full (G_OBJECT (cal_client), "use-uid", uid, g_free);
 }
 
-static gboolean
-test_sync (ECalClient *cal_client)
+static void
+test_result (icalcomponent *icalcomp)
+{
+	g_assert (icalcomp != NULL);
+	g_assert_cmpstr (icalcomponent_get_summary (icalcomp), ==, EVENT_SUMMARY);
+}
+
+static void
+test_modify_object_sync (ETestServerFixture *fixture,
+			 gconstpointer       user_data)
 {
+	ECalClient *cal_client;
 	GError *error = NULL;
 	icalcomponent *icalcomp = NULL;
-	const gchar *uid = g_object_get_data (G_OBJECT (cal_client), "use-uid");
+	const gchar *uid;
+
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
-	g_return_val_if_fail (uid != NULL, FALSE);
+	setup_cal (cal_client);
+	uid = g_object_get_data (G_OBJECT (cal_client), "use-uid");
+	g_assert (uid != NULL);
 
-	if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp, NULL, &error)) {
-		report_error ("get object sync", &error);
-		return FALSE;
-	}
+	if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp, NULL, &error))
+		g_error ("get object sync: %s", error->message);
 
 	icalcomponent_set_summary (icalcomp, EVENT_SUMMARY);
 
-	if (!e_cal_client_modify_object_sync (cal_client, icalcomp, CALOBJ_MOD_ALL, NULL, &error)) {
-		report_error ("modify object sync", &error);
-		icalcomponent_free (icalcomp);
-		return FALSE;
-	}
+	if (!e_cal_client_modify_object_sync (cal_client, icalcomp, CALOBJ_MOD_ALL, NULL, &error))
+		g_error ("modify object sync: %s", error->message);
 
 	icalcomponent_free (icalcomp);
 
-	if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp, NULL, &error)) {
-		report_error ("get object sync after modification", &error);
-		return FALSE;
-	}
-
-	if (!test_result (icalcomp)) {
-		icalcomponent_free (icalcomp);
-		return FALSE;
-	}
+	if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp, NULL, &error))
+		g_error ("get object sync after modification: %s", error->message);
 
+	test_result (icalcomp);
 	icalcomponent_free (icalcomp);
-
-	return TRUE;
 }
 
-/* asynchronous callback with a main-loop running */
 static void
 async_modify_result_ready (GObject *source_object,
                            GAsyncResult *result,
@@ -66,132 +80,62 @@ async_modify_result_ready (GObject *source_object,
 	GError *error = NULL;
 	icalcomponent *icalcomp = NULL;
 	const gchar *uid;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
 	cal_client = E_CAL_CLIENT (source_object);
 	uid = g_object_get_data (G_OBJECT (cal_client), "use-uid");
 
-	if (!e_cal_client_modify_object_finish (cal_client, result, &error)) {
-		report_error ("modify object finish", &error);
-		stop_main_loop (1);
-		return;
-	}
-
-	if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp, NULL, &error)) {
-		report_error ("get object sync after async modification", &error);
-		return;
-	}
+	if (!e_cal_client_modify_object_finish (cal_client, result, &error))
+		g_error ("modify object finish: %s", error->message);
 
-	if (!test_result (icalcomp)) {
-		stop_main_loop (1);
-	} else {
-		stop_main_loop (0);
-	}
+	if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp, NULL, &error))
+		g_error ("get object sync after async modification: %s", error->message);
 
+	test_result (icalcomp);
 	icalcomponent_free (icalcomp);
+
+	g_main_loop_quit (loop);
 }
 
-/* synchronously in idle with main-loop running */
-static gboolean
-test_sync_in_idle (gpointer user_data)
+static void
+test_modify_object_async (ETestServerFixture *fixture,
+			  gconstpointer       user_data)
 {
-	ECalClient *cal_client = user_data;
-	const gchar *uid = g_object_get_data (G_OBJECT (cal_client), "use-uid");
-	icalcomponent *icalcomp = NULL;
+	ECalClient *cal_client;
 	GError *error = NULL;
+	icalcomponent *icalcomp = NULL;
+	const gchar *uid;
 
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-	g_return_val_if_fail (E_IS_CAL_CLIENT (cal_client), FALSE);
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
-	if (!test_sync (cal_client)) {
-		stop_main_loop (1);
-		return FALSE;
-	}
+	setup_cal (cal_client);
+	uid = g_object_get_data (G_OBJECT (cal_client), "use-uid");
+	g_assert (uid != NULL);
 
-	if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp, NULL, &error)) {
-		report_error ("get object sync", &error);
-		stop_main_loop (1);
-		return FALSE;
-	}
+	if (!e_cal_client_get_object_sync (cal_client, uid, NULL, &icalcomp, NULL, &error))
+		g_error ("get object sync: %s", error->message);
 
 	icalcomponent_set_summary (icalcomp, EVENT_SUMMARY);
 
-	e_cal_client_modify_object (cal_client, icalcomp, CALOBJ_MOD_ALL, NULL, async_modify_result_ready, NULL);
-
+	e_cal_client_modify_object (cal_client, icalcomp, CALOBJ_MOD_ALL, NULL, async_modify_result_ready, fixture->loop);
 	icalcomponent_free (icalcomp);
 
-	return FALSE;
-}
-
-/* synchronously in a dedicated thread with main-loop running */
-static gpointer
-test_sync_in_thread (gpointer user_data)
-{
-	if (!test_sync (user_data)) {
-		stop_main_loop (1);
-		return NULL;
-	}
-
-	g_idle_add (test_sync_in_idle, user_data);
-
-	return NULL;
+	g_main_loop_run (fixture->loop);
 }
 
 gint
 main (gint argc,
       gchar **argv)
 {
-	ECalClient *cal_client;
-	GError *error = NULL;
-	icalcomponent *icalcomp;
-	struct icaltimetype now;
-	gchar *uid = NULL;
-
-	main_initialize ();
-
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
-	icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
-	icalcomponent_set_summary (icalcomp, "Initial" EVENT_SUMMARY);
-	icalcomponent_set_dtstart (icalcomp, now);
-	icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
-
-	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error)) {
-		report_error ("create object sync", &error);
-		g_object_unref (cal_client);
-		icalcomponent_free (icalcomp);
-		return 1;
-	}
-
-	icalcomponent_free (icalcomp);
-
-	g_object_set_data_full (G_OBJECT (cal_client), "use-uid", uid, g_free);
-
-	/* synchronously without main-loop */
-	if (!test_sync (cal_client)) {
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	start_in_thread_with_main_loop (test_sync_in_thread, cal_client);
-
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	g_object_unref (cal_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 ("/ECalClient/ModifyObject/Sync", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_modify_object_sync, e_test_server_utils_teardown);
+	g_test_add ("/ECalClient/ModifyObject/Async", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_modify_object_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libecal/client/test-client-receive-objects.c b/tests/libecal/client/test-client-receive-objects.c
index 7c49f36..6aaea97 100644
--- a/tests/libecal/client/test-client-receive-objects.c
+++ b/tests/libecal/client/test-client-receive-objects.c
@@ -4,7 +4,10 @@
 #include <libecal/libecal.h>
 #include <libical/ical.h>
 
-#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure cal_closure =
+	{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
 
 static icalcomponent *
 create_object (void)
@@ -21,28 +24,25 @@ create_object (void)
 	return icalcomp;
 }
 
-static gboolean
-test_sync (ECalClient *cal_client)
+static void
+test_receive_objects_sync (ETestServerFixture *fixture,
+			   gconstpointer       user_data)
 {
+	ECalClient *cal_client;
 	GError *error = NULL;
 	icalcomponent *icalcomp;
 
-	icalcomp = create_object ();
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
-	g_return_val_if_fail (icalcomp != NULL, FALSE);
+	icalcomp = create_object ();
+	g_assert (icalcomp != NULL);
 
-	if (!e_cal_client_receive_objects_sync (cal_client, icalcomp, NULL, &error)) {
-		report_error ("receive objects sync", &error);
-		icalcomponent_free (icalcomp);
-		return FALSE;
-	}
+	if (!e_cal_client_receive_objects_sync (cal_client, icalcomp, NULL, &error))
+		g_error ("receive objects sync: %s", error->message);
 
 	icalcomponent_free (icalcomp);
-
-	return TRUE;
 }
 
-/* asynchronous callback with a main-loop running */
 static void
 async_receive_result_ready (GObject *source_object,
                             GAsyncResult *result,
@@ -50,96 +50,47 @@ async_receive_result_ready (GObject *source_object,
 {
 	ECalClient *cal_client;
 	GError *error = NULL;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
 	cal_client = E_CAL_CLIENT (source_object);
 
-	if (!e_cal_client_receive_objects_finish (cal_client, result, &error)) {
-		report_error ("receive objects finish", &error);
-		stop_main_loop (1);
-		return;
-	}
+	if (!e_cal_client_receive_objects_finish (cal_client, result, &error))
+		g_error ("receive objects finish: %s", error->message);
 
-	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_receive_objects_async (ETestServerFixture *fixture,
+			    gconstpointer       user_data)
 {
-	ECalClient *cal_client = user_data;
+	ECalClient *cal_client;
 	icalcomponent *icalcomp;
 
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-	g_return_val_if_fail (E_IS_CAL_CLIENT (cal_client), FALSE);
-
-	if (!test_sync (cal_client)) {
-		stop_main_loop (1);
-		return FALSE;
-	}
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
 	icalcomp = create_object ();
-	if (!icalcomp) {
-		stop_main_loop (1);
-		return FALSE;
-	}
-
-	e_cal_client_receive_objects (cal_client, icalcomp, NULL, async_receive_result_ready, NULL);
+	g_assert (icalcomp != NULL);
 
+	e_cal_client_receive_objects (cal_client, icalcomp, NULL, async_receive_result_ready, fixture->loop);
 	icalcomponent_free (icalcomp);
 
-	return FALSE;
-}
-
-/* synchronously in a dedicated thread with main-loop running */
-static gpointer
-test_sync_in_thread (gpointer user_data)
-{
-	if (!test_sync (user_data)) {
-		stop_main_loop (1);
-		return NULL;
-	}
-
-	g_idle_add (test_sync_in_idle, user_data);
-
-	return NULL;
+	g_main_loop_run (fixture->loop);
 }
 
 gint
 main (gint argc,
       gchar **argv)
 {
-	ECalClient *cal_client;
-	GError *error = NULL;
-
-	main_initialize ();
-
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	/* synchronously without main-loop */
-	if (!test_sync (cal_client)) {
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	start_in_thread_with_main_loop (test_sync_in_thread, cal_client);
-
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	g_object_unref (cal_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 ("/ECalClient/ReceiveObjects/Sync", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_receive_objects_sync, e_test_server_utils_teardown);
+	g_test_add ("/ECalClient/ReceiveObjects/Async", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_receive_objects_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libecal/client/test-client-refresh.c b/tests/libecal/client/test-client-refresh.c
index 0c8b24b..3586822 100644
--- a/tests/libecal/client/test-client-refresh.c
+++ b/tests/libecal/client/test-client-refresh.c
@@ -6,132 +6,95 @@
 #include <libical/ical.h>
 
 #include "client-test-utils.h"
+#include "e-test-server-utils.h"
 
-static gboolean
-test_sync (ECalClient *cal_client)
+static ETestServerClosure cal_closure =
+	{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
+
+
+static void
+setup_cal (ECalClient *cal_client)
 {
 	GError *error = NULL;
+	icalcomponent *icalcomp;
+	struct icaltimetype now;
+	gchar *uid = NULL;
 
-	g_print ("Refresh supported: %s\n", e_client_check_refresh_supported (E_CLIENT (cal_client)) ? "yes" : "no");
+	now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
+	icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
+	icalcomponent_set_summary (icalcomp, "Test event summary");
+	icalcomponent_set_dtstart (icalcomp, now);
+	icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
 
-	if (!e_client_refresh_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("refresh sync", &error);
-		return FALSE;
-	}
+	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error))
+		g_error ("create object sync: %s", error->message);
 
-	return TRUE;
+	icalcomponent_free (icalcomp);
+	g_free (uid);
 }
 
-/* asynchronous callback with a main-loop running */
 static void
-async_refresh_result_ready (GObject *source_object,
-                            GAsyncResult *result,
-                            gpointer user_data)
+test_refresh_sync (ETestServerFixture *fixture,
+		   gconstpointer       user_data)
 {
-	ECalClient *cal_client;
+	ECalClient *cal;
 	GError *error = NULL;
 
-	cal_client = E_CAL_CLIENT (source_object);
+	cal = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
-	if (!e_client_refresh_finish (E_CLIENT (cal_client), result, &error)) {
-		report_error ("refresh finish", &error);
-		stop_main_loop (1);
-		return;
-	}
+	setup_cal (cal);
 
-	stop_main_loop (0);
+	g_print ("Refresh supported: %s\n", e_client_check_refresh_supported (E_CLIENT (cal)) ? "yes" : "no");
+
+	if (!e_client_refresh_sync (E_CLIENT (cal), NULL, &error))
+		g_error ("refresh sync: %s", error->message);
 }
 
-/* synchronously in idle with main-loop running */
-static gboolean
-test_sync_in_idle (gpointer user_data)
+static void
+async_refresh_result_ready (GObject *source_object,
+                            GAsyncResult *result,
+                            gpointer user_data)
 {
-	ECalClient *cal_client = user_data;
-
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-	g_return_val_if_fail (E_IS_CAL_CLIENT (cal_client), FALSE);
-
-	if (!test_sync (cal_client)) {
-		stop_main_loop (1);
-		return FALSE;
-	}
+	ECalClient *cal_client;
+	GError *error = NULL;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
-	g_print ("Refresh supported: %s\n", e_client_check_refresh_supported (E_CLIENT (cal_client)) ? "yes" : "no");
+	cal_client = E_CAL_CLIENT (source_object);
 
-	e_client_refresh (E_CLIENT (cal_client), NULL, async_refresh_result_ready, NULL);
+	if (!e_client_refresh_finish (E_CLIENT (cal_client), result, &error))
+		g_error ("refresh finish: %s", error->message);
 
-	return FALSE;
+	g_main_loop_quit (loop);
 }
 
-/* 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;
-	}
+	ECalClient *cal;
 
-	g_idle_add (test_sync_in_idle, user_data);
+	cal = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
-	return NULL;
+	setup_cal (cal);
+
+	e_client_refresh (E_CLIENT (cal), NULL, async_refresh_result_ready, fixture->loop);
+	g_main_loop_run (fixture->loop);
 }
 
 gint
 main (gint argc,
       gchar **argv)
 {
-	ECalClient *cal_client;
-	GError *error = NULL;
-	icalcomponent *icalcomp;
-	struct icaltimetype now;
-	gchar *uid = NULL;
-
-	main_initialize ();
-
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
-	icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
-	icalcomponent_set_summary (icalcomp, "Test event summary");
-	icalcomponent_set_dtstart (icalcomp, now);
-	icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+	g_type_init ();
+#endif
+	g_test_init (&argc, &argv, NULL);
 
-	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error)) {
-		report_error ("create object sync", &error);
-		icalcomponent_free (icalcomp);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	icalcomponent_free (icalcomp);
-	g_free (uid);
+	g_test_add ("/ECalClient/Refresh/Sync", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_refresh_sync, e_test_server_utils_teardown);
+	g_test_add ("/ECalClient/Refresh/Async", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_refresh_async, e_test_server_utils_teardown);
 
-	/* synchronously without main-loop */
-	if (!test_sync (cal_client)) {
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	start_in_thread_with_main_loop (test_sync_in_thread, cal_client);
-
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	g_object_unref (cal_client);
-
-	if (get_main_loop_stop_result () == 0)
-		g_print ("Test finished successfully.\n");
-
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
+
diff --git a/tests/libecal/client/test-client-remove-object.c b/tests/libecal/client/test-client-remove-object.c
index 7333ff5..1f389b4 100644
--- a/tests/libecal/client/test-client-remove-object.c
+++ b/tests/libecal/client/test-client-remove-object.c
@@ -4,7 +4,10 @@
 #include <libecal/libecal.h>
 #include <libical/ical.h>
 
-#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure cal_closure =
+	{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
 
 static gchar *
 create_object (ECalClient *cal_client)
@@ -22,138 +25,80 @@ create_object (ECalClient *cal_client)
 	icalcomponent_set_dtstart (icalcomp, now);
 	icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
 
-	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error)) {
-		report_error ("create object sync", &error);
-		icalcomponent_free (icalcomp);
-		return NULL;
-	}
+	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error))
+		g_error ("create object sync: %s", error->message);
 
 	icalcomponent_free (icalcomp);
 
-	g_return_val_if_fail (uid != NULL, NULL);
-
 	return uid;
 }
 
-static gboolean
-test_sync (ECalClient *cal_client)
+static void
+test_remove_object_sync (ETestServerFixture *fixture,
+			 gconstpointer       user_data)
 {
+	ECalClient *cal_client;
 	GError *error = NULL;
 	gchar *uid;
 
-	uid = create_object (cal_client);
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
-	g_return_val_if_fail (uid != NULL, FALSE);
+	uid = create_object (cal_client);
+	g_assert (uid != NULL);
 
-	if (!e_cal_client_remove_object_sync (cal_client, uid, NULL, CALOBJ_MOD_ALL, NULL, &error)) {
-		report_error ("remove object sync", &error);
-		g_free (uid);
-		return FALSE;
-	}
+	if (!e_cal_client_remove_object_sync (cal_client, uid, NULL, CALOBJ_MOD_ALL, NULL, &error))
+		g_error ("remove object sync: %s", error->message);
 
 	g_free (uid);
-
-	return TRUE;
 }
 
-/* asynchronous callback with a main-loop running */
 static void
 async_remove_result_ready (GObject *source_object,
                            GAsyncResult *result,
                            gpointer user_data)
 {
 	ECalClient *cal_client;
+	GMainLoop *loop = (GMainLoop *)user_data;
 	GError *error = NULL;
 
 	cal_client = E_CAL_CLIENT (source_object);
 
-	if (!e_cal_client_remove_object_finish (cal_client, result, &error)) {
-		report_error ("remove object finish", &error);
-		stop_main_loop (1);
-		return;
-	}
+	if (!e_cal_client_remove_object_finish (cal_client, result, &error))
+		g_error ("remove object finish: %s", error->message);
 
-	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_remove_object_async (ETestServerFixture *fixture,
+			  gconstpointer       user_data)
 {
-	ECalClient *cal_client = user_data;
+	ECalClient *cal_client;
 	gchar *uid;
 
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-	g_return_val_if_fail (E_IS_CAL_CLIENT (cal_client), FALSE);
-
-	if (!test_sync (cal_client)) {
-		stop_main_loop (1);
-		return FALSE;
-	}
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
 	uid = create_object (cal_client);
-	if (!uid) {
-		stop_main_loop (1);
-		return FALSE;
-	}
-
-	e_cal_client_remove_object (cal_client, uid, NULL, CALOBJ_MOD_ALL, NULL, async_remove_result_ready, NULL);
+	g_assert (uid != NULL);
 
+	e_cal_client_remove_object (cal_client, uid, NULL, CALOBJ_MOD_ALL, NULL, async_remove_result_ready, fixture->loop);
 	g_free (uid);
-
-	return FALSE;
-}
-
-/* synchronously in a dedicated thread with main-loop running */
-static gpointer
-test_sync_in_thread (gpointer user_data)
-{
-	if (!test_sync (user_data)) {
-		stop_main_loop (1);
-		return NULL;
-	}
-
-	g_idle_add (test_sync_in_idle, user_data);
-
-	return NULL;
+	g_main_loop_run (fixture->loop);
 }
 
 gint
 main (gint argc,
       gchar **argv)
 {
-	ECalClient *cal_client;
-	GError *error = NULL;
-
-	main_initialize ();
-
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	/* synchronously without main-loop */
-	if (!test_sync (cal_client)) {
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	start_in_thread_with_main_loop (test_sync_in_thread, cal_client);
-
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	g_object_unref (cal_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 ("/ECalClient/RemoveObject/Sync", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_remove_object_sync, e_test_server_utils_teardown);
+	g_test_add ("/ECalClient/RemoveObject/Async", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_remove_object_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libecal/client/test-client-revision-view.c b/tests/libecal/client/test-client-revision-view.c
index 50a443a..2851f59 100644
--- a/tests/libecal/client/test-client-revision-view.c
+++ b/tests/libecal/client/test-client-revision-view.c
@@ -4,7 +4,10 @@
 #include <libecal/libecal.h>
 #include <libical/ical.h>
 
-#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure cal_closure =
+	{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
 
 typedef enum {
 	SUBTEST_OBJECTS_ADDED,
@@ -16,7 +19,8 @@ typedef enum {
 } SubTestId;
 
 static void
-subtest_passed (SubTestId id)
+subtest_passed (SubTestId id,
+		GMainLoop *loop)
 {
 	static guint subtests_complete = 0;
 
@@ -28,22 +32,22 @@ subtest_passed (SubTestId id)
 	subtests_complete |= (1 << id);
 
 	if (subtests_complete == ((1 << NUM_SUBTESTS) - 1))
-		stop_main_loop (0);
+		g_main_loop_quit (loop);
 }
 
 static struct icaltimetype
 get_last_modified (icalcomponent *component)
 {
-    icalcomponent *inner = icalcomponent_get_inner (component);
-    icalproperty  *prop;
+	icalcomponent *inner = icalcomponent_get_inner (component);
+	icalproperty  *prop;
 
-    prop = icalcomponent_get_first_property (inner, ICAL_LASTMODIFIED_PROPERTY);
+	prop = icalcomponent_get_first_property (inner, ICAL_LASTMODIFIED_PROPERTY);
 
-    if (prop == 0) {
-	return icaltime_null_time ();
-    }
+	if (prop == 0) {
+		return icaltime_null_time ();
+	}
 
-    return icalproperty_get_lastmodified (prop);
+	return icalproperty_get_lastmodified (prop);
 }
 
 static void
@@ -52,6 +56,7 @@ objects_added_cb (GObject *object,
                   gpointer data)
 {
 	const GSList *l;
+	GMainLoop *loop = (GMainLoop *)data;
 
 	for (l = objects; l; l = l->next) {
 		icalcomponent      *component     = l->data;
@@ -67,7 +72,7 @@ objects_added_cb (GObject *object,
 		g_assert (icalcomponent_get_summary (component) == NULL);
 	}
 
-	subtest_passed (SUBTEST_OBJECTS_ADDED);
+	subtest_passed (SUBTEST_OBJECTS_ADDED, loop);
 }
 
 static void
@@ -76,6 +81,7 @@ objects_modified_cb (GObject *object,
                      gpointer data)
 {
 	const GSList *l;
+	GMainLoop *loop = (GMainLoop *)data;
 
 	for (l = objects; l; l = l->next) {
 		icalcomponent      *component     = l->data;
@@ -91,7 +97,7 @@ objects_modified_cb (GObject *object,
 		g_assert (icalcomponent_get_summary (component) == NULL);
 	}
 
-	subtest_passed (SUBTEST_OBJECTS_MODIFIED);
+	subtest_passed (SUBTEST_OBJECTS_MODIFIED, loop);
 }
 
 static void
@@ -99,6 +105,7 @@ objects_removed_cb (GObject *object,
                     const GSList *objects,
                     gpointer data)
 {
+	GMainLoop *loop = (GMainLoop *)data;
 	const GSList *l;
 
 	for (l = objects; l; l = l->next) {
@@ -107,7 +114,7 @@ objects_removed_cb (GObject *object,
 		g_print ("Object removed: uid: %s, rid: %s\n", id->uid, id->rid);
 	}
 
-	subtest_passed (SUBTEST_OBJECTS_REMOVED);
+	subtest_passed (SUBTEST_OBJECTS_REMOVED, loop);
 }
 
 static void
@@ -115,9 +122,11 @@ complete_cb (GObject *object,
              const GError *error,
              gpointer data)
 {
+	GMainLoop *loop = (GMainLoop *)data;
+
 	g_print ("View complete (status: %d, error_msg:%s)\n", error ? error->code : 0, error ? error->message : "NULL");
 
-	subtest_passed (SUBTEST_VIEW_DONE);
+	subtest_passed (SUBTEST_VIEW_DONE, loop);
 }
 
 static gpointer
@@ -137,39 +146,22 @@ alter_cal_client (gpointer user_data)
 	icalcomponent_set_dtstart (icalcomp, now);
 	icalcomponent_set_dtend   (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
 
-	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error)) {
-		report_error ("create object sync", &error);
-		icalcomponent_free (icalcomp);
-		stop_main_loop (1);
-		return NULL;
-	}
+	if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error))
+		g_error ("create object sync: %s", error->message);
 
 	icalcomponent_set_uid (icalcomp, uid);
-	icalcomponent_set_recurrenceid (
-		icalcomp,
-					icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0));
 	icalcomponent_set_summary (icalcomp, "Modified event summary");
 
-	if (!e_cal_client_modify_object_sync (cal_client, icalcomp, CALOBJ_MOD_ALL, NULL, &error)) {
-		report_error ("modify object sync", &error);
-		icalcomponent_free (icalcomp);
-		g_free (uid);
-		stop_main_loop (1);
-		return NULL;
-	}
+	if (!e_cal_client_modify_object_sync (cal_client, icalcomp, CALOBJ_MOD_ALL, NULL, &error))
+		g_error ("modify object sync: %s", error->message);
 
-	if (!e_cal_client_remove_object_sync (cal_client, uid, NULL, CALOBJ_MOD_ALL, NULL, &error)) {
-		report_error ("remove object sync", &error);
-		icalcomponent_free (icalcomp);
-		g_free (uid);
-		stop_main_loop (1);
-		return NULL;
-	}
+	if (!e_cal_client_remove_object_sync (cal_client, uid, NULL, CALOBJ_MOD_ALL, NULL, &error))
+		g_error ("remove object sync: %s", error->message);
 
 	g_free (uid);
 	icalcomponent_free (icalcomp);
 
-	return NULL;
+	return FALSE;
 }
 
 static void
@@ -180,81 +172,66 @@ async_get_view_ready (GObject *source_object,
 	ECalClient *cal_client = E_CAL_CLIENT (source_object);
 	ECalClientView *view = NULL;
 	GError *error = NULL;
+	GMainLoop *loop = (GMainLoop *)user_data;
 	GSList *field_list = NULL;
 
 	g_return_if_fail (cal_client != NULL);
 
-	if (!e_cal_client_get_view_finish (cal_client, result, &view, &error)) {
-		report_error ("get view finish", &error);
-		stop_main_loop (1);
-		return;
-	}
-
-	subtest_passed (SUBTEST_RESET);
-	g_signal_connect (view, "objects_added", G_CALLBACK (objects_added_cb), cal_client);
-	g_signal_connect (view, "objects_modified", G_CALLBACK (objects_modified_cb), cal_client);
-	g_signal_connect (view, "objects_removed", G_CALLBACK (objects_removed_cb), cal_client);
-	g_signal_connect (view, "complete", G_CALLBACK (complete_cb), cal_client);
+	if (!e_cal_client_get_view_finish (cal_client, result, &view, &error))
+		g_error ("get view finish: %s", error->message);
 
 	g_object_set_data_full (G_OBJECT (cal_client), "cal-view", view, g_object_unref);
 
+	subtest_passed (SUBTEST_RESET, loop);
+	g_signal_connect (view, "objects_added", G_CALLBACK (objects_added_cb), loop);
+	g_signal_connect (view, "objects_modified", G_CALLBACK (objects_modified_cb), loop);
+	g_signal_connect (view, "objects_removed", G_CALLBACK (objects_removed_cb), loop);
+	g_signal_connect (view, "complete", G_CALLBACK (complete_cb), loop);
+
 	field_list = g_slist_prepend (NULL, (gpointer) "UID");
 	field_list = g_slist_prepend (field_list, (gpointer) "RECURRENCE-ID");
 	field_list = g_slist_prepend (field_list, (gpointer) "LAST-MODIFIED");
 
 	e_cal_client_view_set_fields_of_interest (view, field_list, &error);
 	if (error)
-		report_error ("set fields of interest", &error);
+		g_error ("set fields of interest: %s", error->message);
 	g_slist_free (field_list);
 
 	e_cal_client_view_start (view, NULL);
-
 	alter_cal_client (cal_client);
 }
 
-static gpointer
-get_view_async (gpointer user_data)
+static void
+test_get_revision_view_async (ETestServerFixture *fixture,
+			      gconstpointer       user_data)
 {
-	ECalClient *cal_client = user_data;
-
-	g_return_val_if_fail (user_data != NULL, NULL);
+	ECalClient *cal_client;
 
-	e_cal_client_get_view (cal_client, "(contains? \"any\" \"event\")", NULL, async_get_view_ready, NULL);
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
-	return NULL;
+	e_cal_client_get_view (cal_client, "(contains? \"any\" \"event\")", NULL, async_get_view_ready, fixture->loop);
+	g_main_loop_run (fixture->loop);
 }
 
-gint
-main (gint argc,
-      gchar **argv)
+static void
+test_get_revision_view_sync (ETestServerFixture *fixture,
+			     gconstpointer       user_data)
 {
-	ECalClientView *view = NULL;
 	ECalClient *cal_client;
 	GError *error = NULL;
+	ECalClientView *view = NULL;
 	GSList *field_list = NULL;
 
-	main_initialize ();
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
+	if (!e_cal_client_get_view_sync (cal_client, "(contains? \"any\" \"event\")", &view, NULL, &error))
+		g_error ("get view sync: %s", error->message);
 
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	if (!e_cal_client_get_view_sync (cal_client, "(contains? \"any\" \"event\")", &view, NULL, &error)) {
-		report_error ("get view sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	subtest_passed (SUBTEST_RESET);
-	g_signal_connect (view, "objects_added", G_CALLBACK (objects_added_cb), cal_client);
-	g_signal_connect (view, "objects_modified", G_CALLBACK (objects_modified_cb), cal_client);
-	g_signal_connect (view, "objects_removed", G_CALLBACK (objects_removed_cb), cal_client);
-	g_signal_connect (view, "complete", G_CALLBACK (complete_cb), cal_client);
+	subtest_passed (SUBTEST_RESET, fixture->loop);
+	g_signal_connect (view, "objects_added", G_CALLBACK (objects_added_cb), fixture->loop);
+	g_signal_connect (view, "objects_modified", G_CALLBACK (objects_modified_cb), fixture->loop);
+	g_signal_connect (view, "objects_removed", G_CALLBACK (objects_removed_cb), fixture->loop);
+	g_signal_connect (view, "complete", G_CALLBACK (complete_cb), NULL);
 
 	field_list = g_slist_prepend (NULL, (gpointer) "UID");
 	field_list = g_slist_prepend (field_list, (gpointer) "RECURRENCE-ID");
@@ -262,34 +239,30 @@ main (gint argc,
 
 	e_cal_client_view_set_fields_of_interest (view, field_list, &error);
 	if (error)
-		report_error ("set fields of interest", &error);
+		g_error ("set fields of interest: %s", error->message);
 	g_slist_free (field_list);
 
 	e_cal_client_view_start (view, NULL);
 
-	start_in_thread_with_main_loop (alter_cal_client, cal_client);
+	g_idle_add ((GSourceFunc)alter_cal_client, cal_client);
+	g_main_loop_run (fixture->loop);
 
 	g_object_unref (view);
+}
 
-	if (get_main_loop_stop_result () != 0) {
-		g_object_unref (cal_client);
-		return get_main_loop_stop_result ();
-	}
-
-	start_in_idle_with_main_loop (get_view_async, cal_client);
-
-	g_object_set_data (G_OBJECT (cal_client), "cal-view", NULL);
-
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	g_object_unref (cal_client);
+gint
+main (gint argc,
+      gchar **argv)
+{
+#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 ("/ECalClient/GetRevisionView/Sync", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_get_revision_view_sync, e_test_server_utils_teardown);
+	g_test_add ("/ECalClient/GetRevisionView/Async", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_get_revision_view_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }
diff --git a/tests/libecal/client/test-client-send-objects.c b/tests/libecal/client/test-client-send-objects.c
index 4fbc83a..b50127a 100644
--- a/tests/libecal/client/test-client-send-objects.c
+++ b/tests/libecal/client/test-client-send-objects.c
@@ -4,7 +4,11 @@
 #include <libecal/libecal.h>
 #include <libical/ical.h>
 
-#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+#include "client-test-utils.h" /* For print_icomp() */
+
+static ETestServerClosure cal_closure =
+	{ E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
 
 static icalcomponent *
 create_object (void)
@@ -21,7 +25,7 @@ create_object (void)
 	return icalcomp;
 }
 
-static gboolean
+static void
 manage_result (GSList *users,
                icalcomponent *modified_icalcomp)
 {
@@ -44,31 +48,27 @@ manage_result (GSList *users,
 	e_client_util_free_string_slist (users);
 	if (modified_icalcomp)
 		icalcomponent_free (modified_icalcomp);
-
-	return TRUE;
 }
 
-static gboolean
-test_sync (ECalClient *cal_client)
+static void
+test_send_objects_sync (ETestServerFixture *fixture,
+			gconstpointer       user_data)
 {
+	ECalClient *cal_client;
 	GError *error = NULL;
 	icalcomponent *icalcomp, *modified_icalcomp = NULL;
 	GSList *users = NULL;
 
-	icalcomp = create_object ();
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
-	if (!e_cal_client_send_objects_sync (cal_client, icalcomp, &users, &modified_icalcomp, NULL, &error)) {
-		report_error ("send objects sync", &error);
-		icalcomponent_free (icalcomp);
-		return FALSE;
-	}
+	icalcomp = create_object ();
+	if (!e_cal_client_send_objects_sync (cal_client, icalcomp, &users, &modified_icalcomp, NULL, &error))
+		g_error ("send objects sync: %s", error->message);
 
 	icalcomponent_free (icalcomp);
-
-	return manage_result (users, modified_icalcomp);
+	manage_result (users, modified_icalcomp);
 }
 
-/* asynchronous callback with a main-loop running */
 static void
 async_send_result_ready (GObject *source_object,
                          GAsyncResult *result,
@@ -78,96 +78,48 @@ async_send_result_ready (GObject *source_object,
 	GError *error = NULL;
 	GSList *users = NULL;
 	icalcomponent *modified_icalcomp = NULL;
+	GMainLoop *loop = (GMainLoop *)user_data;
 
 	cal_client = E_CAL_CLIENT (source_object);
 
-	if (!e_cal_client_send_objects_finish (cal_client, result, &users, &modified_icalcomp, &error)) {
-		report_error ("send objects finish", &error);
-		stop_main_loop (1);
-		return;
-	}
+	if (!e_cal_client_send_objects_finish (cal_client, result, &users, &modified_icalcomp, &error))
+		g_error ("send objects finish: %s", error->message);
 
-	stop_main_loop (manage_result (users, modified_icalcomp) ? 0 : 1);
+	manage_result (users, modified_icalcomp);
+	g_main_loop_quit (loop);
 }
 
-/* synchronously in idle with main-loop running */
-static gboolean
-test_sync_in_idle (gpointer user_data)
+static void
+test_send_objects_async (ETestServerFixture *fixture,
+			gconstpointer       user_data)
 {
-	ECalClient *cal_client = user_data;
+	ECalClient *cal_client;
 	icalcomponent *icalcomp;
 
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-	g_return_val_if_fail (E_IS_CAL_CLIENT (cal_client), FALSE);
-
-	if (!test_sync (cal_client)) {
-		stop_main_loop (1);
-		return FALSE;
-	}
+	cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
 
 	icalcomp = create_object ();
-	if (!icalcomp) {
-		stop_main_loop (1);
-		return FALSE;
-	}
-
-	e_cal_client_send_objects (cal_client, icalcomp, NULL, async_send_result_ready, NULL);
+	g_assert (icalcomp);
 
+	e_cal_client_send_objects (cal_client, icalcomp, NULL, async_send_result_ready, fixture->loop);
 	icalcomponent_free (icalcomp);
 
-	return FALSE;
-}
-
-/* synchronously in a dedicated thread with main-loop running */
-static gpointer
-test_sync_in_thread (gpointer user_data)
-{
-	if (!test_sync (user_data)) {
-		stop_main_loop (1);
-		return NULL;
-	}
-
-	g_idle_add (test_sync_in_idle, user_data);
-
-	return NULL;
+	g_main_loop_run (fixture->loop);
 }
 
 gint
 main (gint argc,
       gchar **argv)
 {
-	ECalClient *cal_client;
-	GError *error = NULL;
-
-	main_initialize ();
-
-	cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
-	g_return_val_if_fail (cal_client != NULL, FALSE);
-
-	if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) {
-		report_error ("client open sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	/* synchronously without main-loop */
-	if (!test_sync (cal_client)) {
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	start_in_thread_with_main_loop (test_sync_in_thread, cal_client);
-
-	if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) {
-		report_error ("client remove sync", &error);
-		g_object_unref (cal_client);
-		return 1;
-	}
-
-	g_object_unref (cal_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 ("/ECalClient/SendObjects/Sync", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_send_objects_sync, e_test_server_utils_teardown);
+	g_test_add ("/ECalClient/SendObjects/Async", ETestServerFixture, &cal_closure,
+		    e_test_server_utils_setup, test_send_objects_async, e_test_server_utils_teardown);
 
-	return get_main_loop_stop_result ();
+	return e_test_server_utils_run ();
 }



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