blob: 0b2184735b4ca8f466ce50fc9ed7f8596bbc201d [file] [log] [blame]
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001/**
2 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
4 * See COPYING for copyright and distribution information.
5 */
6
7#include <boost/test/unit_test.hpp>
8
9#include <ndn-cpp/interest.hpp>
10
11using namespace std;
12using namespace ndn;
13
14BOOST_AUTO_TEST_SUITE(TestInterest)
15
16const uint8_t Interest1[] = {
17 0x0, 0x41,
18 0x2, 0x14,
19 0x3, 0x5, 0x6c, 0x6f, 0x63, 0x61, 0x6c,
20 0x3, 0x3, 0x6e, 0x64, 0x6e,
21 0x3, 0x6, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
22 0x4, 0x1f,
23 0x8, 0x1, 0x1,
24 0x9, 0x1, 0x1,
25 0xb, 0x14,
26 0x3, 0x4, 0x61, 0x6c, 0x65, 0x78,
27 0x3, 0x4, 0x78, 0x78, 0x78, 0x78,
28 0xe, 0x0,
29 0x3, 0x4, 0x79, 0x79, 0x79, 0x79,
30 0xc, 0x1, 0x1,
31 0x5, 0x1, 0x0,
32 0x6, 0x1, 0x1,
33 0x7, 0x2, 0x3, 0xe8
34};
35
36BOOST_AUTO_TEST_CASE (Decode)
37{
38 Block interestBlock(Interest1, sizeof(Interest1));
39
40 ndn::Interest i;
41 BOOST_CHECK_NO_THROW(i.wireDecode(interestBlock));
42
43 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
44 BOOST_CHECK_EQUAL(i.getScope(), 1);
45 BOOST_CHECK_EQUAL(i.getInterestLifetime(), 1000);
46 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
47 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
48 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
49 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
50 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
51}
52
53BOOST_AUTO_TEST_CASE (Encode)
54{
55 ndn::Interest i(ndn::Name("/local/ndn/prefix"));
56 i.setScope(1);
57 i.setInterestLifetime(1000);
58 i.setMinSuffixComponents(1);
59 i.setMaxSuffixComponents(1);
60 i.setChildSelector(1);
61 i.setMustBeFresh(false);
62 i.getExclude().excludeOne("alex").excludeRange("xxxx", "yyyy");
63
64 const Block &wire = i.wireEncode();
65 BOOST_CHECK_EQUAL_COLLECTIONS(Interest1, Interest1+sizeof(Interest1),
66 wire.begin(), wire.end());
67}
68
69BOOST_AUTO_TEST_SUITE_END()