[evolution-data-server/treitter-client-gdbus] Port EDataCal method 'modifyObject' and add a regression test.



commit ed68143ab6efdfca508a413a29a78dbc1b8cd7e0
Author: Travis Reitter <treitter gmail com>
Date:   Mon Dec 21 16:17:38 2009 -0800

    Port EDataCal method 'modifyObject' and add a regression test.

 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            |   27 +++++++++
 calendar/tests/ecal/ecal-test-utils.h            |    9 +++
 calendar/tests/ecal/test-ecal-create-object--2.c |    7 +--
 calendar/tests/ecal/test-ecal-modify-object.c    |   69 ++++++++++++++++++++++
 7 files changed, 127 insertions(+), 7 deletions(-)
---
diff --git a/calendar/libecal/e-cal.c b/calendar/libecal/e-cal.c
index 7ccbce6..c01c2ac 100644
--- a/calendar/libecal/e-cal.c
+++ b/calendar/libecal/e-cal.c
@@ -3479,7 +3479,7 @@ e_cal_modify_object (ECal *ecal, icalcomponent *icalcomp, CalObjModType mod, GEr
 	e_return_error_if_fail (icalcomponent_is_valid (icalcomp), E_CALENDAR_STATUS_INVALID_ARG);
 	e_return_error_if_fail (mod & CALOBJ_MOD_ALL, 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);
 
 	if (priv->load_state != E_CAL_LOAD_LOADED) {
 		E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_URI_NOT_LOADED, error);
@@ -3487,7 +3487,7 @@ e_cal_modify_object (ECal *ecal, icalcomponent *icalcomp, CalObjModType mod, GEr
 
 	obj = icalcomponent_as_ical_string_r (icalcomp);
 	LOCK_CONN ();
-	if (!org_gnome_evolution_dataserver_calendar_Cal_modify_object (priv->proxy, obj, mod, error)) {
+	if (!e_data_cal_gdbus_modify_object_sync (priv->gdbus_proxy, obj, mod, error)) {
 		UNLOCK_CONN ();
 		g_free (obj);
 		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 7eaefae..dc82f46 100644
--- a/calendar/libecal/e-data-cal-gdbus-bindings.h
+++ b/calendar/libecal/e-data-cal-gdbus-bindings.h
@@ -261,6 +261,21 @@ e_data_cal_gdbus_create_object_sync (GDBusProxy  *proxy,
 }
 
 static gboolean
+e_data_cal_gdbus_modify_object_sync (GDBusProxy  *proxy,
+				     const char  *IN_object,
+				     guint        IN_mod,
+				     GError     **error)
+{
+        GVariant *parameters;
+        GVariant *retvals;
+
+        parameters = g_variant_new ("(su)", IN_object, IN_mod);
+	retvals = g_dbus_proxy_invoke_method_sync (proxy, "modifyObject", parameters, -1, NULL, error);
+
+        return demarshal_retvals__VOID (retvals);
+}
+
+static gboolean
 e_data_cal_gdbus_remove_object_sync (GDBusProxy  *proxy,
 				     const char  *IN_uid,
 				     const char  *IN_rid,
diff --git a/calendar/tests/ecal/Makefile.am b/calendar/tests/ecal/Makefile.am
index b524b05..815e38c 100644
--- a/calendar/tests/ecal/Makefile.am
+++ b/calendar/tests/ecal/Makefile.am
@@ -45,6 +45,7 @@ TESTS = \
         test-ecal-get-objects-for-uid		\
         test-ecal-remove-object			\
         test-ecal-get-object-list		\
+        test-ecal-modify-object			\
         $(NULL)
 
 # The test program
@@ -73,6 +74,8 @@ 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_modify_object_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_modify_object_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 test_ecal_open_LDADD=$(TEST_ECAL_LIBS)
 test_ecal_open_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 test_ecal_remove_LDADD=$(TEST_ECAL_LIBS)
diff --git a/calendar/tests/ecal/ecal-test-utils.c b/calendar/tests/ecal/ecal-test-utils.c
index fff3715..49c4b08 100644
--- a/calendar/tests/ecal/ecal-test-utils.c
+++ b/calendar/tests/ecal/ecal-test-utils.c
@@ -331,6 +331,24 @@ ecal_test_utils_cal_get_object (ECal       *cal,
 }
 
 void
+ecal_test_utils_cal_modify_object (ECal          *cal,
+				   icalcomponent *component,
+				   CalObjModType  mod_type)
+{
+        GError *error = NULL;
+
+        if (!icalcomponent_is_valid (component)) {
+                g_warning (G_STRLOC ": icalcomponent argument is invalid\n");
+                exit(1);
+        }
+        if (!e_cal_modify_object (cal, component, mod_type, &error)) {
+                g_warning ("failed to modify icalcomponent object; %s\n", error->message);
+                exit(1);
+        }
+        g_print ("successfully modified the icalcomponent object\n");
+}
+
+void
 ecal_test_utils_cal_remove_object (ECal       *cal,
 				   const char *uid)
 {
@@ -504,3 +522,12 @@ ecal_test_utils_create_component (ECal           *cal,
         *comp_out = comp;
         *uid_out = uid;
 }
+
+void
+ecal_test_utils_cal_component_set_icalcomponent (ECalComponent *e_component,
+						 icalcomponent *component)
+{
+        if (!e_cal_component_set_icalcomponent (e_component, component)) {
+                g_error ("Could not set icalcomponent\n");
+        }
+}
diff --git a/calendar/tests/ecal/ecal-test-utils.h b/calendar/tests/ecal/ecal-test-utils.h
index 5df35e1..77918f8 100644
--- a/calendar/tests/ecal/ecal-test-utils.h
+++ b/calendar/tests/ecal/ecal-test-utils.h
@@ -73,6 +73,11 @@ ecal_test_utils_cal_get_object (ECal       *cal,
                                 const char *uid);
 
 void
+ecal_test_utils_cal_modify_object (ECal          *cal,
+                                   icalcomponent *component,
+                                   CalObjModType  mod_type);
+
+void
 ecal_test_utils_cal_remove_object (ECal       *cal,
 				   const char *uid);
 
@@ -107,4 +112,8 @@ ecal_test_utils_create_component (ECal           *cal,
                                   ECalComponent **comp_out,
                                   char          **uid_out);
 
+void
+ecal_test_utils_cal_component_set_icalcomponent (ECalComponent *e_component,
+						 icalcomponent *component);
+
 #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 e0e12b1..550f735 100644
--- a/calendar/tests/ecal/test-ecal-create-object--2.c
+++ b/calendar/tests/ecal/test-ecal-create-object--2.c
@@ -25,11 +25,8 @@ main (gint argc, gchar **argv)
 
 	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_component_set_icalcomponent (e_component_final,
+				icalcomponent_final);
 	ecal_test_utils_cal_assert_e_cal_components_equal (e_component,
 			e_component_final);
 
diff --git a/calendar/tests/ecal/test-ecal-modify-object.c b/calendar/tests/ecal/test-ecal-modify-object.c
new file mode 100644
index 0000000..be11289
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-modify-object.c
@@ -0,0 +1,69 @@
+/* -*- 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"
+#define INITIAL_BEGIN_TIME     "20040109T090000Z"
+#define INITIAL_BEGIN_TIMEZONE "UTC"
+#define INITIAL_END_TIME       "20040109T103000"
+#define INITIAL_END_TIMEZONE   "UTC"
+#define FINAL_BEGIN_TIME       "20091221T090000Z"
+#define FINAL_BEGIN_TIMEZONE   "UTC"
+
+gint
+main (gint argc, gchar **argv)
+{
+	ECal *cal;
+	char *uri = NULL;
+	ECalComponent *e_component;
+	ECalComponent *e_component_final;
+	icalcomponent *component;
+	icalcomponent *component_final;
+	struct icaltimetype icaltime;
+	char *uid;
+
+	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, INITIAL_BEGIN_TIME,
+			INITIAL_BEGIN_TIMEZONE, INITIAL_END_TIME,
+			INITIAL_END_TIMEZONE, 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);
+
+	/* make and commit changes */
+	icaltime = icaltime_from_string (FINAL_BEGIN_TIME);
+	icalcomponent_set_dtstart (component, icaltime);
+	ecal_test_utils_cal_component_set_icalcomponent (e_component,
+			component);
+	ecal_test_utils_cal_modify_object (cal, component, CALOBJ_MOD_ALL);
+
+	/* verify */
+        component_final = ecal_test_utils_cal_get_object (cal, uid);
+        e_component_final = e_cal_component_new ();
+        ecal_test_utils_cal_component_set_icalcomponent (e_component_final,
+                                component_final);
+
+        ecal_test_utils_cal_assert_e_cal_components_equal (e_component,
+                        e_component_final);
+
+	/* Clean-up */
+	ecal_test_utils_cal_remove (cal);
+
+	g_object_unref (e_component_final);
+	g_free (uid);
+	icalcomponent_free (component);
+
+	return 0;
+}



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