[evolution-data-server/treitter-test-suites] Add tests for EDataCal methods '{get, create, remove}Object'.



commit 896c434e7bb7737b9068b7d9c06a7bc21c8b537c
Author: Travis Reitter <treitter gmail com>
Date:   Mon Dec 21 10:54:53 2009 -0800

    Add tests for EDataCal methods '{get,create,remove}Object'.

 calendar/tests/ecal/Makefile.am                    |   12 ++
 calendar/tests/ecal/ecal-test-utils.c              |  121 ++++++++++++++++++++
 calendar/tests/ecal/ecal-test-utils.h              |   24 ++++
 calendar/tests/ecal/test-ecal-create-object--2.c   |   73 ++++++++++++
 calendar/tests/ecal/test-ecal-create-object.c      |   36 ++++++
 .../tests/ecal/test-ecal-get-objects-for-uid.c     |   48 ++++++++
 calendar/tests/ecal/test-ecal-remove-object.c      |   36 ++++++
 7 files changed, 350 insertions(+), 0 deletions(-)
---
diff --git a/calendar/tests/ecal/Makefile.am b/calendar/tests/ecal/Makefile.am
index 93e16db..e9d1d6d 100644
--- a/calendar/tests/ecal/Makefile.am
+++ b/calendar/tests/ecal/Makefile.am
@@ -40,6 +40,10 @@ TESTS = \
         test-ecal-get-capabilities		\
         test-ecal-get-default-object		\
         test-ecal-set-mode			\
+        test-ecal-create-object			\
+        test-ecal-create-object--2		\
+        test-ecal-get-objects-for-uid		\
+        test-ecal-remove-object			\
         $(NULL)
 
 # The test program
@@ -50,6 +54,10 @@ TEST_ECAL_CPPFLAGS= \
 	$(NULL)
 
 # ordered alphanumerically
+test_ecal_create_object_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_create_object_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
+test_ecal_create_object__2_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_create_object__2_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 test_ecal_get_alarm_email_address_LDADD=$(TEST_ECAL_LIBS)
 test_ecal_get_alarm_email_address_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 test_ecal_get_cal_address_LDADD=$(TEST_ECAL_LIBS)
@@ -60,10 +68,14 @@ 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_objects_for_uid_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_get_objects_for_uid_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)
 test_ecal_remove_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
+test_ecal_remove_object_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_remove_object_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 test_ecal_set_mode_LDADD=$(TEST_ECAL_LIBS)
 test_ecal_set_mode_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 
diff --git a/calendar/tests/ecal/ecal-test-utils.c b/calendar/tests/ecal/ecal-test-utils.c
index 3bdd96e..149b981 100644
--- a/calendar/tests/ecal/ecal-test-utils.c
+++ b/calendar/tests/ecal/ecal-test-utils.c
@@ -263,6 +263,85 @@ ecal_test_utils_cal_get_capabilities (ECal *cal)
 		 );
 }
 
+void
+ecal_test_utils_cal_assert_objects_equal_shallow (icalcomponent *a,
+						  icalcomponent *b)
+{
+	const char *uid_a, *uid_b;
+
+	if (!icalcomponent_is_valid (a) && !icalcomponent_is_valid (b)) {
+		g_warning ("both components invalid");
+		return;
+	}
+
+	if (!icalcomponent_is_valid (a) || !icalcomponent_is_valid (b)) {
+		g_error ("exactly one of the components being compared is invalid");
+	}
+
+	uid_a = icalcomponent_get_uid (a);
+	uid_b = icalcomponent_get_uid (b);
+        if (g_strcmp0 (uid_a, uid_b)) {
+                g_error ("icomponents not equal:\n"
+			 "        uid A: '%s'\n"
+			 "        uid b: '%s'\n",
+			 uid_a, uid_b);
+        }
+}
+
+void
+ecal_test_utils_cal_assert_e_cal_components_equal (ECalComponent *a,
+						   ECalComponent *b)
+{
+	icalcomponent *ical_a, *ical_b;
+	ECalComponentTransparency transp_a, transp_b;
+
+	ical_a = e_cal_component_get_icalcomponent (a);
+	ical_b = e_cal_component_get_icalcomponent (b);
+        ecal_test_utils_cal_assert_objects_equal_shallow (ical_a, ical_b);
+
+        /* Dumping icalcomp into a string is not useful as the retrieved object
+         * has some generated information like timestamps. We compare
+         * member values we set during creation*/
+        g_assert (e_cal_component_event_dates_match (a, b));
+
+	e_cal_component_get_transparency (a, &transp_a);
+	e_cal_component_get_transparency (b, &transp_b);
+	g_assert (transp_a == transp_b);
+}
+
+icalcomponent*
+ecal_test_utils_cal_get_object (ECal       *cal,
+				const char *uid)
+{
+        GError *error = NULL;
+	icalcomponent *component = NULL;
+
+        if (!e_cal_get_object (cal, uid, NULL, &component, &error)) {
+                g_warning ("failed to get icalcomponent object '%s'; %s\n", uid, error->message);
+                exit(1);
+        }
+        if (!icalcomponent_is_valid (component)) {
+                g_warning ("retrieved icalcomponent is invalid\n");
+                exit(1);
+        }
+        g_print ("successfully got the icalcomponent object '%s'\n", uid);
+
+	return component;
+}
+
+void
+ecal_test_utils_cal_remove_object (ECal       *cal,
+				   const char *uid)
+{
+        GError *error = NULL;
+
+        if (!e_cal_remove_object (cal, uid, &error)) {
+                g_warning ("failed to remove icalcomponent object '%s'; %s\n", uid, error->message);
+                exit(1);
+        }
+        g_print ("successfully remoed the icalcomponent object '%s'\n", uid);
+}
+
 icalcomponent*
 ecal_test_utils_cal_get_default_object (ECal *cal)
 {
@@ -282,6 +361,48 @@ ecal_test_utils_cal_get_default_object (ECal *cal)
 	return component;
 }
 
+GList*
+ecal_test_utils_cal_get_objects_for_uid (ECal       *cal,
+					 const char *uid)
+{
+        GError *error = NULL;
+	GList *objects = NULL;
+
+        if (!e_cal_get_objects_for_uid (cal, uid, &objects, &error)) {
+                g_warning ("failed to get icalcomponent objects for UID '%s'; %s\n", uid, error->message);
+                exit(1);
+        }
+        g_print ("successfully got objects for the icalcomponent with UID '%s'\n", uid);
+
+	return objects;
+}
+
+char*
+ecal_test_utils_cal_create_object (ECal          *cal,
+				   icalcomponent *component)
+{
+        GError *error = NULL;
+	char *uid = NULL;
+	char *ical_string = NULL;
+
+        if (!icalcomponent_is_valid (component)) {
+                g_warning ("supplied icalcomponent is invalid\n");
+                exit(1);
+        }
+
+        if (!e_cal_create_object (cal, component, &uid, &error)) {
+                g_warning ("failed to get create an icalcomponent object; %s\n", error->message);
+                exit(1);
+        }
+
+	ical_string = icalcomponent_as_ical_string (component);
+        g_print ("successfully created icalcomponent object '%s'\n%s\n", uid,
+			ical_string);
+	g_free (ical_string);
+
+	return uid;
+}
+
 static void
 cal_set_mode_cb (ECal            *cal,
 	         ECalendarStatus  status,
diff --git a/calendar/tests/ecal/ecal-test-utils.h b/calendar/tests/ecal/ecal-test-utils.h
index 3e82c52..c0d25c5 100644
--- a/calendar/tests/ecal/ecal-test-utils.h
+++ b/calendar/tests/ecal/ecal-test-utils.h
@@ -60,9 +60,33 @@ ecal_test_utils_cal_get_ldap_attribute (ECal *cal);
 void
 ecal_test_utils_cal_get_capabilities (ECal *cal);
 
+void
+ecal_test_utils_cal_assert_objects_equal_shallow (icalcomponent *a,
+                                                  icalcomponent *b);
+
+void
+ecal_test_utils_cal_assert_e_cal_components_equal (ECalComponent *a,
+                                                   ECalComponent *b);
+
+icalcomponent*
+ecal_test_utils_cal_get_object (ECal       *cal,
+                                const char *uid);
+
+void
+ecal_test_utils_cal_remove_object (ECal       *cal,
+				   const char *uid);
+
 icalcomponent*
 ecal_test_utils_cal_get_default_object (ECal *cal);
 
+GList*
+ecal_test_utils_cal_get_objects_for_uid (ECal       *cal,
+					 const char *uid);
+
+char*
+ecal_test_utils_cal_create_object (ECal          *cal,
+				   icalcomponent *component);
+
 void
 ecal_test_utils_cal_set_mode (ECal        *cal,
                               CalMode      mode,
diff --git a/calendar/tests/ecal/test-ecal-create-object--2.c b/calendar/tests/ecal/test-ecal-create-object--2.c
new file mode 100644
index 0000000..539f38d
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-create-object--2.c
@@ -0,0 +1,73 @@
+/* -*- 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"
+
+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;
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+	ECal *cal;
+	char *uri = NULL;
+        ECalComponent *comp, *comp_retrieved;
+        icalcomponent *icalcomp_retrieved;
+	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)) {
+                g_error ("Could not set icalcomponent\n");
+        }
+
+	ecal_test_utils_cal_assert_e_cal_components_equal (comp, comp_retrieved);
+
+        g_object_unref (comp_retrieved);
+	g_object_unref (comp);
+	g_free (uid);
+
+	return 0;
+}
diff --git a/calendar/tests/ecal/test-ecal-create-object.c b/calendar/tests/ecal/test-ecal-create-object.c
new file mode 100644
index 0000000..4d20482
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-create-object.c
@@ -0,0 +1,36 @@
+/* -*- 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"
+
+gint
+main (gint argc, gchar **argv)
+{
+	ECal *cal;
+	char *uri = NULL;
+	icalcomponent *component;
+	icalcomponent *component_final;
+	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);
+
+	component = icalcomponent_new (ICAL_VEVENT_COMPONENT);
+	uid = ecal_test_utils_cal_create_object (cal, component);
+
+	component_final = ecal_test_utils_cal_get_object (cal, uid);
+	ecal_test_utils_cal_assert_objects_equal_shallow (component, component_final);
+
+	ecal_test_utils_cal_remove (cal);
+
+	g_free (uid);
+	icalcomponent_free (component);
+	icalcomponent_free (component_final);
+
+	return 0;
+}
diff --git a/calendar/tests/ecal/test-ecal-get-objects-for-uid.c b/calendar/tests/ecal/test-ecal-get-objects-for-uid.c
new file mode 100644
index 0000000..cd5e7d1
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-get-objects-for-uid.c
@@ -0,0 +1,48 @@
+/* -*- 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"
+
+gint
+main (gint argc, gchar **argv)
+{
+	ECal *cal;
+	char *uri = NULL;
+	icalcomponent *component;
+	icalcomponent *component_final;
+	ECalComponent *e_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);
+
+	component = icalcomponent_new (ICAL_VEVENT_COMPONENT);
+	uid = ecal_test_utils_cal_create_object (cal, 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);
+
+	/* The list of component and all subcomponents should just contain the
+	 * component itself (wrapped in an ECalComponent) */
+	components = ecal_test_utils_cal_get_objects_for_uid (cal, uid);
+	g_assert (g_list_length (components) == 1);
+	e_component_final = components->data;
+	component_final = e_cal_component_get_icalcomponent (e_component_final);
+	ecal_test_utils_cal_assert_objects_equal_shallow (component, component_final);
+
+	ecal_test_utils_cal_remove (cal);
+
+	g_list_foreach (components, (GFunc) g_object_unref, NULL);
+	g_list_free (components);
+	g_free (uid);
+	icalcomponent_free (component);
+
+	return 0;
+}
diff --git a/calendar/tests/ecal/test-ecal-remove-object.c b/calendar/tests/ecal/test-ecal-remove-object.c
new file mode 100644
index 0000000..7e05731
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-remove-object.c
@@ -0,0 +1,36 @@
+/* -*- 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"
+
+gint
+main (gint argc, gchar **argv)
+{
+	ECal *cal;
+	char *uri = NULL;
+	icalcomponent *component;
+	icalcomponent *component_final;
+	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);
+
+	component = icalcomponent_new (ICAL_VEVENT_COMPONENT);
+	uid = ecal_test_utils_cal_create_object (cal, component);
+
+	component_final = ecal_test_utils_cal_get_object (cal, uid);
+	ecal_test_utils_cal_assert_objects_equal_shallow (component, component_final);
+	ecal_test_utils_cal_remove_object (cal, uid);
+	ecal_test_utils_cal_remove (cal);
+
+	g_free (uid);
+	icalcomponent_free (component);
+	icalcomponent_free (component_final);
+
+	return 0;
+}



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