blob: ddfe03a0156c254908afacee5b9efd0ea8029e44 [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;
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080041 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080042
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080043 BOOST_REQUIRE_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
44 BOOST_REQUIRE_EQUAL(i.getScope(), 1);
45 BOOST_REQUIRE_EQUAL(i.getInterestLifetime(), 1000);
46 BOOST_REQUIRE_EQUAL(i.getMinSuffixComponents(), 1);
47 BOOST_REQUIRE_EQUAL(i.getMaxSuffixComponents(), 1);
48 BOOST_REQUIRE_EQUAL(i.getChildSelector(), 1);
49 BOOST_REQUIRE_EQUAL(i.getMustBeFresh(), false);
50 BOOST_REQUIRE_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080051}
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();
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080065 BOOST_REQUIRE_EQUAL_COLLECTIONS(Interest1, Interest1+sizeof(Interest1),
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080066 wire.begin(), wire.end());
67}
68
69BOOST_AUTO_TEST_SUITE_END()