26 #include <google/protobuf/descriptor.pb.h>
28 #include "dccl/codec.h"
29 #include "dccl/codecs3/field_codec_default.h"
32 #include "dccl/binary.h"
35 template <
typename Msg>
36 void check(
double val,
bool should_pass);
39 TestMsgGroup msg_group_in;
48 double max() {
return 100; }
49 double min() {
return -100; }
50 double precision() {
return 1; }
59 int main(
int argc,
char* argv[])
63 dccl::FieldCodecManager::add<dccl::test::TestCodec>(
"test.grouptest");
64 dccl::FieldCodecManager::add<dccl::v3::DefaultMessageCodec, google::protobuf::FieldDescriptor::TYPE_MESSAGE>(
"test.grouptest");
66 check<TestMsg>(50,
true);
67 check<TestMsg>(-50,
false);
68 check<TestMsgGroup>(50,
true);
69 check<TestMsgGroup>(-50,
true);
70 check<TestMsgVersion>(50,
true);
72 std::cout <<
"all tests passed" << std::endl;
76 template <
typename Msg>
77 void check(
double val,
bool should_pass)
81 msg_in.set_d(++i + 0.1);
82 msg_in.add_d_repeat(12.1);
83 msg_in.add_d_repeat(12.2);
84 msg_in.add_d_repeat(12.3);
86 msg_in.mutable_msg()->set_val(val);
87 msg_in.mutable_msg()->mutable_msg()->set_val(val);
88 codec.info(msg_in.GetDescriptor(), &std::cout);
90 std::cout <<
"Message in:\n" << msg_in.DebugString() << std::endl;
92 codec.load(msg_in.GetDescriptor());
94 std::cout <<
"Try encode..." << std::endl;
96 codec.encode(&bytes, msg_in);
97 std::cout <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
99 std::cout <<
"Try decode..." << std::endl;
102 codec.decode(bytes, &msg_out);
104 std::cout <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
107 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
109 assert(msg_in.SerializeAsString() != msg_out.SerializeAsString());