feat: impl lifecycle with tests

This commit is contained in:
Samsonium
2026-10-03 15:24:21 +03:00
parent 1a2722da57
commit 8c65860153
5 changed files with 107 additions and 18 deletions
+64
View File
@@ -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;
}