diff options
author | Travis Reitter <treitter@gmail.com> | 2009-12-17 16:36:34 -0800 |
---|---|---|
committer | Travis Reitter <treitter@gmail.com> | 2010-01-15 13:29:59 -0800 |
commit | 96ccffe5c4de4effee80f12449ffd9cfd83f31c2 (patch) | |
tree | 3610728fa65164657de52e0087d5b38c49c02c6e | |
parent | fbd0b22fb18adcfd377a376c4f72bfcb9d02d9e2 (diff) | |
download | evolution-data-server-96ccffe5c4de4effee80f12449ffd9cfd83f31c2.tar.gz |
Add test for EDataCal method 'setMode'.
-rw-r--r-- | calendar/tests/ecal/Makefile.am | 3 | ||||
-rw-r--r-- | calendar/tests/ecal/ecal-test-utils.c | 42 | ||||
-rw-r--r-- | calendar/tests/ecal/ecal-test-utils.h | 7 | ||||
-rw-r--r-- | 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 876b35418..c98ee45ba 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 052243e22..d399bea15 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 0fb522b10..5e69a85a7 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 000000000..7eafb22b5 --- /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; +} |