Skip to content

Commit

Permalink
Activate unit tests through CppUnit.
Browse files Browse the repository at this point in the history
Start with a unit test for WF-to-Ogre unit conversions.
  • Loading branch information
erikogenvik committed Nov 21, 2010
1 parent 7012283 commit 1d2d040
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
INCLUDES = -I$(top_srcdir)/src INCLUDES = -I$(top_srcdir)/src
SUBDIRS = src media SUBDIRS = src media test


bin_SCRIPTS = ember bin_SCRIPTS = ember
dist_bin_SCRIPTS = ember dist_bin_SCRIPTS = ember
Expand Down
59 changes: 31 additions & 28 deletions configure.ac
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AC_CONFIG_SRCDIR(src)
AC_CANONICAL_SYSTEM AC_CANONICAL_SYSTEM


#AM_INIT_AUTOMAKE([tar-ustar nostdinc dist-bzip2 check-news]) #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) AM_CONFIG_HEADER(src/config.h)


#AC_LIBTOOL_DLOPEN #AC_LIBTOOL_DLOPEN
Expand Down Expand Up @@ -413,33 +413,35 @@ Please visit http://worldforge.org/dev/eng/libraries to get the latest versions


# Cppunit check # Cppunit check


#AC_ARG_ENABLE(cppunit,[ --enable-cppunit enables cppunit tests [default=yes]], AC_ARG_ENABLE(cppunit,[ --enable-cppunit enables cppunit tests [default=yes]],
#[ [
# if test x$enableval = xno; then if test x$enableval = xno; then
# ac_use_cppunit="no" ac_use_cppunit="no"
# else else
# ac_use_cppunit="yes" ac_use_cppunit="yes"
# fi fi
#], [ac_use_cppunit="yes"]) ], [ac_use_cppunit="yes"])


#found_cppunit=no found_cppunit=no


#if test "$ac_use_cppunit" = "yes"; then if test "$ac_use_cppunit" = "yes"; then
#AM_PATH_CPPUNIT(1.8.0, [ AM_PATH_CPPUNIT(1.8.0, [
# AC_MSG_RESULT([ AC_MSG_RESULT([
#*** Found CppUnit *** Found CppUnit
#*** Setting up make check to run tests...]) *** Setting up make check to run tests...])
# CXXFLAGS="$CXXFLAGS -DUSE_CPP_UNIT" CXXFLAGS="$CXXFLAGS -DUSE_CPP_UNIT"
# LIBS="$LIBS $CPPUNIT_LIBS" LIBS="$LIBS $CPPUNIT_LIBS"
#], found_cppunit=yes
# AC_MSG_RESULT([ ],
# AC_MSG_RESULT([
#*** Unable to find a recent enough CppUnit *** Unable to find a recent enough CppUnit
#*** Will not run unit testing!! *** Will not run unit testing!!
#*** ***
#*** To get CppUnit see http://cppunit.sourceforge.net *** To get CppUnit see http://cppunit.sourceforge.net
#])) ]))
#fi fi

AM_CONDITIONAL(USE_CPPUNIT, [test x$found_cppunit = xyes])




# debugging option # debugging option
Expand Down Expand Up @@ -557,6 +559,7 @@ AC_CONFIG_FILES([Makefile
src/components/cegui/Makefile src/components/cegui/Makefile
media/Makefile media/Makefile
media/packs/Makefile media/packs/Makefile
test/Makefile
]) ])


AC_OUTPUT AC_OUTPUT
Expand Down
35 changes: 35 additions & 0 deletions test/ConvertTestCase.cpp
Original file line number Original file line Diff line number Diff line change
@@ -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)));

}
}
12 changes: 12 additions & 0 deletions test/ConvertTestCase.h
Original file line number Original file line Diff line number Diff line change
@@ -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();
};
}
14 changes: 11 additions & 3 deletions test/Makefile.am
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,13 @@
noinst_LIBRARIES = libTestServices.a

INCLUDES = -I$(top_srcdir)/src 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
27 changes: 8 additions & 19 deletions test/TestServices.cpp
Original file line number Original file line Diff line number Diff line change
@@ -1,31 +1,20 @@
#ifdef USE_CPP_UNIT
#include <cppunit/extensions/TestFactoryRegistry.h> #include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h> #include <cppunit/ui/text/TestRunner.h>


//#include "DataModelTest.h" #include "ConvertTestCase.h"
//#include "InputServiceTest.h" //#include "InputServiceTest.h"
//#include "StateManagerTest.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::InputServiceTestCase );
//CPPUNIT_TEST_SUITE_REGISTRATION( dime::StateManagerTestCase ); //CPPUNIT_TEST_SUITE_REGISTRATION( dime::StateManagerTestCase );



int main(int argc, char **argv)
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()
{ {
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.