summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Reitter <treitter@gmail.com>2009-12-16 16:50:18 -0800
committerTravis Reitter <treitter@gmail.com>2009-12-16 17:03:25 -0800
commit28b1329cc8f0668ace35413ea2d7c8698a5ccbf3 (patch)
tree1aafbfe8c241de6623b920f3165ec4065b2ad798
parent305abdd9bc7c9caa5986a1e46d705e2b213270bc (diff)
downloadevolution-data-server-28b1329cc8f0668ace35413ea2d7c8698a5ccbf3.tar.gz
Port the EDataCal D-Bus methods 'open' and 'isReadOnly' to gdbus; add another regression test for 'open'.
-rw-r--r--calendar/libecal/Makefile.am1
-rw-r--r--calendar/libecal/e-cal.c16
-rw-r--r--calendar/libecal/e-data-cal-gdbus-bindings.h105
-rw-r--r--calendar/tests/ecal/Makefile.am5
-rw-r--r--calendar/tests/ecal/ecal-test-utils.c48
-rw-r--r--calendar/tests/ecal/ecal-test-utils.h11
-rw-r--r--calendar/tests/ecal/test-ecal-open.c57
7 files changed, 236 insertions, 7 deletions
diff --git a/calendar/libecal/Makefile.am b/calendar/libecal/Makefile.am
index 9254ed78b..98e316681 100644
--- a/calendar/libecal/Makefile.am
+++ b/calendar/libecal/Makefile.am
@@ -59,6 +59,7 @@ libecalinclude_HEADERS = \
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libecal-$(API_VERSION).pc
+# FIXME: cut e-data-cal-bindings.h
DBUS_GENERATED_H = e-data-cal-bindings.h e-data-cal-view-bindings.h
%-bindings.h: $(top_srcdir)/calendar/libedata-cal/%.xml
diff --git a/calendar/libecal/e-cal.c b/calendar/libecal/e-cal.c
index e5cc2992c..00365bf17 100644
--- a/calendar/libecal/e-cal.c
+++ b/calendar/libecal/e-cal.c
@@ -45,7 +45,9 @@
#include "e-cal-view-private.h"
#include "e-cal.h"
#include "e-data-cal-factory-gdbus-bindings.h"
+/* FIXME: cut this */
#include "e-data-cal-bindings.h"
+#include "e-data-cal-gdbus-bindings.h"
#include <libedata-cal/e-data-cal-types.h>
static DBusGConnection *connection = NULL;
@@ -1155,7 +1157,9 @@ build_pass_key (ECal *ecal)
}
static void
-async_signal_idle_cb (DBusGProxy *proxy, GError *error, gpointer user_data)
+async_signal_idle_cb (GDBusProxy *proxy,
+ GError *error,
+ gpointer user_data)
{
ECal *ecal;
ECalendarStatus status;
@@ -1169,7 +1173,7 @@ async_signal_idle_cb (DBusGProxy *proxy, GError *error, gpointer user_data)
} else {
status = E_CALENDAR_STATUS_OK;
LOCK_CONN ();
- org_gnome_evolution_dataserver_calendar_Cal_is_read_only (ecal->priv->proxy, NULL);
+ e_data_cal_gdbus_is_read_only_sync (ecal->priv->gdbus_proxy, NULL);
UNLOCK_CONN ();
}
@@ -1185,7 +1189,7 @@ open_calendar (ECal *ecal, gboolean only_if_exists, GError **error, ECalendarSta
e_return_error_if_fail (ecal != NULL, E_CALENDAR_STATUS_INVALID_ARG);
e_return_error_if_fail (E_IS_CAL (ecal), E_CALENDAR_STATUS_INVALID_ARG);
priv = ecal->priv;
- e_return_error_if_fail (priv->proxy, E_CALENDAR_STATUS_REPOSITORY_OFFLINE);
+ e_return_error_if_fail (priv->gdbus_proxy, E_CALENDAR_STATUS_REPOSITORY_OFFLINE);
if (!needs_auth && priv->load_state == E_CAL_LOAD_LOADED) {
return TRUE;
@@ -1255,12 +1259,12 @@ open_calendar (ECal *ecal, gboolean only_if_exists, GError **error, ECalendarSta
*status = E_CALENDAR_STATUS_OK;
if (!async) {
LOCK_CONN ();
- if (!org_gnome_evolution_dataserver_calendar_Cal_open (priv->proxy, only_if_exists, username ? username : "", password ? password : "", error))
+ if (!e_data_cal_gdbus_open_sync (priv->gdbus_proxy, only_if_exists, username ? username : "", password ? password : "", error))
*status = E_CALENDAR_STATUS_CORBA_EXCEPTION;
UNLOCK_CONN ();
} else {
LOCK_CONN ();
- if (!org_gnome_evolution_dataserver_calendar_Cal_open_async (priv->proxy, only_if_exists, username ? username : "", password ? password : "", async_signal_idle_cb, ecal))
+ if (!e_data_cal_gdbus_open (priv->gdbus_proxy, only_if_exists, username ? username : "", password ? password : "", async_signal_idle_cb, ecal))
*status = E_CALENDAR_STATUS_CORBA_EXCEPTION;
UNLOCK_CONN ();
}
@@ -1274,7 +1278,7 @@ open_calendar (ECal *ecal, gboolean only_if_exists, GError **error, ECalendarSta
if (!async) {
LOCK_CONN ();
- org_gnome_evolution_dataserver_calendar_Cal_is_read_only (priv->proxy, &error);
+ e_data_cal_gdbus_is_read_only_sync (priv->gdbus_proxy, &error);
UNLOCK_CONN ();
}
} else {
diff --git a/calendar/libecal/e-data-cal-gdbus-bindings.h b/calendar/libecal/e-data-cal-gdbus-bindings.h
new file mode 100644
index 000000000..d2b816358
--- /dev/null
+++ b/calendar/libecal/e-data-cal-gdbus-bindings.h
@@ -0,0 +1,105 @@
+/* -*- 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)
+ */
+
+#include <glib.h>
+#include <gdbus/gdbus.h>
+
+#include <libedata-gdbus-bindings/e-data-gdbus-bindings-common.h>
+
+G_BEGIN_DECLS
+
+/* FIXME: These bindings were created manually; replace with generated bindings
+ * when possible */
+
+static gboolean
+e_data_cal_gdbus_is_read_only_sync (GDBusProxy *proxy,
+ GError **error)
+{
+ GVariant *parameters;
+ GVariant *retvals;
+
+ parameters = g_variant_new ("()");
+ retvals = g_dbus_proxy_invoke_method_sync (proxy, "isReadOnly",
+ parameters, -1, NULL, error);
+
+ return demarshal_retvals__VOID (retvals);
+}
+
+static gboolean
+e_data_cal_gdbus_open_sync (GDBusProxy *proxy,
+ const gboolean IN_only_if_exists,
+ const char *IN_username,
+ const char *IN_password,
+ GError **error)
+{
+ GVariant *parameters;
+ GVariant *retvals;
+
+ parameters = g_variant_new ("(bss)", IN_only_if_exists, IN_username, IN_password);
+ retvals = g_dbus_proxy_invoke_method_sync (proxy, "open", parameters,
+ -1, NULL, error);
+
+ return demarshal_retvals__VOID (retvals);
+}
+
+static void
+open_cb (GDBusProxy *proxy,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ Closure *closure = user_data;
+ GVariant *retvals;
+ GError *error = NULL;
+
+ retvals = g_dbus_proxy_invoke_method_finish (proxy, result, &error);
+ if (retvals) {
+ if (!demarshal_retvals__VOID (retvals)) {
+ error = g_error_new (E_CALENDAR_ERROR, E_CALENDAR_STATUS_CORBA_EXCEPTION, "demarshalling results for Calendar method 'open'");
+ }
+ }
+
+ (*(reply__VOID)closure->cb) (proxy, error, closure->user_data);
+ closure_free (closure);
+}
+
+static gboolean
+e_data_cal_gdbus_open (GDBusProxy *proxy,
+ const gboolean IN_only_if_exists,
+ const char *IN_username,
+ const char *IN_password,
+ reply__VOID callback,
+ gpointer user_data)
+{
+ GVariant *parameters;
+ Closure *closure;
+
+ parameters = g_variant_new ("(bss)", IN_only_if_exists, IN_username, IN_password);
+
+ closure = g_slice_new (Closure);
+ closure->cb = G_CALLBACK (callback);
+ closure->user_data = user_data;
+
+ g_dbus_proxy_invoke_method (proxy, "open", parameters, -1, NULL, (GAsyncReadyCallback) open_cb, closure);
+
+ return TRUE;
+}
+
+G_END_DECLS
diff --git a/calendar/tests/ecal/Makefile.am b/calendar/tests/ecal/Makefile.am
index 0ba89f8f7..8d87c49e9 100644
--- a/calendar/tests/ecal/Makefile.am
+++ b/calendar/tests/ecal/Makefile.am
@@ -31,7 +31,8 @@ test_scripts = \
cleanup.sh
TESTS = \
- test-ecal-remove \
+ test-ecal-remove \
+ test-ecal-open \
$(NULL)
# The test program
@@ -41,6 +42,8 @@ TEST_ECAL_CPPFLAGS= \
$(libecal_test_utils_la_CPPFLAGS) \
$(NULL)
+test_ecal_open_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_open_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
test_ecal_remove_LDADD=$(TEST_ECAL_LIBS)
test_ecal_remove_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
diff --git a/calendar/tests/ecal/ecal-test-utils.c b/calendar/tests/ecal/ecal-test-utils.c
index a08193d87..185e71f6c 100644
--- a/calendar/tests/ecal/ecal-test-utils.c
+++ b/calendar/tests/ecal/ecal-test-utils.c
@@ -80,6 +80,54 @@ ecal_test_utils_cal_open (ECal *cal,
}
}
+static void
+open_cb (ECal *cal,
+ ECalendarStatus status,
+ ECalTestClosure *closure)
+{
+ if (FALSE) {
+ } else if (status == E_CALENDAR_STATUS_BUSY) {
+ g_print ("calendar server is busy; waiting...");
+ return;
+ } else if (status != E_CALENDAR_STATUS_OK) {
+ g_warning ("failed to asynchronously remove the calendar: "
+ "status %d", status);
+ exit (1);
+ }
+
+ g_print ("successfully asynchronously removed the temporary "
+ "calendar\n");
+ if (closure)
+ (*closure->cb) (closure);
+
+ g_signal_handlers_disconnect_by_func (cal, open_cb, closure);
+ g_free (closure);
+}
+
+void
+ecal_test_utils_cal_async_open (ECal *cal,
+ gboolean only_if_exists,
+ GSourceFunc callback,
+ gpointer user_data)
+{
+ ECalTestClosure *closure;
+
+ closure = g_new0 (ECalTestClosure, 1);
+ closure->cb = callback;
+ closure->user_data = user_data;
+
+ g_signal_connect (G_OBJECT (cal), "cal_opened", G_CALLBACK (open_cb), closure);
+ e_cal_open_async (cal, only_if_exists);
+
+ /* FIXME: cut this
+ if (FALSE)
+ {
+ g_warning ("failed to set up cal removal");
+ exit(1);
+ }
+ */
+}
+
void
ecal_test_utils_cal_remove (ECal *cal)
{
diff --git a/calendar/tests/ecal/ecal-test-utils.h b/calendar/tests/ecal/ecal-test-utils.h
index 38b3f0fd4..ed5104291 100644
--- a/calendar/tests/ecal/ecal-test-utils.h
+++ b/calendar/tests/ecal/ecal-test-utils.h
@@ -25,6 +25,11 @@
#include <glib.h>
#include <libecal/e-cal.h>
+typedef struct {
+ GSourceFunc cb;
+ gpointer user_data;
+} ECalTestClosure;
+
ECal*
ecal_test_utils_cal_new_temp (char **uri,
ECalSourceType type);
@@ -34,6 +39,12 @@ ecal_test_utils_cal_open (ECal *cal,
gboolean only_if_exists);
void
+ecal_test_utils_cal_async_open (ECal *cal,
+ gboolean only_if_exists,
+ GSourceFunc callback,
+ gpointer user_data);
+
+void
ecal_test_utils_cal_remove (ECal *cal);
#endif /* _ECAL_TEST_UTILS_H */
diff --git a/calendar/tests/ecal/test-ecal-open.c b/calendar/tests/ecal/test-ecal-open.c
new file mode 100644
index 000000000..13637319f
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-open.c
@@ -0,0 +1,57 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libecal/e-cal.h>
+
+#include "ecal-test-utils.h"
+
+#define OPEN_ASYNC_TIMEOUT 30
+
+static void open_timeout_cb (gpointer user_data) __attribute__ ((noreturn));
+
+static guint open_timeout_id = 0;
+
+static void
+open_complete_cb (ECalTestClosure *closure)
+{
+ g_source_remove (open_timeout_id);
+
+ g_main_loop_quit ((GMainLoop*) closure->user_data);
+}
+
+static void
+open_timeout_cb (gpointer user_data)
+{
+ g_warning ("failed to get a response for the async 'open' within a "
+ "reasonable time frame");
+ exit (1);
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ ECal *cal;
+ char *uri = NULL;
+ GMainLoop *loop;
+
+ g_type_init ();
+
+ /* Sync version */
+ cal = ecal_test_utils_cal_new_temp (&uri, E_CAL_SOURCE_TYPE_EVENT);
+ ecal_test_utils_cal_open (cal, FALSE);
+ ecal_test_utils_cal_remove (cal);
+
+ /* Async version */
+ cal = ecal_test_utils_cal_new_temp (&uri, E_CAL_SOURCE_TYPE_EVENT);
+ open_timeout_id = g_timeout_add_seconds (OPEN_ASYNC_TIMEOUT,
+ (GSourceFunc) open_timeout_cb, cal);
+
+ loop = g_main_loop_new (NULL, TRUE);
+ ecal_test_utils_cal_async_open (cal, FALSE,
+ (GSourceFunc) open_complete_cb, loop);
+ g_main_loop_run (loop);
+
+ ecal_test_utils_cal_remove (cal);
+
+ return 0;
+}