Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 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. |
| 20 | */ |
| 21 | |
| 22 | #include "util/in-memory-storage-persistent.hpp" |
| 23 | #include "util/in-memory-storage-fifo.hpp" |
| 24 | #include "util/in-memory-storage-lfu.hpp" |
| 25 | #include "util/in-memory-storage-lru.hpp" |
| 26 | #include "security/key-chain.hpp" |
| 27 | |
| 28 | #include "boost-test.hpp" |
| 29 | #include "../test-make-interest-data.hpp" |
| 30 | |
| 31 | #include <boost/mpl/list.hpp> |
| 32 | |
| 33 | namespace ndn { |
| 34 | namespace util { |
| 35 | |
Alexander Afanasyev | 3ccc6f7 | 2014-10-12 12:19:09 -0700 | [diff] [blame^] | 36 | BOOST_AUTO_TEST_SUITE(UtilInMemoryStorage) |
| 37 | |
| 38 | BOOST_AUTO_TEST_SUITE(Common) |
| 39 | |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 40 | typedef boost::mpl::list<InMemoryStoragePersistent, InMemoryStorageFifo, InMemoryStorageLfu, |
| 41 | InMemoryStorageLru> InMemoryStorages; |
| 42 | |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 43 | BOOST_AUTO_TEST_CASE_TEMPLATE(Insertion, T, InMemoryStorages) |
| 44 | { |
| 45 | T ims; |
| 46 | |
| 47 | ims.insert(*makeData("/insertion")); |
| 48 | } |
| 49 | |
| 50 | BOOST_AUTO_TEST_CASE_TEMPLATE(Insertion2, T, InMemoryStorages) |
| 51 | { |
| 52 | T ims; |
| 53 | |
| 54 | ims.insert(*makeData("/a")); |
| 55 | ims.insert(*makeData("/b")); |
| 56 | ims.insert(*makeData("/c")); |
| 57 | ims.insert(*makeData("/d")); |
| 58 | |
| 59 | BOOST_CHECK_EQUAL(ims.size(), 4); |
| 60 | } |
| 61 | |
| 62 | BOOST_AUTO_TEST_CASE_TEMPLATE(Insertion3, T, InMemoryStorages) |
| 63 | { |
| 64 | T ims; |
| 65 | |
| 66 | Name name("/a"); |
| 67 | |
| 68 | uint32_t content1 = 1; |
| 69 | shared_ptr<Data> data1 = makeData(name); |
| 70 | data1->setFreshnessPeriod(time::milliseconds(99999)); |
| 71 | data1->setContent(reinterpret_cast<const uint8_t*>(&content1), sizeof(content1)); |
| 72 | signData(data1); |
| 73 | ims.insert(*data1); |
| 74 | |
| 75 | uint32_t content2 = 2; |
| 76 | shared_ptr<Data> data2 = makeData(name); |
| 77 | data2->setFreshnessPeriod(time::milliseconds(99999)); |
| 78 | data2->setContent(reinterpret_cast<const uint8_t*>(&content2), sizeof(content2)); |
| 79 | signData(data2); |
| 80 | ims.insert(*data2); |
| 81 | |
| 82 | BOOST_CHECK_EQUAL(ims.size(), 2); |
| 83 | } |
| 84 | |
| 85 | BOOST_AUTO_TEST_CASE_TEMPLATE(DuplicateInsertion, T, InMemoryStorages) |
| 86 | { |
| 87 | T ims; |
| 88 | |
| 89 | shared_ptr<Data> data0 = makeData("/insert/smth"); |
| 90 | ims.insert(*data0); |
| 91 | |
| 92 | shared_ptr<Data> data = makeData("/insert/duplicate"); |
| 93 | ims.insert(*data); |
| 94 | |
| 95 | ims.insert(*data); |
| 96 | BOOST_CHECK_EQUAL(ims.size(), 2); |
| 97 | } |
| 98 | |
| 99 | BOOST_AUTO_TEST_CASE_TEMPLATE(DuplicateInsertion2, T, InMemoryStorages) |
| 100 | { |
| 101 | T ims; |
| 102 | |
| 103 | shared_ptr<Data> data = makeData("/insert/duplicate"); |
| 104 | ims.insert(*data); |
| 105 | |
| 106 | ims.insert(*data); |
| 107 | BOOST_CHECK_EQUAL(ims.size(), 1); |
| 108 | |
| 109 | shared_ptr<Data> data2 = makeData("/insert/original"); |
| 110 | ims.insert(*data2); |
| 111 | BOOST_CHECK_EQUAL(ims.size(), 2); |
| 112 | } |
| 113 | |
| 114 | BOOST_AUTO_TEST_CASE_TEMPLATE(InsertAndFind, T, InMemoryStorages) |
| 115 | { |
| 116 | T ims; |
| 117 | |
| 118 | Name name("/insert/and/find"); |
| 119 | |
| 120 | shared_ptr<Data> data = makeData(name); |
| 121 | ims.insert(*data); |
| 122 | |
| 123 | shared_ptr<Interest> interest = makeInterest(name); |
| 124 | |
| 125 | shared_ptr<const Data> found = ims.find(*interest); |
| 126 | |
| 127 | BOOST_CHECK(static_cast<bool>(found)); |
| 128 | BOOST_CHECK_EQUAL(data->getName(), found->getName()); |
| 129 | } |
| 130 | |
| 131 | BOOST_AUTO_TEST_CASE_TEMPLATE(InsertAndNotFind, T, InMemoryStorages) |
| 132 | { |
| 133 | T ims; |
| 134 | |
| 135 | Name name("/insert/and/find"); |
| 136 | shared_ptr<Data> data = makeData(name); |
| 137 | ims.insert(*data); |
| 138 | |
| 139 | Name name2("/not/find"); |
| 140 | shared_ptr<Interest> interest = makeInterest(name2); |
| 141 | |
| 142 | shared_ptr<const Data> found = ims.find(*interest); |
| 143 | |
| 144 | BOOST_CHECK_EQUAL(found.get(), static_cast<const Data*>(0)); |
| 145 | } |
| 146 | |
| 147 | BOOST_AUTO_TEST_CASE_TEMPLATE(InsertAndFindByName, T, InMemoryStorages) |
| 148 | { |
| 149 | T ims; |
| 150 | |
| 151 | Name name("/insert/and/find"); |
| 152 | |
| 153 | shared_ptr<Data> data = makeData(name); |
| 154 | ims.insert(*data); |
| 155 | |
| 156 | shared_ptr<const Data> found = ims.find(name); |
| 157 | |
| 158 | BOOST_CHECK(static_cast<bool>(found)); |
| 159 | BOOST_CHECK_EQUAL(data->getName(), found->getName()); |
| 160 | } |
| 161 | |
| 162 | BOOST_AUTO_TEST_CASE_TEMPLATE(InsertAndFindByFullName, T, InMemoryStorages) |
| 163 | { |
| 164 | T ims; |
| 165 | |
| 166 | Name name("/insert/and/find"); |
| 167 | |
| 168 | shared_ptr<Data> data = makeData(name); |
| 169 | ims.insert(*data); |
| 170 | |
| 171 | shared_ptr<const Data> found = ims.find(data->getFullName()); |
| 172 | |
| 173 | BOOST_CHECK(static_cast<bool>(found)); |
| 174 | BOOST_CHECK_EQUAL(data->getFullName(), found->getFullName()); |
| 175 | } |
| 176 | |
| 177 | BOOST_AUTO_TEST_CASE_TEMPLATE(InsertAndNotFindByName, T, InMemoryStorages) |
| 178 | { |
| 179 | T ims; |
| 180 | |
| 181 | Name name("/insert/and/find"); |
| 182 | shared_ptr<Data> data = makeData(name); |
| 183 | ims.insert(*data); |
| 184 | |
| 185 | Name name2("/not/find"); |
| 186 | |
| 187 | shared_ptr<const Data> found = ims.find(name2); |
| 188 | |
| 189 | BOOST_CHECK(!static_cast<bool>(found)); |
| 190 | } |
| 191 | |
| 192 | BOOST_AUTO_TEST_CASE_TEMPLATE(InsertAndNotFindByFullName, T, InMemoryStorages) |
| 193 | { |
| 194 | T ims; |
| 195 | |
| 196 | Name name("/a"); |
| 197 | uint32_t content1 = 1; |
| 198 | shared_ptr<Data> data1 = makeData(name); |
| 199 | data1->setContent(reinterpret_cast<const uint8_t*>(&content1), sizeof(content1)); |
| 200 | signData(data1); |
| 201 | ims.insert(*data1); |
| 202 | |
| 203 | uint32_t content2 = 2; |
| 204 | shared_ptr<Data> data2 = makeData(name); |
| 205 | data2->setContent(reinterpret_cast<const uint8_t*>(&content2), sizeof(content2)); |
| 206 | signData(data2); |
| 207 | |
| 208 | shared_ptr<const Data> found = ims.find(data2->getFullName()); |
| 209 | |
| 210 | BOOST_CHECK(!static_cast<bool>(found)); |
| 211 | } |
| 212 | |
| 213 | BOOST_AUTO_TEST_CASE_TEMPLATE(InsertAndEraseByName, T, InMemoryStorages) |
| 214 | { |
| 215 | T ims; |
| 216 | |
| 217 | Name name("/insertandremovebyname"); |
| 218 | |
| 219 | uint32_t content1 = 1; |
| 220 | shared_ptr<Data> data1 = makeData(name); |
| 221 | data1->setFreshnessPeriod(time::milliseconds(99999)); |
| 222 | data1->setContent(reinterpret_cast<const uint8_t*>(&content1), sizeof(content1)); |
| 223 | signData(data1); |
| 224 | ims.insert(*data1); |
| 225 | |
| 226 | uint32_t content2 = 2; |
| 227 | shared_ptr<Data> data2 = makeData(name); |
| 228 | data2->setFreshnessPeriod(time::milliseconds(99999)); |
| 229 | data2->setContent(reinterpret_cast<const uint8_t*>(&content2), sizeof(content2)); |
| 230 | signData(data2); |
| 231 | ims.insert(*data2); |
| 232 | |
| 233 | shared_ptr<Data> data3 = makeData("/insertandremovebyname/1"); |
| 234 | ims.insert(*data3); |
| 235 | |
| 236 | shared_ptr<Data> data4 = makeData("/insertandremovebyname/2"); |
| 237 | ims.insert(*data4); |
| 238 | |
| 239 | BOOST_CHECK_EQUAL(ims.size(), 4); |
| 240 | |
| 241 | ims.erase(data1->getFullName(), false); |
| 242 | BOOST_CHECK_EQUAL(ims.size(), 3); |
| 243 | } |
| 244 | |
| 245 | BOOST_AUTO_TEST_CASE_TEMPLATE(InsertAndEraseByPrefix, T, InMemoryStorages) |
| 246 | { |
| 247 | T ims; |
| 248 | |
| 249 | shared_ptr<Data> data = makeData("/a"); |
| 250 | ims.insert(*data); |
| 251 | |
| 252 | shared_ptr<Data> data2 = makeData("/b"); |
| 253 | ims.insert(*data2); |
| 254 | |
| 255 | shared_ptr<Data> data3 = makeData("/c"); |
| 256 | ims.insert(*data3); |
| 257 | |
| 258 | shared_ptr<Data> data4 = makeData("/d"); |
| 259 | ims.insert(*data4); |
| 260 | |
| 261 | shared_ptr<Data> data5 = makeData("/c/c/1/2/3/4/5/6"); |
| 262 | ims.insert(*data5); |
| 263 | |
| 264 | shared_ptr<Data> data6 = makeData("/c/c/1/2/3"); |
| 265 | ims.insert(*data6); |
| 266 | |
| 267 | shared_ptr<Data> data7 = makeData("/c/c/1"); |
| 268 | ims.insert(*data7); |
| 269 | |
| 270 | BOOST_CHECK_EQUAL(ims.size(), 7); |
| 271 | |
| 272 | Name name("/c"); |
| 273 | ims.erase(name); |
| 274 | BOOST_CHECK_EQUAL(ims.size(), 3); |
| 275 | BOOST_CHECK_EQUAL(ims.getCapacity(), 5); |
| 276 | } |
| 277 | |
| 278 | BOOST_AUTO_TEST_CASE_TEMPLATE(DigestCalculation, T, InMemoryStorages) |
| 279 | { |
| 280 | shared_ptr<Data> data = makeData("/digest/compute"); |
| 281 | |
| 282 | ndn::ConstBufferPtr digest1 = ndn::crypto::sha256(data->wireEncode().wire(), |
| 283 | data->wireEncode().size()); |
| 284 | BOOST_CHECK_EQUAL(digest1->size(), 32); |
| 285 | |
| 286 | InMemoryStorageEntry* entry = new InMemoryStorageEntry(); |
| 287 | entry->setData(*data); |
| 288 | |
| 289 | BOOST_CHECK_EQUAL_COLLECTIONS(digest1->begin(), digest1->end(), |
| 290 | entry->getFullName()[-1].value_begin(), |
| 291 | entry->getFullName()[-1].value_end()); |
| 292 | } |
| 293 | |
| 294 | BOOST_AUTO_TEST_CASE_TEMPLATE(Iterator, T, InMemoryStorages) |
| 295 | { |
| 296 | T ims; |
| 297 | |
| 298 | BOOST_CONCEPT_ASSERT((boost::InputIterator<InMemoryStorage::const_iterator>)); |
| 299 | |
| 300 | for (int i = 0; i < 10; i++) { |
| 301 | std::ostringstream convert; |
| 302 | convert << i; |
| 303 | Name name("/" + convert.str()); |
| 304 | shared_ptr<Data> data = makeData(name); |
| 305 | ims.insert(*data); |
| 306 | } |
| 307 | |
| 308 | InMemoryStorage::const_iterator it = ims.begin(); |
| 309 | InMemoryStorage::const_iterator tmp1 = it; |
| 310 | BOOST_REQUIRE(tmp1 == it); |
| 311 | InMemoryStorage::const_iterator tmp2 = tmp1++; |
| 312 | BOOST_REQUIRE(tmp2 != tmp1); |
| 313 | tmp2 = ++tmp1; |
| 314 | BOOST_REQUIRE(tmp2 == tmp1); |
| 315 | |
| 316 | int i = 0; |
| 317 | for (;it != ims.end(); it++) { |
| 318 | std::ostringstream convert; |
| 319 | convert << i; |
| 320 | Name name("/" + convert.str()); |
| 321 | BOOST_CHECK_EQUAL(it->getName(), name); |
| 322 | BOOST_CHECK_EQUAL((*it).getName(), name); |
| 323 | i++; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | BOOST_AUTO_TEST_CASE_TEMPLATE(InsertCanonical, T, InMemoryStorages) |
| 328 | { |
| 329 | T ims; |
| 330 | |
| 331 | shared_ptr<Data> data = makeData("/a"); |
| 332 | ims.insert(*data); |
| 333 | |
| 334 | shared_ptr<Data> data2 = makeData("/b"); |
| 335 | ims.insert(*data2); |
| 336 | |
| 337 | shared_ptr<Data> data3 = makeData("/c"); |
| 338 | ims.insert(*data3); |
| 339 | |
| 340 | shared_ptr<Data> data4 = makeData("/d"); |
| 341 | ims.insert(*data4); |
| 342 | |
| 343 | shared_ptr<Data> data5 = makeData("/c/c/1/2/3/4/5/6"); |
| 344 | ims.insert(*data5); |
| 345 | |
| 346 | shared_ptr<Data> data6 = makeData("/c/c/1/2/3"); |
| 347 | ims.insert(*data6); |
| 348 | |
| 349 | shared_ptr<Data> data7 = makeData("/c/c/1"); |
| 350 | ims.insert(*data7); |
| 351 | } |
| 352 | |
| 353 | BOOST_AUTO_TEST_CASE_TEMPLATE(EraseCanonical, T, InMemoryStorages) |
| 354 | { |
| 355 | T ims; |
| 356 | |
| 357 | shared_ptr<Data> data = makeData("/a"); |
| 358 | ims.insert(*data); |
| 359 | |
| 360 | shared_ptr<Data> data2 = makeData("/b"); |
| 361 | ims.insert(*data2); |
| 362 | |
| 363 | shared_ptr<Data> data3 = makeData("/c"); |
| 364 | ims.insert(*data3); |
| 365 | |
| 366 | shared_ptr<Data> data4 = makeData("/d"); |
| 367 | ims.insert(*data4); |
| 368 | |
| 369 | shared_ptr<Data> data5 = makeData("/c/c/1/2/3/4/5/6"); |
| 370 | ims.insert(*data5); |
| 371 | |
| 372 | shared_ptr<Data> data6 = makeData("/c/c/1/2/3"); |
| 373 | ims.insert(*data6); |
| 374 | |
| 375 | shared_ptr<Data> data7 = makeData("/c/c/1"); |
| 376 | ims.insert(*data7); |
| 377 | |
| 378 | ndn::ConstBufferPtr digest1 = ndn::crypto::sha256(data->wireEncode().wire(), |
| 379 | data->wireEncode().size()); |
| 380 | |
| 381 | Name name("/a"); |
| 382 | ims.erase(name); |
| 383 | BOOST_CHECK_EQUAL(ims.size(), 6); |
| 384 | } |
| 385 | |
| 386 | BOOST_AUTO_TEST_CASE_TEMPLATE(ImplicitDigestSelector, T, InMemoryStorages) |
| 387 | { |
| 388 | T ims; |
| 389 | |
| 390 | Name name("/digest/works"); |
| 391 | shared_ptr<Data> data = makeData(name); |
| 392 | ims.insert(*data); |
| 393 | |
| 394 | shared_ptr<Data> data2 = makeData("/a"); |
| 395 | ims.insert(*data2); |
| 396 | |
| 397 | shared_ptr<Data> data3 = makeData("/z/z/z"); |
| 398 | ims.insert(*data3); |
| 399 | |
| 400 | ndn::ConstBufferPtr digest1 = ndn::crypto::sha256(data->wireEncode().wire(), |
| 401 | data->wireEncode().size()); |
| 402 | uint8_t digest2[32] = {0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 403 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}; |
| 404 | |
| 405 | shared_ptr<Interest> interest = makeInterest(""); |
| 406 | interest->setName(Name(name).append(digest1->buf(), digest1->size())); |
| 407 | interest->setMinSuffixComponents(0); |
| 408 | interest->setMaxSuffixComponents(0); |
| 409 | |
| 410 | shared_ptr<const Data> found = ims.find(*interest); |
| 411 | BOOST_CHECK(static_cast<bool>(found)); |
| 412 | BOOST_CHECK_EQUAL(found->getName(), name); |
| 413 | |
| 414 | shared_ptr<Interest> interest2 = makeInterest(""); |
| 415 | interest2->setName(Name(name).append(digest2, 32)); |
| 416 | interest2->setMinSuffixComponents(0); |
| 417 | interest2->setMaxSuffixComponents(0); |
| 418 | |
| 419 | shared_ptr<const Data> notfound = ims.find(*interest2); |
| 420 | BOOST_CHECK(static_cast<bool>(found)); |
| 421 | } |
| 422 | |
| 423 | BOOST_AUTO_TEST_CASE_TEMPLATE(ChildSelector, T, InMemoryStorages) |
| 424 | { |
| 425 | T ims; |
| 426 | |
| 427 | shared_ptr<Data> data = makeData("/a"); |
| 428 | ims.insert(*data); |
| 429 | |
| 430 | shared_ptr<Data> data2 = makeData("/b"); |
| 431 | ims.insert(*data2); |
| 432 | |
| 433 | shared_ptr<Data> data4 = makeData("/d"); |
| 434 | ims.insert(*data4); |
| 435 | |
| 436 | shared_ptr<Data> data5 = makeData("/c/c"); |
| 437 | ims.insert(*data5); |
| 438 | |
| 439 | shared_ptr<Data> data6 = makeData("/c/f"); |
| 440 | ims.insert(*data6); |
| 441 | |
| 442 | shared_ptr<Data> data7 = makeData("/c/n"); |
| 443 | ims.insert(*data7); |
| 444 | |
| 445 | shared_ptr<Interest> interest = makeInterest("/c"); |
| 446 | interest->setChildSelector(1); |
| 447 | |
| 448 | shared_ptr<const Data> found = ims.find(*interest); |
| 449 | BOOST_CHECK_EQUAL(found->getName(), "/c/n"); |
| 450 | |
| 451 | shared_ptr<Interest> interest2 = makeInterest("/c"); |
| 452 | interest2->setChildSelector(0); |
| 453 | |
| 454 | shared_ptr<const Data> found2 = ims.find(*interest2); |
| 455 | BOOST_CHECK_EQUAL(found2->getName(), "/c/c"); |
| 456 | } |
| 457 | |
| 458 | BOOST_AUTO_TEST_CASE_TEMPLATE(ChildSelector2, T, InMemoryStorages) |
| 459 | { |
| 460 | T ims; |
| 461 | |
| 462 | shared_ptr<Data> data = makeData("/a/b/1"); |
| 463 | ims.insert(*data); |
| 464 | |
| 465 | shared_ptr<Data> data2 = makeData("/a/b/2"); |
| 466 | ims.insert(*data2); |
| 467 | |
| 468 | shared_ptr<Data> data3 = makeData("/a/z/1"); |
| 469 | ims.insert(*data3); |
| 470 | |
| 471 | shared_ptr<Data> data4 = makeData("/a/z/2"); |
| 472 | ims.insert(*data4); |
| 473 | |
| 474 | shared_ptr<Interest> interest = makeInterest("/a"); |
| 475 | interest->setChildSelector(1); |
| 476 | |
| 477 | shared_ptr<const Data> found = ims.find(*interest); |
| 478 | BOOST_CHECK_EQUAL(found->getName(), "/a/z/1"); |
| 479 | } |
| 480 | |
| 481 | BOOST_AUTO_TEST_CASE_TEMPLATE(PublisherKeySelector, T, InMemoryStorages) |
| 482 | { |
| 483 | T ims; |
| 484 | |
| 485 | Name name("/insert/withkey"); |
| 486 | shared_ptr<Data> data = makeData(name); |
| 487 | ims.insert(*data); |
| 488 | |
| 489 | shared_ptr<Interest> interest = makeInterest(name); |
| 490 | Name keyName("/somewhere/key"); |
| 491 | |
| 492 | ndn::KeyLocator locator(keyName); |
| 493 | interest->setPublisherPublicKeyLocator(locator); |
| 494 | |
| 495 | shared_ptr<const Data> found = ims.find(*interest); |
| 496 | BOOST_CHECK(!static_cast<bool>(found)); |
| 497 | } |
| 498 | |
| 499 | BOOST_AUTO_TEST_CASE_TEMPLATE(PublisherKeySelector2, T, InMemoryStorages) |
| 500 | { |
| 501 | T ims; |
| 502 | Name name("/insert/withkey"); |
| 503 | shared_ptr<Data> data = makeData(name); |
| 504 | ims.insert(*data); |
| 505 | |
| 506 | Name name2("/insert/withkey2"); |
| 507 | shared_ptr<Data> data2 = make_shared<Data>(name2); |
| 508 | |
| 509 | Name keyName("/somewhere/key"); |
| 510 | const ndn::KeyLocator locator(keyName); |
| 511 | |
| 512 | ndn::SignatureSha256WithRsa fakeSignature; |
| 513 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 514 | reinterpret_cast<const uint8_t*>(0), 0)); |
| 515 | |
| 516 | fakeSignature.setKeyLocator(locator); |
| 517 | data2->setSignature(fakeSignature); |
| 518 | data2->wireEncode(); |
| 519 | |
| 520 | ims.insert(*data2); |
| 521 | |
| 522 | shared_ptr<Interest> interest = makeInterest(name2); |
| 523 | interest->setPublisherPublicKeyLocator(locator); |
| 524 | |
| 525 | shared_ptr<const Data> found = ims.find(*interest); |
| 526 | BOOST_CHECK(static_cast<bool>(found)); |
| 527 | BOOST_CHECK_EQUAL(found->getName(), data2->getName()); |
| 528 | } |
| 529 | |
| 530 | BOOST_AUTO_TEST_CASE_TEMPLATE(MinMaxComponentsSelector, T, InMemoryStorages) |
| 531 | { |
| 532 | T ims; |
| 533 | |
| 534 | shared_ptr<Data> data = makeData("/a"); |
| 535 | ims.insert(*data); |
| 536 | |
| 537 | shared_ptr<Data> data2 = makeData("/b"); |
| 538 | ims.insert(*data2); |
| 539 | |
| 540 | shared_ptr<Data> data4 = makeData("/d"); |
| 541 | ims.insert(*data4); |
| 542 | |
| 543 | shared_ptr<Data> data5 = makeData("/c/c/1/2/3/4/5/6"); |
| 544 | ims.insert(*data5); |
| 545 | |
| 546 | shared_ptr<Data> data6 = makeData("/c/c/6/7/8/9"); |
| 547 | ims.insert(*data6); |
| 548 | |
| 549 | shared_ptr<Data> data7 = makeData("/c/c/1/2/3"); |
| 550 | ims.insert(*data7); |
| 551 | |
| 552 | shared_ptr<Data> data8 = makeData("/c/c/1"); |
| 553 | ims.insert(*data8); |
| 554 | |
| 555 | shared_ptr<Interest> interest = makeInterest("/c/c"); |
| 556 | interest->setMinSuffixComponents(3); |
| 557 | interest->setChildSelector(0); |
| 558 | |
| 559 | shared_ptr<const Data> found = ims.find(*interest); |
| 560 | BOOST_CHECK_EQUAL(found->getName(), "/c/c/1/2/3/4/5/6"); |
| 561 | |
| 562 | shared_ptr<Interest> interest2 = makeInterest("/c/c"); |
| 563 | interest2->setMinSuffixComponents(4); |
| 564 | interest2->setChildSelector(1); |
| 565 | |
| 566 | shared_ptr<const Data> found2 = ims.find(*interest2); |
| 567 | BOOST_CHECK_EQUAL(found2->getName(), "/c/c/6/7/8/9"); |
| 568 | |
| 569 | shared_ptr<Interest> interest3 = makeInterest("/c/c"); |
| 570 | interest3->setMaxSuffixComponents(2); |
| 571 | interest3->setChildSelector(1); |
| 572 | |
| 573 | shared_ptr<const Data> found3 = ims.find(*interest3); |
| 574 | BOOST_CHECK_EQUAL(found3->getName(), "/c/c/1"); |
| 575 | } |
| 576 | |
| 577 | BOOST_AUTO_TEST_CASE_TEMPLATE(ExcludeSelector, T, InMemoryStorages) |
| 578 | { |
| 579 | T ims; |
| 580 | |
| 581 | shared_ptr<Data> data = makeData("/a"); |
| 582 | ims.insert(*data); |
| 583 | |
| 584 | shared_ptr<Data> data2 = makeData("/b"); |
| 585 | ims.insert(*data2); |
| 586 | |
| 587 | shared_ptr<Data> data3 = makeData("/c/a"); |
| 588 | ims.insert(*data3); |
| 589 | |
| 590 | shared_ptr<Data> data4 = makeData("/d"); |
| 591 | ims.insert(*data4); |
| 592 | |
| 593 | shared_ptr<Data> data5 = makeData("/c/c"); |
| 594 | ims.insert(*data5); |
| 595 | |
| 596 | shared_ptr<Data> data6 = makeData("/c/f"); |
| 597 | ims.insert(*data6); |
| 598 | |
| 599 | shared_ptr<Data> data7 = makeData("/c/n"); |
| 600 | ims.insert(*data7); |
| 601 | |
| 602 | shared_ptr<Interest> interest = makeInterest("/c"); |
| 603 | interest->setChildSelector(1); |
| 604 | Exclude e; |
| 605 | e.excludeOne (Name::Component("n")); |
| 606 | interest->setExclude(e); |
| 607 | |
| 608 | shared_ptr<const Data> found = ims.find(*interest); |
| 609 | BOOST_CHECK_EQUAL(found->getName(), "/c/f"); |
| 610 | |
| 611 | shared_ptr<Interest> interest2 = makeInterest("/c"); |
| 612 | interest2->setChildSelector(0); |
| 613 | |
| 614 | Exclude e2; |
| 615 | e2.excludeOne (Name::Component("a")); |
| 616 | interest2->setExclude(e2); |
| 617 | |
| 618 | shared_ptr<const Data> found2 = ims.find(*interest2); |
| 619 | BOOST_CHECK_EQUAL(found2->getName(), "/c/c"); |
| 620 | |
| 621 | shared_ptr<Interest> interest3 = makeInterest("/c"); |
| 622 | interest3->setChildSelector(0); |
| 623 | |
| 624 | Exclude e3; |
| 625 | e3.excludeOne (Name::Component("c")); |
| 626 | interest3->setExclude(e3); |
| 627 | |
| 628 | shared_ptr<const Data> found3 = ims.find(*interest3); |
| 629 | BOOST_CHECK_EQUAL(found3->getName(), "/c/a"); |
| 630 | } |
| 631 | |
| 632 | typedef boost::mpl::list<InMemoryStorageFifo, InMemoryStorageLfu, InMemoryStorageLru> |
| 633 | InMemoryStoragesLimited; |
| 634 | |
| 635 | BOOST_AUTO_TEST_CASE_TEMPLATE(setCapacity, T, InMemoryStoragesLimited) |
| 636 | { |
| 637 | T ims; |
| 638 | |
| 639 | ims.setCapacity(3); |
| 640 | ims.insert(*makeData("/1")); |
| 641 | ims.insert(*makeData("/2")); |
| 642 | ims.insert(*makeData("/3")); |
| 643 | BOOST_CHECK_EQUAL(ims.size(), 3); |
| 644 | |
| 645 | ims.setCapacity(2); |
| 646 | BOOST_CHECK_EQUAL(ims.size(), 2); |
| 647 | } |
| 648 | |
| 649 | BOOST_AUTO_TEST_CASE_TEMPLATE(GetLimit, T, InMemoryStoragesLimited) |
| 650 | { |
| 651 | T ims(10000); |
| 652 | |
| 653 | BOOST_CHECK_EQUAL(ims.getLimit(), 10000); |
| 654 | |
| 655 | T ims2(4); |
| 656 | |
| 657 | BOOST_CHECK_EQUAL(ims2.getLimit(), 4); |
| 658 | } |
| 659 | |
| 660 | BOOST_AUTO_TEST_CASE_TEMPLATE(InsertAndDouble, T, InMemoryStoragesLimited) |
| 661 | { |
| 662 | T ims(40); |
| 663 | |
| 664 | for (int i = 0; i < 11; i++) { |
| 665 | std::ostringstream convert; |
| 666 | convert << i; |
| 667 | Name name("/" + convert.str()); |
| 668 | shared_ptr<Data> data = makeData(name); |
| 669 | data->setFreshnessPeriod(time::milliseconds(5000)); |
| 670 | signData(data); |
| 671 | ims.insert(*data); |
| 672 | } |
| 673 | |
| 674 | BOOST_CHECK_EQUAL(ims.size(), 11); |
| 675 | |
| 676 | BOOST_CHECK_EQUAL(ims.getCapacity(), 20); |
| 677 | } |
| 678 | |
| 679 | BOOST_AUTO_TEST_CASE_TEMPLATE(InsertAndEvict, T, InMemoryStoragesLimited) |
| 680 | { |
| 681 | T ims(2); |
| 682 | |
| 683 | Name name("/insert/1"); |
| 684 | shared_ptr<Data> data = makeData(name); |
| 685 | ims.insert(*data); |
| 686 | |
| 687 | Name name2("/insert/2"); |
| 688 | shared_ptr<Data> data2 = makeData(name2); |
| 689 | ims.insert(*data2); |
| 690 | |
| 691 | Name name3("/insert/3"); |
| 692 | shared_ptr<Data> data3 = makeData(name3); |
| 693 | ims.insert(*data3); |
| 694 | |
| 695 | BOOST_CHECK_EQUAL(ims.size(), 2); |
| 696 | |
| 697 | shared_ptr<Interest> interest = makeInterest(name); |
| 698 | shared_ptr<const Data> found = ims.find(*interest); |
| 699 | BOOST_CHECK(!static_cast<bool>(found)); |
| 700 | } |
| 701 | |
| 702 | ///as Find function is implemented at the base case, therefore testing for one derived class is |
| 703 | ///sufficient for all |
| 704 | class FindFixture |
| 705 | { |
| 706 | protected: |
| 707 | void |
| 708 | insert(uint32_t id, const Name& name) |
| 709 | { |
| 710 | shared_ptr<Data> data = makeData(name); |
| 711 | data->setFreshnessPeriod(time::milliseconds(99999)); |
| 712 | data->setContent(reinterpret_cast<const uint8_t*>(&id), sizeof(id)); |
| 713 | signData(data); |
| 714 | |
| 715 | m_ims.insert(*data); |
| 716 | } |
| 717 | |
| 718 | Interest& |
| 719 | startInterest(const Name& name) |
| 720 | { |
| 721 | m_interest = makeInterest(name); |
| 722 | return *m_interest; |
| 723 | } |
| 724 | |
| 725 | uint32_t |
| 726 | find() |
| 727 | { |
| 728 | shared_ptr<const Data> found = m_ims.find(*m_interest); |
| 729 | if (found == 0) { |
| 730 | return 0; |
| 731 | } |
| 732 | const Block& content = found->getContent(); |
| 733 | if (content.value_size() != sizeof(uint32_t)) { |
| 734 | return 0; |
| 735 | } |
| 736 | return *reinterpret_cast<const uint32_t*>(content.value()); |
| 737 | } |
| 738 | |
| 739 | protected: |
| 740 | InMemoryStoragePersistent m_ims; |
| 741 | shared_ptr<Interest> m_interest; |
| 742 | }; |
| 743 | |
| 744 | BOOST_FIXTURE_TEST_SUITE(Find, FindFixture) |
| 745 | |
| 746 | BOOST_AUTO_TEST_CASE(EmptyDataName) |
| 747 | { |
| 748 | insert(1, "ndn:/"); |
| 749 | |
| 750 | startInterest("ndn:/"); |
| 751 | BOOST_CHECK_EQUAL(find(), 1); |
| 752 | } |
| 753 | |
| 754 | BOOST_AUTO_TEST_CASE(EmptyInterestName) |
| 755 | { |
| 756 | insert(1, "ndn:/A"); |
| 757 | |
| 758 | startInterest("ndn:/"); |
| 759 | BOOST_CHECK_EQUAL(find(), 1); |
| 760 | } |
| 761 | |
| 762 | BOOST_AUTO_TEST_CASE(Leftmost) |
| 763 | { |
| 764 | insert(1, "ndn:/A"); |
| 765 | insert(2, "ndn:/B/p/1"); |
| 766 | insert(3, "ndn:/B/p/2"); |
| 767 | insert(4, "ndn:/B/q/1"); |
| 768 | insert(5, "ndn:/B/q/2"); |
| 769 | insert(6, "ndn:/C"); |
| 770 | |
| 771 | startInterest("ndn:/B"); |
| 772 | BOOST_CHECK_EQUAL(find(), 2); |
| 773 | } |
| 774 | |
| 775 | BOOST_AUTO_TEST_CASE(Rightmost) |
| 776 | { |
| 777 | insert(1, "ndn:/A"); |
| 778 | insert(2, "ndn:/B/p/1"); |
| 779 | insert(3, "ndn:/B/p/2"); |
| 780 | insert(4, "ndn:/B/q/1"); |
| 781 | insert(5, "ndn:/B/q/2"); |
| 782 | insert(6, "ndn:/C"); |
| 783 | |
| 784 | startInterest("ndn:/B") |
| 785 | .setChildSelector(1); |
| 786 | BOOST_CHECK_EQUAL(find(), 4); |
| 787 | } |
| 788 | |
| 789 | BOOST_AUTO_TEST_CASE(Leftmost_ExactName1) |
| 790 | { |
| 791 | insert(1, "ndn:/"); |
| 792 | insert(2, "ndn:/A/B"); |
| 793 | insert(3, "ndn:/A/C"); |
| 794 | insert(4, "ndn:/A"); |
| 795 | insert(5, "ndn:/D"); |
| 796 | |
| 797 | // Intuitively you would think Data 4 should be between Data 1 and 2, |
| 798 | // but Data 4 has full Name ndn:/A/<32-octet hash>. |
| 799 | startInterest("ndn:/A"); |
| 800 | BOOST_CHECK_EQUAL(find(), 2); |
| 801 | } |
| 802 | |
| 803 | BOOST_AUTO_TEST_CASE(Leftmost_ExactName33) |
| 804 | { |
| 805 | insert(1, "ndn:/"); |
| 806 | insert(2, "ndn:/A"); |
| 807 | insert(3, "ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); // 33 'B's |
| 808 | insert(4, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 33 'C's |
| 809 | insert(5, "ndn:/D"); |
| 810 | |
| 811 | // Data 2 is returned, because <32-octet hash> is less than Data 3. |
| 812 | startInterest("ndn:/A"); |
| 813 | BOOST_CHECK_EQUAL(find(), 2); |
| 814 | } |
| 815 | |
| 816 | BOOST_AUTO_TEST_CASE(MinSuffixComponents) |
| 817 | { |
| 818 | insert(1, "ndn:/A/1/2/3/4"); |
| 819 | insert(2, "ndn:/B/1/2/3"); |
| 820 | insert(3, "ndn:/C/1/2"); |
| 821 | insert(4, "ndn:/D/1"); |
| 822 | insert(5, "ndn:/E"); |
| 823 | insert(6, "ndn:/"); |
| 824 | |
| 825 | startInterest("ndn:/") |
| 826 | .setChildSelector(1) |
| 827 | .setMinSuffixComponents(0); |
| 828 | BOOST_CHECK_EQUAL(find(), 6); |
| 829 | |
| 830 | startInterest("ndn:/") |
| 831 | .setChildSelector(1) |
| 832 | .setMinSuffixComponents(1); |
| 833 | BOOST_CHECK_EQUAL(find(), 6); |
| 834 | |
| 835 | startInterest("ndn:/") |
| 836 | .setChildSelector(1) |
| 837 | .setMinSuffixComponents(2); |
| 838 | BOOST_CHECK_EQUAL(find(), 5); |
| 839 | |
| 840 | startInterest("ndn:/") |
| 841 | .setChildSelector(1) |
| 842 | .setMinSuffixComponents(3); |
| 843 | BOOST_CHECK_EQUAL(find(), 4); |
| 844 | |
| 845 | startInterest("ndn:/") |
| 846 | .setChildSelector(1) |
| 847 | .setMinSuffixComponents(4); |
| 848 | BOOST_CHECK_EQUAL(find(), 3); |
| 849 | |
| 850 | startInterest("ndn:/") |
| 851 | .setChildSelector(1) |
| 852 | .setMinSuffixComponents(5); |
| 853 | BOOST_CHECK_EQUAL(find(), 2); |
| 854 | |
| 855 | startInterest("ndn:/") |
| 856 | .setChildSelector(1) |
| 857 | .setMinSuffixComponents(6); |
| 858 | BOOST_CHECK_EQUAL(find(), 1); |
| 859 | |
| 860 | startInterest("ndn:/") |
| 861 | .setChildSelector(1) |
| 862 | .setMinSuffixComponents(7); |
| 863 | BOOST_CHECK_EQUAL(find(), 0); |
| 864 | } |
| 865 | |
| 866 | BOOST_AUTO_TEST_CASE(MaxSuffixComponents) |
| 867 | { |
| 868 | insert(1, "ndn:/"); |
| 869 | insert(2, "ndn:/A"); |
| 870 | insert(3, "ndn:/A/B"); |
| 871 | insert(4, "ndn:/A/B/C"); |
| 872 | insert(5, "ndn:/A/B/C/D"); |
| 873 | insert(6, "ndn:/A/B/C/D/E"); |
| 874 | // Order is 6,5,4,3,2,1, because <32-octet hash> is greater than a 1-octet component. |
| 875 | |
| 876 | startInterest("ndn:/") |
| 877 | .setMaxSuffixComponents(0); |
| 878 | BOOST_CHECK_EQUAL(find(), 0); |
| 879 | |
| 880 | startInterest("ndn:/") |
| 881 | .setMaxSuffixComponents(1); |
| 882 | BOOST_CHECK_EQUAL(find(), 1); |
| 883 | |
| 884 | startInterest("ndn:/") |
| 885 | .setMaxSuffixComponents(2); |
| 886 | BOOST_CHECK_EQUAL(find(), 2); |
| 887 | |
| 888 | startInterest("ndn:/") |
| 889 | .setMaxSuffixComponents(3); |
| 890 | BOOST_CHECK_EQUAL(find(), 3); |
| 891 | |
| 892 | startInterest("ndn:/") |
| 893 | .setMaxSuffixComponents(4); |
| 894 | BOOST_CHECK_EQUAL(find(), 4); |
| 895 | |
| 896 | startInterest("ndn:/") |
| 897 | .setMaxSuffixComponents(5); |
| 898 | BOOST_CHECK_EQUAL(find(), 5); |
| 899 | |
| 900 | startInterest("ndn:/") |
| 901 | .setMaxSuffixComponents(6); |
| 902 | BOOST_CHECK_EQUAL(find(), 6); |
| 903 | } |
| 904 | |
| 905 | BOOST_AUTO_TEST_CASE(DigestOrder) |
| 906 | { |
| 907 | insert(1, "ndn:/A"); |
| 908 | insert(2, "ndn:/A"); |
| 909 | // We don't know which comes first, but there must be some order |
| 910 | |
| 911 | startInterest("ndn:/A") |
| 912 | .setChildSelector(0); |
| 913 | uint32_t leftmost = find(); |
| 914 | |
| 915 | startInterest("ndn:/A") |
| 916 | .setChildSelector(1); |
| 917 | uint32_t rightmost = find(); |
| 918 | |
| 919 | BOOST_CHECK_NE(leftmost, rightmost); |
| 920 | } |
| 921 | |
| 922 | BOOST_AUTO_TEST_CASE(DigestExclude) |
| 923 | { |
| 924 | insert(1, "ndn:/A/B"); |
| 925 | insert(2, "ndn:/A"); |
| 926 | insert(3, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 33 'C's |
| 927 | |
| 928 | startInterest("ndn:/A") |
| 929 | .setExclude(Exclude().excludeBefore(name::Component(reinterpret_cast<const uint8_t*>( |
| 930 | "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" |
| 931 | "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"), 31))); // 31 0xFF's |
| 932 | BOOST_CHECK_EQUAL(find(), 2); |
| 933 | |
| 934 | startInterest("ndn:/A") |
| 935 | .setChildSelector(1) |
| 936 | .setExclude(Exclude().excludeAfter(name::Component(reinterpret_cast<const uint8_t*>( |
| 937 | "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| 938 | "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| 939 | "\x00"), 33))); // 33 0x00's |
| 940 | BOOST_CHECK_EQUAL(find(), 2); |
| 941 | } |
| 942 | |
| 943 | BOOST_AUTO_TEST_CASE(ExactName32) |
| 944 | { |
| 945 | insert(1, "ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); // 32 'B's |
| 946 | insert(2, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 32 'C's |
| 947 | |
| 948 | startInterest("ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); |
| 949 | BOOST_CHECK_EQUAL(find(), 1); |
| 950 | } |
| 951 | |
| 952 | BOOST_AUTO_TEST_CASE(MinSuffixComponents32) |
| 953 | { |
| 954 | insert(1, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/1/2/3/4"); // 32 'x's |
| 955 | insert(2, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/B/1/2/3"); |
| 956 | insert(3, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/C/1/2"); |
| 957 | insert(4, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/D/1"); |
| 958 | insert(5, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/E"); |
| 959 | insert(6, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); |
| 960 | |
| 961 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 962 | .setChildSelector(1) |
| 963 | .setMinSuffixComponents(0); |
| 964 | BOOST_CHECK_EQUAL(find(), 6); |
| 965 | |
| 966 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 967 | .setChildSelector(1) |
| 968 | .setMinSuffixComponents(1); |
| 969 | BOOST_CHECK_EQUAL(find(), 6); |
| 970 | |
| 971 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 972 | .setChildSelector(1) |
| 973 | .setMinSuffixComponents(2); |
| 974 | BOOST_CHECK_EQUAL(find(), 5); |
| 975 | |
| 976 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 977 | .setChildSelector(1) |
| 978 | .setMinSuffixComponents(3); |
| 979 | BOOST_CHECK_EQUAL(find(), 4); |
| 980 | |
| 981 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 982 | .setChildSelector(1) |
| 983 | .setMinSuffixComponents(4); |
| 984 | BOOST_CHECK_EQUAL(find(), 3); |
| 985 | |
| 986 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 987 | .setChildSelector(1) |
| 988 | .setMinSuffixComponents(5); |
| 989 | BOOST_CHECK_EQUAL(find(), 2); |
| 990 | |
| 991 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 992 | .setChildSelector(1) |
| 993 | .setMinSuffixComponents(6); |
| 994 | BOOST_CHECK_EQUAL(find(), 1); |
| 995 | |
| 996 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 997 | .setChildSelector(1) |
| 998 | .setMinSuffixComponents(7); |
| 999 | BOOST_CHECK_EQUAL(find(), 0); |
| 1000 | } |
| 1001 | |
| 1002 | BOOST_AUTO_TEST_CASE(MaxSuffixComponents32) |
| 1003 | { |
| 1004 | insert(1, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/"); // 32 'x's |
| 1005 | insert(2, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A"); |
| 1006 | insert(3, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B"); |
| 1007 | insert(4, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C"); |
| 1008 | insert(5, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C/D"); |
| 1009 | insert(6, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C/D/E"); |
| 1010 | // Order is 6,5,4,3,2,1, because <32-octet hash> is greater than a 1-octet component. |
| 1011 | |
| 1012 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 1013 | .setMaxSuffixComponents(0); |
| 1014 | BOOST_CHECK_EQUAL(find(), 0); |
| 1015 | |
| 1016 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 1017 | .setMaxSuffixComponents(1); |
| 1018 | BOOST_CHECK_EQUAL(find(), 1); |
| 1019 | |
| 1020 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 1021 | .setMaxSuffixComponents(2); |
| 1022 | BOOST_CHECK_EQUAL(find(), 2); |
| 1023 | |
| 1024 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 1025 | .setMaxSuffixComponents(3); |
| 1026 | BOOST_CHECK_EQUAL(find(), 3); |
| 1027 | |
| 1028 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 1029 | .setMaxSuffixComponents(4); |
| 1030 | BOOST_CHECK_EQUAL(find(), 4); |
| 1031 | |
| 1032 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 1033 | .setMaxSuffixComponents(5); |
| 1034 | BOOST_CHECK_EQUAL(find(), 5); |
| 1035 | |
| 1036 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 1037 | .setMaxSuffixComponents(6); |
| 1038 | BOOST_CHECK_EQUAL(find(), 6); |
| 1039 | } |
| 1040 | |
Alexander Afanasyev | 3ccc6f7 | 2014-10-12 12:19:09 -0700 | [diff] [blame^] | 1041 | BOOST_AUTO_TEST_SUITE_END() // Find |
| 1042 | BOOST_AUTO_TEST_SUITE_END() // Common |
| 1043 | BOOST_AUTO_TEST_SUITE_END() // UtilInMemoryStorage |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 1044 | |
| 1045 | } // namespace util |
| 1046 | } // namespace ndn |