#include "CBodyTest.h"
namespace app {
namespace ode {
CPPUNIT_TEST_SUITE_REGISTRATION(CBodyTest);
void CBodyTest::setUp()
{
}
void CBodyTest::tearDown()
{
}
void CBodyTest::testConstructor()
{
CBody body(&world);
CPPUNIT_ASSERT(0 != body.getId());
}
void CBodyTest::testDestructor()
{
CBody* body = new CBody(&world);
dBodyID id = body->getId();
delete body;
body = 0;
}
void CBodyTest::testGetPosition()
{
CBody body(&world);
dBodySetPosition(body.getId(), 10, 15, 20);
irr::core::vector3df pos = body.getPosition();
CPPUNIT_ASSERT_EQUAL((float)10, pos.X);
CPPUNIT_ASSERT_EQUAL((float)15, pos.Y);
CPPUNIT_ASSERT_EQUAL((float)20, pos.Z);
}
void CBodyTest::testSetPosition()
{
CBody body(&world);
dBodySetPosition(body.getId(), 100, 200, 250);
body.setPosition(irr::core::vector3df(1, 2, 3));
const dReal* pos = dBodyGetPosition(body.getId());
CPPUNIT_ASSERT_EQUAL((dReal)1, pos[0]);
CPPUNIT_ASSERT_EQUAL((dReal)2, pos[1]);
CPPUNIT_ASSERT_EQUAL((dReal)3, pos[2]);
}
void CBodyTest::testGetRotation()
{
CBody body(&world);
irr::core::quaternion qs(10, 5, 15, 2);
// normalize before comparison, otherwise lost accuracy
dQuaternion q = {qs.W, qs.X, qs.Y, qs.Z};
dBodySetQuaternion(body.getId(), q);
irr::core::quaternion rot = body.getRotation();
qs.normalize();
CPPUNIT_ASSERT_EQUAL(qs.W, rot.W);
CPPUNIT_ASSERT_EQUAL(qs.X, rot.X);
CPPUNIT_ASSERT_EQUAL(qs.Y, rot.Y);
CPPUNIT_ASSERT_EQUAL(qs.Z, rot.Z);
}
void CBodyTest::testSetRotation()
{
CBody body(&world);
irr::core::quaternion iq(1, 2, 3, 4);
body.setRotation(iq);
const dReal* oq = dBodyGetQuaternion(body.getId());
iq.normalize();
CPPUNIT_ASSERT_EQUAL((dReal)iq.W, oq[0]);
CPPUNIT_ASSERT_EQUAL((dReal)iq.X, oq[1]);
CPPUNIT_ASSERT_EQUAL((dReal)iq.Y, oq[2]);
CPPUNIT_ASSERT_EQUAL((dReal)iq.Z, oq[3]);
}
void CBodyTest::testGetRotationEuler()
{
CBody body(&world);
irr::core::quaternion i(60 * core::DEGTORAD,
30 * core::DEGTORAD,
10 * core::DEGTORAD);
body.setRotation(i);
irr::core::vector3df rot = body.getRotationEuler();
CPPUNIT_ASSERT_EQUAL((float)60, rot.X);
CPPUNIT_ASSERT_EQUAL((float)30, rot.Y);
CPPUNIT_ASSERT_EQUAL((float)10, rot.Z);
}
void CBodyTest::testSetRotationEuler()
{
CBody body(&world);
body.setRotationEuler(irr::core::vector3df(10, 20, 30));
irr::core::vector3df r = body.getRotationEuler();
CPPUNIT_ASSERT_EQUAL((float)10, r.X);
CPPUNIT_ASSERT_EQUAL((float)20, r.Y);
CPPUNIT_ASSERT_EQUAL((float)30, r.Z);
}
} // end namespace ode
} // end namespace app