[evolution-data-server/treitter-client-gdbus] Port EDataCal method 'getObjectList' and add a regression test; factor out some common test code as



commit deb522c9cde65affa07316c3d252f6903a34cccf
Author: Travis Reitter <treitter gmail com>
Date:   Mon Dec 21 12:05:40 2009 -0800

    Port EDataCal method 'getObjectList' and add a regression test; factor out some common test code as a utility.

 calendar/libecal/e-cal.c                         |    4 +-
 calendar/libecal/e-data-cal-gdbus-bindings.h     |   15 +++++
 calendar/tests/ecal/Makefile.am                  |    3 +
 calendar/tests/ecal/ecal-test-utils.c            |   60 +++++++++++++++++++++
 calendar/tests/ecal/ecal-test-utils.h            |   14 +++++
 calendar/tests/ecal/test-ecal-create-object--2.c |   62 +++++----------------
 calendar/tests/ecal/test-ecal-get-object-list.c  |   51 ++++++++++++++++++
 7 files changed, 160 insertions(+), 49 deletions(-)
---
diff --git a/calendar/libecal/e-cal.c b/calendar/libecal/e-cal.c
index 372604a..7ccbce6 100644
--- a/calendar/libecal/e-cal.c
+++ b/calendar/libecal/e-cal.c
@@ -2327,7 +2327,7 @@ e_cal_get_object_list (ECal *ecal, const gchar *query, GList **objects, GError *
 	e_return_error_if_fail (query, E_CALENDAR_STATUS_INVALID_ARG);
 	e_return_error_if_fail (E_IS_CAL (ecal), E_CALENDAR_STATUS_INVALID_ARG);
 	priv = ecal->priv;
-	e_return_error_if_fail (priv->proxy, E_CALENDAR_STATUS_REPOSITORY_OFFLINE);
+	e_return_error_if_fail (priv->gdbus_proxy, E_CALENDAR_STATUS_REPOSITORY_OFFLINE);
 	*objects = NULL;
 
 	if (priv->load_state != E_CAL_LOAD_LOADED) {
@@ -2335,7 +2335,7 @@ e_cal_get_object_list (ECal *ecal, const gchar *query, GList **objects, GError *
 	}
 
 	LOCK_CONN ();
-	if (!org_gnome_evolution_dataserver_calendar_Cal_get_object_list (priv->proxy, query, &object_array, error)) {
+	if (!e_data_cal_gdbus_get_object_list_sync (priv->gdbus_proxy, query, &object_array, error)) {
 		UNLOCK_CONN ();
 		E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_CORBA_EXCEPTION, error);
 	}
diff --git a/calendar/libecal/e-data-cal-gdbus-bindings.h b/calendar/libecal/e-data-cal-gdbus-bindings.h
index 3b33941..7eaefae 100644
--- a/calendar/libecal/e-data-cal-gdbus-bindings.h
+++ b/calendar/libecal/e-data-cal-gdbus-bindings.h
@@ -217,6 +217,21 @@ e_data_cal_gdbus_get_object_sync (GDBusProxy  *proxy,
 }
 
 static gboolean
+e_data_cal_gdbus_get_object_list_sync (GDBusProxy   *proxy,
+				       const char   *IN_sexp,
+				       char       ***OUT_objects,
+				       GError      **error)
+{
+        GVariant *parameters;
+        GVariant *retvals;
+
+        parameters = g_variant_new ("(s)", IN_sexp);
+	retvals = g_dbus_proxy_invoke_method_sync (proxy, "getObjectList", parameters, -1, NULL, error);
+
+        return demarshal_retvals__STRINGVECTOR (retvals, OUT_objects);
+}
+
+static gboolean
 e_data_cal_gdbus_get_default_object_sync (GDBusProxy  *proxy,
 					  char       **object,
 					  GError     **error)
diff --git a/calendar/tests/ecal/Makefile.am b/calendar/tests/ecal/Makefile.am
index e9d1d6d..b524b05 100644
--- a/calendar/tests/ecal/Makefile.am
+++ b/calendar/tests/ecal/Makefile.am
@@ -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)
diff --git a/calendar/tests/ecal/ecal-test-utils.c b/calendar/tests/ecal/ecal-test-utils.c
index 149b981..fff3715 100644
--- a/calendar/tests/ecal/ecal-test-utils.c
+++ b/calendar/tests/ecal/ecal-test-utils.c
@@ -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;
+}
diff --git a/calendar/tests/ecal/ecal-test-utils.h b/calendar/tests/ecal/ecal-test-utils.h
index c0d25c5..5df35e1 100644
--- a/calendar/tests/ecal/ecal-test-utils.h
+++ b/calendar/tests/ecal/ecal-test-utils.h
@@ -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 */
diff --git a/calendar/tests/ecal/test-ecal-create-object--2.c b/calendar/tests/ecal/test-ecal-create-object--2.c
index 539f38d..e0e12b1 100644
--- a/calendar/tests/ecal/test-ecal-create-object--2.c
+++ b/calendar/tests/ecal/test-ecal-create-object--2.c
@@ -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
index 0000000..6705439
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-get-object-list.c
@@ -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;
+}



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