mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-01 17:55:48 +00:00
adding unit test crashing on addEntity
This commit is contained in:
@@ -51,6 +51,7 @@ add_executable(unit_tests EXCLUDE_FROM_ALL
|
||||
tests/MainTest.cpp
|
||||
tests/EngineTests.cpp
|
||||
tests/CallbackTest.cpp
|
||||
tests/CollisionTest.cpp
|
||||
)
|
||||
target_include_directories(unit_tests PUBLIC sources)
|
||||
target_link_libraries(unit_tests PUBLIC wal ray)
|
||||
|
||||
@@ -17,48 +17,48 @@ namespace BBM
|
||||
}
|
||||
|
||||
CollisionComponent::CollisionComponent(WAL::Entity &entity, std::function<void (WAL::Entity &, const WAL::Entity &)> callback, Vector3f bound)
|
||||
: WAL::Component(entity), onCollide(callback), _boundX(bound.x), _boundY(bound.y), _boundZ(bound.z)
|
||||
: WAL::Component(entity), onCollide(callback), _bound(bound)
|
||||
{ }
|
||||
|
||||
CollisionComponent::CollisionComponent(WAL::Entity &entity, std::function<void (WAL::Entity &, const WAL::Entity &)> callback, float boundSize)
|
||||
: WAL::Component(entity), onCollide(callback), _boundX(boundSize), _boundY(boundSize), _boundZ(boundSize)
|
||||
: WAL::Component(entity), onCollide(callback), _bound({boundSize, boundSize, boundSize})
|
||||
{ }
|
||||
|
||||
CollisionComponent::CollisionComponent(WAL::Entity &entity, WAL::Callback<WAL::Entity &, const WAL::Entity &> callback, Vector3f bound)
|
||||
: WAL::Component(entity), onCollide(callback), _boundX(bound.x), _boundY(bound.y), _boundZ(bound.z)
|
||||
: WAL::Component(entity), onCollide(callback), _bound(bound)
|
||||
{ }
|
||||
|
||||
CollisionComponent::CollisionComponent(WAL::Entity &entity, WAL::Callback<WAL::Entity &, const WAL::Entity &> callback, float boundSize)
|
||||
: WAL::Component(entity), onCollide(callback), _boundX(boundSize), _boundY(boundSize), _boundZ(boundSize)
|
||||
: WAL::Component(entity), onCollide(callback), _bound({boundSize, boundSize, boundSize})
|
||||
{ }
|
||||
|
||||
float CollisionComponent::getBoundX(void) const
|
||||
{
|
||||
return _boundX;
|
||||
return _bound.x;
|
||||
}
|
||||
|
||||
float CollisionComponent::getBoundY(void) const
|
||||
{
|
||||
return _boundY;
|
||||
return _bound.y;
|
||||
}
|
||||
|
||||
float CollisionComponent::getBoundZ(void) const
|
||||
{
|
||||
return _boundZ;
|
||||
return _bound.z;
|
||||
}
|
||||
|
||||
void CollisionComponent::setBoundX(float value)
|
||||
{
|
||||
_boundX = value;
|
||||
_bound.x = value;
|
||||
}
|
||||
|
||||
void CollisionComponent::setBoundY(float value)
|
||||
{
|
||||
_boundY = value;
|
||||
_bound.y = value;
|
||||
}
|
||||
|
||||
void CollisionComponent::setBoundZ(float value)
|
||||
{
|
||||
_boundZ = value;
|
||||
_bound.z = value;
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,7 @@ namespace BBM
|
||||
class CollisionComponent : public WAL::Component
|
||||
{
|
||||
private:
|
||||
float _boundX;
|
||||
float _boundY;
|
||||
float _boundZ;
|
||||
Vector3f _bound;
|
||||
public:
|
||||
//! @brief get bound size on the X axis
|
||||
float getBoundX(void) const;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// Created by Louis Auzuret on 5/31/21.
|
||||
//
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
#include "Entity/Entity.hpp"
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
#include "System/Collision/CollisionSystem.hpp"
|
||||
#include "Wal.hpp"
|
||||
|
||||
#define private public
|
||||
#include "Component/Collision/CollisionComponent.hpp"
|
||||
|
||||
using namespace WAL;
|
||||
using namespace BBM;
|
||||
|
||||
|
||||
TEST_CASE("Collsion test", "[Component][System]")
|
||||
{
|
||||
Wal wal;
|
||||
wal.scene->addEntity("player")
|
||||
.addComponent<PositionComponent>();
|
||||
// .addComponent<CollisionComponent>([](Entity &actual, const Entity &) {
|
||||
// auto &pos = actual.getComponent<PositionComponent>();
|
||||
// pos.position.x = 1;
|
||||
// pos.position.y = 1;
|
||||
// pos.position.z = 1;
|
||||
// }, 5.0);
|
||||
//Entity &entity = wal.scene->getEntities()[0];
|
||||
//
|
||||
//REQUIRE(entity.getComponent<PositionComponent>().position == Vector3f());
|
||||
//
|
||||
//entity.getComponent<CollisionComponent>()._bound.x = 5;
|
||||
//entity.getComponent<CollisionComponent>()._bound.y = 5;
|
||||
//entity.getComponent<CollisionComponent>()._bound.z = 5;
|
||||
//
|
||||
//CollisionSystem collision(wal);
|
||||
//collision.onUpdate(entity, std::chrono::nanoseconds(1));
|
||||
//collision.onFixedUpdate(entity);
|
||||
//REQUIRE(entity.getComponent<PositionComponent>().position.x == 0);
|
||||
//REQUIRE(entity.getComponent<PositionComponent>().position.y == 0);
|
||||
//REQUIRE(entity.getComponent<PositionComponent>().position.z == 0);
|
||||
//
|
||||
//
|
||||
//wal.scene->addEntity("block")
|
||||
// .addComponent<PositionComponent>()
|
||||
// .addComponent<CollisionComponent>([](Entity &, const Entity &){}, 1);
|
||||
//collision.onUpdate(entity, std::chrono::nanoseconds(1));
|
||||
//collision.onFixedUpdate(entity);
|
||||
//REQUIRE(entity.getComponent<PositionComponent>().position.x == 1);
|
||||
//REQUIRE(entity.getComponent<PositionComponent>().position.y == 1);
|
||||
//REQUIRE(entity.getComponent<PositionComponent>().position.z == 1);
|
||||
}
|
||||
Reference in New Issue
Block a user