1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00
openrw/tests/test_object.cpp

60 lines
1.3 KiB
C++
Raw Normal View History

2013-12-10 22:47:56 +01:00
#include <boost/test/unit_test.hpp>
2013-12-12 09:15:07 +01:00
#include "test_globals.hpp"
2013-12-10 22:47:56 +01:00
#include <renderwure/objects/GTAInstance.hpp>
#include <renderwure/engine/GTAEngine.hpp>
BOOST_AUTO_TEST_SUITE(ObjectUnitTests)
BOOST_AUTO_TEST_CASE(instance_test_damage)
{
std::shared_ptr<ObjectData> object(new ObjectData);
2013-12-12 09:15:07 +01:00
GTAInstance inst(Global::get().e,
2013-12-10 22:47:56 +01:00
glm::vec3(0.f, 0.f, 0.f),
glm::quat(), nullptr,
glm::vec3(1.f),
object,
nullptr
);
GTAObject::DamageInfo dmg;
dmg.type = GTAObject::DamageInfo::Bullet;
dmg.hitpoints = 50.f;
// Set object to undamagable.
object->flags = 0;
BOOST_CHECK( ! inst.takeDamage(dmg) );
2013-12-12 09:15:07 +01:00
// Now make it explode on hit
2013-12-10 22:47:56 +01:00
2013-12-12 09:15:07 +01:00
object->flags = ObjectData::EXPLODEONHIT;
2013-12-10 22:47:56 +01:00
BOOST_CHECK( inst.takeDamage(dmg) );
2013-12-12 09:15:07 +01:00
BOOST_CHECK( inst.mHealth < 0.f );
2013-12-10 22:47:56 +01:00
}
BOOST_AUTO_TEST_CASE(instance_test_destroy)
{
std::shared_ptr<ObjectData> object(new ObjectData);
2013-12-12 11:58:14 +01:00
GTAInstance inst(Global::get().e,
2013-12-10 22:47:56 +01:00
glm::vec3(0.f, 0.f, 0.f),
glm::quat(), nullptr,
glm::vec3(1.f),
object,
nullptr
);
GTAObject::DamageInfo dmg;
dmg.type = GTAObject::DamageInfo::Bullet;
dmg.hitpoints = inst.mHealth + 1.f;
// Now make it damageable
2013-12-12 09:15:07 +01:00
object->flags = ObjectData::EXPLODEONHIT;
2013-12-10 22:47:56 +01:00
BOOST_CHECK( inst.takeDamage(dmg) );
BOOST_CHECK( inst.mHealth < 0.f );
}
BOOST_AUTO_TEST_SUITE_END()