26 #include "../../codec.h"
30 int main(
int ,
char* [])
32 dccl::dlog.
connect(dccl::logger::ALL, &std::cerr);
37 ShortIDMsg short_id_msg;
38 codec.load(short_id_msg.GetDescriptor());
39 codec.info(short_id_msg.GetDescriptor(), &dccl::dlog);
42 assert(codec.size(short_id_msg) == 1);
43 codec.encode(&encoded, short_id_msg);
44 assert(codec.id(encoded) == 2);
45 codec.decode(encoded, &short_id_msg);
49 LongIDMsg long_id_msg;
51 codec.load(long_id_msg.GetDescriptor());
52 codec.info(long_id_msg.GetDescriptor(), &dccl::dlog);
53 assert(codec.size(long_id_msg) == 2);
54 codec.encode(&encoded, long_id_msg);
55 assert(codec.id(encoded) == 10000);
56 codec.decode(encoded, &long_id_msg);
60 ShortIDEdgeMsg short_id_edge_msg;
62 codec.load(short_id_edge_msg.GetDescriptor());
63 codec.info(short_id_edge_msg.GetDescriptor(), &dccl::dlog);
64 assert(codec.size(short_id_edge_msg) == 1);
65 codec.encode(&encoded, short_id_edge_msg);
66 assert(codec.id(encoded) == 127);
67 codec.decode(encoded, &short_id_edge_msg);
71 LongIDEdgeMsg long_id_edge_msg;
73 codec.load(long_id_edge_msg.GetDescriptor());
74 codec.info(long_id_edge_msg.GetDescriptor(), &dccl::dlog);
75 codec.encode(&encoded, long_id_edge_msg);
76 assert(codec.id(encoded) == 128);
77 codec.decode(encoded, &long_id_edge_msg);
78 assert(codec.size(long_id_edge_msg) == 2);
82 TooLongIDMsg too_long_id_msg;
86 codec.load(too_long_id_msg.GetDescriptor());
95 ShortIDMsgWithData short_id_msg_with_data;
97 codec.load(short_id_msg_with_data.GetDescriptor());
98 codec.info(short_id_msg_with_data.GetDescriptor(), &dccl::dlog);
100 short_id_msg_with_data.set_in_head(42);
101 short_id_msg_with_data.set_in_body(37);
102 codec.encode(&encoded, short_id_msg_with_data);
103 assert(codec.id(encoded) == 3);
104 codec.decode(encoded, &short_id_msg_with_data);
107 std::cout <<
"all tests passed" << std::endl;