[evolution-data-server/openismus-work] Adding test case for e_book_client_get_contacts_uids()



commit 706de0b1791efc4fe8bb685cbff057ba1ad54019
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Thu Nov 29 20:34:25 2012 +0900

    Adding test case for e_book_client_get_contacts_uids()

 tests/libebook/client/Makefile.am                  |    3 +
 .../libebook/client/test-client-get-contact-uids.c |   94 ++++++++++++++++++++
 2 files changed, 97 insertions(+), 0 deletions(-)
---
diff --git a/tests/libebook/client/Makefile.am b/tests/libebook/client/Makefile.am
index 4831265..df1b3a8 100644
--- a/tests/libebook/client/Makefile.am
+++ b/tests/libebook/client/Makefile.am
@@ -28,6 +28,7 @@ TESTS =								\
 	test-client-refresh					\
 	test-client-add-contact					\
 	test-client-get-contact					\
+	test-client-get-contact-uids				\
 	test-client-custom-summary				\
 	test-client-get-revision				\
 	test-client-get-view					\
@@ -77,6 +78,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_uids_LDADD=$(TEST_LIBS)
+test_client_get_contact_uids_CPPFLAGS=$(TEST_CPPFLAGS)
 test_client_custom_summary_LDADD=$(TEST_LIBS)
 test_client_custom_summary_CPPFLAGS=$(TEST_CPPFLAGS)
 test_client_get_revision_LDADD=$(TEST_LIBS)
diff --git a/tests/libebook/client/test-client-get-contact-uids.c b/tests/libebook/client/test-client-get-contact-uids.c
new file mode 100644
index 0000000..a2edcb3
--- /dev/null
+++ b/tests/libebook/client/test-client-get-contact-uids.c
@@ -0,0 +1,94 @@
+/* -*- 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"
+
+static void
+contacts_ready_cb (GObject *source_object,
+		   GAsyncResult *result,
+		   gpointer 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);
+		stop_main_loop (1);
+	} else {
+
+		g_assert (g_slist_length (contacts) == 1);
+		e_util_free_string_slist (contacts);
+
+		stop_main_loop (0);
+	}
+}
+
+gint
+main (gint argc,
+      gchar **argv)
+{
+	EBookClient *book_client;
+	EContact *contact_final;
+	GError *error = 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;
+	}
+
+	/* Add contact */
+	if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact_final)) {
+		g_object_unref (book_client);
+		return 1;
+	}
+	g_object_unref (contact_final);
+
+	/*
+	 * 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_query_unref (query);
+	g_free (sexp);
+
+	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]