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



commit fd8d5572cffb9f520bd88adf9916226cf7ab670c
Author: Travis Reitter <treitter gmail com>
Date:   Tue Dec 22 10:02:04 2009 -0800

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

 calendar/libecal/e-cal.c                     |    4 +-
 calendar/libecal/e-data-cal-gdbus-bindings.h |   14 +++++++
 calendar/tests/ecal/Makefile.am              |    3 ++
 calendar/tests/ecal/ecal-test-utils.c        |   16 ++++++++
 calendar/tests/ecal/ecal-test-utils.h        |    4 ++
 calendar/tests/ecal/test-ecal-add-timezone.c |   50 ++++++++++++++++++++++++++
 6 files changed, 89 insertions(+), 2 deletions(-)
---
diff --git a/calendar/libecal/e-cal.c b/calendar/libecal/e-cal.c
index 5332966..1468a2c 100644
--- a/calendar/libecal/e-cal.c
+++ b/calendar/libecal/e-cal.c
@@ -3795,7 +3795,7 @@ e_cal_add_timezone (ECal *ecal, icaltimezone *izone, GError **error)
 	e_return_error_if_fail (E_IS_CAL (ecal), E_CALENDAR_STATUS_INVALID_ARG);
 	e_return_error_if_fail (izone, 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);
@@ -3817,7 +3817,7 @@ e_cal_add_timezone (ECal *ecal, icaltimezone *izone, GError **error)
 
 	/* call the backend */
 	LOCK_CONN ();
-	if (!org_gnome_evolution_dataserver_calendar_Cal_add_timezone (priv->proxy, tzobj, error)) {
+	if (!e_data_cal_gdbus_add_timezone_sync (priv->gdbus_proxy, tzobj, error)) {
 		UNLOCK_CONN ();
 		g_free (tzobj);
 		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 0f24e70..5c88b15 100644
--- a/calendar/libecal/e-data-cal-gdbus-bindings.h
+++ b/calendar/libecal/e-data-cal-gdbus-bindings.h
@@ -306,4 +306,18 @@ e_data_cal_gdbus_get_timezone_sync (GDBusProxy  *proxy,
         return demarshal_retvals__STRING (retvals, OUT_object);
 }
 
+static gboolean
+e_data_cal_gdbus_add_timezone_sync (GDBusProxy  *proxy,
+				    const char  *IN_zone,
+				    GError     **error)
+{
+        GVariant *parameters;
+        GVariant *retvals;
+
+        parameters = g_variant_new ("(s)", IN_zone);
+	retvals = g_dbus_proxy_invoke_method_sync (proxy, "addTimezone", parameters, -1, NULL, error);
+
+        return demarshal_retvals__VOID (retvals);
+}
+
 G_END_DECLS
diff --git a/calendar/tests/ecal/Makefile.am b/calendar/tests/ecal/Makefile.am
index 812701d..738a822 100644
--- a/calendar/tests/ecal/Makefile.am
+++ b/calendar/tests/ecal/Makefile.am
@@ -35,6 +35,7 @@ TESTS = \
         test-ecal-remove			\
         test-ecal-open				\
         test-ecal-get-timezone			\
+        test-ecal-add-timezone			\
         test-ecal-get-alarm-email-address	\
         test-ecal-get-cal-address		\
         test-ecal-get-ldap-attribute		\
@@ -57,6 +58,8 @@ TEST_ECAL_CPPFLAGS= \
 	$(NULL)
 
 # ordered alphanumerically
+test_ecal_add_timezone_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_add_timezone_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 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)
diff --git a/calendar/tests/ecal/ecal-test-utils.c b/calendar/tests/ecal/ecal-test-utils.c
index 5c959e1..5cb96e7 100644
--- a/calendar/tests/ecal/ecal-test-utils.c
+++ b/calendar/tests/ecal/ecal-test-utils.c
@@ -547,3 +547,19 @@ ecal_test_utils_cal_get_timezone (ECal       *cal,
 
 	return zone;
 }
+
+void
+ecal_test_utils_cal_add_timezone (ECal         *cal,
+				  icaltimezone *zone)
+{
+        GError *error = NULL;
+	const char *name;
+
+	name = icaltimezone_get_display_name (zone);
+
+        if (!e_cal_add_timezone (cal, zone, &error)) {
+                g_warning ("failed to add icaltimezone '%s'; %s\n", name, error->message);
+                exit(1);
+        }
+        g_print ("successfully added icaltimezone '%s'\n", name);
+}
diff --git a/calendar/tests/ecal/ecal-test-utils.h b/calendar/tests/ecal/ecal-test-utils.h
index aea710f..77afc12 100644
--- a/calendar/tests/ecal/ecal-test-utils.h
+++ b/calendar/tests/ecal/ecal-test-utils.h
@@ -120,4 +120,8 @@ icaltimezone*
 ecal_test_utils_cal_get_timezone (ECal       *cal,
                                   const char *tzid);
 
+void
+ecal_test_utils_cal_add_timezone (ECal         *cal,
+                                  icaltimezone *zone);
+
 #endif /* _ECAL_TEST_UTILS_H */
diff --git a/calendar/tests/ecal/test-ecal-add-timezone.c b/calendar/tests/ecal/test-ecal-add-timezone.c
new file mode 100644
index 0000000..eeb4413
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-add-timezone.c
@@ -0,0 +1,50 @@
+/* -*- 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 TZID_NEW "XYZ"
+#define TZNAME_NEW "Ex Wye Zee"
+
+gint
+main (gint argc, gchar **argv)
+{
+	ECal *cal;
+	char *uri = NULL;
+	icalproperty *property;
+	icalcomponent *component;
+	icaltimezone *zone;
+	icaltimezone *zone_final;
+
+	g_type_init ();
+
+	cal = ecal_test_utils_cal_new_temp (&uri, E_CAL_SOURCE_TYPE_EVENT);
+	ecal_test_utils_cal_open (cal, FALSE);
+
+	/* Build up new timezone */
+	component = icalcomponent_new_vtimezone ();
+	property = icalproperty_new_tzid (TZID_NEW);
+	icalcomponent_add_property (component, property);
+	property = icalproperty_new_tzname (TZNAME_NEW);
+	icalcomponent_add_property (component, property);
+	zone = icaltimezone_new ();
+	icaltimezone_set_component (zone, component);
+	
+	/* add */
+	ecal_test_utils_cal_add_timezone (cal, zone);
+
+	/* verify */
+	zone_final = ecal_test_utils_cal_get_timezone (cal, TZID_NEW);
+	g_assert (!g_strcmp0 (icaltimezone_get_tzid (zone),
+			icaltimezone_get_tzid (zone_final)));
+	g_assert (!g_strcmp0 (icaltimezone_get_tznames (zone),
+			icaltimezone_get_tznames (zone_final)));
+
+	ecal_test_utils_cal_remove (cal);
+	icaltimezone_free (zone, TRUE);
+
+	return 0;
+}



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