29 #include <google/protobuf/descriptor.pb.h>
31 #include "../../codec.h"
32 #include "../../codecs3/field_codec_default.h"
34 #include "../../binary.h"
38 template <
typename Msg>
void check(
double val,
bool should_pass);
41 TestMsgGroup msg_group_in;
49 double max()
override {
return 100; }
50 double min()
override {
return -100; }
51 double precision()
override {
return 1; }
52 double resolution()
override {
return 0.1; }
53 void validate()
override {}
58 int main(
int ,
char* [])
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;
76 template <
typename Msg>
void check(
double val,
bool should_pass)
80 msg_in.set_d(++i + 0.1);
81 msg_in.add_d_repeat(12.1);
82 msg_in.add_d_repeat(12.2);
83 msg_in.add_d_repeat(12.3);
85 msg_in.mutable_msg()->set_val(val);
86 msg_in.mutable_msg()->mutable_msg()->set_val(val);
87 codec.info(msg_in.GetDescriptor(), &std::cout);
89 std::cout <<
"Message in:\n" << msg_in.DebugString() << std::endl;
91 codec.load(msg_in.GetDescriptor());
93 std::cout <<
"Try encode..." << std::endl;
95 codec.encode(&bytes, msg_in);
96 std::cout <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
98 std::cout <<
"Try decode..." << std::endl;
101 codec.decode(bytes, &msg_out);
103 std::cout <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
106 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
108 assert(msg_in.SerializeAsString() != msg_out.SerializeAsString());