Goby v2
test.cpp
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 //
5 //
6 // This file is part of the Goby Underwater Autonomy Project Binaries
7 // ("The Goby Binaries").
8 //
9 // The Goby Binaries are free software: you can redistribute them and/or modify
10 // them under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // The Goby Binaries are distributed in the hope that they will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
21 
22 // tests required versus optional encoding of fields using a presence bit
23 
24 #include "goby/acomms/dccl.h"
25 #include "test.pb.h"
26 
27 using goby::acomms::operator<<;
28 
29 int main(int argc, char* argv[])
30 {
31  goby::glog.add_stream(goby::common::logger::DEBUG3, &std::cerr);
32  goby::glog.set_name(argv[0]);
33 
35 
36  codec->validate<BytesMsg>();
37  codec->info<BytesMsg>(&goby::glog);
38 
39  BytesMsg msg_in;
40 
41  msg_in.set_req_bytes(goby::util::hex_decode("88abcd1122338754"));
42  msg_in.set_opt_bytes(goby::util::hex_decode("102030adef2cb79d"));
43 
44  std::string encoded;
45  codec->encode(&encoded, msg_in);
46 
47  BytesMsg msg_out;
48  codec->decode(encoded, &msg_out);
49 
50  assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
51 
52  std::cout << "all tests passed" << std::endl;
53 }
void set_name(const std::string &s)
Set the name of the application that the logger is serving.
Definition: flex_ostream.h:67
static DCCLCodec * get()
DCCLCodec is a singleton class; use this to get a pointer to the class.
Definition: dccl.h:124
common::FlexOstream glog
Access the Goby logger through this object.
void add_stream(logger::Verbosity verbosity=logger::VERBOSE, std::ostream *os=0)
Attach a stream object (e.g. std::cout, std::ofstream, ...) to the logger with desired verbosity...
Definition: flex_ostream.h:96