Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -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" |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 10 | |
| 11 | using namespace std; |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame^] | 12 | namespace ndn { |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 13 | |
| 14 | BOOST_AUTO_TEST_SUITE(TestInterest) |
| 15 | |
| 16 | const uint8_t Interest1[] = { |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 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 |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | BOOST_AUTO_TEST_CASE (Decode) |
| 47 | { |
| 48 | Block interestBlock(Interest1, sizeof(Interest1)); |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 49 | |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 50 | ndn::Interest i; |
Alexander Afanasyev | 049f8f7 | 2013-12-26 19:07:15 -0800 | [diff] [blame] | 51 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 52 | |
Alexander Afanasyev | 049f8f7 | 2013-12-26 19:07:15 -0800 | [diff] [blame] | 53 | BOOST_REQUIRE_EQUAL(i.getName().toUri(), "/local/ndn/prefix"); |
| 54 | BOOST_REQUIRE_EQUAL(i.getScope(), 1); |
| 55 | BOOST_REQUIRE_EQUAL(i.getInterestLifetime(), 1000); |
| 56 | BOOST_REQUIRE_EQUAL(i.getMinSuffixComponents(), 1); |
| 57 | BOOST_REQUIRE_EQUAL(i.getMaxSuffixComponents(), 1); |
| 58 | BOOST_REQUIRE_EQUAL(i.getChildSelector(), 1); |
| 59 | BOOST_REQUIRE_EQUAL(i.getMustBeFresh(), false); |
| 60 | BOOST_REQUIRE_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy"); |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 61 | BOOST_REQUIRE_EQUAL(i.getNonce(), 1); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | BOOST_AUTO_TEST_CASE (Encode) |
| 65 | { |
| 66 | ndn::Interest i(ndn::Name("/local/ndn/prefix")); |
| 67 | i.setScope(1); |
| 68 | i.setInterestLifetime(1000); |
| 69 | i.setMinSuffixComponents(1); |
| 70 | i.setMaxSuffixComponents(1); |
| 71 | i.setChildSelector(1); |
| 72 | i.setMustBeFresh(false); |
| 73 | i.getExclude().excludeOne("alex").excludeRange("xxxx", "yyyy"); |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 74 | i.setNonce(1); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 75 | |
| 76 | const Block &wire = i.wireEncode(); |
Alexander Afanasyev | 049f8f7 | 2013-12-26 19:07:15 -0800 | [diff] [blame] | 77 | BOOST_REQUIRE_EQUAL_COLLECTIONS(Interest1, Interest1+sizeof(Interest1), |
Alexander Afanasyev | 84c2bd4 | 2014-01-09 22:35:35 -0800 | [diff] [blame] | 78 | wire.begin(), wire.end()); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | BOOST_AUTO_TEST_SUITE_END() |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame^] | 82 | |
| 83 | } // namespace ndn |