diff --git a/libuavcan/test/dsdl_test/dsdl_test.cpp b/libuavcan/test/dsdl_test/dsdl_test.cpp index f808b45ec0..0b8aa1a5b0 100644 --- a/libuavcan/test/dsdl_test/dsdl_test.cpp +++ b/libuavcan/test/dsdl_test/dsdl_test.cpp @@ -7,11 +7,48 @@ #include #include #include +#include +#include -TEST(Dsdl, Basic) +TEST(Dsdl, EmptyServices) { uavcan::StaticTransferBuffer<100> buf; uavcan::BitStream bs_wr(buf); uavcan::ScalarCodec sc_wr(bs_wr); + + root_ns_b::ServiceWithEmptyRequest::Request req; + ASSERT_EQ(1, root_ns_b::ServiceWithEmptyRequest::Request::encode(req, sc_wr)); + ASSERT_EQ("", bs_wr.toString()); + + root_ns_b::ServiceWithEmptyRequest::Response resp; + ASSERT_EQ(1, root_ns_b::ServiceWithEmptyRequest::Response::encode(resp, sc_wr)); + ASSERT_EQ("", bs_wr.toString()); + + resp.covariance.push_back(-2); + resp.covariance.push_back(65504); + root_ns_b::ServiceWithEmptyRequest::Response::encode(resp, sc_wr); + ASSERT_EQ("00000000 11000000 11111111 01111011", bs_wr.toString()); + + resp.covariance.push_back(42); + resp.covariance[0] = 999; + + uavcan::BitStream bs_rd(buf); + uavcan::ScalarCodec sc_rd(bs_rd); + ASSERT_EQ(1, root_ns_b::ServiceWithEmptyRequest::Response::decode(resp, sc_rd)); + + ASSERT_EQ(2, resp.covariance.size()); + ASSERT_EQ(-2, resp.covariance[0]); + ASSERT_EQ(65504, resp.covariance[1]); +} + +TEST(Dsdl, Signature) +{ + ASSERT_EQ(0xe74617107a34aa9c, root_ns_a::EmptyService::getDataTypeSignature().get()); + ASSERT_EQ("root_ns_a.EmptyService", root_ns_a::EmptyService::getDataTypeFullName()); + ASSERT_EQ(uavcan::DataTypeKindService, root_ns_a::EmptyService::DataTypeKind); + + ASSERT_EQ(0x41a2582ee72be419, root_ns_a::NestedMessage::getDataTypeSignature().get()); // Computed manually + ASSERT_EQ("root_ns_a.NestedMessage", root_ns_a::NestedMessage::getDataTypeFullName()); + ASSERT_EQ(uavcan::DataTypeKindMessage, root_ns_a::NestedMessage::DataTypeKind); } diff --git a/libuavcan/test/dsdl_test/root_ns_b/ServiceWithEmptyRequest.uavcan b/libuavcan/test/dsdl_test/root_ns_b/ServiceWithEmptyRequest.uavcan new file mode 100644 index 0000000000..731fe88f85 --- /dev/null +++ b/libuavcan/test/dsdl_test/root_ns_b/ServiceWithEmptyRequest.uavcan @@ -0,0 +1,2 @@ +--- +float16[<=9] covariance diff --git a/libuavcan/test/dsdl_test/root_ns_b/ServiceWithEmptyResponse.uavcan b/libuavcan/test/dsdl_test/root_ns_b/ServiceWithEmptyResponse.uavcan new file mode 100644 index 0000000000..875562aa2b --- /dev/null +++ b/libuavcan/test/dsdl_test/root_ns_b/ServiceWithEmptyResponse.uavcan @@ -0,0 +1,2 @@ +float16[<=9] covariance +---