DCCL v4
Loading...
Searching...
No Matches
test.cpp
1// Copyright 2011-2023:
2// GobySoft, LLC (2013-)
3// Massachusetts Institute of Technology (2007-2014)
4// Community contributors (see AUTHORS file)
5// File authors:
6// Toby Schneider <toby@gobysoft.org>
7// Chris Murphy <cmurphy@aphysci.com>
8//
9//
10// This file is part of the Dynamic Compact Control Language Library
11// ("DCCL").
12//
13// DCCL is free software: you can redistribute it and/or modify
14// it under the terms of the GNU Lesser General Public License as published by
15// the Free Software Foundation, either version 2.1 of the License, or
16// (at your option) any later version.
17//
18// DCCL is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU Lesser General Public License for more details.
22//
23// You should have received a copy of the GNU Lesser General Public License
24// along with DCCL. If not, see <http://www.gnu.org/licenses/>.
25// tests required versus optional encoding of fields using a presence bit
26
27#include "../../codec.h"
28#include "test.pb.h"
29using namespace dccl::test;
30
31int main(int /*argc*/, char* /*argv*/ [])
32{
33 dccl::dlog.connect(dccl::logger::ALL, &std::cerr);
34
35 dccl::Codec codec;
36
37 codec.load<BytesMsg>();
38 codec.info<BytesMsg>(&dccl::dlog);
39
40 BytesMsg msg_in;
41
42 msg_in.set_req_bytes(dccl::hex_decode("88abcd1122338754"));
43 msg_in.set_opt_bytes(dccl::hex_decode("102030adef2cb79d"));
44
45 std::string encoded;
46 codec.encode(&encoded, msg_in);
47
48 BytesMsg msg_out;
49 codec.decode(encoded, &msg_out);
50
51 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
52
53 std::cout << "all tests passed" << std::endl;
54}
The Dynamic CCL enCODer/DECoder. This is the main class you will use to load, encode and decode DCCL ...
Definition codec.h:63
void connect(int verbosity_mask, Slot slot)
Connect the output of one or more given verbosities to a slot (function pointer or similar)
Definition logger.h:214
Unit test namespace.
Definition test.cpp:45
void hex_decode(const std::string &in, std::string *out)
Decodes a (little-endian) hexadecimal string to a byte string. Index 0 and 1 (first byte) of in are w...
Definition binary.h:51