[evolution-data-server/treitter-test-suites] Add test for EDataCal D-Bus methods 'open'.



commit 3ce715a8a32bf78ef64a487a1ac598e8a4c1c23f
Author: Travis Reitter <treitter gmail com>
Date:   Wed Dec 16 16:50:18 2009 -0800

    Add test for EDataCal D-Bus methods 'open'.

 calendar/tests/ecal/Makefile.am       |    5 ++-
 calendar/tests/ecal/ecal-test-utils.c |   48 +++++++++++++++++++++++++++
 calendar/tests/ecal/ecal-test-utils.h |   11 ++++++
 calendar/tests/ecal/test-ecal-open.c  |   57 +++++++++++++++++++++++++++++++++
 4 files changed, 120 insertions(+), 1 deletions(-)
---
diff --git a/calendar/tests/ecal/Makefile.am b/calendar/tests/ecal/Makefile.am
index 0ba89f8..8d87c49 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 a08193d..185e71f 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 38b3f0f..ed51042 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 0000000..1363731
--- /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;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]