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 | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 35 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 36 | pit::Entry entry(*interest); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -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); |
| 45 | |
| 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)); |
| 61 | |
| 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)); |
| 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); |
| 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); |
| 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); |
| 116 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | BOOST_AUTO_TEST_CASE(EntryNonce) |
| 120 | { |
| 121 | Name name("ndn:/qtCQ7I1c"); |
| 122 | Interest interest(name); |
| 123 | |
| 124 | pit::Entry entry(interest); |
| 125 | |
| 126 | BOOST_CHECK_EQUAL(entry.addNonce(25559), true); |
| 127 | BOOST_CHECK_EQUAL(entry.addNonce(25559), false); |
| 128 | BOOST_CHECK_EQUAL(entry.addNonce(19004), true); |
| 129 | BOOST_CHECK_EQUAL(entry.addNonce(19004), false); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | BOOST_AUTO_TEST_CASE(Insert) |
| 133 | { |
| 134 | Name name1("ndn:/5vzBNnMst"); |
| 135 | Name name2("ndn:/igSGfEIM62"); |
| 136 | Exclude exclude0; |
| 137 | Exclude exclude1; |
| 138 | exclude1.excludeOne(Name::Component("u26p47oep")); |
| 139 | Exclude exclude2; |
| 140 | exclude2.excludeOne(Name::Component("FG1Ni6nYcf")); |
| 141 | |
| 142 | // base |
| 143 | Interest interestA(name1, -1, -1, exclude0, -1, false, -1, -1.0, 0); |
| 144 | // A+exclude1 |
| 145 | Interest interestB(name1, -1, -1, exclude1, -1, false, -1, -1.0, 0); |
| 146 | // A+exclude2 |
| 147 | Interest interestC(name1, -1, -1, exclude2, -1, false, -1, -1.0, 0); |
| 148 | // A+MinSuffixComponents |
| 149 | Interest interestD(name1, 2, -1, exclude0, -1, false, -1, -1.0, 0); |
| 150 | // A+MaxSuffixComponents |
| 151 | Interest interestE(name1, -1, 4, exclude0, -1, false, -1, -1.0, 0); |
| 152 | // A+ChildSelector |
| 153 | Interest interestF(name1, -1, -1, exclude0, 1, false, -1, -1.0, 0); |
| 154 | // A+MustBeFresh |
| 155 | Interest interestG(name1, -1, -1, exclude0, -1, true, -1, -1.0, 0); |
| 156 | // A+Scope |
| 157 | Interest interestH(name1, -1, -1, exclude0, -1, false, 2, -1.0, 0); |
| 158 | // A+InterestLifetime |
| 159 | Interest interestI(name1, -1, -1, exclude0, -1, false, -1, 2000, 0); |
| 160 | // A+Nonce |
| 161 | Interest interestJ(name1, -1, -1, exclude0, -1, false, -1, -1.0, 2192); |
| 162 | // different Name+exclude1 |
| 163 | Interest interestK(name2, -1, -1, exclude1, -1, false, -1, -1.0, 0); |
| 164 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 165 | NameTree nameTree(16); |
| 166 | Pit pit(nameTree); |
| 167 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 168 | std::pair<shared_ptr<pit::Entry>, bool> insertResult; |
| 169 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 170 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 171 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 172 | insertResult = pit.insert(interestA); |
| 173 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 174 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 175 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 176 | insertResult = pit.insert(interestB); |
| 177 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 178 | BOOST_CHECK_EQUAL(pit.size(), 2); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 179 | |
| 180 | insertResult = pit.insert(interestC); |
| 181 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 182 | BOOST_CHECK_EQUAL(pit.size(), 3); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 183 | |
| 184 | insertResult = pit.insert(interestD); |
| 185 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 186 | BOOST_CHECK_EQUAL(pit.size(), 4); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 187 | |
| 188 | insertResult = pit.insert(interestE); |
| 189 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 190 | BOOST_CHECK_EQUAL(pit.size(), 5); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 191 | |
| 192 | insertResult = pit.insert(interestF); |
| 193 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 194 | BOOST_CHECK_EQUAL(pit.size(), 6); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 195 | |
| 196 | insertResult = pit.insert(interestG); |
| 197 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 198 | BOOST_CHECK_EQUAL(pit.size(), 7); |
| 199 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 200 | |
| 201 | insertResult = pit.insert(interestH); |
| 202 | BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 203 | BOOST_CHECK_EQUAL(pit.size(), 7); |
| 204 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 205 | insertResult = pit.insert(interestI); |
| 206 | BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 207 | BOOST_CHECK_EQUAL(pit.size(), 7); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 208 | |
| 209 | insertResult = pit.insert(interestJ); |
| 210 | BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 211 | BOOST_CHECK_EQUAL(pit.size(), 7); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 212 | |
| 213 | insertResult = pit.insert(interestK); |
| 214 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 215 | BOOST_CHECK_EQUAL(pit.size(), 8); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 218 | BOOST_AUTO_TEST_CASE(Erase) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 219 | { |
| 220 | Interest interest(Name("ndn:/z88Admz6A2")); |
| 221 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 222 | NameTree nameTree(16); |
| 223 | Pit pit(nameTree); |
| 224 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 225 | std::pair<shared_ptr<pit::Entry>, bool> insertResult; |
| 226 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 227 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 228 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 229 | insertResult = pit.insert(interest); |
| 230 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 231 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 232 | |
| 233 | insertResult = pit.insert(interest); |
| 234 | BOOST_CHECK_EQUAL(insertResult.second, false); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 235 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 236 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 237 | pit.erase(insertResult.first); |
| 238 | BOOST_CHECK_EQUAL(pit.size(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 239 | |
| 240 | insertResult = pit.insert(interest); |
| 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(), 1); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 243 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 244 | } |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 245 | |
| 246 | BOOST_AUTO_TEST_CASE(FindAllDataMatches) |
| 247 | { |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 248 | Name nameA ("ndn:/A"); |
| 249 | Name nameAB ("ndn:/A/B"); |
| 250 | Name nameABC ("ndn:/A/B/C"); |
| 251 | Name nameABCD("ndn:/A/B/C/D"); |
| 252 | Name nameD ("ndn:/D"); |
| 253 | |
| 254 | Interest interestA (nameA ); |
| 255 | Interest interestABC(nameABC); |
| 256 | Interest interestD (nameD ); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 257 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 258 | NameTree nameTree(16); |
| 259 | Pit pit(nameTree); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 260 | int count = 0; |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 261 | |
| 262 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 263 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 264 | pit.insert(interestA ); |
| 265 | pit.insert(interestABC); |
| 266 | pit.insert(interestD ); |
| 267 | |
| 268 | nameTree.lookup(nameABCD); // make sure /A/B/C/D is in nameTree |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 269 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 270 | BOOST_CHECK_EQUAL(pit.size(), 3); |
| 271 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 272 | Data data(nameABCD); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 273 | |
| 274 | shared_ptr<pit::DataMatchResult> matches = pit.findAllDataMatches(data); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 275 | |
| 276 | bool hasA = false; |
| 277 | bool hasAB = false; |
| 278 | bool hasABC = false; |
| 279 | bool hasD = false; |
| 280 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 281 | for (pit::DataMatchResult::iterator it = matches->begin(); |
| 282 | it != matches->end(); ++it) { |
| 283 | ++count; |
| 284 | shared_ptr<pit::Entry> entry = *it; |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 285 | |
| 286 | if (entry->getName().equals(nameA )) |
| 287 | hasA = true; |
| 288 | |
| 289 | if (entry->getName().equals(nameAB)) |
| 290 | hasAB = true; |
| 291 | |
| 292 | if (entry->getName().equals(nameABC)) |
| 293 | hasABC = true; |
| 294 | |
| 295 | if (entry->getName().equals(nameD)) |
| 296 | hasD = true; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 297 | } |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 298 | BOOST_CHECK_EQUAL(hasA , true); |
| 299 | BOOST_CHECK_EQUAL(hasAB , false); |
| 300 | BOOST_CHECK_EQUAL(hasABC, true); |
| 301 | BOOST_CHECK_EQUAL(hasD , false); |
| 302 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 303 | BOOST_CHECK_EQUAL(count, 2); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 304 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | BOOST_AUTO_TEST_SUITE_END() |
| 308 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 309 | } // namespace tests |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 310 | } // namespace nfd |