[evolution-data-server] Add test for EDataCal method 'modifyObject'.



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

    Add test for EDataCal method 'modifyObject'.

 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 ++++++++++++++++++++++
 5 files changed, 110 insertions(+), 5 deletions(-)
---
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]