feat: impl lifecycle with tests
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user