Files
Magic-Scrolls/tests/engine/lifecycle_test.cpp
T

65 lines
1.4 KiB
C++

#include "engine/core/engine.hpp"
#include "engine/core/engine_module.hpp"
#include "engine/utils/rev_range.hpp"
#include <cassert>
#include <cstdint>
#include <memory>
#include <string>
#include <unordered_map>
bool onInitWasCalled = false;
bool onStartWasCalled = false;
bool onUpdateWasCalled = false;
bool onStopWasCalled = false;
class TestModule : public MscEngineModule
{
public:
std::string getName() const override { return "test_mod"; }
std::uint16_t getRev() const override { return 1; }
const std::unordered_map<std::string, MscRevisionRange> &
getDependencies() const override
{
static const std::unordered_map<std::string, MscRevisionRange> deps{};
return deps;
}
void onInitialize(IMscEngineModuleAPI &engine) override
{
onInitWasCalled = true;
}
void onStart(IMscEngineModuleAPI &engine) override
{
onStartWasCalled = true;
}
void onUpdate(IMscEngineModuleAPI &engine,
IMscEngineModuleAPI::clock::duration dt) override
{
onUpdateWasCalled = true;
engine.requestStop();
}
void onStop(IMscEngineModuleAPI &engine) override { onStopWasCalled = true; }
void onDestory(IMscEngineModuleAPI &engine) override {}
};
void testStates()
{
MscEngine engine({std::make_shared<TestModule>()});
engine.start();
assert(onInitWasCalled);
assert(onStartWasCalled);
assert(onUpdateWasCalled);
assert(onStopWasCalled);
}
int main()
{
testStates();
return 0;
}