Unit test for the previous commit

This commit is contained in:
Pavel Kirienko
2018-05-19 17:52:07 +03:00
parent 94c0374165
commit 53e33d01f7
2 changed files with 39 additions and 0 deletions
@@ -22,6 +22,7 @@
#include <root_ns_a/Deep.hpp>
#include <root_ns_a/UnionTest.hpp>
#include <root_ns_a/UnionTest4.hpp>
template <typename T>
static bool validateYaml(const T& obj, const std::string& reference)
@@ -200,6 +201,38 @@ TEST(Dsdl, Union)
}
TEST(Dsdl, UnionTagWidth)
{
using root_ns_a::UnionTest4;
ASSERT_EQ(2, UnionTest4::MinBitLen);
ASSERT_EQ(8, UnionTest4::MaxBitLen);
UnionTest4 s;
{
uavcan::StaticTransferBuffer<100> buf;
uavcan::BitStream bs_wr(buf);
uavcan::ScalarCodec sc_wr(bs_wr);
ASSERT_EQ(1, UnionTest4::encode(s, sc_wr));
ASSERT_EQ("00000000", bs_wr.toString());
}
{
uavcan::StaticTransferBuffer<100> buf;
uavcan::BitStream bs_wr(buf);
uavcan::ScalarCodec sc_wr(bs_wr);
s.to<UnionTest4::Tag::third>() = 1U << 5U; // 32, 0b100000
ASSERT_EQ(1, UnionTest4::encode(s, sc_wr));
ASSERT_EQ("10100000", bs_wr.toString());
}
}
TEST(Dsdl, ParamGetSetRequestUnion)
{
uavcan::protocol::param::GetSet::Request req;
@@ -0,0 +1,6 @@
# A union of four items; tag 2 bits wide, total length 1 byte
@union # 2 bits
Empty first # Tag value 0
uint5 second # Tag value 1
uint6 third # Tag value 2
int2 fourth # Tag value 3