diff options
| -rw-r--r-- | CMakeLists.txt | 2 | ||||
| -rw-r--r-- | domain/CMakeLists.txt | 46 | ||||
| -rw-r--r-- | domain/include/turns/domain/participant.hpp | 30 | ||||
| -rw-r--r-- | domain/src/participant.cpp | 41 | ||||
| -rw-r--r-- | domain/tests/participant.cpp | 43 |
5 files changed, 162 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c1dc323..2b6ae2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ FetchContent_MakeAvailable("Catch2") find_package("Catch2" REQUIRED) +pkg_check_modules("glibmm" IMPORTED_TARGET REQUIRED "glibmm-2.68>=2.80") pkg_check_modules("gtkmm" IMPORTED_TARGET REQUIRED "gtkmm-4.0>=4.14") pkg_check_modules("adwaita" IMPORTED_TARGET REQUIRED "libadwaita-1>=1.5.0") @@ -51,6 +52,7 @@ include("Catch") # Targets add_subdirectory("app") +add_subdirectory("domain") add_subdirectory("res") # License diff --git a/domain/CMakeLists.txt b/domain/CMakeLists.txt new file mode 100644 index 0000000..5e4201c --- /dev/null +++ b/domain/CMakeLists.txt @@ -0,0 +1,46 @@ +# Library + +add_library("domain" + "src/participant.cpp" +) + +add_library("turns::domain" ALIAS "domain") + + +target_compile_options("domain" PUBLIC + "$<$<CXX_COMPILER_ID:GNU,Clang>:-Wall>" + "$<$<CXX_COMPILER_ID:GNU,Clang>:-Wextra>" + "$<$<CXX_COMPILER_ID:GNU,Clang>:-Werror>" + "$<$<CXX_COMPILER_ID:GNU,Clang>:-pedantic-errors>" + PRIVATE + "$<$<AND:$<CXX_COMPILER_ID:GNU,Clang>,$<CONFIG:Debug>>:-fprofile-arcs>" + "$<$<AND:$<CXX_COMPILER_ID:GNU,Clang>,$<CONFIG:Debug>>:-ftest-coverage>" +) + +target_include_directories("domain" PUBLIC + "include" +) + +target_link_libraries("domain" PUBLIC + "$<$<AND:$<CXX_COMPILER_ID:GNU,Clang>,$<CONFIG:Debug>>:gcov>" + + "PkgConfig::glibmm" +) + +target_link_options("domain" PRIVATE + "$<$<AND:$<CXX_COMPILER_ID:GNU,Clang>,$<CONFIG:Debug>>:--coverage>" +) + +# Tests + +add_executable("domain-tests" + "tests/participant.cpp" +) + +target_link_libraries("domain-tests" + "Catch2::Catch2WithMain" + + "turns::domain" +) + +catch_discover_tests("domain-tests")
\ No newline at end of file diff --git a/domain/include/turns/domain/participant.hpp b/domain/include/turns/domain/participant.hpp new file mode 100644 index 0000000..760ba31 --- /dev/null +++ b/domain/include/turns/domain/participant.hpp @@ -0,0 +1,30 @@ +#ifndef TURNS_DOMAIN_PARTICIPANT_HPP +#define TURNS_DOMAIN_PARTICIPANT_HPP + +#include <glibmm/object.h> +#include <glibmm/refptr.h> +#include <glibmm/ustring.h> + +namespace turns::domain +{ + + struct participant : Glib::Object + { + auto static create(Glib::ustring name, float order_value) -> Glib::RefPtr<participant>; + + auto name() const noexcept -> Glib::ustring const &; + auto name(Glib::ustring value) -> participant &; + + auto order() const noexcept -> float; + auto order(float) noexcept -> participant &; + + private: + participant(Glib::ustring name, float order_value); + + Glib::ustring m_name; + float m_order_value; + }; + +} // namespace turns::domain + +#endif
\ No newline at end of file diff --git a/domain/src/participant.cpp b/domain/src/participant.cpp new file mode 100644 index 0000000..8302024 --- /dev/null +++ b/domain/src/participant.cpp @@ -0,0 +1,41 @@ +#include "turns/domain/participant.hpp" + +#include <utility> + +namespace turns::domain +{ + + auto participant::create(Glib::ustring name, float order_value) -> Glib::RefPtr<participant> + { + return Glib::make_refptr_for_instance(new participant{name, order_value}); + } + + participant::participant(Glib::ustring name, float order_value) + : m_name{std::move(name)} + , m_order_value{order_value} + { + } + + auto participant::name() const noexcept -> Glib::ustring const & + { + return m_name; + } + + auto participant::name(Glib::ustring value) -> participant & + { + m_name = std::move(value); + return *this; + } + + auto participant::order() const noexcept -> float + { + return m_order_value; + } + + auto participant::order(float value) noexcept -> participant & + { + m_order_value = value; + return *this; + } + +} // namespace turns::domain
\ No newline at end of file diff --git a/domain/tests/participant.cpp b/domain/tests/participant.cpp new file mode 100644 index 0000000..7220209 --- /dev/null +++ b/domain/tests/participant.cpp @@ -0,0 +1,43 @@ +#include "turns/domain/participant.hpp" + +#include <catch2/catch_test_macros.hpp> + +namespace turns::domain::tests +{ + + TEST_CASE("A participant") + { + + auto constexpr constructed_name = "Vana Thistletop"; + auto constexpr constructed_order = 17; + auto instance = participant::create(constructed_name, constructed_order); + + SECTION("can be created") + { + REQUIRE(instance); + } + + SECTION("the name can be read") + { + REQUIRE(instance->name() == constructed_name); + } + + SECTION("the name can be changed") + { + instance->name("replaced"); + REQUIRE(instance->name() == "replaced"); + } + + SECTION("the order can be read") + { + REQUIRE(instance->order() == constructed_order); + } + + SECTION("the order can be changed") + { + instance->order(8); + REQUIRE(instance->order() == 8); + } + } + +} // namespace turns::domain::tests
\ No newline at end of file |
