Add serialization for primitive boost::optional<T>.
This commit is contained in:
@@ -11,11 +11,38 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
template<typename T>
|
||||
void check_ser_rep(T thing, std::vector<unsigned char> expected)
|
||||
{
|
||||
CDataStream ss(SER_DISK, 0);
|
||||
ss << thing;
|
||||
|
||||
BOOST_CHECK(GetSerializeSize(thing, 0, 0) == ss.size());
|
||||
|
||||
std::vector<unsigned char> serialized_representation(ss.begin(), ss.end());
|
||||
|
||||
BOOST_CHECK(serialized_representation == expected);
|
||||
|
||||
T thing_deserialized;
|
||||
ss >> thing_deserialized;
|
||||
|
||||
BOOST_CHECK(thing_deserialized == thing);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(serialize_tests, BasicTestingSetup)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(boost_optional)
|
||||
{
|
||||
check_ser_rep<boost::optional<unsigned char>>(0xff, {0x01, 0xff});
|
||||
check_ser_rep<boost::optional<unsigned char>>(boost::none, {0x00});
|
||||
check_ser_rep<boost::optional<std::string>>(std::string("Test"), {0x01, 0x04, 'T', 'e', 's', 't'});
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(boost_arrays)
|
||||
{
|
||||
boost::array<std::string, 2> test_case = {string("zub"), string("baz")};
|
||||
|
||||
Reference in New Issue
Block a user