From 977ed85235665be89f1f14259d83f6fb0bf1c437 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 6 Dec 2013 13:21:35 +0100 Subject: CppUnit introduced. --- configure.ac | 13 ++++++++++--- test/Makefile.am | 13 +++++++++++++ test/proto.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++ test/test.cc | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 test/Makefile.am create mode 100644 test/proto.cc create mode 100644 test/test.cc diff --git a/configure.ac b/configure.ac index e115d4f..c50f27e 100644 --- a/configure.ac +++ b/configure.ac @@ -12,9 +12,9 @@ AC_ARG_WITH(debug, [], [with_debug=no]) if test x$with_debug == xyes; then - AC_MSG_WARN([*** Building with debug support!]) - AC_DEFINE_UNQUOTED(WITH_DEBUG, , [The project is configured to use debug output]) - CXXFLAGS="$CXXFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector -Wall -Werror -g -O0" + AC_MSG_WARN([*** Building with debug support!]) + AC_DEFINE_UNQUOTED(WITH_DEBUG, , [The project is configured to use debug output]) + CXXFLAGS="$CXXFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector -Wall -Werror -g -O0" fi dnl ====================== @@ -32,6 +32,13 @@ dnl Check for getopt dnl ====================== AC_HAVE_HEADERS(getopt.h) +AC_ARG_WITH(test, [ --with-test Build unit tests]) +if test x$with_test == xyes; then + AC_MSG_WARN([*** Building unittests!]) + AM_PATH_CPPUNIT(1.9.6) + AC_OUTPUT(test/Makefile) +fi + dnl ====================== dnl Check for eXpat library dnl ====================== diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..8cf4ce5 --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,13 @@ +# Rules for the test code (use `make check` to execute) +TESTS = proto + +check_PROGRAMS = $(TESTS) + +proto_CXXFLAGS = -DOUTPUT=\"proto\" $(CPPUNIT_CFLAGS) \ + -I$(top_srcdir)/src -I$(top_srcdir)/hugin -DDISABLE_HUGIN +proto_CFLAGS = -DDISABLE_HUGIN +proto_LDFLAGS = $(CPPUNIT_LIBS) +proto_SOURCES = \ + $(top_srcdir)/hugin/hugin.c \ + test.cc \ + proto.cc diff --git a/test/proto.cc b/test/proto.cc new file mode 100644 index 0000000..0cc8da9 --- /dev/null +++ b/test/proto.cc @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * engine.cc + * + * Fri Nov 29 18:09:02 CET 2013 + * Copyright 2013 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo 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 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include + +class test_proto_class : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(test_proto_class); + CPPUNIT_TEST(test_proto); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() {} + void tearDown() {} + void test_proto() { + } +}; + +// Registers the fixture into the 'registry' +CPPUNIT_TEST_SUITE_REGISTRATION(test_proto_class); + diff --git a/test/test.cc b/test/test.cc new file mode 100644 index 0000000..88c72e6 --- /dev/null +++ b/test/test.cc @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * test.cc + * + * Fri Nov 29 17:45:40 CET 2013 + * Copyright 2013 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo 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 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include +#include +#include + +#include + +int main(int argc, char* argv[]) +{ + // Get the top level suite from the registry + CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); + + // Adds the test to the list of test to run + CppUnit::TextUi::TestRunner runner; + runner.addTest( suite ); + + std::ofstream myfile; + myfile.open("result_"OUTPUT".xml"); + runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), myfile)); + + // Run the tests. + bool wasSucessful = runner.run(); + + myfile.close(); + + // Return error code 1 if the one of test failed. + return wasSucessful ? 0 : 1; +} -- cgit v1.2.3