28#include "../../binary.h"
29#include "../../codec.h"
33void decode_check(
const TestMsg& msg_in);
36int main(
int argc,
char* argv[])
39 for (
int i = 1; i < argc; ++i)
41 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
45 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
47 codec.info<TestMsg>();
48 codec.load<TestMsg>();
51 codec.set_strict(
true);
58 msg_in.set_b(std::string(9,
'1'));
73 msg_in.set_b(std::string(9,
'1'));
76 bool expected_out_of_range_exception =
false;
77 assert(expected_out_of_range_exception);
81 assert(e.field() == TestMsg::descriptor()->FindFieldByName(
"d"));
82 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Caught (as expected) " << e.what() << std::endl;
92 msg_in.set_b(std::string(9,
'1'));
95 bool expected_out_of_range_exception =
false;
96 assert(expected_out_of_range_exception);
100 assert(e.field() == TestMsg::descriptor()->FindFieldByName(
"i"));
101 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Caught (as expected) " << e.what() << std::endl;
110 msg_in.set_s2(
"foobar1234546789");
111 msg_in.set_b(std::string(9,
'1'));
113 decode_check(msg_in);
114 bool expected_out_of_range_exception =
false;
115 assert(expected_out_of_range_exception);
119 assert(e.field() == TestMsg::descriptor()->FindFieldByName(
"s2"));
120 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Caught (as expected) " << e.what() << std::endl;
129 msg_in.set_s(
"foobar1234546789");
130 msg_in.set_b(std::string(9,
'1'));
132 decode_check(msg_in);
133 bool expected_out_of_range_exception =
false;
134 assert(expected_out_of_range_exception);
138 assert(e.field() == TestMsg::descriptor()->FindFieldByName(
"s"));
139 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Caught (as expected) " << e.what() << std::endl;
149 msg_in.set_b(std::string(12,
'1'));
151 decode_check(msg_in);
152 bool expected_out_of_range_exception =
false;
153 assert(expected_out_of_range_exception);
157 assert(e.field() == TestMsg::descriptor()->FindFieldByName(
"b"));
158 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Caught (as expected) " << e.what() << std::endl;
168 msg_in.set_vb(std::string(12,
'1'));
170 decode_check(msg_in);
171 bool expected_out_of_range_exception =
false;
172 assert(expected_out_of_range_exception);
176 assert(e.field() == TestMsg::descriptor()->FindFieldByName(
"vb"));
177 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Caught (as expected) " << e.what() << std::endl;
187 msg_in.set_b(std::string(9,
'1'));
193 decode_check(msg_in);
197 assert(e.field() == TestMsg::descriptor()->FindFieldByName(
"ri"));
198 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Caught (as expected) " << e.what() << std::endl;
202 codec.set_strict(
false);
209 msg_in.set_b(std::string(9,
'1'));
214 decode_check(msg_in);
223 msg_in.set_b(std::string(9,
'1'));
225 decode_check(msg_in);
234 msg_in.set_b(std::string(9,
'1'));
236 decode_check(msg_in);
244 msg_in.set_s2(
"foobar1234546789");
245 msg_in.set_b(std::string(9,
'1'));
247 decode_check(msg_in);
255 msg_in.set_s(
"foobar1234546789");
256 msg_in.set_b(std::string(9,
'1'));
258 decode_check(msg_in);
267 msg_in.set_b(std::string(12,
'1'));
269 decode_check(msg_in);
278 msg_in.set_vb(std::string(12,
'1'));
280 decode_check(msg_in);
289 msg_in.set_b(std::string(9,
'1'));
295 decode_check(msg_in);
298 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"all tests passed" << std::endl;
301void decode_check(
const TestMsg& msg_in)
303 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Message in:\n" << msg_in.DebugString() << std::endl;
305 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try encode (in bounds)..." << std::endl;
307 codec.encode(&bytes, msg_in);
308 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
310 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try decode..." << std::endl;
313 codec.decode(bytes, &msg_out);
315 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
The Dynamic CCL enCODer/DECoder. This is the main class you will use to load, encode and decode 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.
void hex_encode(CharIterator begin, CharIterator end, std::string *out, bool upper_case=false)
Encodes a (little-endian) hexadecimal string from a byte string. Index 0 of begin is written to index...