blob: f01832aaa585aeec91d356ce846a8e34da5defb4 [file] [log] [blame]
Shuo Chenba793e92014-03-17 17:17:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento759214f2018-03-11 21:03:32 -04002/*
3 * Copyright (c) 2014-2018, Regents of the University of California.
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -07004 *
5 * This file is part of NDN repo-ng (Next generation of NDN repository).
6 * See AUTHORS.md for complete list of repo-ng authors and contributors.
7 *
8 * repo-ng is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Shuo Chenba793e92014-03-17 17:17:16 -070018 */
19
Alexander Afanasyev39d98072014-05-04 12:46:29 -070020#include "repo-command-parameter.hpp"
Shuo Chenca329182014-03-19 18:05:18 -070021
weijia yuan3aa8d2b2018-03-06 15:35:57 -080022#include "common.hpp"
Shuo Chenba793e92014-03-17 17:17:16 -070023
weijia yuan3aa8d2b2018-03-06 15:35:57 -080024#include <ndn-cxx/encoding/block.hpp>
25#include <ndn-cxx/encoding/block-helpers.hpp>
26
27#include <boost/lexical_cast.hpp>
Shuo Chenba793e92014-03-17 17:17:16 -070028#include <boost/test/unit_test.hpp>
29
30namespace repo {
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070031namespace tests {
Shuo Chenba793e92014-03-17 17:17:16 -070032
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070033BOOST_AUTO_TEST_SUITE(RepoCommandParameter)
Shuo Chenba793e92014-03-17 17:17:16 -070034
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070035BOOST_AUTO_TEST_CASE(EncodeDecode)
Shuo Chenba793e92014-03-17 17:17:16 -070036{
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070037 repo::RepoCommandParameter parameter;
Shuo Chenba793e92014-03-17 17:17:16 -070038 parameter.setName("/a/b/c");
39 parameter.setStartBlockId(1);
40 parameter.setEndBlockId(100);
41 parameter.setProcessId(1234567890);
Shuo Chenba793e92014-03-17 17:17:16 -070042
weijia yuan3aa8d2b2018-03-06 15:35:57 -080043 Block wire = parameter.wireEncode();
Shuo Chenba793e92014-03-17 17:17:16 -070044
45 // These octets are obtained by the snippet below.
46 // This check is intended to detect unexpected encoding change in the future.
weijia yuan3aa8d2b2018-03-06 15:35:57 -080047 // Construct a \c Block from hexadecimal \p input.
48 Block expected = "C917 0709080161080162080163CC0101CD0164CE04499602D2"_block;
Shuo Chenba793e92014-03-17 17:17:16 -070049
weijia yuan3aa8d2b2018-03-06 15:35:57 -080050 BOOST_CHECK_EQUAL(wire, expected);
Shuo Chenba793e92014-03-17 17:17:16 -070051
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070052 repo::RepoCommandParameter decoded(wire);
Shuo Chenba793e92014-03-17 17:17:16 -070053 BOOST_CHECK_EQUAL(decoded.getName(), parameter.getName());
54 BOOST_CHECK_EQUAL(decoded.getStartBlockId(), parameter.getStartBlockId());
55 BOOST_CHECK_EQUAL(decoded.getEndBlockId(), parameter.getEndBlockId());
56 BOOST_CHECK_EQUAL(decoded.getProcessId(), parameter.getProcessId());
Shuo Chenba793e92014-03-17 17:17:16 -070057}
58
59BOOST_AUTO_TEST_SUITE_END()
60
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070061} // namespace tests
Shuo Chenba793e92014-03-17 17:17:16 -070062} // namespace repo