150 lines
3.2 KiB
C++
150 lines
3.2 KiB
C++
#include <cassert>
|
|
#include <string>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <stdexcept>
|
|
#include <unordered_map>
|
|
#include <engine/utils/rev_range.hpp>
|
|
#include <engine/core/engine.hpp>
|
|
#include <engine/core/engine_module.hpp>
|
|
|
|
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 {}
|
|
};
|
|
|
|
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 {}
|
|
};
|
|
|
|
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 {}
|
|
};
|
|
|
|
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 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;
|
|
}
|