blob: 3e35169f01d67aaac21052554217d05c220093c1 [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
Alexander Afanasyeve291caf2014-04-25 11:17:36 -070022#include <ndn-cxx/selectors.hpp>
Shuo Chenba793e92014-03-17 17:17:16 -070023
24#include <boost/test/unit_test.hpp>
25
26namespace repo {
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070027namespace tests {
Shuo Chenba793e92014-03-17 17:17:16 -070028
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070029BOOST_AUTO_TEST_SUITE(RepoCommandParameter)
Shuo Chenba793e92014-03-17 17:17:16 -070030
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070031BOOST_AUTO_TEST_CASE(EncodeDecode)
Shuo Chenba793e92014-03-17 17:17:16 -070032{
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070033 repo::RepoCommandParameter parameter;
Shuo Chenba793e92014-03-17 17:17:16 -070034 parameter.setName("/a/b/c");
35 parameter.setStartBlockId(1);
36 parameter.setEndBlockId(100);
37 parameter.setProcessId(1234567890);
38 ndn::Selectors selectors;
39 selectors.setMaxSuffixComponents(1);
40 parameter.setSelectors(selectors);
41
42 ndn::Block wire = parameter.wireEncode();
43
44 // These octets are obtained by the snippet below.
45 // This check is intended to detect unexpected encoding change in the future.
Davide Pesavento759214f2018-03-11 21:03:32 -040046 //for (auto it = wire.begin(); it != wire.end(); ++it) {
Shuo Chenba793e92014-03-17 17:17:16 -070047 // printf("0x%02x, ", *it);
48 //}
49 static const uint8_t expected[] = {
50 0xc9, 0x1c, 0x07, 0x09, 0x08, 0x01, 0x61, 0x08, 0x01, 0x62, 0x08,
51 0x01, 0x63, 0x09, 0x03, 0x0e, 0x01, 0x01, 0xcc, 0x01, 0x01, 0xcd,
52 0x01, 0x64, 0xce, 0x04, 0x49, 0x96, 0x02, 0xd2
53 };
54
55 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
56 wire.begin(), wire.end());
57
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070058 repo::RepoCommandParameter decoded(wire);
Shuo Chenba793e92014-03-17 17:17:16 -070059 BOOST_CHECK_EQUAL(decoded.getName(), parameter.getName());
60 BOOST_CHECK_EQUAL(decoded.getStartBlockId(), parameter.getStartBlockId());
61 BOOST_CHECK_EQUAL(decoded.getEndBlockId(), parameter.getEndBlockId());
62 BOOST_CHECK_EQUAL(decoded.getProcessId(), parameter.getProcessId());
63 BOOST_CHECK_EQUAL(decoded.getSelectors().getMaxSuffixComponents(),
64 parameter.getSelectors().getMaxSuffixComponents());
65}
66
67BOOST_AUTO_TEST_SUITE_END()
68
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070069} // namespace tests
Shuo Chenba793e92014-03-17 17:17:16 -070070} // namespace repo