#include #include #include #include #include #include #include #include #include using namespace std; using namespace crepe; class ConcreteScene1 : public Scene { public: void load_scene() { GameObject object1 = new_object("scene_1", "tag_scene_1", vec2 {0, 0}, 0, 1); GameObject object2 = new_object("scene_1", "tag_scene_1", vec2 {1, 0}, 0, 1); GameObject object3 = new_object("scene_1", "tag_scene_1", vec2 {2, 0}, 0, 1); } string get_name() const { return "scene1"; } }; class ConcreteScene2 : public Scene { public: void load_scene() { GameObject object1 = new_object("scene_2", "tag_scene_2", vec2 {0, 0}, 0, 1); GameObject object2 = new_object("scene_2", "tag_scene_2", vec2 {0, 1}, 0, 1); GameObject object3 = new_object("scene_2", "tag_scene_2", vec2 {0, 2}, 0, 1); GameObject object4 = new_object("scene_2", "tag_scene_2", vec2 {0, 3}, 0, 1); } string get_name() const { return "scene2"; } }; class ConcreteScene3 : public Scene { public: ConcreteScene3(const string & name) : name(name) {} void load_scene() { GameObject object1 = new_object("scene_3", "tag_scene_3", vec2 {0, 0}, 0, 1); } string get_name() const { return name; } private: const string name; }; class SceneManagerTest : public ::testing::Test { Mediator m; public: ComponentManager component_mgr {m}; SceneManager scene_mgr {m}; }; TEST_F(SceneManagerTest, loadScene) { scene_mgr.add_scene(); scene_mgr.add_scene(); 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); } 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); }