From 160e932f2e8b8fa4d89d50a44d501492b82fdb54 Mon Sep 17 00:00:00 2001 From: Samsonium Date: Tue, 29 Sep 2026 15:19:18 +0300 Subject: [PATCH] feat: add engine test --- CMakeLists.txt | 12 +++ tests/engine/engine_test.cpp | 149 +++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 tests/engine/engine_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1252706..86dffa8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,11 @@ add_executable(db_provider_test src/engine/core/engine.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_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_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( NAME "Event Bus" COMMAND event_bus_test @@ -40,3 +48,7 @@ add_test( NAME "Database Provider" COMMAND db_provider_test ) +add_test( + NAME "Engine" + COMMAND engine_test +) diff --git a/tests/engine/engine_test.cpp b/tests/engine/engine_test.cpp new file mode 100644 index 0000000..8aadfc0 --- /dev/null +++ b/tests/engine/engine_test.cpp @@ -0,0 +1,149 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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 &getDependencies() const override + { + static const std::unordered_map 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 &getDependencies() const override + { + static const std::unordered_map 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 &getDependencies() const override + { + static const std::unordered_map 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 &getDependencies() const override + { + static const std::unordered_map deps{ + {"first_tmod", MscRevisionRange{1, 2}}}; + return deps; + } + + void onInitialize(IMscEngineModuleAPI &engine) override {} +}; + +void testSatisfiedModules() +{ + MscEngine engine({std::make_shared(), + std::make_shared()}); +} + +void testDuplicatedModules() +{ + try + { + MscEngine engine({ + std::make_shared(), + std::make_shared(), + }); + assert(false); + } + catch (const std::runtime_error &error) + { + } +} + +void testUnsatisfiedModules() +{ + try + { + MscEngine engine({std::make_shared(), + std::make_shared()}); + assert(false); + } + catch (const std::runtime_error &error) + { + } +} + +void testSatisfiedMultiversionModule() +{ + MscEngine engine({std::make_shared(), + std::make_shared()}); +} + +int main() +{ + testSatisfiedModules(); + testDuplicatedModules(); + testUnsatisfiedModules(); + testSatisfiedMultiversionModule(); + + return 0; +}