Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame] | 3 | * 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 Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 20 | #include "repo-command-parameter.hpp" |
Shuo Chen | ca32918 | 2014-03-19 18:05:18 -0700 | [diff] [blame^] | 21 | |
Alexander Afanasyev | e291caf | 2014-04-25 11:17:36 -0700 | [diff] [blame] | 22 | #include <ndn-cxx/selectors.hpp> |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 23 | |
| 24 | #include <boost/test/unit_test.hpp> |
| 25 | |
| 26 | namespace repo { |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 27 | namespace tests { |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 28 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 29 | BOOST_AUTO_TEST_SUITE(RepoCommandParameter) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 31 | BOOST_AUTO_TEST_CASE(EncodeDecode) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 32 | { |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 33 | repo::RepoCommandParameter parameter; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 34 | 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. |
| 46 | //for (ndn::Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
| 47 | // 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 Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 58 | BOOST_REQUIRE_NO_THROW(repo::RepoCommandParameter(wire)); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 59 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 60 | repo::RepoCommandParameter decoded(wire); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 61 | //std::cout << decoded << std::endl; |
| 62 | BOOST_CHECK_EQUAL(decoded.getName(), parameter.getName()); |
| 63 | BOOST_CHECK_EQUAL(decoded.getStartBlockId(), parameter.getStartBlockId()); |
| 64 | BOOST_CHECK_EQUAL(decoded.getEndBlockId(), parameter.getEndBlockId()); |
| 65 | BOOST_CHECK_EQUAL(decoded.getProcessId(), parameter.getProcessId()); |
| 66 | BOOST_CHECK_EQUAL(decoded.getSelectors().getMaxSuffixComponents(), |
| 67 | parameter.getSelectors().getMaxSuffixComponents()); |
| 68 | } |
| 69 | |
| 70 | BOOST_AUTO_TEST_SUITE_END() |
| 71 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 72 | } // namespace tests |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 73 | } // namespace repo |