aboutsummaryrefslogtreecommitdiff
path: root/src/test/SceneManagerTest.cpp
blob: f3d238726b02a66e45aa2458e4e4918546a3b876 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <crepe/ComponentManager.h>
#include <crepe/api/GameObject.h>
#include <crepe/api/Metadata.h>
#include <crepe/api/Scene.h>
#include <crepe/api/SceneManager.h>
#include <crepe/api/Transform.h>
#include <crepe/api/Vector2.h>
#include <gtest/gtest.h>

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", vec2{0, 0}, 0, 1);
		GameObject object2 = mgr.new_object("scene_1", "tag_scene_1", vec2{1, 0}, 0, 1);
		GameObject object3 = mgr.new_object("scene_1", "tag_scene_1", vec2{2, 0}, 0, 1);
	}

	string get_name() const { return "scene1"; }
};

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", vec2{0, 0}, 0, 1);
		GameObject object2 = mgr.new_object("scene_2", "tag_scene_2", vec2{0, 1}, 0, 1);
		GameObject object3 = mgr.new_object("scene_2", "tag_scene_2", vec2{0, 2}, 0, 1);
		GameObject object4 = mgr.new_object("scene_2", "tag_scene_2", vec2{0, 3}, 0, 1);
	}

	string get_name() const { return "scene2"; }
};

class SceneManagerTest : public ::testing::Test {
public:
	ComponentManager component_mgr{};
	SceneManager scene_mgr{component_mgr};
};

TEST_F(SceneManagerTest, loadScene) {
	scene_mgr.add_scene<ConcreteScene1>();
	scene_mgr.add_scene<ConcreteScene2>();

	scene_mgr.load_next_scene();

	vector<reference_wrapper<Metadata>> metadata
		= component_mgr.get_components_by_type<Metadata>();
	vector<reference_wrapper<Transform>> transform
		= component_mgr.get_components_by_type<Transform>();

	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<Metadata>();
	transform = component_mgr.get_components_by_type<Transform>();

	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);
}