blob: 94429feba7124ac9feffd432df02b84435baef91 [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/*
Davide Pesavento11904062022-04-14 22:33:28 -04003 * Copyright (c) 2014-2022, 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"
weijia yuan3aa8d2b2018-03-06 15:35:57 -080021#include "common.hpp"
Shuo Chenba793e92014-03-17 17:17:16 -070022
weijia yuan3aa8d2b2018-03-06 15:35:57 -080023#include <ndn-cxx/encoding/block-helpers.hpp>
24
25#include <boost/lexical_cast.hpp>
Shuo Chenba793e92014-03-17 17:17:16 -070026#include <boost/test/unit_test.hpp>
27
Davide Pesavento11904062022-04-14 22:33:28 -040028namespace repo::tests {
Shuo Chenba793e92014-03-17 17:17:16 -070029
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070030BOOST_AUTO_TEST_SUITE(RepoCommandParameter)
Shuo Chenba793e92014-03-17 17:17:16 -070031
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070032BOOST_AUTO_TEST_CASE(EncodeDecode)
Shuo Chenba793e92014-03-17 17:17:16 -070033{
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070034 repo::RepoCommandParameter parameter;
Shuo Chenba793e92014-03-17 17:17:16 -070035 parameter.setName("/a/b/c");
36 parameter.setStartBlockId(1);
37 parameter.setEndBlockId(100);
38 parameter.setProcessId(1234567890);
Shuo Chenba793e92014-03-17 17:17:16 -070039
weijia yuan3aa8d2b2018-03-06 15:35:57 -080040 Block wire = parameter.wireEncode();
Shuo Chenba793e92014-03-17 17:17:16 -070041
42 // These octets are obtained by the snippet below.
43 // This check is intended to detect unexpected encoding change in the future.
weijia yuan3aa8d2b2018-03-06 15:35:57 -080044 // Construct a \c Block from hexadecimal \p input.
45 Block expected = "C917 0709080161080162080163CC0101CD0164CE04499602D2"_block;
Shuo Chenba793e92014-03-17 17:17:16 -070046
weijia yuan3aa8d2b2018-03-06 15:35:57 -080047 BOOST_CHECK_EQUAL(wire, expected);
Shuo Chenba793e92014-03-17 17:17:16 -070048
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070049 repo::RepoCommandParameter decoded(wire);
Shuo Chenba793e92014-03-17 17:17:16 -070050 BOOST_CHECK_EQUAL(decoded.getName(), parameter.getName());
51 BOOST_CHECK_EQUAL(decoded.getStartBlockId(), parameter.getStartBlockId());
52 BOOST_CHECK_EQUAL(decoded.getEndBlockId(), parameter.getEndBlockId());
53 BOOST_CHECK_EQUAL(decoded.getProcessId(), parameter.getProcessId());
Shuo Chenba793e92014-03-17 17:17:16 -070054}
55
56BOOST_AUTO_TEST_SUITE_END()
57
Davide Pesavento11904062022-04-14 22:33:28 -040058} // namespace repo::tests