blob: 9e5e01c022a61d74c7ac41add0d82969f75d9739 [file] [log] [blame]
Yingdi Yu27158392014-01-20 13:04:20 -08001/**
2 * Copyright (C) 2013 Regents of the University of California.
Yingdi Yu27158392014-01-20 13:04:20 -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"
Yingdi Yu27158392014-01-20 13:04:20 -08009
10using namespace std;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080011
12namespace ndn {
Yingdi Yu27158392014-01-20 13:04:20 -080013
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()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080067
68} // namespace ndn