blob: 89ceaf0adb27b83ee523f39cdc8c9415d8cfee1d [file] [log] [blame]
Shuo Chenba793e92014-03-17 17:17:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -07003 * Copyright (c) 2014, Regents of the University of California.
4 *
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
20#include "../helpers/repo-command-parameter.hpp"
Alexander Afanasyeve291caf2014-04-25 11:17:36 -070021#include <ndn-cxx/selectors.hpp>
Shuo Chenba793e92014-03-17 17:17:16 -070022
23#include <boost/test/unit_test.hpp>
24
25namespace repo {
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070026namespace tests {
Shuo Chenba793e92014-03-17 17:17:16 -070027
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070028BOOST_AUTO_TEST_SUITE(RepoCommandParameter)
Shuo Chenba793e92014-03-17 17:17:16 -070029
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070030BOOST_AUTO_TEST_CASE(EncodeDecode)
Shuo Chenba793e92014-03-17 17:17:16 -070031{
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070032 repo::RepoCommandParameter parameter;
Shuo Chenba793e92014-03-17 17:17:16 -070033 parameter.setName("/a/b/c");
34 parameter.setStartBlockId(1);
35 parameter.setEndBlockId(100);
36 parameter.setProcessId(1234567890);
37 ndn::Selectors selectors;
38 selectors.setMaxSuffixComponents(1);
39 parameter.setSelectors(selectors);
40
41 ndn::Block wire = parameter.wireEncode();
42
43 // These octets are obtained by the snippet below.
44 // This check is intended to detect unexpected encoding change in the future.
45 //for (ndn::Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
46 // printf("0x%02x, ", *it);
47 //}
48 static const uint8_t expected[] = {
49 0xc9, 0x1c, 0x07, 0x09, 0x08, 0x01, 0x61, 0x08, 0x01, 0x62, 0x08,
50 0x01, 0x63, 0x09, 0x03, 0x0e, 0x01, 0x01, 0xcc, 0x01, 0x01, 0xcd,
51 0x01, 0x64, 0xce, 0x04, 0x49, 0x96, 0x02, 0xd2
52 };
53
54 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
55 wire.begin(), wire.end());
56
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070057 BOOST_REQUIRE_NO_THROW(repo::RepoCommandParameter(wire));
Shuo Chenba793e92014-03-17 17:17:16 -070058
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070059 repo::RepoCommandParameter decoded(wire);
Shuo Chenba793e92014-03-17 17:17:16 -070060 //std::cout << decoded << std::endl;
61 BOOST_CHECK_EQUAL(decoded.getName(), parameter.getName());
62 BOOST_CHECK_EQUAL(decoded.getStartBlockId(), parameter.getStartBlockId());
63 BOOST_CHECK_EQUAL(decoded.getEndBlockId(), parameter.getEndBlockId());
64 BOOST_CHECK_EQUAL(decoded.getProcessId(), parameter.getProcessId());
65 BOOST_CHECK_EQUAL(decoded.getSelectors().getMaxSuffixComponents(),
66 parameter.getSelectors().getMaxSuffixComponents());
67}
68
69BOOST_AUTO_TEST_SUITE_END()
70
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070071} // namespace tests
Shuo Chenba793e92014-03-17 17:17:16 -070072} // namespace repo