[evolution-data-server/treitter-client-gdbus] Begin factoring out ebook test functions
- From: Travis Reitter <treitter src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-data-server/treitter-client-gdbus] Begin factoring out ebook test functions
- Date: Fri, 4 Dec 2009 01:44:45 +0000 (UTC)
commit 2473e28696b4aca6f15765b3ceb3d702e680d399
Author: Travis Reitter <treitter gmail com>
Date: Thu Dec 3 09:03:18 2009 -0800
Begin factoring out ebook test functions
addressbook/libebook/e-data-book-gdbus-bindings.h | 84 +++++++++++++++++++++
addressbook/tests/ebook/Makefile.am | 50 ++++++++++--
addressbook/tests/ebook/ebook-test-utils.c | 38 +++++++++
addressbook/tests/ebook/ebook-test-utils.h | 29 +++++++
addressbook/tests/ebook/test-changes.c | 25 +------
addressbook/tests/ebook/test-ebook-remove.c | 38 +--------
6 files changed, 199 insertions(+), 65 deletions(-)
---
diff --git a/addressbook/libebook/e-data-book-gdbus-bindings.h b/addressbook/libebook/e-data-book-gdbus-bindings.h
index 00e84c7..bc09d79 100644
--- a/addressbook/libebook/e-data-book-gdbus-bindings.h
+++ b/addressbook/libebook/e-data-book-gdbus-bindings.h
@@ -159,4 +159,88 @@ e_data_book_gdbus_remove (GDBusProxy *proxy,
g_dbus_proxy_invoke_method (proxy, "remove", parameters, -1, NULL, (GAsyncReadyCallback) remove_cb, closure);
}
+static gboolean
+get_contact_demarshal_retvals (GVariant *retvals, char **OUT_vcard)
+{
+ gboolean success = TRUE;
+
+ if (retvals) {
+ const char *vcard = NULL;
+
+ g_variant_get (retvals, "(s)", &vcard);
+ if (vcard) {
+ *OUT_vcard = g_strdup (vcard);
+ } else {
+ success = FALSE;
+ }
+
+ g_variant_unref (retvals);
+ } else {
+ success = FALSE;
+ }
+
+ return success;
+}
+
+static gboolean
+e_data_book_gdbus_get_contact_sync (GDBusProxy *proxy,
+ char **IN_uid,
+ char **OUT_vcard,
+ GError **error)
+
+{
+ GVariant *parameters;
+ GVariant *retvals;
+
+ parameters = g_variant_new ("(s)", IN_uid);
+ retvals = g_dbus_proxy_invoke_method_sync (proxy, "getContact", parameters, -1, NULL, error);
+
+ return get_contact_demarshal_retvals (retvals, OUT_vcard);
+}
+
+typedef void (*e_data_book_gdbus_get_contact_reply) (GDBusProxy *proxy,
+ char *OUT_vcard,
+ GError *error,
+ gpointer user_data);
+
+static void
+get_contact_cb (GDBusProxy *proxy,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ Closure *closure = user_data;
+ GVariant *retvals;
+ GError *error = NULL;
+ char *OUT_vcard = NULL;
+
+ retvals = g_dbus_proxy_invoke_method_finish (proxy, result, &error);
+ if (retvals) {
+ if (!get_contact_demarshal_retvals (retvals, &OUT_vcard)) {
+ error = g_error_new (E_BOOK_ERROR, E_BOOK_ERROR_CORBA_EXCEPTION, "demarshalling results for Book method 'getContact'");
+ }
+ }
+
+ (*(e_data_book_gdbus_get_contact_reply) closure->cb) (proxy, OUT_vcard, error, closure->user_data);
+ closure_free (closure);
+}
+
+static void
+e_data_book_factory_gdbus_get_contact (GDBusProxy *proxy,
+ const char *IN_uid,
+ e_data_book_gdbus_get_contact_reply callback,
+ gpointer user_data)
+{
+ GVariant *parameters;
+ Closure *closure;
+
+ parameters = g_variant_new ("(s)", IN_uid);
+
+ closure = g_slice_new (Closure);
+ closure->cb = G_CALLBACK (callback);
+ closure->user_data = user_data;
+
+ g_dbus_proxy_invoke_method (proxy, "getContact", parameters, -1, NULL, (GAsyncReadyCallback*) get_contact_cb, closure);
+}
+
+
G_END_DECLS
diff --git a/addressbook/tests/ebook/Makefile.am b/addressbook/tests/ebook/Makefile.am
index edf55df..b0b95dc 100644
--- a/addressbook/tests/ebook/Makefile.am
+++ b/addressbook/tests/ebook/Makefile.am
@@ -1,16 +1,48 @@
-TEST_LIBS= \
+noinst_LTLIBRARIES = libebook-test-utils.la
+libebook_test_utils_la_SOURCES = ebook-test-utils.c ebook-test-utils.h
+
+# FIXME: reduct redundancy
+libebook_test_utils_la_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ -I$(top_srcdir)/addressbook \
+ -I$(top_builddir)/addressbook \
+ $(EVOLUTION_ADDRESSBOOK_CFLAGS) \
+ $(NULL)
+
+libebook_test_utils_la_LIBADD = \
$(top_builddir)/addressbook/libebook/libebook-1.2.la \
- $(EVOLUTION_ADDRESSBOOK_LIBS)
+ $(EVOLUTION_ADDRESSBOOK_LIBS) \
+ $(NULL)
+
+TEST_LIBS = \
+ $(libebook_test_utils_la_LIBADD) \
+ libebook-test-utils.la \
+ $(NULL)
-noinst_PROGRAMS = test-changes test-categories test-date test-ebook test-ebook-async test-ebook-remove test-ebook-view test-nonexistent-id test-photo test-query test-self test-string test-undefinedfield test-untyped-phones test-search test-stress-bookviews
+noinst_PROGRAMS = \
+ test-changes \
+ test-categories \
+ test-date \
+ test-ebook \
+ test-ebook-async \
+ test-ebook-remove \
+ 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= \
- $(AM_CPPFLAGS) \
- -I$(top_srcdir) \
- -I$(top_builddir) \
- -I$(top_srcdir)/addressbook \
- -I$(top_builddir)/addressbook \
- $(EVOLUTION_ADDRESSBOOK_CFLAGS)
+ $(libebook_test_utils_la_CPPFLAGS) \
+ $(NULL)
test_search_LDADD=$(TEST_LIBS)
test_search_CPPFLAGS=$(TEST_CPPFLAGS)
diff --git a/addressbook/tests/ebook/ebook-test-utils.c b/addressbook/tests/ebook/ebook-test-utils.c
new file mode 100644
index 0000000..d3c10a1
--- /dev/null
+++ b/addressbook/tests/ebook/ebook-test-utils.c
@@ -0,0 +1,38 @@
+/* -*- 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"
+
+EBook*
+ebook_test_utils_create_temp_addressbook (char **uri)
+{
+ EBook *book;
+ GError *error = NULL;
+ gchar *file_template;
+
+ file_template = g_build_filename (g_get_tmp_dir (),
+ "ebook-test-XXXXXX/",
+ NULL);
+ g_mkstemp (file_template);
+
+ *uri = g_filename_to_uri (file_template, NULL, &error);
+ if (!*uri) {
+ printf ("failed to convert %s to an URI: %s\n",
+ file_template, error->message);
+ exit (1);
+ }
+ g_free (file_template);
+
+ /* create a temp addressbook in /tmp */
+ printf ("loading addressbook\n");
+ book = e_book_new_from_uri (*uri, &error);
+ if (!book) {
+ printf ("failed to create addressbook: `%s': %s\n",
+ *uri, error->message);
+ exit(1);
+ }
+
+ return book;
+}
diff --git a/addressbook/tests/ebook/ebook-test-utils.h b/addressbook/tests/ebook/ebook-test-utils.h
new file mode 100644
index 0000000..d1e8daa
--- /dev/null
+++ b/addressbook/tests/ebook/ebook-test-utils.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Travis Reitter (travis reitter collabora co uk)
+ */
+
+#ifndef _EBOOK_TEST_UTILS_H
+#define _EBOOK_TEST_UTILS_H
+
+#include <libebook/e-book.h>
+
+EBook* ebook_test_utils_create_temp_addressbook (char **uri);
+
+#endif /* _EBOOK_TEST_UTILS_H */
diff --git a/addressbook/tests/ebook/test-changes.c b/addressbook/tests/ebook/test-changes.c
index e5a339e..0836e38 100644
--- a/addressbook/tests/ebook/test-changes.c
+++ b/addressbook/tests/ebook/test-changes.c
@@ -3,6 +3,8 @@
#include <stdlib.h>
#include <libebook/e-book.h>
+#include "ebook-test-utils.h"
+
#define NEW_VCARD "BEGIN:VCARD\n\
X-EVOLUTION-FILE-AS:Toshok, Chris\n\
FN:Chris Toshok\n\
@@ -18,32 +20,11 @@ main (gint argc, gchar **argv)
GList *changes;
GError *error = NULL;
EBookChange *change;
- gchar *file_template;
gchar *uri;
g_type_init ();
- file_template = g_build_filename (g_get_tmp_dir (),
- "change-test-XXXXXX",
- NULL);
- g_mkstemp (file_template);
-
- uri = g_filename_to_uri (file_template, NULL, &error);
- if (!uri) {
- printf ("failed to convert %s to an URI: %s\n",
- file_template, error->message);
- exit (0);
- }
- g_free (file_template);
-
- /* create a temp addressbook in /tmp */
- printf ("loading addressbook\n");
- book = e_book_new_from_uri (uri, &error);
- if (!book) {
- printf ("failed to create addressbook: `%s': %s\n",
- uri, error->message);
- exit(0);
- }
+ book = ebook_test_utils_create_temp_addressbook (&uri);
if (!e_book_open (book, FALSE, &error)) {
printf ("failed to open addressbook: `%s': %s\n",
diff --git a/addressbook/tests/ebook/test-ebook-remove.c b/addressbook/tests/ebook/test-ebook-remove.c
index b9fea7a..ebe5120 100644
--- a/addressbook/tests/ebook/test-ebook-remove.c
+++ b/addressbook/tests/ebook/test-ebook-remove.c
@@ -3,39 +3,9 @@
#include <stdlib.h>
#include <libebook/e-book.h>
-static GMainLoop *loop;
+#include "ebook-test-utils.h"
-static EBook*
-create_test_addressbook (char **uri)
-{
- EBook *book;
- GError *error = NULL;
- gchar *file_template;
-
- file_template = g_build_filename (g_get_tmp_dir (),
- "change-test-XXXXXX/",
- NULL);
- g_mkstemp (file_template);
-
- *uri = g_filename_to_uri (file_template, NULL, &error);
- if (!*uri) {
- printf ("failed to convert %s to an URI: %s\n",
- file_template, error->message);
- exit (1);
- }
- g_free (file_template);
-
- /* create a temp addressbook in /tmp */
- printf ("loading addressbook\n");
- book = e_book_new_from_uri (*uri, &error);
- if (!book) {
- printf ("failed to create addressbook: `%s': %s\n",
- *uri, error->message);
- exit(1);
- }
-
- return book;
-}
+static GMainLoop *loop;
static void
remove_cb (EBook *book, EBookStatus status, gpointer closure)
@@ -60,7 +30,7 @@ main (gint argc, gchar **argv)
g_type_init ();
/* Sync version */
- book = create_test_addressbook (&uri);
+ book = ebook_test_utils_create_temp_addressbook (&uri);
if (!e_book_open (book, FALSE, &error)) {
printf ("failed to open addressbook: `%s': %s\n",
@@ -77,7 +47,7 @@ main (gint argc, gchar **argv)
g_object_unref (book);
/* Async version */
- book = create_test_addressbook (&uri);
+ book = ebook_test_utils_create_temp_addressbook (&uri);
if (!e_book_open (book, FALSE, &error)) {
printf ("failed to open addressbook: `%s': %s\n",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]