aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2014-10-10 08:18:29 +0200
committerGuido Günther <agx@sigxcpu.org>2014-10-10 21:07:40 +0200
commit13f0206e8f967f47d78816490a0284525603dfee (patch)
tree6c1970267211387ce174037d857ced8dc35e6a17
parent0015d23eba0a1a6d4f275705356a34a4483d5610 (diff)
Add tests for LpfManager
now that we have the test driver
-rw-r--r--.gitignore2
-rw-r--r--configure.ac1
-rw-r--r--libplanfahr/Makefile.am2
-rw-r--r--libplanfahr/lpf-manager.h2
-rw-r--r--libplanfahr/tests/Makefile.am45
-rw-r--r--libplanfahr/tests/lpf-manager.c104
6 files changed, 154 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index e80393d..eda11da 100644
--- a/.gitignore
+++ b/.gitignore
@@ -46,6 +46,8 @@ docs/reference/libplanfahr-*-sections.txt
docs/reference/tmpl
docs/reference/xml
m4/
+libplanfahr/tests/lpf-manager
+libplanfahr/tests/*.trs
libplanfahr/providers/tests/hafas-bin6
libplanfahr/providers/tests/hafas-bin6-format
libplanfahr/providers/tests/*.trs
diff --git a/configure.ac b/configure.ac
index 2d99f69..06950bf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -76,6 +76,7 @@ AC_CONFIG_FILES([run],
[chmod +x,-w run])
AC_CONFIG_FILES(Makefile
libplanfahr/Makefile
+ libplanfahr/tests/Makefile
libplanfahr/providers/Makefile
libplanfahr/providers/tests/Makefile
data/Makefile
diff --git a/libplanfahr/Makefile.am b/libplanfahr/Makefile.am
index 07d0115..f96cd13 100644
--- a/libplanfahr/Makefile.am
+++ b/libplanfahr/Makefile.am
@@ -1,6 +1,6 @@
include $(top_srcdir)/flymake.mk
-SUBDIRS = providers
+SUBDIRS = providers tests
EXTRA_DIST = libplanfahr.sym
diff --git a/libplanfahr/lpf-manager.h b/libplanfahr/lpf-manager.h
index 8de5bc7..5fb1285 100644
--- a/libplanfahr/lpf-manager.h
+++ b/libplanfahr/lpf-manager.h
@@ -80,7 +80,7 @@ LpfManager *lpf_manager_new (void);
GType lpf_manager_get_type (void);
GQuark lpf_manager_error_quark (void);
GStrv lpf_manager_get_available_providers(void);
-LpfProvider *lpf_manager_activate_provider(LpfManager *self,
+LpfProvider* lpf_manager_activate_provider(LpfManager *self,
const gchar *name,
GError **error);
void lpf_manager_deactivate_provider(LpfManager *self, LpfProvider *provider);
diff --git a/libplanfahr/tests/Makefile.am b/libplanfahr/tests/Makefile.am
new file mode 100644
index 0000000..c36748e
--- /dev/null
+++ b/libplanfahr/tests/Makefile.am
@@ -0,0 +1,45 @@
+include $(top_srcdir)/flymake.mk
+include $(top_srcdir)/glib-tap.mk
+
+test_programs = lpf-manager
+
+AM_CPPFLAGS = \
+ -DLIBPLANFAHR_COMPILATION \
+ -DLPF_TEST_SRCDIR=\""$(abs_srcdir)"\" \
+ $(GLIB2_CFLAGS) \
+ $(GIO2_CFLAGS) \
+ $(GOBJECT2_CFLAGS) \
+ $(GTHREAD2_CFLAGS) \
+ $(LIBXML2_CFLAGS) \
+ $(WARN_CFLAGS) \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/libplanfahr \
+ $(NULL)
+
+LDADD = \
+ $(top_builddir)/libplanfahr/libplanfahr-0.0.la \
+ $(GLIB2_LIBS) \
+ $(GIO2_LIBS) \
+ $(GOBJECT2_LIBS) \
+ $(GTHREAD2_LIBS) \
+ $(NULL)
+
+lpf_manager_SOURCES = \
+ lpf-manager.c \
+ $(NULL)
+
+lpf_manager_CFLAGS = \
+ $(AM_CPPFLAGS) \
+ $(LIBSOUP_CFLAGS) \
+ $(LIBXML2_CFLAGS) \
+ $(NULL)
+lpf_manager_LDADD = \
+ ../providers/libplanfahr-provider-test-test.la \
+ $(LDADD) \
+ $(LIBSOUP_LIBS) \
+ $(LIBXML2_LIBS) \
+ $(NULL)
+
+dist_test_data = \
+ $(NULL)
+
diff --git a/libplanfahr/tests/lpf-manager.c b/libplanfahr/tests/lpf-manager.c
new file mode 100644
index 0000000..502a3a5
--- /dev/null
+++ b/libplanfahr/tests/lpf-manager.c
@@ -0,0 +1,104 @@
+/*
+ * db.c: Deutsche Bahn provider for libplanfahr
+ *
+ * Copyright (C) 2014 Guido Günther
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * 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 General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Guido Günther <agx@sigxcpu.org>
+ */
+
+#include "../libplanfahr.h"
+
+#define LPF_TEST_PROVIDER "test-test"
+
+LpfManager *manager;
+LpfProvider *provider;
+
+static void
+test_lpf_manager(void)
+{
+ manager = lpf_manager_new();
+ g_assert_nonnull (manager);
+}
+
+
+static void
+test_lpf_manager_activate_provider(void)
+{
+ GError *err;
+
+ g_assert_nonnull (manager);
+ provider = lpf_manager_activate_provider(manager, LPF_TEST_PROVIDER, &err);
+ g_assert_nonnull (provider);
+ g_assert_no_error (err);
+ g_assert_cmpstr ("test_test", ==, lpf_provider_get_name(provider));
+}
+
+
+static void
+test_lpf_manager_activate_nonexistent_provider(void)
+{
+ GError *err;
+ LpfProvider *nonexistent;
+
+ g_assert_nonnull (manager);
+ nonexistent = lpf_manager_activate_provider(manager, "doesnot-exist", &err);
+ g_assert_error (err, LPF_MANAGER_ERROR, LPF_MANAGER_ERROR_ACTIVATION_FAILED);
+ g_assert_null (nonexistent);
+}
+
+
+static void
+test_lpf_manager_deactivate_provider(void)
+{
+ g_assert_nonnull (manager);
+ lpf_manager_deactivate_provider(manager, provider);
+}
+
+
+static void
+test_lpf_manager_get_available_providers(void)
+{
+ GStrv providers;
+ gint i;
+
+ g_assert_nonnull (manager);
+ providers = lpf_manager_get_available_providers();
+ g_assert_nonnull(providers);
+ for (i = 0; i < g_strv_length (providers); i++) {
+ if (!g_strcmp0 (LPF_TEST_PROVIDER, providers[i]))
+ return;
+ }
+ g_assert_not_reached(); /* test provider not found */
+}
+
+
+int main(int argc, char **argv)
+{
+ gboolean ret;
+
+ g_test_init (&argc, &argv, NULL);
+ g_setenv(LPF_PROVIDERS_ENV, LPF_TEST_SRCDIR "/../providers/.libs/", TRUE);
+
+ g_test_add_func ("/libplanfahr/lpf-manager/new", test_lpf_manager);
+ g_test_add_func ("/libplanfahr/lpf-manager/get_available-providers", test_lpf_manager_get_available_providers);
+ g_test_add_func ("/libplanfahr/lpf-manager/activate-provider", test_lpf_manager_activate_provider);
+ g_test_add_func ("/libplanfahr/lpf-manager/activate-nonexistent-provider", test_lpf_manager_activate_nonexistent_provider);
+ g_test_add_func ("/libplanfahr/lpf-manager/deactivate-provider", test_lpf_manager_deactivate_provider);
+
+ ret = g_test_run ();
+ return ret;
+}