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;
114int main(
int argc,
char* argv[])
116 bool verbose =
false;
117 for (
int i = 1; i < argc; ++i)
119 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
123 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
127 test_acoustic_too_large();
129 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.