diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 586e2436..e2642659 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,8 +9,8 @@ include_directories(${PROJECT_SOURCE_DIR}/engine/include) find_package(Boost COMPONENTS unit_test_framework REQUIRED) -include_directories(../framework2/include) +include_directories(../framework2/include /usr/include/bullet) -target_link_libraries(run_tests renderware sfml-window sfml-system GL ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) +target_link_libraries(run_tests renderware sfml-window sfml-system GL GLEW BulletDynamics BulletCollision LinearMath ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) add_test(UnitTests run_tests) diff --git a/tests/test_object.cpp b/tests/test_object.cpp new file mode 100644 index 00000000..5608ad5a --- /dev/null +++ b/tests/test_object.cpp @@ -0,0 +1,58 @@ +#include +#include +#include + +BOOST_AUTO_TEST_SUITE(ObjectUnitTests) + +GTAEngine e(""); + +BOOST_AUTO_TEST_CASE(instance_test_damage) +{ + std::shared_ptr object(new ObjectData); + GTAInstance inst(&e, + 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) ); + + // Now make it damageable + + object->flags = ObjectData::BREAKABLE; + + BOOST_CHECK( inst.takeDamage(dmg) ); +} + +BOOST_AUTO_TEST_CASE(instance_test_destroy) +{ + std::shared_ptr object(new ObjectData); + GTAInstance inst(&e, + 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 + + object->flags = ObjectData::BREAKABLE; + + BOOST_CHECK( inst.takeDamage(dmg) ); + + BOOST_CHECK( inst.mHealth < 0.f ); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/viewer/main.cpp b/viewer/main.cpp index b61f30c0..9133d5ea 100644 --- a/viewer/main.cpp +++ b/viewer/main.cpp @@ -447,6 +447,7 @@ void render() if(debugObject) { auto p = debugObject->getPosition(); ss << "Position: " << p.x << " " << p.y << " " << p.z << std::endl; + ss << "Health: " << debugObject->mHealth << std::endl; if(debugObject->type() == GTAObject::Vehicle) { GTAVehicle* vehicle = static_cast(debugObject); ss << "ID: " << vehicle->info.handling.ID << std::endl;