From e714303c486fb81851116710ba5d68e1b469df02 Mon Sep 17 00:00:00 2001 From: max-001 Date: Wed, 20 Nov 2024 10:59:34 +0100 Subject: Added SceneManager tests --- src/test/SceneManagerTest.cpp | 120 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/test/SceneManagerTest.cpp (limited to 'src/test/SceneManagerTest.cpp') diff --git a/src/test/SceneManagerTest.cpp b/src/test/SceneManagerTest.cpp new file mode 100644 index 0000000..98b2a23 --- /dev/null +++ b/src/test/SceneManagerTest.cpp @@ -0,0 +1,120 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace crepe; + +class ConcreteScene1 : public Scene { +public: + using Scene::Scene; + + void load_scene() { + auto & 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); + } +}; + +class ConcreteScene2 : public Scene { +public: + using Scene::Scene; + + void load_scene() { + auto & 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); + GameObject object4 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 3}, 0, 1); + } +}; + +class SceneManagerTest : public ::testing::Test { +public: + ComponentManager component_mgr{}; + SceneManager scene_mgr{component_mgr}; +}; + +TEST_F(SceneManagerTest, loadScene) { + scene_mgr.add_scene("scene1"); + scene_mgr.add_scene("scene2"); + + 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(), 3); + EXPECT_EQ(transform.size(), 3); + + EXPECT_EQ(metadata[0].get().game_object_id, 0); + EXPECT_EQ(metadata[0].get().name, "scene_1"); + EXPECT_EQ(metadata[0].get().tag, "tag_scene_1"); + 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); + + EXPECT_EQ(metadata[1].get().game_object_id, 1); + EXPECT_EQ(metadata[1].get().name, "scene_1"); + EXPECT_EQ(metadata[1].get().tag, "tag_scene_1"); + EXPECT_EQ(metadata[1].get().parent, -1); + EXPECT_EQ(metadata[1].get().children.size(), 0); + EXPECT_EQ(transform[1].get().position.x, 1); + EXPECT_EQ(transform[1].get().position.y, 0); + + EXPECT_EQ(metadata[2].get().game_object_id, 2); + EXPECT_EQ(metadata[2].get().name, "scene_1"); + EXPECT_EQ(metadata[2].get().tag, "tag_scene_1"); + EXPECT_EQ(metadata[2].get().parent, -1); + EXPECT_EQ(metadata[2].get().children.size(), 0); + EXPECT_EQ(transform[2].get().position.x, 2); + EXPECT_EQ(transform[2].get().position.y, 0); + + scene_mgr.set_next_scene("scene2"); + scene_mgr.load_next_scene(); + + metadata = component_mgr.get_components_by_type(); + transform = component_mgr.get_components_by_type(); + + EXPECT_EQ(metadata.size(), 4); + EXPECT_EQ(transform.size(), 4); + + EXPECT_EQ(metadata[0].get().game_object_id, 0); + EXPECT_EQ(metadata[0].get().name, "scene_2"); + EXPECT_EQ(metadata[0].get().tag, "tag_scene_2"); + 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); + + EXPECT_EQ(metadata[1].get().game_object_id, 1); + EXPECT_EQ(metadata[1].get().name, "scene_2"); + EXPECT_EQ(metadata[1].get().tag, "tag_scene_2"); + EXPECT_EQ(metadata[1].get().parent, -1); + EXPECT_EQ(metadata[1].get().children.size(), 0); + EXPECT_EQ(transform[1].get().position.x, 0); + EXPECT_EQ(transform[1].get().position.y, 1); + + EXPECT_EQ(metadata[2].get().game_object_id, 2); + EXPECT_EQ(metadata[2].get().name, "scene_2"); + EXPECT_EQ(metadata[2].get().tag, "tag_scene_2"); + EXPECT_EQ(metadata[2].get().parent, -1); + EXPECT_EQ(metadata[2].get().children.size(), 0); + EXPECT_EQ(transform[2].get().position.x, 0); + EXPECT_EQ(transform[2].get().position.y, 2); + + EXPECT_EQ(metadata[3].get().game_object_id, 3); + EXPECT_EQ(metadata[3].get().name, "scene_2"); + EXPECT_EQ(metadata[3].get().tag, "tag_scene_2"); + EXPECT_EQ(metadata[3].get().parent, -1); + EXPECT_EQ(metadata[3].get().children.size(), 0); + EXPECT_EQ(transform[3].get().position.x, 0); + EXPECT_EQ(transform[3].get().position.y, 3); +} -- cgit v1.2.3 From fb35ca64eee9afdd72f2cf8d279c4e745444baf9 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 20 Nov 2024 14:51:26 +0100 Subject: `make format` --- src/test/ECSTest.cpp | 15 +++++++++------ src/test/SceneManagerTest.cpp | 10 ++++++---- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src/test/SceneManagerTest.cpp') diff --git a/src/test/ECSTest.cpp b/src/test/ECSTest.cpp index eaa2dbc..d5a5826 100644 --- a/src/test/ECSTest.cpp +++ b/src/test/ECSTest.cpp @@ -1,3 +1,5 @@ +#include + #define protected public #include @@ -5,7 +7,6 @@ #include #include #include -#include using namespace std; using namespace crepe; @@ -94,7 +95,7 @@ TEST_F(ECSTest, deleteGameObject) { } TEST_F(ECSTest, manyGameObjects) { - for(int i = 0; i < 5000; i++) { + for (int i = 0; i < 5000; i++) { GameObject obj = mgr.new_object("body", "person", Vector2{0, 0}, 0, i); } @@ -103,7 +104,7 @@ TEST_F(ECSTest, manyGameObjects) { EXPECT_EQ(metadata.size(), 5000); EXPECT_EQ(transform.size(), 5000); - for(int i = 0; i < 5000; i++) { + for (int i = 0; i < 5000; i++) { EXPECT_EQ(metadata[i].get().game_object_id, i); EXPECT_EQ(metadata[i].get().name, "body"); EXPECT_EQ(metadata[i].get().tag, "person"); @@ -125,7 +126,7 @@ TEST_F(ECSTest, manyGameObjects) { EXPECT_EQ(metadata.size(), 0); EXPECT_EQ(transform.size(), 5000); - for(int i = 0; i < 10000 - 5000; i++) { + for (int i = 0; i < 10000 - 5000; i++) { string tag = "person" + to_string(i); GameObject obj = mgr.new_object("body", tag, Vector2{0, 0}, i, 0); } @@ -165,14 +166,16 @@ TEST_F(ECSTest, tooMuchComponents) { GameObject obj0 = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); obj0.add_component(Vector2{10, 10}, 0, 1); } catch (const exception & e) { - EXPECT_EQ(e.what(), string("Exceeded maximum number of instances for this component type")); + EXPECT_EQ(e.what(), + string("Exceeded maximum number of instances for this component type")); } try { GameObject obj1 = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); obj1.add_component("body", "person"); } catch (const exception & e) { - EXPECT_EQ(e.what(), string("Exceeded maximum number of instances for this component type")); + EXPECT_EQ(e.what(), + string("Exceeded maximum number of instances for this component type")); } vector> metadata = mgr.get_components_by_type(); diff --git a/src/test/SceneManagerTest.cpp b/src/test/SceneManagerTest.cpp index 98b2a23..69e1171 100644 --- a/src/test/SceneManagerTest.cpp +++ b/src/test/SceneManagerTest.cpp @@ -1,10 +1,10 @@ #include #include #include -#include -#include #include #include +#include +#include #include using namespace std; @@ -47,8 +47,10 @@ TEST_F(SceneManagerTest, loadScene) { scene_mgr.load_next_scene(); - vector> metadata = component_mgr.get_components_by_type(); - vector> transform = component_mgr.get_components_by_type(); + vector> metadata + = component_mgr.get_components_by_type(); + vector> transform + = component_mgr.get_components_by_type(); EXPECT_EQ(metadata.size(), 3); EXPECT_EQ(transform.size(), 3); -- cgit v1.2.3