From 17c0003a87cc95e36706c80492f3f85ac788ee74 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sat, 11 Jul 2015 14:03:50 +0300 Subject: [PATCH] Another test for complex data structures with unions and voids --- .../dsdl_test/dsdl_uavcan_compilability.cpp | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/libuavcan/test/dsdl_test/dsdl_uavcan_compilability.cpp b/libuavcan/test/dsdl_test/dsdl_uavcan_compilability.cpp index 153521a00c..8055e52921 100644 --- a/libuavcan/test/dsdl_test/dsdl_uavcan_compilability.cpp +++ b/libuavcan/test/dsdl_test/dsdl_uavcan_compilability.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -139,7 +140,7 @@ static bool encodeDecodeValidate(const T& obj, const std::string& reference_bit_ return false; } - if (decoded != obj) + if (!decoded.isClose(obj)) { std::cout << "DECODED OBJECT DOESN'T MATCH THE REFERENCE:\nEXPECTED:\n" << obj << "\nACTUAL:\n" @@ -197,3 +198,45 @@ TEST(Dsdl, Union) EXPECT_TRUE(validateYaml(s, "e: \n array: [0, 1, 2, 3]")); EXPECT_TRUE(encodeDecodeValidate(s, "10100000 11011000")); } + + +TEST(Dsdl, ParamGetSetRequestUnion) +{ + uavcan::protocol::param::GetSet::Request req; + + req.index = 8191; + req.name = "123"; // 49, 50, 51 // 00110001, 00110010, 00110011 + EXPECT_TRUE(encodeDecodeValidate(req, "11111111 11111000 00110001 00110010 00110011")); + + req.value.to() = "abc"; // 01100001, 01100010, 01100011 + EXPECT_TRUE(encodeDecodeValidate(req, + "11111111 11111100 " // Index, Union tag + "00000011 " // Array length + "01100001 01100010 01100011 " // Payload + "00110001 00110010 00110011")); // Name + + req.value.to() = 1; + EXPECT_TRUE(encodeDecodeValidate(req, + "11111111 11111001 " // Index, Union tag + "00000001 00000000 00000000 00000000 00000000 00000000 00000000 00000000 " // Payload + "00110001 00110010 00110011")); // Name +} + + +TEST(Dsdl, ParamGetSetResponseUnion) +{ + uavcan::protocol::param::GetSet::Response res; + + res.value.to() = "abc"; + res.default_value.to(); // Empty + res.name = "123"; + EXPECT_TRUE(encodeDecodeValidate(res, + "00000100 " // Value union tag + "00000011 " // Value array length + "01100001 01100010 01100011 " // Value array payload + "00000100 " // Default union tag + "00000000 " // Default array length + "00000000 " // Max value tag + "00000000 " // Min value tag + "00110001 00110010 00110011")); // Name +}