Reworked test cases in tests/libebook/client directory
authorTristan Van Berkom <tristanvb@openismus.com>
Sat, 16 Mar 2013 06:39:11 +0000 (15:39 +0900)
committerTristan Van Berkom <tristanvb@openismus.com>
Sat, 16 Mar 2013 06:43:48 +0000 (15:43 +0900)
  o Removed obsolete test cases:

      test-client-nonexistent-id:
          Test covered by test-client-remove-contact already
      test-client-examine: Unable to easily refactor
      test-client-search:  A test which only applies to an existing
                           addressbook, can't be useful in unit tests
      stress factories: Not worth refactoring, partly covered by tests
                        in test-server-utils/test-fixture.c already

  o Revived several test cases which were not previously running at make check
  o Cleaned up client-test-utils.[ch]: now only includes convenience functions
    for loading contacts from the test case vcards.

16 files changed:
tests/libebook/client/Makefile.am
tests/libebook/client/client-test-utils.c
tests/libebook/client/client-test-utils.h
tests/libebook/client/test-client-add-and-get-async.c [moved from tests/libebook/client/test-client-async.c with 74% similarity]
tests/libebook/client/test-client-add-and-get-sync.c [moved from tests/libebook/client/test-client.c with 63% similarity]
tests/libebook/client/test-client-examine.c [deleted file]
tests/libebook/client/test-client-get-contact-uids.c
tests/libebook/client/test-client-nonexistent-id.c [deleted file]
tests/libebook/client/test-client-revision-view.c
tests/libebook/client/test-client-search.c [deleted file]
tests/libebook/client/test-client-self.c
tests/libebook/client/test-client-stress-factory--fifo.c [deleted file]
tests/libebook/client/test-client-stress-factory--serial.c [deleted file]
tests/libebook/client/test-client-stress-factory--single-book.c [deleted file]
tests/libebook/client/test-client-stress-views.c [deleted file]
tests/libebook/client/test-client-uid-only-view.c

index 2cb283d..746b8e5 100644 (file)
@@ -28,23 +28,26 @@ libclient_test_utils_la_LIBADD =                            \
 TESTS =                                                                \
        test-client-refresh                                     \
        test-client-add-contact                                 \
-       test-client-preserve-uid                                \
        test-client-get-contact                                 \
        test-client-get-contact-uids                            \
+       test-client-modify-contact                              \
+       test-client-remove-contact                              \
+       test-client-remove-contact-by-uid                       \
+       test-client-remove-contacts                             \
+       test-client-add-and-get-sync                            \
+       test-client-add-and-get-async                           \
+       test-client-self                                        \
+       test-client-preserve-uid                                \
+       test-client-photo-is-uri                                \
        test-client-e164-param                                  \
         test-client-custom-summary                             \
        test-client-get-revision                                \
-       test-client-get-view                                    \
        test-client-write-write                                 \
+       test-client-get-view                                    \
        test-client-uid-only-view                               \
        test-client-revision-view                               \
        test-client-view-operations                             \
        test-client-suppress-notifications                      \
-       test-client-modify-contact                              \
-       test-client-remove-contact                              \
-       test-client-remove-contact-by-uid                       \
-       test-client-remove-contacts                             \
-       test-client-photo-is-uri                                \
        $(NULL)
 
 # The noinst tests are functional tests, not unit tests.
@@ -53,16 +56,6 @@ TESTS =                                                              \
 # not been ported to use ETestServerFixture yet.
 noinst_PROGRAMS =                                              \
        $(TESTS)                                                \
-       test-client-async                                       \
-       test-client-examine                                     \
-       test-client                                             \
-       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 =                                                        \
@@ -77,16 +70,14 @@ TEST_LIBS =                                                 \
        $(EVOLUTION_ADDRESSBOOK_LIBS)                           \
        $(NULL)
 
-test_client_LDADD=$(TEST_LIBS)
-test_client_CPPFLAGS=$(TEST_CPPFLAGS)
-test_client_async_LDADD=$(TEST_LIBS)
-test_client_async_CPPFLAGS=$(TEST_CPPFLAGS)
+test_client_add_and_get_sync_LDADD=$(TEST_LIBS)
+test_client_add_and_get_sync_CPPFLAGS=$(TEST_CPPFLAGS)
+test_client_add_and_get_async_LDADD=$(TEST_LIBS)
+test_client_add_and_get_async_CPPFLAGS=$(TEST_CPPFLAGS)
 test_client_add_contact_LDADD=$(TEST_LIBS)
 test_client_add_contact_CPPFLAGS=$(TEST_CPPFLAGS)
 test_client_preserve_uid_LDADD=$(TEST_LIBS)
 test_client_preserve_uid_CPPFLAGS=$(TEST_CPPFLAGS)
-test_client_examine_LDADD=$(TEST_LIBS)
-test_client_examine_CPPFLAGS=$(TEST_CPPFLAGS)
 test_client_get_contact_LDADD=$(TEST_LIBS)
 test_client_get_contact_CPPFLAGS=$(TEST_CPPFLAGS)
 test_client_get_contact_uids_LDADD=$(TEST_LIBS)
@@ -121,19 +112,7 @@ test_client_photo_is_uri_LDADD=$(TEST_LIBS)
 test_client_photo_is_uri_CPPFLAGS=$(TEST_CPPFLAGS)
 test_client_write_write_LDADD=$(TEST_LIBS)
 test_client_write_write_CPPFLAGS=$(TEST_CPPFLAGS)
-test_client_stress_factory__fifo_LDADD=$(TEST_LIBS)
-test_client_stress_factory__fifo_CPPFLAGS=$(TEST_CPPFLAGS)
-test_client_stress_factory__serial_LDADD=$(TEST_LIBS)
-test_client_stress_factory__serial_CPPFLAGS=$(TEST_CPPFLAGS)
-test_client_stress_factory__single_book_LDADD=$(TEST_LIBS)
-test_client_stress_factory__single_book_CPPFLAGS=$(TEST_CPPFLAGS)
-test_client_nonexistent_id_LDADD=$(TEST_LIBS)
-test_client_nonexistent_id_CPPFLAGS=$(TEST_CPPFLAGS)
-test_client_search_LDADD=$(TEST_LIBS)
-test_client_search_CPPFLAGS=$(TEST_CPPFLAGS)
 test_client_self_LDADD=$(TEST_LIBS)
 test_client_self_CPPFLAGS=$(TEST_CPPFLAGS)
-test_client_stress_views_LDADD=$(TEST_LIBS)
-test_client_stress_views_CPPFLAGS=$(TEST_CPPFLAGS)
 
 -include $(top_srcdir)/git.mk
index f9bda66..d7368c6 100644 (file)
 #include "client-test-utils.h"
 
 void
-report_error (const gchar *operation,
-              GError **error)
-{
-       g_return_if_fail (operation != NULL);
-
-       g_printerr ("Failed to %s: %s\n", operation, (error && *error) ? (*error)->message : "Unknown error");
-
-       g_clear_error (error);
-}
-
-void
 print_email (EContact *contact)
 {
        const gchar *file_as = e_contact_get_const (contact, E_CONTACT_FILE_AS);
@@ -60,351 +49,6 @@ print_email (EContact *contact)
        g_print ("\n");
 }
 
-EBookClient *
-open_system_book (ESourceRegistry *registry,
-                  gboolean only_if_exists)
-{
-       ESource *source;
-       EBookClient *book_client;
-       GError *error = NULL;
-
-       main_initialize ();
-
-       source = e_source_registry_ref_builtin_address_book (registry);
-       book_client = e_book_client_new (source, &error);
-       g_object_unref (source);
-
-       if (error) {
-               report_error ("create system addressbook", &error);
-               return NULL;
-       }
-
-       if (!e_client_open_sync (E_CLIENT (book_client), only_if_exists, NULL, &error)) {
-               g_object_unref (book_client);
-               report_error ("open client sync", &error);
-               return NULL;
-       }
-
-       return book_client;
-}
-
-void
-main_initialize (void)
-{
-       static gboolean initialized = FALSE;
-
-       if (initialized)
-               return;
-
-       g_type_init ();
-       e_gdbus_templates_init_main_thread ();
-
-       initialized = TRUE;
-}
-
-struct IdleData {
-       GThreadFunc func;
-       gpointer data;
-       gboolean run_in_thread; /* FALSE to run in idle callback */
-};
-
-static gboolean
-idle_cb (gpointer data)
-{
-       struct IdleData *idle = data;
-
-       g_return_val_if_fail (idle != NULL, FALSE);
-       g_return_val_if_fail (idle->func != NULL, FALSE);
-
-       if (idle->run_in_thread) {
-               GThread *thread;
-
-               thread = g_thread_new (NULL, idle->func, idle->data);
-               g_thread_unref (thread);
-       } else {
-               idle->func (idle->data);
-       }
-
-       g_free (idle);
-
-       return FALSE;
-}
-
-static GMainLoop *loop = NULL;
-static gint main_stop_result = 0;
-
-static void
-do_start (GThreadFunc func,
-          gpointer data)
-{
-       main_initialize ();
-
-       g_return_if_fail (loop == NULL);
-
-       loop = g_main_loop_new (NULL, FALSE);
-
-       if (func)
-               func (data);
-
-       g_main_loop_run (loop);
-
-       g_main_loop_unref (loop);
-       loop = NULL;
-}
-
-/* Starts new main-loop, but just before that calls 'func'.
- * Main-loop is kept running, and this function blocks,
- * until call of stop_main_loop (). */
-void
-start_main_loop (GThreadFunc func,
-                 gpointer data)
-{
-       g_return_if_fail (loop == NULL);
-
-       do_start (func, data);
-}
-
-/* Starts new main-loop and then invokes func in a new thread.
- * Main-loop is kept running, and this function blocks,
- * until call of stop_main_loop (). */
-void
-start_in_thread_with_main_loop (GThreadFunc func,
-                                gpointer data)
-{
-       struct IdleData *idle;
-
-       g_return_if_fail (func != NULL);
-       g_return_if_fail (loop == NULL);
-
-       main_initialize ();
-
-       idle = g_new0 (struct IdleData, 1);
-       idle->func = func;
-       idle->data = data;
-       idle->run_in_thread = TRUE;
-
-       g_idle_add (idle_cb, idle);
-
-       do_start (NULL, NULL);
-}
-
-/* Starts new main-loop and then invokes func in an idle callback.
- * Main-loop is kept running, and this function blocks,
- * until call of stop_main_loop (). */
-void
-start_in_idle_with_main_loop (GThreadFunc func,
-                              gpointer data)
-{
-       struct IdleData *idle;
-
-       g_return_if_fail (func != NULL);
-       g_return_if_fail (loop == NULL);
-
-       main_initialize ();
-
-       idle = g_new0 (struct IdleData, 1);
-       idle->func = func;
-       idle->data = data;
-       idle->run_in_thread = FALSE;
-
-       g_idle_add (idle_cb, idle);
-
-       do_start (NULL, NULL);
-}
-
-/* Stops main-loop previously run by start_main_loop,
- * start_in_thread_with_main_loop or start_in_idle_with_main_loop.
-*/
-void
-stop_main_loop (gint stop_result)
-{
-       g_return_if_fail (loop != NULL);
-
-       main_stop_result = stop_result;
-       g_main_loop_quit (loop);
-}
-
-/* returns value used in stop_main_loop() */
-gint
-get_main_loop_stop_result (void)
-{
-       return main_stop_result;
-}
-
-void
-foreach_configured_source (ESourceRegistry *registry,
-                           void (*func) (ESource *source))
-{
-       gpointer foreach_async_data;
-       ESource *source = NULL;
-
-       g_return_if_fail (func != NULL);
-
-       main_initialize ();
-
-       foreach_async_data = foreach_configured_source_async_start (registry, &source);
-       if (!foreach_async_data)
-               return;
-
-       do {
-               func (source);
-       } while (foreach_configured_source_async_next (&foreach_async_data, &source));
-}
-
-struct ForeachConfiguredData {
-       GList *list;
-};
-
-gpointer
-foreach_configured_source_async_start (ESourceRegistry *registry,
-                                       ESource **source)
-{
-       struct ForeachConfiguredData *async_data;
-       const gchar *extension_name;
-       GList *list;
-
-       g_return_val_if_fail (source != NULL, NULL);
-
-       main_initialize ();
-
-       extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
-       list = e_source_registry_list_sources (registry, extension_name);
-
-       async_data = g_new0 (struct ForeachConfiguredData, 1);
-       async_data->list = list;
-
-       *source = async_data->list->data;
-
-       return async_data;
-}
-
-gboolean
-foreach_configured_source_async_next (gpointer *foreach_async_data,
-                                      ESource **source)
-{
-       struct ForeachConfiguredData *async_data;
-
-       g_return_val_if_fail (foreach_async_data != NULL, FALSE);
-       g_return_val_if_fail (source != NULL, FALSE);
-
-       async_data = *foreach_async_data;
-       g_return_val_if_fail (async_data != NULL, FALSE);
-
-       if (async_data->list) {
-               g_object_unref (async_data->list->data);
-               async_data->list = async_data->list->next;
-       }
-       if (async_data->list) {
-               *source = async_data->list->data;
-               return TRUE;
-       }
-
-       g_free (async_data);
-
-       *foreach_async_data = NULL;
-
-       return FALSE;
-}
-
-typedef struct {
-       GMainLoop       *loop;
-       const gchar     *uid;
-       ESourceRegistry *registry;
-       ESource         *scratch;
-       ESource         *source;
-       EBookClient     *book;
-} CreateBookData;
-
-static gboolean
-quit_idle (CreateBookData *data)
-{
-       g_main_loop_quit (data->loop);
-       return FALSE;
-}
-
-static gboolean
-create_book_idle (CreateBookData *data)
-{
-       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);
-
-       data->book = e_book_client_new (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;
-}
-
-static gboolean
-register_source_idle (CreateBookData *data)
-{
-       GError *error = NULL;
-       ESourceBackend  *backend;
-
-       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");
-
-       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;
-}
-
-EBookClient *
-new_temp_client (gchar **uri)
-{
-       EBookClient     *book;
-       gchar           *uid;
-       guint64          real_time = g_get_real_time ();
-
-       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);
-
-       return book;
-}
-
 gchar *
 new_vcard_from_test_case (const gchar *case_name)
 {
@@ -465,20 +109,13 @@ add_contact_from_test_case_verify (EBookClient *book_client,
        vcard = new_vcard_from_test_case (case_name);
        contact_orig = e_contact_new_from_vcard (vcard);
        g_free (vcard);
-       if (!e_book_client_add_contact_sync (book_client, contact_orig, &uid, NULL, &error)) {
-               report_error ("add contact sync", &error);
-               g_object_unref (contact_orig);
-               return FALSE;
-       }
+       if (!e_book_client_add_contact_sync (book_client, contact_orig, &uid, NULL, &error))
+               g_error ("add contact sync: %s", error->message);
 
        e_contact_set (contact_orig, E_CONTACT_UID, uid);
 
-       if (!e_book_client_get_contact_sync (book_client, uid, &contact_final, NULL, &error)) {
-               report_error ("get contact sync", &error);
-               g_object_unref (contact_orig);
-               g_free (uid);
-               return FALSE;
-       }
+       if (!e_book_client_get_contact_sync (book_client, uid, &contact_final, NULL, &error))
+               g_error ("get contact sync: %s", error->message);
 
         /* verify the contact was added "successfully" (not thorough) */
        g_assert (contacts_are_equal_shallow (contact_orig, contact_final));
@@ -501,18 +138,13 @@ add_contact_verify (EBookClient *book_client,
        gchar *uid;
        GError *error = NULL;
 
-       if (!e_book_client_add_contact_sync (book_client, contact, &uid, NULL, &error)) {
-               report_error ("add contact sync", &error);
-               return FALSE;
-       }
+       if (!e_book_client_add_contact_sync (book_client, contact, &uid, NULL, &error))
+               g_error ("add contact sync: %s", error->message);
 
        e_contact_set (contact, E_CONTACT_UID, uid);
 
-       if (!e_book_client_get_contact_sync (book_client, uid, &contact_final, NULL, &error)) {
-               report_error ("get contact sync", &error);
-               g_free (uid);
-               return FALSE;
-       }
+       if (!e_book_client_get_contact_sync (book_client, uid, &contact_final, NULL, &error))
+               g_error ("get contact sync: %s", error->message);
 
         /* verify the contact was added "successfully" (not thorough) */
        g_assert (contacts_are_equal_shallow (contact, contact_final));
index 2537735..7b42232 100644 (file)
 
 #include <libebook/libebook.h>
 
-void report_error (const gchar *operation, GError **error);
 void print_email (EContact *contact);
-EBookClient *open_system_book (ESourceRegistry *registry, gboolean only_if_exists);
 
-void main_initialize (void);
-void start_main_loop (GThreadFunc func, gpointer data);
-void start_in_thread_with_main_loop (GThreadFunc func, gpointer data);
-void start_in_idle_with_main_loop (GThreadFunc func, gpointer data);
-void stop_main_loop (gint stop_result);
-gint get_main_loop_stop_result (void);
-
-void foreach_configured_source (ESourceRegistry *registry, void (*func) (ESource *source));
-gpointer foreach_configured_source_async_start (ESourceRegistry *registry, ESource **source);
-gboolean foreach_configured_source_async_next (gpointer *foreach_async_data, ESource **source);
-
-EBookClient *new_temp_client (gchar **uri);
 gboolean add_contact_from_test_case_verify (EBookClient *book_client, const gchar *case_name, EContact **contact);
 gboolean add_contact_verify (EBookClient *book_client, EContact *contact);
 gchar *new_vcard_from_test_case (const gchar *case_name);
@@ -8,13 +8,20 @@
 
 static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 
+#define N_CONTACTS 5
+
+static gint fetched_contacts = 0;
+static gint fetched_uids = 0;
+static gint added_contacts = 0;
+
+
 static void
-print_all_uids_cb (GObject *source_object,
+count_all_uids_cb (GObject *source_object,
                    GAsyncResult *result,
                    gpointer user_data)
 {
        EBookClient *book_client;
-       GSList *uids = NULL, *u;
+       GSList *uids = NULL;
        GError *error = NULL;
        GMainLoop *loop = (GMainLoop *) user_data;
 
@@ -24,11 +31,7 @@ print_all_uids_cb (GObject *source_object,
        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;
-
-               g_print ("   uid:'%s'\n", uid);
-       }
+       fetched_uids = g_slist_length (uids);
 
        g_slist_foreach (uids, (GFunc) g_free, NULL);
        g_slist_free (uids);
@@ -37,14 +40,14 @@ print_all_uids_cb (GObject *source_object,
 }
 
 static void
-print_all_emails_cb (GObject *source_object,
-                     GAsyncResult *result,
-                     gpointer user_data)
+count_all_contacts_cb (GObject *source_object,
+                      GAsyncResult *result,
+                      gpointer user_data)
 {
        EBookClient *book_client;
        EBookQuery *query;
        gchar *sexp;
-       GSList *contacts = NULL, *c;
+       GSList *contacts = NULL;
        GError *error = NULL;
        GMainLoop *loop = (GMainLoop *) user_data;
 
@@ -54,11 +57,7 @@ print_all_emails_cb (GObject *source_object,
        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);
-
-               print_email (contact);
-       }
+       fetched_contacts = g_slist_length (contacts);
 
        g_slist_foreach (contacts, (GFunc) g_object_unref, NULL);
        g_slist_free (contacts);
@@ -67,14 +66,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, loop);
+       e_book_client_get_contacts_uids (book_client, sexp, NULL, count_all_uids_cb, loop);
 
        g_free (sexp);
 }
 
 static void
-print_all_emails (EBookClient *book_client,
-                  GMainLoop *loop)
+count_all_contacts (EBookClient *book_client,
+                   GMainLoop *loop)
 {
        EBookQuery *query;
        gchar *sexp;
@@ -83,15 +82,15 @@ 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, loop);
+       e_book_client_get_contacts (book_client, sexp, NULL, count_all_contacts_cb, loop);
 
        g_free (sexp);
 }
 
 static void
-print_email_cb (GObject *source_object,
-                GAsyncResult *result,
-                gpointer user_data)
+get_contact_cb (GObject *source_object,
+               GAsyncResult *result,
+               gpointer user_data)
 {
        EBookClient *book_client;
        EContact *contact = NULL;
@@ -104,24 +103,20 @@ print_email_cb (GObject *source_object,
        if (!e_book_client_get_contact_finish (book_client, result, &contact, &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, loop);
+       count_all_contacts (book_client, loop);
 }
 
 static void
-print_one_email (EBookClient *book_client,
-                 GSList *uids,
-                 GMainLoop *loop)
+get_contact_async (EBookClient *book_client,
+                  GSList *uids,
+                  GMainLoop *loop)
 {
        const gchar *uid = uids->data;
 
-       e_book_client_get_contact (book_client, uid, NULL, print_email_cb, loop);
-
-       e_util_free_string_slist (uids);
+       e_book_client_get_contact (book_client, uid, NULL, get_contact_cb, loop);
 }
 
 static void
@@ -131,7 +126,7 @@ contacts_added_cb (GObject *source_object,
 {
        EBookClient *book_client;
        GError *error = NULL;
-       GSList *uids = NULL, *l;
+       GSList *uids = NULL;
        GMainLoop *loop = (GMainLoop *) user_data;
 
        book_client = E_BOOK_CLIENT (source_object);
@@ -139,16 +134,10 @@ contacts_added_cb (GObject *source_object,
        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) {
-               const gchar *uid = l->data;
+       added_contacts = g_slist_length (uids);
+       get_contact_async (book_client, uids, loop);
 
-               printf ("\t%s\n", uid);
-       }
-       printf ("\n");
-
-       printf ("printing one contact\n");
-       print_one_email (book_client, uids, loop);
+       e_util_free_string_slist (uids);
 }
 
 static void
@@ -197,9 +186,12 @@ test_async (ETestServerFixture *fixture,
 
        book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 
-       printf ("Adding contacts\n");
        add_contacts (book_client, fixture->loop);
        g_main_loop_run (fixture->loop);
+
+       g_assert_cmpint (added_contacts, ==, N_CONTACTS);
+       g_assert_cmpint (fetched_contacts, ==, N_CONTACTS);
+       g_assert_cmpint (fetched_uids, ==, N_CONTACTS);
 }
 
 gint
@@ -212,7 +204,7 @@ main (gint argc,
        g_test_init (&argc, &argv, NULL);
 
        g_test_add (
-               "/EBookClient/AsyncTest", ETestServerFixture, &book_closure,
+               "/EBookClient/AddAndGet/Async", ETestServerFixture, &book_closure,
                e_test_server_utils_setup, test_async, e_test_server_utils_teardown);
 
        return e_test_server_utils_run ();
similarity index 63%
rename from tests/libebook/client/test-client.c
rename to tests/libebook/client/test-client-add-and-get-sync.c
index 06e4298..3b126ab 100644 (file)
@@ -8,72 +8,54 @@
 
 static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 
+#define N_CONTACTS 6
+
+static gint fetched_contacts = 0;
+static gint fetched_uids = 0;
+
 static void
-print_all_uids (EBookClient *book)
+count_all_uids (EBookClient *book)
 {
        GError *error = NULL;
        EBookQuery *query;
        gchar *sexp;
-       gboolean result;
-       GSList *uids, *u;
+       GSList *uids;
 
        query = e_book_query_field_exists (E_CONTACT_FULL_NAME);
        sexp = e_book_query_to_string (query);
        e_book_query_unref (query);
 
-       result = e_book_client_get_contacts_uids_sync (book, sexp, &uids, NULL, &error);
+       if (!e_book_client_get_contacts_uids_sync (book, sexp, &uids, NULL, &error))
+               g_error ("Error getting contact uids: %s", error->message);
 
        g_free (sexp);
 
-       if (!result) {
-               fprintf (stderr, "Error getting uid list: %s\n", error ? error->message : "Unknown error");
-               if (error)
-                       g_error_free (error);
-               exit (1);
-       }
-
-       for (u = uids; u; u = u->next) {
-               const gchar *uid = u->data;
-
-               g_print ("   uid:'%s'\n", uid);
-       }
+       fetched_uids = g_slist_length (uids);
 
        g_slist_foreach (uids, (GFunc) g_free, NULL);
        g_slist_free (uids);
 }
 
 static void
-print_all_emails (EBookClient *book)
+count_all_contacts (EBookClient *book)
 {
        GError *error = NULL;
        EBookQuery *query;
        gchar *sexp;
-       gboolean result;
-       GSList *cards, *c;
+       GSList *cards;
 
        query = e_book_query_field_exists (E_CONTACT_FULL_NAME);
        sexp = e_book_query_to_string (query);
        e_book_query_unref (query);
 
-       result = e_book_client_get_contacts_sync (book, sexp, &cards, NULL, &error);
+       if (!e_book_client_get_contacts_sync (book, sexp, &cards, NULL, &error))
+               g_error ("Error getting contacts: %s", error->message);
 
        g_free (sexp);
 
-       if (!result) {
-               fprintf (stderr, "Error getting card list: %s\n", error ? error->message : "Unknown error");
-               if (error)
-                       g_error_free (error);
-               exit (1);
-       }
-
-       for (c = cards; c; c = c->next) {
-               EContact *contact = E_CONTACT (c->data);
-
-               print_email (contact);
-
-               g_object_unref (contact);
-       }
+       fetched_contacts = g_slist_length (cards);
 
+       g_slist_foreach (cards, (GFunc) g_object_unref, NULL);
        g_slist_free (cards);
 }
 
@@ -96,11 +78,11 @@ test_client (ETestServerFixture *fixture,
                g_error ("Failed to add contacts");
        }
 
-       printf ("printing all contacts\n");
-       print_all_emails (book_client);
+       count_all_contacts (book_client);
+       count_all_uids (book_client);
 
-       printf ("printing all uids\n");
-       print_all_uids (book_client);
+       g_assert_cmpint (fetched_contacts, ==, N_CONTACTS);
+       g_assert_cmpint (fetched_uids, ==, N_CONTACTS);
 }
 
 gint
@@ -113,7 +95,7 @@ main (gint argc,
        g_test_init (&argc, &argv, NULL);
 
        g_test_add (
-               "/EBookClient/BasicTest", ETestServerFixture, &book_closure,
+               "/EBookClient/AddAndGet/Sync", ETestServerFixture, &book_closure,
                e_test_server_utils_setup, test_client, e_test_server_utils_teardown);
 
        return e_test_server_utils_run ();
diff --git a/tests/libebook/client/test-client-examine.c b/tests/libebook/client/test-client-examine.c
deleted file mode 100644 (file)
index 443ce46..0000000
+++ /dev/null
@@ -1,397 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <libebook/libebook.h>
-
-#include "client-test-utils.h"
-
-static gint running_async = 0;
-
-static GSList *
-get_known_prop_names (void)
-{
-       GSList *prop_names = NULL;
-
-       prop_names = g_slist_append (prop_names, (gpointer) CLIENT_BACKEND_PROPERTY_READONLY);
-       prop_names = g_slist_append (prop_names, (gpointer) CLIENT_BACKEND_PROPERTY_ONLINE);
-       prop_names = g_slist_append (prop_names, (gpointer) CLIENT_BACKEND_PROPERTY_OPENING);
-       prop_names = g_slist_append (prop_names, (gpointer) CLIENT_BACKEND_PROPERTY_OPENED);
-       prop_names = g_slist_append (prop_names, (gpointer) CLIENT_BACKEND_PROPERTY_CACHE_DIR);
-       prop_names = g_slist_append (prop_names, (gpointer) CLIENT_BACKEND_PROPERTY_CAPABILITIES);
-       prop_names = g_slist_append (prop_names, (gpointer) BOOK_BACKEND_PROPERTY_REQUIRED_FIELDS);
-       prop_names = g_slist_append (prop_names, (gpointer) BOOK_BACKEND_PROPERTY_SUPPORTED_FIELDS);
-
-       return prop_names;
-}
-
-typedef struct _ExtraValues {
-       gpointer async_data;
-
-       GSList *todo_prop_names;
-       GHashTable *retrieved_props;
-} ExtraValues;
-
-static void
-extra_values_free (ExtraValues *evals)
-{
-       if (!evals)
-               return;
-
-       g_slist_free (evals->todo_prop_names);
-       g_hash_table_destroy (evals->retrieved_props);
-       g_free (evals);
-}
-
-static void
-print_each_property (gpointer prop_name,
-                     gpointer prop_value,
-                     gpointer user_data)
-{
-       g_return_if_fail (prop_name != NULL);
-
-       if (prop_value == NULL) {
-               g_print ("\t   %s: NULL\n", (const gchar *) prop_name);
-               return;
-       }
-
-       g_print ("\t   %s: ", (const gchar *) prop_name);
-
-       if (g_str_equal (prop_name, CLIENT_BACKEND_PROPERTY_CAPABILITIES) ||
-           g_str_equal (prop_name, BOOK_BACKEND_PROPERTY_REQUIRED_FIELDS) ||
-           g_str_equal (prop_name, BOOK_BACKEND_PROPERTY_SUPPORTED_FIELDS)) {
-               GSList *values = e_client_util_parse_comma_strings (prop_value), *v;
-
-               for (v = values; v; v = v->next) {
-                       if (v != values)
-                               g_print (", ");
-
-                       g_print ("'%s'", (const gchar *) v->data);
-               }
-
-               e_client_util_free_string_slist (values);
-       } else {
-               g_print ("'%s'", (const gchar *) prop_value);
-       }
-
-       g_print ("\n");
-}
-
-static void
-print_values (const ExtraValues *evals,
-              EClient *client)
-{
-       const GSList *values;
-
-       g_return_if_fail (evals != NULL);
-
-       g_print ("\treadonly:%s\n", e_client_is_readonly (client) ? "yes" : "no");
-       g_print ("\tonline:%s\n", e_client_is_online (client) ? "yes" : "no");
-       g_print ("\tcapabilities: ");
-       values = e_client_get_capabilities (client);
-       if (!values) {
-               g_print ("NULL");
-       } else {
-               while (values) {
-                       const gchar *cap = values->data;
-
-                       g_print ("'%s'", cap);
-                       if (!e_client_check_capability (client, cap))
-                               g_print (" (not found in EClient)");
-
-                       values = values->next;
-
-                       if (values)
-                               g_print (", ");
-               }
-       }
-       g_print ("\n");
-
-       g_print ("\tbackend properties:\n");
-       g_hash_table_foreach (evals->retrieved_props, print_each_property, NULL);
-}
-
-static void
-identify_source (ESource *source)
-{
-       const gchar *name, *uid;
-
-       g_return_if_fail (source != NULL);
-
-       uid = e_source_get_uid (source);
-       name = e_source_get_display_name (source);
-
-       g_print ("\n   Checking source '%s' (%s)\n", name, uid);
-}
-
-static void
-identify_client (EBookClient *book_client)
-{
-       g_return_if_fail (book_client != NULL);
-       g_return_if_fail (E_IS_BOOK_CLIENT (book_client));
-
-       identify_source (e_client_get_source (E_CLIENT (book_client)));
-}
-
-static void client_opened_async (GObject *source_object, GAsyncResult *result, gpointer async_data);
-
-static void
-continue_next_source (gpointer async_data)
-{
-       ESource *source = NULL;
-       EBookClient *book_client;
-       GError *error = NULL;
-
-       g_return_if_fail (async_data != NULL);
-
-       while (async_data && foreach_configured_source_async_next (&async_data, &source)) {
-               book_client = e_book_client_new (source, &error);
-               if (!book_client) {
-                       identify_source (source);
-                       report_error ("book client new", &error);
-                       continue;
-               }
-
-               e_client_open (E_CLIENT (book_client), TRUE, NULL, client_opened_async, async_data);
-               break;
-       }
-
-       if (!async_data) {
-               running_async--;
-               if (!running_async)
-                       stop_main_loop (0);
-       }
-}
-
-static void
-client_got_backend_property_async (GObject *source_object,
-                                   GAsyncResult *result,
-                                   gpointer user_data)
-{
-       ExtraValues *evals = user_data;
-       gchar *prop_value = NULL;
-       GError *error = NULL;
-       EBookClient *book_client;
-
-       g_return_if_fail (source_object != NULL);
-       g_return_if_fail (E_IS_BOOK_CLIENT (source_object));
-       g_return_if_fail (evals != NULL);
-
-       book_client = E_BOOK_CLIENT (source_object);
-
-       if (!e_client_get_backend_property_finish (E_CLIENT (book_client), result, &prop_value, &error)) {
-               identify_client (book_client);
-               report_error ("get backend property finish", &error);
-       }
-
-       g_hash_table_insert (evals->retrieved_props, evals->todo_prop_names->data, prop_value);
-       evals->todo_prop_names = g_slist_remove (evals->todo_prop_names, evals->todo_prop_names->data);
-
-       if (!evals->todo_prop_names) {
-               /* to cache them, as it can be fetched with idle as well */
-               e_client_get_capabilities (E_CLIENT (source_object));
-
-               identify_client (book_client);
-               print_values (evals, E_CLIENT (source_object));
-
-               g_object_unref (source_object);
-
-               continue_next_source (evals->async_data);
-               extra_values_free (evals);
-       } else {
-               e_client_get_backend_property (E_CLIENT (book_client), evals->todo_prop_names->data, NULL, client_got_backend_property_async, evals);
-       }
-}
-
-static void
-client_set_backend_property_async (GObject *source_object,
-                                   GAsyncResult *result,
-                                   gpointer user_data)
-{
-       ExtraValues *evals = user_data;
-       GError *error = NULL;
-       EBookClient *book_client;
-
-       g_return_if_fail (source_object != NULL);
-       g_return_if_fail (E_IS_BOOK_CLIENT (source_object));
-       g_return_if_fail (evals != NULL);
-
-       book_client = E_BOOK_CLIENT (source_object);
-
-       if (!e_client_set_backend_property_finish (E_CLIENT (book_client), result, &error)) {
-               /* it may fail on the set_backend_property */
-               g_clear_error (&error);
-       } else {
-               identify_client (book_client);
-               g_printerr ("   Might fail on set_backend_property, but reported success\n");
-       }
-
-       e_client_get_backend_property (E_CLIENT (book_client), evals->todo_prop_names->data, NULL, client_got_backend_property_async, evals);
-}
-
-static void
-client_opened_async (GObject *source_object,
-                     GAsyncResult *result,
-                     gpointer async_data)
-{
-       ExtraValues *evals;
-       GError *error = NULL;
-       EBookClient *book_client;
-
-       g_return_if_fail (source_object != NULL);
-       g_return_if_fail (E_IS_BOOK_CLIENT (source_object));
-       g_return_if_fail (async_data != NULL);
-
-       book_client = E_BOOK_CLIENT (source_object);
-
-       if (!e_client_open_finish (E_CLIENT (source_object), result, &error)) {
-               identify_client (book_client);
-               report_error ("client open finish", &error);
-               g_object_unref (source_object);
-               continue_next_source (async_data);
-               return;
-       }
-
-       evals = g_new0 (ExtraValues, 1);
-       evals->async_data = async_data;
-       evals->todo_prop_names = get_known_prop_names ();
-       evals->retrieved_props = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
-
-       e_client_set_backend_property (E_CLIENT (book_client), "*unknown*property*", "*value*", NULL, client_set_backend_property_async, evals);
-}
-
-static void
-check_source_sync (ESource *source)
-{
-       EBookClient *book_client;
-       GError *error = NULL;
-       GSList *properties, *p;
-       ExtraValues evals = { 0 };
-
-       g_return_if_fail (source != NULL);
-
-       identify_source (source);
-
-       book_client = e_book_client_new (source, &error);
-       if (!book_client) {
-               report_error ("book client new", &error);
-               return;
-       }
-
-       if (!e_client_open_sync (E_CLIENT (book_client), TRUE, NULL, &error)) {
-               report_error ("client open sync", &error);
-               g_object_unref (book_client);
-               return;
-       }
-
-       if (!e_client_set_backend_property_sync (E_CLIENT (book_client), "*unknown*property*", "*value*", NULL, &error)) {
-               g_clear_error (&error);
-       } else {
-               identify_client (book_client);
-               g_printerr ("   Might fail on set_backend_property, but reported success\n");
-       }
-
-       evals.retrieved_props = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
-
-       properties = get_known_prop_names ();
-       for (p = properties; p != NULL; p = p->next) {
-               gchar *prop_value = NULL;
-
-               if (!e_client_get_backend_property_sync (E_CLIENT (book_client), p->data, &prop_value, NULL, &error)) {
-                       identify_client (book_client);
-                       report_error ("get backend property sync", &error);
-               } else {
-                       g_hash_table_insert (evals.retrieved_props, p->data, prop_value);
-               }
-       }
-       g_slist_free (properties);
-
-       print_values (&evals, E_CLIENT (book_client));
-
-       g_hash_table_destroy (evals.retrieved_props);
-       g_object_unref (book_client);
-}
-
-static gboolean
-foreach_async (ESourceRegistry *registry)
-{
-       gpointer async_data;
-       ESource *source = NULL;
-       EBookClient *book_client;
-       GError *error = NULL;
-
-       async_data = foreach_configured_source_async_start (registry, &source);
-       if (!async_data) {
-               stop_main_loop (1);
-               return FALSE;
-       }
-
-       running_async++;
-
-       while (book_client = e_book_client_new (source, &error), !book_client) {
-               identify_source (source);
-               report_error ("book client new", &error);
-
-               if (!foreach_configured_source_async_next (&async_data, &source)) {
-                       running_async--;
-                       if (!running_async)
-                               stop_main_loop (0);
-                       return FALSE;
-               }
-
-               identify_source (source);
-       }
-
-       e_client_open (E_CLIENT (book_client), TRUE, NULL, client_opened_async, async_data);
-
-       return TRUE;
-}
-
-static gboolean
-in_main_thread_idle_cb (ESourceRegistry *registry)
-{
-       g_print ("* run in main thread with mainloop running\n");
-       foreach_configured_source (registry, check_source_sync);
-       g_print ("---------------------------------------------------------\n\n");
-
-       g_print ("* run in main thread async\n");
-
-       if (!foreach_async (registry))
-               return FALSE;
-
-       return FALSE;
-}
-
-static gpointer
-worker_thread (ESourceRegistry *registry)
-{
-       g_print ("* run in dedicated thread with mainloop running\n");
-       foreach_configured_source (registry, check_source_sync);
-       g_print ("---------------------------------------------------------\n\n");
-
-       g_idle_add ((GSourceFunc) in_main_thread_idle_cb, registry);
-
-       return NULL;
-}
-
-gint
-main (gint argc,
-      gchar **argv)
-{
-       ESourceRegistry *registry;
-       GError *error = NULL;
-
-       main_initialize ();
-
-       registry = e_source_registry_new_sync (NULL, &error);
-       if (error != NULL)
-               g_error ("%s", error->message);
-
-       g_print ("* run in main thread without mainloop\n");
-       foreach_configured_source (registry, check_source_sync);
-       g_print ("---------------------------------------------------------\n\n");
-
-       start_in_thread_with_main_loop ((GThreadFunc) worker_thread, registry);
-
-       return get_main_loop_stop_result ();
-}
index 45be60b..4fc8667 100644 (file)
@@ -53,7 +53,6 @@ contacts_ready_cb (GObject *source_object,
 
        if (!e_book_client_get_contacts_uids_finish (E_BOOK_CLIENT (source_object), result, &contacts, &error)) {
                g_error ("get contact finish: %s", error->message);
-               stop_main_loop (1);
        } else {
 
                g_assert_cmpint (g_slist_length (contacts), ==, 1);
diff --git a/tests/libebook/client/test-client-nonexistent-id.c b/tests/libebook/client/test-client-nonexistent-id.c
deleted file mode 100644 (file)
index 0df821d..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-
-#include <libebook/libebook.h>
-
-#include "client-test-utils.h"
-
-gint
-main (gint argc,
-      gchar **argv)
-{
-       EBookClient *book_client = NULL;
-       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 ("removing nonexistent contact\n");
-       if (!e_book_client_remove_contact_by_uid_sync (book_client, "ii", NULL, &error)) {
-               if (!g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
-                       report_error ("remove contact sync", &error);
-                       g_object_unref (book_client);
-                       return 1;
-               }
-
-               printf ("\tOK, ended with expected Not Found error\n");
-               g_error_free (error);
-       } else if (error) {
-               report_error ("remove contact sync returned error, but success", &error);
-               g_object_unref (book_client);
-               return 1;
-       } else {
-               report_error ("remove contact sync returned success, but should return error", NULL);
-               g_object_unref (book_client);
-               return 1;
-       }
-
-       g_object_unref (book_client);
-
-       return 0;
-}
index f99a5b1..f8f2979 100644 (file)
@@ -23,7 +23,7 @@ add_contact (EBookClient *client)
        e_contact_set (contact, E_CONTACT_FULL_NAME, "Micheal Jackson");
 
        if (!add_contact_verify (client, contact))
-               stop_main_loop (1);
+               g_error ("Failed to add Micheal Jackson");
 
        g_object_unref (contact);
 }
diff --git a/tests/libebook/client/test-client-search.c b/tests/libebook/client/test-client-search.c
deleted file mode 100644 (file)
index b2bc80c..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-
-#include <stdlib.h>
-#include <libebook/libebook.h>
-
-#include "client-test-utils.h"
-
-gint
-main (gint argc,
-      gchar **argv)
-{
-       EBookClient *book_client;
-       ESourceRegistry *registry;
-       const gchar *query_string;
-       EBookQuery *query;
-       gchar *sexp;
-       GSList *c, *contacts;
-       GError *error = NULL;
-
-       main_initialize ();
-
-       if (argc != 2) {
-               query_string = "contains \"full_name\" \"a\"";
-               printf ("usage: test-search <query>\n");
-               printf ("   using default query \"%s\"\n", query_string);
-       } else {
-               query_string = argv[1];
-       }
-
-       registry = e_source_registry_new_sync (NULL, &error);
-       if (error != NULL)
-               g_error ("%s", error->message);
-
-       query = e_book_query_from_string (query_string);
-       if (!query) {
-               fprintf (stderr, " * Failed to parse query string '%s'\n", query_string);
-               return 1;
-       }
-
-       sexp = e_book_query_to_string (query);
-       e_book_query_unref (query);
-
-       book_client = open_system_book (registry, FALSE);
-       if (!book_client) {
-               g_free (sexp);
-               return 1;
-       }
-
-       if (!e_book_client_get_contacts_sync (book_client, sexp, &contacts, NULL, &error)) {
-               report_error ("get contacts sync", &error);
-               g_free (sexp);
-               g_object_unref (book_client);
-               return 1;
-       }
-
-       for (c = contacts; c; c = c->next) {
-               EContact *contact = E_CONTACT (c->data);
-               gchar *vcard = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
-
-               printf ("%s\n\n", vcard);
-
-               g_free (vcard);
-       }
-
-       g_slist_foreach (contacts, (GFunc) g_object_unref, NULL);
-       g_slist_free (contacts);
-
-       g_free (sexp);
-       g_object_unref (book_client);
-
-       return 0;
-}
index 1a1b4cc..d6a520f 100644 (file)
@@ -3,50 +3,94 @@
 #include <stdlib.h>
 #include <libebook/libebook.h>
 
+#include "e-test-server-utils.h"
 #include "client-test-utils.h"
 
+static ETestServerClosure registry_closure = { E_TEST_SERVER_NONE, NULL, 0 };
+
+static void
+test_get_self (ETestServerFixture *fixture,
+              gconstpointer user_data)
+{
+       EBookClient *client;
+       EContact    *contact;
+       GError      *error = NULL;
+
+       if (!e_book_client_get_self (fixture->registry, &contact, &client, &error))
+               g_error ("failed to get self contact: %s", error->message);
+
+       if (!client)
+               g_error ("e_book_client_get_self(): No client returned");
+
+       if (!contact)
+               g_error ("e_book_client_get_self(): No contact returned");
+
+       g_object_unref (contact);
+       g_object_unref (client);
+}
+
+static void
+test_set_self (ETestServerFixture *fixture,
+              gconstpointer user_data)
+{
+       ESource     *source;
+       EBookClient *client;
+       EContact    *loaded_contact = NULL;
+       EContact    *self_contact = NULL;
+       GError      *error = NULL;
+       const gchar *added_uid, *self_uid;
+
+       /* Open the system addressbook */
+       source = e_source_registry_ref_builtin_address_book (fixture->registry);
+       client = (EBookClient *)e_book_client_connect_sync (source, NULL, &error);
+       g_object_unref (source);
+       if (!client)
+               g_error ("Error connecting to system addressbook: %s", error->message);
+
+       /* Add contact to addressbook */
+       g_assert (add_contact_from_test_case_verify (client, "simple-1", &loaded_contact));
+
+       /* Set contact as self */
+       if (!e_book_client_set_self (client, loaded_contact, &error))
+               g_error ("Error setting self: %s", error->message);
+
+       g_object_unref (client);
+       client = NULL;
+
+       if (!e_book_client_get_self (fixture->registry, &self_contact, &client, &error))
+               g_error ("failed to get self contact: %s", error->message);
+
+       if (!client)
+               g_error ("e_book_client_get_self(): No client returned");
+
+       if (!self_contact)
+               g_error ("e_book_client_get_self(): No contact returned");
+
+       /* Assert the fetched contact is the right one */
+       added_uid = e_contact_get_const (loaded_contact, E_CONTACT_UID);
+       self_uid = e_contact_get_const (self_contact, E_CONTACT_UID);
+       g_assert_cmpstr (added_uid, ==, self_uid);
+
+       g_object_unref (self_contact);
+       g_object_unref (loaded_contact);
+       g_object_unref (client);
+}
+
 gint
 main (gint argc,
       gchar **argv)
 {
-       EBookClient *book_client = NULL;
-       ESourceRegistry *registry;
-       EContact *contact = NULL;
-       GError *error = NULL;
-       gchar *vcard;
-
-       main_initialize ();
-
-       printf ("getting the self contact\n");
-
-       registry = e_source_registry_new_sync (NULL, &error);
-       if (error != NULL)
-               g_error ("%s", error->message);
-
-       if (!e_book_client_get_self (registry, &contact, &book_client, &error)) {
-               report_error ("get self", &error);
-               return 1;
-       }
-
-       if (!contact) {
-               fprintf (stderr, " * Self contact not set\n");
-               if (book_client)
-                       g_object_unref (book_client);
-               return 0;
-       }
-
-       if (!book_client) {
-               fprintf (stderr, " * Book client for a self contact not returned\n");
-               g_object_unref (contact);
-               return 1;
-       }
-
-       vcard = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
-       printf ("self contact = \n%s\n", vcard);
-       g_free (vcard);
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+       g_type_init ();
+#endif
+       g_test_init (&argc, &argv, NULL);
 
-       g_object_unref (contact);
-       g_object_unref (book_client);
+       g_test_add (
+               "/EBookClient/Self/Get", ETestServerFixture, &registry_closure,
+               e_test_server_utils_setup, test_get_self, e_test_server_utils_teardown);
+       g_test_add (
+               "/EBookClient/Self/Set", ETestServerFixture, &registry_closure,
+               e_test_server_utils_setup, test_set_self, e_test_server_utils_teardown);
 
-       return 0;
+       return e_test_server_utils_run ();
 }
diff --git a/tests/libebook/client/test-client-stress-factory--fifo.c b/tests/libebook/client/test-client-stress-factory--fifo.c
deleted file mode 100644 (file)
index 954de03..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-
-#include <stdlib.h>
-#include <libebook/libebook.h>
-
-#include "client-test-utils.h"
-
-#define NUM_CLIENTS 200
-
-gint
-main (gint argc,
-      gchar **argv)
-{
-       EBookClient *book_clients[NUM_CLIENTS];
-       GError *error = NULL;
-       gint ii;
-
-       main_initialize ();
-
-       /* Create and open many books; then remove each of them */
-
-       for (ii = 0; ii < NUM_CLIENTS; ii++) {
-               book_clients[ii] = new_temp_client (NULL);
-               g_return_val_if_fail (book_clients[ii] != NULL, 1);
-
-               if (!e_client_open_sync (E_CLIENT (book_clients[ii]), FALSE, NULL, &error)) {
-                       report_error ("client open sync", &error);
-                       while (ii >= 0) {
-                               g_object_unref (book_clients[ii]);
-                               ii--;
-                       }
-
-                       return 1;
-               }
-       }
-
-       for (ii = 0; ii < NUM_CLIENTS; ii++) {
-               if (!e_client_remove_sync (E_CLIENT (book_clients[ii]), NULL, &error)) {
-                       report_error ("client remove sync", &error);
-                       while (ii < NUM_CLIENTS) {
-                               g_object_unref (book_clients[ii]);
-                               ii++;
-                       }
-                       return 1;
-               }
-
-               g_object_unref (book_clients[ii]);
-       }
-
-       return 0;
-}
diff --git a/tests/libebook/client/test-client-stress-factory--serial.c b/tests/libebook/client/test-client-stress-factory--serial.c
deleted file mode 100644 (file)
index 1af2bba..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-
-#include <libebook/libebook.h>
-
-#include "client-test-utils.h"
-
-#define NUM_CLIENTS 200
-
-gint
-main (gint argc,
-      gchar **argv)
-{
-       GError *error = NULL;
-       gint ii;
-
-       main_initialize ();
-
-       /* Serially create, open, (close), and remove many books */
-       for (ii = 0; ii < NUM_CLIENTS; ii++) {
-               EBookClient *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);
-                       return 1;
-               }
-
-               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);
-       }
-
-       return 0;
-}
diff --git a/tests/libebook/client/test-client-stress-factory--single-book.c b/tests/libebook/client/test-client-stress-factory--single-book.c
deleted file mode 100644 (file)
index d0e2666..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-
-#include <stdlib.h>
-#include <libebook/libebook.h>
-
-#include "client-test-utils.h"
-
-#define NUM_OPENS 200
-
-gint
-main (gint argc,
-      gchar **argv)
-{
-#if 0  /* ACCOUNT_MGMT */
-       gchar *uri = NULL;
-       EBookClient *book_client;
-       GError *error = NULL;
-       gint ii;
-
-       main_initialize ();
-
-       book_client = new_temp_client (&uri);
-       g_return_val_if_fail (book_client != NULL, 1);
-       g_return_val_if_fail (uri != NULL, 1);
-
-       g_object_unref (book_client);
-
-       /* open and close the same book repeatedly */
-       for (ii = 0; ii < NUM_OPENS; ii++) {
-               book_client = e_book_client_new_from_uri (uri, &error);
-               if (!book_client) {
-                       report_error ("new from uri", &error);
-                       break;
-               }
-
-               if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-                       report_error ("client open sync", &error);
-                       g_object_unref (book_client);
-                       break;
-               }
-
-               g_object_unref (book_client);
-       }
-
-       book_client = e_book_client_new_from_uri (uri, &error);
-       if (!book_client) {
-               g_clear_error (&error);
-       } else if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-               report_error ("client open sync", &error);
-               g_object_unref (book_client);
-               g_free (uri);
-               return 1;
-       } else  if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
-               report_error ("client remove sync", &error);
-               g_object_unref (book_client);
-               g_free (uri);
-               return 1;
-       }
-
-       g_free (uri);
-       g_object_unref (book_client);
-
-       return ii == NUM_OPENS ? 0 : 1;
-#endif  /* ACCOUNT_MGMT */
-
-       return 0;
-}
diff --git a/tests/libebook/client/test-client-stress-views.c b/tests/libebook/client/test-client-stress-views.c
deleted file mode 100644 (file)
index 7a666f0..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-
-#include <stdlib.h>
-#include <libebook/libebook.h>
-
-#include "client-test-utils.h"
-
-#define NUM_VIEWS 200
-
-#if 0  /* ACCOUNT_MGMT */
-static void
-objects_added (EBookClientView *view,
-               const GSList *contacts)
-{
-       const GSList *l;
-
-       for (l = contacts; l; l = l->next) {
-               print_email (l->data);
-       }
-}
-
-static void
-objects_removed (EBookClientView *view,
-                 const GSList *ids)
-{
-       const GSList *l;
-
-       for (l = ids; l; l = l->next) {
-               printf ("   Removed contact: %s\n", (gchar *) l->data);
-       }
-}
-
-static void
-complete (EBookClientView *view,
-          const GError *error)
-{
-       printf ("view_complete (status == %d, error_msg == %s%s%s)\n", error ? error->code : 0, error ? "'" : "", error ? error->message : "NULL", error ? "'" : "");
-}
-
-static gint
-stress_book_views (EBookClient *book_client,
-                   gboolean in_thread)
-{
-       EBookQuery *query;
-       EBookClientView *view = NULL;
-       EBookClientView *new_view;
-       gchar *sexp;
-       gint i;
-
-       g_return_val_if_fail (book_client != NULL, -1);
-       g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), -1);
-
-       query = e_book_query_any_field_contains ("");
-       sexp = e_book_query_to_string (query);
-       e_book_query_unref (query);
-
-       for (i = 0; i < NUM_VIEWS; i++) {
-               GError *error = NULL;
-
-               if (!e_book_client_get_view_sync (book_client, sexp, &new_view, NULL, &error)) {
-                       report_error ("get book view sync", &error);
-                       g_object_unref (view);
-                       g_free (sexp);
-                       return 1;
-               }
-
-               g_signal_connect (new_view, "objects-added", G_CALLBACK (objects_added), NULL);
-               g_signal_connect (new_view, "objects-removed", G_CALLBACK (objects_removed), NULL);
-               g_signal_connect (new_view, "complete", G_CALLBACK (complete), NULL);
-
-               e_book_client_view_start (new_view, NULL);
-
-               if (view) {
-                       /* wait 100 ms when in a thread */
-                       if (in_thread)
-                               g_usleep (100000);
-
-                       e_book_client_view_stop (view, NULL);
-                       g_object_unref (view);
-               }
-
-               view = new_view;
-       }
-
-       e_book_client_view_stop (view, NULL);
-       g_object_unref (view);
-
-       g_free (sexp);
-
-       return 0;
-}
-
-static gpointer
-stress_book_views_thread (gpointer user_data)
-{
-       stop_main_loop (stress_book_views (user_data, TRUE));
-
-       return NULL;
-}
-#endif /* ACCOUNT_MGMT */
-
-gint
-main (gint argc,
-      gchar **argv)
-{
-#if 0  /* ACCOUNT_MGMT */
-       EBookClient *book_client;
-       GError *error = NULL;
-
-       main_initialize ();
-
-       printf ("loading addressbook\n");
-
-       book_client = e_book_client_new_system (&error);
-       if (!book_client) {
-               report_error ("create local addressbook", &error);
-               return 1;
-       }
-
-       if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) {
-               g_object_unref (book_client);
-               report_error ("open client sync", &error);
-               return 1;
-       }
-
-       /* test from main thread */
-       stress_book_views (book_client, FALSE);
-
-       /* test from dedicated thread */
-       start_in_thread_with_main_loop (stress_book_views_thread, book_client);
-
-       g_object_unref (book_client);
-
-       return get_main_loop_stop_result ();
-#endif /* ACCOUNT_MGMT */
-
-       return 0;
-}
index 2f83fb2..aab3b4c 100644 (file)
@@ -47,7 +47,7 @@ add_contact (EBookClient *client)
        e_contact_set (contact, E_CONTACT_FULL_NAME, "Micheal Jackson");
 
        if (!add_contact_verify (client, contact))
-               stop_main_loop (1);
+               g_error ("Failed to add Micheal Jackson");
 
        g_object_unref (contact);
 }