YAML streaming for generated types

This commit is contained in:
Pavel Kirienko
2014-03-07 00:43:36 +04:00
parent da6e25a708
commit 4753d4ac79
10 changed files with 386 additions and 5 deletions
@@ -3,6 +3,7 @@
*/
#include <gtest/gtest.h>
#include <uavcan/Timestamp.hpp>
#include <uavcan/FigureOfMerit.hpp>
#include <uavcan/mavlink/Message.hpp>
@@ -29,3 +30,92 @@
#include <uavcan/protocol/file/BeginTransfer.hpp>
#include <uavcan/protocol/file/Crc.hpp>
#include <uavcan/protocol/file/GetInfo.hpp>
#include <root_ns_a/Deep.hpp>
TEST(Dsdl, Streaming)
{
std::ostringstream os;
uavcan::mavlink::Message mavlink;
os << mavlink << std::endl << "==========" << std::endl;
mavlink.compid = 12;
mavlink.seq = 42;
mavlink.payload = "Here goes payload";
os << mavlink << std::endl << "==========" << std::endl;
uavcan::protocol::GetNodeInfo::Response get_node_info_rsp;
os << get_node_info_rsp << std::endl << "==========" << std::endl;
root_ns_a::Deep ps;
ps.a.resize(2);
os << ps << std::endl << "==========" << std::endl;
static const std::string Reference = "seq: 0\n"
"sysid: 0\n"
"compid: 0\n"
"msgid: 0\n"
"payload: \"\"\n"
"==========\n"
"seq: 42\n"
"sysid: 0\n"
"compid: 12\n"
"msgid: 0\n"
"payload: \"Here goes payload\"\n"
"==========\n"
"software_version: \n"
" major: 0\n"
" minor: 0\n"
"hardware_version: \n"
" major: 0\n"
" minor: 0\n"
"uavcan_version: \n"
" major: 0\n"
" minor: 0\n"
"status: \n"
" uptime_sec: 0\n"
" status_code: 0\n"
"name: \"\"\n"
"==========\n"
"c: 0\n"
"str: \"\"\n"
"a: \n"
" - \n"
" scalar: 0\n"
" vector: \n"
" - \n"
" vector: [0, 0, 0, 0]\n"
" bools: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
" - \n"
" vector: [0, 0, 0, 0]\n"
" bools: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
" - \n"
" vector: [0, 0, 0, 0]\n"
" bools: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
" - \n"
" scalar: 0\n"
" vector: \n"
" - \n"
" vector: [0, 0, 0, 0]\n"
" bools: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
" - \n"
" vector: [0, 0, 0, 0]\n"
" bools: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
" - \n"
" vector: [0, 0, 0, 0]\n"
" bools: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
"b: \n"
" - \n"
" vector: [0, 0, 0, 0]\n"
" bools: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
" - \n"
" vector: [0, 0, 0, 0]\n"
" bools: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
" - \n"
" vector: [0, 0, 0, 0]\n"
" bools: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
"==========\n";
ASSERT_EQ(Reference, os.str());
}
@@ -0,0 +1,8 @@
#
# Nested type.
# Energy and capacity are expressed in watt hours (Joules are infeasible because of range limitations).
# Unknown values should be represented as NAN.
#
float32 scalar
B[3] vector
@@ -0,0 +1,2 @@
float64[4] vector
bool[16] bools
@@ -0,0 +1,8 @@
#
# Info for all battery packs of the primary power supply.
#
bool c
uint8[<64] str
A[<3] a
B[3] b
+56
View File
@@ -710,3 +710,59 @@ TEST(Array, Strings)
ASSERT_STREQ("Our sun is dying. 123456-789", a8.c_str());
ASSERT_STREQ("456", a7.c_str());
}
TEST(Array, FlatStreaming)
{
typedef Array<IntegerSpec<8, SignednessUnsigned, CastModeSaturate>, ArrayModeDynamic, 32> A8D;
typedef Array<FloatSpec<16, CastModeSaturate>, ArrayModeDynamic, 16> AF16D;
typedef Array<FloatSpec<16, CastModeSaturate>, ArrayModeStatic, 3> AF16S;
A8D a1;
a1 = "12\n3\x44\xa5\xde\xad\x79";
uavcan::YamlStreamer<A8D>::stream(std::cout, a1, 0);
std::cout << std::endl;
A8D a2;
a2 = "Hello";
uavcan::YamlStreamer<A8D>::stream(std::cout, a2, 0);
std::cout << std::endl;
AF16D af16d1;
af16d1.push_back(1.23);
af16d1.push_back(4.56);
uavcan::YamlStreamer<AF16D>::stream(std::cout, af16d1, 0);
std::cout << std::endl;
AF16D af16d2;
uavcan::YamlStreamer<AF16D>::stream(std::cout, af16d2, 0);
std::cout << std::endl;
AF16S af16s;
uavcan::YamlStreamer<AF16S>::stream(std::cout, af16s, 0);
std::cout << std::endl;
}
TEST(Array, MultidimensionalStreaming)
{
typedef Array<FloatSpec<16, CastModeSaturate>, ArrayModeDynamic, 16> Float16Array;
typedef Array<Float16Array, ArrayModeDynamic, 8> TwoDimensional;
typedef Array<TwoDimensional, ArrayModeDynamic, 4> ThreeDimensional;
ThreeDimensional threedee;
threedee.resize(3);
for (int x = 0; x < threedee.size(); x++)
{
threedee[x].resize(3);
for (int y = 0; y < threedee[x].size(); y++)
{
threedee[x][y].resize(3);
for (int z = 0; z < threedee[x][y].size(); z++)
threedee[x][y][z] = 1.0 / (x + y + z + 1.0);
}
}
uavcan::YamlStreamer<ThreeDimensional>::stream(std::cout, threedee, 0);
std::cout << std::endl;
}