158 lines
4.1 KiB
C++
158 lines
4.1 KiB
C++
#include <cassert>
|
|
#include <cstdint>
|
|
#include <engine/core/engine.hpp>
|
|
#include <engine/core/engine_module.hpp>
|
|
#include <engine/utils/rev_range.hpp>
|
|
#include <memory>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
class FirstTestModuleR1 : public MscEngineModule
|
|
{
|
|
public:
|
|
std::string getName() const override { return "first_tmod"; };
|
|
|
|
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 {}
|
|
void onStart(IMscEngineModuleAPI &engine) override {}
|
|
void onUpdate(IMscEngineModuleAPI &engine,
|
|
IMscEngineModuleAPI::clock::duration dt) override
|
|
{
|
|
}
|
|
void onStop(IMscEngineModuleAPI &engine) override {}
|
|
void onDestory(IMscEngineModuleAPI &engine) override {}
|
|
};
|
|
|
|
class FirstTestModuleR2 : public MscEngineModule
|
|
{
|
|
public:
|
|
std::string getName() const override { return "first_tmod"; };
|
|
|
|
std::uint16_t getRev() const override { return 2; }
|
|
|
|
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 {}
|
|
void onStart(IMscEngineModuleAPI &engine) override {}
|
|
void onUpdate(IMscEngineModuleAPI &engine,
|
|
IMscEngineModuleAPI::clock::duration dt) override
|
|
{
|
|
}
|
|
void onStop(IMscEngineModuleAPI &engine) override {}
|
|
void onDestory(IMscEngineModuleAPI &engine) override {}
|
|
};
|
|
|
|
class SecondTestModuleE1 : public MscEngineModule
|
|
{
|
|
public:
|
|
std::string getName() const override { return "second_tmod"; }
|
|
|
|
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{
|
|
{"first_tmod", MscRevisionRange{1, 1}}};
|
|
return deps;
|
|
}
|
|
|
|
void onInitialize(IMscEngineModuleAPI &engine) override {}
|
|
void onStart(IMscEngineModuleAPI &engine) override {}
|
|
void onUpdate(IMscEngineModuleAPI &engine,
|
|
IMscEngineModuleAPI::clock::duration dt) override
|
|
{
|
|
}
|
|
void onStop(IMscEngineModuleAPI &engine) override {}
|
|
void onDestory(IMscEngineModuleAPI &engine) override {}
|
|
};
|
|
|
|
class SecondTestModuleE2 : public MscEngineModule
|
|
{
|
|
public:
|
|
std::string getName() const override { return "second_tmod"; }
|
|
|
|
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{
|
|
{"first_tmod", MscRevisionRange{1, 2}}};
|
|
return deps;
|
|
}
|
|
|
|
void onInitialize(IMscEngineModuleAPI &engine) override {}
|
|
void onStart(IMscEngineModuleAPI &engine) override {}
|
|
void onUpdate(IMscEngineModuleAPI &engine,
|
|
IMscEngineModuleAPI::clock::duration dt) override
|
|
{
|
|
}
|
|
void onStop(IMscEngineModuleAPI &engine) override {}
|
|
void onDestory(IMscEngineModuleAPI &engine) override {}
|
|
};
|
|
|
|
void testSatisfiedModules()
|
|
{
|
|
MscEngine engine({std::make_shared<FirstTestModuleR1>(),
|
|
std::make_shared<SecondTestModuleE1>()});
|
|
}
|
|
|
|
void testDuplicatedModules()
|
|
{
|
|
try
|
|
{
|
|
MscEngine engine({
|
|
std::make_shared<FirstTestModuleR1>(),
|
|
std::make_shared<FirstTestModuleR2>(),
|
|
});
|
|
assert(false);
|
|
}
|
|
catch (const std::runtime_error &error)
|
|
{
|
|
}
|
|
}
|
|
|
|
void testUnsatisfiedModules()
|
|
{
|
|
try
|
|
{
|
|
MscEngine engine({std::make_shared<FirstTestModuleR2>(),
|
|
std::make_shared<SecondTestModuleE1>()});
|
|
assert(false);
|
|
}
|
|
catch (const std::runtime_error &error)
|
|
{
|
|
}
|
|
}
|
|
|
|
void testSatisfiedMultiversionModule()
|
|
{
|
|
MscEngine engine({std::make_shared<FirstTestModuleR2>(),
|
|
std::make_shared<SecondTestModuleE2>()});
|
|
}
|
|
|
|
int main()
|
|
{
|
|
testSatisfiedModules();
|
|
testDuplicatedModules();
|
|
testUnsatisfiedModules();
|
|
testSatisfiedMultiversionModule();
|
|
|
|
return 0;
|
|
}
|