[evolution-data-server/treitter-test-suites] Add a test for the e-book 'getSupportedFields' method.



commit d27dc68f30a8e7afa08a72f410eec145321aed4f
Author: Travis Reitter <treitter gmail com>
Date:   Thu Dec 10 08:33:05 2009 -0800

    Add a test for the e-book 'getSupportedFields' method.

 addressbook/tests/ebook/Makefile.am                |    3 +
 addressbook/tests/ebook/ebook-test-utils.c         |   58 +++++++++++++++
 addressbook/tests/ebook/ebook-test-utils.h         |    7 ++
 .../tests/ebook/test-ebook-get-supported-fields.c  |   75 ++++++++++++++++++++
 4 files changed, 143 insertions(+), 0 deletions(-)
---
diff --git a/addressbook/tests/ebook/Makefile.am b/addressbook/tests/ebook/Makefile.am
index a0eb6ed..768eebb 100644
--- a/addressbook/tests/ebook/Makefile.am
+++ b/addressbook/tests/ebook/Makefile.am
@@ -32,6 +32,7 @@ noinst_PROGRAMS = \
 	test-ebook-get-contact               \
 	test-ebook-get-required-fields       \
 	test-ebook-get-static-capabilities   \
+	test-ebook-get-supported-fields      \
 	test-ebook-remove                    \
 	test-ebook-remove-contact            \
 	test-ebook-remove-contact-by-id      \
@@ -70,6 +71,8 @@ test_ebook_get_required_fields_LDADD=$(TEST_LIBS)
 test_ebook_get_required_fields_CPPFLAGS=$(TEST_CPPFLAGS)
 test_ebook_get_static_capabilities_LDADD=$(TEST_LIBS)
 test_ebook_get_static_capabilities_CPPFLAGS=$(TEST_CPPFLAGS)
+test_ebook_get_supported_fields_LDADD=$(TEST_LIBS)
+test_ebook_get_supported_fields_CPPFLAGS=$(TEST_CPPFLAGS)
 test_ebook_remove_LDADD=$(TEST_LIBS)
 test_ebook_remove_CPPFLAGS=$(TEST_CPPFLAGS)
 test_ebook_remove_contact_LDADD=$(TEST_LIBS)
diff --git a/addressbook/tests/ebook/ebook-test-utils.c b/addressbook/tests/ebook/ebook-test-utils.c
index 0fee18d..bb5b145 100644
--- a/addressbook/tests/ebook/ebook-test-utils.c
+++ b/addressbook/tests/ebook/ebook-test-utils.c
@@ -336,6 +336,64 @@ ebook_test_utils_book_get_static_capabilities (EBook *book)
         return caps;
 }
 
+GList*
+ebook_test_utils_book_get_supported_fields (EBook *book)
+{
+        GList *fields = NULL;
+        GError *error = NULL;
+
+        if (!e_book_get_supported_fields (book, &fields, &error)) {
+                const char *uri;
+
+                uri = e_book_get_uri (book);
+                g_warning ("failed to get supported fields for addressbook "
+                                "`%s': %s", uri, error->message);
+                exit(1);
+        }
+
+        return fields;
+}
+
+static void
+get_supported_fields_cb (EBook            *book,
+                        EBookStatus       status,
+                        EList            *fields,
+                        EBookTestClosure *closure)
+{
+        if (status != E_BOOK_ERROR_OK) {
+                g_warning ("failed to asynchronously get the contact: "
+                                "status %d", status);
+                exit (1);
+        }
+
+        closure->list = fields;
+
+        g_print ("successfully asynchronously retrieved the supported fields\n");
+
+        if (closure) {
+                (*closure->cb) (closure);
+                g_free (closure);
+        }
+}
+
+void
+ebook_test_utils_book_async_get_supported_fields (EBook       *book,
+                                                 GSourceFunc  callback,
+                                                 gpointer     user_data)
+{
+        EBookTestClosure *closure;
+
+        closure = g_new0 (EBookTestClosure, 1);
+        closure->cb = callback;
+        closure->user_data = user_data;
+        if (e_book_async_get_supported_fields (book,
+                                (EBookEListCallback) get_supported_fields_cb,
+                                closure)) {
+                g_warning ("failed to set up async getSupportedFields");
+                exit(1);
+        }
+}
+
 void
 ebook_test_utils_book_remove_contact (EBook      *book,
                                       const char *uid)
diff --git a/addressbook/tests/ebook/ebook-test-utils.h b/addressbook/tests/ebook/ebook-test-utils.h
index 02f8bc3..4595f7d 100644
--- a/addressbook/tests/ebook/ebook-test-utils.h
+++ b/addressbook/tests/ebook/ebook-test-utils.h
@@ -86,6 +86,13 @@ ebook_test_utils_book_async_get_required_fields (EBook       *book,
                                                  GSourceFunc  callback,
                                                  gpointer     user_data);
 
+GList*
+ebook_test_utils_book_get_supported_fields (EBook *book);
+void
+ebook_test_utils_book_async_get_supported_fields (EBook       *book,
+						  GSourceFunc  callback,
+                                                  gpointer     user_data);
+
 const char*
 ebook_test_utils_book_get_static_capabilities (EBook *book);
 
diff --git a/addressbook/tests/ebook/test-ebook-get-supported-fields.c b/addressbook/tests/ebook/test-ebook-get-supported-fields.c
new file mode 100644
index 0000000..69caa79
--- /dev/null
+++ b/addressbook/tests/ebook/test-ebook-get-supported-fields.c
@@ -0,0 +1,75 @@
+/* -*- 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 void
+list_member_print_and_free (char     *member,
+		            gpointer  user_data)
+{
+	g_print ("    %s\n", member);
+	g_free (member);
+}
+
+static void
+get_supported_fields_cb (EBookTestClosure *closure)
+{
+	/* XXX: assuming an empty list is valid, we'll just print out anything
+	 * we do get */
+	if (closure->list) {
+		EIterator *iter;
+		const char *field;
+
+		g_print ("supported fields:\n");
+		iter = e_list_get_iterator (closure->list);
+		while ((field = e_iterator_get (iter))) {
+			g_print ("    %s\n", field);
+			e_iterator_next (iter);
+		}
+		g_print ("----------------\n");
+	}
+
+	g_object_unref (closure->list);
+
+	g_main_loop_quit ((GMainLoop*) (closure->user_data));
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+	EBook *book;
+	GMainLoop *loop;
+	GList *fields;
+
+	g_type_init ();
+
+	/*
+	 * Setup
+	 */
+	book = ebook_test_utils_book_new_temp (NULL);
+	ebook_test_utils_book_open (book, FALSE);
+
+	/*
+	 * Sync version
+	 */
+	fields = ebook_test_utils_book_get_supported_fields (book);
+
+	g_print ("successfully retrieved supported fields:\n");
+	g_list_foreach (fields, (GFunc) list_member_print_and_free, NULL);
+	g_list_free (fields);
+
+	/*
+	 * Async version
+	 */
+	loop = g_main_loop_new (NULL, TRUE);
+	ebook_test_utils_book_async_get_supported_fields (book,
+			(GSourceFunc) get_supported_fields_cb, loop);
+
+	g_main_loop_run (loop);
+
+	ebook_test_utils_book_remove (book);
+
+	return 0;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]