blob: 301f9c312eda587907b03be2381013c38836ad0d [file] [log] [blame]
Yingdi Yu27158392014-01-20 13:04:20 -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"
Yingdi Yu27158392014-01-20 13:04:20 -080010
11using namespace std;
12using namespace ndn;
13
14BOOST_AUTO_TEST_SUITE(TestBlock)
15
16const uint8_t Interest1[] = {
17 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
44};
45
46BOOST_AUTO_TEST_CASE (Decode)
47{
48 boost::iostreams::stream<boost::iostreams::array_source> is (reinterpret_cast<const char *>(Interest1), sizeof(Interest1));
49
50 Block interestBlock(is);
51
52 ndn::Interest i;
53 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
54
55 BOOST_REQUIRE_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
56 BOOST_REQUIRE_EQUAL(i.getScope(), 1);
57 BOOST_REQUIRE_EQUAL(i.getInterestLifetime(), 1000);
58 BOOST_REQUIRE_EQUAL(i.getMinSuffixComponents(), 1);
59 BOOST_REQUIRE_EQUAL(i.getMaxSuffixComponents(), 1);
60 BOOST_REQUIRE_EQUAL(i.getChildSelector(), 1);
61 BOOST_REQUIRE_EQUAL(i.getMustBeFresh(), false);
62 BOOST_REQUIRE_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
63 BOOST_REQUIRE_EQUAL(i.getNonce(), 1);
64}
65
66BOOST_AUTO_TEST_SUITE_END()