From b113b902576e2824d9e43828f5cb737eb1756957 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 4 Nov 2024 22:30:48 -0500 Subject: [PATCH] Cleaned up the tests for tser more and then removed cereal. --- meson.build | 3 +-- tests/config.cpp | 54 +++++++----------------------------------------- tser.hpp | 4 ---- 3 files changed, 8 insertions(+), 53 deletions(-) diff --git a/meson.build b/meson.build index 8722b84..e271b94 100644 --- a/meson.build +++ b/meson.build @@ -8,11 +8,10 @@ ftxui_screen = dependency('ftxui-screen') ftxui_dom = dependency('ftxui-dom') ftxui_component = dependency('ftxui-component') sfml = dependency('sfml') -cereal = dependency('cereal') dependencies = [catch2, fmt, ftxui_screen, ftxui_dom, ftxui_component, - json, sfml, cereal] + json, sfml] runtests = executable('runtests', [ 'dbc.cpp', diff --git a/tests/config.cpp b/tests/config.cpp index 7d97c29..5029a26 100644 --- a/tests/config.cpp +++ b/tests/config.cpp @@ -62,50 +62,6 @@ TEST_CASE("can go into a world", "[config]") { REQUIRE(cfg["types"]["NUMBER"] == 1234); } -#include -#include -#include -#include -#include -#include - -struct MyData -{ - int x, y, z; - std::string tiles; - - template - void serialize(Archive &ar) { - ar(x, y, z, tiles); - } -}; - - -TEST_CASE("test using serialization", "[config]") { - { - std::ofstream os("cereal.json", std::ios::binary); - cereal::JSONOutputArchive oarchive(os); - - MyData m1{1,2,3, "\u2849█Ω♣"}; - MyData m2{5,6,7, "\u2849█Ω♣"}; - MyData m3{8,9,10, "\u2849█Ω♣"}; - - oarchive(m1, m2, m3); - } - - { - std::ifstream is("cereal.json", std::ios::binary); - cereal::JSONInputArchive iarchive(is); - - MyData m1, m2, m3; - - iarchive(m1, m2, m3); - - REQUIRE(m1.tiles == "\u2849█Ω♣"); - REQUIRE(m2.tiles == "\u2849█Ω♣"); - REQUIRE(m3.tiles == "\u2849█Ω♣"); - } -} #include #include @@ -134,12 +90,16 @@ struct Robot { TEST_CASE("test using tser for serialization", "[config]") { auto robot = Robot{ Pixel{3,4}, Item::RADAR}; std::cout << robot << '\n'; - std::cout << Robot() << '\n'; tser::BinaryArchive archive; archive.save(robot); std::string_view archive_view = archive.get_buffer(); - auto loadedRobot = tser::load(archive_view); - REQUIRE(loadedRobot == robot); + tser::BinaryArchive archive2(0); + archive2.initialize(archive_view); + auto loadedRobot = archive2.load(); + + REQUIRE(loadedRobot.point.x == robot.point.x); + REQUIRE(loadedRobot.point.y == robot.point.y); + REQUIRE(loadedRobot.item == robot.item); } diff --git a/tser.hpp b/tser.hpp index bd555c0..d603dc6 100644 --- a/tser.hpp +++ b/tser.hpp @@ -258,9 +258,5 @@ static constexpr std::array _me for(size_t _i = 0, nArgs = 0; nArgs < tser::detail::n_args(#__VA_ARGS__) ; ++_i) { \ while(Type::_memberNameData[_i] == '\0') _i++; out[nArgs++] = &Type::_memberNameData[_i]; \ while(Type::_memberNameData[++_i] != '\0'); } return out;}();\ -template && !tser::is_detected_v, int> = 0>\ -friend bool operator==(const Type& lhs, const OT& rhs) { return lhs.members() == rhs.members(); }\ -template && !tser::is_detected_v, int> = 0>\ -friend bool operator!=(const Type& lhs, const OT& rhs) { return !(lhs == rhs); }\ template && !tser::is_detected_v, int> = 0>\ friend std::ostream& operator<<(std::ostream& os, const OT& t) { tser::print(os, t); return os; }