blob: db193e88f4fd0171c6f78cc363ebca04af1a970d [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
Alexander Afanasyev09c613f2014-01-29 00:23:58 -08009#include "interest.hpp"
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080010
11using namespace std;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080012namespace ndn {
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080013
14BOOST_AUTO_TEST_SUITE(TestInterest)
15
16const uint8_t Interest1[] = {
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080017 0x1, 0x41, // NDN Interest
18 0x3, 0x14, // Name
19 0x4, 0x5, // NameComponent
20 0x6c, 0x6f, 0x63, 0x61, 0x6c,
21 0x4, 0x3, // NameComponent
22 0x6e, 0x64, 0x6e,
23 0x4, 0x6, // NameComponent
24 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
25 0x5, 0x1f, // Selectors
26 0x09, 0x1, 0x1, // MinSuffix
27 0x0a, 0x1, 0x1, // MaxSuffix
28 0x0c, 0x14, // Exclude
29 0x4, 0x4, // NameComponent
30 0x61, 0x6c, 0x65, 0x78,
31 0x4, 0x4, // NameComponent
32 0x78, 0x78, 0x78, 0x78,
33 0xf, 0x0, // Any
34 0x4, 0x4, // NameComponent
35 0x79, 0x79, 0x79, 0x79,
36 0x0d, 0x1, // ChildSelector
37 0x1,
38 0x6, 0x1, // Nonce
39 0x1,
40 0x7, 0x1, // Scope
41 0x1,
42 0x8, // InterestLifetime
43 0x2, 0x3, 0xe8
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080044};
45
46BOOST_AUTO_TEST_CASE (Decode)
47{
48 Block interestBlock(Interest1, sizeof(Interest1));
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080049
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080050 ndn::Interest i;
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080051 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080052
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080053 BOOST_REQUIRE_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
54 BOOST_REQUIRE_EQUAL(i.getScope(), 1);
55 BOOST_REQUIRE_EQUAL(i.getInterestLifetime(), 1000);
56 BOOST_REQUIRE_EQUAL(i.getMinSuffixComponents(), 1);
57 BOOST_REQUIRE_EQUAL(i.getMaxSuffixComponents(), 1);
58 BOOST_REQUIRE_EQUAL(i.getChildSelector(), 1);
59 BOOST_REQUIRE_EQUAL(i.getMustBeFresh(), false);
60 BOOST_REQUIRE_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
Alexander Afanasyev840139f2013-12-28 15:02:50 -080061 BOOST_REQUIRE_EQUAL(i.getNonce(), 1);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080062}
63
64BOOST_AUTO_TEST_CASE (Encode)
65{
66 ndn::Interest i(ndn::Name("/local/ndn/prefix"));
67 i.setScope(1);
68 i.setInterestLifetime(1000);
69 i.setMinSuffixComponents(1);
70 i.setMaxSuffixComponents(1);
71 i.setChildSelector(1);
72 i.setMustBeFresh(false);
73 i.getExclude().excludeOne("alex").excludeRange("xxxx", "yyyy");
Alexander Afanasyev840139f2013-12-28 15:02:50 -080074 i.setNonce(1);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080075
76 const Block &wire = i.wireEncode();
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080077 BOOST_REQUIRE_EQUAL_COLLECTIONS(Interest1, Interest1+sizeof(Interest1),
Alexander Afanasyev84c2bd42014-01-09 22:35:35 -080078 wire.begin(), wire.end());
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080079}
80
81BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080082
83} // namespace ndn