idl: add unit-test for const specifiers feature

Signed-off-by: Pavel Solodovnikov <pa.solodovnikov@scylladb.com>
This commit is contained in:
Pavel Solodovnikov
2020-12-09 17:51:34 +03:00
parent facf27dbe4
commit 1e6df841a5
2 changed files with 48 additions and 0 deletions

View File

@@ -86,3 +86,12 @@ struct empty_final_struct final { };
struct just_a_variant stub [[writable]] {
std::variant<writable_simple_compound, simple_compound> variant;
};
template <typename T>
struct const_template_arg_wrapper {
T x;
}
struct const_template_arg_test_object {
std::vector<const_template_arg_wrapper<const simple_compound>> first;
};

View File

@@ -145,6 +145,27 @@ public:
}
};
template <typename T>
struct const_template_arg_wrapper {
T x;
const_template_arg_wrapper(const T& t)
: x(t)
{}
bool operator == (const const_template_arg_wrapper& rhs) const {
return x == rhs.x;
}
};
struct const_template_arg_test_object {
std::vector<const_template_arg_wrapper<const simple_compound>> first;
bool operator == (const const_template_arg_test_object& rhs) const {
return first == rhs.first;
}
};
#include "serialization_visitors.hh"
#include "idl/idl_test.dist.hh"
#include "serializer_impl.hh"
@@ -445,3 +466,21 @@ BOOST_AUTO_TEST_CASE(test_fragmented_write)
BOOST_CHECK_EQUAL(deserialized, fragment_generator(fragment_count, fragment_size).to_bytes());
}
}
BOOST_AUTO_TEST_CASE(test_const_template_arg)
{
const_template_arg_test_object obj {
.first = {
simple_compound{ 0xdeadbeef, 0xbadc0ffe },
simple_compound{ 0xbaaaaaad, 0xdeadc0de }
}
};
bytes_ostream buf;
ser::serialize(buf, obj);
BOOST_REQUIRE_EQUAL(buf.size(), 40);
auto in = ser::as_input_stream(buf);
auto deser_obj = ser::deserialize(in, boost::type<const_template_arg_test_object>());
BOOST_REQUIRE(obj == deser_obj);
}