Yingdi Yu | 2715839 | 2014-01-20 13:04:20 -0800 | [diff] [blame] | 1 | /** |
| 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 Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 9 | #include "interest.hpp" |
Yingdi Yu | 2715839 | 2014-01-20 13:04:20 -0800 | [diff] [blame] | 10 | |
| 11 | using namespace std; |
| 12 | using namespace ndn; |
| 13 | |
| 14 | BOOST_AUTO_TEST_SUITE(TestBlock) |
| 15 | |
| 16 | const 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 | |
| 46 | BOOST_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 | |
| 66 | BOOST_AUTO_TEST_SUITE_END() |