Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Regents of the University of California. |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "../helpers/repo-command-parameter.hpp" |
| 8 | #include <ndn-cpp-dev/selectors.hpp> |
| 9 | |
| 10 | #include <boost/test/unit_test.hpp> |
| 11 | |
| 12 | namespace repo { |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 13 | namespace tests { |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 14 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 15 | BOOST_AUTO_TEST_SUITE(RepoCommandParameter) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 16 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 17 | BOOST_AUTO_TEST_CASE(EncodeDecode) |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 18 | { |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 19 | repo::RepoCommandParameter parameter; |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 20 | parameter.setName("/a/b/c"); |
| 21 | parameter.setStartBlockId(1); |
| 22 | parameter.setEndBlockId(100); |
| 23 | parameter.setProcessId(1234567890); |
| 24 | ndn::Selectors selectors; |
| 25 | selectors.setMaxSuffixComponents(1); |
| 26 | parameter.setSelectors(selectors); |
| 27 | |
| 28 | ndn::Block wire = parameter.wireEncode(); |
| 29 | |
| 30 | // These octets are obtained by the snippet below. |
| 31 | // This check is intended to detect unexpected encoding change in the future. |
| 32 | //for (ndn::Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) { |
| 33 | // printf("0x%02x, ", *it); |
| 34 | //} |
| 35 | static const uint8_t expected[] = { |
| 36 | 0xc9, 0x1c, 0x07, 0x09, 0x08, 0x01, 0x61, 0x08, 0x01, 0x62, 0x08, |
| 37 | 0x01, 0x63, 0x09, 0x03, 0x0e, 0x01, 0x01, 0xcc, 0x01, 0x01, 0xcd, |
| 38 | 0x01, 0x64, 0xce, 0x04, 0x49, 0x96, 0x02, 0xd2 |
| 39 | }; |
| 40 | |
| 41 | BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 42 | wire.begin(), wire.end()); |
| 43 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 44 | BOOST_REQUIRE_NO_THROW(repo::RepoCommandParameter(wire)); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 45 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 46 | repo::RepoCommandParameter decoded(wire); |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 47 | //std::cout << decoded << std::endl; |
| 48 | BOOST_CHECK_EQUAL(decoded.getName(), parameter.getName()); |
| 49 | BOOST_CHECK_EQUAL(decoded.getStartBlockId(), parameter.getStartBlockId()); |
| 50 | BOOST_CHECK_EQUAL(decoded.getEndBlockId(), parameter.getEndBlockId()); |
| 51 | BOOST_CHECK_EQUAL(decoded.getProcessId(), parameter.getProcessId()); |
| 52 | BOOST_CHECK_EQUAL(decoded.getSelectors().getMaxSuffixComponents(), |
| 53 | parameter.getSelectors().getMaxSuffixComponents()); |
| 54 | } |
| 55 | |
| 56 | BOOST_AUTO_TEST_SUITE_END() |
| 57 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 58 | } // namespace tests |
Shuo Chen | ba793e9 | 2014-03-17 17:17:16 -0700 | [diff] [blame] | 59 | } // namespace repo |