[evolution-data-server] Add a test for e-cal's 'remove' method to libecal (as the beginning of an automated test suite, like



commit 9d1ad0d70dc7811a70abf57d3773a1937cef1103
Author: Travis Reitter <treitter gmail com>
Date:   Tue Dec 29 15:08:54 2009 -0800

    Add a test for e-cal's 'remove' method to libecal (as the beginning of an automated test suite, like libebook has).

 calendar/tests/ecal/Makefile.am        |   44 ++++++++++++---
 calendar/tests/ecal/ecal-test-utils.c  |   95 ++++++++++++++++++++++++++++++++
 calendar/tests/ecal/ecal-test-utils.h  |   39 +++++++++++++
 calendar/tests/ecal/test-ecal-remove.c |   21 +++++++
 4 files changed, 190 insertions(+), 9 deletions(-)
---
diff --git a/calendar/tests/ecal/Makefile.am b/calendar/tests/ecal/Makefile.am
index af5f5b8..0ba89f8 100644
--- a/calendar/tests/ecal/Makefile.am
+++ b/calendar/tests/ecal/Makefile.am
@@ -1,3 +1,27 @@
+noinst_LTLIBRARIES = libecal-test-utils.la
+libecal_test_utils_la_SOURCES = ecal-test-utils.c ecal-test-utils.h
+
+libecal_test_utils_la_CPPFLAGS = \
+	$(AM_CPPFLAGS)					\
+	-DEVOLUTION_LOCALEDIR=\""$(localedir)"\"	\
+	-I$(top_srcdir)					\
+	-I$(top_builddir)				\
+	-I$(top_srcdir)/calendar			\
+	-I$(top_builddir)/calendar			\
+	$(LIBICAL_CFLAGS)				\
+	$(EVOLUTION_CALENDAR_CFLAGS)                    \
+	$(NULL)
+
+libecal_test_utils_la_LIBADD = \
+        $(top_builddir)/calendar/libecal/libecal-1.2.la    \
+        $(EVOLUTION_CALENDAR_LIBS)                         \
+        $(NULL)
+
+TEST_ECAL_LIBS = \
+        $(libecal_test_utils_la_LIBADD) \
+        libecal-test-utils.la           \
+        $(NULL)
+
 EXTRA_DIST =                          \
 	$(test_scripts)               \
 	testdata.ics
@@ -6,19 +30,21 @@ test_scripts =                         \
 	test-runner.sh                 \
 	cleanup.sh
 
+TESTS = \
+        test-ecal-remove                            \
+        $(NULL)
+
 # The test program
-noinst_PROGRAMS = test-ecal test-recur test-search
+noinst_PROGRAMS = $(TESTS) test-ecal test-recur test-search
 
 TEST_ECAL_CPPFLAGS= \
-	$(AM_CPPFLAGS)					\
-	-DEVOLUTION_LOCALEDIR=\""$(localedir)"\"	\
-	-I$(top_srcdir)					\
-	-I$(top_builddir)				\
-	-I$(top_srcdir)/calendar			\
-	-I$(top_builddir)/calendar			\
-	$(LIBICAL_CFLAGS)				\
-	$(EVOLUTION_CALENDAR_CFLAGS)
+	$(libecal_test_utils_la_CPPFLAGS) \
+	$(NULL)
+
+test_ecal_remove_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_remove_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 
+# monolithic tests
 test_ecal_SOURCES = test-ecal.c
 test_ecal_CPPFLAGS = $(TEST_ECAL_CPPFLAGS)
 test_ecal_INCLUDES =			\
diff --git a/calendar/tests/ecal/ecal-test-utils.c b/calendar/tests/ecal/ecal-test-utils.c
new file mode 100644
index 0000000..a08193d
--- /dev/null
+++ b/calendar/tests/ecal/ecal-test-utils.c
@@ -0,0 +1,95 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Travis Reitter (travis reitter collabora co uk)
+ */
+
+#include <stdlib.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <libecal/e-cal.h>
+
+#include "ecal-test-utils.h"
+
+ECal*
+ecal_test_utils_cal_new_temp (char           **uri,
+                              ECalSourceType   type)
+{
+        ECal *cal;
+        GError *error = NULL;
+        gchar *file_template;
+        char *uri_result;
+
+        file_template = g_build_filename (g_get_tmp_dir (),
+                        "ecal-test-XXXXXX/", NULL);
+        g_mkstemp (file_template);
+
+        uri_result = g_filename_to_uri (file_template, NULL, &error);
+        if (!uri_result) {
+                g_warning ("failed to convert %s to an URI: %s", file_template,
+                                error->message);
+                exit (1);
+        }
+        g_free (file_template);
+
+        /* create a temp calendar in /tmp */
+        g_print ("loading calendar\n");
+        cal = e_cal_new_from_uri (uri_result, type);
+        if (!cal) {
+                g_warning ("failed to create calendar: `%s'", *uri);
+                exit(1);
+        }
+
+        if (uri)
+                *uri = g_strdup (uri_result);
+
+        g_free (uri_result);
+
+        return cal;
+}
+
+void
+ecal_test_utils_cal_open (ECal     *cal,
+                          gboolean  only_if_exists)
+{
+        GError *error = NULL;
+
+        if (!e_cal_open (cal, only_if_exists, &error)) {
+                const char *uri;
+
+                uri = e_cal_get_uri (cal);
+
+                g_warning ("failed to open calendar: `%s': %s", uri,
+                                error->message);
+                exit(1);
+        }
+}
+
+void
+ecal_test_utils_cal_remove (ECal *cal)
+{
+        GError *error = NULL;
+
+        if (!e_cal_remove (cal, &error)) {
+                g_warning ("failed to remove calendar; %s\n", error->message);
+                exit(1);
+        }
+        g_print ("successfully removed the temporary calendar\n");
+
+        g_object_unref (cal);
+}
diff --git a/calendar/tests/ecal/ecal-test-utils.h b/calendar/tests/ecal/ecal-test-utils.h
new file mode 100644
index 0000000..38b3f0f
--- /dev/null
+++ b/calendar/tests/ecal/ecal-test-utils.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Travis Reitter (travis reitter collabora co uk)
+ */
+
+#ifndef _ECAL_TEST_UTILS_H
+#define _ECAL_TEST_UTILS_H
+
+#include <glib.h>
+#include <libecal/e-cal.h>
+
+ECal*
+ecal_test_utils_cal_new_temp (char           **uri,
+		              ECalSourceType   type);
+
+void
+ecal_test_utils_cal_open (ECal     *cal,
+                          gboolean  only_if_exists);
+
+void
+ecal_test_utils_cal_remove (ECal *cal);
+
+#endif /* _ECAL_TEST_UTILS_H */
diff --git a/calendar/tests/ecal/test-ecal-remove.c b/calendar/tests/ecal/test-ecal-remove.c
new file mode 100644
index 0000000..7b48ff7
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-remove.c
@@ -0,0 +1,21 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libecal/e-cal.h>
+
+#include "ecal-test-utils.h"
+
+gint
+main (gint argc, gchar **argv)
+{
+	ECal *cal;
+	char *uri = NULL;
+
+	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_cal_remove (cal);
+
+	return 0;
+}



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