added cppunit unit testing framework, using cmake, stripped out the original build systems.

added starting point for Bullet unit tests, with one example unit test
Enable the option BUILD_UNIT_TESTS in cmake to build the test. Note that the test doesn't automatically run.
This commit is contained in:
erwin.coumans
2010-07-23 22:09:57 +00:00
parent 6f823687b5
commit a983353f34
139 changed files with 15575 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src
${BULLET_PHYSICS_SOURCE_DIR}/UnitTests/cppunit/include
${VECTOR_MATH_INCLUDE}
)
LINK_LIBRARIES(
cppunit BulletMultiThreaded BulletDynamics BulletCollision LinearMath
)
ADD_EXECUTABLE(AppBulletUnitTests
Main.cpp
TestBulletOnly.h
)

View File

@@ -0,0 +1,38 @@
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include "TestBulletOnly.h"
CPPUNIT_TEST_SUITE_REGISTRATION( TestBulletOnly );
int main(int argc, char* argv[])
{
// 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 );
// Print test in a compiler compatible format.
CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() );
outputter.write();
getchar();
return result.wasSuccessful() ? 0 : 1;
}

View File

@@ -0,0 +1,122 @@
#ifndef TESTBULLETONLY_HAS_BEEN_INCLUDED
#define TESTBULLETONLY_HAS_BEEN_INCLUDED
#include "cppunit/TestFixture.h"
#include "cppunit/extensions/HelperMacros.h"
#include "btBulletDynamicsCommon.h"
#include "BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h"
// ---------------------------------------------------------------------------
class TestBulletOnly : public CppUnit::TestFixture
{
public:
void setUp()
{
// empty
}
void tearDown()
{
// empty
}
btRigidBody::btRigidBodyConstructionInfo buildConstructionInfo( btScalar mass, btScalar friction, btScalar restitution, btScalar linearDamping,
btScalar angularDamping, btDefaultMotionState & state, btCollisionShape * shape )
{
btVector3 inertia;
shape->calculateLocalInertia( mass, inertia );
btRigidBody::btRigidBodyConstructionInfo info( mass, &state, shape, inertia );
info.m_friction = friction;
info.m_restitution = restitution;
info.m_linearDamping = linearDamping;
info.m_angularDamping = angularDamping;
return info;
}
void testKinematicVelocity0()
{
// Setup the world --
btCollisionConfiguration * mCollisionConfig;
btCollisionDispatcher * mCollisionDispatch;
btBroadphaseInterface * mBroadphase;
btConstraintSolver * mConstraintSolver;
btDiscreteDynamicsWorld * mWorld;
mCollisionConfig = new btDefaultCollisionConfiguration;
mCollisionDispatch = new btCollisionDispatcher( mCollisionConfig );
mBroadphase = new btDbvtBroadphase();
mConstraintSolver = new btSequentialImpulseConstraintSolver();
mWorld = new btDiscreteDynamicsWorld( mCollisionDispatch, mBroadphase, mConstraintSolver, mCollisionConfig );
mWorld->setGravity( btVector3( 0, -9.81, 0 ));
// -- .
// Set up the rigid body --
btCollisionShape * bodyShape = new btBoxShape( btVector3( 1, 1, 1 ) );
btTransform bodyInitial;
btDefaultMotionState mMotionState;
bodyInitial.setIdentity();
bodyInitial.setOrigin( btVector3( 0, 0, 0 ) );
btRigidBody mRigidBody( buildConstructionInfo( 1, 0.5, 0.5, 0, 0, mMotionState, bodyShape ) );
mWorld->addRigidBody( &mRigidBody );
mRigidBody.setMassProps( 1, btVector3( 1, 1, 1 ) );
mRigidBody.updateInertiaTensor();
mRigidBody.setCollisionFlags( btCollisionObject::CF_KINEMATIC_OBJECT );
// -- .
// Interpolate the velocity --
//btVector3 velocity( 1., 2., 3. ), spin( 0.1, 0.2, 0.3 );
btVector3 velocity( 1., 2., 3. ), spin( 0.1, 0.2, .3 );
btTransform interpolated;
// TODO: This is inaccurate for small spins.
btTransformUtil::integrateTransform( mRigidBody.getCenterOfMassTransform(), velocity, spin, 1.0f/60.f, interpolated );
mRigidBody.setInterpolationWorldTransform( interpolated );
// -- .
mWorld->stepSimulation( 1.f/60.f, 60, 1.0f/60.f );
btScalar a = 0.f;
btScalar f = 1.f/a;
CPPUNIT_ASSERT_DOUBLES_EQUAL( mRigidBody.getLinearVelocity().length2(), velocity.length2(), 1e-8 );
#ifdef BT_USE_DOUBLE_PRECISION
CPPUNIT_ASSERT_DOUBLES_EQUAL( mRigidBody.getAngularVelocity().length2(), spin.length2(), 1e-4 );
#else
CPPUNIT_ASSERT_DOUBLES_EQUAL( mRigidBody.getAngularVelocity().length2(), spin.length2(), 5e-3 );
#endif //CPPUNIT_ASSERT_DOUBLES_EQUAL
delete mWorld;
delete mConstraintSolver;
delete mBroadphase;
delete mCollisionDispatch;
delete mCollisionConfig;
delete bodyShape;
}
CPPUNIT_TEST_SUITE(TestBulletOnly);
CPPUNIT_TEST(testKinematicVelocity0);
CPPUNIT_TEST_SUITE_END();
private:
};
#endif