Add test for EDataCal method 'getObjectList'; factor out some common test code as...
authorTravis Reitter <treitter@gmail.com>
Mon, 21 Dec 2009 20:05:40 +0000 (12:05 -0800)
committerTravis Reitter <treitter@gmail.com>
Fri, 15 Jan 2010 21:29:59 +0000 (13:29 -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-create-object--2.c
calendar/tests/ecal/test-ecal-get-object-list.c [new file with mode: 0644]

index e9d1d6d..b524b05 100644 (file)
@@ -44,6 +44,7 @@ TESTS = \
         test-ecal-create-object--2             \
         test-ecal-get-objects-for-uid          \
         test-ecal-remove-object                        \
+        test-ecal-get-object-list              \
         $(NULL)
 
 # The test program
@@ -68,6 +69,8 @@ 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)
 test_ecal_get_capabilities_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
+test_ecal_get_object_list_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_get_object_list_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 test_ecal_get_objects_for_uid_LDADD=$(TEST_ECAL_LIBS)
 test_ecal_get_objects_for_uid_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 test_ecal_open_LDADD=$(TEST_ECAL_LIBS)
index 149b981..fff3715 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "ecal-test-utils.h"
 
+
 ECal*
 ecal_test_utils_cal_new_temp (char           **uri,
                               ECalSourceType   type)
@@ -362,6 +363,22 @@ ecal_test_utils_cal_get_default_object (ECal *cal)
 }
 
 GList*
+ecal_test_utils_cal_get_object_list (ECal       *cal,
+                                    const char *query)
+{
+        GError *error = NULL;
+       GList *objects = NULL;
+
+        if (!e_cal_get_object_list (cal, query, &objects, &error)) {
+                g_warning ("failed to get list of icalcomponent objects for query '%s'; %s\n", query, error->message);
+                exit(1);
+        }
+        g_print ("successfully got list of icalcomponent objects for the query '%s'\n", query);
+
+       return objects;
+}
+
+GList*
 ecal_test_utils_cal_get_objects_for_uid (ECal       *cal,
                                         const char *uid)
 {
@@ -444,3 +461,46 @@ ecal_test_utils_cal_set_mode (ECal        *cal,
        g_signal_connect (G_OBJECT (cal), "cal_set_mode", G_CALLBACK (cal_set_mode_cb), closure);
        e_cal_set_mode (cal, mode);
 }
+
+void
+ecal_test_utils_create_component (ECal           *cal,
+                                 const char     *dtstart,
+                                 const char     *dtstart_tzid,
+                                 const char     *dtend,
+                                 const char     *dtend_tzid,
+                                 const char     *summary,
+                                 ECalComponent **comp_out,
+                                 char          **uid_out)
+{
+        ECalComponent *comp;
+        icalcomponent *icalcomp;
+        struct icaltimetype tt;
+        ECalComponentText text;
+        ECalComponentDateTime dt;
+        char *uid;
+
+        comp = e_cal_component_new ();
+        /* set fields */
+        e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT);
+        text.value = summary;
+        text.altrep = NULL;
+        e_cal_component_set_summary (comp, &text);
+        tt = icaltime_from_string (dtstart);
+        dt.value = &tt;
+        dt.tzid = dtstart_tzid;
+        e_cal_component_set_dtstart (comp, &dt);
+        tt = icaltime_from_string (dtend);
+        dt.value = &tt;
+        dt.tzid = dtend_tzid;
+        e_cal_component_set_dtend (comp, &dt);
+        e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_OPAQUE);
+
+        e_cal_component_commit_sequence (comp);
+        icalcomp = e_cal_component_get_icalcomponent (comp);
+
+        uid = ecal_test_utils_cal_create_object (cal, icalcomp);
+        e_cal_component_commit_sequence (comp);
+
+        *comp_out = comp;
+        *uid_out = uid;
+}
index c0d25c5..5df35e1 100644 (file)
@@ -80,6 +80,10 @@ icalcomponent*
 ecal_test_utils_cal_get_default_object (ECal *cal);
 
 GList*
+ecal_test_utils_cal_get_object_list (ECal       *cal,
+                                     const char *query);
+
+GList*
 ecal_test_utils_cal_get_objects_for_uid (ECal       *cal,
                                         const char *uid);
 
@@ -93,4 +97,14 @@ ecal_test_utils_cal_set_mode (ECal        *cal,
                               GSourceFunc  callback,
                               gpointer     user_data);
 
+void
+ecal_test_utils_create_component (ECal           *cal,
+                                  const char     *dtstart,
+                                  const char     *dtstart_tzid,
+                                  const char     *dtend,
+                                  const char     *dtend_tzid,
+                                  const char     *summary,
+                                  ECalComponent **comp_out,
+                                  char          **uid_out);
+
 #endif /* _ECAL_TEST_UTILS_H */
index 539f38d..e0e12b1 100644 (file)
@@ -6,67 +6,35 @@
 
 #include "ecal-test-utils.h"
 
-static void
-create_test_component (ECal           *cal,
-                      ECalComponent **comp_out,
-                      char          **uid_out)
-{
-        ECalComponent *comp;
-        icalcomponent *icalcomp;
-        struct icaltimetype tt;
-        ECalComponentText text;
-        ECalComponentDateTime dt;
-       char *uid;
-
-        comp = e_cal_component_new ();
-        /* set fields */
-        e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT);
-        text.value = "Creation of new test event";
-        text.altrep = NULL;
-        e_cal_component_set_summary (comp, &text);
-        tt = icaltime_from_string ("20040109T090000Z");
-        dt.value = &tt;
-        dt.tzid ="UTC";
-        e_cal_component_set_dtstart (comp, &dt);
-        tt = icaltime_from_string ("20040109T103000");
-        dt.value = &tt;
-        dt.tzid ="UTC";
-        e_cal_component_set_dtend (comp, &dt);
-        e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_OPAQUE);
-
-        e_cal_component_commit_sequence (comp);
-        icalcomp = e_cal_component_get_icalcomponent (comp);
-
-       uid = ecal_test_utils_cal_create_object (cal, icalcomp);
-        e_cal_component_commit_sequence (comp);
-
-       *comp_out = comp;
-       *uid_out = uid;
-}
+#define EVENT_SUMMARY "Creation of new test event"
 
 gint
 main (gint argc, gchar **argv)
 {
        ECal *cal;
        char *uri = NULL;
-        ECalComponent *comp, *comp_retrieved;
-        icalcomponent *icalcomp_retrieved;
+        ECalComponent *e_component, *e_component_final;
+        icalcomponent *icalcomponent_final;
        char *uid;
 
        cal = ecal_test_utils_cal_new_temp (&uri, E_CAL_SOURCE_TYPE_EVENT);
        ecal_test_utils_cal_open (cal, FALSE);
-       create_test_component (cal, &comp, &uid);
-
-       icalcomp_retrieved = ecal_test_utils_cal_get_object (cal, uid);
-        comp_retrieved = e_cal_component_new ();
-        if (!e_cal_component_set_icalcomponent (comp_retrieved, icalcomp_retrieved)) {
+        ecal_test_utils_create_component (cal, "20040109T090000Z", "UTC",
+                        "20040109T103000", "UTC", EVENT_SUMMARY, &e_component,
+                        &uid);
+
+       icalcomponent_final = ecal_test_utils_cal_get_object (cal, uid);
+        e_component_final = e_cal_component_new ();
+       if (!e_cal_component_set_icalcomponent (e_component_final,
+                               icalcomponent_final)) {
                 g_error ("Could not set icalcomponent\n");
         }
 
-       ecal_test_utils_cal_assert_e_cal_components_equal (comp, comp_retrieved);
+       ecal_test_utils_cal_assert_e_cal_components_equal (e_component,
+                       e_component_final);
 
-        g_object_unref (comp_retrieved);
-       g_object_unref (comp);
+        g_object_unref (e_component_final);
+       g_object_unref (e_component);
        g_free (uid);
 
        return 0;
diff --git a/calendar/tests/ecal/test-ecal-get-object-list.c b/calendar/tests/ecal/test-ecal-get-object-list.c
new file mode 100644 (file)
index 0000000..6705439
--- /dev/null
@@ -0,0 +1,51 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libecal/e-cal.h>
+#include <libical/ical.h>
+
+#include "ecal-test-utils.h"
+
+#define EVENT_SUMMARY "Creation of new test event"
+
+gint
+main (gint argc, gchar **argv)
+{
+       ECal *cal;
+       char *uri = NULL;
+       ECalComponent *e_component;
+       icalcomponent *component;
+       icalcomponent *component_final;
+       char *uid;
+       GList *components;
+
+       g_type_init ();
+
+       cal = ecal_test_utils_cal_new_temp (&uri, E_CAL_SOURCE_TYPE_EVENT);
+       ecal_test_utils_cal_open (cal, FALSE);
+
+       ecal_test_utils_create_component (cal, "20040109T090000Z", "UTC",
+                       "20040109T103000", "UTC", EVENT_SUMMARY, &e_component,
+                       &uid);
+        component = e_cal_component_get_icalcomponent (e_component);
+
+       component_final = ecal_test_utils_cal_get_object (cal, uid);
+       ecal_test_utils_cal_assert_objects_equal_shallow (component,
+                       component_final);
+       icalcomponent_free (component_final);
+
+       components = ecal_test_utils_cal_get_object_list (cal,
+                       "(contains? \"summary\" \"" EVENT_SUMMARY "\")");
+       g_assert (g_list_length (components) == 1);
+       component_final = components->data;
+       ecal_test_utils_cal_assert_objects_equal_shallow (component,
+                       component_final);
+
+       ecal_test_utils_cal_remove (cal);
+
+       e_cal_free_object_list (components);
+       g_free (uid);
+       icalcomponent_free (component);
+
+       return 0;
+}