blob: 17df2d77ce28aa727f3f59c71f7a0a9aa2017541 [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "table/pit.hpp"
Junxiao Shid9ee45c2014-02-27 15:38:11 -07008#include "tests/face/dummy-face.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -07009
Junxiao Shid9ee45c2014-02-27 15:38:11 -070010#include "tests/test-common.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070011
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080012namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070013namespace tests {
Junxiao Shicbba04c2014-01-26 14:21:22 -070014
Junxiao Shid9ee45c2014-02-27 15:38:11 -070015BOOST_FIXTURE_TEST_SUITE(TablePit, BaseFixture)
Junxiao Shicbba04c2014-01-26 14:21:22 -070016
Junxiao Shid3c792f2014-01-30 00:46:13 -070017BOOST_AUTO_TEST_CASE(EntryInOutRecords)
Junxiao Shicbba04c2014-01-26 14:21:22 -070018{
Junxiao Shi8c8d2182014-01-30 22:33:00 -070019 shared_ptr<Face> face1 = make_shared<DummyFace>();
20 shared_ptr<Face> face2 = make_shared<DummyFace>();
Junxiao Shicbba04c2014-01-26 14:21:22 -070021 Name name("ndn:/KuYfjtRq");
Junxiao Shif3c07812014-03-11 21:48:49 -070022 shared_ptr<Interest> interest = makeInterest(name);
23 shared_ptr<Interest> interest1 = makeInterest(name);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070024 interest1->setInterestLifetime(time::milliseconds(2528));
Junxiao Shif3c07812014-03-11 21:48:49 -070025 interest1->setNonce(25559);
26 shared_ptr<Interest> interest2 = makeInterest(name);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070027 interest2->setInterestLifetime(time::milliseconds(6464));
Junxiao Shif3c07812014-03-11 21:48:49 -070028 interest2->setNonce(19004);
29 shared_ptr<Interest> interest3 = makeInterest(name);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070030 interest3->setInterestLifetime(time::milliseconds(3585));
Junxiao Shif3c07812014-03-11 21:48:49 -070031 interest3->setNonce(24216);
32 shared_ptr<Interest> interest4 = makeInterest(name);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070033 interest4->setInterestLifetime(time::milliseconds(8795));
Junxiao Shif3c07812014-03-11 21:48:49 -070034 interest4->setNonce(17365);
Junxiao Shi57f0f312014-03-16 11:52:20 -070035
Junxiao Shif3c07812014-03-11 21:48:49 -070036 pit::Entry entry(*interest);
Junxiao Shi57f0f312014-03-16 11:52:20 -070037
Junxiao Shif3c07812014-03-11 21:48:49 -070038 BOOST_CHECK_EQUAL(entry.getInterest().getName(), name);
39 BOOST_CHECK_EQUAL(entry.getName(), name);
Haowei Yuan78c84d12014-02-27 15:35:13 -060040
Junxiao Shicbba04c2014-01-26 14:21:22 -070041 const pit::InRecordCollection& inRecords1 = entry.getInRecords();
42 BOOST_CHECK_EQUAL(inRecords1.size(), 0);
43 const pit::OutRecordCollection& outRecords1 = entry.getOutRecords();
44 BOOST_CHECK_EQUAL(outRecords1.size(), 0);
Junxiao Shi57f0f312014-03-16 11:52:20 -070045
Junxiao Shicbba04c2014-01-26 14:21:22 -070046 // insert InRecord
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070047 time::steady_clock::TimePoint before1 = time::steady_clock::now();
Junxiao Shicbba04c2014-01-26 14:21:22 -070048 pit::InRecordCollection::iterator in1 =
Junxiao Shif3c07812014-03-11 21:48:49 -070049 entry.insertOrUpdateInRecord(face1, *interest1);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070050 time::steady_clock::TimePoint after1 = time::steady_clock::now();
Junxiao Shicbba04c2014-01-26 14:21:22 -070051 const pit::InRecordCollection& inRecords2 = entry.getInRecords();
52 BOOST_CHECK_EQUAL(inRecords2.size(), 1);
53 BOOST_CHECK(in1 == inRecords2.begin());
54 BOOST_CHECK_EQUAL(in1->getFace(), face1);
Junxiao Shif3c07812014-03-11 21:48:49 -070055 BOOST_CHECK_EQUAL(in1->getLastNonce(), interest1->getNonce());
Junxiao Shicbba04c2014-01-26 14:21:22 -070056 BOOST_CHECK_GE(in1->getLastRenewed(), before1);
57 BOOST_CHECK_LE(in1->getLastRenewed(), after1);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070058 BOOST_CHECK_LE(in1->getExpiry() - in1->getLastRenewed()
59 - interest1->getInterestLifetime(),
60 (after1 - before1));
Junxiao Shi57f0f312014-03-16 11:52:20 -070061
Junxiao Shicbba04c2014-01-26 14:21:22 -070062 // insert OutRecord
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070063 time::steady_clock::TimePoint before2 = time::steady_clock::now();
Junxiao Shicbba04c2014-01-26 14:21:22 -070064 pit::OutRecordCollection::iterator out1 =
Junxiao Shif3c07812014-03-11 21:48:49 -070065 entry.insertOrUpdateOutRecord(face1, *interest1);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070066 time::steady_clock::TimePoint after2 = time::steady_clock::now();
Junxiao Shicbba04c2014-01-26 14:21:22 -070067 const pit::OutRecordCollection& outRecords2 = entry.getOutRecords();
68 BOOST_CHECK_EQUAL(outRecords2.size(), 1);
69 BOOST_CHECK(out1 == outRecords2.begin());
70 BOOST_CHECK_EQUAL(out1->getFace(), face1);
Junxiao Shif3c07812014-03-11 21:48:49 -070071 BOOST_CHECK_EQUAL(out1->getLastNonce(), interest1->getNonce());
Junxiao Shicbba04c2014-01-26 14:21:22 -070072 BOOST_CHECK_GE(out1->getLastRenewed(), before2);
73 BOOST_CHECK_LE(out1->getLastRenewed(), after2);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070074 BOOST_CHECK_LE(out1->getExpiry() - out1->getLastRenewed()
75 - interest1->getInterestLifetime(),
76 (after2 - before2));
Junxiao Shi57f0f312014-03-16 11:52:20 -070077
Junxiao Shicbba04c2014-01-26 14:21:22 -070078 // update InRecord
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070079 time::steady_clock::TimePoint before3 = time::steady_clock::now();
Junxiao Shicbba04c2014-01-26 14:21:22 -070080 pit::InRecordCollection::iterator in2 =
Junxiao Shif3c07812014-03-11 21:48:49 -070081 entry.insertOrUpdateInRecord(face1, *interest2);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070082 time::steady_clock::TimePoint after3 = time::steady_clock::now();
Junxiao Shicbba04c2014-01-26 14:21:22 -070083 const pit::InRecordCollection& inRecords3 = entry.getInRecords();
84 BOOST_CHECK_EQUAL(inRecords3.size(), 1);
85 BOOST_CHECK(in2 == inRecords3.begin());
86 BOOST_CHECK_EQUAL(in2->getFace(), face1);
Junxiao Shif3c07812014-03-11 21:48:49 -070087 BOOST_CHECK_EQUAL(in2->getLastNonce(), interest2->getNonce());
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070088 BOOST_CHECK_LE(in2->getExpiry() - in2->getLastRenewed()
89 - interest2->getInterestLifetime(),
90 (after3 - before3));
Junxiao Shicbba04c2014-01-26 14:21:22 -070091
Junxiao Shicbba04c2014-01-26 14:21:22 -070092 // insert another InRecord
93 pit::InRecordCollection::iterator in3 =
Junxiao Shif3c07812014-03-11 21:48:49 -070094 entry.insertOrUpdateInRecord(face2, *interest3);
Junxiao Shicbba04c2014-01-26 14:21:22 -070095 const pit::InRecordCollection& inRecords4 = entry.getInRecords();
96 BOOST_CHECK_EQUAL(inRecords4.size(), 2);
97 BOOST_CHECK_EQUAL(in3->getFace(), face2);
Junxiao Shi57f0f312014-03-16 11:52:20 -070098
Junxiao Shicbba04c2014-01-26 14:21:22 -070099 // delete all InRecords
100 entry.deleteInRecords();
101 const pit::InRecordCollection& inRecords5 = entry.getInRecords();
102 BOOST_CHECK_EQUAL(inRecords5.size(), 0);
103
Junxiao Shicbba04c2014-01-26 14:21:22 -0700104 // insert another OutRecord
105 pit::OutRecordCollection::iterator out2 =
Junxiao Shif3c07812014-03-11 21:48:49 -0700106 entry.insertOrUpdateOutRecord(face2, *interest4);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700107 const pit::OutRecordCollection& outRecords3 = entry.getOutRecords();
108 BOOST_CHECK_EQUAL(outRecords3.size(), 2);
109 BOOST_CHECK_EQUAL(out2->getFace(), face2);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700110
Junxiao Shicbba04c2014-01-26 14:21:22 -0700111 // delete OutRecord
112 entry.deleteOutRecord(face2);
113 const pit::OutRecordCollection& outRecords4 = entry.getOutRecords();
114 BOOST_REQUIRE_EQUAL(outRecords4.size(), 1);
115 BOOST_CHECK_EQUAL(outRecords4.begin()->getFace(), face1);
Junxiao Shid3c792f2014-01-30 00:46:13 -0700116}
117
118BOOST_AUTO_TEST_CASE(EntryNonce)
119{
Junxiao Shi57f0f312014-03-16 11:52:20 -0700120 shared_ptr<Interest> interest = makeInterest("ndn:/qtCQ7I1c");
121
122 pit::Entry entry(*interest);
123
Junxiao Shid3c792f2014-01-30 00:46:13 -0700124 BOOST_CHECK_EQUAL(entry.addNonce(25559), true);
125 BOOST_CHECK_EQUAL(entry.addNonce(25559), false);
126 BOOST_CHECK_EQUAL(entry.addNonce(19004), true);
127 BOOST_CHECK_EQUAL(entry.addNonce(19004), false);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700128}
129
Junxiao Shi57f0f312014-03-16 11:52:20 -0700130BOOST_AUTO_TEST_CASE(EntryLifetime)
131{
132 shared_ptr<Interest> interest = makeInterest("ndn:/7oIEurbgy6");
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700133 BOOST_ASSERT(interest->getInterestLifetime() < time::milliseconds::zero()); // library uses -1 to indicate unset lifetime
Junxiao Shi57f0f312014-03-16 11:52:20 -0700134
135 shared_ptr<Face> face = make_shared<DummyFace>();
136 pit::Entry entry(*interest);
137
138 pit::InRecordCollection::iterator inIt = entry.insertOrUpdateInRecord(face, *interest);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700139 BOOST_CHECK_GT(inIt->getExpiry(), time::steady_clock::now());
Junxiao Shi57f0f312014-03-16 11:52:20 -0700140
141 pit::OutRecordCollection::iterator outIt = entry.insertOrUpdateOutRecord(face, *interest);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700142 BOOST_CHECK_GT(outIt->getExpiry(), time::steady_clock::now());
Junxiao Shi57f0f312014-03-16 11:52:20 -0700143}
144
145BOOST_AUTO_TEST_CASE(EntryCanForwardTo)
146{
147 shared_ptr<Interest> interest = makeInterest("ndn:/WDsuBLIMG");
148 pit::Entry entry(*interest);
149
150 shared_ptr<Face> face1 = make_shared<DummyFace>();
151 shared_ptr<Face> face2 = make_shared<DummyFace>();
152
153 entry.insertOrUpdateInRecord(face1, *interest);
154 BOOST_CHECK_EQUAL(entry.canForwardTo(*face1), false);
155 BOOST_CHECK_EQUAL(entry.canForwardTo(*face2), true);
156
157 entry.insertOrUpdateInRecord(face2, *interest);
158 BOOST_CHECK_EQUAL(entry.canForwardTo(*face1), true);
159 BOOST_CHECK_EQUAL(entry.canForwardTo(*face2), true);
160
161 entry.insertOrUpdateOutRecord(face1, *interest);
162 BOOST_CHECK_EQUAL(entry.canForwardTo(*face1), false);
163 BOOST_CHECK_EQUAL(entry.canForwardTo(*face2), true);
164}
165
Junxiao Shicbba04c2014-01-26 14:21:22 -0700166BOOST_AUTO_TEST_CASE(Insert)
167{
168 Name name1("ndn:/5vzBNnMst");
169 Name name2("ndn:/igSGfEIM62");
170 Exclude exclude0;
171 Exclude exclude1;
172 exclude1.excludeOne(Name::Component("u26p47oep"));
173 Exclude exclude2;
174 exclude2.excludeOne(Name::Component("FG1Ni6nYcf"));
175
176 // base
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700177 Interest interestA(name1, -1, -1, exclude0, -1, false, -1, time::milliseconds::min(), 0);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700178 // A+exclude1
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700179 Interest interestB(name1, -1, -1, exclude1, -1, false, -1, time::milliseconds::min(), 0);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700180 // A+exclude2
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700181 Interest interestC(name1, -1, -1, exclude2, -1, false, -1, time::milliseconds::min(), 0);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700182 // A+MinSuffixComponents
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700183 Interest interestD(name1, 2, -1, exclude0, -1, false, -1, time::milliseconds::min(), 0);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700184 // A+MaxSuffixComponents
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700185 Interest interestE(name1, -1, 4, exclude0, -1, false, -1, time::milliseconds::min(), 0);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700186 // A+ChildSelector
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700187 Interest interestF(name1, -1, -1, exclude0, 1, false, -1, time::milliseconds::min(), 0);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700188 // A+MustBeFresh
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700189 Interest interestG(name1, -1, -1, exclude0, -1, true, -1, time::milliseconds::min(), 0);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700190 // A+Scope
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700191 Interest interestH(name1, -1, -1, exclude0, -1, false, 2, time::milliseconds::min(), 0);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700192 // A+InterestLifetime
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700193 Interest interestI(name1, -1, -1, exclude0, -1, false, -1, time::milliseconds(2000), 0);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700194 // A+Nonce
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700195 Interest interestJ(name1, -1, -1, exclude0, -1, false, -1, time::milliseconds::min(), 2192);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700196 // different Name+exclude1
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700197 Interest interestK(name2, -1, -1, exclude1, -1, false, -1, time::milliseconds::min(), 0);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700198
Haowei Yuan78c84d12014-02-27 15:35:13 -0600199 NameTree nameTree(16);
200 Pit pit(nameTree);
201
Junxiao Shicbba04c2014-01-26 14:21:22 -0700202 std::pair<shared_ptr<pit::Entry>, bool> insertResult;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700203
Haowei Yuan78c84d12014-02-27 15:35:13 -0600204 BOOST_CHECK_EQUAL(pit.size(), 0);
205
Junxiao Shicbba04c2014-01-26 14:21:22 -0700206 insertResult = pit.insert(interestA);
207 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600208 BOOST_CHECK_EQUAL(pit.size(), 1);
209
Junxiao Shicbba04c2014-01-26 14:21:22 -0700210 insertResult = pit.insert(interestB);
211 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600212 BOOST_CHECK_EQUAL(pit.size(), 2);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700213
Junxiao Shicbba04c2014-01-26 14:21:22 -0700214 insertResult = pit.insert(interestC);
215 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600216 BOOST_CHECK_EQUAL(pit.size(), 3);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700217
Junxiao Shicbba04c2014-01-26 14:21:22 -0700218 insertResult = pit.insert(interestD);
219 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600220 BOOST_CHECK_EQUAL(pit.size(), 4);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700221
Junxiao Shicbba04c2014-01-26 14:21:22 -0700222 insertResult = pit.insert(interestE);
223 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600224 BOOST_CHECK_EQUAL(pit.size(), 5);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700225
Junxiao Shicbba04c2014-01-26 14:21:22 -0700226 insertResult = pit.insert(interestF);
227 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600228 BOOST_CHECK_EQUAL(pit.size(), 6);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700229
Junxiao Shicbba04c2014-01-26 14:21:22 -0700230 insertResult = pit.insert(interestG);
231 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600232 BOOST_CHECK_EQUAL(pit.size(), 7);
233
Junxiao Shi57f0f312014-03-16 11:52:20 -0700234
Junxiao Shicbba04c2014-01-26 14:21:22 -0700235 insertResult = pit.insert(interestH);
236 BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ
Haowei Yuan78c84d12014-02-27 15:35:13 -0600237 BOOST_CHECK_EQUAL(pit.size(), 7);
238
Junxiao Shicbba04c2014-01-26 14:21:22 -0700239 insertResult = pit.insert(interestI);
240 BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ
Haowei Yuan78c84d12014-02-27 15:35:13 -0600241 BOOST_CHECK_EQUAL(pit.size(), 7);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700242
Junxiao Shicbba04c2014-01-26 14:21:22 -0700243 insertResult = pit.insert(interestJ);
244 BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ
Haowei Yuan78c84d12014-02-27 15:35:13 -0600245 BOOST_CHECK_EQUAL(pit.size(), 7);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700246
Junxiao Shicbba04c2014-01-26 14:21:22 -0700247 insertResult = pit.insert(interestK);
248 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600249 BOOST_CHECK_EQUAL(pit.size(), 8);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700250}
251
Haowei Yuan78c84d12014-02-27 15:35:13 -0600252BOOST_AUTO_TEST_CASE(Erase)
Junxiao Shicbba04c2014-01-26 14:21:22 -0700253{
254 Interest interest(Name("ndn:/z88Admz6A2"));
255
Haowei Yuan78c84d12014-02-27 15:35:13 -0600256 NameTree nameTree(16);
257 Pit pit(nameTree);
258
Junxiao Shicbba04c2014-01-26 14:21:22 -0700259 std::pair<shared_ptr<pit::Entry>, bool> insertResult;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700260
Haowei Yuan78c84d12014-02-27 15:35:13 -0600261 BOOST_CHECK_EQUAL(pit.size(), 0);
262
Junxiao Shicbba04c2014-01-26 14:21:22 -0700263 insertResult = pit.insert(interest);
264 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600265 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700266
267 insertResult = pit.insert(interest);
268 BOOST_CHECK_EQUAL(insertResult.second, false);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600269 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700270
Haowei Yuan78c84d12014-02-27 15:35:13 -0600271 pit.erase(insertResult.first);
272 BOOST_CHECK_EQUAL(pit.size(), 0);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700273
274 insertResult = pit.insert(interest);
275 BOOST_CHECK_EQUAL(insertResult.second, true);
Haowei Yuan78c84d12014-02-27 15:35:13 -0600276 BOOST_CHECK_EQUAL(pit.size(), 1);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700277
Haowei Yuan78c84d12014-02-27 15:35:13 -0600278}
Junxiao Shicbba04c2014-01-26 14:21:22 -0700279
280BOOST_AUTO_TEST_CASE(FindAllDataMatches)
281{
Haowei Yuane1079fc2014-03-08 14:41:25 -0600282 Name nameA ("ndn:/A");
283 Name nameAB ("ndn:/A/B");
284 Name nameABC ("ndn:/A/B/C");
285 Name nameABCD("ndn:/A/B/C/D");
286 Name nameD ("ndn:/D");
287
288 Interest interestA (nameA );
289 Interest interestABC(nameABC);
290 Interest interestD (nameD );
Junxiao Shicbba04c2014-01-26 14:21:22 -0700291
Haowei Yuan78c84d12014-02-27 15:35:13 -0600292 NameTree nameTree(16);
293 Pit pit(nameTree);
Haowei Yuane1079fc2014-03-08 14:41:25 -0600294 int count = 0;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700295
Haowei Yuan78c84d12014-02-27 15:35:13 -0600296 BOOST_CHECK_EQUAL(pit.size(), 0);
297
Haowei Yuane1079fc2014-03-08 14:41:25 -0600298 pit.insert(interestA );
299 pit.insert(interestABC);
300 pit.insert(interestD );
301
302 nameTree.lookup(nameABCD); // make sure /A/B/C/D is in nameTree
Junxiao Shi57f0f312014-03-16 11:52:20 -0700303
Haowei Yuan78c84d12014-02-27 15:35:13 -0600304 BOOST_CHECK_EQUAL(pit.size(), 3);
305
Haowei Yuane1079fc2014-03-08 14:41:25 -0600306 Data data(nameABCD);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700307
Junxiao Shicbba04c2014-01-26 14:21:22 -0700308 shared_ptr<pit::DataMatchResult> matches = pit.findAllDataMatches(data);
Junxiao Shi57f0f312014-03-16 11:52:20 -0700309
Haowei Yuane1079fc2014-03-08 14:41:25 -0600310 bool hasA = false;
311 bool hasAB = false;
312 bool hasABC = false;
313 bool hasD = false;
314
Junxiao Shicbba04c2014-01-26 14:21:22 -0700315 for (pit::DataMatchResult::iterator it = matches->begin();
316 it != matches->end(); ++it) {
317 ++count;
318 shared_ptr<pit::Entry> entry = *it;
Haowei Yuane1079fc2014-03-08 14:41:25 -0600319
320 if (entry->getName().equals(nameA ))
321 hasA = true;
322
323 if (entry->getName().equals(nameAB))
324 hasAB = true;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700325
Haowei Yuane1079fc2014-03-08 14:41:25 -0600326 if (entry->getName().equals(nameABC))
327 hasABC = true;
Junxiao Shi57f0f312014-03-16 11:52:20 -0700328
Haowei Yuane1079fc2014-03-08 14:41:25 -0600329 if (entry->getName().equals(nameD))
330 hasD = true;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700331 }
Haowei Yuane1079fc2014-03-08 14:41:25 -0600332 BOOST_CHECK_EQUAL(hasA , true);
333 BOOST_CHECK_EQUAL(hasAB , false);
334 BOOST_CHECK_EQUAL(hasABC, true);
335 BOOST_CHECK_EQUAL(hasD , false);
336
Junxiao Shicbba04c2014-01-26 14:21:22 -0700337 BOOST_CHECK_EQUAL(count, 2);
Haowei Yuane1079fc2014-03-08 14:41:25 -0600338
Junxiao Shicbba04c2014-01-26 14:21:22 -0700339}
340
341BOOST_AUTO_TEST_SUITE_END()
342
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700343} // namespace tests
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800344} // namespace nfd