blob: fe433a4c3c459860ed6425e8785dd23fff1a3853 [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;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080012
13namespace ndn {
Yingdi Yu27158392014-01-20 13:04:20 -080014
15BOOST_AUTO_TEST_SUITE(TestBlock)
16
17const uint8_t Interest1[] = {
18 0x1, 0x41, // NDN Interest
19 0x3, 0x14, // Name
20 0x4, 0x5, // NameComponent
21 0x6c, 0x6f, 0x63, 0x61, 0x6c,
22 0x4, 0x3, // NameComponent
23 0x6e, 0x64, 0x6e,
24 0x4, 0x6, // NameComponent
25 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
26 0x5, 0x1f, // Selectors
27 0x09, 0x1, 0x1, // MinSuffix
28 0x0a, 0x1, 0x1, // MaxSuffix
29 0x0c, 0x14, // Exclude
30 0x4, 0x4, // NameComponent
31 0x61, 0x6c, 0x65, 0x78,
32 0x4, 0x4, // NameComponent
33 0x78, 0x78, 0x78, 0x78,
34 0xf, 0x0, // Any
35 0x4, 0x4, // NameComponent
36 0x79, 0x79, 0x79, 0x79,
37 0x0d, 0x1, // ChildSelector
38 0x1,
39 0x6, 0x1, // Nonce
40 0x1,
41 0x7, 0x1, // Scope
42 0x1,
43 0x8, // InterestLifetime
44 0x2, 0x3, 0xe8
45};
46
47BOOST_AUTO_TEST_CASE (Decode)
48{
49 boost::iostreams::stream<boost::iostreams::array_source> is (reinterpret_cast<const char *>(Interest1), sizeof(Interest1));
50
51 Block interestBlock(is);
52
53 ndn::Interest i;
54 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
55
56 BOOST_REQUIRE_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
57 BOOST_REQUIRE_EQUAL(i.getScope(), 1);
58 BOOST_REQUIRE_EQUAL(i.getInterestLifetime(), 1000);
59 BOOST_REQUIRE_EQUAL(i.getMinSuffixComponents(), 1);
60 BOOST_REQUIRE_EQUAL(i.getMaxSuffixComponents(), 1);
61 BOOST_REQUIRE_EQUAL(i.getChildSelector(), 1);
62 BOOST_REQUIRE_EQUAL(i.getMustBeFresh(), false);
63 BOOST_REQUIRE_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
64 BOOST_REQUIRE_EQUAL(i.getNonce(), 1);
65}
66
67BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080068
69} // namespace ndn