Cleaned up the tests for tser more and then removed cereal.

main
Zed A. Shaw 2 weeks ago
parent bf57713416
commit b113b90257
  1. 3
      meson.build
  2. 54
      tests/config.cpp
  3. 4
      tser.hpp

@ -8,11 +8,10 @@ ftxui_screen = dependency('ftxui-screen')
ftxui_dom = dependency('ftxui-dom') ftxui_dom = dependency('ftxui-dom')
ftxui_component = dependency('ftxui-component') ftxui_component = dependency('ftxui-component')
sfml = dependency('sfml') sfml = dependency('sfml')
cereal = dependency('cereal')
dependencies = [catch2, fmt, dependencies = [catch2, fmt,
ftxui_screen, ftxui_dom, ftxui_component, ftxui_screen, ftxui_dom, ftxui_component,
json, sfml, cereal] json, sfml]
runtests = executable('runtests', [ runtests = executable('runtests', [
'dbc.cpp', 'dbc.cpp',

@ -62,50 +62,6 @@ TEST_CASE("can go into a world", "[config]") {
REQUIRE(cfg["types"]["NUMBER"] == 1234); REQUIRE(cfg["types"]["NUMBER"] == 1234);
} }
#include <cereal/types/unordered_map.hpp>
#include <cereal/types/memory.hpp>
#include <cereal/archives/json.hpp>
#include <cereal/archives/binary.hpp>
#include <cereal/archives/portable_binary.hpp>
#include <fstream>
struct MyData
{
int x, y, z;
std::string tiles;
template<class Archive>
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 <optional> #include <optional>
#include <iostream> #include <iostream>
@ -134,12 +90,16 @@ struct Robot {
TEST_CASE("test using tser for serialization", "[config]") { TEST_CASE("test using tser for serialization", "[config]") {
auto robot = Robot{ Pixel{3,4}, Item::RADAR}; auto robot = Robot{ Pixel{3,4}, Item::RADAR};
std::cout << robot << '\n'; std::cout << robot << '\n';
std::cout << Robot() << '\n';
tser::BinaryArchive archive; tser::BinaryArchive archive;
archive.save(robot); archive.save(robot);
std::string_view archive_view = archive.get_buffer(); std::string_view archive_view = archive.get_buffer();
auto loadedRobot = tser::load<Robot>(archive_view); tser::BinaryArchive archive2(0);
REQUIRE(loadedRobot == robot); archive2.initialize(archive_view);
auto loadedRobot = archive2.load<Robot>();
REQUIRE(loadedRobot.point.x == robot.point.x);
REQUIRE(loadedRobot.point.y == robot.point.y);
REQUIRE(loadedRobot.item == robot.item);
} }

@ -258,9 +258,5 @@ static constexpr std::array<const char*, tser::detail::n_args(#__VA_ARGS__)> _me
for(size_t _i = 0, nArgs = 0; nArgs < tser::detail::n_args(#__VA_ARGS__) ; ++_i) { \ 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') _i++; out[nArgs++] = &Type::_memberNameData[_i]; \
while(Type::_memberNameData[++_i] != '\0'); } return out;}();\ while(Type::_memberNameData[++_i] != '\0'); } return out;}();\
template<typename OT, std::enable_if_t<std::is_same_v<OT,Type> && !tser::is_detected_v<tser::has_equal_t, OT>, int> = 0>\
friend bool operator==(const Type& lhs, const OT& rhs) { return lhs.members() == rhs.members(); }\
template<typename OT, std::enable_if_t<std::is_same_v<OT,Type> && !tser::is_detected_v<tser::has_nequal_t, OT>, int> = 0>\
friend bool operator!=(const Type& lhs, const OT& rhs) { return !(lhs == rhs); }\
template<typename OT, std::enable_if_t<std::is_same_v<OT,Type> && !tser::is_detected_v<tser::has_outstream_op_t, OT>, int> = 0>\ template<typename OT, std::enable_if_t<std::is_same_v<OT,Type> && !tser::is_detected_v<tser::has_outstream_op_t, OT>, int> = 0>\
friend std::ostream& operator<<(std::ostream& os, const OT& t) { tser::print(os, t); return os; } friend std::ostream& operator<<(std::ostream& os, const OT& t) { tser::print(os, t); return os; }

Loading…
Cancel
Save