blob: 9b706367c4011cd5b3519a62552438aa80c94151 [file] [log] [blame]
Shuo Chenba793e92014-03-17 17:17:16 -07001/* -*- 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
12namespace repo {
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070013namespace tests {
Shuo Chenba793e92014-03-17 17:17:16 -070014
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070015BOOST_AUTO_TEST_SUITE(RepoCommandParameter)
Shuo Chenba793e92014-03-17 17:17:16 -070016
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070017BOOST_AUTO_TEST_CASE(EncodeDecode)
Shuo Chenba793e92014-03-17 17:17:16 -070018{
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070019 repo::RepoCommandParameter parameter;
Shuo Chenba793e92014-03-17 17:17:16 -070020 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 Afanasyevb0c78ea2014-04-15 18:12:04 -070044 BOOST_REQUIRE_NO_THROW(repo::RepoCommandParameter(wire));
Shuo Chenba793e92014-03-17 17:17:16 -070045
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070046 repo::RepoCommandParameter decoded(wire);
Shuo Chenba793e92014-03-17 17:17:16 -070047 //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
56BOOST_AUTO_TEST_SUITE_END()
57
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070058} // namespace tests
Shuo Chenba793e92014-03-17 17:17:16 -070059} // namespace repo