Skip to content

Commit

Permalink
test(blueprint): test to check if entities spawned have the right com…
Browse files Browse the repository at this point in the history
…ponents
  • Loading branch information
diogomsmiranda committed Feb 3, 2024
1 parent 6db8272 commit eea719c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions core/include/cubos/core/ecs/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <cassert>
#include <cstddef>

#include <cubos/core/ecs/name.hpp>
#include <cubos/core/ecs/entity/archetype_graph.hpp>
#include <cubos/core/ecs/entity/pool.hpp>
#include <cubos/core/ecs/name.hpp>
#include <cubos/core/ecs/resource/manager.hpp>
#include <cubos/core/ecs/table/tables.hpp>
#include <cubos/core/ecs/types.hpp>
Expand All @@ -29,7 +29,8 @@ namespace cubos::core::ecs
{
public:
/// @brief World constructor.
World() {
World()
{
this->registerComponent<Name>();
}

Expand Down
26 changes: 26 additions & 0 deletions core/tests/ecs/blueprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cubos/core/ecs/blueprint.hpp>
#include <cubos/core/ecs/command_buffer.hpp>
#include <cubos/core/ecs/name.hpp>
#include <cubos/core/ecs/system/arguments/commands.hpp>

#include "utils.hpp"
Expand All @@ -10,6 +11,7 @@ using cubos::core::ecs::Blueprint;
using cubos::core::ecs::CommandBuffer;
using cubos::core::ecs::Commands;
using cubos::core::ecs::Entity;
using cubos::core::ecs::Name;
using cubos::core::ecs::World;

TEST_CASE("ecs::Blueprint")
Expand Down Expand Up @@ -183,4 +185,28 @@ TEST_CASE("ecs::Blueprint")
CHECK(dict.map.at('0') == spawned0);
CHECK(dict.map.at('1') == spawned1);
}

SUBCASE("check if entities from spawned blueprint have the right components")
{
Blueprint blueprint{};
auto entity0 = blueprint.create("0");
auto entity1 = blueprint.create("1");
blueprint.add(entity0, IntegerComponent{0});
blueprint.add(entity1, IntegerComponent{1});

// Spawn the blueprint into the world and get the identifiers of the spawned entities.
auto spawned = cmds.spawn(blueprint);
auto spawned0 = spawned.entity("0");
auto spawned1 = spawned.entity("1");
cmdBuffer.commit();

auto components0 = world.components(spawned0);
auto components1 = world.components(spawned1);
REQUIRE(components0.has<IntegerComponent>());
REQUIRE(components1.has<IntegerComponent>());
REQUIRE(components0.has<Name>());
REQUIRE(components1.has<Name>());
CHECK(components0.get<IntegerComponent>().value == 0);
CHECK(components1.get<IntegerComponent>().value == 1);
}
}

0 comments on commit eea719c

Please sign in to comment.