|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|