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