Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame^] | 3 | * 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 Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 24 | |
| 25 | #include "table/pit.hpp" |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 26 | #include "tests/face/dummy-face.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 27 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 28 | #include "tests/test-common.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 30 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 31 | namespace tests { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 32 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 33 | BOOST_FIXTURE_TEST_SUITE(TablePit, BaseFixture) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 34 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 35 | BOOST_AUTO_TEST_CASE(EntryInOutRecords) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 36 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 37 | shared_ptr<Face> face1 = make_shared<DummyFace>(); |
| 38 | shared_ptr<Face> face2 = make_shared<DummyFace>(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 39 | Name name("ndn:/KuYfjtRq"); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 40 | shared_ptr<Interest> interest = makeInterest(name); |
| 41 | shared_ptr<Interest> interest1 = makeInterest(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 42 | interest1->setInterestLifetime(time::milliseconds(2528)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 43 | interest1->setNonce(25559); |
| 44 | shared_ptr<Interest> interest2 = makeInterest(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 45 | interest2->setInterestLifetime(time::milliseconds(6464)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 46 | interest2->setNonce(19004); |
| 47 | shared_ptr<Interest> interest3 = makeInterest(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 48 | interest3->setInterestLifetime(time::milliseconds(3585)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 49 | interest3->setNonce(24216); |
| 50 | shared_ptr<Interest> interest4 = makeInterest(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 51 | interest4->setInterestLifetime(time::milliseconds(8795)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 52 | interest4->setNonce(17365); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 53 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 54 | pit::Entry entry(*interest); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 55 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 56 | BOOST_CHECK_EQUAL(entry.getInterest().getName(), name); |
| 57 | BOOST_CHECK_EQUAL(entry.getName(), name); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 58 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 59 | 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 Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 63 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 64 | // insert InRecord |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 65 | time::steady_clock::TimePoint before1 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 66 | pit::InRecordCollection::iterator in1 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 67 | entry.insertOrUpdateInRecord(face1, *interest1); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 68 | time::steady_clock::TimePoint after1 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 69 | 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 Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 73 | BOOST_CHECK_EQUAL(in1->getLastNonce(), interest1->getNonce()); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 74 | BOOST_CHECK_GE(in1->getLastRenewed(), before1); |
| 75 | BOOST_CHECK_LE(in1->getLastRenewed(), after1); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 76 | BOOST_CHECK_LE(in1->getExpiry() - in1->getLastRenewed() |
| 77 | - interest1->getInterestLifetime(), |
| 78 | (after1 - before1)); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 79 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 80 | // insert OutRecord |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 81 | time::steady_clock::TimePoint before2 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 82 | pit::OutRecordCollection::iterator out1 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 83 | entry.insertOrUpdateOutRecord(face1, *interest1); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 84 | time::steady_clock::TimePoint after2 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 85 | 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 Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 89 | BOOST_CHECK_EQUAL(out1->getLastNonce(), interest1->getNonce()); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 90 | BOOST_CHECK_GE(out1->getLastRenewed(), before2); |
| 91 | BOOST_CHECK_LE(out1->getLastRenewed(), after2); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 92 | BOOST_CHECK_LE(out1->getExpiry() - out1->getLastRenewed() |
| 93 | - interest1->getInterestLifetime(), |
| 94 | (after2 - before2)); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 95 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 96 | // update InRecord |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 97 | time::steady_clock::TimePoint before3 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 98 | pit::InRecordCollection::iterator in2 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 99 | entry.insertOrUpdateInRecord(face1, *interest2); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 100 | time::steady_clock::TimePoint after3 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 101 | 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 Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 105 | BOOST_CHECK_EQUAL(in2->getLastNonce(), interest2->getNonce()); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 106 | BOOST_CHECK_LE(in2->getExpiry() - in2->getLastRenewed() |
| 107 | - interest2->getInterestLifetime(), |
| 108 | (after3 - before3)); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 109 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 110 | // insert another InRecord |
| 111 | pit::InRecordCollection::iterator in3 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 112 | entry.insertOrUpdateInRecord(face2, *interest3); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 113 | const pit::InRecordCollection& inRecords4 = entry.getInRecords(); |
| 114 | BOOST_CHECK_EQUAL(inRecords4.size(), 2); |
| 115 | BOOST_CHECK_EQUAL(in3->getFace(), face2); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 116 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 117 | // delete all InRecords |
| 118 | entry.deleteInRecords(); |
| 119 | const pit::InRecordCollection& inRecords5 = entry.getInRecords(); |
| 120 | BOOST_CHECK_EQUAL(inRecords5.size(), 0); |
| 121 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 122 | // insert another OutRecord |
| 123 | pit::OutRecordCollection::iterator out2 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 124 | entry.insertOrUpdateOutRecord(face2, *interest4); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 125 | const pit::OutRecordCollection& outRecords3 = entry.getOutRecords(); |
| 126 | BOOST_CHECK_EQUAL(outRecords3.size(), 2); |
| 127 | BOOST_CHECK_EQUAL(out2->getFace(), face2); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 128 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 129 | // 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 Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | BOOST_AUTO_TEST_CASE(EntryNonce) |
| 137 | { |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 138 | shared_ptr<Interest> interest = makeInterest("ndn:/qtCQ7I1c"); |
| 139 | |
| 140 | pit::Entry entry(*interest); |
| 141 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 142 | 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 Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 148 | BOOST_AUTO_TEST_CASE(EntryLifetime) |
| 149 | { |
| 150 | shared_ptr<Interest> interest = makeInterest("ndn:/7oIEurbgy6"); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 151 | BOOST_ASSERT(interest->getInterestLifetime() < time::milliseconds::zero()); // library uses -1 to indicate unset lifetime |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 152 | |
| 153 | shared_ptr<Face> face = make_shared<DummyFace>(); |
| 154 | pit::Entry entry(*interest); |
| 155 | |
| 156 | pit::InRecordCollection::iterator inIt = entry.insertOrUpdateInRecord(face, *interest); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 157 | BOOST_CHECK_GT(inIt->getExpiry(), time::steady_clock::now()); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 158 | |
| 159 | pit::OutRecordCollection::iterator outIt = entry.insertOrUpdateOutRecord(face, *interest); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 160 | BOOST_CHECK_GT(outIt->getExpiry(), time::steady_clock::now()); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | BOOST_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 Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 184 | BOOST_AUTO_TEST_CASE(Insert) |
| 185 | { |
| 186 | Name name1("ndn:/5vzBNnMst"); |
| 187 | Name name2("ndn:/igSGfEIM62"); |
| 188 | Exclude exclude0; |
| 189 | Exclude exclude1; |
| 190 | exclude1.excludeOne(Name::Component("u26p47oep")); |
| 191 | Exclude exclude2; |
| 192 | exclude2.excludeOne(Name::Component("FG1Ni6nYcf")); |
| 193 | |
| 194 | // base |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 195 | Interest interestA(name1, -1, -1, exclude0, -1, false, -1, time::milliseconds::min(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 196 | // A+exclude1 |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 197 | Interest interestB(name1, -1, -1, exclude1, -1, false, -1, time::milliseconds::min(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 198 | // A+exclude2 |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 199 | Interest interestC(name1, -1, -1, exclude2, -1, false, -1, time::milliseconds::min(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 200 | // A+MinSuffixComponents |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 201 | Interest interestD(name1, 2, -1, exclude0, -1, false, -1, time::milliseconds::min(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 202 | // A+MaxSuffixComponents |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 203 | Interest interestE(name1, -1, 4, exclude0, -1, false, -1, time::milliseconds::min(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 204 | // A+ChildSelector |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 205 | Interest interestF(name1, -1, -1, exclude0, 1, false, -1, time::milliseconds::min(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 206 | // A+MustBeFresh |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 207 | Interest interestG(name1, -1, -1, exclude0, -1, true, -1, time::milliseconds::min(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 208 | // A+Scope |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 209 | Interest interestH(name1, -1, -1, exclude0, -1, false, 2, time::milliseconds::min(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 210 | // A+InterestLifetime |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 211 | Interest interestI(name1, -1, -1, exclude0, -1, false, -1, time::milliseconds(2000), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 212 | // A+Nonce |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 213 | Interest interestJ(name1, -1, -1, exclude0, -1, false, -1, time::milliseconds::min(), 2192); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 214 | // different Name+exclude1 |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 215 | Interest interestK(name2, -1, -1, exclude1, -1, false, -1, time::milliseconds::min(), 0); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 216 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 217 | NameTree nameTree(16); |
| 218 | Pit pit(nameTree); |
| 219 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 220 | std::pair<shared_ptr<pit::Entry>, bool> insertResult; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 221 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 222 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 223 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 224 | insertResult = pit.insert(interestA); |
| 225 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 226 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 227 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 228 | insertResult = pit.insert(interestB); |
| 229 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 230 | BOOST_CHECK_EQUAL(pit.size(), 2); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 231 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 232 | insertResult = pit.insert(interestC); |
| 233 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 234 | BOOST_CHECK_EQUAL(pit.size(), 3); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 235 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 236 | insertResult = pit.insert(interestD); |
| 237 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 238 | BOOST_CHECK_EQUAL(pit.size(), 4); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 239 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 240 | insertResult = pit.insert(interestE); |
| 241 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 242 | BOOST_CHECK_EQUAL(pit.size(), 5); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 243 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 244 | insertResult = pit.insert(interestF); |
| 245 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 246 | BOOST_CHECK_EQUAL(pit.size(), 6); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 247 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 248 | insertResult = pit.insert(interestG); |
| 249 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 250 | BOOST_CHECK_EQUAL(pit.size(), 7); |
| 251 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 252 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 253 | insertResult = pit.insert(interestH); |
| 254 | BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 255 | BOOST_CHECK_EQUAL(pit.size(), 7); |
| 256 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 257 | insertResult = pit.insert(interestI); |
| 258 | BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 259 | BOOST_CHECK_EQUAL(pit.size(), 7); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 260 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 261 | insertResult = pit.insert(interestJ); |
| 262 | BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 263 | BOOST_CHECK_EQUAL(pit.size(), 7); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 264 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 265 | insertResult = pit.insert(interestK); |
| 266 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 267 | BOOST_CHECK_EQUAL(pit.size(), 8); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 270 | BOOST_AUTO_TEST_CASE(Erase) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 271 | { |
| 272 | Interest interest(Name("ndn:/z88Admz6A2")); |
| 273 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 274 | NameTree nameTree(16); |
| 275 | Pit pit(nameTree); |
| 276 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 277 | std::pair<shared_ptr<pit::Entry>, bool> insertResult; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 278 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 279 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 280 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 281 | insertResult = pit.insert(interest); |
| 282 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 283 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 284 | |
| 285 | insertResult = pit.insert(interest); |
| 286 | BOOST_CHECK_EQUAL(insertResult.second, false); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 287 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 288 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 289 | pit.erase(insertResult.first); |
| 290 | BOOST_CHECK_EQUAL(pit.size(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 291 | |
| 292 | insertResult = pit.insert(interest); |
| 293 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 294 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 295 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 296 | } |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 297 | |
| 298 | BOOST_AUTO_TEST_CASE(FindAllDataMatches) |
| 299 | { |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 300 | Name nameA ("ndn:/A"); |
| 301 | Name nameAB ("ndn:/A/B"); |
| 302 | Name nameABC ("ndn:/A/B/C"); |
| 303 | Name nameABCD("ndn:/A/B/C/D"); |
| 304 | Name nameD ("ndn:/D"); |
| 305 | |
| 306 | Interest interestA (nameA ); |
| 307 | Interest interestABC(nameABC); |
| 308 | Interest interestD (nameD ); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 309 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 310 | NameTree nameTree(16); |
| 311 | Pit pit(nameTree); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 312 | int count = 0; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 313 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 314 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 315 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 316 | pit.insert(interestA ); |
| 317 | pit.insert(interestABC); |
| 318 | pit.insert(interestD ); |
| 319 | |
| 320 | nameTree.lookup(nameABCD); // make sure /A/B/C/D is in nameTree |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 321 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 322 | BOOST_CHECK_EQUAL(pit.size(), 3); |
| 323 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 324 | Data data(nameABCD); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 325 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 326 | shared_ptr<pit::DataMatchResult> matches = pit.findAllDataMatches(data); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 327 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 328 | bool hasA = false; |
| 329 | bool hasAB = false; |
| 330 | bool hasABC = false; |
| 331 | bool hasD = false; |
| 332 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 333 | for (pit::DataMatchResult::iterator it = matches->begin(); |
| 334 | it != matches->end(); ++it) { |
| 335 | ++count; |
| 336 | shared_ptr<pit::Entry> entry = *it; |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 337 | |
| 338 | if (entry->getName().equals(nameA )) |
| 339 | hasA = true; |
| 340 | |
| 341 | if (entry->getName().equals(nameAB)) |
| 342 | hasAB = true; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 343 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 344 | if (entry->getName().equals(nameABC)) |
| 345 | hasABC = true; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 346 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 347 | if (entry->getName().equals(nameD)) |
| 348 | hasD = true; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 349 | } |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 350 | BOOST_CHECK_EQUAL(hasA , true); |
| 351 | BOOST_CHECK_EQUAL(hasAB , false); |
| 352 | BOOST_CHECK_EQUAL(hasABC, true); |
| 353 | BOOST_CHECK_EQUAL(hasD , false); |
| 354 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 355 | BOOST_CHECK_EQUAL(count, 2); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 356 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | BOOST_AUTO_TEST_SUITE_END() |
| 360 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 361 | } // namespace tests |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 362 | } // namespace nfd |