Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 1 | /* -*- 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 Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 8 | #include "tests/face/dummy-face.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 9 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 10 | #include "tests/test-common.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 11 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 12 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 13 | namespace tests { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 14 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 15 | BOOST_FIXTURE_TEST_SUITE(TablePit, BaseFixture) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 16 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 17 | BOOST_AUTO_TEST_CASE(EntryInOutRecords) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 18 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 19 | shared_ptr<Face> face1 = make_shared<DummyFace>(); |
| 20 | shared_ptr<Face> face2 = make_shared<DummyFace>(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 21 | Name name("ndn:/KuYfjtRq"); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 22 | shared_ptr<Interest> interest = makeInterest(name); |
| 23 | shared_ptr<Interest> interest1 = makeInterest(name); |
| 24 | interest1->setInterestLifetime(static_cast<ndn::Milliseconds>(2528)); |
| 25 | interest1->setNonce(25559); |
| 26 | shared_ptr<Interest> interest2 = makeInterest(name); |
| 27 | interest2->setInterestLifetime(static_cast<ndn::Milliseconds>(6464)); |
| 28 | interest2->setNonce(19004); |
| 29 | shared_ptr<Interest> interest3 = makeInterest(name); |
| 30 | interest3->setInterestLifetime(static_cast<ndn::Milliseconds>(3585)); |
| 31 | interest3->setNonce(24216); |
| 32 | shared_ptr<Interest> interest4 = makeInterest(name); |
| 33 | interest4->setInterestLifetime(static_cast<ndn::Milliseconds>(8795)); |
| 34 | interest4->setNonce(17365); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 35 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 36 | pit::Entry entry(*interest); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 37 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 38 | BOOST_CHECK_EQUAL(entry.getInterest().getName(), name); |
| 39 | BOOST_CHECK_EQUAL(entry.getName(), name); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 40 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 41 | 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 Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 45 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 46 | // insert InRecord |
| 47 | time::Point before1 = time::now(); |
| 48 | pit::InRecordCollection::iterator in1 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 49 | entry.insertOrUpdateInRecord(face1, *interest1); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 50 | time::Point after1 = time::now(); |
| 51 | 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 Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 55 | BOOST_CHECK_EQUAL(in1->getLastNonce(), interest1->getNonce()); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 56 | BOOST_CHECK_GE(in1->getLastRenewed(), before1); |
| 57 | BOOST_CHECK_LE(in1->getLastRenewed(), after1); |
| 58 | BOOST_CHECK_LE(std::abs(in1->getExpiry() - in1->getLastRenewed() |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 59 | - time::milliseconds(interest1->getInterestLifetime())), |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 60 | (after1 - before1)); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 61 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 62 | // insert OutRecord |
| 63 | time::Point before2 = time::now(); |
| 64 | pit::OutRecordCollection::iterator out1 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 65 | entry.insertOrUpdateOutRecord(face1, *interest1); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 66 | time::Point after2 = time::now(); |
| 67 | 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 Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 71 | BOOST_CHECK_EQUAL(out1->getLastNonce(), interest1->getNonce()); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 72 | BOOST_CHECK_GE(out1->getLastRenewed(), before2); |
| 73 | BOOST_CHECK_LE(out1->getLastRenewed(), after2); |
| 74 | BOOST_CHECK_LE(std::abs(out1->getExpiry() - out1->getLastRenewed() |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 75 | - time::milliseconds(interest1->getInterestLifetime())), |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 76 | (after2 - before2)); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 77 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 78 | // update InRecord |
| 79 | time::Point before3 = time::now(); |
| 80 | pit::InRecordCollection::iterator in2 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 81 | entry.insertOrUpdateInRecord(face1, *interest2); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 82 | time::Point after3 = time::now(); |
| 83 | 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 Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 87 | BOOST_CHECK_EQUAL(in2->getLastNonce(), interest2->getNonce()); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 88 | BOOST_CHECK_LE(std::abs(in2->getExpiry() - in2->getLastRenewed() |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 89 | - time::milliseconds(interest2->getInterestLifetime())), |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 90 | (after3 - before3)); |
| 91 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 92 | // insert another InRecord |
| 93 | pit::InRecordCollection::iterator in3 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 94 | entry.insertOrUpdateInRecord(face2, *interest3); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 95 | const pit::InRecordCollection& inRecords4 = entry.getInRecords(); |
| 96 | BOOST_CHECK_EQUAL(inRecords4.size(), 2); |
| 97 | BOOST_CHECK_EQUAL(in3->getFace(), face2); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 98 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 99 | // delete all InRecords |
| 100 | entry.deleteInRecords(); |
| 101 | const pit::InRecordCollection& inRecords5 = entry.getInRecords(); |
| 102 | BOOST_CHECK_EQUAL(inRecords5.size(), 0); |
| 103 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 104 | // insert another OutRecord |
| 105 | pit::OutRecordCollection::iterator out2 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 106 | entry.insertOrUpdateOutRecord(face2, *interest4); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 107 | const pit::OutRecordCollection& outRecords3 = entry.getOutRecords(); |
| 108 | BOOST_CHECK_EQUAL(outRecords3.size(), 2); |
| 109 | BOOST_CHECK_EQUAL(out2->getFace(), face2); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 110 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 111 | // 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 Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | BOOST_AUTO_TEST_CASE(EntryNonce) |
| 119 | { |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 120 | shared_ptr<Interest> interest = makeInterest("ndn:/qtCQ7I1c"); |
| 121 | |
| 122 | pit::Entry entry(*interest); |
| 123 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 124 | 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 Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 130 | BOOST_AUTO_TEST_CASE(EntryLifetime) |
| 131 | { |
| 132 | shared_ptr<Interest> interest = makeInterest("ndn:/7oIEurbgy6"); |
| 133 | BOOST_ASSERT(interest->getInterestLifetime() < 0); // library uses -1 to indicate unset lifetime |
| 134 | |
| 135 | shared_ptr<Face> face = make_shared<DummyFace>(); |
| 136 | pit::Entry entry(*interest); |
| 137 | |
| 138 | pit::InRecordCollection::iterator inIt = entry.insertOrUpdateInRecord(face, *interest); |
| 139 | BOOST_CHECK_GT(inIt->getExpiry(), time::now()); |
| 140 | |
| 141 | pit::OutRecordCollection::iterator outIt = entry.insertOrUpdateOutRecord(face, *interest); |
| 142 | BOOST_CHECK_GT(outIt->getExpiry(), time::now()); |
| 143 | } |
| 144 | |
| 145 | BOOST_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 Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 166 | BOOST_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 |
| 177 | Interest interestA(name1, -1, -1, exclude0, -1, false, -1, -1.0, 0); |
| 178 | // A+exclude1 |
| 179 | Interest interestB(name1, -1, -1, exclude1, -1, false, -1, -1.0, 0); |
| 180 | // A+exclude2 |
| 181 | Interest interestC(name1, -1, -1, exclude2, -1, false, -1, -1.0, 0); |
| 182 | // A+MinSuffixComponents |
| 183 | Interest interestD(name1, 2, -1, exclude0, -1, false, -1, -1.0, 0); |
| 184 | // A+MaxSuffixComponents |
| 185 | Interest interestE(name1, -1, 4, exclude0, -1, false, -1, -1.0, 0); |
| 186 | // A+ChildSelector |
| 187 | Interest interestF(name1, -1, -1, exclude0, 1, false, -1, -1.0, 0); |
| 188 | // A+MustBeFresh |
| 189 | Interest interestG(name1, -1, -1, exclude0, -1, true, -1, -1.0, 0); |
| 190 | // A+Scope |
| 191 | Interest interestH(name1, -1, -1, exclude0, -1, false, 2, -1.0, 0); |
| 192 | // A+InterestLifetime |
| 193 | Interest interestI(name1, -1, -1, exclude0, -1, false, -1, 2000, 0); |
| 194 | // A+Nonce |
| 195 | Interest interestJ(name1, -1, -1, exclude0, -1, false, -1, -1.0, 2192); |
| 196 | // different Name+exclude1 |
| 197 | Interest interestK(name2, -1, -1, exclude1, -1, false, -1, -1.0, 0); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 198 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 199 | NameTree nameTree(16); |
| 200 | Pit pit(nameTree); |
| 201 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 202 | std::pair<shared_ptr<pit::Entry>, bool> insertResult; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 203 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 204 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 205 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 206 | insertResult = pit.insert(interestA); |
| 207 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 208 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 209 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 210 | insertResult = pit.insert(interestB); |
| 211 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 212 | BOOST_CHECK_EQUAL(pit.size(), 2); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 213 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 214 | insertResult = pit.insert(interestC); |
| 215 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 216 | BOOST_CHECK_EQUAL(pit.size(), 3); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 217 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 218 | insertResult = pit.insert(interestD); |
| 219 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 220 | BOOST_CHECK_EQUAL(pit.size(), 4); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 221 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 222 | insertResult = pit.insert(interestE); |
| 223 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 224 | BOOST_CHECK_EQUAL(pit.size(), 5); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 225 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 226 | insertResult = pit.insert(interestF); |
| 227 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 228 | BOOST_CHECK_EQUAL(pit.size(), 6); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 229 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 230 | insertResult = pit.insert(interestG); |
| 231 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 232 | BOOST_CHECK_EQUAL(pit.size(), 7); |
| 233 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 234 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 235 | insertResult = pit.insert(interestH); |
| 236 | BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 237 | BOOST_CHECK_EQUAL(pit.size(), 7); |
| 238 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 239 | insertResult = pit.insert(interestI); |
| 240 | BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 241 | BOOST_CHECK_EQUAL(pit.size(), 7); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 242 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 243 | insertResult = pit.insert(interestJ); |
| 244 | BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 245 | BOOST_CHECK_EQUAL(pit.size(), 7); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 246 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 247 | insertResult = pit.insert(interestK); |
| 248 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 249 | BOOST_CHECK_EQUAL(pit.size(), 8); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 252 | BOOST_AUTO_TEST_CASE(Erase) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 253 | { |
| 254 | Interest interest(Name("ndn:/z88Admz6A2")); |
| 255 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 256 | NameTree nameTree(16); |
| 257 | Pit pit(nameTree); |
| 258 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 259 | std::pair<shared_ptr<pit::Entry>, bool> insertResult; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 260 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 261 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 262 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 263 | insertResult = pit.insert(interest); |
| 264 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 265 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 266 | |
| 267 | insertResult = pit.insert(interest); |
| 268 | BOOST_CHECK_EQUAL(insertResult.second, false); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 269 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 270 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 271 | pit.erase(insertResult.first); |
| 272 | BOOST_CHECK_EQUAL(pit.size(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 273 | |
| 274 | insertResult = pit.insert(interest); |
| 275 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 276 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 277 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 278 | } |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 279 | |
| 280 | BOOST_AUTO_TEST_CASE(FindAllDataMatches) |
| 281 | { |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 282 | 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 Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 291 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 292 | NameTree nameTree(16); |
| 293 | Pit pit(nameTree); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 294 | int count = 0; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 295 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 296 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 297 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 298 | 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 Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 303 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 304 | BOOST_CHECK_EQUAL(pit.size(), 3); |
| 305 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 306 | Data data(nameABCD); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 307 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 308 | shared_ptr<pit::DataMatchResult> matches = pit.findAllDataMatches(data); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 309 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 310 | bool hasA = false; |
| 311 | bool hasAB = false; |
| 312 | bool hasABC = false; |
| 313 | bool hasD = false; |
| 314 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 315 | for (pit::DataMatchResult::iterator it = matches->begin(); |
| 316 | it != matches->end(); ++it) { |
| 317 | ++count; |
| 318 | shared_ptr<pit::Entry> entry = *it; |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 319 | |
| 320 | if (entry->getName().equals(nameA )) |
| 321 | hasA = true; |
| 322 | |
| 323 | if (entry->getName().equals(nameAB)) |
| 324 | hasAB = true; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 325 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 326 | if (entry->getName().equals(nameABC)) |
| 327 | hasABC = true; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 328 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 329 | if (entry->getName().equals(nameD)) |
| 330 | hasD = true; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 331 | } |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 332 | 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 Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 337 | BOOST_CHECK_EQUAL(count, 2); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 338 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | BOOST_AUTO_TEST_SUITE_END() |
| 342 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 343 | } // namespace tests |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 344 | } // namespace nfd |