blob: c77c909cd55624a142b629f3b9b3c0faade6d45e [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 Regents of the University of California,
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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Junxiao Shicbba04c2014-01-26 14:21:22 -070024
25#include "table/pit.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070027
Junxiao Shid9ee45c2014-02-27 15:38:11 -070028#include "tests/test-common.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070029
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080030namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070031namespace tests {
Junxiao Shicbba04c2014-01-26 14:21:22 -070032
Junxiao Shid9ee45c2014-02-27 15:38:11 -070033BOOST_FIXTURE_TEST_SUITE(TablePit, BaseFixture)
Junxiao Shicbba04c2014-01-26 14:21:22 -070034
Junxiao Shid3c792f2014-01-30 00:46:13 -070035BOOST_AUTO_TEST_CASE(EntryInOutRecords)
Junxiao Shicbba04c2014-01-26 14:21:22 -070036{
Junxiao Shi8c8d2182014-01-30 22:33:00 -070037 shared_ptr<Face> face1 = make_shared<DummyFace>();
38 shared_ptr<Face> face2 = make_shared<DummyFace>();
Junxiao Shicbba04c2014-01-26 14:21:22 -070039 Name name("ndn:/KuYfjtRq");
Junxiao Shif3c07812014-03-11 21:48:49 -070040 shared_ptr<Interest> interest = makeInterest(name);
41 shared_ptr<Interest> interest1 = makeInterest(name);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070042 interest1->setInterestLifetime(time::milliseconds(2528));
Junxiao Shif3c07812014-03-11 21:48:49 -070043 interest1->setNonce(25559);
44 shared_ptr<Interest> interest2 = makeInterest(name);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070045 interest2->setInterestLifetime(time::milliseconds(6464));
Junxiao Shif3c07812014-03-11 21:48:49 -070046 interest2->setNonce(19004);
47 shared_ptr<Interest> interest3 = makeInterest(name);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070048 interest3->setInterestLifetime(time::milliseconds(3585));
Junxiao Shif3c07812014-03-11 21:48:49 -070049 interest3->setNonce(24216);
50 shared_ptr<Interest> interest4 = makeInterest(name);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070051 interest4->setInterestLifetime(time::milliseconds(8795));
Junxiao Shif3c07812014-03-11 21:48:49 -070052 interest4->setNonce(17365);
Junxiao Shi57f0f312014-03-16 11:52:20 -070053
Junxiao Shif3c07812014-03-11 21:48:49 -070054 pit::Entry entry(*interest);
Junxiao Shi57f0f312014-03-16 11:52:20 -070055
Junxiao Shif3c07812014-03-11 21:48:49 -070056 BOOST_CHECK_EQUAL(entry.getInterest().getName(), name);
57 BOOST_CHECK_EQUAL(entry.getName(), name);
Haowei Yuan78c84d12014-02-27 15:35:13 -060058
Junxiao Shicbba04c2014-01-26 14:21:22 -070059 const pit::InRecordCollection& inRecords1 = entry.getInRecords();
60 BOOST_CHECK_EQUAL(inRecords1.size(), 0);
61 const pit::OutRecordCollection& outRecords1 = entry.getOutRecords();
62 BOOST_CHECK_EQUAL(outRecords1.size(), 0);
Junxiao Shi57f0f312014-03-16 11:52:20 -070063
Junxiao Shicbba04c2014-01-26 14:21:22 -070064 // insert InRecord
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070065 time::steady_clock::TimePoint before1 = time::steady_clock::now();
Junxiao Shicbba04c2014-01-26 14:21:22 -070066 pit::InRecordCollection::iterator in1 =
Junxiao Shif3c07812014-03-11 21:48:49 -070067 entry.insertOrUpdateInRecord(face1, *interest1);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070068 time::steady_clock::TimePoint after1 = time::steady_clock::now();
Junxiao Shicbba04c2014-01-26 14:21:22 -070069 const pit::InRecordCollection& inRecords2 = entry.getInRecords();
70 BOOST_CHECK_EQUAL(inRecords2.size(), 1);
71 BOOST_CHECK(in1 == inRecords2.begin());
72 BOOST_CHECK_EQUAL(in1->getFace(), face1);
Junxiao Shif3c07812014-03-11 21:48:49 -070073 BOOST_CHECK_EQUAL(in1->getLastNonce(), interest1->getNonce());
Junxiao Shicbba04c2014-01-26 14:21:22 -070074 BOOST_CHECK_GE(in1->getLastRenewed(), before1);
75 BOOST_CHECK_LE(in1->getLastRenewed(), after1);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070076 BOOST_CHECK_LE(in1->getExpiry() - in1->getLastRenewed()
77 - interest1->getInterestLifetime(),
78 (after1 - before1));
Junxiao Shi57f0f312014-03-16 11:52:20 -070079
Junxiao Shicbba04c2014-01-26 14:21:22 -070080 // insert OutRecord
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070081 time::steady_clock::TimePoint before2 = time::steady_clock::now();
Junxiao Shicbba04c2014-01-26 14:21:22 -070082 pit::OutRecordCollection::iterator out1 =
Junxiao Shif3c07812014-03-11 21:48:49 -070083 entry.insertOrUpdateOutRecord(face1, *interest1);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070084 time::steady_clock::TimePoint after2 = time::steady_clock::now();
Junxiao Shicbba04c2014-01-26 14:21:22 -070085 const pit::OutRecordCollection& outRecords2 = entry.getOutRecords();
86 BOOST_CHECK_EQUAL(outRecords2.size(), 1);
87 BOOST_CHECK(out1 == outRecords2.begin());
88 BOOST_CHECK_EQUAL(out1->getFace(), face1);
Junxiao Shif3c07812014-03-11 21:48:49 -070089 BOOST_CHECK_EQUAL(out1->getLastNonce(), interest1->getNonce());
Junxiao Shicbba04c2014-01-26 14:21:22 -070090 BOOST_CHECK_GE(out1->getLastRenewed(), before2);
91 BOOST_CHECK_LE(out1->getLastRenewed(), after2);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070092 BOOST_CHECK_LE(out1->getExpiry() - out1->getLastRenewed()
93 - interest1->getInterestLifetime(),
94 (after2 - before2));
Junxiao Shi57f0f312014-03-16 11:52:20 -070095
Junxiao Shicbba04c2014-01-26 14:21:22 -070096 // update InRecord
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070097 time::steady_clock::TimePoint before3 = time::steady_clock::now();
Junxiao Shicbba04c2014-01-26 14:21:22 -070098 pit::InRecordCollection::iterator in2 =
Junxiao Shif3c07812014-03-11 21:48:49 -070099 entry.insertOrUpdateInRecord(face1, *interest2);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700100 time::steady_clock::TimePoint after3 = time::steady_clock::now();
Junxiao Shicbba04c2014-01-26 14:21:22 -0700101 const pit::InRecordCollection& inRecords3 = entry.getInRecords();
102 BOOST_CHECK_EQUAL(inRecords3.size(), 1);
103 BOOST_CHECK(in2 == inRecords3.begin());
104 BOOST_CHECK_EQUAL(in2->getFace(), face1);
Junxiao Shif3c07812014-03-11 21:48:49 -0700105 BOOST_CHECK_EQUAL(in2->getLastNonce(), interest2->getNonce());
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700106 BOOST_CHECK_LE(in2->getExpiry() - in2->getLastRenewed()
107 - interest2->getInterestLifetime(),
108 (after3 - before3));
Junxiao Shicbba04c2014-01-26 14:21:22 -0700109
Junxiao Shicbba04c2014-01-26 14:21:22 -0700110 // insert another InRecord
111 pit::InRecordCollection::iterator in3 =
Junxiao Shif3c07812014-03-11 21:48:49 -0700112 entry.insertOrUpdateInRecord(face2, *interest3);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700113 const pit::InRecordCollection& inRecords4 = entry.getInRecords();
114 BOOST_CHECK_EQUAL(inRecords4.size(), 2);
115 BOOST_CHECK_EQUAL(in3->getFace(), face2);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700116
Junxiao Shicbba04c2014-01-26 14:21:22 -0700117 // delete all InRecords
118 entry.deleteInRecords();
119 const pit::InRecordCollection& inRecords5 = entry.getInRecords();
120 BOOST_CHECK_EQUAL(inRecords5.size(), 0);
121
Junxiao Shicbba04c2014-01-26 14:21:22 -0700122 // insert another OutRecord
123 pit::OutRecordCollection::iterator out2 =
Junxiao Shif3c07812014-03-11 21:48:49 -0700124 entry.insertOrUpdateOutRecord(face2, *interest4);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700125 const pit::OutRecordCollection& outRecords3 = entry.getOutRecords();
126 BOOST_CHECK_EQUAL(outRecords3.size(), 2);
127 BOOST_CHECK_EQUAL(out2->getFace(), face2);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700128
Junxiao Shicbba04c2014-01-26 14:21:22 -0700129 // delete OutRecord
130 entry.deleteOutRecord(face2);
131 const pit::OutRecordCollection& outRecords4 = entry.getOutRecords();
132 BOOST_REQUIRE_EQUAL(outRecords4.size(), 1);
133 BOOST_CHECK_EQUAL(outRecords4.begin()->getFace(), face1);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700134}
135
136BOOST_AUTO_TEST_CASE(EntryNonce)
137{
Junxiao Shi57f0f312014-03-16 11:52:20 -0700138 shared_ptr<Interest> interest = makeInterest("ndn:/qtCQ7I1c");
139
140 pit::Entry entry(*interest);
141
Junxiao Shid3c792f2014-01-30 00:46:13 -0700142 BOOST_CHECK_EQUAL(entry.addNonce(25559), true);
143 BOOST_CHECK_EQUAL(entry.addNonce(25559), false);
144 BOOST_CHECK_EQUAL(entry.addNonce(19004), true);
145 BOOST_CHECK_EQUAL(entry.addNonce(19004), false);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700146}
147
Junxiao Shi57f0f312014-03-16 11:52:20 -0700148BOOST_AUTO_TEST_CASE(EntryLifetime)
149{
150 shared_ptr<Interest> interest = makeInterest("ndn:/7oIEurbgy6");
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700151 BOOST_ASSERT(interest->getInterestLifetime() < time::milliseconds::zero()); // library uses -1 to indicate unset lifetime
Junxiao Shi57f0f312014-03-16 11:52:20 -0700152
153 shared_ptr<Face> face = make_shared<DummyFace>();
154 pit::Entry entry(*interest);
155
156 pit::InRecordCollection::iterator inIt = entry.insertOrUpdateInRecord(face, *interest);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700157 BOOST_CHECK_GT(inIt->getExpiry(), time::steady_clock::now());
Junxiao Shi57f0f312014-03-16 11:52:20 -0700158
159 pit::OutRecordCollection::iterator outIt = entry.insertOrUpdateOutRecord(face, *interest);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700160 BOOST_CHECK_GT(outIt->getExpiry(), time::steady_clock::now());
Junxiao Shi57f0f312014-03-16 11:52:20 -0700161}
162
163BOOST_AUTO_TEST_CASE(EntryCanForwardTo)
164{
165 shared_ptr<Interest> interest = makeInterest("ndn:/WDsuBLIMG");
166 pit::Entry entry(*interest);
167
168 shared_ptr<Face> face1 = make_shared<DummyFace>();
169 shared_ptr<Face> face2 = make_shared<DummyFace>();
170
171 entry.insertOrUpdateInRecord(face1, *interest);
172 BOOST_CHECK_EQUAL(entry.canForwardTo(*face1), false);
173 BOOST_CHECK_EQUAL(entry.canForwardTo(*face2), true);
174
175 entry.insertOrUpdateInRecord(face2, *interest);
176 BOOST_CHECK_EQUAL(entry.canForwardTo(*face1), true);
177 BOOST_CHECK_EQUAL(entry.canForwardTo(*face2), true);
178
179 entry.insertOrUpdateOutRecord(face1, *interest);
180 BOOST_CHECK_EQUAL(entry.canForwardTo(*face1), false);
181 BOOST_CHECK_EQUAL(entry.canForwardTo(*face2), true);
182}
183
Junxiao Shicbba04c2014-01-26 14:21:22 -0700184BOOST_AUTO_TEST_CASE(Insert)
185{
186 Name name1("ndn:/5vzBNnMst");
187 Name name2("ndn:/igSGfEIM62");
Junxiao Shicbba04c2014-01-26 14:21:22 -0700188 Exclude exclude1;
189 exclude1.excludeOne(Name::Component("u26p47oep"));
190 Exclude exclude2;
Junxiao Shi30d35992014-04-03 14:51:58 -0700191 exclude2.excludeBefore(Name::Component("u26p47oep"));
192 ndn::KeyLocator keyLocator1("ndn:/sGAE3peMHA");
193 ndn::KeyLocator keyLocator2("ndn:/nIJH6pr4");
Junxiao Shi57f0f312014-03-16 11:52:20 -0700194
Haowei Yuan78c84d12014-02-27 15:35:13 -0600195 NameTree nameTree(16);
196 Pit pit(nameTree);
Junxiao Shi30d35992014-04-03 14:51:58 -0700197 BOOST_CHECK_EQUAL(pit.size(), 0);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700198 std::pair<shared_ptr<pit::Entry>, bool> insertResult;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700199
Junxiao Shi30d35992014-04-03 14:51:58 -0700200 // base
201 shared_ptr<Interest> interestA = make_shared<Interest>(name1);
202 insertResult = pit.insert(*interestA);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700203 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600204 BOOST_CHECK_EQUAL(pit.size(), 1);
205
Junxiao Shi30d35992014-04-03 14:51:58 -0700206 // A+MinSuffixComponents
207 shared_ptr<Interest> interestB = make_shared<Interest>(*interestA);
208 interestB->setMinSuffixComponents(2);
209 insertResult = pit.insert(*interestB);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700210 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600211 BOOST_CHECK_EQUAL(pit.size(), 2);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700212
Junxiao Shi30d35992014-04-03 14:51:58 -0700213 // A+MaxSuffixComponents
214 shared_ptr<Interest> interestC = make_shared<Interest>(*interestA);
215 interestC->setMaxSuffixComponents(4);
216 insertResult = pit.insert(*interestC);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700217 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600218 BOOST_CHECK_EQUAL(pit.size(), 3);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700219
Junxiao Shi30d35992014-04-03 14:51:58 -0700220 // A+KeyLocator1
221 shared_ptr<Interest> interestD = make_shared<Interest>(*interestA);
222 interestD->setPublisherPublicKeyLocator(keyLocator1);
223 insertResult = pit.insert(*interestD);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700224 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600225 BOOST_CHECK_EQUAL(pit.size(), 4);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700226
Junxiao Shi30d35992014-04-03 14:51:58 -0700227 // A+KeyLocator2
228 shared_ptr<Interest> interestE = make_shared<Interest>(*interestA);
229 interestE->setPublisherPublicKeyLocator(keyLocator2);
230 insertResult = pit.insert(*interestE);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700231 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600232 BOOST_CHECK_EQUAL(pit.size(), 5);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700233
Junxiao Shi30d35992014-04-03 14:51:58 -0700234 // A+Exclude1
235 shared_ptr<Interest> interestF = make_shared<Interest>(*interestA);
236 interestF->setExclude(exclude1);
237 insertResult = pit.insert(*interestF);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700238 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600239 BOOST_CHECK_EQUAL(pit.size(), 6);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700240
Junxiao Shi30d35992014-04-03 14:51:58 -0700241 // A+Exclude2
242 shared_ptr<Interest> interestG = make_shared<Interest>(*interestA);
243 interestG->setExclude(exclude2);
244 insertResult = pit.insert(*interestG);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700245 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600246 BOOST_CHECK_EQUAL(pit.size(), 7);
247
Junxiao Shi30d35992014-04-03 14:51:58 -0700248 // A+ChildSelector0
249 shared_ptr<Interest> interestH = make_shared<Interest>(*interestA);
250 interestH->setChildSelector(0);
251 insertResult = pit.insert(*interestH);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700252 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600253 BOOST_CHECK_EQUAL(pit.size(), 8);
Junxiao Shi30d35992014-04-03 14:51:58 -0700254
255 // A+ChildSelector1
256 shared_ptr<Interest> interestI = make_shared<Interest>(*interestA);
257 interestI->setChildSelector(1);
258 insertResult = pit.insert(*interestI);
259 BOOST_CHECK_EQUAL(insertResult.second, true);
260 BOOST_CHECK_EQUAL(pit.size(), 9);
261
262 // A+MustBeFresh
263 shared_ptr<Interest> interestJ = make_shared<Interest>(*interestA);
264 interestJ->setMustBeFresh(true);
265 insertResult = pit.insert(*interestJ);
266 BOOST_CHECK_EQUAL(insertResult.second, true);
267 BOOST_CHECK_EQUAL(pit.size(), 10);
268
269 // A+InterestLifetime
270 shared_ptr<Interest> interestK = make_shared<Interest>(*interestA);
271 interestK->setInterestLifetime(time::milliseconds(1000));
272 insertResult = pit.insert(*interestK);
273 BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ
274 BOOST_CHECK_EQUAL(pit.size(), 10);
275
276 // A+Nonce
277 shared_ptr<Interest> interestL = make_shared<Interest>(*interestA);
278 interestL->setNonce(2192);
279 insertResult = pit.insert(*interestL);
280 BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ
281 BOOST_CHECK_EQUAL(pit.size(), 10);
282
283 // different Name+Exclude1
284 shared_ptr<Interest> interestM = make_shared<Interest>(name2);
285 interestM->setExclude(exclude1);
286 insertResult = pit.insert(*interestM);
287 BOOST_CHECK_EQUAL(insertResult.second, true);
288 BOOST_CHECK_EQUAL(pit.size(), 11);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700289}
290
Haowei Yuan78c84d12014-02-27 15:35:13 -0600291BOOST_AUTO_TEST_CASE(Erase)
Junxiao Shicbba04c2014-01-26 14:21:22 -0700292{
293 Interest interest(Name("ndn:/z88Admz6A2"));
294
Haowei Yuan78c84d12014-02-27 15:35:13 -0600295 NameTree nameTree(16);
296 Pit pit(nameTree);
297
Junxiao Shicbba04c2014-01-26 14:21:22 -0700298 std::pair<shared_ptr<pit::Entry>, bool> insertResult;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700299
Haowei Yuan78c84d12014-02-27 15:35:13 -0600300 BOOST_CHECK_EQUAL(pit.size(), 0);
301
Junxiao Shicbba04c2014-01-26 14:21:22 -0700302 insertResult = pit.insert(interest);
303 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600304 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700305
306 insertResult = pit.insert(interest);
307 BOOST_CHECK_EQUAL(insertResult.second, false);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600308 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700309
Haowei Yuan78c84d12014-02-27 15:35:13 -0600310 pit.erase(insertResult.first);
311 BOOST_CHECK_EQUAL(pit.size(), 0);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700312
313 insertResult = pit.insert(interest);
314 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600315 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700316
Haowei Yuan78c84d12014-02-27 15:35:13 -0600317}
Junxiao Shicbba04c2014-01-26 14:21:22 -0700318
319BOOST_AUTO_TEST_CASE(FindAllDataMatches)
320{
Haowei Yuane1079fc2014-03-08 14:41:25 -0600321 Name nameA ("ndn:/A");
322 Name nameAB ("ndn:/A/B");
323 Name nameABC ("ndn:/A/B/C");
324 Name nameABCD("ndn:/A/B/C/D");
325 Name nameD ("ndn:/D");
326
327 Interest interestA (nameA );
328 Interest interestABC(nameABC);
329 Interest interestD (nameD );
Junxiao Shicbba04c2014-01-26 14:21:22 -0700330
Haowei Yuan78c84d12014-02-27 15:35:13 -0600331 NameTree nameTree(16);
332 Pit pit(nameTree);
Haowei Yuane1079fc2014-03-08 14:41:25 -0600333 int count = 0;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700334
Haowei Yuan78c84d12014-02-27 15:35:13 -0600335 BOOST_CHECK_EQUAL(pit.size(), 0);
336
Haowei Yuane1079fc2014-03-08 14:41:25 -0600337 pit.insert(interestA );
338 pit.insert(interestABC);
339 pit.insert(interestD );
340
341 nameTree.lookup(nameABCD); // make sure /A/B/C/D is in nameTree
Junxiao Shi57f0f312014-03-16 11:52:20 -0700342
Haowei Yuan78c84d12014-02-27 15:35:13 -0600343 BOOST_CHECK_EQUAL(pit.size(), 3);
344
Haowei Yuane1079fc2014-03-08 14:41:25 -0600345 Data data(nameABCD);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700346
Junxiao Shicbba04c2014-01-26 14:21:22 -0700347 shared_ptr<pit::DataMatchResult> matches = pit.findAllDataMatches(data);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700348
Haowei Yuane1079fc2014-03-08 14:41:25 -0600349 bool hasA = false;
350 bool hasAB = false;
351 bool hasABC = false;
352 bool hasD = false;
353
Junxiao Shicbba04c2014-01-26 14:21:22 -0700354 for (pit::DataMatchResult::iterator it = matches->begin();
355 it != matches->end(); ++it) {
356 ++count;
357 shared_ptr<pit::Entry> entry = *it;
Haowei Yuane1079fc2014-03-08 14:41:25 -0600358
359 if (entry->getName().equals(nameA ))
360 hasA = true;
361
362 if (entry->getName().equals(nameAB))
363 hasAB = true;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700364
Haowei Yuane1079fc2014-03-08 14:41:25 -0600365 if (entry->getName().equals(nameABC))
366 hasABC = true;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700367
Haowei Yuane1079fc2014-03-08 14:41:25 -0600368 if (entry->getName().equals(nameD))
369 hasD = true;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700370 }
Haowei Yuane1079fc2014-03-08 14:41:25 -0600371 BOOST_CHECK_EQUAL(hasA , true);
372 BOOST_CHECK_EQUAL(hasAB , false);
373 BOOST_CHECK_EQUAL(hasABC, true);
374 BOOST_CHECK_EQUAL(hasD , false);
375
Junxiao Shicbba04c2014-01-26 14:21:22 -0700376 BOOST_CHECK_EQUAL(count, 2);
Haowei Yuane1079fc2014-03-08 14:41:25 -0600377
Junxiao Shicbba04c2014-01-26 14:21:22 -0700378}
379
380BOOST_AUTO_TEST_SUITE_END()
381
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700382} // namespace tests
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800383} // namespace nfd