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; }
51 double resolution() {
return 0.1; }
60 int main(
int argc,
char* argv[])
64 dccl::FieldCodecManager::add<dccl::test::TestCodec>(
"test.grouptest");
65 dccl::FieldCodecManager::add<dccl::v3::DefaultMessageCodec, google::protobuf::FieldDescriptor::TYPE_MESSAGE>(
"test.grouptest");
67 check<TestMsg>(50,
true);
68 check<TestMsg>(-50,
false);
69 check<TestMsgGroup>(50,
true);
70 check<TestMsgGroup>(-50,
true);
71 check<TestMsgVersion>(50,
true);
73 std::cout <<
"all tests passed" << std::endl;
77 template <
typename Msg>
78 void check(
double val,
bool should_pass)
82 msg_in.set_d(++i + 0.1);
83 msg_in.add_d_repeat(12.1);
84 msg_in.add_d_repeat(12.2);
85 msg_in.add_d_repeat(12.3);
87 msg_in.mutable_msg()->set_val(val);
88 msg_in.mutable_msg()->mutable_msg()->set_val(val);
89 codec.info(msg_in.GetDescriptor(), &std::cout);
91 std::cout <<
"Message in:\n" << msg_in.DebugString() << std::endl;
93 codec.load(msg_in.GetDescriptor());
95 std::cout <<
"Try encode..." << std::endl;
97 codec.encode(&bytes, msg_in);
98 std::cout <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
100 std::cout <<
"Try decode..." << std::endl;
103 codec.decode(bytes, &msg_out);
105 std::cout <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
108 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
110 assert(msg_in.SerializeAsString() != msg_out.SerializeAsString());