28 #include <google/protobuf/descriptor.pb.h>
30 #include "../../codec.h"
31 #include "../../codecs3/field_codec_default.h"
33 #include "../../binary.h"
37 template <
typename Msg>
void check(
double val,
bool should_pass);
40 TestMsgGroup msg_group_in;
48 double max()
override {
return 100; }
49 double min()
override {
return -100; }
50 double precision()
override {
return 1; }
51 double resolution()
override {
return 0.1; }
52 void validate()
override {}
57 int main(
int ,
char* [])
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;
75 template <
typename Msg>
void check(
double val,
bool should_pass)
79 msg_in.set_d(++i + 0.1);
80 msg_in.add_d_repeat(12.1);
81 msg_in.add_d_repeat(12.2);
82 msg_in.add_d_repeat(12.3);
84 msg_in.mutable_msg()->set_val(val);
85 msg_in.mutable_msg()->mutable_msg()->set_val(val);
86 codec.info(msg_in.GetDescriptor(), &std::cout);
88 std::cout <<
"Message in:\n" << msg_in.DebugString() << std::endl;
90 codec.load(msg_in.GetDescriptor());
92 std::cout <<
"Try encode..." << std::endl;
94 codec.encode(&bytes, msg_in);
95 std::cout <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
97 std::cout <<
"Try decode..." << std::endl;
100 codec.decode(bytes, &msg_out);
102 std::cout <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
105 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
107 assert(msg_in.SerializeAsString() != msg_out.SerializeAsString());