]> git.localhorst.tv Git - blobs.git/blob - tst/app/MasterTest.cpp
test basic interaction
[blobs.git] / tst / app / MasterTest.cpp
1 #include "MasterTest.hpp"
2
3 #include "../event.hpp"
4
5 #include "app/Application.hpp"
6 #include "app/Assets.hpp"
7 #include "app/init.hpp"
8 #include "app/MasterState.hpp"
9 #include "creature/Creature.hpp"
10 #include "world/Planet.hpp"
11 #include "world/Simulation.hpp"
12
13 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(blobs::app::test::MasterTest, "headed");
14
15 using blobs::test::FakeKeyPress;
16 using blobs::test::FakeMouseClick;
17 using blobs::test::FakeQuit;
18
19
20 namespace blobs {
21 namespace app {
22 namespace test {
23
24 void MasterTest::setUp() {
25 }
26
27 void MasterTest::tearDown() {
28 }
29
30
31 void MasterTest::testOneSecond() {
32         Init init(false, 1);
33         Assets assets;
34
35         world::Simulation sim(assets);
36         assets.LoadUniverse("universe", sim);
37
38         auto blob = new creature::Creature(sim);
39         blob->Name(assets.name.Sequential());
40         Spawn(*blob, sim.PlanetByName("Planet"));
41         // decrease chances of ur-blob dying without splitting
42         blob->GetProperties().Fertility() = 1.0;
43         blob->BuildVAO();
44
45         app::MasterState state(assets, sim);
46         state.Show(*blob);
47
48         app::Application app(init.window, init.viewport);
49         app.PushState(&state);
50
51         // just run it for one second and check if anything segfaults or throws
52         for (int t = 0; t < 1000; t += 17) {
53                 app.Loop(17);
54         }
55 }
56
57 void MasterTest::testBasicInteraction() {
58         Init init(false, 1);
59         Assets assets;
60
61         world::Simulation sim(assets);
62         assets.LoadUniverse("universe", sim);
63
64         auto blob = new creature::Creature(sim);
65         blob->Name(assets.name.Sequential());
66         Spawn(*blob, sim.PlanetByName("Planet"));
67         // decrease chances of ur-blob dying without splitting
68         blob->GetProperties().Fertility() = 1.0;
69         blob->BuildVAO();
70
71         app::MasterState state(assets, sim);
72         state.Show(*blob);
73
74         app::Application app(init.window, init.viewport);
75         app.PushState(&state);
76
77         // skip first 200ms to let camera settle
78         for (int t = 0; t < 200; t += 17) {
79                 app.Loop(17);
80         }
81
82         CPPUNIT_ASSERT_MESSAGE(
83                 "creature panel not shown",
84                 state.GetCreaturePanel().Shown()
85         );
86         CPPUNIT_ASSERT_EQUAL_MESSAGE(
87                 "creature panel showing wrong creature",
88                 const_cast<const creature::Creature *>(blob), &state.GetCreaturePanel().GetCreature()
89         );
90         CPPUNIT_ASSERT_MESSAGE(
91                 "records panel not shown",
92                 state.GetRecordsPanel().Shown()
93         );
94         CPPUNIT_ASSERT_MESSAGE(
95                 "body panel shown",
96                 !state.GetBodyPanel().Shown()
97         );
98
99         // hide records panel
100         FakeKeyPress(SDLK_F1);
101         app.Loop(17);
102         CPPUNIT_ASSERT_MESSAGE(
103                 "records panel shown",
104                 !state.GetRecordsPanel().Shown()
105         );
106
107         // show records panel
108         FakeKeyPress(SDLK_F1);
109         app.Loop(17);
110         CPPUNIT_ASSERT_MESSAGE(
111                 "records panel not shown",
112                 state.GetRecordsPanel().Shown()
113         );
114
115         // click on blob
116         FakeMouseClick(SDL_BUTTON_LEFT, init.viewport.Width() / 2, init.viewport.Height() / 2);
117         app.Loop(17);
118         CPPUNIT_ASSERT_MESSAGE(
119                 "creature panel not shown",
120                 state.GetCreaturePanel().Shown()
121         );
122         CPPUNIT_ASSERT_MESSAGE(
123                 "body panel shown",
124                 !state.GetBodyPanel().Shown()
125         );
126
127         // click on planet
128         FakeMouseClick(SDL_BUTTON_LEFT, init.viewport.Width() / 3, init.viewport.Height() / 2);
129         app.Loop(17);
130         CPPUNIT_ASSERT_MESSAGE(
131                 "creature panel shown",
132                 !state.GetCreaturePanel().Shown()
133         );
134         CPPUNIT_ASSERT_MESSAGE(
135                 "body panel not shown",
136                 state.GetBodyPanel().Shown()
137         );
138         CPPUNIT_ASSERT_EQUAL_MESSAGE(
139                 "body panel showing wrong body",
140                 static_cast<const world::Body *>(&sim.PlanetByName("Planet")), &state.GetBodyPanel().GetBody()
141         );
142
143         // close window
144         FakeQuit();
145         app.Loop(17);
146         CPPUNIT_ASSERT_MESSAGE(
147                 "app didn't exit after quit event",
148                 !app.HasState()
149         );
150 }
151
152 }
153 }
154 }