X-Git-Url: http://git.localhorst.tv/?p=blobs.git;a=blobdiff_plain;f=tst%2Fapp%2FMasterTest.cpp;h=1624efa0cf6099960272fb295bb2692b89d561e7;hp=c9ab2d90d672ea60febbe8b3e2775a31c93f8db6;hb=cf31daa35ac163986158b6f95df06fd7b43f6e79;hpb=34697f07a0bb7b26b3eb2f102d18fb74e5ed7ec4 diff --git a/tst/app/MasterTest.cpp b/tst/app/MasterTest.cpp index c9ab2d9..1624efa 100644 --- a/tst/app/MasterTest.cpp +++ b/tst/app/MasterTest.cpp @@ -1,14 +1,21 @@ #include "MasterTest.hpp" +#include "../event.hpp" + #include "app/Application.hpp" #include "app/Assets.hpp" #include "app/init.hpp" #include "app/MasterState.hpp" #include "creature/Creature.hpp" +#include "world/Planet.hpp" #include "world/Simulation.hpp" CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(blobs::app::test::MasterTest, "headed"); +using blobs::test::FakeKeyPress; +using blobs::test::FakeMouseClick; +using blobs::test::FakeQuit; + namespace blobs { namespace app { @@ -47,6 +54,101 @@ void MasterTest::testOneSecond() { } } +void MasterTest::testBasicInteraction() { + Init init(false, 1); + Assets assets; + + world::Simulation sim(assets); + assets.LoadUniverse("universe", sim); + + auto blob = new creature::Creature(sim); + blob->Name(assets.name.Sequential()); + Spawn(*blob, sim.PlanetByName("Planet")); + // decrease chances of ur-blob dying without splitting + blob->GetProperties().Fertility() = 1.0; + blob->BuildVAO(); + + app::MasterState state(assets, sim); + state.Show(*blob); + + app::Application app(init.window, init.viewport); + app.PushState(&state); + + // skip first 200ms to let camera settle + for (int t = 0; t < 200; t += 17) { + app.Loop(17); + } + + CPPUNIT_ASSERT_MESSAGE( + "creature panel not shown", + state.GetCreaturePanel().Shown() + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "creature panel showing wrong creature", + const_cast(blob), &state.GetCreaturePanel().GetCreature() + ); + CPPUNIT_ASSERT_MESSAGE( + "records panel not shown", + state.GetRecordsPanel().Shown() + ); + CPPUNIT_ASSERT_MESSAGE( + "body panel shown", + !state.GetBodyPanel().Shown() + ); + + // hide records panel + FakeKeyPress(SDLK_F1); + app.Loop(17); + CPPUNIT_ASSERT_MESSAGE( + "records panel shown", + !state.GetRecordsPanel().Shown() + ); + + // show records panel + FakeKeyPress(SDLK_F1); + app.Loop(17); + CPPUNIT_ASSERT_MESSAGE( + "records panel not shown", + state.GetRecordsPanel().Shown() + ); + + // click on blob + FakeMouseClick(SDL_BUTTON_LEFT, init.viewport.Width() / 2, init.viewport.Height() / 2); + app.Loop(17); + CPPUNIT_ASSERT_MESSAGE( + "creature panel not shown", + state.GetCreaturePanel().Shown() + ); + CPPUNIT_ASSERT_MESSAGE( + "body panel shown", + !state.GetBodyPanel().Shown() + ); + + // click on planet + FakeMouseClick(SDL_BUTTON_LEFT, init.viewport.Width() / 3, init.viewport.Height() / 2); + app.Loop(17); + CPPUNIT_ASSERT_MESSAGE( + "creature panel shown", + !state.GetCreaturePanel().Shown() + ); + CPPUNIT_ASSERT_MESSAGE( + "body panel not shown", + state.GetBodyPanel().Shown() + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "body panel showing wrong body", + static_cast(&sim.PlanetByName("Planet")), &state.GetBodyPanel().GetBody() + ); + + // close window + FakeQuit(); + app.Loop(17); + CPPUNIT_ASSERT_MESSAGE( + "app didn't exit after quit event", + !app.HasState() + ); +} + } } }