tests/idl: add test for stdx::optional<> serialization
Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com> Message-Id: <1456761055-23916-1-git-send-email-pdziepak@scylladb.com>
This commit is contained in:
committed by
Pekka Enberg
parent
dec63eac6e
commit
e194835d8a
@@ -64,4 +64,9 @@ struct writable_variants stub [[writable]] {
|
||||
boost::variant<writable_vector, simple_compound, writable_final_simple_compound> first;
|
||||
boost::variant<writable_vector, simple_compound, writable_final_simple_compound> second;
|
||||
boost::variant<writable_vector, simple_compound, writable_final_simple_compound> third;
|
||||
};
|
||||
};
|
||||
|
||||
struct compound_with_optional {
|
||||
std::experimental::optional<simple_compound> first;
|
||||
simple_compound second;
|
||||
};
|
||||
|
||||
@@ -28,11 +28,14 @@
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <experimental/optional>
|
||||
|
||||
#include "bytes.hh"
|
||||
#include "bytes_ostream.hh"
|
||||
#include "serializer.hh"
|
||||
|
||||
namespace stdx = std::experimental;
|
||||
|
||||
struct simple_compound {
|
||||
// TODO: change this to test for #905
|
||||
uint32_t foo;
|
||||
@@ -48,6 +51,27 @@ std::ostream& operator<<(std::ostream& os, const simple_compound& sc)
|
||||
return os << " { foo: " << sc.foo << ", bar: " << sc.bar << " }";
|
||||
}
|
||||
|
||||
struct compound_with_optional {
|
||||
stdx::optional<simple_compound> first;
|
||||
simple_compound second;
|
||||
|
||||
bool operator==(const compound_with_optional& other) const {
|
||||
return first == other.first && second == other.second;
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const compound_with_optional& v)
|
||||
{
|
||||
os << " { first: ";
|
||||
if (v.first) {
|
||||
os << *v.first;
|
||||
} else {
|
||||
os << "<disengaged>";
|
||||
}
|
||||
os << ", second: " << v.second << " }";
|
||||
return os;
|
||||
}
|
||||
|
||||
struct wrapped_vector {
|
||||
std::vector<simple_compound> vector;
|
||||
|
||||
@@ -238,4 +262,32 @@ BOOST_AUTO_TEST_CASE(test_variant)
|
||||
auto v3 = wv_view.third();
|
||||
auto&& compound2 = boost::apply_visitor(expect_writable_compound(), v3);
|
||||
BOOST_REQUIRE_EQUAL(compound2, sc2);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_compound_with_optional)
|
||||
{
|
||||
simple_compound foo = { 0xdeadbeef, 0xbadc0ffe };
|
||||
simple_compound bar = { 0x12345678, 0x87654321 };
|
||||
|
||||
compound_with_optional one = { foo, bar };
|
||||
|
||||
bytes_ostream buf1;
|
||||
ser::serialize(buf1, one);
|
||||
BOOST_REQUIRE_EQUAL(buf1.size(), 29);
|
||||
|
||||
auto bv1 = buf1.linearize();
|
||||
seastar::simple_input_stream in1(reinterpret_cast<const char*>(bv1.data()), bv1.size());
|
||||
auto deser_one = ser::deserialize(in1, boost::type<compound_with_optional>());
|
||||
BOOST_REQUIRE_EQUAL(one, deser_one);
|
||||
|
||||
compound_with_optional two = { {}, foo };
|
||||
|
||||
bytes_ostream buf2;
|
||||
ser::serialize(buf2, two);
|
||||
BOOST_REQUIRE_EQUAL(buf2.size(), 17);
|
||||
|
||||
auto bv2 = buf2.linearize();
|
||||
seastar::simple_input_stream in2(reinterpret_cast<const char*>(bv2.data()), bv2.size());
|
||||
auto deser_two = ser::deserialize(in2, boost::type<compound_with_optional>());
|
||||
BOOST_REQUIRE_EQUAL(two, deser_two);
|
||||
}
|
||||
Reference in New Issue
Block a user