[evolution-data-server/treitter-client-gdbus] Port the e-book 'getSupportedAuthMethods' method to gdbus and add a regression test.



commit d5fce962c91e6505754adff9c5dbed409598c566
Author: Travis Reitter <treitter gmail com>
Date:   Thu Dec 10 15:53:06 2009 -0800

    Port the e-book 'getSupportedAuthMethods' method to gdbus and add a regression test.

 addressbook/libebook/e-book.c                      |   13 ++--
 addressbook/libebook/e-data-book-gdbus-bindings.h  |   57 +++++++++++++++
 addressbook/tests/ebook/Makefile.am                |   53 +++++++-------
 addressbook/tests/ebook/ebook-test-utils.c         |   59 +++++++++++++++
 addressbook/tests/ebook/ebook-test-utils.h         |    7 ++
 .../ebook/test-ebook-get-supported-auth-methods.c  |   76 ++++++++++++++++++++
 6 files changed, 235 insertions(+), 30 deletions(-)
---
diff --git a/addressbook/libebook/e-book.c b/addressbook/libebook/e-book.c
index 3a4da20..fc96a22 100644
--- a/addressbook/libebook/e-book.c
+++ b/addressbook/libebook/e-book.c
@@ -734,10 +734,10 @@ e_book_get_supported_auth_methods (EBook            *book,
 	gchar **list = NULL;
 
 	e_return_error_if_fail (E_IS_BOOK (book), E_BOOK_ERROR_INVALID_ARG);
-	e_return_error_if_fail (book->priv->proxy, E_BOOK_ERROR_REPOSITORY_OFFLINE);
+	e_return_error_if_fail (book->priv->gdbus_proxy, E_BOOK_ERROR_REPOSITORY_OFFLINE);
 
 	LOCK_CONN ();
-	org_gnome_evolution_dataserver_addressbook_Book_get_supported_auth_methods (book->priv->proxy, &list, &err);
+	e_data_book_gdbus_get_supported_auth_methods_sync (book->priv->gdbus_proxy, &list, &err);
 	UNLOCK_CONN ();
 	if (list) {
 		*auth_methods = array_to_stringlist (list);
@@ -748,7 +748,10 @@ e_book_get_supported_auth_methods (EBook            *book,
 }
 
 static void
-get_supported_auth_methods_reply(DBusGProxy *proxy, gchar **methods, GError *error, gpointer user_data)
+get_supported_auth_methods_reply (GDBusProxy  *proxy,
+				  gchar      **methods,
+				  GError      *error,
+				  gpointer     user_data)
 {
 	AsyncData *data = user_data;
 	EBookEListCallback cb = data->callback;
@@ -790,7 +793,7 @@ e_book_async_get_supported_auth_methods (EBook              *book,
 	AsyncData *data;
 
 	e_return_async_error_val_if_fail (E_IS_BOOK (book), E_BOOK_ERROR_INVALID_ARG);
-	e_return_async_error_val_if_fail (book->priv->proxy, E_BOOK_ERROR_REPOSITORY_OFFLINE);
+	e_return_async_error_val_if_fail (book->priv->gdbus_proxy, E_BOOK_ERROR_REPOSITORY_OFFLINE);
 
 	data = g_slice_new0 (AsyncData);
 	data->book = g_object_ref (book);
@@ -798,7 +801,7 @@ e_book_async_get_supported_auth_methods (EBook              *book,
 	data->closure = closure;
 
 	LOCK_CONN ();
-	org_gnome_evolution_dataserver_addressbook_Book_get_supported_auth_methods_async (book->priv->proxy, get_supported_auth_methods_reply, data);
+	e_data_book_gdbus_get_supported_auth_methods (book->priv->gdbus_proxy, get_supported_auth_methods_reply, data);
 	UNLOCK_CONN ();
 
 	return 0;
diff --git a/addressbook/libebook/e-data-book-gdbus-bindings.h b/addressbook/libebook/e-data-book-gdbus-bindings.h
index 8ecd98f..1e0984e 100644
--- a/addressbook/libebook/e-data-book-gdbus-bindings.h
+++ b/addressbook/libebook/e-data-book-gdbus-bindings.h
@@ -384,6 +384,63 @@ e_data_book_gdbus_get_required_fields (GDBusProxy
 }
 
 static gboolean
+e_data_book_gdbus_get_supported_auth_methods_sync (GDBusProxy   *proxy,
+						   char       ***OUT_methods,
+						   GError      **error)
+{
+	GVariant *parameters;
+	GVariant *retvals;
+
+	parameters = g_variant_new ("()");
+	retvals = g_dbus_proxy_invoke_method_sync (proxy, "getSupportedAuthMethods", parameters, -1, NULL, error);
+
+	return demarshal_retvals__STRINGVECTOR (retvals, OUT_methods);
+}
+
+typedef void (*e_data_book_gdbus_get_supported_auth_methods_reply) (GDBusProxy  *proxy,
+								    char       **OUT_methods,
+								    GError      *error,
+								    gpointer     user_data);
+
+static void
+get_supported_auth_methods_cb (GDBusProxy   *proxy,
+			       GAsyncResult *result,
+			       gpointer      user_data)
+{
+        Closure *closure = user_data;
+        GVariant *retvals;
+        GError *error = NULL;
+        char **OUT_methods = NULL;
+
+        retvals = g_dbus_proxy_invoke_method_finish (proxy, result, &error);
+	if (retvals) {
+		if (!demarshal_retvals__STRINGVECTOR (retvals, &OUT_methods)) {
+			error = g_error_new (E_BOOK_ERROR, E_BOOK_ERROR_CORBA_EXCEPTION, "demarshalling results for Book method 'getSupportedAuthMethods'");
+		}
+	}
+
+	(*(e_data_book_gdbus_get_supported_auth_methods_reply) closure->cb) (proxy, OUT_methods, error, closure->user_data);
+	closure_free (closure);
+}
+
+static void
+e_data_book_gdbus_get_supported_auth_methods (GDBusProxy                                         *proxy,
+					      e_data_book_gdbus_get_supported_auth_methods_reply  callback,
+					      gpointer                                            user_data)
+{
+        GVariant *parameters;
+        Closure *closure;
+
+        parameters = g_variant_new ("()");
+
+        closure = g_slice_new (Closure);
+        closure->cb = G_CALLBACK (callback);
+        closure->user_data = user_data;
+
+        g_dbus_proxy_invoke_method (proxy, "getSupportedAuthMethods", parameters, -1, NULL, (GAsyncReadyCallback) get_supported_auth_methods_cb, closure);
+}
+
+static gboolean
 e_data_book_gdbus_get_supported_fields_sync (GDBusProxy   *proxy,
 					    char       ***OUT_fields,
 					    GError      **error)
diff --git a/addressbook/tests/ebook/Makefile.am b/addressbook/tests/ebook/Makefile.am
index 768eebb..cf59876 100644
--- a/addressbook/tests/ebook/Makefile.am
+++ b/addressbook/tests/ebook/Makefile.am
@@ -22,31 +22,32 @@ TEST_LIBS =							\
 	$(NULL)
 
 noinst_PROGRAMS = \
-	test-changes                         \
-	test-categories                      \
-	test-date                            \
-	test-ebook                           \
-	test-ebook-async                     \
-	test-ebook-add-contact               \
-	test-ebook-commit-contact            \
-	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      \
-	test-ebook-remove-contacts           \
-	test-ebook-view                      \
-	test-nonexistent-id                  \
-	test-photo                           \
-	test-query                           \
-	test-self                            \
-	test-string                          \
-	test-undefinedfield                  \
-	test-untyped-phones                  \
-	test-search                          \
-	test-stress-bookviews                \
+	test-changes				     \
+	test-categories				     \
+	test-date				     \
+	test-ebook				     \
+	test-ebook-async			     \
+	test-ebook-add-contact			     \
+	test-ebook-commit-contact		     \
+	test-ebook-get-contact			     \
+	test-ebook-get-required-fields		     \
+	test-ebook-get-static-capabilities	     \
+	test-ebook-get-supported-fields		     \
+	test-ebook-get-supported-auth-methods	     \
+	test-ebook-remove			     \
+	test-ebook-remove-contact		     \
+	test-ebook-remove-contact-by-id		     \
+	test-ebook-remove-contacts		     \
+	test-ebook-view				     \
+	test-nonexistent-id			     \
+	test-photo				     \
+	test-query				     \
+	test-self				     \
+	test-string				     \
+	test-undefinedfield			     \
+	test-untyped-phones			     \
+	test-search				     \
+	test-stress-bookviews			     \
 	$(NULL)
 
 TEST_CPPFLAGS= \
@@ -71,6 +72,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_auth_methods_LDADD=$(TEST_LIBS)
+test_ebook_get_supported_auth_methods_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)
diff --git a/addressbook/tests/ebook/ebook-test-utils.c b/addressbook/tests/ebook/ebook-test-utils.c
index bb5b145..b4b3083 100644
--- a/addressbook/tests/ebook/ebook-test-utils.c
+++ b/addressbook/tests/ebook/ebook-test-utils.c
@@ -337,6 +337,65 @@ ebook_test_utils_book_get_static_capabilities (EBook *book)
 }
 
 GList*
+ebook_test_utils_book_get_supported_auth_methods (EBook *book)
+{
+        GList *fields = NULL;
+        GError *error = NULL;
+
+        if (!e_book_get_supported_auth_methods (book, &fields, &error)) {
+                const char *uri;
+
+                uri = e_book_get_uri (book);
+                g_warning ("failed to get supported auth methods for "
+                                "addressbook `%s': %s", uri, error->message);
+                exit(1);
+        }
+
+        return fields;
+}
+
+static void
+get_supported_auth_methods_cb (EBook            *book,
+                               EBookStatus       status,
+                               EList            *methods,
+                               EBookTestClosure *closure)
+{
+        if (status != E_BOOK_ERROR_OK) {
+                g_warning ("failed to asynchronously get the supported auth "
+                                "methods: status %d", status);
+                exit (1);
+        }
+
+        closure->list = methods;
+
+        g_print ("successfully asynchronously retrieved the supported auth "
+                        "methods\n");
+
+        if (closure) {
+                (*closure->cb) (closure);
+                g_free (closure);
+        }
+}
+
+void
+ebook_test_utils_book_async_get_supported_auth_methods (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_auth_methods (book,
+                                (EBookEListCallback) get_supported_auth_methods_cb,
+                                closure)) {
+                g_warning ("failed to set up async getSupportedAuthMethods");
+                exit(1);
+        }
+}
+
+GList*
 ebook_test_utils_book_get_supported_fields (EBook *book)
 {
         GList *fields = NULL;
diff --git a/addressbook/tests/ebook/ebook-test-utils.h b/addressbook/tests/ebook/ebook-test-utils.h
index 4595f7d..c6d9d08 100644
--- a/addressbook/tests/ebook/ebook-test-utils.h
+++ b/addressbook/tests/ebook/ebook-test-utils.h
@@ -93,6 +93,13 @@ ebook_test_utils_book_async_get_supported_fields (EBook       *book,
 						  GSourceFunc  callback,
                                                   gpointer     user_data);
 
+GList*
+ebook_test_utils_book_get_supported_auth_methods (EBook *book);
+void
+ebook_test_utils_book_async_get_supported_auth_methods (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-auth-methods.c b/addressbook/tests/ebook/test-ebook-get-supported-auth-methods.c
new file mode 100644
index 0000000..d557b95
--- /dev/null
+++ b/addressbook/tests/ebook/test-ebook-get-supported-auth-methods.c
@@ -0,0 +1,76 @@
+/* -*- 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_auth_methods_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 auth methods:\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 *auth_methods;
+
+	g_type_init ();
+
+	/*
+	 * Setup
+	 */
+	book = ebook_test_utils_book_new_temp (NULL);
+	ebook_test_utils_book_open (book, FALSE);
+
+	/*
+	 * Sync version
+	 */
+	auth_methods = ebook_test_utils_book_get_supported_auth_methods (book);
+
+	g_print ("successfully retrieved supported auth methods:\n");
+	g_list_foreach (auth_methods, (GFunc) list_member_print_and_free, NULL);
+	g_print ("----------------\n");
+	g_list_free (auth_methods);
+
+	/*
+	 * Async version
+	 */
+	loop = g_main_loop_new (NULL, TRUE);
+	ebook_test_utils_book_async_get_supported_auth_methods (book,
+			(GSourceFunc) get_supported_auth_methods_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]