From 4007ca049b41adeeb1d315bc36fbe9b3ac432617 Mon Sep 17 00:00:00 2001 From: Razakhel Date: Wed, 7 Feb 2024 21:53:14 +0100 Subject: [PATCH] [Tests/Entity] Test entities use custom components - This replaces the current usage of Mesh, Transform & Light - The render system's test's cubemap doesn't load twice the images anymore --- tests/src/RaZ/Entity.cpp | 72 +++++++++++++++------------ tests/src/RaZ/Render/RenderSystem.cpp | 10 ++-- tests/src/RaZ/World.cpp | 2 +- 3 files changed, 44 insertions(+), 40 deletions(-) diff --git a/tests/src/RaZ/Entity.cpp b/tests/src/RaZ/Entity.cpp index 441a2e78..c20af21c 100644 --- a/tests/src/RaZ/Entity.cpp +++ b/tests/src/RaZ/Entity.cpp @@ -1,25 +1,26 @@ #include "RaZ/Entity.hpp" -#include "RaZ/Data/Mesh.hpp" -#include "RaZ/Math/Transform.hpp" -#include "RaZ/Render/Light.hpp" #include namespace { -// Declaring entities to be tested -Raz::Entity entity0(0); -Raz::Entity entity1(1); -Raz::Entity entity2(2); +struct FirstTestComponent : public Raz::Component {}; +struct SecondTestComponent : public Raz::Component {}; } // namespace TEST_CASE("Entity basic", "[core]") { + Raz::Entity entity0(0); + const Raz::Entity entity1(1); + const Raz::Entity entity2(2, false); + CHECK(entity0.getId() == 0); CHECK(entity1.getId() == 1); CHECK(entity2.getId() == 2); CHECK(entity0.isEnabled()); + CHECK(entity1.isEnabled()); + CHECK_FALSE(entity2.isEnabled()); entity0.disable(); CHECK_FALSE(entity0.isEnabled()); @@ -28,46 +29,51 @@ TEST_CASE("Entity basic", "[core]") { CHECK(entity0.isEnabled()); } -TEST_CASE("Entity-component manipulations", "[core]") { - CHECK(entity0.getComponents().empty()); +TEST_CASE("Entity-component manipulation", "[core]") { + Raz::Entity entity(0); - CHECK_FALSE(entity0.hasComponent()); - CHECK_FALSE(entity0.hasComponent()); + CHECK(entity.getComponents().empty()); + CHECK_FALSE(entity.hasComponent()); + CHECK_FALSE(entity.hasComponent()); - entity0.addComponent(); - CHECK(entity0.hasComponent()); - CHECK_FALSE(entity0.hasComponent()); + entity.addComponent(); + CHECK(entity.hasComponent()); + CHECK_NOTHROW(entity.getComponent()); + CHECK_FALSE(entity.hasComponent()); + CHECK_THROWS(entity.getComponent()); - CHECK(std::is_same_v()), Raz::Transform&>); - CHECK_THROWS(entity0.getComponent()); + CHECK(std::is_same_v()), FirstTestComponent&>); - entity0.removeComponent(); - CHECK_FALSE(entity0.hasComponent()); - CHECK_THROWS(entity0.getComponent()); + entity.removeComponent(); + CHECK_FALSE(entity.hasComponent()); + CHECK_THROWS(entity.getComponent()); } TEST_CASE("Entity bitset", "[core]") { + Raz::Entity entity0(0); + Raz::Entity entity1(1); + + CHECK(entity0.getEnabledComponents().isEmpty()); + entity0.addComponent(); + CHECK_FALSE(entity0.getEnabledComponents().isEmpty()); + + CHECK(entity0.getEnabledComponents().getEnabledBitCount() == 1); + CHECK(entity0.getEnabledComponents()[Raz::Component::getId()]); + CHECK(entity0.getEnabledComponents().getSize() == Raz::Component::getId() + 1); + CHECK(entity1.getEnabledComponents().isEmpty()); - entity1.addComponent(); + entity1.addComponent(); CHECK_FALSE(entity1.getEnabledComponents().isEmpty()); CHECK(entity1.getEnabledComponents().getEnabledBitCount() == 1); - CHECK(entity1.getEnabledComponents()[Raz::Component::getId()]); - CHECK(entity1.getEnabledComponents().getSize() == Raz::Component::getId() + 1); - - CHECK(entity2.getEnabledComponents().isEmpty()); - entity2.addComponent(Raz::LightType::POINT, 10.f); - CHECK_FALSE(entity2.getEnabledComponents().isEmpty()); - - CHECK(entity2.getEnabledComponents().getEnabledBitCount() == 1); - CHECK(entity2.getEnabledComponents()[Raz::Component::getId()]); - CHECK(entity2.getEnabledComponents().getSize() == Raz::Component::getId() + 1); + CHECK(entity1.getEnabledComponents()[Raz::Component::getId()]); + CHECK(entity1.getEnabledComponents().getSize() == Raz::Component::getId() + 1); // Match test // --- - // 0 0 1 -> Transform - // & 0 1 0 -> Light + // 0 0 1 -> FirstTestComponent + // & 0 1 0 -> SecondTestComponent // _______ // = 0 0 0 - CHECK((entity1.getEnabledComponents() & entity2.getEnabledComponents()) == Raz::Bitset(entity1.getEnabledComponents().getSize())); + CHECK((entity0.getEnabledComponents() & entity1.getEnabledComponents()) == Raz::Bitset(entity1.getEnabledComponents().getSize(), false)); } diff --git a/tests/src/RaZ/Render/RenderSystem.cpp b/tests/src/RaZ/Render/RenderSystem.cpp index 48e37ac1..cecab41a 100644 --- a/tests/src/RaZ/Render/RenderSystem.cpp +++ b/tests/src/RaZ/Render/RenderSystem.cpp @@ -80,12 +80,10 @@ TEST_CASE("RenderSystem Cook-Torrance ball", "[render]") { // Setting a cubemap & moving the camera to look the ball from below, in order to see the left, top & back faces of the cubemap - renderSystem.setCubemap(Raz::Cubemap(Raz::ImageFormat::load(RAZ_TESTS_ROOT "assets/textures/ŔŖȒȐ.png"), - Raz::ImageFormat::load(RAZ_TESTS_ROOT "assets/textures/ŔŖȒȐ.png"), - Raz::ImageFormat::load(RAZ_TESTS_ROOT "assets/textures/ĜƓGǦ.png"), - Raz::ImageFormat::load(RAZ_TESTS_ROOT "assets/textures/ĜƓGǦ.png"), - Raz::ImageFormat::load(RAZ_TESTS_ROOT "assets/textures/BƁḂɃ.png"), - Raz::ImageFormat::load(RAZ_TESTS_ROOT "assets/textures/BƁḂɃ.png"))); + const Raz::Image redImg = Raz::ImageFormat::load(RAZ_TESTS_ROOT "assets/textures/ŔŖȒȐ.png"); + const Raz::Image greenImg = Raz::ImageFormat::load(RAZ_TESTS_ROOT "assets/textures/ĜƓGǦ.png"); + const Raz::Image blueImg = Raz::ImageFormat::load(RAZ_TESTS_ROOT "assets/textures/BƁḂɃ.png"); + renderSystem.setCubemap(Raz::Cubemap(redImg, redImg, greenImg, greenImg, blueImg, blueImg)); cameraTrans.translate(Raz::Vec3f(3.f, -3.f, 0.f)); cameraComp.setCameraType(Raz::CameraType::LOOK_AT); diff --git a/tests/src/RaZ/World.cpp b/tests/src/RaZ/World.cpp index 1de46c5b..e9f6cf87 100644 --- a/tests/src/RaZ/World.cpp +++ b/tests/src/RaZ/World.cpp @@ -82,7 +82,7 @@ TEST_CASE("World refresh", "[core]") { Raz::Entity& entity0 = world.addEntity(true); Raz::Entity& entity1 = world.addEntity(true); - Raz::Entity& entity2 = world.addEntity(true); + const Raz::Entity& entity2 = world.addEntity(true); CHECK(entity0.getId() == 0); CHECK(entity1.getId() == 1);