[evolution-data-server/treitter-test-suites] Add test for EDataCal method 'setMode'.



commit 342e85dbed7ea5d71165ed60415d86ee7850cfac
Author: Travis Reitter <treitter gmail com>
Date:   Thu Dec 17 16:36:34 2009 -0800

    Add test for EDataCal method 'setMode'.

 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 ++++++++++++++++++++++++++++++
 4 files changed, 112 insertions(+), 0 deletions(-)
---
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]