[evolution-data-server/openismus-work: 7/7] Added test-ebook-get-book-view-uid-only.c test to addressbook/tests/ebook
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work: 7/7] Added test-ebook-get-book-view-uid-only.c test to addressbook/tests/ebook
- Date: Sun, 12 Jun 2011 21:57:02 +0000 (UTC)
commit 069c1f61ce371d51437fd0a98372dc2702da2e40
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Sun Jun 12 18:54:14 2011 +0900
Added test-ebook-get-book-view-uid-only.c test to addressbook/tests/ebook
The new test is like test-ebook-get-book-view.c except that it passes
the UID field as the only requested field and asserts that the returned
contact does not come with a 'fullname' field.
addressbook/tests/ebook/Makefile.am | 3 +
.../ebook/test-ebook-get-book-view-uid-only.c | 123 ++++++++++++++++++++
2 files changed, 126 insertions(+), 0 deletions(-)
---
diff --git a/addressbook/tests/ebook/Makefile.am b/addressbook/tests/ebook/Makefile.am
index 32c8e40..c2dca52 100644
--- a/addressbook/tests/ebook/Makefile.am
+++ b/addressbook/tests/ebook/Makefile.am
@@ -32,6 +32,7 @@ TESTS = \
test-ebook-add-contact \
test-ebook-get-contact \
test-ebook-get-book-view \
+ test-ebook-get-book-view-uid-only \
test-ebook-commit-contact \
test-ebook-remove-contact \
test-ebook-remove-contact-by-id \
@@ -83,6 +84,8 @@ test_ebook_commit_contact_LDADD=$(TEST_LIBS)
test_ebook_commit_contact_CPPFLAGS=$(TEST_CPPFLAGS)
test_ebook_get_book_view_LDADD=$(TEST_LIBS)
test_ebook_get_book_view_CPPFLAGS=$(TEST_CPPFLAGS)
+test_ebook_get_book_view_uid_only_LDADD=$(TEST_LIBS)
+test_ebook_get_book_view_uid_only_CPPFLAGS=$(TEST_CPPFLAGS)
test_ebook_get_contact_LDADD=$(TEST_LIBS)
test_ebook_get_contact_CPPFLAGS=$(TEST_CPPFLAGS)
test_ebook_get_required_fields_LDADD=$(TEST_LIBS)
diff --git a/addressbook/tests/ebook/test-ebook-get-book-view-uid-only.c b/addressbook/tests/ebook/test-ebook-get-book-view-uid-only.c
new file mode 100644
index 0000000..d149244
--- /dev/null
+++ b/addressbook/tests/ebook/test-ebook-get-book-view-uid-only.c
@@ -0,0 +1,123 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libebook/e-book.h>
+
+#include "ebook-test-utils.h"
+
+static GMainLoop *loop;
+
+static void
+contacts_added (EBookView *book_view, const GList *contacts)
+{
+ GList *l;
+
+ for (l = (GList*)contacts; l; l = l->next) {
+ EContact *contact = l->data;
+
+ test_print ("UID: %s\n", (gchar *)e_contact_get_const (contact, E_CONTACT_UID));
+
+ if (e_contact_get_const (contact, E_CONTACT_FULL_NAME) != NULL) {
+ g_warning ("received contact name `%s' when only the uid was requested",
+ (gchar *)e_contact_get_const (contact, E_CONTACT_FULL_NAME));
+ exit(1);
+ }
+ }
+}
+
+static void
+contacts_removed (EBookView *book_view, const GList *ids)
+{
+ GList *l;
+
+ for (l = (GList*)ids; l; l = l->next) {
+ test_print ("Removed contact: %s\n", (gchar *)l->data);
+ }
+}
+
+static void
+view_complete (EBookView *book_view, EBookViewStatus status, const gchar *error_msg)
+{
+ e_book_view_stop (book_view);
+ g_object_unref (book_view);
+ g_main_loop_quit (loop);
+}
+
+static void
+setup_and_start_view (EBookView *view)
+{
+ g_signal_connect (view, "contacts_added", G_CALLBACK (contacts_added), NULL);
+ g_signal_connect (view, "contacts_removed", G_CALLBACK (contacts_removed), NULL);
+ g_signal_connect (view, "view_complete", G_CALLBACK (view_complete), NULL);
+
+ e_book_view_start (view);
+}
+
+static void
+get_book_view_cb (EBookTestClosure *closure)
+{
+ g_assert (closure->view);
+
+ setup_and_start_view (closure->view);
+}
+
+static void
+setup_book (EBook **book_out)
+{
+ EBook *book;
+
+ book = ebook_test_utils_book_new_temp (NULL);
+ ebook_test_utils_book_open (book, FALSE);
+
+ ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-1", NULL);
+ ebook_test_utils_book_add_contact_from_test_case_verify (book, "simple-2", NULL);
+ ebook_test_utils_book_add_contact_from_test_case_verify (book, "name-only", NULL);
+
+ *book_out = book;
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ EBook *book;
+ EBookQuery *query;
+ EBookView *view;
+ GList requested_field = { 0, };
+
+ requested_field.data = (gpointer)e_contact_field_name (E_CONTACT_UID);
+
+ g_type_init ();
+
+ /*
+ * Sync version
+ */
+ setup_book (&book);
+ query = e_book_query_any_field_contains ("");
+ ebook_test_utils_book_get_book_view (book, query, &requested_field, &view);
+ setup_and_start_view (view);
+
+ test_print ("successfully set up the book view\n");
+
+ loop = g_main_loop_new (NULL, TRUE);
+ g_main_loop_run (loop);
+
+ e_book_query_unref (query);
+ ebook_test_utils_book_remove (book);
+
+ /*
+ * Async version
+ */
+ setup_book (&book);
+ query = e_book_query_any_field_contains ("");
+
+ loop = g_main_loop_new (NULL, TRUE);
+ ebook_test_utils_book_async_get_book_view (book, query, &requested_field,
+ (GSourceFunc) get_book_view_cb, loop);
+
+ g_main_loop_run (loop);
+
+ e_book_query_unref (query);
+ ebook_test_utils_book_remove (book);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]