blob: 5b051fb1f1b51565395d2cf21106c6f61b32f574 [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi042a3312017-09-15 02:51:20 +00002/*
Davide Pesaventocf7db2f2019-03-24 23:17:28 -04003 * Copyright (c) 2014-2019, Regents of the University of California,
Alexander Afanasyev319f2c82015-01-07 14:56:53 -08004 * 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 Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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 Afanasyevc026d252014-06-16 11:14:15 -070024 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070025
26#include "table/pit.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070027
Junxiao Shid9ee45c2014-02-27 15:38:11 -070028#include "tests/test-common.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040029#include "tests/daemon/global-io-fixture.hpp"
30#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070031
Davide Pesavento87fc0f82018-04-11 23:43:51 -040032#include <ndn-cxx/exclude.hpp>
33
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080034namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080035namespace pit {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070036namespace tests {
Junxiao Shicbba04c2014-01-26 14:21:22 -070037
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080038using namespace nfd::tests;
39
Junxiao Shi5e5e4452015-09-24 16:56:52 -070040BOOST_AUTO_TEST_SUITE(Table)
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040041BOOST_FIXTURE_TEST_SUITE(TestPit, GlobalIoFixture)
Junxiao Shicbba04c2014-01-26 14:21:22 -070042
Junxiao Shi28797792016-05-26 18:10:18 +000043BOOST_AUTO_TEST_CASE(Find)
44{
45 shared_ptr<Interest> interest1 = makeInterest("/6hNwxJjw");
46 shared_ptr<Interest> interest2 = makeInterest("/v65zqxm4d");
47
48 NameTree nameTree(16);
49 Pit pit(nameTree);
50
51 pit.insert(*interest1);
52 shared_ptr<pit::Entry> found1a = pit.find(*interest1);
53 shared_ptr<pit::Entry> found1b = pit.find(*interest1);
54 BOOST_CHECK(found1a != nullptr);
55 BOOST_CHECK(found1a == found1b);
56
57 shared_ptr<pit::Entry> found2 = pit.find(*interest2);
58 BOOST_CHECK(found2 == nullptr);
59 BOOST_CHECK(nameTree.findExactMatch(interest2->getName()) == nullptr);
60}
61
Junxiao Shicbba04c2014-01-26 14:21:22 -070062BOOST_AUTO_TEST_CASE(Insert)
63{
64 Name name1("ndn:/5vzBNnMst");
65 Name name2("ndn:/igSGfEIM62");
Davide Pesavento87fc0f82018-04-11 23:43:51 -040066 ndn::Exclude exclude1;
Junxiao Shicbba04c2014-01-26 14:21:22 -070067 exclude1.excludeOne(Name::Component("u26p47oep"));
Davide Pesavento87fc0f82018-04-11 23:43:51 -040068 ndn::Exclude exclude2;
Junxiao Shi30d35992014-04-03 14:51:58 -070069 exclude2.excludeBefore(Name::Component("u26p47oep"));
70 ndn::KeyLocator keyLocator1("ndn:/sGAE3peMHA");
71 ndn::KeyLocator keyLocator2("ndn:/nIJH6pr4");
Junxiao Shi57f0f312014-03-16 11:52:20 -070072
Haowei Yuan78c84d12014-02-27 15:35:13 -060073 NameTree nameTree(16);
74 Pit pit(nameTree);
Junxiao Shi30d35992014-04-03 14:51:58 -070075 BOOST_CHECK_EQUAL(pit.size(), 0);
Junxiao Shi4846f372016-04-05 13:39:30 -070076 std::pair<shared_ptr<Entry>, bool> insertResult;
Junxiao Shi57f0f312014-03-16 11:52:20 -070077
Junxiao Shi30d35992014-04-03 14:51:58 -070078 // base
79 shared_ptr<Interest> interestA = make_shared<Interest>(name1);
80 insertResult = pit.insert(*interestA);
Junxiao Shicbba04c2014-01-26 14:21:22 -070081 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -060082 BOOST_CHECK_EQUAL(pit.size(), 1);
83
Eric Newberryf4056d02017-05-26 17:31:53 +000084 // same as A
85 shared_ptr<Interest> interestA2 = make_shared<Interest>(*interestA);
86 insertResult = pit.insert(*interestA2);
87 BOOST_CHECK_EQUAL(insertResult.second, false); // sharing the same PIT entry
88 BOOST_CHECK_EQUAL(pit.size(), 1);
89
Junxiao Shi30d35992014-04-03 14:51:58 -070090 // A+MinSuffixComponents
91 shared_ptr<Interest> interestB = make_shared<Interest>(*interestA);
92 interestB->setMinSuffixComponents(2);
93 insertResult = pit.insert(*interestB);
Junxiao Shicbba04c2014-01-26 14:21:22 -070094 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -060095 BOOST_CHECK_EQUAL(pit.size(), 2);
Junxiao Shi57f0f312014-03-16 11:52:20 -070096
Junxiao Shi30d35992014-04-03 14:51:58 -070097 // A+MaxSuffixComponents
98 shared_ptr<Interest> interestC = make_shared<Interest>(*interestA);
99 interestC->setMaxSuffixComponents(4);
100 insertResult = pit.insert(*interestC);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700101 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600102 BOOST_CHECK_EQUAL(pit.size(), 3);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700103
Junxiao Shi30d35992014-04-03 14:51:58 -0700104 // A+KeyLocator1
105 shared_ptr<Interest> interestD = make_shared<Interest>(*interestA);
106 interestD->setPublisherPublicKeyLocator(keyLocator1);
107 insertResult = pit.insert(*interestD);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700108 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600109 BOOST_CHECK_EQUAL(pit.size(), 4);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700110
Junxiao Shi30d35992014-04-03 14:51:58 -0700111 // A+KeyLocator2
112 shared_ptr<Interest> interestE = make_shared<Interest>(*interestA);
113 interestE->setPublisherPublicKeyLocator(keyLocator2);
114 insertResult = pit.insert(*interestE);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700115 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600116 BOOST_CHECK_EQUAL(pit.size(), 5);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700117
Junxiao Shi30d35992014-04-03 14:51:58 -0700118 // A+Exclude1
119 shared_ptr<Interest> interestF = make_shared<Interest>(*interestA);
120 interestF->setExclude(exclude1);
121 insertResult = pit.insert(*interestF);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700122 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600123 BOOST_CHECK_EQUAL(pit.size(), 6);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700124
Junxiao Shi30d35992014-04-03 14:51:58 -0700125 // A+Exclude2
126 shared_ptr<Interest> interestG = make_shared<Interest>(*interestA);
127 interestG->setExclude(exclude2);
128 insertResult = pit.insert(*interestG);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700129 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600130 BOOST_CHECK_EQUAL(pit.size(), 7);
131
Junxiao Shi30d35992014-04-03 14:51:58 -0700132 // A+ChildSelector1
133 shared_ptr<Interest> interestI = make_shared<Interest>(*interestA);
134 interestI->setChildSelector(1);
135 insertResult = pit.insert(*interestI);
136 BOOST_CHECK_EQUAL(insertResult.second, true);
Eric Newberryf4056d02017-05-26 17:31:53 +0000137 BOOST_CHECK_EQUAL(pit.size(), 8);
Junxiao Shi30d35992014-04-03 14:51:58 -0700138
139 // A+MustBeFresh
140 shared_ptr<Interest> interestJ = make_shared<Interest>(*interestA);
141 interestJ->setMustBeFresh(true);
142 insertResult = pit.insert(*interestJ);
143 BOOST_CHECK_EQUAL(insertResult.second, true);
Eric Newberryf4056d02017-05-26 17:31:53 +0000144 BOOST_CHECK_EQUAL(pit.size(), 9);
Junxiao Shi30d35992014-04-03 14:51:58 -0700145
146 // A+InterestLifetime
147 shared_ptr<Interest> interestK = make_shared<Interest>(*interestA);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400148 interestK->setInterestLifetime(1_s);
Junxiao Shi30d35992014-04-03 14:51:58 -0700149 insertResult = pit.insert(*interestK);
Eric Newberryf4056d02017-05-26 17:31:53 +0000150 BOOST_CHECK_EQUAL(insertResult.second, false); // only guiders differ
151 BOOST_CHECK_EQUAL(pit.size(), 9);
Junxiao Shi30d35992014-04-03 14:51:58 -0700152
153 // A+Nonce
154 shared_ptr<Interest> interestL = make_shared<Interest>(*interestA);
155 interestL->setNonce(2192);
156 insertResult = pit.insert(*interestL);
Eric Newberryf4056d02017-05-26 17:31:53 +0000157 BOOST_CHECK_EQUAL(insertResult.second, false); // only guiders differ
158 BOOST_CHECK_EQUAL(pit.size(), 9);
Junxiao Shi30d35992014-04-03 14:51:58 -0700159
160 // different Name+Exclude1
161 shared_ptr<Interest> interestM = make_shared<Interest>(name2);
162 interestM->setExclude(exclude1);
163 insertResult = pit.insert(*interestM);
164 BOOST_CHECK_EQUAL(insertResult.second, true);
Eric Newberryf4056d02017-05-26 17:31:53 +0000165 BOOST_CHECK_EQUAL(pit.size(), 10);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700166}
167
Haowei Yuan78c84d12014-02-27 15:35:13 -0600168BOOST_AUTO_TEST_CASE(Erase)
Junxiao Shicbba04c2014-01-26 14:21:22 -0700169{
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700170 shared_ptr<Interest> interest = makeInterest("/z88Admz6A2");
Junxiao Shicbba04c2014-01-26 14:21:22 -0700171
Haowei Yuan78c84d12014-02-27 15:35:13 -0600172 NameTree nameTree(16);
173 Pit pit(nameTree);
174
Junxiao Shi4846f372016-04-05 13:39:30 -0700175 std::pair<shared_ptr<Entry>, bool> insertResult;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700176
Haowei Yuan78c84d12014-02-27 15:35:13 -0600177 BOOST_CHECK_EQUAL(pit.size(), 0);
178
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700179 insertResult = pit.insert(*interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700180 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600181 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700182 BOOST_CHECK(pit.find(*interest) != nullptr);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700183
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700184 insertResult = pit.insert(*interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700185 BOOST_CHECK_EQUAL(insertResult.second, false);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600186 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700187 BOOST_CHECK(pit.find(*interest) != nullptr);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700188
Junxiao Shidbef6dc2016-08-15 02:58:36 +0000189 pit.erase(insertResult.first.get());
Haowei Yuan78c84d12014-02-27 15:35:13 -0600190 BOOST_CHECK_EQUAL(pit.size(), 0);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700191 BOOST_CHECK(pit.find(*interest) == nullptr);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700192
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700193 insertResult = pit.insert(*interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700194 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600195 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700196 BOOST_CHECK(pit.find(*interest) != nullptr);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600197}
Junxiao Shicbba04c2014-01-26 14:21:22 -0700198
Junxiao Shiee5a4442014-07-27 17:13:43 -0700199BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)
200{
201 NameTree nameTree;
202 Pit pit(nameTree);
203 size_t nNameTreeEntriesBefore = nameTree.size();
204
205 shared_ptr<Interest> interest = makeInterest("/37xWVvQ2K");
Junxiao Shi4846f372016-04-05 13:39:30 -0700206 shared_ptr<Entry> entry = pit.insert(*interest).first;
Junxiao Shidbef6dc2016-08-15 02:58:36 +0000207 pit.erase(entry.get());
Junxiao Shiee5a4442014-07-27 17:13:43 -0700208 BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
209}
210
spirosmastorakisff920302016-05-26 18:09:31 +0000211BOOST_AUTO_TEST_CASE(EraseWithFullName)
212{
213 shared_ptr<Data> data = makeData("/test");
214 shared_ptr<Interest> interest = makeInterest(data->getFullName());
215
216 NameTree nameTree(16);
217 Pit pit(nameTree);
218
219 BOOST_CHECK_EQUAL(pit.size(), 0);
220
221 BOOST_CHECK_EQUAL(pit.insert(*interest).second, true);
222 BOOST_CHECK_EQUAL(pit.size(), 1);
223 BOOST_CHECK(pit.find(*interest) != nullptr);
224
225 BOOST_CHECK_EQUAL(pit.insert(*interest).second, false);
226 BOOST_CHECK_EQUAL(pit.size(), 1);
227 shared_ptr<pit::Entry> pitEntry = pit.find(*interest);
228 BOOST_REQUIRE(pitEntry != nullptr);
229
Junxiao Shidbef6dc2016-08-15 02:58:36 +0000230 pit.erase(pitEntry.get());
spirosmastorakisff920302016-05-26 18:09:31 +0000231 BOOST_CHECK_EQUAL(pit.size(), 0);
232 BOOST_CHECK(pit.find(*interest) == nullptr);
233
234 BOOST_CHECK_EQUAL(pit.insert(*interest).second, true);
235 BOOST_CHECK_EQUAL(pit.size(), 1);
236 BOOST_CHECK(pit.find(*interest) != nullptr);
237}
238
Junxiao Shicbba04c2014-01-26 14:21:22 -0700239BOOST_AUTO_TEST_CASE(FindAllDataMatches)
240{
Haowei Yuane1079fc2014-03-08 14:41:25 -0600241 Name nameA ("ndn:/A");
242 Name nameAB ("ndn:/A/B");
243 Name nameABC ("ndn:/A/B/C");
244 Name nameABCD("ndn:/A/B/C/D");
245 Name nameD ("ndn:/D");
246
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700247 shared_ptr<Interest> interestA = makeInterest(nameA );
248 shared_ptr<Interest> interestABC = makeInterest(nameABC);
249 shared_ptr<Interest> interestD = makeInterest(nameD );
Junxiao Shicbba04c2014-01-26 14:21:22 -0700250
Haowei Yuan78c84d12014-02-27 15:35:13 -0600251 NameTree nameTree(16);
252 Pit pit(nameTree);
Haowei Yuane1079fc2014-03-08 14:41:25 -0600253 int count = 0;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700254
Haowei Yuan78c84d12014-02-27 15:35:13 -0600255 BOOST_CHECK_EQUAL(pit.size(), 0);
256
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700257 pit.insert(*interestA );
258 pit.insert(*interestABC);
259 pit.insert(*interestD );
Haowei Yuane1079fc2014-03-08 14:41:25 -0600260
261 nameTree.lookup(nameABCD); // make sure /A/B/C/D is in nameTree
Junxiao Shi57f0f312014-03-16 11:52:20 -0700262
Haowei Yuan78c84d12014-02-27 15:35:13 -0600263 BOOST_CHECK_EQUAL(pit.size(), 3);
264
Alexander Afanasyevc026d252014-06-16 11:14:15 -0700265 shared_ptr<Data> data = makeData(nameABCD);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700266
Junxiao Shi4846f372016-04-05 13:39:30 -0700267 DataMatchResult matches = pit.findAllDataMatches(*data);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700268
Haowei Yuane1079fc2014-03-08 14:41:25 -0600269 bool hasA = false;
270 bool hasAB = false;
271 bool hasABC = false;
272 bool hasD = false;
273
Junxiao Shi4846f372016-04-05 13:39:30 -0700274 for (const shared_ptr<Entry>& entry : matches) {
Junxiao Shicbba04c2014-01-26 14:21:22 -0700275 ++count;
Haowei Yuane1079fc2014-03-08 14:41:25 -0600276
277 if (entry->getName().equals(nameA ))
278 hasA = true;
279
280 if (entry->getName().equals(nameAB))
281 hasAB = true;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700282
Haowei Yuane1079fc2014-03-08 14:41:25 -0600283 if (entry->getName().equals(nameABC))
284 hasABC = true;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700285
Haowei Yuane1079fc2014-03-08 14:41:25 -0600286 if (entry->getName().equals(nameD))
287 hasD = true;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700288 }
Haowei Yuane1079fc2014-03-08 14:41:25 -0600289 BOOST_CHECK_EQUAL(hasA , true);
290 BOOST_CHECK_EQUAL(hasAB , false);
291 BOOST_CHECK_EQUAL(hasABC, true);
292 BOOST_CHECK_EQUAL(hasD , false);
293
Junxiao Shicbba04c2014-01-26 14:21:22 -0700294 BOOST_CHECK_EQUAL(count, 2);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700295}
Haowei Yuane1079fc2014-03-08 14:41:25 -0600296
Junxiao Shi4370fde2016-02-24 12:20:46 -0700297BOOST_AUTO_TEST_CASE(MatchFullName) // Bug 3363
298{
299 NameTree nameTree(16);
300 Pit pit(nameTree);
301
302 shared_ptr<Data> data = makeData("/A");
303 Name fullName = data->getFullName();
304 shared_ptr<Interest> interest = makeInterest(fullName);
305
306 pit.insert(*interest);
Junxiao Shi4846f372016-04-05 13:39:30 -0700307 DataMatchResult matches = pit.findAllDataMatches(*data);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700308
309 BOOST_REQUIRE_EQUAL(std::distance(matches.begin(), matches.end()), 1);
Junxiao Shi4846f372016-04-05 13:39:30 -0700310 shared_ptr<Entry> found = *matches.begin();
Junxiao Shi4370fde2016-02-24 12:20:46 -0700311 BOOST_CHECK_EQUAL(found->getName(), fullName);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700312}
313
Junxiao Shi042a3312017-09-15 02:51:20 +0000314BOOST_AUTO_TEST_CASE(InsertMatchLongName)
315{
316 NameTree nameTree(16);
317 Pit pit(nameTree);
318
319 Name n1;
320 while (n1.size() < NameTree::getMaxDepth()) {
321 n1.append("A");
322 }
323 Name n2 = n1;
324 while (n2.size() < NameTree::getMaxDepth() * 2) {
325 n2.append("B");
326 }
327 Name n3 = n1;
328 while (n3.size() < NameTree::getMaxDepth() * 2) {
329 n3.append("C");
330 }
331 auto d2 = makeData(n2);
332 auto i2 = makeInterest(n2);
333 auto d3 = makeData(n3);
334 auto i3 = makeInterest(d3->getFullName());
335
336 shared_ptr<Entry> entry2 = pit.insert(*i2).first;
337 shared_ptr<Entry> entry3 = pit.insert(*i3).first;
338
339 BOOST_CHECK_EQUAL(pit.size(), 2);
340 BOOST_CHECK_EQUAL(nameTree.size(), 1 + NameTree::getMaxDepth()); // root node + max depth
341 BOOST_CHECK(entry2->getInterest().matchesInterest(*i2));
342 BOOST_CHECK(entry3->getInterest().matchesInterest(*i3));
343
344 DataMatchResult matches2 = pit.findAllDataMatches(*d2);
345 BOOST_REQUIRE_EQUAL(std::distance(matches2.begin(), matches2.end()), 1);
346 BOOST_CHECK(*matches2.begin() == entry2);
347 DataMatchResult matches3 = pit.findAllDataMatches(*d3);
348 BOOST_REQUIRE_EQUAL(std::distance(matches3.begin(), matches3.end()), 1);
349 BOOST_CHECK(*matches3.begin() == entry3);
350}
351
Alexander Afanasyev750fa1c2015-01-03 17:28:31 -0800352BOOST_AUTO_TEST_CASE(Iterator)
353{
354 NameTree nameTree(16);
355 Pit pit(nameTree);
356
357 shared_ptr<Interest> interestA = makeInterest("/A");
358 shared_ptr<Interest> interestABC1 = makeInterest("/A/B/C");
359 shared_ptr<Interest> interestABC2 = makeInterest("/A/B/C");
360 interestABC2->setSelectors(ndn::Selectors().setMinSuffixComponents(10));
361 shared_ptr<Interest> interestD = makeInterest("/D");
362
363 BOOST_CHECK_EQUAL(pit.size(), 0);
364 BOOST_CHECK(pit.begin() == pit.end());
365
366 pit.insert(*interestABC1);
367 BOOST_CHECK_EQUAL(pit.size(), 1);
368 BOOST_CHECK(pit.begin() != pit.end());
369 BOOST_CHECK(pit.begin()->getInterest() == *interestABC1);
370 BOOST_CHECK((*pit.begin()).getInterest() == *interestABC1);
371
372 auto i = pit.begin();
373 auto j = pit.begin();
374 BOOST_CHECK(++i == pit.end());
375 BOOST_CHECK(j++ == pit.begin());
376 BOOST_CHECK(j == pit.end());
377
378 pit.insert(*interestA);
379 pit.insert(*interestABC2);
380 pit.insert(*interestD);
381
382 std::set<const Interest*> expected = {&*interestA, &*interestABC1, &*interestABC2, &*interestD};
383 std::set<const Interest*> actual;
384 for (const auto& pitEntry : pit) {
385 actual.insert(&pitEntry.getInterest());
386 }
387 BOOST_CHECK(actual == expected);
388 for (auto actualIt = actual.begin(), expectedIt = expected.begin();
389 actualIt != actual.end() && expectedIt != expected.end(); ++actualIt, ++expectedIt) {
390 BOOST_CHECK_EQUAL(**actualIt, **expectedIt);
391 }
392}
393
Davide Pesavento14e71f02019-03-28 17:35:25 -0400394BOOST_AUTO_TEST_SUITE_END() // TestPit
395BOOST_AUTO_TEST_SUITE_END() // Table
Junxiao Shicbba04c2014-01-26 14:21:22 -0700396
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700397} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800398} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800399} // namespace nfd