Cleaner YAML validation

This commit is contained in:
Pavel Kirienko
2015-07-11 11:52:39 +03:00
parent e6aeb036e8
commit 96c496600b
@@ -19,59 +19,74 @@
#include <uavcan/protocol/debug/KeyValue.hpp>
#include <root_ns_a/Deep.hpp>
#include <root_ns_a/UnionTest.hpp>
template <typename T>
static bool validateYaml(const T& obj, const std::string& reference)
{
std::ostringstream os;
os << obj;
if (os.str() == reference)
{
return true;
}
else
{
std::cout << "INVALID YAML:\n"
<< "EXPECTED:\n"
<< "===\n"
<< reference
<< "\n===\n"
<< "ACTUAL:\n"
<< "\n===\n"
<< os.str()
<< "===" << std::endl;
return false;
}
}
TEST(Dsdl, Streaming)
{
std::ostringstream os;
uavcan::protocol::GetNodeInfo::Response get_node_info_rsp;
os << get_node_info_rsp << std::endl << "==========" << std::endl;
EXPECT_TRUE(validateYaml(uavcan::protocol::GetNodeInfo::Response(),
"status: \n"
" uptime_sec: 0\n"
" health: 0\n"
" mode: 0\n"
" sub_mode: 0\n"
" vendor_specific_status_code: 0\n"
"software_version: \n"
" major: 0\n"
" minor: 0\n"
" optional_field_flags: 0\n"
" vcs_commit: 0\n"
" image_crc: 0\n"
"hardware_version: \n"
" major: 0\n"
" minor: 0\n"
" unique_id: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
" certificate_of_authenticity: \"\"\n"
"name: \"\""));
root_ns_a::Deep ps;
ps.a.resize(1);
os << ps << std::endl << "==========" << std::endl;
static const std::string Reference =
"status: \n"
" uptime_sec: 0\n"
" health: 0\n"
" mode: 0\n"
" sub_mode: 0\n"
" vendor_specific_status_code: 0\n"
"software_version: \n"
" major: 0\n"
" minor: 0\n"
" optional_field_flags: 0\n"
" vcs_commit: 0\n"
" image_crc: 0\n"
"hardware_version: \n"
" major: 0\n"
" minor: 0\n"
" unique_id: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
" certificate_of_authenticity: \"\"\n"
"name: \"\"\n"
"==========\n"
"c: 0\n"
"str: \"\"\n"
"a: \n"
" - \n"
" scalar: 0\n"
" vector: \n"
" - \n"
" vector: [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]\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]\n"
" bools: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
" - \n"
" vector: [0, 0]\n"
" bools: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
"==========\n";
std::cout << os.str();
ASSERT_EQ(Reference, os.str());
EXPECT_TRUE(validateYaml(ps,
"c: 0\n"
"str: \"\"\n"
"a: \n"
" - \n"
" scalar: 0\n"
" vector: \n"
" - \n"
" vector: [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]\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]\n"
" bools: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
" - \n"
" vector: [0, 0]\n"
" bools: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
}