blob: 76ca5488399abd383a0bb46ef5323011f042e703 [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 {
13
14BOOST_AUTO_TEST_SUITE(TestRepoCommandParameter)
15
16BOOST_AUTO_TEST_CASE(TestRepoCommandParameter)
17{
18 RepoCommandParameter parameter;
19 parameter.setName("/a/b/c");
20 parameter.setStartBlockId(1);
21 parameter.setEndBlockId(100);
22 parameter.setProcessId(1234567890);
23 ndn::Selectors selectors;
24 selectors.setMaxSuffixComponents(1);
25 parameter.setSelectors(selectors);
26
27 ndn::Block wire = parameter.wireEncode();
28
29 // These octets are obtained by the snippet below.
30 // This check is intended to detect unexpected encoding change in the future.
31 //for (ndn::Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
32 // printf("0x%02x, ", *it);
33 //}
34 static const uint8_t expected[] = {
35 0xc9, 0x1c, 0x07, 0x09, 0x08, 0x01, 0x61, 0x08, 0x01, 0x62, 0x08,
36 0x01, 0x63, 0x09, 0x03, 0x0e, 0x01, 0x01, 0xcc, 0x01, 0x01, 0xcd,
37 0x01, 0x64, 0xce, 0x04, 0x49, 0x96, 0x02, 0xd2
38 };
39
40 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
41 wire.begin(), wire.end());
42
43 BOOST_REQUIRE_NO_THROW(RepoCommandParameter(wire));
44
45 RepoCommandParameter decoded(wire);
46 //std::cout << decoded << std::endl;
47 BOOST_CHECK_EQUAL(decoded.getName(), parameter.getName());
48 BOOST_CHECK_EQUAL(decoded.getStartBlockId(), parameter.getStartBlockId());
49 BOOST_CHECK_EQUAL(decoded.getEndBlockId(), parameter.getEndBlockId());
50 BOOST_CHECK_EQUAL(decoded.getProcessId(), parameter.getProcessId());
51 BOOST_CHECK_EQUAL(decoded.getSelectors().getMaxSuffixComponents(),
52 parameter.getSelectors().getMaxSuffixComponents());
53}
54
55BOOST_AUTO_TEST_SUITE_END()
56
57} // namespace repo