[evolution-data-server/treitter-client-gdbus] Port EDataCal method 'setMode' and add a regression test.
- From: Travis Reitter <treitter src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-data-server/treitter-client-gdbus] Port EDataCal method 'setMode' and add a regression test.
- Date: Fri, 18 Dec 2009 01:24:45 +0000 (UTC)
commit ddd83eda103462dbeb122e1eaf041fab59987058
Author: Travis Reitter <treitter gmail com>
Date: Thu Dec 17 16:36:34 2009 -0800
Port EDataCal method 'setMode' and add a regression test.
calendar/libecal/e-cal.c | 4 +-
calendar/libecal/e-data-cal-gdbus-bindings.h | 14 ++++++
calendar/tests/ecal/Makefile.am | 3 +
calendar/tests/ecal/ecal-test-utils.c | 42 ++++++++++++++++++
calendar/tests/ecal/ecal-test-utils.h | 7 +++
calendar/tests/ecal/test-ecal-set-mode.c | 60 ++++++++++++++++++++++++++
6 files changed, 128 insertions(+), 2 deletions(-)
---
diff --git a/calendar/libecal/e-cal.c b/calendar/libecal/e-cal.c
index ee6eeca..9dc0953 100644
--- a/calendar/libecal/e-cal.c
+++ b/calendar/libecal/e-cal.c
@@ -1865,11 +1865,11 @@ e_cal_set_mode (ECal *ecal, CalMode mode)
g_return_val_if_fail (mode & CAL_MODE_ANY, FALSE);
priv = ecal->priv;
- g_return_val_if_fail (priv->proxy, FALSE);
+ g_return_val_if_fail (priv->gdbus_proxy, FALSE);
g_return_val_if_fail (priv->load_state == E_CAL_LOAD_LOADED, FALSE);
LOCK_CONN ();
- if (!org_gnome_evolution_dataserver_calendar_Cal_set_mode (priv->proxy, mode, &error)) {
+ if (!e_data_cal_gdbus_set_mode (priv->gdbus_proxy, mode, &error)) {
UNLOCK_CONN ();
g_printerr ("%s: %s\n", G_STRFUNC, error ? error->message : "Unknown error");
g_error_free (error);
diff --git a/calendar/libecal/e-data-cal-gdbus-bindings.h b/calendar/libecal/e-data-cal-gdbus-bindings.h
index 981f7f3..00a12ad 100644
--- a/calendar/libecal/e-data-cal-gdbus-bindings.h
+++ b/calendar/libecal/e-data-cal-gdbus-bindings.h
@@ -186,4 +186,18 @@ e_data_cal_gdbus_get_scheduling_information_sync (GDBusProxy *proxy,
return demarshal_retvals__STRING (retvals, caps);
}
+static gboolean
+e_data_cal_gdbus_set_mode (GDBusProxy *proxy,
+ guint mode,
+ GError **error)
+{
+ GVariant *parameters;
+ GVariant *retvals;
+
+ parameters = g_variant_new ("(u)", mode);
+ retvals = g_dbus_proxy_invoke_method_sync (proxy, "setMode", parameters, -1, NULL, error);
+
+ return demarshal_retvals__VOID (retvals);
+}
+
G_END_DECLS
diff --git a/calendar/tests/ecal/Makefile.am b/calendar/tests/ecal/Makefile.am
index 876b354..c98ee45 100644
--- a/calendar/tests/ecal/Makefile.am
+++ b/calendar/tests/ecal/Makefile.am
@@ -38,6 +38,7 @@ TESTS = \
test-ecal-get-cal-address \
test-ecal-get-ldap-attribute \
test-ecal-get-capabilities \
+ test-ecal-set-mode \
$(NULL)
# The test program
@@ -60,6 +61,8 @@ 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)
+test_ecal_set_mode_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_set_mode_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
# monolithic tests
test_ecal_SOURCES = test-ecal.c
diff --git a/calendar/tests/ecal/ecal-test-utils.c b/calendar/tests/ecal/ecal-test-utils.c
index 052243e..d399bea 100644
--- a/calendar/tests/ecal/ecal-test-utils.c
+++ b/calendar/tests/ecal/ecal-test-utils.c
@@ -262,3 +262,45 @@ ecal_test_utils_cal_get_capabilities (ECal *cal)
CAL_STATIC_CAPABILITY_HAS_UNACCEPTED_MEETING))
);
}
+
+static void
+cal_set_mode_cb (ECal *cal,
+ ECalendarStatus status,
+ CalMode mode,
+ 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);
+ }
+
+ closure->mode = mode;
+
+ g_print ("successfully set the calendar mode to %d\n", mode);
+ if (closure)
+ (*closure->cb) (closure);
+
+ g_signal_handlers_disconnect_by_func (cal, cal_set_mode_cb, closure);
+ g_free (closure);
+}
+
+void
+ecal_test_utils_cal_set_mode (ECal *cal,
+ CalMode mode,
+ 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_set_mode", G_CALLBACK (cal_set_mode_cb), closure);
+ e_cal_set_mode (cal, mode);
+}
diff --git a/calendar/tests/ecal/ecal-test-utils.h b/calendar/tests/ecal/ecal-test-utils.h
index 0fb522b..5e69a85 100644
--- a/calendar/tests/ecal/ecal-test-utils.h
+++ b/calendar/tests/ecal/ecal-test-utils.h
@@ -28,6 +28,7 @@
typedef struct {
GSourceFunc cb;
gpointer user_data;
+ CalMode mode;
} ECalTestClosure;
ECal*
@@ -59,4 +60,10 @@ ecal_test_utils_cal_get_ldap_attribute (ECal *cal);
void
ecal_test_utils_cal_get_capabilities (ECal *cal);
+void
+ecal_test_utils_cal_set_mode (ECal *cal,
+ CalMode mode,
+ GSourceFunc callback,
+ gpointer user_data);
+
#endif /* _ECAL_TEST_UTILS_H */
diff --git a/calendar/tests/ecal/test-ecal-set-mode.c b/calendar/tests/ecal/test-ecal-set-mode.c
new file mode 100644
index 0000000..7eafb22
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-set-mode.c
@@ -0,0 +1,60 @@
+/* -*- 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 SET_MODE_TIMEOUT 30
+#define MODE_FINAL CAL_MODE_LOCAL
+
+static void cal_set_mode_timeout_cb (gpointer user_data) __attribute__ ((noreturn));
+
+static guint cal_set_mode_timeout_id = 0;
+
+static void
+cal_set_mode_cb (ECalTestClosure *closure)
+{
+ g_source_remove (cal_set_mode_timeout_id);
+
+ if (closure->mode != MODE_FINAL) {
+ g_warning ("set mode to %d, but we expected %d", closure->mode,
+ MODE_FINAL);
+ }
+
+ g_main_loop_quit ((GMainLoop*) closure->user_data);
+}
+
+static void
+cal_set_mode_timeout_cb (gpointer user_data)
+{
+ g_warning ("failed to get a confirmation for the new calendar mode we "
+ "set (within a reasonable time frame)");
+ exit (1);
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ ECal *cal;
+ char *uri = NULL;
+ GMainLoop *loop;
+
+ g_type_init ();
+
+ cal = ecal_test_utils_cal_new_temp (&uri, E_CAL_SOURCE_TYPE_EVENT);
+ ecal_test_utils_cal_open (cal, FALSE);
+
+ cal_set_mode_timeout_id = g_timeout_add_seconds (SET_MODE_TIMEOUT,
+ (GSourceFunc) cal_set_mode_timeout_cb, cal);
+
+ loop = g_main_loop_new (NULL, TRUE);
+ ecal_test_utils_cal_set_mode (cal, MODE_FINAL,
+ (GSourceFunc) cal_set_mode_cb, loop);
+
+ g_main_loop_run (loop);
+
+ ecal_test_utils_cal_remove (cal);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]