blob: 511f2aa6f84a632afacccbeabb8c4cadbb23eb3e [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 Pesavento87fc0f82018-04-11 23:43:51 -04003 * Copyright (c) 2014-2018, 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
Davide Pesavento87fc0f82018-04-11 23:43:51 -040028#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shid9ee45c2014-02-27 15:38:11 -070029#include "tests/test-common.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070030
Davide Pesavento87fc0f82018-04-11 23:43:51 -040031#include <ndn-cxx/exclude.hpp>
32
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080033namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080034namespace pit {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070035namespace tests {
Junxiao Shicbba04c2014-01-26 14:21:22 -070036
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080037using namespace nfd::tests;
38
Junxiao Shi5e5e4452015-09-24 16:56:52 -070039BOOST_AUTO_TEST_SUITE(Table)
40BOOST_FIXTURE_TEST_SUITE(TestPit, BaseFixture)
Junxiao Shicbba04c2014-01-26 14:21:22 -070041
Junxiao Shi28797792016-05-26 18:10:18 +000042BOOST_AUTO_TEST_CASE(Find)
43{
44 shared_ptr<Interest> interest1 = makeInterest("/6hNwxJjw");
45 shared_ptr<Interest> interest2 = makeInterest("/v65zqxm4d");
46
47 NameTree nameTree(16);
48 Pit pit(nameTree);
49
50 pit.insert(*interest1);
51 shared_ptr<pit::Entry> found1a = pit.find(*interest1);
52 shared_ptr<pit::Entry> found1b = pit.find(*interest1);
53 BOOST_CHECK(found1a != nullptr);
54 BOOST_CHECK(found1a == found1b);
55
56 shared_ptr<pit::Entry> found2 = pit.find(*interest2);
57 BOOST_CHECK(found2 == nullptr);
58 BOOST_CHECK(nameTree.findExactMatch(interest2->getName()) == nullptr);
59}
60
Junxiao Shicbba04c2014-01-26 14:21:22 -070061BOOST_AUTO_TEST_CASE(Insert)
62{
63 Name name1("ndn:/5vzBNnMst");
64 Name name2("ndn:/igSGfEIM62");
Davide Pesavento87fc0f82018-04-11 23:43:51 -040065 ndn::Exclude exclude1;
Junxiao Shicbba04c2014-01-26 14:21:22 -070066 exclude1.excludeOne(Name::Component("u26p47oep"));
Davide Pesavento87fc0f82018-04-11 23:43:51 -040067 ndn::Exclude exclude2;
Junxiao Shi30d35992014-04-03 14:51:58 -070068 exclude2.excludeBefore(Name::Component("u26p47oep"));
69 ndn::KeyLocator keyLocator1("ndn:/sGAE3peMHA");
70 ndn::KeyLocator keyLocator2("ndn:/nIJH6pr4");
Junxiao Shi57f0f312014-03-16 11:52:20 -070071
Haowei Yuan78c84d12014-02-27 15:35:13 -060072 NameTree nameTree(16);
73 Pit pit(nameTree);
Junxiao Shi30d35992014-04-03 14:51:58 -070074 BOOST_CHECK_EQUAL(pit.size(), 0);
Junxiao Shi4846f372016-04-05 13:39:30 -070075 std::pair<shared_ptr<Entry>, bool> insertResult;
Junxiao Shi57f0f312014-03-16 11:52:20 -070076
Junxiao Shi30d35992014-04-03 14:51:58 -070077 // base
78 shared_ptr<Interest> interestA = make_shared<Interest>(name1);
79 insertResult = pit.insert(*interestA);
Junxiao Shicbba04c2014-01-26 14:21:22 -070080 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -060081 BOOST_CHECK_EQUAL(pit.size(), 1);
82
Eric Newberryf4056d02017-05-26 17:31:53 +000083 // same as A
84 shared_ptr<Interest> interestA2 = make_shared<Interest>(*interestA);
85 insertResult = pit.insert(*interestA2);
86 BOOST_CHECK_EQUAL(insertResult.second, false); // sharing the same PIT entry
87 BOOST_CHECK_EQUAL(pit.size(), 1);
88
Junxiao Shi30d35992014-04-03 14:51:58 -070089 // A+MinSuffixComponents
90 shared_ptr<Interest> interestB = make_shared<Interest>(*interestA);
91 interestB->setMinSuffixComponents(2);
92 insertResult = pit.insert(*interestB);
Junxiao Shicbba04c2014-01-26 14:21:22 -070093 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -060094 BOOST_CHECK_EQUAL(pit.size(), 2);
Junxiao Shi57f0f312014-03-16 11:52:20 -070095
Junxiao Shi30d35992014-04-03 14:51:58 -070096 // A+MaxSuffixComponents
97 shared_ptr<Interest> interestC = make_shared<Interest>(*interestA);
98 interestC->setMaxSuffixComponents(4);
99 insertResult = pit.insert(*interestC);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700100 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600101 BOOST_CHECK_EQUAL(pit.size(), 3);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700102
Junxiao Shi30d35992014-04-03 14:51:58 -0700103 // A+KeyLocator1
104 shared_ptr<Interest> interestD = make_shared<Interest>(*interestA);
105 interestD->setPublisherPublicKeyLocator(keyLocator1);
106 insertResult = pit.insert(*interestD);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700107 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600108 BOOST_CHECK_EQUAL(pit.size(), 4);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700109
Junxiao Shi30d35992014-04-03 14:51:58 -0700110 // A+KeyLocator2
111 shared_ptr<Interest> interestE = make_shared<Interest>(*interestA);
112 interestE->setPublisherPublicKeyLocator(keyLocator2);
113 insertResult = pit.insert(*interestE);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700114 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600115 BOOST_CHECK_EQUAL(pit.size(), 5);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700116
Junxiao Shi30d35992014-04-03 14:51:58 -0700117 // A+Exclude1
118 shared_ptr<Interest> interestF = make_shared<Interest>(*interestA);
119 interestF->setExclude(exclude1);
120 insertResult = pit.insert(*interestF);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700121 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600122 BOOST_CHECK_EQUAL(pit.size(), 6);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700123
Junxiao Shi30d35992014-04-03 14:51:58 -0700124 // A+Exclude2
125 shared_ptr<Interest> interestG = make_shared<Interest>(*interestA);
126 interestG->setExclude(exclude2);
127 insertResult = pit.insert(*interestG);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700128 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600129 BOOST_CHECK_EQUAL(pit.size(), 7);
130
Junxiao Shi30d35992014-04-03 14:51:58 -0700131 // A+ChildSelector1
132 shared_ptr<Interest> interestI = make_shared<Interest>(*interestA);
133 interestI->setChildSelector(1);
134 insertResult = pit.insert(*interestI);
135 BOOST_CHECK_EQUAL(insertResult.second, true);
Eric Newberryf4056d02017-05-26 17:31:53 +0000136 BOOST_CHECK_EQUAL(pit.size(), 8);
Junxiao Shi30d35992014-04-03 14:51:58 -0700137
138 // A+MustBeFresh
139 shared_ptr<Interest> interestJ = make_shared<Interest>(*interestA);
140 interestJ->setMustBeFresh(true);
141 insertResult = pit.insert(*interestJ);
142 BOOST_CHECK_EQUAL(insertResult.second, true);
Eric Newberryf4056d02017-05-26 17:31:53 +0000143 BOOST_CHECK_EQUAL(pit.size(), 9);
Junxiao Shi30d35992014-04-03 14:51:58 -0700144
145 // A+InterestLifetime
146 shared_ptr<Interest> interestK = make_shared<Interest>(*interestA);
147 interestK->setInterestLifetime(time::milliseconds(1000));
148 insertResult = pit.insert(*interestK);
Eric Newberryf4056d02017-05-26 17:31:53 +0000149 BOOST_CHECK_EQUAL(insertResult.second, false); // only guiders differ
150 BOOST_CHECK_EQUAL(pit.size(), 9);
Junxiao Shi30d35992014-04-03 14:51:58 -0700151
152 // A+Nonce
153 shared_ptr<Interest> interestL = make_shared<Interest>(*interestA);
154 interestL->setNonce(2192);
155 insertResult = pit.insert(*interestL);
Eric Newberryf4056d02017-05-26 17:31:53 +0000156 BOOST_CHECK_EQUAL(insertResult.second, false); // only guiders differ
157 BOOST_CHECK_EQUAL(pit.size(), 9);
Junxiao Shi30d35992014-04-03 14:51:58 -0700158
159 // different Name+Exclude1
160 shared_ptr<Interest> interestM = make_shared<Interest>(name2);
161 interestM->setExclude(exclude1);
162 insertResult = pit.insert(*interestM);
163 BOOST_CHECK_EQUAL(insertResult.second, true);
Eric Newberryf4056d02017-05-26 17:31:53 +0000164 BOOST_CHECK_EQUAL(pit.size(), 10);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700165}
166
Haowei Yuan78c84d12014-02-27 15:35:13 -0600167BOOST_AUTO_TEST_CASE(Erase)
Junxiao Shicbba04c2014-01-26 14:21:22 -0700168{
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700169 shared_ptr<Interest> interest = makeInterest("/z88Admz6A2");
Junxiao Shicbba04c2014-01-26 14:21:22 -0700170
Haowei Yuan78c84d12014-02-27 15:35:13 -0600171 NameTree nameTree(16);
172 Pit pit(nameTree);
173
Junxiao Shi4846f372016-04-05 13:39:30 -0700174 std::pair<shared_ptr<Entry>, bool> insertResult;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700175
Haowei Yuan78c84d12014-02-27 15:35:13 -0600176 BOOST_CHECK_EQUAL(pit.size(), 0);
177
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700178 insertResult = pit.insert(*interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700179 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600180 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700181 BOOST_CHECK(pit.find(*interest) != nullptr);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700182
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700183 insertResult = pit.insert(*interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700184 BOOST_CHECK_EQUAL(insertResult.second, false);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600185 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700186 BOOST_CHECK(pit.find(*interest) != nullptr);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700187
Junxiao Shidbef6dc2016-08-15 02:58:36 +0000188 pit.erase(insertResult.first.get());
Haowei Yuan78c84d12014-02-27 15:35:13 -0600189 BOOST_CHECK_EQUAL(pit.size(), 0);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700190 BOOST_CHECK(pit.find(*interest) == nullptr);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700191
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700192 insertResult = pit.insert(*interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700193 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600194 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700195 BOOST_CHECK(pit.find(*interest) != nullptr);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600196}
Junxiao Shicbba04c2014-01-26 14:21:22 -0700197
Junxiao Shiee5a4442014-07-27 17:13:43 -0700198BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)
199{
200 NameTree nameTree;
201 Pit pit(nameTree);
202 size_t nNameTreeEntriesBefore = nameTree.size();
203
204 shared_ptr<Interest> interest = makeInterest("/37xWVvQ2K");
Junxiao Shi4846f372016-04-05 13:39:30 -0700205 shared_ptr<Entry> entry = pit.insert(*interest).first;
Junxiao Shidbef6dc2016-08-15 02:58:36 +0000206 pit.erase(entry.get());
Junxiao Shiee5a4442014-07-27 17:13:43 -0700207 BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
208}
209
spirosmastorakisff920302016-05-26 18:09:31 +0000210BOOST_AUTO_TEST_CASE(EraseWithFullName)
211{
212 shared_ptr<Data> data = makeData("/test");
213 shared_ptr<Interest> interest = makeInterest(data->getFullName());
214
215 NameTree nameTree(16);
216 Pit pit(nameTree);
217
218 BOOST_CHECK_EQUAL(pit.size(), 0);
219
220 BOOST_CHECK_EQUAL(pit.insert(*interest).second, true);
221 BOOST_CHECK_EQUAL(pit.size(), 1);
222 BOOST_CHECK(pit.find(*interest) != nullptr);
223
224 BOOST_CHECK_EQUAL(pit.insert(*interest).second, false);
225 BOOST_CHECK_EQUAL(pit.size(), 1);
226 shared_ptr<pit::Entry> pitEntry = pit.find(*interest);
227 BOOST_REQUIRE(pitEntry != nullptr);
228
Junxiao Shidbef6dc2016-08-15 02:58:36 +0000229 pit.erase(pitEntry.get());
spirosmastorakisff920302016-05-26 18:09:31 +0000230 BOOST_CHECK_EQUAL(pit.size(), 0);
231 BOOST_CHECK(pit.find(*interest) == nullptr);
232
233 BOOST_CHECK_EQUAL(pit.insert(*interest).second, true);
234 BOOST_CHECK_EQUAL(pit.size(), 1);
235 BOOST_CHECK(pit.find(*interest) != nullptr);
236}
237
Junxiao Shicbba04c2014-01-26 14:21:22 -0700238BOOST_AUTO_TEST_CASE(FindAllDataMatches)
239{
Haowei Yuane1079fc2014-03-08 14:41:25 -0600240 Name nameA ("ndn:/A");
241 Name nameAB ("ndn:/A/B");
242 Name nameABC ("ndn:/A/B/C");
243 Name nameABCD("ndn:/A/B/C/D");
244 Name nameD ("ndn:/D");
245
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700246 shared_ptr<Interest> interestA = makeInterest(nameA );
247 shared_ptr<Interest> interestABC = makeInterest(nameABC);
248 shared_ptr<Interest> interestD = makeInterest(nameD );
Junxiao Shicbba04c2014-01-26 14:21:22 -0700249
Haowei Yuan78c84d12014-02-27 15:35:13 -0600250 NameTree nameTree(16);
251 Pit pit(nameTree);
Haowei Yuane1079fc2014-03-08 14:41:25 -0600252 int count = 0;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700253
Haowei Yuan78c84d12014-02-27 15:35:13 -0600254 BOOST_CHECK_EQUAL(pit.size(), 0);
255
Alexander Afanasyev28d586a2014-07-10 20:10:54 -0700256 pit.insert(*interestA );
257 pit.insert(*interestABC);
258 pit.insert(*interestD );
Haowei Yuane1079fc2014-03-08 14:41:25 -0600259
260 nameTree.lookup(nameABCD); // make sure /A/B/C/D is in nameTree
Junxiao Shi57f0f312014-03-16 11:52:20 -0700261
Haowei Yuan78c84d12014-02-27 15:35:13 -0600262 BOOST_CHECK_EQUAL(pit.size(), 3);
263
Alexander Afanasyevc026d252014-06-16 11:14:15 -0700264 shared_ptr<Data> data = makeData(nameABCD);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700265
Junxiao Shi4846f372016-04-05 13:39:30 -0700266 DataMatchResult matches = pit.findAllDataMatches(*data);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700267
Haowei Yuane1079fc2014-03-08 14:41:25 -0600268 bool hasA = false;
269 bool hasAB = false;
270 bool hasABC = false;
271 bool hasD = false;
272
Junxiao Shi4846f372016-04-05 13:39:30 -0700273 for (const shared_ptr<Entry>& entry : matches) {
Junxiao Shicbba04c2014-01-26 14:21:22 -0700274 ++count;
Haowei Yuane1079fc2014-03-08 14:41:25 -0600275
276 if (entry->getName().equals(nameA ))
277 hasA = true;
278
279 if (entry->getName().equals(nameAB))
280 hasAB = true;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700281
Haowei Yuane1079fc2014-03-08 14:41:25 -0600282 if (entry->getName().equals(nameABC))
283 hasABC = true;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700284
Haowei Yuane1079fc2014-03-08 14:41:25 -0600285 if (entry->getName().equals(nameD))
286 hasD = true;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700287 }
Haowei Yuane1079fc2014-03-08 14:41:25 -0600288 BOOST_CHECK_EQUAL(hasA , true);
289 BOOST_CHECK_EQUAL(hasAB , false);
290 BOOST_CHECK_EQUAL(hasABC, true);
291 BOOST_CHECK_EQUAL(hasD , false);
292
Junxiao Shicbba04c2014-01-26 14:21:22 -0700293 BOOST_CHECK_EQUAL(count, 2);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700294}
Haowei Yuane1079fc2014-03-08 14:41:25 -0600295
Junxiao Shi4370fde2016-02-24 12:20:46 -0700296BOOST_AUTO_TEST_CASE(MatchFullName) // Bug 3363
297{
298 NameTree nameTree(16);
299 Pit pit(nameTree);
300
301 shared_ptr<Data> data = makeData("/A");
302 Name fullName = data->getFullName();
303 shared_ptr<Interest> interest = makeInterest(fullName);
304
305 pit.insert(*interest);
Junxiao Shi4846f372016-04-05 13:39:30 -0700306 DataMatchResult matches = pit.findAllDataMatches(*data);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700307
308 BOOST_REQUIRE_EQUAL(std::distance(matches.begin(), matches.end()), 1);
Junxiao Shi4846f372016-04-05 13:39:30 -0700309 shared_ptr<Entry> found = *matches.begin();
Junxiao Shi4370fde2016-02-24 12:20:46 -0700310 BOOST_CHECK_EQUAL(found->getName(), fullName);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700311}
312
Junxiao Shi042a3312017-09-15 02:51:20 +0000313BOOST_AUTO_TEST_CASE(InsertMatchLongName)
314{
315 NameTree nameTree(16);
316 Pit pit(nameTree);
317
318 Name n1;
319 while (n1.size() < NameTree::getMaxDepth()) {
320 n1.append("A");
321 }
322 Name n2 = n1;
323 while (n2.size() < NameTree::getMaxDepth() * 2) {
324 n2.append("B");
325 }
326 Name n3 = n1;
327 while (n3.size() < NameTree::getMaxDepth() * 2) {
328 n3.append("C");
329 }
330 auto d2 = makeData(n2);
331 auto i2 = makeInterest(n2);
332 auto d3 = makeData(n3);
333 auto i3 = makeInterest(d3->getFullName());
334
335 shared_ptr<Entry> entry2 = pit.insert(*i2).first;
336 shared_ptr<Entry> entry3 = pit.insert(*i3).first;
337
338 BOOST_CHECK_EQUAL(pit.size(), 2);
339 BOOST_CHECK_EQUAL(nameTree.size(), 1 + NameTree::getMaxDepth()); // root node + max depth
340 BOOST_CHECK(entry2->getInterest().matchesInterest(*i2));
341 BOOST_CHECK(entry3->getInterest().matchesInterest(*i3));
342
343 DataMatchResult matches2 = pit.findAllDataMatches(*d2);
344 BOOST_REQUIRE_EQUAL(std::distance(matches2.begin(), matches2.end()), 1);
345 BOOST_CHECK(*matches2.begin() == entry2);
346 DataMatchResult matches3 = pit.findAllDataMatches(*d3);
347 BOOST_REQUIRE_EQUAL(std::distance(matches3.begin(), matches3.end()), 1);
348 BOOST_CHECK(*matches3.begin() == entry3);
349}
350
Alexander Afanasyev750fa1c2015-01-03 17:28:31 -0800351BOOST_AUTO_TEST_CASE(Iterator)
352{
353 NameTree nameTree(16);
354 Pit pit(nameTree);
355
356 shared_ptr<Interest> interestA = makeInterest("/A");
357 shared_ptr<Interest> interestABC1 = makeInterest("/A/B/C");
358 shared_ptr<Interest> interestABC2 = makeInterest("/A/B/C");
359 interestABC2->setSelectors(ndn::Selectors().setMinSuffixComponents(10));
360 shared_ptr<Interest> interestD = makeInterest("/D");
361
362 BOOST_CHECK_EQUAL(pit.size(), 0);
363 BOOST_CHECK(pit.begin() == pit.end());
364
365 pit.insert(*interestABC1);
366 BOOST_CHECK_EQUAL(pit.size(), 1);
367 BOOST_CHECK(pit.begin() != pit.end());
368 BOOST_CHECK(pit.begin()->getInterest() == *interestABC1);
369 BOOST_CHECK((*pit.begin()).getInterest() == *interestABC1);
370
371 auto i = pit.begin();
372 auto j = pit.begin();
373 BOOST_CHECK(++i == pit.end());
374 BOOST_CHECK(j++ == pit.begin());
375 BOOST_CHECK(j == pit.end());
376
377 pit.insert(*interestA);
378 pit.insert(*interestABC2);
379 pit.insert(*interestD);
380
381 std::set<const Interest*> expected = {&*interestA, &*interestABC1, &*interestABC2, &*interestD};
382 std::set<const Interest*> actual;
383 for (const auto& pitEntry : pit) {
384 actual.insert(&pitEntry.getInterest());
385 }
386 BOOST_CHECK(actual == expected);
387 for (auto actualIt = actual.begin(), expectedIt = expected.begin();
388 actualIt != actual.end() && expectedIt != expected.end(); ++actualIt, ++expectedIt) {
389 BOOST_CHECK_EQUAL(**actualIt, **expectedIt);
390 }
391}
392
Junxiao Shicbba04c2014-01-26 14:21:22 -0700393BOOST_AUTO_TEST_SUITE_END()
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700394BOOST_AUTO_TEST_SUITE_END()
Junxiao Shicbba04c2014-01-26 14:21:22 -0700395
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700396} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800397} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800398} // namespace nfd