BillySheet/Unit testing/sheet_tests.cpp
2024-11-25 16:46:51 +01:00

32 lines
924 B
C++

#include <catch2/catch_all.hpp>
#include <fstream>
#include <character_sheet.hpp>
using namespace character;
TEST_CASE("[E] Serialize sheet", "[serialize][0]") {
CharacterSheet sheet;
BillyObjects gestion{};
REQUIRE(gestion.insert_object(sheet, weapons::Sword));
REQUIRE(gestion.insert_object(sheet, weapons::Lance));
REQUIRE(gestion.insert_object(sheet, tools::Dagger));
BillyObjects::check_dagger_conditions(sheet);
BillyObjects::json serializer;
REQUIRE_NOTHROW(serializer["character_sheet"] = sheet); {
std::ofstream file{ "character_sheet.json" };
file << serializer << std::flush;
}
}
TEST_CASE("[F] Deserialize sheet", "[deserialize][0]") {
const auto deserializer = []() {
std::ifstream file{ "character_sheet.json" };
return json::parse(file);
}();
const auto sheet = deserializer.at("character_sheet").get<CharacterSheet>();
}