blob: c883ff44887d9b197e68755932a4e650742bec31 [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/*
Eric Newberryf4056d02017-05-26 17:31:53 +00003 * Copyright (c) 2014-2017, 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"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070027#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070028
Junxiao Shid9ee45c2014-02-27 15:38:11 -070029#include "tests/test-common.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070030
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080031namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080032namespace pit {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070033namespace tests {
Junxiao Shicbba04c2014-01-26 14:21:22 -070034
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080035using namespace nfd::tests;
36
Junxiao Shi5e5e4452015-09-24 16:56:52 -070037BOOST_AUTO_TEST_SUITE(Table)
38BOOST_FIXTURE_TEST_SUITE(TestPit, BaseFixture)
Junxiao Shicbba04c2014-01-26 14:21:22 -070039
Junxiao Shi28797792016-05-26 18:10:18 +000040BOOST_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 Shicbba04c2014-01-26 14:21:22 -070059BOOST_AUTO_TEST_CASE(Insert)
60{
61 Name name1("ndn:/5vzBNnMst");
62 Name name2("ndn:/igSGfEIM62");
Junxiao Shicbba04c2014-01-26 14:21:22 -070063 Exclude exclude1;
64 exclude1.excludeOne(Name::Component("u26p47oep"));
65 Exclude exclude2;
Junxiao Shi30d35992014-04-03 14:51:58 -070066 exclude2.excludeBefore(Name::Component("u26p47oep"));
67 ndn::KeyLocator keyLocator1("ndn:/sGAE3peMHA");
68 ndn::KeyLocator keyLocator2("ndn:/nIJH6pr4");
Junxiao Shi57f0f312014-03-16 11:52:20 -070069
Haowei Yuan78c84d12014-02-27 15:35:13 -060070 NameTree nameTree(16);
71 Pit pit(nameTree);
Junxiao Shi30d35992014-04-03 14:51:58 -070072 BOOST_CHECK_EQUAL(pit.size(), 0);
Junxiao Shi4846f372016-04-05 13:39:30 -070073 std::pair<shared_ptr<Entry>, bool> insertResult;
Junxiao Shi57f0f312014-03-16 11:52:20 -070074
Junxiao Shi30d35992014-04-03 14:51:58 -070075 // base
76 shared_ptr<Interest> interestA = make_shared<Interest>(name1);
77 insertResult = pit.insert(*interestA);
Junxiao Shicbba04c2014-01-26 14:21:22 -070078 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -060079 BOOST_CHECK_EQUAL(pit.size(), 1);
80
Eric Newberryf4056d02017-05-26 17:31:53 +000081 // 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 Shi30d35992014-04-03 14:51:58 -070087 // A+MinSuffixComponents
88 shared_ptr<Interest> interestB = make_shared<Interest>(*interestA);
89 interestB->setMinSuffixComponents(2);
90 insertResult = pit.insert(*interestB);
Junxiao Shicbba04c2014-01-26 14:21:22 -070091 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -060092 BOOST_CHECK_EQUAL(pit.size(), 2);
Junxiao Shi57f0f312014-03-16 11:52:20 -070093
Junxiao Shi30d35992014-04-03 14:51:58 -070094 // A+MaxSuffixComponents
95 shared_ptr<Interest> interestC = make_shared<Interest>(*interestA);
96 interestC->setMaxSuffixComponents(4);
97 insertResult = pit.insert(*interestC);
Junxiao Shicbba04c2014-01-26 14:21:22 -070098 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -060099 BOOST_CHECK_EQUAL(pit.size(), 3);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700100
Junxiao Shi30d35992014-04-03 14:51:58 -0700101 // A+KeyLocator1
102 shared_ptr<Interest> interestD = make_shared<Interest>(*interestA);
103 interestD->setPublisherPublicKeyLocator(keyLocator1);
104 insertResult = pit.insert(*interestD);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700105 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600106 BOOST_CHECK_EQUAL(pit.size(), 4);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700107
Junxiao Shi30d35992014-04-03 14:51:58 -0700108 // A+KeyLocator2
109 shared_ptr<Interest> interestE = make_shared<Interest>(*interestA);
110 interestE->setPublisherPublicKeyLocator(keyLocator2);
111 insertResult = pit.insert(*interestE);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700112 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600113 BOOST_CHECK_EQUAL(pit.size(), 5);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700114
Junxiao Shi30d35992014-04-03 14:51:58 -0700115 // A+Exclude1
116 shared_ptr<Interest> interestF = make_shared<Interest>(*interestA);
117 interestF->setExclude(exclude1);
118 insertResult = pit.insert(*interestF);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700119 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600120 BOOST_CHECK_EQUAL(pit.size(), 6);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700121
Junxiao Shi30d35992014-04-03 14:51:58 -0700122 // A+Exclude2
123 shared_ptr<Interest> interestG = make_shared<Interest>(*interestA);
124 interestG->setExclude(exclude2);
125 insertResult = pit.insert(*interestG);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700126 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600127 BOOST_CHECK_EQUAL(pit.size(), 7);
128
Junxiao Shi30d35992014-04-03 14:51:58 -0700129 // 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 Newberryf4056d02017-05-26 17:31:53 +0000134 BOOST_CHECK_EQUAL(pit.size(), 8);
Junxiao Shi30d35992014-04-03 14:51:58 -0700135
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 Newberryf4056d02017-05-26 17:31:53 +0000141 BOOST_CHECK_EQUAL(pit.size(), 9);
Junxiao Shi30d35992014-04-03 14:51:58 -0700142
143 // A+InterestLifetime
144 shared_ptr<Interest> interestK = make_shared<Interest>(*interestA);
145 interestK->setInterestLifetime(time::milliseconds(1000));
146 insertResult = pit.insert(*interestK);
Eric Newberryf4056d02017-05-26 17:31:53 +0000147 BOOST_CHECK_EQUAL(insertResult.second, false); // only guiders differ
148 BOOST_CHECK_EQUAL(pit.size(), 9);
Junxiao Shi30d35992014-04-03 14:51:58 -0700149
150 // A+Nonce
151 shared_ptr<Interest> interestL = make_shared<Interest>(*interestA);
152 interestL->setNonce(2192);
153 insertResult = pit.insert(*interestL);
Eric Newberryf4056d02017-05-26 17:31:53 +0000154 BOOST_CHECK_EQUAL(insertResult.second, false); // only guiders differ
155 BOOST_CHECK_EQUAL(pit.size(), 9);
Junxiao Shi30d35992014-04-03 14:51:58 -0700156
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 Newberryf4056d02017-05-26 17:31:53 +0000162 BOOST_CHECK_EQUAL(pit.size(), 10);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700163}
164
Haowei Yuan78c84d12014-02-27 15:35:13 -0600165BOOST_AUTO_TEST_CASE(Erase)
Junxiao Shicbba04c2014-01-26 14:21:22 -0700166{
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700167 shared_ptr<Interest> interest = makeInterest("/z88Admz6A2");
Junxiao Shicbba04c2014-01-26 14:21:22 -0700168
Haowei Yuan78c84d12014-02-27 15:35:13 -0600169 NameTree nameTree(16);
170 Pit pit(nameTree);
171
Junxiao Shi4846f372016-04-05 13:39:30 -0700172 std::pair<shared_ptr<Entry>, bool> insertResult;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700173
Haowei Yuan78c84d12014-02-27 15:35:13 -0600174 BOOST_CHECK_EQUAL(pit.size(), 0);
175
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700176 insertResult = pit.insert(*interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700177 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600178 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700179 BOOST_CHECK(pit.find(*interest) != nullptr);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700180
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700181 insertResult = pit.insert(*interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700182 BOOST_CHECK_EQUAL(insertResult.second, false);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600183 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700184 BOOST_CHECK(pit.find(*interest) != nullptr);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700185
Junxiao Shidbef6dc2016-08-15 02:58:36 +0000186 pit.erase(insertResult.first.get());
Haowei Yuan78c84d12014-02-27 15:35:13 -0600187 BOOST_CHECK_EQUAL(pit.size(), 0);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700188 BOOST_CHECK(pit.find(*interest) == nullptr);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700189
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700190 insertResult = pit.insert(*interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700191 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600192 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700193 BOOST_CHECK(pit.find(*interest) != nullptr);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600194}
Junxiao Shicbba04c2014-01-26 14:21:22 -0700195
Junxiao Shiee5a4442014-07-27 17:13:43 -0700196BOOST_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 Shi4846f372016-04-05 13:39:30 -0700203 shared_ptr<Entry> entry = pit.insert(*interest).first;
Junxiao Shidbef6dc2016-08-15 02:58:36 +0000204 pit.erase(entry.get());
Junxiao Shiee5a4442014-07-27 17:13:43 -0700205 BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
206}
207
spirosmastorakisff920302016-05-26 18:09:31 +0000208BOOST_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 Shidbef6dc2016-08-15 02:58:36 +0000227 pit.erase(pitEntry.get());
spirosmastorakisff920302016-05-26 18:09:31 +0000228 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 Shicbba04c2014-01-26 14:21:22 -0700236BOOST_AUTO_TEST_CASE(FindAllDataMatches)
237{
Haowei Yuane1079fc2014-03-08 14:41:25 -0600238 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 Afanasyev28d586a2014-07-10 20:10:54 -0700244 shared_ptr<Interest> interestA = makeInterest(nameA );
245 shared_ptr<Interest> interestABC = makeInterest(nameABC);
246 shared_ptr<Interest> interestD = makeInterest(nameD );
Junxiao Shicbba04c2014-01-26 14:21:22 -0700247
Haowei Yuan78c84d12014-02-27 15:35:13 -0600248 NameTree nameTree(16);
249 Pit pit(nameTree);
Haowei Yuane1079fc2014-03-08 14:41:25 -0600250 int count = 0;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700251
Haowei Yuan78c84d12014-02-27 15:35:13 -0600252 BOOST_CHECK_EQUAL(pit.size(), 0);
253
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700254 pit.insert(*interestA );
255 pit.insert(*interestABC);
256 pit.insert(*interestD );
Haowei Yuane1079fc2014-03-08 14:41:25 -0600257
258 nameTree.lookup(nameABCD); // make sure /A/B/C/D is in nameTree
Junxiao Shi57f0f312014-03-16 11:52:20 -0700259
Haowei Yuan78c84d12014-02-27 15:35:13 -0600260 BOOST_CHECK_EQUAL(pit.size(), 3);
261
Alexander Afanasyevc026d252014-06-16 11:14:15 -0700262 shared_ptr<Data> data = makeData(nameABCD);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700263
Junxiao Shi4846f372016-04-05 13:39:30 -0700264 DataMatchResult matches = pit.findAllDataMatches(*data);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700265
Haowei Yuane1079fc2014-03-08 14:41:25 -0600266 bool hasA = false;
267 bool hasAB = false;
268 bool hasABC = false;
269 bool hasD = false;
270
Junxiao Shi4846f372016-04-05 13:39:30 -0700271 for (const shared_ptr<Entry>& entry : matches) {
Junxiao Shicbba04c2014-01-26 14:21:22 -0700272 ++count;
Haowei Yuane1079fc2014-03-08 14:41:25 -0600273
274 if (entry->getName().equals(nameA ))
275 hasA = true;
276
277 if (entry->getName().equals(nameAB))
278 hasAB = true;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700279
Haowei Yuane1079fc2014-03-08 14:41:25 -0600280 if (entry->getName().equals(nameABC))
281 hasABC = true;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700282
Haowei Yuane1079fc2014-03-08 14:41:25 -0600283 if (entry->getName().equals(nameD))
284 hasD = true;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700285 }
Haowei Yuane1079fc2014-03-08 14:41:25 -0600286 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 Shicbba04c2014-01-26 14:21:22 -0700291 BOOST_CHECK_EQUAL(count, 2);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700292}
Haowei Yuane1079fc2014-03-08 14:41:25 -0600293
Junxiao Shi4370fde2016-02-24 12:20:46 -0700294BOOST_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 Shi4846f372016-04-05 13:39:30 -0700304 DataMatchResult matches = pit.findAllDataMatches(*data);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700305
306 BOOST_REQUIRE_EQUAL(std::distance(matches.begin(), matches.end()), 1);
Junxiao Shi4846f372016-04-05 13:39:30 -0700307 shared_ptr<Entry> found = *matches.begin();
Junxiao Shi4370fde2016-02-24 12:20:46 -0700308 BOOST_CHECK_EQUAL(found->getName(), fullName);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700309}
310
Junxiao Shi042a3312017-09-15 02:51:20 +0000311BOOST_AUTO_TEST_CASE(InsertMatchLongName)
312{
313 NameTree nameTree(16);
314 Pit pit(nameTree);
315
316 Name n1;
317 while (n1.size() < NameTree::getMaxDepth()) {
318 n1.append("A");
319 }
320 Name n2 = n1;
321 while (n2.size() < NameTree::getMaxDepth() * 2) {
322 n2.append("B");
323 }
324 Name n3 = n1;
325 while (n3.size() < NameTree::getMaxDepth() * 2) {
326 n3.append("C");
327 }
328 auto d2 = makeData(n2);
329 auto i2 = makeInterest(n2);
330 auto d3 = makeData(n3);
331 auto i3 = makeInterest(d3->getFullName());
332
333 shared_ptr<Entry> entry2 = pit.insert(*i2).first;
334 shared_ptr<Entry> entry3 = pit.insert(*i3).first;
335
336 BOOST_CHECK_EQUAL(pit.size(), 2);
337 BOOST_CHECK_EQUAL(nameTree.size(), 1 + NameTree::getMaxDepth()); // root node + max depth
338 BOOST_CHECK(entry2->getInterest().matchesInterest(*i2));
339 BOOST_CHECK(entry3->getInterest().matchesInterest(*i3));
340
341 DataMatchResult matches2 = pit.findAllDataMatches(*d2);
342 BOOST_REQUIRE_EQUAL(std::distance(matches2.begin(), matches2.end()), 1);
343 BOOST_CHECK(*matches2.begin() == entry2);
344 DataMatchResult matches3 = pit.findAllDataMatches(*d3);
345 BOOST_REQUIRE_EQUAL(std::distance(matches3.begin(), matches3.end()), 1);
346 BOOST_CHECK(*matches3.begin() == entry3);
347}
348
Alexander Afanasyev750fa1c2015-01-03 17:28:31 -0800349BOOST_AUTO_TEST_CASE(Iterator)
350{
351 NameTree nameTree(16);
352 Pit pit(nameTree);
353
354 shared_ptr<Interest> interestA = makeInterest("/A");
355 shared_ptr<Interest> interestABC1 = makeInterest("/A/B/C");
356 shared_ptr<Interest> interestABC2 = makeInterest("/A/B/C");
357 interestABC2->setSelectors(ndn::Selectors().setMinSuffixComponents(10));
358 shared_ptr<Interest> interestD = makeInterest("/D");
359
360 BOOST_CHECK_EQUAL(pit.size(), 0);
361 BOOST_CHECK(pit.begin() == pit.end());
362
363 pit.insert(*interestABC1);
364 BOOST_CHECK_EQUAL(pit.size(), 1);
365 BOOST_CHECK(pit.begin() != pit.end());
366 BOOST_CHECK(pit.begin()->getInterest() == *interestABC1);
367 BOOST_CHECK((*pit.begin()).getInterest() == *interestABC1);
368
369 auto i = pit.begin();
370 auto j = pit.begin();
371 BOOST_CHECK(++i == pit.end());
372 BOOST_CHECK(j++ == pit.begin());
373 BOOST_CHECK(j == pit.end());
374
375 pit.insert(*interestA);
376 pit.insert(*interestABC2);
377 pit.insert(*interestD);
378
379 std::set<const Interest*> expected = {&*interestA, &*interestABC1, &*interestABC2, &*interestD};
380 std::set<const Interest*> actual;
381 for (const auto& pitEntry : pit) {
382 actual.insert(&pitEntry.getInterest());
383 }
384 BOOST_CHECK(actual == expected);
385 for (auto actualIt = actual.begin(), expectedIt = expected.begin();
386 actualIt != actual.end() && expectedIt != expected.end(); ++actualIt, ++expectedIt) {
387 BOOST_CHECK_EQUAL(**actualIt, **expectedIt);
388 }
389}
390
Junxiao Shicbba04c2014-01-26 14:21:22 -0700391BOOST_AUTO_TEST_SUITE_END()
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700392BOOST_AUTO_TEST_SUITE_END()
Junxiao Shicbba04c2014-01-26 14:21:22 -0700393
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700394} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800395} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800396} // namespace nfd