blob: ca2ffeb5416a95f69d32b1bef4a19ef2c1edfc23 [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,
Alexander Afanasyev840139f2013-12-28 15:02:50 -080031 0x5, 0x1, 0x1,
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080032 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 Afanasyev840139f2013-12-28 15:02:50 -080051 BOOST_REQUIRE_EQUAL(i.getNonce(), 1);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080052}
53
54BOOST_AUTO_TEST_CASE (Encode)
55{
56 ndn::Interest i(ndn::Name("/local/ndn/prefix"));
57 i.setScope(1);
58 i.setInterestLifetime(1000);
59 i.setMinSuffixComponents(1);
60 i.setMaxSuffixComponents(1);
61 i.setChildSelector(1);
62 i.setMustBeFresh(false);
63 i.getExclude().excludeOne("alex").excludeRange("xxxx", "yyyy");
Alexander Afanasyev840139f2013-12-28 15:02:50 -080064 i.setNonce(1);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080065
66 const Block &wire = i.wireEncode();
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080067 BOOST_REQUIRE_EQUAL_COLLECTIONS(Interest1, Interest1+sizeof(Interest1),
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080068 wire.begin(), wire.end());
69}
70
71BOOST_AUTO_TEST_SUITE_END()