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

This commit is contained in:
Zed A. Shaw 2024-11-04 22:30:48 -05:00
parent bf57713416
commit b113b90257
3 changed files with 8 additions and 53 deletions

View file

@ -62,50 +62,6 @@ TEST_CASE("can go into a world", "[config]") {
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 <iostream>
@ -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<Robot>(archive_view);
REQUIRE(loadedRobot == robot);
tser::BinaryArchive archive2(0);
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);
}