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 assert(encoded.size() == 2);
57 codec.decode(encoded, &long_id_msg);
62 codec.id(std::string());
68 std::cout <<
"Expected exception: " << e.what() << std::endl;
72 codec.id(encoded.substr(0, 1));
78 std::cout <<
"Expected exception: " << e.what() << std::endl;
83 ShortIDEdgeMsg short_id_edge_msg;
85 codec.load(short_id_edge_msg.GetDescriptor());
86 codec.info(short_id_edge_msg.GetDescriptor(), &dccl::dlog);
87 assert(codec.size(short_id_edge_msg) == 1);
88 codec.encode(&encoded, short_id_edge_msg);
89 assert(codec.id(encoded) == 127);
90 codec.decode(encoded, &short_id_edge_msg);
94 LongIDEdgeMsg long_id_edge_msg;
96 codec.load(long_id_edge_msg.GetDescriptor());
97 codec.info(long_id_edge_msg.GetDescriptor(), &dccl::dlog);
98 codec.encode(&encoded, long_id_edge_msg);
99 assert(codec.id(encoded) == 128);
100 codec.decode(encoded, &long_id_edge_msg);
101 assert(codec.size(long_id_edge_msg) == 2);
105 TooLongIDMsg too_long_id_msg;
109 codec.load(too_long_id_msg.GetDescriptor());
118 ShortIDMsgWithData short_id_msg_with_data;
120 codec.load(short_id_msg_with_data.GetDescriptor());
121 codec.info(short_id_msg_with_data.GetDescriptor(), &dccl::dlog);
123 short_id_msg_with_data.set_in_head(42);
124 short_id_msg_with_data.set_in_body(37);
125 codec.encode(&encoded, short_id_msg_with_data);
126 assert(codec.id(encoded) == 3);
127 codec.decode(encoded, &short_id_msg_with_data);
130 std::cout <<
"all tests passed" << std::endl;