Permalink
Browse files

Activate unit tests through CppUnit.

Start with a unit test for WF-to-Ogre unit conversions.
  • Loading branch information...
1 parent 7012283 commit 1d2d04034e2634e2f4570391f32abe93453585d9 @erikogenvik erikogenvik committed Nov 21, 2010
Showing with 98 additions and 51 deletions.
  1. +1 −1 Makefile.am
  2. +31 −28 configure.ac
  3. +35 −0 test/ConvertTestCase.cpp
  4. +12 −0 test/ConvertTestCase.h
  5. +11 −3 test/Makefile.am
  6. +8 −19 test/TestServices.cpp
View
@@ -1,5 +1,5 @@
INCLUDES = -I$(top_srcdir)/src
-SUBDIRS = src media
+SUBDIRS = src media test
bin_SCRIPTS = ember
dist_bin_SCRIPTS = ember
View
@@ -7,7 +7,7 @@ AC_CONFIG_SRCDIR(src)
AC_CANONICAL_SYSTEM
#AM_INIT_AUTOMAKE([tar-ustar nostdinc dist-bzip2 check-news])
-AM_INIT_AUTOMAKE([tar-ustar nostdinc dist-bzip2])
+AM_INIT_AUTOMAKE([tar-ustar nostdinc dist-bzip2 color-tests parallel-tests])
AM_CONFIG_HEADER(src/config.h)
#AC_LIBTOOL_DLOPEN
@@ -413,33 +413,35 @@ Please visit http://worldforge.org/dev/eng/libraries to get the latest versions
# Cppunit check
-#AC_ARG_ENABLE(cppunit,[ --enable-cppunit enables cppunit tests [default=yes]],
-#[
-# if test x$enableval = xno; then
-# ac_use_cppunit="no"
-# else
-# ac_use_cppunit="yes"
-# fi
-#], [ac_use_cppunit="yes"])
-
-#found_cppunit=no
-
-#if test "$ac_use_cppunit" = "yes"; then
-#AM_PATH_CPPUNIT(1.8.0, [
-# AC_MSG_RESULT([
-#*** Found CppUnit
-#*** Setting up make check to run tests...])
-# CXXFLAGS="$CXXFLAGS -DUSE_CPP_UNIT"
-# LIBS="$LIBS $CPPUNIT_LIBS"
-#],
-# AC_MSG_RESULT([
-#
-#*** Unable to find a recent enough CppUnit
-#*** Will not run unit testing!!
-#***
-#*** To get CppUnit see http://cppunit.sourceforge.net
-#]))
-#fi
+AC_ARG_ENABLE(cppunit,[ --enable-cppunit enables cppunit tests [default=yes]],
+[
+ if test x$enableval = xno; then
+ ac_use_cppunit="no"
+ else
+ ac_use_cppunit="yes"
+ fi
+], [ac_use_cppunit="yes"])
+
+found_cppunit=no
+
+if test "$ac_use_cppunit" = "yes"; then
+ AM_PATH_CPPUNIT(1.8.0, [
+ AC_MSG_RESULT([
+ *** Found CppUnit
+ *** Setting up make check to run tests...])
+ CXXFLAGS="$CXXFLAGS -DUSE_CPP_UNIT"
+ LIBS="$LIBS $CPPUNIT_LIBS"
+ found_cppunit=yes
+ ],
+ AC_MSG_RESULT([
+ *** Unable to find a recent enough CppUnit
+ *** Will not run unit testing!!
+ ***
+ *** To get CppUnit see http://cppunit.sourceforge.net
+ ]))
+fi
+
+AM_CONDITIONAL(USE_CPPUNIT, [test x$found_cppunit = xyes])
# debugging option
@@ -557,6 +559,7 @@ AC_CONFIG_FILES([Makefile
src/components/cegui/Makefile
media/Makefile
media/packs/Makefile
+ test/Makefile
])
AC_OUTPUT
View
@@ -0,0 +1,35 @@
+#include "ConvertTestCase.h"
+
+#include "components/ogre/Convert.h"
+
+using namespace EmberOgre;
+using namespace WFMath;
+
+namespace Ember
+{
+void ConvertTestCase::testWFMathToOgre()
+{
+ Point<2> wfMathPoint2(10, 20);
+ CPPUNIT_ASSERT(wfMathPoint2 == Convert::toWF(Convert::toOgre<Ogre::Vector2>(wfMathPoint2)));
+ CPPUNIT_ASSERT(wfMathPoint2 == Convert::toWF<Point<2> >(Convert::toOgre<Ogre::Vector3>(wfMathPoint2)));
+
+ Point<3> wfMathPoint3(10, 20, 30);
+ CPPUNIT_ASSERT(wfMathPoint3 == Convert::toWF<Point<3> >(Convert::toOgre(wfMathPoint3)));
+
+ Vector<2> wfMathVector2(10, 20);
+ CPPUNIT_ASSERT(Point<2>(wfMathVector2) == Convert::toWF(Convert::toOgre(wfMathVector2)));
+
+ Vector<3> wfMathVector3(10, 20, 30);
+ CPPUNIT_ASSERT(wfMathVector3 == Convert::toWF<Vector<3> >(Convert::toOgre(wfMathVector3)));
+
+ Quaternion wfQuaternion(1, 2.4f);
+ CPPUNIT_ASSERT(wfQuaternion == Convert::toWF(Convert::toOgre(wfQuaternion)));
+
+ WFMath::AxisBox<3> wfAxisBox3(Point<3>(1,2,3), Point<3>(10, 20, 30));
+ CPPUNIT_ASSERT(wfAxisBox3 == Convert::toWF(Convert::toOgre(wfAxisBox3)));
+
+ WFMath::AxisBox<2> wfAxisBox2(Point<2>(1,2), Point<2>(10, 20));
+ CPPUNIT_ASSERT(wfAxisBox2 == Convert::toWF(Convert::toOgre(wfAxisBox2)));
+
+}
+}
View
@@ -0,0 +1,12 @@
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace Ember {
+ class ConvertTestCase : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(ConvertTestCase);
+ CPPUNIT_TEST(testWFMathToOgre);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testWFMathToOgre();
+ };
+}
View
@@ -1,5 +1,13 @@
-noinst_LIBRARIES = libTestServices.a
-
INCLUDES = -I$(top_srcdir)/src
-libTestServices_a_SOURCES = TestServices.cpp
+if USE_CPPUNIT
+TESTS = TestServices
+check_PROGRAMS = $(TESTS)
+TestServices_SOURCES = TestServices.cpp ConvertTestCase.cpp
+
+TestServices_CXXFLAGS = $(CPPUNIT_CFLAGS)
+TestServices_LDFLAGS = $(CPPUNIT_LIBS)
+
+
+noinst_HEADERS = TestServices.h ConvertTestCase.h
+endif
View
@@ -1,31 +1,20 @@
-#ifdef USE_CPP_UNIT
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
-//#include "DataModelTest.h"
+#include "ConvertTestCase.h"
//#include "InputServiceTest.h"
//#include "StateManagerTest.h"
-//CPPUNIT_TEST_SUITE_REGISTRATION( dime::DataModelTestCase );
+CPPUNIT_TEST_SUITE_REGISTRATION( Ember::ConvertTestCase);
//CPPUNIT_TEST_SUITE_REGISTRATION( dime::InputServiceTestCase );
//CPPUNIT_TEST_SUITE_REGISTRATION( dime::StateManagerTestCase );
-
-bool runTests()
-{
- CppUnit::TextUi::TestRunner runner;
- CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
- runner.addTest( registry.makeTest() );
- bool wasSucessful = runner.run( "", false );
-
- return wasSucessful;
-}
-
-#else
-
-bool runTests()
+int main(int argc, char **argv)
{
- return true;
+ CppUnit::TextUi::TestRunner runner;
+ CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
+ runner.addTest(registry.makeTest());
+ bool wasSuccessful = runner.run("", false);
+ return !wasSuccessful;
}
-#endif

0 comments on commit 1d2d040

Please sign in to comment.