[evolution-data-server/openismus-work-master: 9/10] Added test case to create a book with custom summary fields and fetch a contact.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work-master: 9/10] Added test case to create a book with custom summary fields and fetch a contact.
- Date: Thu, 8 Nov 2012 05:35:13 +0000 (UTC)
commit 471ec34dbaa74ca10901e28092f87c0956cdf5c1
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Mon Oct 8 16:43:06 2012 +0900
Added test case to create a book with custom summary fields and fetch a contact.
tests/libebook/client/Makefile.am | 3 +
.../client/test-client-get-contact-custom.c | 196 ++++++++++++++++++++
2 files changed, 199 insertions(+), 0 deletions(-)
---
diff --git a/tests/libebook/client/Makefile.am b/tests/libebook/client/Makefile.am
index 670029b..e0e5f7e 100644
--- a/tests/libebook/client/Makefile.am
+++ b/tests/libebook/client/Makefile.am
@@ -26,6 +26,7 @@ TESTS = \
test-client-refresh \
test-client-add-contact \
test-client-get-contact \
+ test-client-get-contact-custom \
test-client-get-revision \
test-client-get-view \
test-client-uid-only-view \
@@ -73,6 +74,8 @@ 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_custom_LDADD=$(TEST_LIBS)
+test_client_get_contact_custom_CPPFLAGS=$(TEST_CPPFLAGS)
test_client_get_revision_LDADD=$(TEST_LIBS)
test_client_get_revision_CPPFLAGS=$(TEST_CPPFLAGS)
test_client_get_view_LDADD=$(TEST_LIBS)
diff --git a/tests/libebook/client/test-client-get-contact-custom.c b/tests/libebook/client/test-client-get-contact-custom.c
new file mode 100644
index 0000000..95e7709
--- /dev/null
+++ b/tests/libebook/client/test-client-get-contact-custom.c
@@ -0,0 +1,196 @@
+/* -*- 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"
+
+
+/****************************** Custom Book Creation *****************************/
+
+
+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;
+ ESourceAddressBookConfig *config;
+
+ 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_class_unref (g_type_class_ref (E_TYPE_SOURCE_ADDRESS_BOOK_CONFIG));
+ config = e_source_get_extension (data->scratch, E_SOURCE_EXTENSION_ADDRESS_BOOK_CONFIG);
+ e_source_address_book_config_set_summary_fields (config,
+ E_CONTACT_FULL_NAME,
+ E_CONTACT_GIVEN_NAME,
+ E_CONTACT_FAMILY_NAME,
+ E_CONTACT_NICKNAME,
+ E_CONTACT_EMAIL_1,
+ E_CONTACT_PHONE_HOME,
+ E_CONTACT_PHONE_MOBILE,
+ 0);
+ e_source_address_book_config_set_indexed_fields (config,
+ E_CONTACT_FULL_NAME,
+ E_CONTACT_PHONE_MOBILE,
+ 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)
+{
+ 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;
+}
+
+
+
+static void
+contact_ready_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer 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);
+ }
+}
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ EBookClient *book_client;
+ EContact *contact_final;
+ GError *error = 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;
+ }
+
+ /*
+ * Sync version
+ */
+ if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact_final)) {
+ g_object_unref (book_client);
+ return 1;
+ }
+
+ /*
+ * 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);
+
+ 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);
+
+ return get_main_loop_stop_result ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]