[evolution-data-server/openismus-work-master: 16/18] Ported all tests in tests/ebook/client to use new test framework
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work-master: 16/18] Ported all tests in tests/ebook/client to use new test framework
- Date: Fri, 14 Dec 2012 08:13:01 +0000 (UTC)
commit 9ade426787d3e627625c3e0b1e5994b9c171bcb0
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Wed Dec 12 19:35:59 2012 +0900
Ported all tests in tests/ebook/client to use new test framework
'make check' now passes in ebook except for a few cases which geniunely fail.
tests/libebook/client/Makefile.am | 33 ++--
tests/libebook/client/test-client-add-contact.c | 100 +++-----
tests/libebook/client/test-client-async.c | 90 +++----
tests/libebook/client/test-client-custom-summary.c | 260 ++++++--------------
.../libebook/client/test-client-get-contact-uids.c | 118 +++++----
tests/libebook/client/test-client-get-contact.c | 97 ++++----
tests/libebook/client/test-client-get-revision.c | 46 ++--
tests/libebook/client/test-client-get-view.c | 147 +++++-------
tests/libebook/client/test-client-modify-contact.c | 166 ++++++-------
tests/libebook/client/test-client-photo-is-uri.c | 68 ++----
tests/libebook/client/test-client-refresh.c | 112 ++++------
.../client/test-client-remove-contact-by-uid.c | 159 +++++-------
tests/libebook/client/test-client-remove-contact.c | 159 +++++-------
.../libebook/client/test-client-remove-contacts.c | 158 +++++-------
tests/libebook/client/test-client-remove.c | 72 ------
tests/libebook/client/test-client-revision-view.c | 150 +++++-------
.../client/test-client-suppress-notifications.c | 156 +++++-------
tests/libebook/client/test-client-uid-only-view.c | 213 ++++++-----------
tests/libebook/client/test-client.c | 63 +++---
19 files changed, 933 insertions(+), 1434 deletions(-)
---
diff --git a/tests/libebook/client/Makefile.am b/tests/libebook/client/Makefile.am
index 2805bef..7845c18 100644
--- a/tests/libebook/client/Makefile.am
+++ b/tests/libebook/client/Makefile.am
@@ -8,6 +8,10 @@ libclient_test_utils_la_CPPFLAGS = \
-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_ADDRESSBOOK_CFLAGS) \
$(CAMEL_CFLAGS) \
@@ -16,14 +20,13 @@ libclient_test_utils_la_CPPFLAGS = \
libclient_test_utils_la_LIBADD = \
$(top_builddir)/addressbook/libebook-contacts/libebook-contacts-1.2.la \
$(top_builddir)/addressbook/libebook/libebook-1.2.la \
+ $(top_builddir)/tests/test-server-utils/libetestserverutils.la \
$(EVOLUTION_ADDRESSBOOK_LIBS) \
$(CAMEL_LIBS) \
$(NULL)
# Should be kept ordered approximately from least to most difficult/complex
TESTS = \
- test-client-remove \
- test-client-examine \
test-client-refresh \
test-client-add-contact \
test-client-get-contact \
@@ -39,20 +42,25 @@ TESTS = \
test-client-remove-contact-by-uid \
test-client-remove-contacts \
test-client-photo-is-uri \
- test-client-write-write \
- test-client-stress-factory--serial \
- test-client-stress-factory--fifo \
- test-client-stress-factory--single-book \
+ test-client-async \
$(NULL)
+# The noinst tests are functional tests, not unit tests.
+#
+# Either they were designed as functional tests or have
+# not been ported to use ETestServerFixture yet.
noinst_PROGRAMS = \
$(TESTS) \
+ test-client-write-write \
+ test-client-examine \
test-client \
- test-client-async \
test-client-nonexistent-id \
test-client-search \
test-client-self \
test-client-stress-views \
+ test-client-stress-factory--serial \
+ test-client-stress-factory--fifo \
+ test-client-stress-factory--single-book \
$(NULL)
TEST_CPPFLAGS = \
@@ -61,19 +69,12 @@ TEST_CPPFLAGS = \
$(NULL)
TEST_LIBS = \
- $(libclient_test_utils_la_LIBS) \
+ $(libclient_test_utils_la_LIBADD) \
libclient-test-utils.la \
$(top_builddir)/addressbook/libebook/libebook-1.2.la \
$(EVOLUTION_ADDRESSBOOK_LIBS) \
$(NULL)
-RUN_WITH_PRIVATE_BUS = $(top_srcdir)/tests/tools/with-session-bus-eds.sh
-
-TESTS_ENVIRONMENT = \
- $(RUN_WITH_PRIVATE_BUS) \
- --session \
- --
-
test_client_LDADD=$(TEST_LIBS)
test_client_CPPFLAGS=$(TEST_CPPFLAGS)
test_client_async_LDADD=$(TEST_LIBS)
@@ -102,8 +103,6 @@ test_client_modify_contact_LDADD=$(TEST_LIBS)
test_client_modify_contact_CPPFLAGS=$(TEST_CPPFLAGS)
test_client_refresh_LDADD=$(TEST_LIBS)
test_client_refresh_CPPFLAGS=$(TEST_CPPFLAGS)
-test_client_remove_LDADD=$(TEST_LIBS)
-test_client_remove_CPPFLAGS=$(TEST_CPPFLAGS)
test_client_remove_contact_LDADD=$(TEST_LIBS)
test_client_remove_contact_CPPFLAGS=$(TEST_CPPFLAGS)
test_client_remove_contact_by_uid_LDADD=$(TEST_LIBS)
diff --git a/tests/libebook/client/test-client-add-contact.c b/tests/libebook/client/test-client-add-contact.c
index fc784e2..1a07fbc 100644
--- a/tests/libebook/client/test-client-add-contact.c
+++ b/tests/libebook/client/test-client-add-contact.c
@@ -4,95 +4,77 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
+
+static void
+test_add_contact_sync (ETestServerFixture *fixture,
+ gconstpointer user_data)
+{
+ EBookClient *book_client;
+ EContact *contact;
+
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+ if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
+ g_error ("Failed to add contact sync");
+ }
+ g_object_unref (contact);
+}
static void
add_contact_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
+ GMainLoop *loop = (GMainLoop *)user_data;
GError *error = NULL;
gchar *uid;
if (!e_book_client_add_contact_finish (E_BOOK_CLIENT (source_object), result, &uid, &error)) {
- report_error ("add contact finish", &error);
- stop_main_loop (1);
- return;
+ g_error ("add contact finish: %s", error->message);
}
printf ("Contact added as '%s'\n", uid);
g_free (uid);
- stop_main_loop (0);
+ g_main_loop_quit (loop);
}
-gint
-main (gint argc,
- gchar **argv)
+static void
+test_add_contact_async (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
EBookClient *book_client;
- GError *error = NULL;
EContact *contact;
gchar *vcard;
- main_initialize ();
-
- /*
- * Setup
- */
- book_client = new_temp_client (NULL);
- g_return_val_if_fail (book_client != NULL, 1);
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
-
- /*
- * Sync version
- */
- if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
- g_object_unref (book_client);
- return 1;
- }
-
- g_object_unref (contact);
-
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
- return 1;
- }
-
- g_object_unref (book_client);
-
- /*
- * Async version
- */
- book_client = new_temp_client (NULL);
- g_return_val_if_fail (book_client != NULL, 1);
-
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
vcard = new_vcard_from_test_case ("simple-1");
contact = e_contact_new_from_vcard (vcard);
g_free (vcard);
- e_book_client_add_contact (book_client, contact, NULL, add_contact_cb, NULL);
+ e_book_client_add_contact (book_client, contact, NULL, add_contact_cb, fixture->loop);
g_object_unref (contact);
- start_main_loop (NULL, NULL);
+ g_main_loop_run (fixture->loop);
+}
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+gint
+main (gint argc,
+ gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- g_object_unref (book_client);
+ g_test_add ("/EBookClient/AddContact/Sync", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_add_contact_sync, e_test_server_utils_teardown);
+ g_test_add ("/EBookClient/AddContact/Async", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_add_contact_async, e_test_server_utils_teardown);
- return get_main_loop_stop_result ();
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client-async.c b/tests/libebook/client/test-client-async.c
index f43e050..0568517 100644
--- a/tests/libebook/client/test-client-async.c
+++ b/tests/libebook/client/test-client-async.c
@@ -4,6 +4,9 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
static void
print_all_uids_cb (GObject *source_object,
@@ -13,15 +16,13 @@ print_all_uids_cb (GObject *source_object,
EBookClient *book_client;
GSList *uids = NULL, *u;
GError *error = NULL;
+ GMainLoop *loop = (GMainLoop *)user_data;
book_client = E_BOOK_CLIENT (source_object);
g_return_if_fail (book_client != NULL);
- if (!e_book_client_get_contacts_uids_finish (book_client, result, &uids, &error)) {
- report_error ("get contacts uids finish", &error);
- stop_main_loop (1);
- return;
- }
+ if (!e_book_client_get_contacts_uids_finish (book_client, result, &uids, &error))
+ g_error ("get contacts uids finish: %s", error->message);
for (u = uids; u; u = u->next) {
const gchar *uid = u->data;
@@ -32,7 +33,7 @@ print_all_uids_cb (GObject *source_object,
g_slist_foreach (uids, (GFunc) g_free, NULL);
g_slist_free (uids);
- stop_main_loop (0);
+ g_main_loop_quit (loop);
}
static void
@@ -45,15 +46,13 @@ print_all_emails_cb (GObject *source_object,
gchar *sexp;
GSList *contacts = NULL, *c;
GError *error = NULL;
+ GMainLoop *loop = (GMainLoop *)user_data;
book_client = E_BOOK_CLIENT (source_object);
g_return_if_fail (book_client != NULL);
- if (!e_book_client_get_contacts_finish (book_client, result, &contacts, &error)) {
- report_error ("get contacts finish", &error);
- stop_main_loop (1);
- return;
- }
+ if (!e_book_client_get_contacts_finish (book_client, result, &contacts, &error))
+ g_error ("get contacts finish: %s", error->message);
for (c = contacts; c; c = c->next) {
EContact *contact = E_CONTACT (c->data);
@@ -68,13 +67,14 @@ print_all_emails_cb (GObject *source_object,
sexp = e_book_query_to_string (query);
e_book_query_unref (query);
- e_book_client_get_contacts_uids (book_client, sexp, NULL, print_all_uids_cb, NULL);
+ e_book_client_get_contacts_uids (book_client, sexp, NULL, print_all_uids_cb, loop);
g_free (sexp);
}
static void
-print_all_emails (EBookClient *book_client)
+print_all_emails (EBookClient *book_client,
+ GMainLoop *loop)
{
EBookQuery *query;
gchar *sexp;
@@ -83,7 +83,7 @@ print_all_emails (EBookClient *book_client)
sexp = e_book_query_to_string (query);
e_book_query_unref (query);
- e_book_client_get_contacts (book_client, sexp, NULL, print_all_emails_cb, NULL);
+ e_book_client_get_contacts (book_client, sexp, NULL, print_all_emails_cb, loop);
g_free (sexp);
}
@@ -96,27 +96,28 @@ print_email_cb (GObject *source_object,
EBookClient *book_client;
EContact *contact = NULL;
GError *error = NULL;
+ GMainLoop *loop = (GMainLoop *)user_data;
book_client = E_BOOK_CLIENT (source_object);
g_return_if_fail (book_client != NULL);
if (!e_book_client_get_contact_finish (book_client, result, &contact, &error)) {
- report_error ("get contact finish", &error);
+ g_error ("get contact finish: %s", error->message);
} else {
print_email (contact);
g_object_unref (contact);
}
printf ("printing all contacts\n");
- print_all_emails (book_client);
+ print_all_emails (book_client, loop);
}
static void
-print_one_email (EBookClient *book_client, GSList *uids)
+print_one_email (EBookClient *book_client, GSList *uids, GMainLoop *loop)
{
const gchar *uid = uids->data;
- e_book_client_get_contact (book_client, uid, NULL, print_email_cb, NULL);
+ e_book_client_get_contact (book_client, uid, NULL, print_email_cb, loop);
e_util_free_string_slist (uids);
}
@@ -129,14 +130,12 @@ contacts_added_cb (GObject *source_object,
EBookClient *book_client;
GError *error = NULL;
GSList *uids = NULL, *l;
+ GMainLoop *loop = (GMainLoop *)user_data;
book_client = E_BOOK_CLIENT (source_object);
- if (!e_book_client_add_contacts_finish (book_client, result, &uids, &error)) {
- report_error ("client open finish", &error);
- stop_main_loop (1);
- return;
- }
+ if (!e_book_client_add_contacts_finish (book_client, result, &uids, &error))
+ g_error ("client open finish: %s", error->message);
printf ("Added contacts uids are:\n");
for (l = uids; l; l = l->next) {
@@ -147,11 +146,12 @@ contacts_added_cb (GObject *source_object,
printf ("\n");
printf ("printing one contact\n");
- print_one_email (book_client, uids);
+ print_one_email (book_client, uids, loop);
}
static void
-add_contacts (EBookClient *book_client)
+add_contacts (EBookClient *book_client,
+ GMainLoop *loop)
{
GSList *contacts = NULL;
EContact *contact;
@@ -182,49 +182,35 @@ add_contacts (EBookClient *book_client)
g_free (vcard);
contacts = g_slist_prepend (contacts, contact);
- e_book_client_add_contacts (book_client, contacts, NULL, contacts_added_cb, NULL);
+ e_book_client_add_contacts (book_client, contacts, NULL, contacts_added_cb, loop);
e_util_free_object_slist (contacts);
}
static void
-client_loaded_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+test_async (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
EBookClient *book_client;
- GError *error = NULL;
- book_client = E_BOOK_CLIENT (source_object);
- g_return_if_fail (book_client != NULL);
-
- if (!e_client_open_finish (E_CLIENT (book_client), result, &error)) {
- report_error ("client open finish", &error);
- stop_main_loop (1);
- return;
- }
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
printf ("Adding contacts\n");
- add_contacts (book_client);
+ add_contacts (book_client, fixture->loop);
+ g_main_loop_run (fixture->loop);
}
gint
main (gint argc,
gchar **argv)
{
- EBookClient *book_client;
-
- main_initialize ();
-
- book_client = new_temp_client (NULL);
-
- printf ("loading addressbook\n");
-
- e_client_open (E_CLIENT (book_client), FALSE, NULL, client_loaded_cb, NULL);
-
- start_main_loop (NULL, NULL);
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- g_object_unref (book_client);
+ g_test_add ("/EBookClient/AsyncTest", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_async, e_test_server_utils_teardown);
- return get_main_loop_stop_result ();
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client-custom-summary.c b/tests/libebook/client/test-client-custom-summary.c
index 46dbdc6..dc0abd0 100644
--- a/tests/libebook/client/test-client-custom-summary.c
+++ b/tests/libebook/client/test-client-custom-summary.c
@@ -24,65 +24,36 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
-
-
-/****************************** Custom Book Creation *****************************/
+#include "e-test-server-utils.h"
typedef struct {
- GMainLoop *loop;
- const gchar *uid;
- ESourceRegistry *registry;
- ESource *scratch;
- ESource *source;
- EBookClient *book;
-} CreateBookData;
+ ETestServerClosure closure;
+ EBookQuery *query;
+ gint num_contacts;
+} ClientTestData;
-static gboolean
-quit_idle (CreateBookData *data)
-{
- g_main_loop_quit (data->loop);
- return FALSE;
-}
+/* Cleanup the closures, just for the hell of it... */
+static GList *closures = NULL;
-static gboolean
-create_book_idle (CreateBookData *data)
+static void
+client_test_data_free (gpointer p)
{
- GError *error = NULL;
-
- data->source = e_source_registry_ref_source (data->registry, data->uid);
- if (!data->source)
- g_error ("Unable to fetch newly created source uid '%s' from the registry", data->uid);
+ ClientTestData *data = (ClientTestData *)p;
- data->book = e_book_client_new_direct (data->registry, data->source, &error);
- if (!data->book)
- g_error ("Unable to create the book: %s", error->message);
-
- g_idle_add ((GSourceFunc)quit_idle, data);
-
- return FALSE;
+ if (data->query)
+ e_book_query_unref (data->query);
+ g_slice_free (ClientTestData, data);
}
-static gboolean
-register_source_idle (CreateBookData *data)
+static void
+setup_custom_book (ESource *scratch,
+ ETestServerClosure *closure)
{
- GError *error = NULL;
- ESourceBackend *backend;
ESourceBackendSummarySetup *setup;
- data->registry = e_source_registry_new_sync (NULL, &error);
- if (!data->registry)
- g_error ("Unable to create the registry: %s", error->message);
-
- data->scratch = e_source_new_with_uid (data->uid, NULL, &error);
- if (!data->scratch)
- g_error ("Failed to create source with uid '%s': %s", data->uid, error->message);
-
- backend = e_source_get_extension (data->scratch, E_SOURCE_EXTENSION_ADDRESS_BOOK);
- e_source_backend_set_backend_name (backend, "local");
-
g_type_ensure (E_TYPE_SOURCE_BACKEND_SUMMARY_SETUP);
- setup = e_source_get_extension (data->scratch, E_SOURCE_EXTENSION_BACKEND_SUMMARY_SETUP);
+ setup = e_source_get_extension (scratch, E_SOURCE_EXTENSION_BACKEND_SUMMARY_SETUP);
e_source_backend_summary_setup_set_summary_fields (setup,
E_CONTACT_FULL_NAME,
E_CONTACT_FAMILY_NAME,
@@ -97,87 +68,56 @@ register_source_idle (CreateBookData *data)
E_CONTACT_FAMILY_NAME, E_BOOK_INDEX_PREFIX,
E_CONTACT_FAMILY_NAME, E_BOOK_INDEX_SUFFIX,
0);
-
-
- if (!e_source_registry_commit_source_sync (data->registry, data->scratch, NULL, &error))
- g_error ("Unable to add new source to the registry for uid %s: %s", data->uid, error->message);
-
- /* XXX e_source_registry_commit_source_sync isnt really sync... or else
- * we could call e_source_registry_ref_source() immediately
- */
- g_timeout_add (20, (GSourceFunc)create_book_idle, data);
-
- return FALSE;
-}
-
-static EBookClient *
-ebook_test_utils_book_with_uid (const gchar *uid)
-{
- CreateBookData data = { 0, };
-
- data.uid = uid;
-
- data.loop = g_main_loop_new (NULL, FALSE);
- g_idle_add ((GSourceFunc)register_source_idle, &data);
- g_main_loop_run (data.loop);
- g_main_loop_unref (data.loop);
-
- g_object_unref (data.scratch);
- g_object_unref (data.source);
- g_object_unref (data.registry);
-
- return data.book;
}
-static EBookClient *
-new_custom_temp_client (gchar **uri)
+static void
+add_client_test (const gchar *path,
+ gpointer func,
+ EBookQuery *query,
+ gint num_contacts)
{
- EBookClient *book;
- gchar *uid;
- guint64 real_time = g_get_real_time ();
+ ClientTestData *data = g_slice_new0 (ClientTestData);
- uid = g_strdup_printf ("test-book-%" G_GINT64_FORMAT, real_time);
- book = ebook_test_utils_book_with_uid (uid);
-
- if (uri)
- *uri = g_strdup (uid);
-
- g_free (uid);
+ data->closure.type = E_TEST_SERVER_ADDRESS_BOOK;
+ data->closure.customize = setup_custom_book;
+ data->query = query;
+ data->num_contacts = num_contacts;
- return book;
+ g_test_add (path, ETestServerFixture, data, e_test_server_utils_setup, func, e_test_server_utils_teardown);
+ closures = g_list_prepend (closures, data);
}
-typedef struct {
- EBookClient *client;
- EBookQuery *query;
- gint num_contacts;
-} ClientTestData;
-
static void
-client_test_data_free (gpointer p)
+setup_book (EBookClient *book_client)
{
- ClientTestData *const data = p;
- g_object_unref (data->client);
-
- if (data->query)
- e_book_query_unref (data->query);
- g_slice_free (ClientTestData, data);
+ /* Add contacts */
+ if (!add_contact_from_test_case_verify (book_client, "custom-1", NULL) ||
+ !add_contact_from_test_case_verify (book_client, "custom-2", NULL) ||
+ !add_contact_from_test_case_verify (book_client, "custom-3", NULL) ||
+ !add_contact_from_test_case_verify (book_client, "custom-4", NULL) ||
+ !add_contact_from_test_case_verify (book_client, "custom-5", NULL) ||
+ !add_contact_from_test_case_verify (book_client, "custom-6", NULL)) {
+ g_error ("Failed to add contacts");
+ }
}
static void
-search_test (gconstpointer p)
+search_test (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
- const ClientTestData *const data = p;
+ EBookClient *book_client;
GSList *results = NULL;
GError *error = NULL;
gchar *sexp;
+ const ClientTestData *const data = user_data;
+
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+ setup_book (book_client);
sexp = e_book_query_to_string (data->query);
- if (!e_book_client_get_contacts_sync (data->client, sexp, &results, NULL, &error)) {
- report_error ("get contacts", &error);
- g_test_fail ();
- return;
+ if (!e_book_client_get_contacts_sync (book_client, sexp, &results, NULL, &error)) {
+ g_error ("get contacts: %s", error->message);
}
g_assert_cmpint (g_slist_length (results), ==, data->num_contacts);
@@ -186,19 +126,22 @@ search_test (gconstpointer p)
}
static void
-uid_test (gconstpointer p)
+uid_test (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
- const ClientTestData *const data = p;
+ EBookClient *book_client;
GSList *results = NULL;
GError *error = NULL;
gchar *sexp;
+ const ClientTestData *const data = user_data;
+
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+ setup_book (book_client);
sexp = e_book_query_to_string (data->query);
- if (!e_book_client_get_contacts_uids_sync (data->client, sexp, &results, NULL, &error)) {
- report_error ("get contact uids", &error);
- g_test_fail ();
- return;
+ if (!e_book_client_get_contacts_uids_sync (book_client, sexp, &results, NULL, &error)) {
+ g_error ("get contact uids: %s", error->message);
}
g_assert_cmpint (g_slist_length (results), ==, data->num_contacts);
@@ -206,112 +149,61 @@ uid_test (gconstpointer p)
g_free (sexp);
}
-static void
-remove_test (gconstpointer p)
-{
- const ClientTestData *const data = p;
- GError *error = NULL;
-
- if (!e_client_remove_sync (E_CLIENT (data->client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_test_fail ();
- return;
- }
-}
-
-static void
-add_client_test (const gchar *path,
- GTestDataFunc func,
- EBookClient *client,
- EBookQuery *query,
- gint num_contacts)
-{
- ClientTestData *data = g_slice_new (ClientTestData);
-
- data->client = g_object_ref (client);
- data->query = query;
- data->num_contacts = num_contacts;
-
- g_test_add_data_func_full (path, data, func, client_test_data_free);
-}
-
gint
main (gint argc,
gchar **argv)
{
- EBookClient *book_client;
- EContact *contact_final;
- GError *error = NULL;
+ gint ret;
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
g_test_init (&argc, &argv, NULL);
- main_initialize ();
- /* Setup */
- book_client = new_custom_temp_client (NULL);
- g_return_val_if_fail (book_client != NULL, 1);
-
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
-
- /* Add contacts */
- if (!add_contact_from_test_case_verify (book_client, "custom-1", &contact_final) ||
- !add_contact_from_test_case_verify (book_client, "custom-2", &contact_final) ||
- !add_contact_from_test_case_verify (book_client, "custom-3", &contact_final) ||
- !add_contact_from_test_case_verify (book_client, "custom-4", &contact_final) ||
- !add_contact_from_test_case_verify (book_client, "custom-5", &contact_final) ||
- !add_contact_from_test_case_verify (book_client, "custom-6", &contact_final)) {
- g_object_unref (book_client);
- return 1;
- }
/* Add search tests that fetch contacts */
- add_client_test ("/client/search/exact/fn", search_test, book_client,
+ add_client_test ("/client/search/exact/fn", search_test,
e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, "James Brown"),
1);
- add_client_test ("/client/search/exact/name", search_test, book_client,
+ add_client_test ("/client/search/exact/name", search_test,
e_book_query_vcard_field_test(EVC_N, E_BOOK_QUERY_IS, "Janet"),
1);
- add_client_test ("/client/search/prefix/fn", search_test, book_client,
+ add_client_test ("/client/search/prefix/fn", search_test,
e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_BEGINS_WITH, "B"),
2);
- add_client_test ("/client/search/prefix/fn/percent", search_test, book_client,
+ add_client_test ("/client/search/prefix/fn/percent", search_test,
e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_BEGINS_WITH, "%"),
1);
- add_client_test ("/client/search/suffix/phone", search_test, book_client,
+ add_client_test ("/client/search/suffix/phone", search_test,
e_book_query_field_test (E_CONTACT_TEL, E_BOOK_QUERY_ENDS_WITH, "999"),
2);
- add_client_test ("/client/search/suffix/email", search_test, book_client,
+ add_client_test ("/client/search/suffix/email", search_test,
e_book_query_field_test (E_CONTACT_EMAIL, E_BOOK_QUERY_ENDS_WITH, "jackson.com"),
2);
/* Add search tests that fetch uids */
- add_client_test ("/client/search-uid/exact/fn", uid_test, book_client,
+ add_client_test ("/client/search-uid/exact/fn", uid_test,
e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, "James Brown"),
1);
- add_client_test ("/client/search-uid/exact/name", uid_test, book_client,
+ add_client_test ("/client/search-uid/exact/name", uid_test,
e_book_query_vcard_field_test(EVC_N, E_BOOK_QUERY_IS, "Janet"),
1);
- add_client_test ("/client/search-uid/prefix/fn", uid_test, book_client,
+ add_client_test ("/client/search-uid/prefix/fn", uid_test,
e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_BEGINS_WITH, "B"),
2);
- add_client_test ("/client/search-uid/prefix/fn/percent", uid_test, book_client,
+ add_client_test ("/client/search-uid/prefix/fn/percent", uid_test,
e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_BEGINS_WITH, "%"),
1);
- add_client_test ("/client/search-uid/suffix/phone", uid_test, book_client,
+ add_client_test ("/client/search-uid/suffix/phone", uid_test,
e_book_query_field_test (E_CONTACT_TEL, E_BOOK_QUERY_ENDS_WITH, "999"),
2);
- add_client_test ("/client/search-uid/suffix/email", uid_test, book_client,
+ add_client_test ("/client/search-uid/suffix/email", uid_test,
e_book_query_field_test (E_CONTACT_EMAIL, E_BOOK_QUERY_ENDS_WITH, "jackson.com"),
2);
- /* Test remove operation */
- add_client_test ("/client/remove", remove_test, book_client, NULL, 0);
+ ret = e_test_server_utils_run ();
- /* Roll dices */
- g_object_unref (book_client);
+ g_list_free_full (closures, client_test_data_free);
- return g_test_run ();
+ return ret;
}
diff --git a/tests/libebook/client/test-client-get-contact-uids.c b/tests/libebook/client/test-client-get-contact-uids.c
index a2edcb3..51bfd1c 100644
--- a/tests/libebook/client/test-client-get-contact-uids.c
+++ b/tests/libebook/client/test-client-get-contact-uids.c
@@ -4,91 +4,105 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
+
+
+static void
+test_get_contact_uids_sync (ETestServerFixture *fixture,
+ gconstpointer user_data)
+{
+ EBookClient *book_client;
+ EContact *contact = NULL;
+ EBookQuery *query;
+ gchar *sexp;
+ GSList *contacts = NULL;
+ GError *error = NULL;
+
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+ if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
+ g_error ("Failed to add contact");
+ }
+ g_object_unref (contact);
+
+ query = e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, "Foo Bar");
+ sexp = e_book_query_to_string (query);
+
+ if (!e_book_client_get_contacts_uids_sync (book_client, sexp, &contacts, NULL, &error)) {
+ g_error ("get contacts uids: %s", error->message);
+ }
+
+ g_assert_cmpint (g_slist_length (contacts), ==, 1);
+ e_util_free_string_slist (contacts);
+
+ e_book_query_unref (query);
+ g_free (sexp);
+
+}
static void
contacts_ready_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
+ GMainLoop *loop = (GMainLoop *)user_data;
GError *error = NULL;
GSList *contacts = NULL;
if (!e_book_client_get_contacts_uids_finish (E_BOOK_CLIENT (source_object), result, &contacts, &error)) {
- report_error ("get contact finish", &error);
+ g_error ("get contact finish: %s", error->message);
stop_main_loop (1);
} else {
- g_assert (g_slist_length (contacts) == 1);
+ g_assert_cmpint (g_slist_length (contacts), ==, 1);
e_util_free_string_slist (contacts);
-
- stop_main_loop (0);
}
+
+ g_main_loop_quit (loop);
}
-gint
-main (gint argc,
- gchar **argv)
+static void
+test_get_contact_uids_async (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
EBookClient *book_client;
- EContact *contact_final;
- GError *error = NULL;
+ EContact *contact = NULL;
EBookQuery *query;
gchar *sexp;
- GSList *contacts = NULL;
-
- main_initialize ();
-
- /*
- * Setup
- */
- book_client = new_temp_client (NULL);
- g_return_val_if_fail (book_client != NULL, 1);
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- /* Add contact */
- if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact_final)) {
- g_object_unref (book_client);
- return 1;
+ if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
+ g_error ("Failed to add contact");
}
- g_object_unref (contact_final);
+ g_object_unref (contact);
- /*
- * Sync version
- */
query = e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, "Foo Bar");
sexp = e_book_query_to_string (query);
- if (!e_book_client_get_contacts_uids_sync (book_client, sexp, &contacts, NULL, &error)) {
- report_error ("get contacts uids", &error);
- g_object_unref (book_client);
- return 1;
- }
-
- g_assert (g_slist_length (contacts) == 1);
- e_util_free_string_slist (contacts);
-
- /*
- * Async version
- */
- e_book_client_get_contacts_uids (book_client, sexp, NULL, contacts_ready_cb, NULL);
+ e_book_client_get_contacts_uids (book_client, sexp, NULL, contacts_ready_cb, fixture->loop);
e_book_query_unref (query);
g_free (sexp);
- start_main_loop (NULL, NULL);
+ g_main_loop_run (fixture->loop);
+}
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+gint
+main (gint argc,
+ gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- g_object_unref (book_client);
+ g_test_add ("/EBookClient/GetContactUids/Sync", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_get_contact_uids_sync, e_test_server_utils_teardown);
+ g_test_add ("/EBookClient/GetContactUids/Async", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_get_contact_uids_async, e_test_server_utils_teardown);
- return get_main_loop_stop_result ();
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client-get-contact.c b/tests/libebook/client/test-client-get-contact.c
index 8c27483..e19ff94 100644
--- a/tests/libebook/client/test-client-get-contact.c
+++ b/tests/libebook/client/test-client-get-contact.c
@@ -4,70 +4,79 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
+
+
+static void
+test_get_contact_sync (ETestServerFixture *fixture,
+ gconstpointer user_data)
+{
+ EBookClient *book_client;
+ EContact *contact = NULL;
+
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+ if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
+ g_error ("Failed to get contact");
+ }
+
+ g_assert (contact != NULL);
+ g_object_unref (contact);
+}
static void
contact_ready_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
+ GMainLoop *loop = (GMainLoop *)user_data;
EContact *contact;
GError *error = NULL;
if (!e_book_client_get_contact_finish (E_BOOK_CLIENT (source_object), result, &contact, &error)) {
- report_error ("get contact finish", &error);
- stop_main_loop (1);
- } else {
- g_object_unref (contact);
- stop_main_loop (0);
- }
+ g_error ("get contact finish: %s", error->message);
+ }
+
+ g_object_unref (contact);
+ g_main_loop_quit (loop);
}
-gint
-main (gint argc,
- gchar **argv)
+static void
+test_get_contact_async (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
EBookClient *book_client;
- EContact *contact_final;
- GError *error = NULL;
+ EContact *contact = NULL;
- main_initialize ();
-
- /*
- * Setup
- */
- book_client = new_temp_client (NULL);
- g_return_val_if_fail (book_client != NULL, 1);
-
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- /*
- * Sync version
- */
- if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact_final)) {
- g_object_unref (book_client);
- return 1;
+ if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
+ g_error ("Failed to get contact");
}
- /*
- * Async version
- */
- e_book_client_get_contact (book_client, e_contact_get_const (contact_final, E_CONTACT_UID), NULL, contact_ready_cb, NULL);
-
- g_object_unref (contact_final);
+ e_book_client_get_contact (book_client,
+ e_contact_get_const (contact, E_CONTACT_UID),
+ NULL, contact_ready_cb, fixture->loop);
+ g_object_unref (contact);
+ g_main_loop_run (fixture->loop);
+}
- start_main_loop (NULL, NULL);
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+gint
+main (gint argc,
+ gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- g_object_unref (book_client);
+ g_test_add ("/EBookClient/GetContact/Sync", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_get_contact_sync, e_test_server_utils_teardown);
+ g_test_add ("/EBookClient/GetContact/Async", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_get_contact_async, e_test_server_utils_teardown);
- return get_main_loop_stop_result ();
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client-get-revision.c b/tests/libebook/client/test-client-get-revision.c
index adac4ed..6bc2970 100644
--- a/tests/libebook/client/test-client-get-revision.c
+++ b/tests/libebook/client/test-client-get-revision.c
@@ -5,6 +5,9 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
#define CYCLES 10
@@ -42,40 +45,31 @@ get_revision_compare_cycle (EBookClient *client)
g_free (revision_after);
}
-gint
-main (gint argc,
- gchar **argv)
+static void
+test_get_revision (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
EBookClient *book_client;
- GError *error = NULL;
- gint i;
+ gint i;
- g_type_init ();
-
- /*
- * Setup
- */
- book_client = new_temp_client (NULL);
-
- g_return_val_if_fail (book_client != NULL, 1);
-
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
/* Test that modifications make the revisions increment */
for (i = 0; i < CYCLES; i++)
get_revision_compare_cycle (book_client);
+}
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+gint
+main (gint argc,
+ gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- g_object_unref (book_client);
+ g_test_add ("/EBookClient/GetRevision", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_get_revision, e_test_server_utils_teardown);
- return 0;
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client-get-view.c b/tests/libebook/client/test-client-get-view.c
index 55cafae..e4c9f3a 100644
--- a/tests/libebook/client/test-client-get-view.c
+++ b/tests/libebook/client/test-client-get-view.c
@@ -4,6 +4,9 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
static void
objects_added (EBookClientView *view,
@@ -29,30 +32,34 @@ objects_removed (EBookClientView *view,
static void
complete (EBookClientView *view,
- const GError *error)
+ const GError *error,
+ gpointer user_data)
{
+ GMainLoop *loop = (GMainLoop *)user_data;
+
e_book_client_view_stop (view, NULL);
g_object_unref (view);
- stop_main_loop (0);
+ g_main_loop_quit (loop);
}
static void
-setup_and_start_view (EBookClientView *view)
+setup_and_start_view (EBookClientView *view,
+ GMainLoop *loop)
{
GError *error = NULL;
g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), NULL);
g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), NULL);
- g_signal_connect (view, "complete", G_CALLBACK (complete), NULL);
+ g_signal_connect (view, "complete", G_CALLBACK (complete), loop);
e_book_client_view_set_fields_of_interest (view, NULL, &error);
if (error)
- report_error ("set fields of interest", &error);
+ g_error ("set fields of interest: %s", error->message);
e_book_client_view_start (view, &error);
if (error)
- report_error ("start view", &error);
+ g_error ("start view: %s", error->message);
}
static void
@@ -60,126 +67,90 @@ get_view_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
+ GMainLoop *loop = (GMainLoop *)user_data;
EBookClientView *view;
GError *error = NULL;
if (!e_book_client_get_view_finish (E_BOOK_CLIENT (source_object), result, &view, &error)) {
- report_error ("get view finish", &error);
- stop_main_loop (1);
-
- return;
+ g_error ("get view finish: %s", error->message);
}
- setup_and_start_view (view);
+ setup_and_start_view (view, loop);
}
-static gboolean
-setup_book (EBookClient **book_client)
+static void
+setup_book (EBookClient *book_client)
{
- GError *error = NULL;
-
- g_return_val_if_fail (book_client != NULL, FALSE);
-
- *book_client = new_temp_client (NULL);
- g_return_val_if_fail (*book_client != NULL, FALSE);
-
- if (!e_client_open_sync (E_CLIENT (*book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (*book_client);
- return FALSE;
- }
-
- if (!add_contact_from_test_case_verify (*book_client, "simple-1", NULL) ||
- !add_contact_from_test_case_verify (*book_client, "simple-2", NULL) ||
- !add_contact_from_test_case_verify (*book_client, "name-only", NULL)) {
- g_object_unref (*book_client);
- return FALSE;
+ if (!add_contact_from_test_case_verify (book_client, "simple-1", NULL) ||
+ !add_contact_from_test_case_verify (book_client, "simple-2", NULL) ||
+ !add_contact_from_test_case_verify (book_client, "name-only", NULL)) {
+ g_error ("Failed to add contacts");
}
-
- return TRUE;
}
-static gpointer
-call_get_view (gpointer user_data)
+static void
+test_get_view_sync (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
+ EBookClient *book_client;
EBookQuery *query;
- EBookClient *book_client = user_data;
+ EBookClientView *view;
gchar *sexp;
+ GError *error = NULL;
+
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- g_return_val_if_fail (book_client != NULL, NULL);
- g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), NULL);
+ setup_book (book_client);
query = e_book_query_any_field_contains ("");
sexp = e_book_query_to_string (query);
e_book_query_unref (query);
-
- e_book_client_get_view (book_client, sexp, NULL, get_view_cb, NULL);
+ if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
+ g_error ("get book view sync: %s", error->message);
+ g_free (sexp);
+ g_object_unref (book_client);
+ }
g_free (sexp);
- return NULL;
+ setup_and_start_view (view, fixture->loop);
+ g_main_loop_run (fixture->loop);
}
-gint
-main (gint argc,
- gchar **argv)
+static void
+test_get_view_async (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
EBookClient *book_client;
EBookQuery *query;
- EBookClientView *view;
gchar *sexp;
- GError *error = NULL;
-
- main_initialize ();
- /*
- * Sync version
- */
- if (!setup_book (&book_client))
- return 1;
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+ setup_book (book_client);
query = e_book_query_any_field_contains ("");
sexp = e_book_query_to_string (query);
e_book_query_unref (query);
- if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
- report_error ("get book view sync", &error);
- g_free (sexp);
- g_object_unref (book_client);
- return 1;
- }
+ e_book_client_get_view (book_client, sexp, NULL, get_view_cb, fixture->loop);
g_free (sexp);
+ g_main_loop_run (fixture->loop);
+}
- setup_and_start_view (view);
-
- start_main_loop (NULL, NULL);
-
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
-
- return 1;
- }
-
- g_object_unref (book_client);
-
- /*
- * Async version
- */
- if (!setup_book (&book_client))
- return 1;
-
- start_in_idle_with_main_loop (call_get_view, book_client);
-
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
-
- return 1;
- }
+gint
+main (gint argc,
+ gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- g_object_unref (book_client);
+ g_test_add ("/EBookClient/GetBookClientView/Sync", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_get_view_sync, e_test_server_utils_teardown);
+ g_test_add ("/EBookClient/GetBookClientView/Async", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_get_view_async, e_test_server_utils_teardown);
- return get_main_loop_stop_result ();
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client-modify-contact.c b/tests/libebook/client/test-client-modify-contact.c
index d9d0aae..10817d4 100644
--- a/tests/libebook/client/test-client-modify-contact.c
+++ b/tests/libebook/client/test-client-modify-contact.c
@@ -4,6 +4,9 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
#define EMAIL_ADD "foo bar com"
@@ -32,24 +35,55 @@ verify_modify (EContact *contact)
}
static void
+test_modify_contact_sync (ETestServerFixture *fixture,
+ gconstpointer user_data)
+{
+ EBookClient *book_client;
+ GError *error = NULL;
+ EContact *contact, *book_contact;
+
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+ if (!add_contact_from_test_case_verify (book_client, "name-only", &contact))
+ g_error ("Failed to add contact");
+
+ verify_premodify_and_prepare_contact (contact);
+
+ if (!e_book_client_modify_contact_sync (book_client, contact, NULL, &error))
+ g_error ("modify contact sync: %s", error->message);
+
+ if (!e_book_client_get_contact_sync (book_client, e_contact_get_const (contact, E_CONTACT_UID),
+ &book_contact, NULL, &error))
+ g_error ("get contact sync: %s", error->message);
+
+ verify_modify (book_contact);
+ g_object_unref (book_contact);
+ g_object_unref (contact);
+}
+
+
+typedef struct {
+ EContact *contact;
+ GMainLoop *loop;
+} ModifyData;
+
+
+static void
contact_ready_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
EContact *contact;
GError *error = NULL;
+ GMainLoop *loop = (GMainLoop *)user_data;
- if (!e_book_client_get_contact_finish (E_BOOK_CLIENT (source_object), result, &contact, &error)) {
- report_error ("get contact finish", &error);
- stop_main_loop (1);
- return;
- }
+ if (!e_book_client_get_contact_finish (E_BOOK_CLIENT (source_object), result, &contact, &error))
+ g_error ("get contact finish: %s", error->message);
verify_modify (contact);
g_object_unref (contact);
-
- stop_main_loop (0);
+ g_main_loop_quit (loop);
}
static void
@@ -57,108 +91,54 @@ contact_modified_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
- EContact *contact = user_data;
+ ModifyData *data = (ModifyData *)user_data;
GError *error = NULL;
- if (!e_book_client_modify_contact_finish (E_BOOK_CLIENT (source_object), result, &error)) {
- report_error ("modify contact finish", &error);
- stop_main_loop (1);
- return;
- }
+ if (!e_book_client_modify_contact_finish (E_BOOK_CLIENT (source_object), result, &error))
+ g_error ("modify contact finish: %s", error->message);
- e_book_client_get_contact (E_BOOK_CLIENT (source_object), e_contact_get_const (contact, E_CONTACT_UID), NULL, contact_ready_cb, NULL);
+ e_book_client_get_contact (E_BOOK_CLIENT (source_object),
+ e_contact_get_const (data->contact, E_CONTACT_UID),
+ NULL, contact_ready_cb, data->loop);
}
-gint
-main (gint argc,
- gchar **argv)
+static void
+test_modify_contact_async (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
EBookClient *book_client;
- GError *error = NULL;
- EContact *contact, *book_contact;
-
- main_initialize ();
-
- /*
- * Setup
- */
- book_client = new_temp_client (NULL);
- g_return_val_if_fail (book_client != NULL, 1);
-
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
-
- /*
- * Sync version
- */
- if (!add_contact_from_test_case_verify (book_client, "name-only", &contact)) {
- g_object_unref (book_client);
- return 1;
- }
-
- verify_premodify_and_prepare_contact (contact);
-
- if (!e_book_client_modify_contact_sync (book_client, contact, NULL, &error)) {
- report_error ("modify contact sync", &error);
- g_object_unref (book_client);
- return 1;
- }
-
- if (!e_book_client_get_contact_sync (book_client, e_contact_get_const (contact, E_CONTACT_UID), &book_contact, NULL, &error)) {
- report_error ("get contact sync", &error);
- g_object_unref (contact);
- g_object_unref (book_client);
- return 1;
- }
-
- verify_modify (book_contact);
-
- g_object_unref (book_contact);
- g_object_unref (contact);
-
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
- return 1;
- }
-
- g_object_unref (book_client);
-
- /*
- * Async version
- */
- book_client = new_temp_client (NULL);
- g_return_val_if_fail (book_client != NULL, 1);
+ EContact *contact;
+ ModifyData data;
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- if (!add_contact_from_test_case_verify (book_client, "name-only", &contact)) {
- g_object_unref (book_client);
- return 1;
- }
+ if (!add_contact_from_test_case_verify (book_client, "name-only", &contact))
+ g_error ("Failed to add contact");
verify_premodify_and_prepare_contact (contact);
- e_book_client_modify_contact (book_client, contact, NULL, contact_modified_cb, contact);
+ data.contact = contact;
+ data.loop = fixture->loop;
+ e_book_client_modify_contact (book_client, contact, NULL, contact_modified_cb, &data);
- start_main_loop (NULL, NULL);
+ g_main_loop_run (fixture->loop);
g_object_unref (contact);
+}
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+gint
+main (gint argc,
+ gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- g_object_unref (book_client);
+ g_test_add ("/EBookClient/ModifyContact/Sync", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_modify_contact_sync, e_test_server_utils_teardown);
+ g_test_add ("/EBookClient/ModifyContact/Async", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_modify_contact_async, e_test_server_utils_teardown);
- return get_main_loop_stop_result ();
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client-photo-is-uri.c b/tests/libebook/client/test-client-photo-is-uri.c
index ea4ba20..1621e26 100644
--- a/tests/libebook/client/test-client-photo-is-uri.c
+++ b/tests/libebook/client/test-client-photo-is-uri.c
@@ -3,6 +3,9 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
static const gchar *photo_data =
"/9j / 4AAQSkZJRgABAQEARwBHAAD//gAXQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q / 9sAQwAIBgYHB\
@@ -238,11 +241,11 @@ setup_and_start_view (EBookClientView *view)
e_book_client_view_set_fields_of_interest (view, NULL, &error);
if (error)
- report_error ("set fields of interest", &error);
+ g_error ("set fields of interest: %s", error->message);
e_book_client_view_start (view, &error);
if (error)
- report_error ("start view", &error);
+ g_error ("start view: %s", error->message);
}
static void
@@ -296,64 +299,45 @@ add_contact_uri (EBookClient *book)
}
static void
-setup_book (EBookClient **book_out)
-{
- EBookClient *book;
- GError *error = NULL;
-
- book = new_temp_client (NULL);
- g_assert (book != NULL);
-
- if (!e_client_open_sync (E_CLIENT (book), FALSE, NULL, &error)) {
- g_error ("failed to open client: %s", error->message);
- }
-
- add_contact_inline (book);
- add_contact_uri (book);
-
- *book_out = book;
-}
-
-gint
-main (gint argc,
- gchar **argv)
+test_photo_is_uri (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
- EBookClient *book;
+ EBookClient *book_client;
EBookClientView *view;
EBookQuery *query;
GError *error = NULL;
gchar *sexp;
- g_type_init ();
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- setup_book (&book);
+ add_contact_inline (book_client);
+ add_contact_uri (book_client);
query = e_book_query_any_field_contains ("");
sexp = e_book_query_to_string (query);
e_book_query_unref (query);
- if (!e_book_client_get_view_sync (book, sexp, &view, NULL, &error)) {
- report_error ("get book view sync", &error);
- g_free (sexp);
- g_object_unref (book);
-
- return 1;
- }
+ if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error))
+ g_error ("get book view sync: %s", error->message);
g_free (sexp);
setup_and_start_view (view);
- loop = g_main_loop_new (NULL, TRUE);
+ loop = fixture->loop;
g_main_loop_run (loop);
+}
- if (!e_client_remove_sync (E_CLIENT (book), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book);
-
- return 1;
- }
+gint
+main (gint argc,
+ gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- g_object_unref (book);
+ g_test_add ("/EBookClient/PhotoIsUri", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_photo_is_uri, e_test_server_utils_teardown);
- return 0;
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client-refresh.c b/tests/libebook/client/test-client-refresh.c
index 9ffaef3..8ef2385 100644
--- a/tests/libebook/client/test-client-refresh.c
+++ b/tests/libebook/client/test-client-refresh.c
@@ -5,21 +5,9 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
-static gboolean
-test_sync (EBookClient *book_client)
-{
- GError *error = NULL;
-
- g_print ("Refresh supported: %s\n", e_client_check_refresh_supported (E_CLIENT (book_client)) ? "yes" : "no");
-
- if (!e_client_refresh_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("refresh sync", &error);
- return FALSE;
- }
-
- return TRUE;
-}
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
/* asynchronous callback with a main-loop running */
static void
@@ -29,89 +17,73 @@ async_refresh_result_ready (GObject *source_object,
{
EBookClient *book_client;
GError *error = NULL;
+ GMainLoop *loop = (GMainLoop *)user_data;
book_client = E_BOOK_CLIENT (source_object);
if (!e_client_refresh_finish (E_CLIENT (book_client), result, &error)) {
- report_error ("refresh finish", &error);
- stop_main_loop (1);
+ g_error ("refresh finish: %s", error->message);
return;
}
- stop_main_loop (0);
+ g_main_loop_quit (loop);
}
-/* synchronously in idle with main-loop running */
-static gboolean
-test_sync_in_idle (gpointer user_data)
+static void
+test_refresh_sync (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
- EBookClient *book_client = user_data;
-
- g_return_val_if_fail (book_client != NULL, FALSE);
- g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), FALSE);
+ EBookClient *book_client;
+ GError *error = NULL;
- if (!test_sync (book_client)) {
- stop_main_loop (1);
- return FALSE;
- }
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
g_print ("Refresh supported: %s\n", e_client_check_refresh_supported (E_CLIENT (book_client)) ? "yes" : "no");
+ if (!e_client_check_refresh_supported (E_CLIENT (book_client)))
+ return;
- e_client_refresh (E_CLIENT (book_client), NULL, async_refresh_result_ready, NULL);
+ if (!e_client_refresh_sync (E_CLIENT (book_client), NULL, &error)) {
+ g_error ("Error in refresh: %s", error->message);
+ }
+}
+static gboolean
+main_loop_fail_timeout (gpointer unused)
+{
+ g_error ("Failed to refresh, async call timed out");
return FALSE;
}
-/* synchronously in a dedicated thread with main-loop running */
-static gpointer
-test_sync_in_thread (gpointer user_data)
+static void
+test_refresh_async (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
- if (!test_sync (user_data)) {
- stop_main_loop (1);
- return NULL;
- }
+ EBookClient *book_client;
- g_idle_add (test_sync_in_idle, user_data);
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- return NULL;
+ g_print ("Refresh supported: %s\n", e_client_check_refresh_supported (E_CLIENT (book_client)) ? "yes" : "no");
+ if (!e_client_check_refresh_supported (E_CLIENT (book_client)))
+ return;
+
+ e_client_refresh (E_CLIENT (book_client), NULL, async_refresh_result_ready, fixture->loop);
+ g_timeout_add (5 * 1000, (GSourceFunc)main_loop_fail_timeout, NULL);
+ g_main_loop_run (fixture->loop);
}
gint
main (gint argc,
gchar **argv)
{
- EBookClient *book_client;
- GError *error = NULL;
-
- main_initialize ();
-
- book_client = new_temp_client (NULL);
- g_return_val_if_fail (book_client != NULL, FALSE);
-
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
-
- /* synchronously without main-loop */
- if (!test_sync (book_client)) {
- g_object_unref (book_client);
- return 1;
- }
-
- start_in_thread_with_main_loop (test_sync_in_thread, book_client);
-
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
- return 1;
- }
-
- g_object_unref (book_client);
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- if (get_main_loop_stop_result () == 0)
- g_print ("Test finished successfully.\n");
+ g_test_add ("/EBookClient/Refresh/Sync", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_refresh_sync, e_test_server_utils_teardown);
+ g_test_add ("/EBookClient/Refresh/Async", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_refresh_async, e_test_server_utils_teardown);
- return get_main_loop_stop_result ();
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client-remove-contact-by-uid.c b/tests/libebook/client/test-client-remove-contact-by-uid.c
index bc1c5c5..a9dd9cc 100644
--- a/tests/libebook/client/test-client-remove-contact-by-uid.c
+++ b/tests/libebook/client/test-client-remove-contact-by-uid.c
@@ -3,128 +3,103 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
-static void
-remove_contact_by_uid_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer uid)
-{
- GError *error = NULL;
- EContact *contact = NULL;
-
- if (!e_book_client_remove_contact_by_uid_finish (E_BOOK_CLIENT (source_object), result, &error)) {
- report_error ("remove contact by uid finish", &error);
- stop_main_loop (1);
- return;
- }
-
- if (!e_book_client_get_contact_sync (E_BOOK_CLIENT (source_object), uid, &contact, NULL, &error) &&
- g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
- g_clear_error (&error);
- stop_main_loop (0);
- } else {
- report_error ("fail with get contact on removed contact", &error);
- if (contact)
- g_object_unref (contact);
- stop_main_loop (1);
- }
-}
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
-gint
-main (gint argc,
- gchar **argv)
+static void
+test_remove_contact_by_uid_sync (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
EBookClient *book_client;
GError *error = NULL;
EContact *contact;
gchar *uid;
- main_initialize ();
-
- /*
- * Setup
- */
- book_client = new_temp_client (NULL);
- g_return_val_if_fail (book_client != NULL, 1);
-
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- /*
- * Sync version
- */
- if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
- g_object_unref (book_client);
- return 1;
- }
+ if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact))
+ g_error ("Failed to add contact");
uid = e_contact_get (contact, E_CONTACT_UID);
- g_object_unref (contact);
- if (!e_book_client_remove_contact_by_uid_sync (book_client, uid, NULL, &error)) {
- report_error ("remove contact sync", &error);
- g_object_unref (book_client);
- g_free (uid);
- return 1;
- }
+ if (!e_book_client_remove_contact_by_uid_sync (book_client, uid, NULL, &error))
+ g_error ("remove contact sync: %s", error->message);
if (!e_book_client_get_contact_sync (book_client, uid, &contact, NULL, &error) &&
g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
g_clear_error (&error);
- } else {
- report_error ("fail with get contact sync on removed contact", &error);
- g_object_unref (book_client);
- g_free (uid);
- return 1;
- }
+ } else
+ g_error ("fail with get contact sync on removed contact: %s", error->message);
g_free (uid);
+}
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+typedef struct {
+ const gchar *uid;
+ GMainLoop *loop;
+} RemoveData;
- g_object_unref (book_client);
+static void
+remove_contact_by_uid_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ RemoveData *data = (RemoveData *)user_data;
+ GError *error = NULL;
+ EContact *contact = NULL;
- /*
- * Async version
- */
- book_client = new_temp_client (NULL);
- g_return_val_if_fail (book_client != NULL, 1);
+ if (!e_book_client_remove_contact_by_uid_finish (E_BOOK_CLIENT (source_object), result, &error))
+ g_error ("remove contact by uid finish: %s", error->message);
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+ if (!e_book_client_get_contact_sync (E_BOOK_CLIENT (source_object), data->uid, &contact, NULL, &error) &&
+ g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
+ g_clear_error (&error);
+ } else
+ g_error ("fail with get contact on removed contact: %s", error->message);
- contact = NULL;
+ g_main_loop_quit (data->loop);
+}
- if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
- g_object_unref (book_client);
- return 1;
- }
+static void
+test_remove_contact_by_uid_async (ETestServerFixture *fixture,
+ gconstpointer user_data)
+{
+ EBookClient *book_client;
+ EContact *contact = NULL;
+ gchar *uid;
+ RemoveData data;
+
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+ if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact))
+ g_error ("Failed to add contact");
uid = e_contact_get (contact, E_CONTACT_UID);
- g_object_unref (contact);
- e_book_client_remove_contact_by_uid (book_client, uid, NULL, remove_contact_by_uid_cb, uid);
- start_main_loop (NULL, NULL);
+ data.uid = uid;
+ data.loop = fixture->loop;
+ e_book_client_remove_contact_by_uid (book_client, uid, NULL, remove_contact_by_uid_cb, &data);
+
+ g_object_unref (contact);
+ g_main_loop_run (fixture->loop);
g_free (uid);
+}
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+gint
+main (gint argc,
+ gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- g_object_unref (book_client);
+ g_test_add ("/EBookClient/RemoveContactByUid/Sync", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_remove_contact_by_uid_sync, e_test_server_utils_teardown);
+ g_test_add ("/EBookClient/RemoveContactByUid/Async", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_remove_contact_by_uid_async, e_test_server_utils_teardown);
- return 0;
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client-remove-contact.c b/tests/libebook/client/test-client-remove-contact.c
index a945d75..23bd215 100644
--- a/tests/libebook/client/test-client-remove-contact.c
+++ b/tests/libebook/client/test-client-remove-contact.c
@@ -3,131 +3,106 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
-static void
-remove_contact_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer uid)
-{
- GError *error = NULL;
- EContact *contact = NULL;
-
- if (!e_book_client_remove_contact_finish (E_BOOK_CLIENT (source_object), result, &error)) {
- report_error ("remove contact finish", &error);
- stop_main_loop (1);
- return;
- }
-
- if (!e_book_client_get_contact_sync (E_BOOK_CLIENT (source_object), uid, &contact, NULL, &error) &&
- g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
- g_clear_error (&error);
- stop_main_loop (0);
- } else {
- report_error ("fail with get contact on removed contact", &error);
- if (contact)
- g_object_unref (contact);
- stop_main_loop (1);
- }
-}
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
-gint
-main (gint argc,
- gchar **argv)
+static void
+test_remove_contact_sync (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
EBookClient *book_client;
GError *error = NULL;
EContact *contact;
gchar *uid;
- main_initialize ();
-
- /*
- * Setup
- */
- book_client = new_temp_client (NULL);
- g_return_val_if_fail (book_client != NULL, 1);
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
-
- /*
- * Sync version
- */
- if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
- g_object_unref (book_client);
- return 1;
- }
+ if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact))
+ g_error ("Failed to add contact");
uid = e_contact_get (contact, E_CONTACT_UID);
- if (!e_book_client_remove_contact_sync (book_client, contact, NULL, &error)) {
- report_error ("remove contact sync", &error);
- g_object_unref (contact);
- g_object_unref (book_client);
- g_free (uid);
- return 1;
- }
+ if (!e_book_client_remove_contact_sync (book_client, contact, NULL, &error))
+ g_error ("remove contact sync: %s", error->message);
g_object_unref (contact);
if (!e_book_client_get_contact_sync (book_client, uid, &contact, NULL, &error) &&
g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
g_clear_error (&error);
- } else {
- report_error ("fail with get contact sync on removed contact", &error);
- g_object_unref (book_client);
- g_free (uid);
- return 1;
- }
+ } else
+ g_error ("fail with get contact sync on removed contact: %s", error->message);
g_free (uid);
+}
+
+typedef struct {
+ const gchar *uid;
+ GMainLoop *loop;
+} RemoveData;
+
+static void
+remove_contact_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ RemoveData *data = (RemoveData *)user_data;
+ GError *error = NULL;
+ EContact *contact = NULL;
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+ if (!e_book_client_remove_contact_finish (E_BOOK_CLIENT (source_object), result, &error))
+ g_error ("remove contact finish: %s", error->message);
- g_object_unref (book_client);
+ if (!e_book_client_get_contact_sync (E_BOOK_CLIENT (source_object), data->uid, &contact, NULL, &error) &&
+ g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
+ g_clear_error (&error);
+ } else
+ g_error ("fail with get contact on removed contact: %s", error->message);
- /*
- * Async version
- */
- book_client = new_temp_client (NULL);
- g_return_val_if_fail (book_client != NULL, 1);
+ g_main_loop_quit (data->loop);
+}
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+static void
+test_remove_contact_async (ETestServerFixture *fixture,
+ gconstpointer user_data)
+{
+ EBookClient *book_client;
+ EContact *contact = NULL;
+ gchar *uid;
+ RemoveData data;
- contact = NULL;
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) {
- g_object_unref (book_client);
- return 1;
- }
+ if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact))
+ g_error ("Failed to add contact");
uid = e_contact_get (contact, E_CONTACT_UID);
- e_book_client_remove_contact (book_client, contact, NULL, remove_contact_cb, uid);
- g_object_unref (contact);
+ data.uid = uid;
+ data.loop = fixture->loop;
+ e_book_client_remove_contact (book_client, contact, NULL, remove_contact_cb, &data);
- start_main_loop (NULL, NULL);
+ g_object_unref (contact);
+ g_main_loop_run (fixture->loop);
g_free (uid);
+}
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
- return 1;
- }
- g_object_unref (book_client);
+gint
+main (gint argc,
+ gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/EBookClient/RemoveContact/Sync", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_remove_contact_sync, e_test_server_utils_teardown);
+ g_test_add ("/EBookClient/RemoveContact/Async", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_remove_contact_async, e_test_server_utils_teardown);
- return 0;
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client-remove-contacts.c b/tests/libebook/client/test-client-remove-contacts.c
index cdba188..bc9a3be 100644
--- a/tests/libebook/client/test-client-remove-contacts.c
+++ b/tests/libebook/client/test-client-remove-contacts.c
@@ -3,13 +3,16 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
-static gboolean
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
+
+static void
check_removed (EBookClient *book_client,
const GSList *uids)
{
- g_return_val_if_fail (book_client != NULL, FALSE);
- g_return_val_if_fail (uids != NULL, FALSE);
+ g_return_if_fail (book_client != NULL);
+ g_return_if_fail (uids != NULL);
while (uids) {
GError *error = NULL;
@@ -18,17 +21,11 @@ check_removed (EBookClient *book_client,
if (!e_book_client_get_contact_sync (book_client, uids->data, &contact, NULL, &error) &&
g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
g_clear_error (&error);
- } else {
- report_error ("fail with get contact on removed contact", &error);
- if (contact)
- g_object_unref (contact);
- return FALSE;
- }
+ } else
+ g_error ("fail with get contact on removed contact: %s", error->message);
uids = uids->next;
}
-
- return TRUE;
}
static gboolean
@@ -58,108 +55,83 @@ fill_book_client (EBookClient *book_client,
}
static void
-remove_contacts_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer uids)
-{
- GError *error = NULL;
-
- if (!e_book_client_remove_contacts_finish (E_BOOK_CLIENT (source_object), result, &error)) {
- report_error ("remove contacts finish", &error);
- stop_main_loop (1);
- return;
- }
-
- stop_main_loop (check_removed (E_BOOK_CLIENT (source_object), uids) ? 0 : 1);
-}
-
-gint
-main (gint argc,
- gchar **argv)
+test_remove_contacts_sync (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
EBookClient *book_client;
GError *error = NULL;
- GSList *uids;
-
- main_initialize ();
-
- /*
- * Setup
- */
- book_client = new_temp_client (NULL);
- g_return_val_if_fail (book_client != NULL, 1);
+ GSList *uids = NULL;
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- /*
- * Sync version
- */
- if (!fill_book_client (book_client, &uids)) {
- g_object_unref (book_client);
- return 1;
- }
+ if (!fill_book_client (book_client, &uids))
+ g_error ("Failed to add contacts");
- if (!e_book_client_remove_contacts_sync (book_client, uids, NULL, &error)) {
- report_error ("remove contact sync", &error);
- g_object_unref (book_client);
- g_slist_foreach (uids, (GFunc) g_free, NULL);
- g_slist_free (uids);
- return 1;
- }
-
- if (!check_removed (book_client, uids)) {
- g_object_unref (book_client);
- g_slist_foreach (uids, (GFunc) g_free, NULL);
- g_slist_free (uids);
- return 1;
- }
+ if (!e_book_client_remove_contacts_sync (book_client, uids, NULL, &error))
+ g_error ("remove contact sync: %s", error->message);
+ /* This will assert they are actually removed */
+ check_removed (book_client, uids);
g_slist_foreach (uids, (GFunc) g_free, NULL);
g_slist_free (uids);
+}
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+typedef struct {
+ GSList *uids;
+ GMainLoop *loop;
+} RemoveData;
- g_object_unref (book_client);
+static void
+remove_contacts_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GError *error = NULL;
+ RemoveData *data = (RemoveData *)user_data;
- /*
- * Async version
- */
- book_client = new_temp_client (NULL);
- g_return_val_if_fail (book_client != NULL, 1);
+ if (!e_book_client_remove_contacts_finish (E_BOOK_CLIENT (source_object), result, &error))
+ g_error ("remove contacts finish: %s", error->message);
- if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+ check_removed (E_BOOK_CLIENT (source_object), data->uids);
+ g_main_loop_quit (data->loop);
+}
- if (!fill_book_client (book_client, &uids)) {
- g_object_unref (book_client);
- return 1;
- }
+static void
+test_remove_contacts_async (ETestServerFixture *fixture,
+ gconstpointer user_data)
+{
+ EBookClient *book_client;
+ GSList *uids = NULL;
+ RemoveData data;
+
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+ if (!fill_book_client (book_client, &uids))
+ g_error ("Failed to add contacts");
- e_book_client_remove_contacts (book_client, uids, NULL, remove_contacts_cb, uids);
+ data.uids = uids;
+ data.loop = fixture->loop;
+ e_book_client_remove_contacts (book_client, uids, NULL, remove_contacts_cb, &data);
- start_main_loop (NULL, NULL);
+ g_main_loop_run (fixture->loop);
g_slist_foreach (uids, (GFunc) g_free, NULL);
g_slist_free (uids);
+}
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
- return 1;
- }
+gint
+main (gint argc,
+ gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- g_object_unref (book_client);
+ g_test_add ("/EBookClient/RemoveContacts/Sync", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_remove_contacts_sync, e_test_server_utils_teardown);
+ g_test_add ("/EBookClient/RemoveContacts/Async", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_remove_contacts_async, e_test_server_utils_teardown);
- return get_main_loop_stop_result ();
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client-revision-view.c b/tests/libebook/client/test-client-revision-view.c
index 5a3abba..2301a69 100644
--- a/tests/libebook/client/test-client-revision-view.c
+++ b/tests/libebook/client/test-client-revision-view.c
@@ -4,6 +4,9 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
#define N_TEST_CONTACTS 4
@@ -25,23 +28,11 @@ add_contact (EBookClient *client)
g_object_unref (contact);
}
-static gboolean
-setup_book (EBookClient **book_out)
+static void
+setup_book (EBookClient *book_client)
{
- GError *error = NULL;
gint i;
- g_return_val_if_fail (book_out != NULL, FALSE);
-
- *book_out = new_temp_client (NULL);
- g_return_val_if_fail (*book_out != NULL, FALSE);
-
- if (!e_client_open_sync (E_CLIENT (*book_out), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (*book_out);
- return FALSE;
- }
-
for (i = 0; i < N_TEST_CONTACTS; i++)
{
EContact *contact = e_contact_new ();
@@ -51,18 +42,16 @@ setup_book (EBookClient **book_out)
e_contact_set (contact, E_CONTACT_NICKNAME, name);
/* verify the contact was added "successfully" (not thorough) */
- if (!add_contact_verify (*book_out, contact))
+ if (!add_contact_verify (book_client, contact))
g_error ("Failed to add contact");
g_free (name);
g_object_unref (contact);
}
-
- return TRUE;
}
/****************************************************************
- * Handle EClientBookView notifications *
+ * Handle EClientBookView notifications *
****************************************************************/
static void
print_contact (EContact *contact)
@@ -74,18 +63,21 @@ print_contact (EContact *contact)
}
static void
-finish_test (EBookClientView *view)
+finish_test (EBookClientView *view,
+ GMainLoop *loop)
{
e_book_client_view_stop (view, NULL);
g_object_unref (view);
- stop_main_loop (0);
+ g_main_loop_quit (loop);
}
static void
objects_added (EBookClientView *view,
- const GSList *contacts)
+ const GSList *contacts,
+ gpointer user_data)
{
+ GMainLoop *loop = (GMainLoop *)user_data;
const GSList *l;
for (l = contacts; l; l = l->next) {
@@ -100,7 +92,7 @@ objects_added (EBookClientView *view,
}
if (!loading_view)
- finish_test (view);
+ finish_test (view, loop);
}
@@ -125,14 +117,15 @@ complete (EBookClientView *view,
}
static void
-setup_and_start_view (EBookClientView *view)
+setup_and_start_view (EBookClientView *view,
+ GMainLoop *loop)
{
GError *error = NULL;
GSList *field_list;
- g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), NULL);
- g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), NULL);
- g_signal_connect (view, "complete", G_CALLBACK (complete), NULL);
+ g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), loop);
+ g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), loop);
+ g_signal_connect (view, "complete", G_CALLBACK (complete), loop);
field_list = g_slist_prepend (NULL, (gpointer) e_contact_field_name (E_CONTACT_UID));
field_list = g_slist_prepend (field_list, (gpointer) e_contact_field_name (E_CONTACT_REV));
@@ -141,13 +134,13 @@ setup_and_start_view (EBookClientView *view)
g_slist_free (field_list);
if (error)
- report_error ("set fields of interest", &error);
+ g_error ("set fields of interest: %s", error->message);
loading_view = TRUE;
e_book_client_view_start (view, &error);
if (error)
- report_error ("start view", &error);
+ g_error ("start view: %s", error->message);
}
@@ -158,96 +151,77 @@ get_view_cb (GObject *source_object,
{
EBookClientView *view;
GError *error = NULL;
+ GMainLoop *loop = (GMainLoop *)user_data;
- if (!e_book_client_get_view_finish (E_BOOK_CLIENT (source_object), result, &view, &error)) {
- report_error ("get view finish", &error);
- stop_main_loop (1);
-
- return;
- }
+ if (!e_book_client_get_view_finish (E_BOOK_CLIENT (source_object), result, &view, &error))
+ g_error ("get view finish: %s", error->message);
- setup_and_start_view (view);
+ setup_and_start_view (view, loop);
}
-static gpointer
-call_get_view (gpointer user_data)
+static void
+test_revision_view_sync (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
+ EBookClient *book_client;
EBookQuery *query;
- EBookClient *book_client = user_data;
+ EBookClientView *view;
gchar *sexp;
+ GError *error = NULL;
- g_return_val_if_fail (book_client != NULL, NULL);
- g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), NULL);
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+ setup_book (book_client);
query = e_book_query_any_field_contains ("");
sexp = e_book_query_to_string (query);
e_book_query_unref (query);
-
- e_book_client_get_view (book_client, sexp, NULL, get_view_cb, NULL);
+ if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
+ g_error ("get book view sync: %s", error->message);
+ g_free (sexp);
+ g_object_unref (book_client);
+ }
g_free (sexp);
- return NULL;
+ setup_and_start_view (view, fixture->loop);
+ g_main_loop_run (fixture->loop);
}
-gint
-main (gint argc,
- gchar **argv)
+static void
+test_revision_view_async (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
EBookClient *book_client;
EBookQuery *query;
- EBookClientView *view;
gchar *sexp;
- GError *error = NULL;
- main_initialize ();
-
- /*
- * Sync version
- */
- if (!setup_book (&book_client))
- return 1;
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+ setup_book (book_client);
query = e_book_query_any_field_contains ("");
sexp = e_book_query_to_string (query);
e_book_query_unref (query);
- if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
- report_error ("get book view sync", &error);
- g_free (sexp);
- g_object_unref (book_client);
- return 1;
- }
+ e_book_client_get_view (book_client, sexp, NULL, get_view_cb, fixture->loop);
g_free (sexp);
+ g_main_loop_run (fixture->loop);
+}
- setup_and_start_view (view);
- start_main_loop (NULL, NULL);
-
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
-
- return 1;
- }
- g_object_unref (book_client);
-
- /*
- * Async version uids only
- */
- if (!setup_book (&book_client))
- return 1;
-
- start_in_idle_with_main_loop (call_get_view, book_client);
-
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
-
- return 1;
- }
+gint
+main (gint argc,
+ gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- g_object_unref (book_client);
+ g_test_add ("/EBookClient/RevisionView/Sync", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_revision_view_sync, e_test_server_utils_teardown);
+ g_test_add ("/EBookClient/RevisionView/Async", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_revision_view_async, e_test_server_utils_teardown);
- return get_main_loop_stop_result ();
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client-suppress-notifications.c b/tests/libebook/client/test-client-suppress-notifications.c
index 7a83811..1bae38b 100644
--- a/tests/libebook/client/test-client-suppress-notifications.c
+++ b/tests/libebook/client/test-client-suppress-notifications.c
@@ -4,6 +4,9 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
#define NOTIFICATION_WAIT 2000
@@ -15,45 +18,31 @@ add_contact (EBookClient *book_client)
g_return_if_fail (add_contact_from_test_case_verify (book_client, "name-only", NULL));
}
-static gboolean
-setup_book (EBookClient **book_client)
+static void
+setup_book (EBookClient *book_client)
{
- GError *error = NULL;
-
- g_return_val_if_fail (book_client != NULL, FALSE);
-
- *book_client = new_temp_client (NULL);
- g_return_val_if_fail (*book_client != NULL, FALSE);
-
- if (!e_client_open_sync (E_CLIENT (*book_client), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (*book_client);
- return FALSE;
- }
-
- if (!add_contact_from_test_case_verify (*book_client, "simple-1", NULL) ||
- !add_contact_from_test_case_verify (*book_client, "simple-2", NULL)) {
- g_object_unref (*book_client);
- return FALSE;
- }
-
- return TRUE;
+ if (!add_contact_from_test_case_verify (book_client, "simple-1", NULL) ||
+ !add_contact_from_test_case_verify (book_client, "simple-2", NULL))
+ g_error ("Failed to add contacts");
}
static void
-finish_test (EBookClientView *view)
+finish_test (EBookClientView *view,
+ GMainLoop *loop)
{
e_book_client_view_stop (view, NULL);
g_object_unref (view);
- stop_main_loop (0);
+ g_main_loop_quit (loop);
}
static void
objects_added (EBookClientView *view,
- const GSList *contacts)
+ const GSList *contacts,
+ gpointer user_data)
{
const GSList *l;
+ GMainLoop *loop = (GMainLoop *)user_data;
/* We quit the mainloop and the test succeeds if we get the notification
* for the contact we add after loading the view completes */
@@ -64,7 +53,7 @@ objects_added (EBookClientView *view,
if (loading_view)
g_error ("Expected no contact additions while loading the view");
else {
- finish_test (view);
+ finish_test (view, loop);
}
}
@@ -93,27 +82,28 @@ complete (EBookClientView *view,
}
static void
-setup_and_start_view (EBookClientView *view)
+setup_and_start_view (EBookClientView *view,
+ GMainLoop *loop)
{
GError *error = NULL;
- g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), NULL);
- g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), NULL);
- g_signal_connect (view, "complete", G_CALLBACK (complete), NULL);
+ g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), loop);
+ g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), loop);
+ g_signal_connect (view, "complete", G_CALLBACK (complete), loop);
e_book_client_view_set_fields_of_interest (view, NULL, &error);
if (error)
- report_error ("set fields of interest", &error);
+ g_error ("set fields of interest: %s", error->message);
/* Set flags to 0, i.e. unflag E_BOOK_VIEW_NOTIFY_INITIAL */
e_book_client_view_set_flags (view, 0, &error);
if (error)
- report_error ("set view flags", &error);
+ g_error ("set view flags: %s", error->message);
loading_view = TRUE;
e_book_client_view_start (view, &error);
if (error)
- report_error ("start view", &error);
+ g_error ("start view: %s", error->message);
}
@@ -122,100 +112,80 @@ get_view_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
+ GMainLoop *loop = (GMainLoop *)user_data;
EBookClientView *view;
GError *error = NULL;
if (!e_book_client_get_view_finish (E_BOOK_CLIENT (source_object), result, &view, &error)) {
- report_error ("get view finish", &error);
- stop_main_loop (1);
-
- return;
+ g_error ("get view finish: %s", error->message);
}
- setup_and_start_view (view);
+ setup_and_start_view (view, loop);
}
-static gpointer
-call_get_view (gpointer user_data)
+static void
+test_suppress_notifications_sync (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
+ EBookClient *book_client;
EBookQuery *query;
- EBookClient *book_client = user_data;
+ EBookClientView *view;
gchar *sexp;
+ GError *error = NULL;
+
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- g_return_val_if_fail (book_client != NULL, NULL);
- g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), NULL);
+ setup_book (book_client);
query = e_book_query_any_field_contains ("");
sexp = e_book_query_to_string (query);
e_book_query_unref (query);
-
- e_book_client_get_view (book_client, sexp, NULL, get_view_cb, NULL);
+ if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
+ g_error ("get book view sync: %s", error->message);
+ g_free (sexp);
+ g_object_unref (book_client);
+ }
g_free (sexp);
- return NULL;
+ setup_and_start_view (view, fixture->loop);
+ g_main_loop_run (fixture->loop);
}
-gint
-main (gint argc,
- gchar **argv)
+static void
+test_suppress_notifications_async (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
EBookClient *book_client;
EBookQuery *query;
- EBookClientView *view;
gchar *sexp;
- GError *error = NULL;
-
- main_initialize ();
- /*
- * Sync version
- */
- if (!setup_book (&book_client))
- return 1;
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+ setup_book (book_client);
query = e_book_query_any_field_contains ("");
sexp = e_book_query_to_string (query);
e_book_query_unref (query);
- if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
- report_error ("get book view sync", &error);
- g_free (sexp);
- g_object_unref (book_client);
- return 1;
- }
+ e_book_client_get_view (book_client, sexp, NULL, get_view_cb, fixture->loop);
g_free (sexp);
+ g_main_loop_run (fixture->loop);
+}
- setup_and_start_view (view);
-
- start_main_loop (NULL, NULL);
-
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
-
- return 1;
- }
-
- g_object_unref (book_client);
-
- /*
- * Async version
- */
- if (!setup_book (&book_client))
- return 1;
-
- start_in_idle_with_main_loop (call_get_view, book_client);
-
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
-
- return 1;
- }
+gint
+main (gint argc,
+ gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- g_object_unref (book_client);
+ g_test_add ("/EBookClient/SuppressNotifications/Sync", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_suppress_notifications_sync, e_test_server_utils_teardown);
+ g_test_add ("/EBookClient/SuppressNotifications/Async", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_suppress_notifications_async, e_test_server_utils_teardown);
- return get_main_loop_stop_result ();
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client-uid-only-view.c b/tests/libebook/client/test-client-uid-only-view.c
index 9b3c5af..0332740 100644
--- a/tests/libebook/client/test-client-uid-only-view.c
+++ b/tests/libebook/client/test-client-uid-only-view.c
@@ -4,6 +4,15 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+typedef struct {
+ ETestServerClosure closure;
+ gboolean uids_only;
+} UIDOnlyClosure;
+
+static UIDOnlyClosure book_closure_all_data = { { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 }, FALSE };
+static UIDOnlyClosure book_closure_uids_only = { { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 }, TRUE };
#define N_TEST_CONTACTS 4
@@ -44,22 +53,10 @@ add_contact (EBookClient *client)
}
static gboolean
-setup_book (EBookClient **book_out)
+setup_book (EBookClient *book_client)
{
- GError *error = NULL;
gint i, j;
- g_return_val_if_fail (book_out != NULL, FALSE);
-
- *book_out = new_temp_client (NULL);
- g_return_val_if_fail (*book_out != NULL, FALSE);
-
- if (!e_client_open_sync (E_CLIENT (*book_out), FALSE, NULL, &error)) {
- report_error ("client open sync", &error);
- g_object_unref (*book_out);
- return FALSE;
- }
-
for (i = 0; i < N_TEST_CONTACTS; i++)
{
EContact *contact = e_contact_new ();
@@ -100,7 +97,7 @@ setup_book (EBookClient **book_out)
#endif
/* verify the contact was added "successfully" (not thorough) */
- if (!add_contact_verify (*book_out, contact))
+ if (!add_contact_verify (book_client, contact))
g_error ("Failed to add contact");
g_free (name);
@@ -138,19 +135,22 @@ print_contact (EContact *contact)
#endif
static void
-finish_test (EBookClientView *view)
+finish_test (EBookClientView *view,
+ GMainLoop *loop)
{
e_book_client_view_stop (view, NULL);
g_object_unref (view);
- stop_main_loop (0);
+ g_main_loop_quit (loop);
}
static void
objects_added (EBookClientView *view,
- const GSList *contacts)
+ const GSList *contacts,
+ gpointer user_data)
{
const GSList *l;
+ GMainLoop *loop = (GMainLoop *)user_data;
for (l = contacts; l; l = l->next) {
EContact *contact = l->data;
@@ -168,7 +168,7 @@ objects_added (EBookClientView *view,
}
if (!loading_view)
- finish_test (view);
+ finish_test (view, loop);
}
@@ -193,14 +193,15 @@ complete (EBookClientView *view,
}
static void
-setup_and_start_view (EBookClientView *view)
+setup_and_start_view (EBookClientView *view,
+ GMainLoop *loop)
{
GError *error = NULL;
GSList uid_field_list = { 0, };
- g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), NULL);
- g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), NULL);
- g_signal_connect (view, "complete", G_CALLBACK (complete), NULL);
+ g_signal_connect (view, "objects-added", G_CALLBACK (objects_added), loop);
+ g_signal_connect (view, "objects-removed", G_CALLBACK (objects_removed), loop);
+ g_signal_connect (view, "complete", G_CALLBACK (complete), loop);
uid_field_list.data = (gpointer) e_contact_field_name (E_CONTACT_UID);
@@ -210,13 +211,13 @@ setup_and_start_view (EBookClientView *view)
e_book_client_view_set_fields_of_interest (view, NULL, &error);
if (error)
- report_error ("set fields of interest", &error);
+ g_error ("set fields of interest: %s", error->message);
loading_view = TRUE;
e_book_client_view_start (view, &error);
if (error)
- report_error ("start view", &error);
+ g_error ("start view: %s", error->message);
}
@@ -227,164 +228,90 @@ get_view_cb (GObject *source_object,
{
EBookClientView *view;
GError *error = NULL;
+ GMainLoop *loop = (GMainLoop *)user_data;
if (!e_book_client_get_view_finish (E_BOOK_CLIENT (source_object), result, &view, &error)) {
- report_error ("get view finish", &error);
- stop_main_loop (1);
-
- return;
+ g_error ("get view finish: %s", error->message);
}
- setup_and_start_view (view);
-}
-
-static gpointer
-call_get_view (gpointer user_data)
-{
- EBookQuery *query;
- EBookClient *book_client = user_data;
- gchar *sexp;
-
- g_return_val_if_fail (book_client != NULL, NULL);
- g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), NULL);
-
- query = e_book_query_any_field_contains ("");
- sexp = e_book_query_to_string (query);
- e_book_query_unref (query);
-
- e_book_client_get_view (book_client, sexp, NULL, get_view_cb, NULL);
-
- g_free (sexp);
-
- return NULL;
+ setup_and_start_view (view, loop);
}
-gint
-main (gint argc,
- gchar **argv)
+static void
+test_get_view_sync (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
EBookClient *book_client;
EBookQuery *query;
EBookClientView *view;
gchar *sexp;
GError *error = NULL;
- SETUP_TIMER (timer);
+ UIDOnlyClosure *closure = (UIDOnlyClosure *)user_data;
- main_initialize ();
+ uids_only = closure->uids_only;
- /*
- * Sync version all data
- */
- uids_only = FALSE;
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
- if (!setup_book (&book_client))
- return 1;
+ setup_book (book_client);
query = e_book_query_any_field_contains ("");
sexp = e_book_query_to_string (query);
e_book_query_unref (query);
if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
- report_error ("get book view sync", &error);
+ g_error ("get book view sync: %s", error->message);
g_free (sexp);
g_object_unref (book_client);
-
- return 1;
}
g_free (sexp);
- START_TIMER (timer);
- setup_and_start_view (view);
- start_main_loop (NULL, NULL);
- STOP_TIMER (timer);
- PRINT_TIMER (timer, "Loading all data from book view synchronously");
-
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
+ setup_and_start_view (view, fixture->loop);
+ g_main_loop_run (fixture->loop);
+}
- return 1;
- }
- g_object_unref (book_client);
+static void
+test_get_view_async (ETestServerFixture *fixture,
+ gconstpointer user_data)
+{
+ EBookClient *book_client;
+ EBookQuery *query;
+ gchar *sexp;
+ UIDOnlyClosure *closure = (UIDOnlyClosure *)user_data;
- /*
- * Sync version uids only
- */
- uids_only = TRUE;
+ uids_only = closure->uids_only;
- if (!setup_book (&book_client))
- return 1;
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+ setup_book (book_client);
query = e_book_query_any_field_contains ("");
sexp = e_book_query_to_string (query);
e_book_query_unref (query);
- if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
- report_error ("get book view sync", &error);
- g_free (sexp);
- g_object_unref (book_client);
- return 1;
- }
+ e_book_client_get_view (book_client, sexp, NULL, get_view_cb, fixture->loop);
g_free (sexp);
+ g_main_loop_run (fixture->loop);
+}
- START_TIMER (timer);
- setup_and_start_view (view);
- start_main_loop (NULL, NULL);
- STOP_TIMER (timer);
- PRINT_TIMER (timer, "Loading uids only from book view synchronously");
-
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
-
- return 1;
- }
- g_object_unref (book_client);
-
- /*
- * Async version all data
- */
- uids_only = FALSE;
-
- if (!setup_book (&book_client))
- return 1;
-
- START_TIMER (timer);
- start_in_idle_with_main_loop (call_get_view, book_client);
- STOP_TIMER (timer);
- PRINT_TIMER (timer, "Loading all data from book view asynchronously");
-
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
-
- return 1;
- }
-
- g_object_unref (book_client);
-
- /*
- * Async version uids only
- */
- uids_only = TRUE;
-
- if (!setup_book (&book_client))
- return 1;
-
- START_TIMER (timer);
- start_in_idle_with_main_loop (call_get_view, book_client);
- STOP_TIMER (timer);
- PRINT_TIMER (timer, "Loading uids only from book view asynchronously");
- if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
- report_error ("client remove sync", &error);
- g_object_unref (book_client);
+gint
+main (gint argc,
+ gchar **argv)
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- return 1;
- }
+ g_test_add ("/EBookClient/UidOnlyView/Sync/AllData", ETestServerFixture, &book_closure_all_data,
+ e_test_server_utils_setup, test_get_view_sync, e_test_server_utils_teardown);
+ g_test_add ("/EBookClient/UidOnlyView/Sync/UidsOnly", ETestServerFixture, &book_closure_uids_only,
+ e_test_server_utils_setup, test_get_view_sync, e_test_server_utils_teardown);
- g_object_unref (book_client);
+ g_test_add ("/EBookClient/UidOnlyView/Async/AllData", ETestServerFixture, &book_closure_all_data,
+ e_test_server_utils_setup, test_get_view_async, e_test_server_utils_teardown);
+ g_test_add ("/EBookClient/UidOnlyView/Async/UidsOnly", ETestServerFixture, &book_closure_uids_only,
+ e_test_server_utils_setup, test_get_view_async, e_test_server_utils_teardown);
- return get_main_loop_stop_result ();
+ return e_test_server_utils_run ();
}
diff --git a/tests/libebook/client/test-client.c b/tests/libebook/client/test-client.c
index 0de6380..69e2a03 100644
--- a/tests/libebook/client/test-client.c
+++ b/tests/libebook/client/test-client.c
@@ -4,6 +4,9 @@
#include <libebook/libebook.h>
#include "client-test-utils.h"
+#include "e-test-server-utils.h"
+
+static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
static void
print_all_uids (EBookClient *book)
@@ -75,51 +78,43 @@ print_all_emails (EBookClient *book)
}
static void
-print_one_email (EBookClient *book_client)
+test_client (ETestServerFixture *fixture,
+ gconstpointer user_data)
{
- EContact *contact;
- GError *error = NULL;
+ EBookClient *book_client;
- if (!e_book_client_get_contact_sync (book_client, "pas-id-0002023", &contact, NULL, &error)) {
- report_error ("get_contact_sync", &error);
- return;
+ book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
+
+ /* Add some contacts */
+ if (!add_contact_from_test_case_verify (book_client, "custom-1", NULL) ||
+ !add_contact_from_test_case_verify (book_client, "custom-2", NULL) ||
+ !add_contact_from_test_case_verify (book_client, "custom-3", NULL) ||
+ !add_contact_from_test_case_verify (book_client, "custom-4", NULL) ||
+ !add_contact_from_test_case_verify (book_client, "custom-5", NULL) ||
+ !add_contact_from_test_case_verify (book_client, "custom-6", NULL)) {
+ g_object_unref (book_client);
+ g_error ("Failed to add contacts");
}
- print_email (contact);
+ printf ("printing all contacts\n");
+ print_all_emails (book_client);
- g_object_unref (contact);
+ printf ("printing all uids\n");
+ print_all_uids (book_client);
}
+
gint
main (gint argc,
gchar **argv)
{
- EBookClient *book_client;
- ESourceRegistry *registry;
- GError *error = NULL;
-
- main_initialize ();
-
- registry = e_source_registry_new_sync (NULL, &error);
- if (error != NULL)
- g_error ("%s", error->message);
-
- printf ("loading addressbook\n");
-
- book_client = open_system_book (registry, FALSE);
- if (!book_client)
- return 1;
-
- printf ("printing one contact\n");
- print_one_email (book_client);
-
- printf ("printing all contacts\n");
- print_all_emails (book_client);
-
- printf ("printing all uids\n");
- print_all_uids (book_client);
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
- g_object_unref (book_client);
+ g_test_add ("/EBookClient/BasicTest", ETestServerFixture, &book_closure,
+ e_test_server_utils_setup, test_client, e_test_server_utils_teardown);
- return 0;
+ return e_test_server_utils_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]