From ca6745d06563c8f65d86bbc98dffa5e2dec76da2 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Wed, 30 Oct 2024 21:43:09 +0100 Subject: [PATCH 1/4] characteristics_tests.cpp are working --- Unit testing/CMakeLists.txt | 4 ++-- Unit testing/characteristics_tests.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Unit testing/CMakeLists.txt b/Unit testing/CMakeLists.txt index 554d3fd..d3fa7d2 100644 --- a/Unit testing/CMakeLists.txt +++ b/Unit testing/CMakeLists.txt @@ -9,8 +9,8 @@ add_executable(UnitTest adummy.cpp billy_objects_tests.cpp ) -set_target_properties(Catch2 UnitTest svector PROPERTIES CXX_STANDARD 17 +set_target_properties(Catch2 UnitTest PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF INTERPROCEDURAL_OPTIMIZATION_RELEASE ON @@ -20,7 +20,7 @@ target_include_directories(UnitTest PRIVATE ${CMAKE_SOURCE_DIR}/include) target_compile_definitions(UnitTest PRIVATE ${DEF_COMP}) target_compile_options(UnitTest PRIVATE ${COMPILE_FLAGS} -fdiagnostics-all-candidates) target_link_options(UnitTest PRIVATE ${LINKER_OPTIONS}) -target_link_libraries(UnitTest ${LINKER_FLAGS} spdlog::spdlog_header_only Catch2::Catch2WithMain nlohmann_json::nlohmann_json svector::svector BillySheet) +target_link_libraries(UnitTest ${LINKER_FLAGS} Catch2::Catch2WithMain nlohmann_json::nlohmann_json BillySheet) enable_testing() catch_discover_tests(UnitTest WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} REPORTER junit OUTPUT_DIR ${CMAKE_SOURCE_DIR} OUTPUT_PREFIX cppspec- OUTPUT_SUFFIX .xml) diff --git a/Unit testing/characteristics_tests.cpp b/Unit testing/characteristics_tests.cpp index c96d713..34b179b 100644 --- a/Unit testing/characteristics_tests.cpp +++ b/Unit testing/characteristics_tests.cpp @@ -1,7 +1,7 @@ #include -#include "characteristic/characteristic.hpp" -#include "character_sheet.hpp" #include +#include "characteristic.hpp" +#include "character_sheet.hpp" using namespace character::characteristic; From 033c6281268ffba727ce32f57837fe21a102b5d5 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Wed, 30 Oct 2024 22:18:48 +0100 Subject: [PATCH 2/4] Correct target properties --- Unit testing/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Unit testing/CMakeLists.txt b/Unit testing/CMakeLists.txt index d3fa7d2..e07ead7 100644 --- a/Unit testing/CMakeLists.txt +++ b/Unit testing/CMakeLists.txt @@ -9,8 +9,8 @@ add_executable(UnitTest adummy.cpp billy_objects_tests.cpp ) - CXX_STANDARD 17 set_target_properties(Catch2 UnitTest PROPERTIES + CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF INTERPROCEDURAL_OPTIMIZATION_RELEASE ON From 7ed56f1b78161d744ab6cebc01f4c1b997b07e15 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Wed, 30 Oct 2024 22:19:09 +0100 Subject: [PATCH 3/4] Debug property in compile definition is public now. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1258457..4639e0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,7 +88,7 @@ set_target_properties(BillySheet PROPERTIES PUBLIC_HEADER "include/billy_objects.hpp;include/character_sheet.hpp;include/generic_object.hpp;include/characteristic.hpp" ) -target_compile_definitions(BillySheet PRIVATE +target_compile_definitions(BillySheet PUBLIC $<$:_GLIBCXX_DEBUG> ) From 166fa6007a0242b1f6c3c59bcf1ca2780e6a731e Mon Sep 17 00:00:00 2001 From: Pcornat Date: Wed, 30 Oct 2024 22:19:23 +0100 Subject: [PATCH 4/4] Tests on billy objects work now --- Unit testing/billy_objects_tests.cpp | 52 ++++++++++++++++------------ 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/Unit testing/billy_objects_tests.cpp b/Unit testing/billy_objects_tests.cpp index b133b12..904a393 100644 --- a/Unit testing/billy_objects_tests.cpp +++ b/Unit testing/billy_objects_tests.cpp @@ -3,6 +3,7 @@ #include #include "billy_objects.hpp" #include "character_sheet.hpp" +#include "generic_object.hpp" using namespace character; @@ -19,6 +20,13 @@ namespace character::test { void from_json(const json &j, DummyObject &dummy) { BillyObjects::from_json(j, dummy.objects); } + static std::unique_ptr get_obj(const billyEnums &object) noexcept { + return std::visit(overloaded{ + [](const weapons &arg) { return std::unique_ptr(std::make_unique(arg)); }, + [](const equipments &arg) { return std::unique_ptr(std::make_unique(arg)); }, + [](const tools &arg) { return std::unique_ptr(std::make_unique(arg)); }, + }, object); + } } TEST_CASE("[C] Serialize empty BillyObjects", "[serialize][0]") { @@ -44,10 +52,12 @@ TEST_CASE("[C] Serialize full BillyObjects", "[serialize][1]") { test::DummyObject dummy_object; { CharacterSheet sheet; - gestionnaire.push_object(weapons::Sword, sheet); - gestionnaire.push_object(tools::Fourche, sheet); - gestionnaire.push_object(equipments::MedicKit, sheet); - dummy_object.objects = sheet.get_objects(); + REQUIRE(gestionnaire.insert_object(sheet, weapons::Sword)); + REQUIRE(gestionnaire.insert_object(sheet, tools::Fourche)); + REQUIRE(gestionnaire.insert_object(sheet, equipments::MedicKit)); + for (const auto &[obj_type, _]: sheet.get_objects()) { + dummy_object.objects.emplace(obj_type, test::get_obj(obj_type)); + } } json serializer; @@ -78,7 +88,7 @@ TEST_CASE("[D] Deserialize empty BillyObjects", "[deserialize][0]") { } TEST_CASE("[D] Deserialize full BillyObjects", "[deserialize][1]") { - BillyObjects gestionnaire{}; +// BillyObjects gestionnaire{}; test::DummyObject dummy_object; const auto deserializer = []() -> json { @@ -90,21 +100,18 @@ TEST_CASE("[D] Deserialize full BillyObjects", "[deserialize][1]") { REQUIRE_FALSE(dummy_object.objects.empty()); - REQUIRE_FALSE(std::holds_alternative(dummy_object.objects[0])); - REQUIRE(std::holds_alternative(dummy_object.objects[0])); - REQUIRE(std::get(dummy_object.objects[0]) == weapons::Sword); + REQUIRE_NOTHROW(dummy_object.objects.at(weapons::Sword)); + REQUIRE(std::get(dummy_object.objects.at(weapons::Sword)->get_type()) == weapons::Sword); - REQUIRE_FALSE(std::holds_alternative(dummy_object.objects[1])); - REQUIRE(std::holds_alternative(dummy_object.objects[1])); - REQUIRE(std::get(dummy_object.objects[1]) == tools::Fourche); + REQUIRE_NOTHROW(dummy_object.objects.at(tools::Fourche)); + REQUIRE(std::get(dummy_object.objects.at(tools::Fourche)->get_type()) == tools::Fourche); - REQUIRE_FALSE(std::holds_alternative(dummy_object.objects[2])); - REQUIRE(std::holds_alternative(dummy_object.objects[2])); - REQUIRE(std::get(dummy_object.objects[2]) == equipments::MedicKit); + REQUIRE_NOTHROW(dummy_object.objects.at(equipments::MedicKit)); + REQUIRE(std::get(dummy_object.objects.at(equipments::MedicKit)->get_type()) == equipments::MedicKit); } TEST_CASE("[D] Pushing popping BillyObjects", "[pushpop][0]") { - constexpr std::array all_objects{ + constexpr std::array all_objects{ weapons::Sword, weapons::Lance, weapons::Morgenstern, @@ -123,22 +130,22 @@ TEST_CASE("[D] Pushing popping BillyObjects", "[pushpop][0]") { CharacterSheet sheet; REQUIRE(sheet.get_objects().empty()); - REQUIRE_NOTHROW(gestionnaire.push_object(weapons::Sword, sheet)); + REQUIRE(gestionnaire.insert_object(sheet, weapons::Sword)); REQUIRE_FALSE(sheet.get_objects().empty()); - REQUIRE(std::holds_alternative(sheet.get_objects().back())); - REQUIRE(std::get(sheet.get_objects().back()) == weapons::Sword); + REQUIRE_NOTHROW(sheet.get_objects().at(weapons::Sword)); + REQUIRE(std::get(sheet.get_objects().at(weapons::Sword)->get_type()) == weapons::Sword); - REQUIRE_NOTHROW(gestionnaire.pop_object(sheet)); + REQUIRE_NOTHROW(gestionnaire.erase_object(sheet, weapons::Sword)); REQUIRE(sheet.get_objects().empty()); for (std::size_t j = 0; j < all_objects.size(); j += 3) { for (std::size_t i = 0; i < 3; ++i) { - REQUIRE_NOTHROW(gestionnaire.push_object(all_objects[i + j], sheet)); + REQUIRE_NOTHROW(gestionnaire.insert_object(sheet, all_objects[i + j])); } REQUIRE_FALSE(sheet.get_objects().empty()); for (std::size_t i = 0; i < 3; ++i) { - REQUIRE_NOTHROW(gestionnaire.pop_object(sheet)); + REQUIRE_NOTHROW(gestionnaire.erase_object(sheet, all_objects[i + j])); } REQUIRE(sheet.get_objects().empty()); } @@ -146,7 +153,8 @@ TEST_CASE("[D] Pushing popping BillyObjects", "[pushpop][0]") { TEST_CASE("[D] Printing Billy's objects", "[printing]") { for (const auto &object: BillyObjects::all_objects) { - REQUIRE_NOTHROW(BillyObjects::billy_object_to_string(object)); + const std::unique_ptr obj = test::get_obj(object); + REQUIRE_NOTHROW(BillyObjects::billy_object_to_string(obj)); } }