From 7c21e34ae1898fce8c8051b5f1380e268da32140 Mon Sep 17 00:00:00 2001 From: max-001 Date: Fri, 22 Nov 2024 09:36:35 +0100 Subject: Replaced ComponentManager reference by OptionalRef for late binding --- src/test/SceneManagerTest.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/test') diff --git a/src/test/SceneManagerTest.cpp b/src/test/SceneManagerTest.cpp index 1efcfb2..1706de0 100644 --- a/src/test/SceneManagerTest.cpp +++ b/src/test/SceneManagerTest.cpp @@ -12,10 +12,8 @@ using namespace crepe; class ConcreteScene1 : public Scene { public: - using Scene::Scene; - void load_scene() { - auto & mgr = this->component_manager; + ComponentManager & mgr = this->component_manager; GameObject object1 = mgr.new_object("scene_1", "tag_scene_1", Vector2{0, 0}, 0, 1); GameObject object2 = mgr.new_object("scene_1", "tag_scene_1", Vector2{1, 0}, 0, 1); GameObject object3 = mgr.new_object("scene_1", "tag_scene_1", Vector2{2, 0}, 0, 1); @@ -26,10 +24,8 @@ public: class ConcreteScene2 : public Scene { public: - using Scene::Scene; - void load_scene() { - auto & mgr = this->component_manager; + ComponentManager & mgr = this->component_manager; GameObject object1 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 0}, 0, 1); GameObject object2 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 1}, 0, 1); GameObject object3 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 2}, 0, 1); -- cgit v1.2.3 From 2052988dba049cfa2032d01ff9e6f7bb53d084fe Mon Sep 17 00:00:00 2001 From: max-001 Date: Fri, 22 Nov 2024 09:46:35 +0100 Subject: Added perfect forwarding test --- src/test/SceneManagerTest.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/test') diff --git a/src/test/SceneManagerTest.cpp b/src/test/SceneManagerTest.cpp index 1706de0..cd3b827 100644 --- a/src/test/SceneManagerTest.cpp +++ b/src/test/SceneManagerTest.cpp @@ -35,6 +35,21 @@ public: string get_name() const { return "scene2"; } }; +class ConcreteScene3 : public Scene { +public: + ConcreteScene3(const string & name) : name(name) {} + + void load_scene() { + ComponentManager & mgr = this->component_manager; + GameObject object1 = mgr.new_object("scene_3", "tag_scene_3", Vector2{0, 0}, 0, 1); + } + + string get_name() const { return name; } + +private: + const string name; +}; + class SceneManagerTest : public ::testing::Test { public: ComponentManager component_mgr{}; @@ -120,3 +135,25 @@ TEST_F(SceneManagerTest, loadScene) { EXPECT_EQ(transform[3].get().position.x, 0); EXPECT_EQ(transform[3].get().position.y, 3); } + +TEST_F(SceneManagerTest, perfectForwarding) { + scene_mgr.add_scene("scene3"); + + scene_mgr.load_next_scene(); + + vector> metadata + = component_mgr.get_components_by_type(); + vector> transform + = component_mgr.get_components_by_type(); + + EXPECT_EQ(metadata.size(), 1); + EXPECT_EQ(transform.size(), 1); + + EXPECT_EQ(metadata[0].get().game_object_id, 0); + EXPECT_EQ(metadata[0].get().name, "scene_3"); + EXPECT_EQ(metadata[0].get().tag, "tag_scene_3"); + EXPECT_EQ(metadata[0].get().parent, -1); + EXPECT_EQ(metadata[0].get().children.size(), 0); + EXPECT_EQ(transform[0].get().position.x, 0); + EXPECT_EQ(transform[0].get().position.y, 0); +} -- cgit v1.2.3 From 1a56d7dcbf0c7375c2f0b1bb2dcd2b108a489fa8 Mon Sep 17 00:00:00 2001 From: max-001 Date: Sun, 24 Nov 2024 12:03:21 +0100 Subject: Make format --- src/test/SceneManagerTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/SceneManagerTest.cpp b/src/test/SceneManagerTest.cpp index 3b61d5c..62b7d33 100644 --- a/src/test/SceneManagerTest.cpp +++ b/src/test/SceneManagerTest.cpp @@ -139,7 +139,7 @@ TEST_F(SceneManagerTest, loadScene) { TEST_F(SceneManagerTest, perfectForwarding) { scene_mgr.add_scene("scene3"); - + scene_mgr.load_next_scene(); vector> metadata -- cgit v1.2.3