1 #include "MasterTest.hpp"
3 #include "../event.hpp"
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"
13 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(blobs::app::test::MasterTest, "headed");
15 using blobs::test::FakeKeyPress;
16 using blobs::test::FakeMouseClick;
17 using blobs::test::FakeQuit;
24 void MasterTest::setUp() {
27 void MasterTest::tearDown() {
31 void MasterTest::testOneSecond() {
35 world::Simulation sim(assets);
36 assets.LoadUniverse("universe", sim);
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;
45 app::MasterState state(assets, sim);
48 app::Application app(init.window, init.viewport);
49 app.PushState(&state);
51 // just run it for one second and check if anything segfaults or throws
52 for (int t = 0; t < 1000; t += 17) {
57 void MasterTest::testBasicInteraction() {
61 world::Simulation sim(assets);
62 assets.LoadUniverse("universe", sim);
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;
71 app::MasterState state(assets, sim);
74 app::Application app(init.window, init.viewport);
75 app.PushState(&state);
77 // skip first 200ms to let camera settle
78 for (int t = 0; t < 200; t += 17) {
82 CPPUNIT_ASSERT_MESSAGE(
83 "creature panel not shown",
84 state.GetCreaturePanel().Shown()
86 CPPUNIT_ASSERT_EQUAL_MESSAGE(
87 "creature panel showing wrong creature",
88 const_cast<const creature::Creature *>(blob), &state.GetCreaturePanel().GetCreature()
90 CPPUNIT_ASSERT_MESSAGE(
91 "records panel not shown",
92 state.GetRecordsPanel().Shown()
94 CPPUNIT_ASSERT_MESSAGE(
96 !state.GetBodyPanel().Shown()
100 FakeKeyPress(SDLK_F1);
102 CPPUNIT_ASSERT_MESSAGE(
103 "records panel shown",
104 !state.GetRecordsPanel().Shown()
107 // show records panel
108 FakeKeyPress(SDLK_F1);
110 CPPUNIT_ASSERT_MESSAGE(
111 "records panel not shown",
112 state.GetRecordsPanel().Shown()
116 FakeMouseClick(SDL_BUTTON_LEFT, init.viewport.Width() / 2, init.viewport.Height() / 2);
118 CPPUNIT_ASSERT_MESSAGE(
119 "creature panel not shown",
120 state.GetCreaturePanel().Shown()
122 CPPUNIT_ASSERT_MESSAGE(
124 !state.GetBodyPanel().Shown()
128 FakeMouseClick(SDL_BUTTON_LEFT, init.viewport.Width() / 3, init.viewport.Height() / 2);
130 CPPUNIT_ASSERT_MESSAGE(
131 "creature panel shown",
132 !state.GetCreaturePanel().Shown()
134 CPPUNIT_ASSERT_MESSAGE(
135 "body panel not shown",
136 state.GetBodyPanel().Shown()
138 CPPUNIT_ASSERT_EQUAL_MESSAGE(
139 "body panel showing wrong body",
140 static_cast<const world::Body *>(&sim.PlanetByName("Planet")), &state.GetBodyPanel().GetBody()
146 CPPUNIT_ASSERT_MESSAGE(
147 "app didn't exit after quit event",