summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2016-03-13 10:28:15 +0100
committerDavid Tardon <dtardon@redhat.com>2016-03-13 15:15:05 +0100
commiteaa9b5611163ad80ffd517e028b4d4dae804464e (patch)
tree0aa2ce0c652669c6a6faf555052f1adcd405d078
parent675646f42ffedba4c7827c050d40a46ab6b10caf (diff)
add unit test support
-rw-r--r--configure.ac16
-rw-r--r--src/Makefile.am4
-rw-r--r--src/test/.gitignore10
-rw-r--r--src/test/Makefile.am26
-rw-r--r--src/test/test.cpp45
5 files changed, 101 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 0ff3164..da9f487 100644
--- a/configure.ac
+++ b/configure.ac
@@ -236,6 +236,21 @@ AS_IF([test "x$enable_static_tools" = "xyes"], [
])
AM_CONDITIONAL(STATIC_TOOLS, [test "x$enable_static_tools" = "xyes"])
+# ==========
+# Unit tests
+# ==========
+AC_ARG_ENABLE([tests],
+ [AS_HELP_STRING([--enable-tests], [Build and run unit tests])],
+ [enable_tests="$enableval"],
+ [enable_tests=yes]
+)
+AS_IF([test "x$enable_tests" = "xyes"], [
+ PKG_CHECK_MODULES([CPPUNIT], [cppunit])
+], [])
+AC_SUBST([CPPUNIT_CFLAGS])
+AC_SUBST([CPPUNIT_LIBS])
+AM_CONDITIONAL(WITH_TESTS, [test "x$enable_tests" = "xyes"])
+
# =============
# Documentation
# =============
@@ -283,6 +298,7 @@ src/conv/text/Makefile
src/conv/text/sw6022text.rc
src/lib/Makefile
src/lib/libsw602.rc
+src/test/Makefile
build/Makefile
build/win32/Makefile
docs/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 4796627..d23d2a9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1 +1,5 @@
SUBDIRS = lib conv
+
+if WITH_TESTS
+SUBDIRS += test
+endif
diff --git a/src/test/.gitignore b/src/test/.gitignore
new file mode 100644
index 0000000..7742c8b
--- /dev/null
+++ b/src/test/.gitignore
@@ -0,0 +1,10 @@
+Makefile
+Makefile.in
+test
+.libs
+.deps
+*.lo
+*.log
+*.o
+*.trs
+*~
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
new file mode 100644
index 0000000..22e6dd0
--- /dev/null
+++ b/src/test/Makefile.am
@@ -0,0 +1,26 @@
+## -*- Mode: make; tab-width: 4; indent-tabs-mode: tabs -*-
+
+target_test = test
+
+check_PROGRAMS = $(target_test)
+
+AM_CXXFLAGS = \
+ -I$(top_srcdir)/inc \
+ -I$(top_srcdir)/src/lib \
+ $(CPPUNIT_CFLAGS) \
+ $(REVENGE_CFLAGS) \
+ $(REVENGE_STREAM_CFLAGS) \
+ $(DEBUG_CXXFLAGS)
+
+test_LDFLAGS = -L$(top_srcdir)/src/lib
+test_LDADD = \
+ $(CPPUNIT_LIBS) \
+ $(REVENGE_LIBS) \
+ $(REVENGE_STREAM_LIBS)
+
+test_SOURCES = \
+ test.cpp
+
+TESTS = $(target_test)
+
+## vim:set shiftwidth=4 tabstop=4 noexpandtab:
diff --git a/src/test/test.cpp b/src/test/test.cpp
new file mode 100644
index 0000000..aa1137c
--- /dev/null
+++ b/src/test/test.cpp
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libe-book project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <iostream>
+
+#include <cppunit/BriefTestProgressListener.h>
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/TestResult.h>
+#include <cppunit/TestResultCollector.h>
+#include <cppunit/TestRunner.h>
+
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+int main()
+{
+ // Create the event manager and test controller
+ CPPUNIT_NS::TestResult controller;
+
+ // Add a listener that colllects test result
+ CPPUNIT_NS::TestResultCollector result;
+ controller.addListener(&result);
+
+ // Add a listener that print dots as test run.
+ CPPUNIT_NS::BriefTestProgressListener progress;
+ controller.addListener(&progress);
+
+ // Add the top suite to the test runner
+ CPPUNIT_NS::TestRunner runner;
+ runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
+ runner.run(controller);
+
+ // output
+ CPPUNIT_NS::CompilerOutputter outputter(&result, std::cerr);
+ outputter.write();
+
+ // return status code
+ return result.wasSuccessful() ? 0 : 1;
+}
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */