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