diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index af1cfb6..1d2731b 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -1,4 +1,5 @@ # other features set(CMAKE_CXX_CLANG_TIDY clang-tidy) +add_subdirectory(common) add_subdirectory(cli) diff --git a/libs/common/CMakeLists.txt b/libs/common/CMakeLists.txt new file mode 100644 index 0000000..b11e859 --- /dev/null +++ b/libs/common/CMakeLists.txt @@ -0,0 +1,8 @@ +add_library(common INTERFACE) +target_include_directories(common INTERFACE include) + +add_executable(common_test src/command.test.cpp) +target_link_libraries(common_test common gtest gmock gtest_main) + +include(GoogleTest) +gtest_discover_tests(common_test) diff --git a/libs/common/include/command.hpp b/libs/common/include/command.hpp new file mode 100644 index 0000000..1ec8d2b --- /dev/null +++ b/libs/common/include/command.hpp @@ -0,0 +1,27 @@ +/// \file +/// \copyright SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include +#include + +namespace command { + +class Command { + public: + virtual ~Command() = default; + virtual void execute() const = 0; +}; + +class PrintCommand : public Command { + public: + explicit PrintCommand(std::string_view sv) : message{std::move(sv)} {} + + void execute() const override { std::cout << message << std::endl; } + + private: + std::string_view message; +}; + +} // namespace command diff --git a/libs/common/src/command.test.cpp b/libs/common/src/command.test.cpp new file mode 100644 index 0000000..497fd07 --- /dev/null +++ b/libs/common/src/command.test.cpp @@ -0,0 +1,16 @@ +/// \copyright SPDX-License-Identifier: GPL-3.0-or-later + +#include "command.hpp" + +#include + +namespace command { + +TEST(CommandTest, Initialization) { + const PrintCommand command{"Hi!"}; + + auto execute = [](const command::Command& cmd) { cmd.execute(); }; + execute(command); +} + +} // namespace command