feat: add engine test
This commit is contained in:
@@ -25,6 +25,11 @@ add_executable(db_provider_test
|
|||||||
src/engine/core/engine.cpp
|
src/engine/core/engine.cpp
|
||||||
src/engine/core/engine_db_provider.cpp
|
src/engine/core/engine_db_provider.cpp
|
||||||
)
|
)
|
||||||
|
add_executable(engine_test
|
||||||
|
tests/engine/engine_test.cpp
|
||||||
|
src/engine/core/engine.cpp
|
||||||
|
src/engine/core/engine_db_provider.cpp
|
||||||
|
)
|
||||||
|
|
||||||
target_include_directories(event_bus_test PUBLIC "${CMAKE_SOURCE_DIR}/include")
|
target_include_directories(event_bus_test PUBLIC "${CMAKE_SOURCE_DIR}/include")
|
||||||
target_link_libraries(event_bus_test PRIVATE SQLite::SQLite3)
|
target_link_libraries(event_bus_test PRIVATE SQLite::SQLite3)
|
||||||
@@ -32,6 +37,9 @@ target_link_libraries(event_bus_test PRIVATE SQLite::SQLite3)
|
|||||||
target_include_directories(db_provider_test PUBLIC "${CMAKE_SOURCE_DIR}/include")
|
target_include_directories(db_provider_test PUBLIC "${CMAKE_SOURCE_DIR}/include")
|
||||||
target_link_libraries(db_provider_test PRIVATE SQLite::SQLite3)
|
target_link_libraries(db_provider_test PRIVATE SQLite::SQLite3)
|
||||||
|
|
||||||
|
target_include_directories(engine_test PUBLIC "${CMAKE_SOURCE_DIR}/include")
|
||||||
|
target_link_libraries(engine_test PRIVATE SQLite::SQLite3)
|
||||||
|
|
||||||
add_test(
|
add_test(
|
||||||
NAME "Event Bus"
|
NAME "Event Bus"
|
||||||
COMMAND event_bus_test
|
COMMAND event_bus_test
|
||||||
@@ -40,3 +48,7 @@ add_test(
|
|||||||
NAME "Database Provider"
|
NAME "Database Provider"
|
||||||
COMMAND db_provider_test
|
COMMAND db_provider_test
|
||||||
)
|
)
|
||||||
|
add_test(
|
||||||
|
NAME "Engine"
|
||||||
|
COMMAND engine_test
|
||||||
|
)
|
||||||
|
|||||||
@@ -0,0 +1,149 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user