Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 22 | #include "interest.hpp" |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 23 | #include "data.hpp" |
| 24 | #include "security/signature-sha256-with-rsa.hpp" |
Yingdi Yu | bf6a281 | 2014-06-17 15:32:11 -0700 | [diff] [blame] | 25 | #include "security/digest-sha256.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 26 | #include "encoding/buffer-stream.hpp" |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 27 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 28 | #include "boost-test.hpp" |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 29 | |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 30 | namespace ndn { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 31 | namespace tests { |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 32 | |
| 33 | BOOST_AUTO_TEST_SUITE(TestInterest) |
| 34 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 35 | BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Interest>)); |
| 36 | BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Selectors>)); |
| 37 | |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 38 | const uint8_t Interest1[] = { |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 39 | 0x05, 0x5c, // NDN Interest |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 40 | 0x07, 0x14, // Name |
| 41 | 0x08, 0x5, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 42 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 43 | 0x08, 0x3, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 44 | 0x6e, 0x64, 0x6e, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 45 | 0x08, 0x6, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 46 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 47 | 0x09, 0x37, // Selectors |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 48 | 0x0d, 0x1, 0x1, // MinSuffix |
| 49 | 0x0e, 0x1, 0x1, // MaxSuffix |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 50 | 0x1c, 0x16, // KeyLocator |
| 51 | 0x07, 0x14, // Name |
| 52 | 0x08, 0x04, |
| 53 | 0x74, 0x65, 0x73, 0x74, |
| 54 | 0x08, 0x03, |
| 55 | 0x6b, 0x65, 0x79, |
| 56 | 0x08, 0x07, |
| 57 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 58 | 0x10, 0x14, // Exclude |
| 59 | 0x08, 0x4, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 60 | 0x61, 0x6c, 0x65, 0x78, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 61 | 0x08, 0x4, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 62 | 0x78, 0x78, 0x78, 0x78, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 63 | 0x13, 0x0, // Any |
| 64 | 0x08, 0x4, // NameComponent |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 65 | 0x79, 0x79, 0x79, 0x79, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 66 | 0x11, 0x1, // ChildSelector |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 67 | 0x1, |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 68 | 0x0a, 0x4, // Nonce |
| 69 | 0x1, 0x0, 0x0, 0x00, |
| 70 | 0x0b, 0x1, // Scope |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 71 | 0x1, |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 72 | 0x0c, // InterestLifetime |
| 73 | 0x2, 0x3, 0xe8 |
| 74 | }; |
| 75 | |
| 76 | const uint8_t Interest2[] = { |
| 77 | 0x05, 0x5c, // NDN Interest |
| 78 | 0x07, 0x14, // Name |
| 79 | 0x08, 0x5, // NameComponent |
| 80 | 0x6c, 0x6f, 0x63, 0x61, 0x6c, |
| 81 | 0x08, 0x3, // NameComponent |
| 82 | 0x6e, 0x64, 0x6e, |
| 83 | 0x08, 0x6, // NameComponent |
| 84 | 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, |
| 85 | 0x09, 0x37, // Selectors |
| 86 | 0x0d, 0x1, 0x1, // MinSuffix |
| 87 | 0x0e, 0x1, 0x1, // MaxSuffix |
| 88 | 0x1c, 0x16, // KeyLocator |
| 89 | 0x07, 0x14, // Name |
| 90 | 0x08, 0x04, |
| 91 | 0x74, 0x65, 0x73, 0x74, |
| 92 | 0x08, 0x03, |
| 93 | 0x6b, 0x65, 0x79, |
| 94 | 0x08, 0x07, |
| 95 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 96 | 0x10, 0x14, // Exclude |
| 97 | 0x08, 0x4, // NameComponent |
| 98 | 0x61, 0x6c, 0x65, 0x78, |
| 99 | 0x08, 0x4, // NameComponent |
| 100 | 0x78, 0x78, 0x78, 0x78, |
| 101 | 0x13, 0x0, // Any |
| 102 | 0x08, 0x4, // NameComponent |
| 103 | 0x79, 0x79, 0x79, 0x79, |
| 104 | 0x11, 0x1, // ChildSelector |
| 105 | 0x1, |
| 106 | 0x0a, 0x4, // Nonce |
| 107 | 0x2, 0x0, 0x0, 0x00, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 108 | 0x0b, 0x1, // Scope |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 109 | 0x1, |
Alexander Afanasyev | 4b45628 | 2014-02-13 00:34:34 -0800 | [diff] [blame] | 110 | 0x0c, // InterestLifetime |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 111 | 0x2, 0x3, 0xe8 |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 112 | }; |
| 113 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 114 | const uint8_t InterestWithLocalControlHeader[] = { |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 115 | 0x50, 0x25, 0x51, 0x01, 0x0a, |
| 116 | 0x05, 0x20, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64, |
| 117 | 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x04, |
| 118 | 0x01, 0x00, 0x00, 0x00 |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | const uint8_t InterestWithoutLocalControlHeader[] = { |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 122 | 0x05, 0x20, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64, |
| 123 | 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x04, |
| 124 | 0x01, 0x00, 0x00, 0x00 |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 125 | }; |
| 126 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 127 | BOOST_AUTO_TEST_CASE(InterestEqualityChecks) |
| 128 | { |
| 129 | // Interest ::= INTEREST-TYPE TLV-LENGTH |
| 130 | // Name |
| 131 | // Selectors? |
| 132 | // Nonce |
| 133 | // Scope? |
| 134 | // InterestLifetime? |
| 135 | |
| 136 | Interest a; |
| 137 | Interest b; |
| 138 | |
| 139 | // if nonce is not set, it will be set to a random value |
| 140 | a.setNonce(1); |
| 141 | b.setNonce(1); |
| 142 | |
| 143 | BOOST_CHECK_EQUAL(a == b, true); |
| 144 | BOOST_CHECK_EQUAL(a != b, false); |
| 145 | |
| 146 | // check comparison on Name |
| 147 | a.setName("ndn:/A"); |
| 148 | BOOST_CHECK_EQUAL(a == b, false); |
| 149 | BOOST_CHECK_EQUAL(a != b, true); |
| 150 | |
| 151 | b.setName("ndn:/B"); |
| 152 | BOOST_CHECK_EQUAL(a == b, false); |
| 153 | BOOST_CHECK_EQUAL(a != b, true); |
| 154 | |
| 155 | b.setName("ndn:/A"); |
| 156 | BOOST_CHECK_EQUAL(a == b, true); |
| 157 | BOOST_CHECK_EQUAL(a != b, false); |
| 158 | |
| 159 | // check comparison on Selectors |
| 160 | a.setChildSelector(1); |
| 161 | BOOST_CHECK_EQUAL(a == b, false); |
| 162 | BOOST_CHECK_EQUAL(a != b, true); |
| 163 | |
| 164 | b.setChildSelector(1); |
| 165 | BOOST_CHECK_EQUAL(a == b, true); |
| 166 | BOOST_CHECK_EQUAL(a != b, false); |
| 167 | |
| 168 | // check comparison on Nonce |
| 169 | a.setNonce(100); |
| 170 | BOOST_CHECK_EQUAL(a == b, false); |
| 171 | BOOST_CHECK_EQUAL(a != b, true); |
| 172 | |
| 173 | b.setNonce(100); |
| 174 | BOOST_CHECK_EQUAL(a == b, true); |
| 175 | BOOST_CHECK_EQUAL(a != b, false); |
| 176 | |
| 177 | // check comparison on Nonce |
| 178 | a.setScope(1); |
| 179 | BOOST_CHECK_EQUAL(a == b, false); |
| 180 | BOOST_CHECK_EQUAL(a != b, true); |
| 181 | |
| 182 | b.setScope(1); |
| 183 | BOOST_CHECK_EQUAL(a == b, true); |
| 184 | BOOST_CHECK_EQUAL(a != b, false); |
| 185 | |
| 186 | // check comparison on InterestLifetime |
| 187 | a.setInterestLifetime(time::seconds(10)); |
| 188 | BOOST_CHECK_EQUAL(a == b, false); |
| 189 | BOOST_CHECK_EQUAL(a != b, true); |
| 190 | |
| 191 | b.setInterestLifetime(time::seconds(10)); |
| 192 | BOOST_CHECK_EQUAL(a == b, true); |
| 193 | BOOST_CHECK_EQUAL(a != b, false); |
| 194 | } |
| 195 | |
| 196 | BOOST_AUTO_TEST_CASE(SelectorsEqualityChecks) |
| 197 | { |
| 198 | // Selectors ::= SELECTORS-TYPE TLV-LENGTH |
| 199 | // MinSuffixComponents? |
| 200 | // MaxSuffixComponents? |
| 201 | // PublisherPublicKeyLocator? |
| 202 | // Exclude? |
| 203 | // ChildSelector? |
| 204 | // MustBeFresh? |
| 205 | |
| 206 | Selectors a; |
| 207 | Selectors b; |
| 208 | BOOST_CHECK_EQUAL(a == b, true); |
| 209 | BOOST_CHECK_EQUAL(a != b, false); |
| 210 | |
| 211 | // MinSuffixComponents |
| 212 | a.setMinSuffixComponents(1); |
| 213 | BOOST_CHECK_EQUAL(a == b, false); |
| 214 | BOOST_CHECK_EQUAL(a != b, true); |
| 215 | |
| 216 | b.setMinSuffixComponents(2); |
| 217 | BOOST_CHECK_EQUAL(a == b, false); |
| 218 | BOOST_CHECK_EQUAL(a != b, true); |
| 219 | |
| 220 | b.setMinSuffixComponents(1); |
| 221 | BOOST_CHECK_EQUAL(a == b, true); |
| 222 | BOOST_CHECK_EQUAL(a != b, false); |
| 223 | |
| 224 | // MaxSuffixComponents |
| 225 | a.setMaxSuffixComponents(10); |
| 226 | BOOST_CHECK_EQUAL(a == b, false); |
| 227 | BOOST_CHECK_EQUAL(a != b, true); |
| 228 | |
| 229 | b.setMaxSuffixComponents(10); |
| 230 | BOOST_CHECK_EQUAL(a == b, true); |
| 231 | BOOST_CHECK_EQUAL(a != b, false); |
| 232 | |
| 233 | // PublisherPublicKeyLocator |
| 234 | a.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name")); |
| 235 | BOOST_CHECK_EQUAL(a == b, false); |
| 236 | BOOST_CHECK_EQUAL(a != b, true); |
| 237 | |
| 238 | b.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name")); |
| 239 | BOOST_CHECK_EQUAL(a == b, true); |
| 240 | BOOST_CHECK_EQUAL(a != b, false); |
| 241 | |
| 242 | // Exclude |
| 243 | a.setExclude(Exclude().excludeOne(name::Component("exclude"))); |
| 244 | BOOST_CHECK_EQUAL(a == b, false); |
| 245 | BOOST_CHECK_EQUAL(a != b, true); |
| 246 | |
| 247 | b.setExclude(Exclude().excludeOne(name::Component("exclude"))); |
| 248 | BOOST_CHECK_EQUAL(a == b, true); |
| 249 | BOOST_CHECK_EQUAL(a != b, false); |
| 250 | |
| 251 | // ChildSelector |
| 252 | a.setChildSelector(1); |
| 253 | BOOST_CHECK_EQUAL(a == b, false); |
| 254 | BOOST_CHECK_EQUAL(a != b, true); |
| 255 | |
| 256 | b.setChildSelector(1); |
| 257 | BOOST_CHECK_EQUAL(a == b, true); |
| 258 | BOOST_CHECK_EQUAL(a != b, false); |
| 259 | |
| 260 | // MustBeFresh |
| 261 | a.setMustBeFresh(true); |
| 262 | BOOST_CHECK_EQUAL(a == b, false); |
| 263 | BOOST_CHECK_EQUAL(a != b, true); |
| 264 | |
| 265 | b.setMustBeFresh(true); |
| 266 | BOOST_CHECK_EQUAL(a == b, true); |
| 267 | BOOST_CHECK_EQUAL(a != b, false); |
| 268 | } |
| 269 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 270 | BOOST_AUTO_TEST_CASE(Decode) |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 271 | { |
| 272 | Block interestBlock(Interest1, sizeof(Interest1)); |
Alexander Afanasyev | 636e9f1 | 2014-01-07 12:01:03 -0800 | [diff] [blame] | 273 | |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 274 | ndn::Interest i; |
Alexander Afanasyev | 049f8f7 | 2013-12-26 19:07:15 -0800 | [diff] [blame] | 275 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 276 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 277 | BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix"); |
| 278 | BOOST_CHECK_EQUAL(i.getScope(), 1); |
| 279 | BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000)); |
| 280 | BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1); |
| 281 | BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1); |
| 282 | BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getType(), |
| 283 | static_cast<uint32_t>(KeyLocator::KeyLocator_Name)); |
| 284 | BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getName(), "ndn:/test/key/locator"); |
| 285 | BOOST_CHECK_EQUAL(i.getChildSelector(), 1); |
| 286 | BOOST_CHECK_EQUAL(i.getMustBeFresh(), false); |
| 287 | BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy"); |
| 288 | BOOST_CHECK_EQUAL(i.getNonce(), 1U); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 289 | } |
| 290 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 291 | BOOST_AUTO_TEST_CASE(DecodeFromStream) |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 292 | { |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 293 | boost::iostreams::stream<boost::iostreams::array_source> is( |
| 294 | reinterpret_cast<const char *>(Interest1), sizeof(Interest1)); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 295 | |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 296 | Block interestBlock = Block::fromStream(is); |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 297 | |
| 298 | ndn::Interest i; |
| 299 | BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock)); |
| 300 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 301 | BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix"); |
| 302 | BOOST_CHECK_EQUAL(i.getScope(), 1); |
| 303 | BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000)); |
| 304 | BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1); |
| 305 | BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1); |
| 306 | BOOST_CHECK_EQUAL(i.getChildSelector(), 1); |
| 307 | BOOST_CHECK_EQUAL(i.getMustBeFresh(), false); |
| 308 | BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy"); |
| 309 | BOOST_CHECK_EQUAL(i.getNonce(), 1U); |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 312 | BOOST_AUTO_TEST_CASE(Encode) |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 313 | { |
| 314 | ndn::Interest i(ndn::Name("/local/ndn/prefix")); |
| 315 | i.setScope(1); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 316 | i.setInterestLifetime(time::milliseconds(1000)); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 317 | i.setMinSuffixComponents(1); |
| 318 | i.setMaxSuffixComponents(1); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 319 | i.setPublisherPublicKeyLocator(KeyLocator("ndn:/test/key/locator")); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 320 | i.setChildSelector(1); |
| 321 | i.setMustBeFresh(false); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 322 | Exclude exclude; |
| 323 | exclude |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 324 | .excludeOne(name::Component("alex")) |
| 325 | .excludeRange(name::Component("xxxx"), name::Component("yyyy")); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 326 | i.setExclude(exclude); |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 327 | i.setNonce(1); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 328 | |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 329 | BOOST_CHECK_EQUAL(i.hasWire(), false); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 330 | const Block &wire = i.wireEncode(); |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 331 | BOOST_CHECK_EQUAL(i.hasWire(), true); |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 332 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 333 | BOOST_CHECK_EQUAL_COLLECTIONS(Interest1, Interest1 + sizeof(Interest1), |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 334 | wire.begin(), wire.end()); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 335 | |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 336 | const uint8_t* originalWire = wire.wire(); |
| 337 | i.setNonce(2); |
| 338 | BOOST_CHECK_EQUAL(i.hasWire(), true); |
| 339 | BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire()); |
| 340 | BOOST_CHECK_EQUAL(i.hasWire(), true); |
| 341 | |
| 342 | BOOST_CHECK_EQUAL_COLLECTIONS(Interest2, Interest2 + sizeof(Interest2), |
| 343 | wire.begin(), wire.end()); |
Alexander Afanasyev | a0c5f83 | 2014-06-19 13:27:56 -0700 | [diff] [blame] | 344 | |
| 345 | std::ostringstream strStream; |
| 346 | BOOST_CHECK_NO_THROW(strStream << i); |
| 347 | |
| 348 | BOOST_CHECK_EQUAL(strStream.str(), |
| 349 | "/local/ndn/prefix?" |
| 350 | "ndn.MinSuffixComponents=1&ndn.MaxSuffixComponents=1&" |
| 351 | "ndn.ChildSelector=1&ndn.Scope=1&" |
| 352 | "ndn.InterestLifetime=1000&" |
| 353 | "ndn.Nonce=2&ndn.Exclude=alex,xxxx,*,yyyy"); |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 354 | |
| 355 | i.refreshNonce(); |
| 356 | BOOST_CHECK_EQUAL(i.hasWire(), true); |
| 357 | BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire()); |
| 358 | BOOST_CHECK_NE(i.getNonce(), 2); |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 359 | } |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 360 | |
| 361 | BOOST_AUTO_TEST_CASE(EncodeWithLocalHeader) |
| 362 | { |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 363 | ndn::Interest interest(ndn::Name("/local/ndn/prefix")); |
| 364 | interest.setMustBeFresh(true); |
| 365 | interest.setIncomingFaceId(10); |
| 366 | interest.setNonce(1); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 367 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 368 | BOOST_CHECK(!interest.hasWire()); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 369 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 370 | Block headerBlock = interest.getLocalControlHeader().wireEncode(interest, true, true); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 371 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 372 | BOOST_CHECK(interest.hasWire()); |
| 373 | BOOST_CHECK(headerBlock.hasWire()); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 374 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 375 | BOOST_CHECK_NE(headerBlock.wire(), interest.wireEncode().wire()); |
| 376 | BOOST_CHECK_NE(headerBlock.size(), interest.wireEncode().size()); |
| 377 | BOOST_CHECK_EQUAL(headerBlock.size(), 5); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 378 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 379 | BOOST_CHECK_EQUAL_COLLECTIONS(InterestWithLocalControlHeader, |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 380 | InterestWithLocalControlHeader + 5, |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 381 | headerBlock.begin(), headerBlock.end()); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 382 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 383 | interest.setNonce(1000); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 384 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 385 | Block updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true); |
| 386 | BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 387 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 388 | // only length should have changed |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 389 | BOOST_CHECK_EQUAL_COLLECTIONS(updatedHeaderBlock.begin() + 2, updatedHeaderBlock.end(), |
| 390 | headerBlock.begin() + 2, headerBlock.end()); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 391 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 392 | // updating IncomingFaceId that keeps the length |
| 393 | interest.setIncomingFaceId(100); |
| 394 | updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true); |
| 395 | BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 396 | BOOST_CHECK_NE(*(updatedHeaderBlock.begin() + 4), *(headerBlock.begin() + 4)); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 397 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 398 | // updating IncomingFaceId that increases the length by 2 |
| 399 | interest.setIncomingFaceId(1000); |
| 400 | updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true); |
| 401 | BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 402 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 403 | // adding NextHopId |
| 404 | interest.setNextHopFaceId(1); |
| 405 | updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true); |
| 406 | BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 9); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 407 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 408 | // masking IncomingFaceId |
| 409 | updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, false, true); |
| 410 | BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 411 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 412 | // masking NextHopId |
| 413 | updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, false); |
| 414 | BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 415 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 416 | // masking everything |
| 417 | BOOST_CHECK_THROW(interest.getLocalControlHeader().wireEncode(interest, false, false), |
| 418 | nfd::LocalControlHeader::Error); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 421 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 422 | BOOST_AUTO_TEST_CASE(DecodeWithLocalHeader) |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 423 | { |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 424 | Block wireBlock(InterestWithLocalControlHeader, sizeof(InterestWithLocalControlHeader)); |
| 425 | const Block& payload = nfd::LocalControlHeader::getPayload(wireBlock); |
| 426 | BOOST_REQUIRE_NE(&payload, &wireBlock); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 427 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 428 | BOOST_CHECK_EQUAL(payload.type(), static_cast<uint32_t>(tlv::Interest)); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 429 | BOOST_CHECK_EQUAL(wireBlock.type(), static_cast<uint32_t>(tlv::nfd::LocalControlHeader)); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 430 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 431 | Interest interest(payload); |
| 432 | BOOST_CHECK(!interest.getLocalControlHeader().hasIncomingFaceId()); |
| 433 | BOOST_CHECK(!interest.getLocalControlHeader().hasNextHopFaceId()); |
| 434 | |
| 435 | BOOST_REQUIRE_NO_THROW(interest.getLocalControlHeader().wireDecode(wireBlock)); |
| 436 | |
| 437 | BOOST_CHECK_EQUAL(interest.getLocalControlHeader().wireEncode(interest, true, true).size(), 5); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 438 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 439 | BOOST_CHECK_EQUAL(interest.getIncomingFaceId(), 10); |
| 440 | BOOST_CHECK(!interest.getLocalControlHeader().hasNextHopFaceId()); |
| 441 | |
| 442 | BOOST_CHECK_THROW(interest.getLocalControlHeader().wireEncode(interest, false, false), |
| 443 | nfd::LocalControlHeader::Error); |
| 444 | |
| 445 | BOOST_CHECK_THROW(interest.getLocalControlHeader().wireEncode(interest, false, true), |
| 446 | nfd::LocalControlHeader::Error); |
| 447 | |
| 448 | BOOST_CHECK_NO_THROW(interest.getLocalControlHeader().wireEncode(interest, true, false)); |
| 449 | BOOST_CHECK_NO_THROW(interest.getLocalControlHeader().wireEncode(interest, true, true)); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 450 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 451 | BOOST_CHECK_NE((void*)interest.getLocalControlHeader().wireEncode(interest, true, true).wire(), |
| 452 | (void*)wireBlock.wire()); |
| 453 | |
| 454 | BOOST_CHECK_EQUAL(interest.getLocalControlHeader().wireEncode(interest, true, true).size(), 5); |
| 455 | } |
| 456 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 457 | BOOST_AUTO_TEST_CASE(DecodeWithoutLocalHeader) |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 458 | { |
| 459 | Block wireBlock(InterestWithoutLocalControlHeader, sizeof(InterestWithoutLocalControlHeader)); |
| 460 | const Block& payload = nfd::LocalControlHeader::getPayload(wireBlock); |
| 461 | BOOST_CHECK_EQUAL(&payload, &wireBlock); |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 462 | } |
| 463 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 464 | BOOST_AUTO_TEST_CASE(MatchesData) |
| 465 | { |
| 466 | Interest interest; |
| 467 | interest.setName("ndn:/A") |
| 468 | .setMinSuffixComponents(2) |
| 469 | .setMaxSuffixComponents(2) |
| 470 | .setPublisherPublicKeyLocator(KeyLocator("ndn:/B")) |
| 471 | .setExclude(Exclude().excludeBefore(name::Component("C"))); |
| 472 | |
| 473 | Data data("ndn:/A/D"); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 474 | SignatureSha256WithRsa signature(KeyLocator("ndn:/B")); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 475 | data.setSignature(signature); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 476 | data.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 477 | BOOST_CHECK_EQUAL(interest.matchesData(data), true); |
| 478 | |
| 479 | Data data1 = data; |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 480 | data1.setName("ndn:/A"); // violates MinSuffixComponents |
| 481 | data1.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 482 | BOOST_CHECK_EQUAL(interest.matchesData(data1), false); |
| 483 | |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 484 | interest.setMinSuffixComponents(1); |
| 485 | BOOST_CHECK_EQUAL(interest.matchesData(data1), true); |
| 486 | interest.setMinSuffixComponents(2); |
| 487 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 488 | Data data2 = data; |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 489 | data2.setName("ndn:/A/E/F"); // violates MaxSuffixComponents |
| 490 | data2.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 491 | BOOST_CHECK_EQUAL(interest.matchesData(data2), false); |
| 492 | |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 493 | interest.setMaxSuffixComponents(3); |
| 494 | BOOST_CHECK_EQUAL(interest.matchesData(data2), true); |
| 495 | interest.setMaxSuffixComponents(2); |
| 496 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 497 | Data data3 = data; |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 498 | SignatureSha256WithRsa signature3(KeyLocator("ndn:/G")); // violates PublisherPublicKeyLocator |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 499 | data3.setSignature(signature3); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 500 | data3.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 501 | BOOST_CHECK_EQUAL(interest.matchesData(data3), false); |
| 502 | |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 503 | interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/G")); |
| 504 | BOOST_CHECK_EQUAL(interest.matchesData(data3), true); |
| 505 | interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/B")); |
| 506 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 507 | Data data4 = data; |
Yingdi Yu | bf6a281 | 2014-06-17 15:32:11 -0700 | [diff] [blame] | 508 | DigestSha256 signature4; // violates PublisherPublicKeyLocator |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 509 | data4.setSignature(signature4); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 510 | data4.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 511 | BOOST_CHECK_EQUAL(interest.matchesData(data4), false); |
| 512 | |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 513 | interest.setPublisherPublicKeyLocator(KeyLocator()); |
| 514 | BOOST_CHECK_EQUAL(interest.matchesData(data4), true); |
| 515 | interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/B")); |
| 516 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 517 | Data data5 = data; |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 518 | data5.setName("ndn:/A/C"); // violates Exclude |
| 519 | data5.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 520 | BOOST_CHECK_EQUAL(interest.matchesData(data5), false); |
| 521 | |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 522 | interest.setExclude(Exclude().excludeBefore(name::Component("A"))); |
| 523 | BOOST_CHECK_EQUAL(interest.matchesData(data5), true); |
| 524 | interest.setExclude(Exclude().excludeBefore(name::Component("C"))); |
| 525 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 526 | Data data6 = data; |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 527 | data6.setName("ndn:/H/I"); // violates Name |
| 528 | data6.wireEncode(); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 529 | BOOST_CHECK_EQUAL(interest.matchesData(data6), false); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 530 | |
| 531 | Data data7 = data; |
| 532 | data7.setName("ndn:/A/B"); |
| 533 | data7.wireEncode(); |
| 534 | |
| 535 | interest = Interest() |
| 536 | .setName("/A/B/%D5H%DE%CE%FCK%88%07%20%DC%92W%A8%D8%15%E9%DFDe%E67B%EEU%C2%913%05%5D%AAg%C2"); |
| 537 | BOOST_CHECK_EQUAL(interest.matchesData(data7), true); |
| 538 | |
| 539 | interest = Interest() |
| 540 | .setName("/A/B/%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00" |
| 541 | "%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00"); |
| 542 | BOOST_CHECK_EQUAL(interest.matchesData(data7), false); // violates implicit digest |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 545 | |
| 546 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 547 | BOOST_AUTO_TEST_CASE(InterestFilterMatching) |
| 548 | { |
| 549 | BOOST_CHECK_EQUAL(InterestFilter("/a").doesMatch("/a/b"), true); |
| 550 | BOOST_CHECK_EQUAL(InterestFilter("/a/b").doesMatch("/a/b"), true); |
| 551 | BOOST_CHECK_EQUAL(InterestFilter("/a/b/c").doesMatch("/a/b"), false); |
| 552 | |
| 553 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b"), true); |
| 554 | BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b"), false); |
| 555 | |
| 556 | BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b/c/b"), false); |
| 557 | BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<>*<b>").doesMatch("/a/b/c/b"), true); |
| 558 | |
| 559 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b/c/d"), false); |
| 560 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b/c/d"), true); |
| 561 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b"), true); |
| 562 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b"), false); |
| 563 | BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b/c"), true); |
| 564 | } |
| 565 | |
Alexander Afanasyev | 5fa9e9a | 2013-12-24 19:45:07 -0800 | [diff] [blame] | 566 | BOOST_AUTO_TEST_SUITE_END() |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 567 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 568 | } // namespace tests |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 569 | } // namespace ndn |