Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 042a331 | 2017-09-15 02:51:20 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 8f0b8b6 | 2023-08-29 21:04:08 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2023, Regents of the University of California, |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Alexander Afanasyev | c026d25 | 2014-06-16 11:14:15 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 25 | |
| 26 | #include "table/pit.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 27 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 28 | #include "tests/test-common.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 29 | #include "tests/daemon/global-io-fixture.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 30 | |
Davide Pesavento | 8f0b8b6 | 2023-08-29 21:04:08 -0400 | [diff] [blame^] | 31 | #include <ndn-cxx/util/concepts.hpp> |
| 32 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 33 | namespace nfd::tests { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 34 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 35 | using namespace nfd::pit; |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 36 | |
Davide Pesavento | 8f0b8b6 | 2023-08-29 21:04:08 -0400 | [diff] [blame^] | 37 | NDN_CXX_ASSERT_FORWARD_ITERATOR(Pit::const_iterator); |
| 38 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 39 | BOOST_AUTO_TEST_SUITE(Table) |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 40 | BOOST_FIXTURE_TEST_SUITE(TestPit, GlobalIoFixture) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 41 | |
Junxiao Shi | 2879779 | 2016-05-26 18:10:18 +0000 | [diff] [blame] | 42 | BOOST_AUTO_TEST_CASE(Find) |
| 43 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 44 | auto interest1 = makeInterest("/6hNwxJjw"); |
| 45 | auto interest2 = makeInterest("/v65zqxm4d"); |
Junxiao Shi | 2879779 | 2016-05-26 18:10:18 +0000 | [diff] [blame] | 46 | |
| 47 | NameTree nameTree(16); |
| 48 | Pit pit(nameTree); |
| 49 | |
| 50 | pit.insert(*interest1); |
| 51 | shared_ptr<pit::Entry> found1a = pit.find(*interest1); |
| 52 | shared_ptr<pit::Entry> found1b = pit.find(*interest1); |
| 53 | BOOST_CHECK(found1a != nullptr); |
| 54 | BOOST_CHECK(found1a == found1b); |
| 55 | |
| 56 | shared_ptr<pit::Entry> found2 = pit.find(*interest2); |
| 57 | BOOST_CHECK(found2 == nullptr); |
| 58 | BOOST_CHECK(nameTree.findExactMatch(interest2->getName()) == nullptr); |
| 59 | } |
| 60 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 61 | BOOST_AUTO_TEST_CASE(Insert) |
| 62 | { |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 63 | Name name1("/5vzBNnMst"); |
| 64 | Name name2("/igSGfEIM62"); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 65 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 66 | NameTree nameTree(16); |
| 67 | Pit pit(nameTree); |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 68 | BOOST_CHECK_EQUAL(pit.size(), 0); |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 69 | |
| 70 | shared_ptr<Entry> entry; |
| 71 | bool isNew = false; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 72 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 73 | // base |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 74 | auto interestA = makeInterest(name1, false, std::nullopt, 2148); |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 75 | std::tie(entry, isNew) = pit.insert(*interestA); |
| 76 | BOOST_CHECK_EQUAL(isNew, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 77 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 78 | |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 79 | // same Interest, same PIT entry |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 80 | auto interestA2 = make_shared<Interest>(*interestA); |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 81 | std::tie(entry, isNew) = pit.insert(*interestA2); |
| 82 | BOOST_CHECK_EQUAL(isNew, false); |
Eric Newberry | f4056d0 | 2017-05-26 17:31:53 +0000 | [diff] [blame] | 83 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 84 | |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 85 | // different CanBePrefix, different PIT entry |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 86 | auto interestB = make_shared<Interest>(*interestA); |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 87 | interestB->setCanBePrefix(true); |
| 88 | std::tie(entry, isNew) = pit.insert(*interestB); |
| 89 | BOOST_CHECK_EQUAL(isNew, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 90 | BOOST_CHECK_EQUAL(pit.size(), 2); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 91 | |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 92 | // different MustBeFresh, different PIT entry |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 93 | auto interestC = make_shared<Interest>(*interestA); |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 94 | interestC->setMustBeFresh(true); |
| 95 | std::tie(entry, isNew) = pit.insert(*interestC); |
| 96 | BOOST_CHECK_EQUAL(isNew, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 97 | BOOST_CHECK_EQUAL(pit.size(), 3); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 98 | |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 99 | // different InterestLifetime, same PIT entry |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 100 | auto interestD = make_shared<Interest>(*interestA); |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 101 | interestD->setInterestLifetime(1_s); |
| 102 | std::tie(entry, isNew) = pit.insert(*interestD); |
| 103 | BOOST_CHECK_EQUAL(isNew, false); |
| 104 | BOOST_CHECK_EQUAL(pit.size(), 3); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 105 | |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 106 | // different Nonce, same PIT entry |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 107 | auto interestE = make_shared<Interest>(*interestA); |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 108 | interestE->setNonce(2192); |
| 109 | std::tie(entry, isNew) = pit.insert(*interestE); |
| 110 | BOOST_CHECK_EQUAL(isNew, false); |
| 111 | BOOST_CHECK_EQUAL(pit.size(), 3); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 112 | |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 113 | // different name, different PIT entry |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 114 | auto interestF = make_shared<Interest>(*interestA); |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 115 | interestF->setName(name2); |
| 116 | std::tie(entry, isNew) = pit.insert(*interestF); |
| 117 | BOOST_CHECK_EQUAL(isNew, true); |
| 118 | BOOST_CHECK_EQUAL(pit.size(), 4); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 121 | BOOST_AUTO_TEST_CASE(Erase) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 122 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 123 | auto interest = makeInterest("/z88Admz6A2"); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 124 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 125 | NameTree nameTree(16); |
| 126 | Pit pit(nameTree); |
| 127 | |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 128 | shared_ptr<Entry> entry; |
| 129 | bool isNew = false; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 130 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 131 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 132 | |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 133 | std::tie(entry, isNew) = pit.insert(*interest); |
| 134 | BOOST_CHECK_EQUAL(isNew, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 135 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 136 | BOOST_CHECK(pit.find(*interest) != nullptr); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 137 | |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 138 | std::tie(entry, isNew) = pit.insert(*interest); |
| 139 | BOOST_CHECK_EQUAL(isNew, false); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 140 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 141 | BOOST_CHECK(pit.find(*interest) != nullptr); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 142 | |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 143 | pit.erase(entry.get()); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 144 | BOOST_CHECK_EQUAL(pit.size(), 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 145 | BOOST_CHECK(pit.find(*interest) == nullptr); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 146 | |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 147 | std::tie(entry, isNew) = pit.insert(*interest); |
| 148 | BOOST_CHECK_EQUAL(isNew, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 149 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 150 | BOOST_CHECK(pit.find(*interest) != nullptr); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 151 | } |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 152 | |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 153 | BOOST_AUTO_TEST_CASE(EraseNameTreeEntry) |
| 154 | { |
| 155 | NameTree nameTree; |
| 156 | Pit pit(nameTree); |
| 157 | size_t nNameTreeEntriesBefore = nameTree.size(); |
| 158 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 159 | auto interest = makeInterest("/37xWVvQ2K"); |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 160 | auto entry = pit.insert(*interest).first; |
Junxiao Shi | dbef6dc | 2016-08-15 02:58:36 +0000 | [diff] [blame] | 161 | pit.erase(entry.get()); |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 162 | BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore); |
| 163 | } |
| 164 | |
spirosmastorakis | ff92030 | 2016-05-26 18:09:31 +0000 | [diff] [blame] | 165 | BOOST_AUTO_TEST_CASE(EraseWithFullName) |
| 166 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 167 | auto data = makeData("/test"); |
| 168 | auto interest = makeInterest(data->getFullName()); |
spirosmastorakis | ff92030 | 2016-05-26 18:09:31 +0000 | [diff] [blame] | 169 | |
| 170 | NameTree nameTree(16); |
| 171 | Pit pit(nameTree); |
| 172 | |
| 173 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 174 | |
| 175 | BOOST_CHECK_EQUAL(pit.insert(*interest).second, true); |
| 176 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 177 | BOOST_CHECK(pit.find(*interest) != nullptr); |
| 178 | |
| 179 | BOOST_CHECK_EQUAL(pit.insert(*interest).second, false); |
| 180 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 181 | shared_ptr<pit::Entry> pitEntry = pit.find(*interest); |
| 182 | BOOST_REQUIRE(pitEntry != nullptr); |
| 183 | |
Junxiao Shi | dbef6dc | 2016-08-15 02:58:36 +0000 | [diff] [blame] | 184 | pit.erase(pitEntry.get()); |
spirosmastorakis | ff92030 | 2016-05-26 18:09:31 +0000 | [diff] [blame] | 185 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 186 | BOOST_CHECK(pit.find(*interest) == nullptr); |
| 187 | |
| 188 | BOOST_CHECK_EQUAL(pit.insert(*interest).second, true); |
| 189 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 190 | BOOST_CHECK(pit.find(*interest) != nullptr); |
| 191 | } |
| 192 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 193 | BOOST_AUTO_TEST_CASE(FindAllDataMatches) |
| 194 | { |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 195 | Name nameA ("/A"); |
| 196 | Name nameAB ("/A/B"); |
| 197 | Name nameABC ("/A/B/C"); |
| 198 | Name nameABCD("/A/B/C/D"); |
| 199 | Name nameD ("/D"); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 200 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 201 | auto interestA = makeInterest(nameA, true); |
| 202 | auto interestABC = makeInterest(nameABC, true); |
| 203 | auto interestD = makeInterest(nameD, true); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 204 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 205 | NameTree nameTree(16); |
| 206 | Pit pit(nameTree); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 207 | int count = 0; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 208 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 209 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 210 | |
Alexander Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 211 | pit.insert(*interestA ); |
| 212 | pit.insert(*interestABC); |
| 213 | pit.insert(*interestD ); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 214 | |
| 215 | nameTree.lookup(nameABCD); // make sure /A/B/C/D is in nameTree |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 216 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 217 | BOOST_CHECK_EQUAL(pit.size(), 3); |
| 218 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 219 | auto data = makeData(nameABCD); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 220 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 221 | DataMatchResult matches = pit.findAllDataMatches(*data); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 222 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 223 | bool hasA = false; |
| 224 | bool hasAB = false; |
| 225 | bool hasABC = false; |
| 226 | bool hasD = false; |
| 227 | |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 228 | for (const auto& entry : matches) { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 229 | ++count; |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 230 | |
| 231 | if (entry->getName().equals(nameA )) |
| 232 | hasA = true; |
| 233 | |
| 234 | if (entry->getName().equals(nameAB)) |
| 235 | hasAB = true; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 236 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 237 | if (entry->getName().equals(nameABC)) |
| 238 | hasABC = true; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 239 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 240 | if (entry->getName().equals(nameD)) |
| 241 | hasD = true; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 242 | } |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 243 | BOOST_CHECK_EQUAL(hasA , true); |
| 244 | BOOST_CHECK_EQUAL(hasAB , false); |
| 245 | BOOST_CHECK_EQUAL(hasABC, true); |
| 246 | BOOST_CHECK_EQUAL(hasD , false); |
| 247 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 248 | BOOST_CHECK_EQUAL(count, 2); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 249 | } |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 250 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 251 | BOOST_AUTO_TEST_CASE(MatchFullName) // Bug 3363 |
| 252 | { |
| 253 | NameTree nameTree(16); |
| 254 | Pit pit(nameTree); |
| 255 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 256 | auto data = makeData("/A"); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 257 | Name fullName = data->getFullName(); |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 258 | auto interest = makeInterest(fullName); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 259 | |
| 260 | pit.insert(*interest); |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 261 | DataMatchResult matches = pit.findAllDataMatches(*data); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 262 | |
| 263 | BOOST_REQUIRE_EQUAL(std::distance(matches.begin(), matches.end()), 1); |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 264 | auto found = *matches.begin(); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 265 | BOOST_CHECK_EQUAL(found->getName(), fullName); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Junxiao Shi | 042a331 | 2017-09-15 02:51:20 +0000 | [diff] [blame] | 268 | BOOST_AUTO_TEST_CASE(InsertMatchLongName) |
| 269 | { |
| 270 | NameTree nameTree(16); |
| 271 | Pit pit(nameTree); |
| 272 | |
| 273 | Name n1; |
| 274 | while (n1.size() < NameTree::getMaxDepth()) { |
| 275 | n1.append("A"); |
| 276 | } |
| 277 | Name n2 = n1; |
| 278 | while (n2.size() < NameTree::getMaxDepth() * 2) { |
| 279 | n2.append("B"); |
| 280 | } |
| 281 | Name n3 = n1; |
| 282 | while (n3.size() < NameTree::getMaxDepth() * 2) { |
| 283 | n3.append("C"); |
| 284 | } |
| 285 | auto d2 = makeData(n2); |
| 286 | auto i2 = makeInterest(n2); |
| 287 | auto d3 = makeData(n3); |
| 288 | auto i3 = makeInterest(d3->getFullName()); |
| 289 | |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 290 | auto entry2 = pit.insert(*i2).first; |
| 291 | auto entry3 = pit.insert(*i3).first; |
Junxiao Shi | 042a331 | 2017-09-15 02:51:20 +0000 | [diff] [blame] | 292 | |
| 293 | BOOST_CHECK_EQUAL(pit.size(), 2); |
| 294 | BOOST_CHECK_EQUAL(nameTree.size(), 1 + NameTree::getMaxDepth()); // root node + max depth |
| 295 | BOOST_CHECK(entry2->getInterest().matchesInterest(*i2)); |
| 296 | BOOST_CHECK(entry3->getInterest().matchesInterest(*i3)); |
| 297 | |
| 298 | DataMatchResult matches2 = pit.findAllDataMatches(*d2); |
| 299 | BOOST_REQUIRE_EQUAL(std::distance(matches2.begin(), matches2.end()), 1); |
| 300 | BOOST_CHECK(*matches2.begin() == entry2); |
| 301 | DataMatchResult matches3 = pit.findAllDataMatches(*d3); |
| 302 | BOOST_REQUIRE_EQUAL(std::distance(matches3.begin(), matches3.end()), 1); |
| 303 | BOOST_CHECK(*matches3.begin() == entry3); |
| 304 | } |
| 305 | |
Alexander Afanasyev | 750fa1c | 2015-01-03 17:28:31 -0800 | [diff] [blame] | 306 | BOOST_AUTO_TEST_CASE(Iterator) |
| 307 | { |
| 308 | NameTree nameTree(16); |
| 309 | Pit pit(nameTree); |
| 310 | |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 311 | auto interestA = makeInterest("/A"); |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 312 | auto interestABC1 = makeInterest("/A/B/C"); |
| 313 | auto interestABC2 = makeInterest("/A/B/C"); |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 314 | interestABC2->setMustBeFresh(true); |
| 315 | auto interestD = makeInterest("/D"); |
Alexander Afanasyev | 750fa1c | 2015-01-03 17:28:31 -0800 | [diff] [blame] | 316 | |
| 317 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 318 | BOOST_CHECK(pit.begin() == pit.end()); |
| 319 | |
| 320 | pit.insert(*interestABC1); |
| 321 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 322 | BOOST_CHECK(pit.begin() != pit.end()); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 323 | BOOST_CHECK(&pit.begin()->getInterest() == interestABC1.get()); |
| 324 | BOOST_CHECK(&(*pit.begin()).getInterest() == interestABC1.get()); |
Alexander Afanasyev | 750fa1c | 2015-01-03 17:28:31 -0800 | [diff] [blame] | 325 | |
| 326 | auto i = pit.begin(); |
| 327 | auto j = pit.begin(); |
| 328 | BOOST_CHECK(++i == pit.end()); |
| 329 | BOOST_CHECK(j++ == pit.begin()); |
| 330 | BOOST_CHECK(j == pit.end()); |
| 331 | |
| 332 | pit.insert(*interestA); |
| 333 | pit.insert(*interestABC2); |
| 334 | pit.insert(*interestD); |
| 335 | |
Alexander Afanasyev | 750fa1c | 2015-01-03 17:28:31 -0800 | [diff] [blame] | 336 | std::set<const Interest*> actual; |
| 337 | for (const auto& pitEntry : pit) { |
| 338 | actual.insert(&pitEntry.getInterest()); |
| 339 | } |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 340 | const auto expected = std::set{interestA.get(), interestABC1.get(), |
| 341 | interestABC2.get(), interestD.get()}; |
| 342 | BOOST_TEST(actual == expected, boost::test_tools::per_element()); |
Alexander Afanasyev | 750fa1c | 2015-01-03 17:28:31 -0800 | [diff] [blame] | 343 | } |
| 344 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 345 | BOOST_AUTO_TEST_SUITE_END() // TestPit |
| 346 | BOOST_AUTO_TEST_SUITE_END() // Table |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 347 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 348 | } // namespace nfd::tests |