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 | |
| 9 | #include <ndn-cpp/interest.hpp> |
| 10 | |
| 11 | using namespace std; |
| 12 | using namespace ndn; |
| 13 | |
| 14 | BOOST_AUTO_TEST_SUITE(TestInterest) |
| 15 | |
| 16 | const uint8_t Interest1[] = { |
| 17 | 0x0, 0x41, |
| 18 | 0x2, 0x14, |
| 19 | 0x3, 0x5, 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 20 | 0x3, 0x3, 0x6e, 0x64, 0x6e, |
| 21 | 0x3, 0x6, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 22 | 0x4, 0x1f, |
| 23 | 0x8, 0x1, 0x1, |
| 24 | 0x9, 0x1, 0x1, |
| 25 | 0xb, 0x14, |
| 26 | 0x3, 0x4, 0x61, 0x6c, 0x65, 0x78, |
| 27 | 0x3, 0x4, 0x78, 0x78, 0x78, 0x78, |
| 28 | 0xe, 0x0, |
| 29 | 0x3, 0x4, 0x79, 0x79, 0x79, 0x79, |
| 30 | 0xc, 0x1, 0x1, |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 31 | 0x5, 0x1, 0x1, |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 32 | 0x6, 0x1, 0x1, |
| 33 | 0x7, 0x2, 0x3, 0xe8 |
| 34 | }; |
| 35 | |
| 36 | BOOST_AUTO_TEST_CASE (Decode) |
| 37 | { |
| 38 | Block interestBlock(Interest1, sizeof(Interest1)); |
| 39 | |
| 40 | ndn::Interest i; |
Alexander Afanasyev | 049f8f7 | 2013-12-26 19:07:15 -0800 | [diff] [blame] | 41 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 42 | |
Alexander Afanasyev | 049f8f7 | 2013-12-26 19:07:15 -0800 | [diff] [blame] | 43 | BOOST_REQUIRE_EQUAL(i.getName().toUri(), "/local/ndn/prefix"); |
| 44 | BOOST_REQUIRE_EQUAL(i.getScope(), 1); |
| 45 | BOOST_REQUIRE_EQUAL(i.getInterestLifetime(), 1000); |
| 46 | BOOST_REQUIRE_EQUAL(i.getMinSuffixComponents(), 1); |
| 47 | BOOST_REQUIRE_EQUAL(i.getMaxSuffixComponents(), 1); |
| 48 | BOOST_REQUIRE_EQUAL(i.getChildSelector(), 1); |
| 49 | BOOST_REQUIRE_EQUAL(i.getMustBeFresh(), false); |
| 50 | BOOST_REQUIRE_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy"); |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 51 | BOOST_REQUIRE_EQUAL(i.getNonce(), 1); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | BOOST_AUTO_TEST_CASE (Encode) |
| 55 | { |
| 56 | ndn::Interest i(ndn::Name("/local/ndn/prefix")); |
| 57 | i.setScope(1); |
| 58 | i.setInterestLifetime(1000); |
| 59 | i.setMinSuffixComponents(1); |
| 60 | i.setMaxSuffixComponents(1); |
| 61 | i.setChildSelector(1); |
| 62 | i.setMustBeFresh(false); |
| 63 | i.getExclude().excludeOne("alex").excludeRange("xxxx", "yyyy"); |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 64 | i.setNonce(1); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 65 | |
| 66 | const Block &wire = i.wireEncode(); |
Alexander Afanasyev | 049f8f7 | 2013-12-26 19:07:15 -0800 | [diff] [blame] | 67 | BOOST_REQUIRE_EQUAL_COLLECTIONS(Interest1, Interest1+sizeof(Interest1), |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 68 | wire.begin(), wire.end()); |
| 69 | } |
| 70 | |
| 71 | BOOST_AUTO_TEST_SUITE_END() |