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