DCCL v5
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//
8//
9// This file is part of the Dynamic Compact Control Language Library
10// ("DCCL").
11//
12// DCCL is free software: you can redistribute it and/or modify
13// it under the terms of the GNU Lesser General Public License as published by
14// the Free Software Foundation, either version 2.1 of the License, or
15// (at your option) any later version.
16//
17// DCCL is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU Lesser General Public License for more details.
21//
22// You should have received a copy of the GNU Lesser General Public License
23// along with DCCL. If not, see <http://www.gnu.org/licenses/>.
24// tests required versus optional encoding of fields using a presence bit
25
26#include "../../codec.h"
27#include "test.pb.h"
28using namespace dccl::test;
29
30int main(int argc, char* argv[])
31{
32 bool verbose = false;
33 for (int i = 1; i < argc; ++i)
34 {
35 if (argv[i] && argv[i][0] == '-' && argv[i][1] == 'v' && argv[i][2] == '\0')
36 verbose = true;
37 }
38
39 dccl::dlog.connect(verbose ? dccl::logger::ALL : dccl::logger::WARN_PLUS, &std::cerr);
40
41 dccl::Codec codec;
42
43 codec.load<BytesMsg>();
44 codec.info<BytesMsg>(&dccl::dlog);
45
46 BytesMsg msg_in;
47
48 msg_in.set_req_bytes(dccl::hex_decode("88abcd1122338754"));
49 msg_in.set_opt_bytes(dccl::hex_decode("102030adef2cb79d"));
50 msg_in.add_rep_bytes(dccl::hex_decode("0011223344556677"));
51 msg_in.add_rep_bytes(dccl::hex_decode("8899aabbccddeeff"));
52
53 std::string encoded;
54 codec.encode(&encoded, msg_in);
55
56 assert(encoded.size() == 36);
57
58 BytesMsg msg_out;
59 codec.decode(encoded, &msg_out);
60
61 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
62
63 dccl::dlog.is(dccl::logger::INFO) && dccl::dlog << "all tests passed" << std::endl;
64}
The Dynamic CCL enCODer/DECoder. This is the main class you will use to load, encode and decode DCCL ...
Definition codec.h:61
bool is(logger::Verbosity verbosity, logger::Group group=logger::GENERAL)
Indicates the verbosity of the Logger until the next std::flush or std::endl. The boolean return is u...
Definition logger.h:191
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:213
Unit test namespace.
Definition test.cpp:45
Dynamic Compact Control Language namespace.
Definition any.h:28
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:46