Add test for EDataCal method 'getFreeBusy'.
authorTravis Reitter <treitter@gmail.com>
Wed, 23 Dec 2009 00:38:37 +0000 (16:38 -0800)
committerTravis Reitter <treitter@gmail.com>
Fri, 15 Jan 2010 21:30:00 +0000 (13:30 -0800)
calendar/tests/ecal/Makefile.am
calendar/tests/ecal/ecal-test-utils.c
calendar/tests/ecal/ecal-test-utils.h
calendar/tests/ecal/test-ecal-get-free-busy.c [new file with mode: 0644]

index fd30692..c3c3fa8 100644 (file)
@@ -34,6 +34,7 @@ test_scripts =                         \
 TESTS = \
         test-ecal-remove                       \
         test-ecal-open                         \
+        test-ecal-get-free-busy                        \
         test-ecal-get-timezone                 \
         test-ecal-add-timezone                 \
         test-ecal-set-default-timezone         \
@@ -71,6 +72,8 @@ test_ecal_get_cal_address_LDADD=$(TEST_ECAL_LIBS)
 test_ecal_get_cal_address_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 test_ecal_get_default_object_LDADD=$(TEST_ECAL_LIBS)
 test_ecal_get_default_object_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
+test_ecal_get_free_busy_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_get_free_busy_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 test_ecal_get_ldap_attribute_LDADD=$(TEST_ECAL_LIBS)
 test_ecal_get_ldap_attribute_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 test_ecal_get_capabilities_LDADD=$(TEST_ECAL_LIBS)
index 4cc2597..7b41a54 100644 (file)
@@ -579,3 +579,35 @@ ecal_test_utils_cal_set_default_timezone (ECal         *cal,
         }
         g_print ("successfully set default icaltimezone '%s'\n", name);
 }
+
+GList*
+ecal_test_utils_cal_get_free_busy (ECal   *cal,
+                                  GList  *users,
+                                  time_t  start,
+                                  time_t  end)
+{
+       GList *free_busy = NULL;
+       GList *l = NULL;
+       GError *error = NULL;
+
+       if (!e_cal_get_free_busy (cal, users, start, end, &free_busy, &error)) {
+               g_error ("Test free/busy : Could not retrieve free busy information :  %s\n", error->message);
+       }
+       if (free_busy) {
+               g_print ("Printing free/busy information\n");
+
+               for (l = free_busy; l; l = l->next) {
+                       gchar *comp_string;
+                       ECalComponent *comp = E_CAL_COMPONENT (l->data);
+
+                       comp_string = e_cal_component_get_as_string (comp);
+                       g_print ("%s\n", comp_string);
+                       g_object_unref (comp);
+                       g_free (comp_string);
+               }
+       } else {
+               g_error ("got empty free/busy information");
+       }
+
+       return free_busy;
+}
index 3deaf3f..a3db11d 100644 (file)
@@ -60,6 +60,12 @@ ecal_test_utils_cal_get_ldap_attribute (ECal *cal);
 void
 ecal_test_utils_cal_get_capabilities (ECal *cal);
 
+GList*
+ecal_test_utils_cal_get_free_busy (ECal   *cal,
+                                   GList  *users,
+                                   time_t  start,
+                                   time_t  end);
+
 void
 ecal_test_utils_cal_assert_objects_equal_shallow (icalcomponent *a,
                                                   icalcomponent *b);
diff --git a/calendar/tests/ecal/test-ecal-get-free-busy.c b/calendar/tests/ecal/test-ecal-get-free-busy.c
new file mode 100644 (file)
index 0000000..3708fe0
--- /dev/null
@@ -0,0 +1,39 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libecal/e-cal.h>
+#include <libecal/e-cal-time-util.h>
+#include <libical/ical.h>
+
+#include "ecal-test-utils.h"
+
+gint
+main (gint argc, gchar **argv)
+{
+       ECal *cal;
+       char *uri = NULL;
+        GList *users = NULL;
+        icaltimezone *utc;
+        time_t start = time (NULL), end;
+       GList *free_busy;
+
+       g_type_init ();
+
+       cal = ecal_test_utils_cal_new_temp (&uri, E_CAL_SOURCE_TYPE_EVENT);
+       ecal_test_utils_cal_open (cal, FALSE);
+
+        utc = icaltimezone_get_utc_timezone ();
+        start = time_from_isodate ("20040212T000000Z");
+        end = time_add_day_with_zone (start, 2, utc);
+       /* XXX: create dummy list, which the file backend will ignore */
+       users = g_list_prepend (users, NULL);
+
+       free_busy = ecal_test_utils_cal_get_free_busy (cal, users, start, end);
+
+       ecal_test_utils_cal_remove (cal);
+
+       g_list_foreach (free_busy, (GFunc) icalcomponent_free, NULL);
+       g_list_free (free_busy);
+
+       return 0;
+}