26#include "../../codec.h"
30int main(
int argc,
char* argv[])
33 for (
int i = 1; i < argc; ++i)
35 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
39 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
43 codec.load<NumericMsg>();
44 codec.info<NumericMsg>(&dccl::dlog);
48 codec.load<TooBigNumericMsg>();
49 bool message_should_fail_load =
false;
50 assert(message_should_fail_load);
54 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"** Note: this error is expected during proper execution of this unit test "
55 "**: Field a failed validation: "
56 "[(dccl.field).max-(dccl.field).min]/(dccl.field).resolution must fit in a "
57 "double-precision floating point value. Please increase min, decrease max, or "
64 msg_in.set_a(10.12345678);
65 msg_in.set_b(11.42106);
66 msg_in.set_u1(18446744073709500000ull);
70 codec.encode(&encoded, msg_in);
73 codec.decode(encoded, &msg_out);
75 msg_in.set_b(11.4211);
76 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
79 const int NUM_TESTS = 8;
80 int test_values[NUM_TESTS][4] = {
82 {20, 20, -500000, -500000}, {0, 0, 254000, 254000},
83 {10, 10, -257000, -257000}, {-10, -10, -499000, -499000},
84 {-20, -20, 500000, 500000}, {-19, -20, 499999, 500000},
85 {6, 10, -123400, -123000}, {0, 0, 0, 0},
87 for (
auto& test_value : test_values)
89 NegativePrecisionNumericMsg msg_in_neg, msg_out_neg;
91 msg_in_neg.set_a(test_value[0]);
92 msg_in_neg.set_b(test_value[2]);
94 codec.encode(&enc, msg_in_neg);
95 codec.decode(enc, &msg_out_neg);
97 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"msg_in: " << msg_in_neg.ShortDebugString() << std::endl;
98 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"msg_out: " << msg_out_neg.ShortDebugString() << std::endl;
100 assert(msg_out_neg.a() == test_value[1]);
101 assert(msg_out_neg.b() == test_value[3]);
104 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.