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