diff options
author | Travis Reitter <treitter@gmail.com> | 2009-12-21 12:05:40 -0800 |
---|---|---|
committer | Travis Reitter <treitter@gmail.com> | 2010-01-15 13:29:59 -0800 |
commit | 19ffd51b9e5a3728da9c935b89b34867b7dc379b (patch) | |
tree | d9f1b6410a486f3008c04d497dea19c006e1f900 | |
parent | b834455c1c56a0ff3963d1a206f6b67e2050457c (diff) | |
download | evolution-data-server-19ffd51b9e5a3728da9c935b89b34867b7dc379b.tar.gz |
Add test for EDataCal method 'getObjectList'; factor out some common test code as a utility.
-rw-r--r-- | calendar/tests/ecal/Makefile.am | 3 | ||||
-rw-r--r-- | calendar/tests/ecal/ecal-test-utils.c | 60 | ||||
-rw-r--r-- | calendar/tests/ecal/ecal-test-utils.h | 14 | ||||
-rw-r--r-- | calendar/tests/ecal/test-ecal-create-object--2.c | 62 | ||||
-rw-r--r-- | calendar/tests/ecal/test-ecal-get-object-list.c | 51 |
5 files changed, 143 insertions, 47 deletions
diff --git a/calendar/tests/ecal/Makefile.am b/calendar/tests/ecal/Makefile.am index e9d1d6db4..b524b05d2 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 149b981a8..fff37150a 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 c0d25c5dc..5df35e1ca 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 539f38ddd..e0e12b197 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 000000000..6705439b6 --- /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; +} |