27 #include "../../codec.h"
31 int main(
int ,
char* [])
33 dccl::dlog.
connect(dccl::logger::ALL, &std::cerr);
37 codec.load<NumericMsg>();
38 codec.info<NumericMsg>(&dccl::dlog);
42 codec.load<TooBigNumericMsg>();
43 bool message_should_fail_load =
false;
44 assert(message_should_fail_load);
48 std::cout <<
"** Note: this error is expected during proper execution of this unit test "
49 "**: Field a failed validation: "
50 "[(dccl.field).max-(dccl.field).min]/(dccl.field).resolution must fit in a "
51 "double-precision floating point value. Please increase min, decrease max, or "
58 msg_in.set_a(10.12345678);
59 msg_in.set_b(11.42106);
60 msg_in.set_u1(18446744073709500000ull);
64 codec.encode(&encoded, msg_in);
67 codec.decode(encoded, &msg_out);
69 msg_in.set_b(11.4211);
70 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
73 const int NUM_TESTS = 8;
74 int test_values[NUM_TESTS][4] = {
76 {20, 20, -500000, -500000}, {0, 0, 254000, 254000},
77 {10, 10, -257000, -257000}, {-10, -10, -499000, -499000},
78 {-20, -20, 500000, 500000}, {-19, -20, 499999, 500000},
79 {6, 10, -123400, -123000}, {0, 0, 0, 0},
81 for (
auto& test_value : test_values)
83 NegativePrecisionNumericMsg msg_in_neg, msg_out_neg;
85 msg_in_neg.set_a(test_value[0]);
86 msg_in_neg.set_b(test_value[2]);
88 codec.encode(&enc, msg_in_neg);
89 codec.decode(enc, &msg_out_neg);
91 std::cout <<
"msg_in: " << msg_in_neg.ShortDebugString() << std::endl;
92 std::cout <<
"msg_out: " << msg_out_neg.ShortDebugString() << std::endl;
94 assert(msg_out_neg.a() == test_value[1]);
95 assert(msg_out_neg.b() == test_value[3]);
98 std::cout <<
"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.
void connect(int verbosity_mask, Slot slot)
Connect the output of one or more given verbosities to a slot (function pointer or similar)