2017-12-22 21:36:25 +08:00
|
|
|
#include <experimental/optional>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
#include "boost/archive/binary_iarchive.hpp"
|
|
|
|
#include "boost/archive/binary_oarchive.hpp"
|
2018-01-10 19:57:44 +08:00
|
|
|
#include "utils/serialization.hpp"
|
2017-12-22 21:36:25 +08:00
|
|
|
|
|
|
|
using std::experimental::optional;
|
|
|
|
|
|
|
|
TEST(SerializationOptionalTest, SerializeAndDeserialize) {
|
|
|
|
std::stringstream ss;
|
|
|
|
|
|
|
|
optional<int> x1 = {};
|
|
|
|
optional<int> x2 = 42;
|
|
|
|
optional<int> y1, y2;
|
|
|
|
|
|
|
|
{
|
|
|
|
boost::archive::binary_oarchive ar(ss);
|
|
|
|
ar << x1;
|
|
|
|
ar << x2;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
boost::archive::binary_iarchive ar(ss);
|
|
|
|
ar >> y1;
|
|
|
|
ar >> y2;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_EQ(x1, y1);
|
|
|
|
EXPECT_EQ(x2, y2);
|
|
|
|
}
|