blob: 4c6daaa13555366abebe2ce955261ef6abb66775 [file] [log] [blame]
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001/**
2 * Copyright (C) 2013 Regents of the University of California.
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08003 * See COPYING for copyright and distribution information.
4 */
5
6#include <boost/test/unit_test.hpp>
7
Alexander Afanasyev09c613f2014-01-29 00:23:58 -08008#include "interest.hpp"
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08009
10using namespace std;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080011namespace ndn {
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080012
13BOOST_AUTO_TEST_SUITE(TestInterest)
14
15const uint8_t Interest1[] = {
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080016 0x1, 0x41, // NDN Interest
17 0x3, 0x14, // Name
18 0x4, 0x5, // NameComponent
19 0x6c, 0x6f, 0x63, 0x61, 0x6c,
20 0x4, 0x3, // NameComponent
21 0x6e, 0x64, 0x6e,
22 0x4, 0x6, // NameComponent
23 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
24 0x5, 0x1f, // Selectors
25 0x09, 0x1, 0x1, // MinSuffix
26 0x0a, 0x1, 0x1, // MaxSuffix
27 0x0c, 0x14, // Exclude
28 0x4, 0x4, // NameComponent
29 0x61, 0x6c, 0x65, 0x78,
30 0x4, 0x4, // NameComponent
31 0x78, 0x78, 0x78, 0x78,
32 0xf, 0x0, // Any
33 0x4, 0x4, // NameComponent
34 0x79, 0x79, 0x79, 0x79,
35 0x0d, 0x1, // ChildSelector
36 0x1,
37 0x6, 0x1, // Nonce
38 0x1,
39 0x7, 0x1, // Scope
40 0x1,
41 0x8, // InterestLifetime
42 0x2, 0x3, 0xe8
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080043};
44
45BOOST_AUTO_TEST_CASE (Decode)
46{
47 Block interestBlock(Interest1, sizeof(Interest1));
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080048
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080049 ndn::Interest i;
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080050 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080051
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080052 BOOST_REQUIRE_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
53 BOOST_REQUIRE_EQUAL(i.getScope(), 1);
54 BOOST_REQUIRE_EQUAL(i.getInterestLifetime(), 1000);
55 BOOST_REQUIRE_EQUAL(i.getMinSuffixComponents(), 1);
56 BOOST_REQUIRE_EQUAL(i.getMaxSuffixComponents(), 1);
57 BOOST_REQUIRE_EQUAL(i.getChildSelector(), 1);
58 BOOST_REQUIRE_EQUAL(i.getMustBeFresh(), false);
59 BOOST_REQUIRE_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
Alexander Afanasyev840139f2013-12-28 15:02:50 -080060 BOOST_REQUIRE_EQUAL(i.getNonce(), 1);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080061}
62
63BOOST_AUTO_TEST_CASE (Encode)
64{
65 ndn::Interest i(ndn::Name("/local/ndn/prefix"));
66 i.setScope(1);
67 i.setInterestLifetime(1000);
68 i.setMinSuffixComponents(1);
69 i.setMaxSuffixComponents(1);
70 i.setChildSelector(1);
71 i.setMustBeFresh(false);
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -080072 i.getExclude()
73 .excludeOne(name::Component("alex"))
74 .excludeRange(name::Component("xxxx"), name::Component("yyyy"));
Alexander Afanasyev840139f2013-12-28 15:02:50 -080075 i.setNonce(1);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080076
77 const Block &wire = i.wireEncode();
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080078 BOOST_REQUIRE_EQUAL_COLLECTIONS(Interest1, Interest1+sizeof(Interest1),
Alexander Afanasyev84c2bd42014-01-09 22:35:35 -080079 wire.begin(), wire.end());
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080080}
81
82BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080083
84} // namespace ndn