31#include "../../codec.h"
42 codec.load<TestMaxBytes>();
45 msg.set_channel(TestMaxBytes::WIFI);
47 for (
int i = 0; i < 5; ++i)
48 msg.add_data(i * 1000);
50 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"test_wifi_ok: encoding..." << std::endl;
52 codec.encode(&bytes, msg);
53 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
" encoded size: " << bytes.size() <<
" bytes" << std::endl;
54 assert(bytes.size() <= 200);
57 codec.decode(bytes, &msg_out);
59 assert(msg.SerializeAsString() == msg_out.SerializeAsString());
60 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"test_wifi_ok: passed" << std::endl;
65void test_acoustic_ok()
67 codec.load<TestMaxBytes>();
70 msg.set_channel(TestMaxBytes::ACOUSTIC);
73 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"test_acoustic_ok: encoding..." << std::endl;
75 codec.encode(&bytes, msg);
76 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
" encoded size: " << bytes.size() <<
" bytes" << std::endl;
77 assert(bytes.size() <= 10);
80 codec.decode(bytes, &msg_out);
82 assert(msg.SerializeAsString() == msg_out.SerializeAsString());
83 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"test_acoustic_ok: passed" << std::endl;
88void test_acoustic_too_large()
90 codec.load<TestMaxBytes>();
93 msg.set_channel(TestMaxBytes::ACOUSTIC);
95 for (
int i = 0; i < 15; ++i)
96 msg.add_data(i * 1000);
98 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"test_acoustic_too_large: encoding (should throw)..." << std::endl;
103 codec.encode(&bytes, msg);
108 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
" caught expected exception: " << e.what() << std::endl;
110 assert(threw &&
"Expected exception when encoding message exceeding dynamic max_bytes");
111 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"test_acoustic_too_large: passed" << std::endl;
116void test_channel_omit()
118 codec.load<ChannelMessage>();
124 msg.set_heading(180);
127 msg.set_status(
"all systems nominal");
130 ChannelMessage msg_out;
132 msg.set_channel(ChannelMessage::WIFI);
134 codec.encode(&bytes, msg);
135 assert(bytes.size() == 30);
136 codec.decode(bytes, &msg_out);
137 assert(msg.SerializeAsString() == msg_out.SerializeAsString());
139 msg.set_channel(ChannelMessage::ACOUSTIC);
141 codec.encode(&bytes, msg);
142 assert(bytes.size() == 8);
144 codec.decode(bytes, &msg_out);
145 assert(!msg_out.has_pitch() && !msg_out.has_roll() && !msg_out.has_status());
146 assert(msg_out.x() == msg.x() && msg_out.y() == msg.y() && msg_out.z() == msg.z());
147 assert(msg_out.heading() == msg.heading());
149 msg.set_channel(ChannelMessage::IRIDIUM);
151 codec.encode(&bytes, msg);
152 assert(bytes.size() == 10);
154 codec.decode(bytes, &msg_out);
155 assert(msg_out.has_pitch() && msg_out.has_roll() && !msg_out.has_status());
156 assert(msg_out.pitch() == msg.pitch() && msg_out.roll() == msg.roll());
158 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"test_channel_omit: passed" << std::endl;
161int main(
int argc,
char* argv[])
163 bool verbose =
false;
164 for (
int i = 1; i < argc; ++i)
166 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
170 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
174 test_acoustic_too_large();
177 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"all tests passed" << std::endl;
The Dynamic CCL enCODer/DECoder. This is the main class you will use to load, encode and decode DCCL ...
Exception class for DCCL.
bool is(logger::Verbosity verbosity, logger::Group group=logger::GENERAL)
Indicates the verbosity of the Logger until the next std::flush or std::endl. The boolean return is u...
void connect(int verbosity_mask, Slot slot)
Connect the output of one or more given verbosities to a slot (function pointer or similar)
Dynamic Compact Control Language namespace.