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