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 | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, 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 | * The University of Memphis. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Alexander Afanasyev | c026d25 | 2014-06-16 11:14:15 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 25 | |
| 26 | #include "table/pit.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 27 | #include "tests/daemon/face/dummy-face.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 28 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 31 | namespace nfd { |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 32 | namespace pit { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 33 | namespace tests { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 34 | |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 35 | using namespace nfd::tests; |
| 36 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 37 | BOOST_FIXTURE_TEST_SUITE(TablePit, BaseFixture) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 38 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 39 | BOOST_AUTO_TEST_CASE(EntryInOutRecords) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 40 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 41 | shared_ptr<Face> face1 = make_shared<DummyFace>(); |
| 42 | shared_ptr<Face> face2 = make_shared<DummyFace>(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 43 | Name name("ndn:/KuYfjtRq"); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 44 | shared_ptr<Interest> interest = makeInterest(name); |
| 45 | shared_ptr<Interest> interest1 = makeInterest(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 46 | interest1->setInterestLifetime(time::milliseconds(2528)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 47 | interest1->setNonce(25559); |
| 48 | shared_ptr<Interest> interest2 = makeInterest(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 49 | interest2->setInterestLifetime(time::milliseconds(6464)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 50 | interest2->setNonce(19004); |
| 51 | shared_ptr<Interest> interest3 = makeInterest(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 52 | interest3->setInterestLifetime(time::milliseconds(3585)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 53 | interest3->setNonce(24216); |
| 54 | shared_ptr<Interest> interest4 = makeInterest(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 55 | interest4->setInterestLifetime(time::milliseconds(8795)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 56 | interest4->setNonce(17365); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 57 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 58 | pit::Entry entry(*interest); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 59 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 60 | BOOST_CHECK_EQUAL(entry.getInterest().getName(), name); |
| 61 | BOOST_CHECK_EQUAL(entry.getName(), name); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 62 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 63 | const pit::InRecordCollection& inRecords1 = entry.getInRecords(); |
| 64 | BOOST_CHECK_EQUAL(inRecords1.size(), 0); |
| 65 | const pit::OutRecordCollection& outRecords1 = entry.getOutRecords(); |
| 66 | BOOST_CHECK_EQUAL(outRecords1.size(), 0); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 67 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 68 | // insert InRecord |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 69 | time::steady_clock::TimePoint before1 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 70 | pit::InRecordCollection::iterator in1 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 71 | entry.insertOrUpdateInRecord(face1, *interest1); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 72 | time::steady_clock::TimePoint after1 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 73 | const pit::InRecordCollection& inRecords2 = entry.getInRecords(); |
| 74 | BOOST_CHECK_EQUAL(inRecords2.size(), 1); |
| 75 | BOOST_CHECK(in1 == inRecords2.begin()); |
| 76 | BOOST_CHECK_EQUAL(in1->getFace(), face1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 77 | BOOST_CHECK_EQUAL(in1->getLastNonce(), interest1->getNonce()); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 78 | BOOST_CHECK_GE(in1->getLastRenewed(), before1); |
| 79 | BOOST_CHECK_LE(in1->getLastRenewed(), after1); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 80 | BOOST_CHECK_LE(in1->getExpiry() - in1->getLastRenewed() |
| 81 | - interest1->getInterestLifetime(), |
| 82 | (after1 - before1)); |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 83 | BOOST_CHECK(in1 == entry.getInRecord(*face1)); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 84 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 85 | // insert OutRecord |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 86 | time::steady_clock::TimePoint before2 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 87 | pit::OutRecordCollection::iterator out1 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 88 | entry.insertOrUpdateOutRecord(face1, *interest1); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 89 | time::steady_clock::TimePoint after2 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 90 | const pit::OutRecordCollection& outRecords2 = entry.getOutRecords(); |
| 91 | BOOST_CHECK_EQUAL(outRecords2.size(), 1); |
| 92 | BOOST_CHECK(out1 == outRecords2.begin()); |
| 93 | BOOST_CHECK_EQUAL(out1->getFace(), face1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 94 | BOOST_CHECK_EQUAL(out1->getLastNonce(), interest1->getNonce()); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 95 | BOOST_CHECK_GE(out1->getLastRenewed(), before2); |
| 96 | BOOST_CHECK_LE(out1->getLastRenewed(), after2); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 97 | BOOST_CHECK_LE(out1->getExpiry() - out1->getLastRenewed() |
| 98 | - interest1->getInterestLifetime(), |
| 99 | (after2 - before2)); |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 100 | BOOST_CHECK(out1 == entry.getOutRecord(*face1)); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 101 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 102 | // update InRecord |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 103 | time::steady_clock::TimePoint before3 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 104 | pit::InRecordCollection::iterator in2 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 105 | entry.insertOrUpdateInRecord(face1, *interest2); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 106 | time::steady_clock::TimePoint after3 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 107 | const pit::InRecordCollection& inRecords3 = entry.getInRecords(); |
| 108 | BOOST_CHECK_EQUAL(inRecords3.size(), 1); |
| 109 | BOOST_CHECK(in2 == inRecords3.begin()); |
| 110 | BOOST_CHECK_EQUAL(in2->getFace(), face1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 111 | BOOST_CHECK_EQUAL(in2->getLastNonce(), interest2->getNonce()); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 112 | BOOST_CHECK_LE(in2->getExpiry() - in2->getLastRenewed() |
| 113 | - interest2->getInterestLifetime(), |
| 114 | (after3 - before3)); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 115 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 116 | // insert another InRecord |
| 117 | pit::InRecordCollection::iterator in3 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 118 | entry.insertOrUpdateInRecord(face2, *interest3); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 119 | const pit::InRecordCollection& inRecords4 = entry.getInRecords(); |
| 120 | BOOST_CHECK_EQUAL(inRecords4.size(), 2); |
| 121 | BOOST_CHECK_EQUAL(in3->getFace(), face2); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 122 | |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 123 | // get InRecord |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 124 | pit::InRecordCollection::const_iterator in4 = entry.getInRecord(*face1); |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 125 | BOOST_REQUIRE(in4 != entry.getInRecords().end()); |
| 126 | BOOST_CHECK_EQUAL(in4->getFace(), face1); |
| 127 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 128 | // delete all InRecords |
| 129 | entry.deleteInRecords(); |
| 130 | const pit::InRecordCollection& inRecords5 = entry.getInRecords(); |
| 131 | BOOST_CHECK_EQUAL(inRecords5.size(), 0); |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 132 | BOOST_CHECK(entry.getInRecord(*face1) == entry.getInRecords().end()); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 133 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 134 | // insert another OutRecord |
| 135 | pit::OutRecordCollection::iterator out2 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 136 | entry.insertOrUpdateOutRecord(face2, *interest4); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 137 | const pit::OutRecordCollection& outRecords3 = entry.getOutRecords(); |
| 138 | BOOST_CHECK_EQUAL(outRecords3.size(), 2); |
| 139 | BOOST_CHECK_EQUAL(out2->getFace(), face2); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 140 | |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 141 | // get OutRecord |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 142 | pit::OutRecordCollection::const_iterator out3 = entry.getOutRecord(*face1); |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 143 | BOOST_REQUIRE(out3 != entry.getOutRecords().end()); |
| 144 | BOOST_CHECK_EQUAL(out3->getFace(), face1); |
| 145 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 146 | // delete OutRecord |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 147 | entry.deleteOutRecord(*face2); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 148 | const pit::OutRecordCollection& outRecords4 = entry.getOutRecords(); |
| 149 | BOOST_REQUIRE_EQUAL(outRecords4.size(), 1); |
| 150 | BOOST_CHECK_EQUAL(outRecords4.begin()->getFace(), face1); |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 151 | BOOST_CHECK(entry.getOutRecord(*face2) == entry.getOutRecords().end()); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | BOOST_AUTO_TEST_CASE(EntryNonce) |
| 155 | { |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 156 | shared_ptr<Face> face1 = make_shared<DummyFace>(); |
| 157 | shared_ptr<Face> face2 = make_shared<DummyFace>(); |
| 158 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 159 | shared_ptr<Interest> interest = makeInterest("ndn:/qtCQ7I1c"); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 160 | interest->setNonce(25559); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 161 | |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 162 | pit::Entry entry0(*interest); |
| 163 | BOOST_CHECK_EQUAL(entry0.findNonce(25559, *face1), pit::DUPLICATE_NONCE_NONE); |
| 164 | BOOST_CHECK_EQUAL(entry0.findNonce(25559, *face2), pit::DUPLICATE_NONCE_NONE); |
| 165 | BOOST_CHECK_EQUAL(entry0.findNonce(19004, *face1), pit::DUPLICATE_NONCE_NONE); |
| 166 | BOOST_CHECK_EQUAL(entry0.findNonce(19004, *face2), pit::DUPLICATE_NONCE_NONE); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 167 | |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 168 | pit::Entry entry1(*interest); |
| 169 | entry1.insertOrUpdateInRecord(face1, *interest); |
| 170 | BOOST_CHECK_EQUAL(entry1.findNonce(25559, *face1), pit::DUPLICATE_NONCE_IN_SAME); |
| 171 | BOOST_CHECK_EQUAL(entry1.findNonce(25559, *face2), pit::DUPLICATE_NONCE_IN_OTHER); |
| 172 | BOOST_CHECK_EQUAL(entry1.findNonce(19004, *face1), pit::DUPLICATE_NONCE_NONE); |
| 173 | BOOST_CHECK_EQUAL(entry1.findNonce(19004, *face2), pit::DUPLICATE_NONCE_NONE); |
| 174 | |
| 175 | pit::Entry entry2(*interest); |
| 176 | entry2.insertOrUpdateOutRecord(face1, *interest); |
| 177 | BOOST_CHECK_EQUAL(entry2.findNonce(25559, *face1), pit::DUPLICATE_NONCE_OUT_SAME); |
| 178 | BOOST_CHECK_EQUAL(entry2.findNonce(25559, *face2), pit::DUPLICATE_NONCE_OUT_OTHER); |
| 179 | BOOST_CHECK_EQUAL(entry2.findNonce(19004, *face1), pit::DUPLICATE_NONCE_NONE); |
| 180 | BOOST_CHECK_EQUAL(entry2.findNonce(19004, *face2), pit::DUPLICATE_NONCE_NONE); |
| 181 | |
| 182 | pit::Entry entry3(*interest); |
| 183 | entry3.insertOrUpdateInRecord(face1, *interest); |
| 184 | entry3.insertOrUpdateOutRecord(face1, *interest); |
| 185 | BOOST_CHECK_EQUAL(entry3.findNonce(25559, *face1), |
| 186 | pit::DUPLICATE_NONCE_IN_SAME | pit::DUPLICATE_NONCE_OUT_SAME); |
| 187 | BOOST_CHECK_EQUAL(entry3.findNonce(25559, *face2), |
| 188 | pit::DUPLICATE_NONCE_IN_OTHER | pit::DUPLICATE_NONCE_OUT_OTHER); |
| 189 | BOOST_CHECK_EQUAL(entry3.findNonce(19004, *face1), pit::DUPLICATE_NONCE_NONE); |
| 190 | BOOST_CHECK_EQUAL(entry3.findNonce(19004, *face2), pit::DUPLICATE_NONCE_NONE); |
| 191 | |
| 192 | pit::Entry entry4(*interest); |
| 193 | entry4.insertOrUpdateInRecord(face1, *interest); |
| 194 | entry4.insertOrUpdateInRecord(face2, *interest); |
| 195 | BOOST_CHECK_EQUAL(entry4.findNonce(25559, *face1), |
| 196 | pit::DUPLICATE_NONCE_IN_SAME | pit::DUPLICATE_NONCE_IN_OTHER); |
| 197 | BOOST_CHECK_EQUAL(entry4.findNonce(25559, *face2), |
| 198 | pit::DUPLICATE_NONCE_IN_SAME | pit::DUPLICATE_NONCE_IN_OTHER); |
| 199 | BOOST_CHECK_EQUAL(entry4.findNonce(19004, *face1), pit::DUPLICATE_NONCE_NONE); |
| 200 | BOOST_CHECK_EQUAL(entry4.findNonce(19004, *face2), pit::DUPLICATE_NONCE_NONE); |
| 201 | |
| 202 | pit::Entry entry5(*interest); |
| 203 | entry5.insertOrUpdateOutRecord(face1, *interest); |
| 204 | entry5.insertOrUpdateOutRecord(face2, *interest); |
| 205 | BOOST_CHECK_EQUAL(entry5.findNonce(25559, *face1), |
| 206 | pit::DUPLICATE_NONCE_OUT_SAME | pit::DUPLICATE_NONCE_OUT_OTHER); |
| 207 | BOOST_CHECK_EQUAL(entry5.findNonce(25559, *face2), |
| 208 | pit::DUPLICATE_NONCE_OUT_SAME | pit::DUPLICATE_NONCE_OUT_OTHER); |
| 209 | BOOST_CHECK_EQUAL(entry5.findNonce(19004, *face1), pit::DUPLICATE_NONCE_NONE); |
| 210 | BOOST_CHECK_EQUAL(entry5.findNonce(19004, *face2), pit::DUPLICATE_NONCE_NONE); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 213 | BOOST_AUTO_TEST_CASE(EntryLifetime) |
| 214 | { |
| 215 | shared_ptr<Interest> interest = makeInterest("ndn:/7oIEurbgy6"); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 216 | // library uses -1 to indicate unset lifetime |
| 217 | BOOST_ASSERT(interest->getInterestLifetime() < time::milliseconds::zero()); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 218 | |
| 219 | shared_ptr<Face> face = make_shared<DummyFace>(); |
| 220 | pit::Entry entry(*interest); |
| 221 | |
| 222 | pit::InRecordCollection::iterator inIt = entry.insertOrUpdateInRecord(face, *interest); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 223 | BOOST_CHECK_GT(inIt->getExpiry(), time::steady_clock::now()); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 224 | |
| 225 | pit::OutRecordCollection::iterator outIt = entry.insertOrUpdateOutRecord(face, *interest); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 226 | BOOST_CHECK_GT(outIt->getExpiry(), time::steady_clock::now()); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | BOOST_AUTO_TEST_CASE(EntryCanForwardTo) |
| 230 | { |
| 231 | shared_ptr<Interest> interest = makeInterest("ndn:/WDsuBLIMG"); |
| 232 | pit::Entry entry(*interest); |
| 233 | |
| 234 | shared_ptr<Face> face1 = make_shared<DummyFace>(); |
| 235 | shared_ptr<Face> face2 = make_shared<DummyFace>(); |
| 236 | |
| 237 | entry.insertOrUpdateInRecord(face1, *interest); |
| 238 | BOOST_CHECK_EQUAL(entry.canForwardTo(*face1), false); |
| 239 | BOOST_CHECK_EQUAL(entry.canForwardTo(*face2), true); |
| 240 | |
| 241 | entry.insertOrUpdateInRecord(face2, *interest); |
| 242 | BOOST_CHECK_EQUAL(entry.canForwardTo(*face1), true); |
| 243 | BOOST_CHECK_EQUAL(entry.canForwardTo(*face2), true); |
| 244 | |
| 245 | entry.insertOrUpdateOutRecord(face1, *interest); |
| 246 | BOOST_CHECK_EQUAL(entry.canForwardTo(*face1), false); |
| 247 | BOOST_CHECK_EQUAL(entry.canForwardTo(*face2), true); |
| 248 | } |
| 249 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 250 | BOOST_AUTO_TEST_CASE(Insert) |
| 251 | { |
| 252 | Name name1("ndn:/5vzBNnMst"); |
| 253 | Name name2("ndn:/igSGfEIM62"); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 254 | Exclude exclude1; |
| 255 | exclude1.excludeOne(Name::Component("u26p47oep")); |
| 256 | Exclude exclude2; |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 257 | exclude2.excludeBefore(Name::Component("u26p47oep")); |
| 258 | ndn::KeyLocator keyLocator1("ndn:/sGAE3peMHA"); |
| 259 | ndn::KeyLocator keyLocator2("ndn:/nIJH6pr4"); |
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 | NameTree nameTree(16); |
| 262 | Pit pit(nameTree); |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 263 | BOOST_CHECK_EQUAL(pit.size(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 264 | std::pair<shared_ptr<pit::Entry>, bool> insertResult; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 265 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 266 | // base |
| 267 | shared_ptr<Interest> interestA = make_shared<Interest>(name1); |
| 268 | insertResult = pit.insert(*interestA); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 269 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 270 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 271 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 272 | // A+MinSuffixComponents |
| 273 | shared_ptr<Interest> interestB = make_shared<Interest>(*interestA); |
| 274 | interestB->setMinSuffixComponents(2); |
| 275 | insertResult = pit.insert(*interestB); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 276 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 277 | BOOST_CHECK_EQUAL(pit.size(), 2); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 278 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 279 | // A+MaxSuffixComponents |
| 280 | shared_ptr<Interest> interestC = make_shared<Interest>(*interestA); |
| 281 | interestC->setMaxSuffixComponents(4); |
| 282 | insertResult = pit.insert(*interestC); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 283 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 284 | BOOST_CHECK_EQUAL(pit.size(), 3); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 285 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 286 | // A+KeyLocator1 |
| 287 | shared_ptr<Interest> interestD = make_shared<Interest>(*interestA); |
| 288 | interestD->setPublisherPublicKeyLocator(keyLocator1); |
| 289 | insertResult = pit.insert(*interestD); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 290 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 291 | BOOST_CHECK_EQUAL(pit.size(), 4); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 292 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 293 | // A+KeyLocator2 |
| 294 | shared_ptr<Interest> interestE = make_shared<Interest>(*interestA); |
| 295 | interestE->setPublisherPublicKeyLocator(keyLocator2); |
| 296 | insertResult = pit.insert(*interestE); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 297 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 298 | BOOST_CHECK_EQUAL(pit.size(), 5); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 299 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 300 | // A+Exclude1 |
| 301 | shared_ptr<Interest> interestF = make_shared<Interest>(*interestA); |
| 302 | interestF->setExclude(exclude1); |
| 303 | insertResult = pit.insert(*interestF); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 304 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 305 | BOOST_CHECK_EQUAL(pit.size(), 6); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 306 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 307 | // A+Exclude2 |
| 308 | shared_ptr<Interest> interestG = make_shared<Interest>(*interestA); |
| 309 | interestG->setExclude(exclude2); |
| 310 | insertResult = pit.insert(*interestG); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 311 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 312 | BOOST_CHECK_EQUAL(pit.size(), 7); |
| 313 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 314 | // A+ChildSelector0 |
| 315 | shared_ptr<Interest> interestH = make_shared<Interest>(*interestA); |
| 316 | interestH->setChildSelector(0); |
| 317 | insertResult = pit.insert(*interestH); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 318 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 319 | BOOST_CHECK_EQUAL(pit.size(), 8); |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 320 | |
| 321 | // A+ChildSelector1 |
| 322 | shared_ptr<Interest> interestI = make_shared<Interest>(*interestA); |
| 323 | interestI->setChildSelector(1); |
| 324 | insertResult = pit.insert(*interestI); |
| 325 | BOOST_CHECK_EQUAL(insertResult.second, true); |
| 326 | BOOST_CHECK_EQUAL(pit.size(), 9); |
| 327 | |
| 328 | // A+MustBeFresh |
| 329 | shared_ptr<Interest> interestJ = make_shared<Interest>(*interestA); |
| 330 | interestJ->setMustBeFresh(true); |
| 331 | insertResult = pit.insert(*interestJ); |
| 332 | BOOST_CHECK_EQUAL(insertResult.second, true); |
| 333 | BOOST_CHECK_EQUAL(pit.size(), 10); |
| 334 | |
| 335 | // A+InterestLifetime |
| 336 | shared_ptr<Interest> interestK = make_shared<Interest>(*interestA); |
| 337 | interestK->setInterestLifetime(time::milliseconds(1000)); |
| 338 | insertResult = pit.insert(*interestK); |
| 339 | BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ |
| 340 | BOOST_CHECK_EQUAL(pit.size(), 10); |
| 341 | |
| 342 | // A+Nonce |
| 343 | shared_ptr<Interest> interestL = make_shared<Interest>(*interestA); |
| 344 | interestL->setNonce(2192); |
| 345 | insertResult = pit.insert(*interestL); |
| 346 | BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ |
| 347 | BOOST_CHECK_EQUAL(pit.size(), 10); |
| 348 | |
| 349 | // different Name+Exclude1 |
| 350 | shared_ptr<Interest> interestM = make_shared<Interest>(name2); |
| 351 | interestM->setExclude(exclude1); |
| 352 | insertResult = pit.insert(*interestM); |
| 353 | BOOST_CHECK_EQUAL(insertResult.second, true); |
| 354 | BOOST_CHECK_EQUAL(pit.size(), 11); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 357 | BOOST_AUTO_TEST_CASE(Erase) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 358 | { |
Alexander Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 359 | shared_ptr<Interest> interest = makeInterest("/z88Admz6A2"); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 360 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 361 | NameTree nameTree(16); |
| 362 | Pit pit(nameTree); |
| 363 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 364 | std::pair<shared_ptr<pit::Entry>, bool> insertResult; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 365 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 366 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 367 | |
Alexander Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 368 | insertResult = pit.insert(*interest); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 369 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 370 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 371 | |
Alexander Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 372 | insertResult = pit.insert(*interest); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 373 | BOOST_CHECK_EQUAL(insertResult.second, false); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 374 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 375 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 376 | pit.erase(insertResult.first); |
| 377 | BOOST_CHECK_EQUAL(pit.size(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 378 | |
Alexander Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 379 | insertResult = pit.insert(*interest); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 380 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 381 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 382 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 383 | } |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 384 | |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 385 | BOOST_AUTO_TEST_CASE(EraseNameTreeEntry) |
| 386 | { |
| 387 | NameTree nameTree; |
| 388 | Pit pit(nameTree); |
| 389 | size_t nNameTreeEntriesBefore = nameTree.size(); |
| 390 | |
| 391 | shared_ptr<Interest> interest = makeInterest("/37xWVvQ2K"); |
| 392 | shared_ptr<pit::Entry> entry = pit.insert(*interest).first; |
| 393 | pit.erase(entry); |
| 394 | BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore); |
| 395 | } |
| 396 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 397 | BOOST_AUTO_TEST_CASE(FindAllDataMatches) |
| 398 | { |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 399 | Name nameA ("ndn:/A"); |
| 400 | Name nameAB ("ndn:/A/B"); |
| 401 | Name nameABC ("ndn:/A/B/C"); |
| 402 | Name nameABCD("ndn:/A/B/C/D"); |
| 403 | Name nameD ("ndn:/D"); |
| 404 | |
Alexander Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 405 | shared_ptr<Interest> interestA = makeInterest(nameA ); |
| 406 | shared_ptr<Interest> interestABC = makeInterest(nameABC); |
| 407 | shared_ptr<Interest> interestD = makeInterest(nameD ); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 408 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 409 | NameTree nameTree(16); |
| 410 | Pit pit(nameTree); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 411 | int count = 0; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 412 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 413 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 414 | |
Alexander Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 415 | pit.insert(*interestA ); |
| 416 | pit.insert(*interestABC); |
| 417 | pit.insert(*interestD ); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 418 | |
| 419 | nameTree.lookup(nameABCD); // make sure /A/B/C/D is in nameTree |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 420 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 421 | BOOST_CHECK_EQUAL(pit.size(), 3); |
| 422 | |
Alexander Afanasyev | c026d25 | 2014-06-16 11:14:15 -0700 | [diff] [blame] | 423 | shared_ptr<Data> data = makeData(nameABCD); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 424 | |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 425 | pit::DataMatchResult matches = pit.findAllDataMatches(*data); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 426 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 427 | bool hasA = false; |
| 428 | bool hasAB = false; |
| 429 | bool hasABC = false; |
| 430 | bool hasD = false; |
| 431 | |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 432 | for (const shared_ptr<pit::Entry>& entry : matches) { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 433 | ++count; |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 434 | |
| 435 | if (entry->getName().equals(nameA )) |
| 436 | hasA = true; |
| 437 | |
| 438 | if (entry->getName().equals(nameAB)) |
| 439 | hasAB = true; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 440 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 441 | if (entry->getName().equals(nameABC)) |
| 442 | hasABC = true; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 443 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 444 | if (entry->getName().equals(nameD)) |
| 445 | hasD = true; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 446 | } |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 447 | BOOST_CHECK_EQUAL(hasA , true); |
| 448 | BOOST_CHECK_EQUAL(hasAB , false); |
| 449 | BOOST_CHECK_EQUAL(hasABC, true); |
| 450 | BOOST_CHECK_EQUAL(hasD , false); |
| 451 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 452 | BOOST_CHECK_EQUAL(count, 2); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 453 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Alexander Afanasyev | 750fa1c | 2015-01-03 17:28:31 -0800 | [diff] [blame] | 456 | BOOST_AUTO_TEST_CASE(Iterator) |
| 457 | { |
| 458 | NameTree nameTree(16); |
| 459 | Pit pit(nameTree); |
| 460 | |
| 461 | shared_ptr<Interest> interestA = makeInterest("/A"); |
| 462 | shared_ptr<Interest> interestABC1 = makeInterest("/A/B/C"); |
| 463 | shared_ptr<Interest> interestABC2 = makeInterest("/A/B/C"); |
| 464 | interestABC2->setSelectors(ndn::Selectors().setMinSuffixComponents(10)); |
| 465 | shared_ptr<Interest> interestD = makeInterest("/D"); |
| 466 | |
| 467 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 468 | BOOST_CHECK(pit.begin() == pit.end()); |
| 469 | |
| 470 | pit.insert(*interestABC1); |
| 471 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 472 | BOOST_CHECK(pit.begin() != pit.end()); |
| 473 | BOOST_CHECK(pit.begin()->getInterest() == *interestABC1); |
| 474 | BOOST_CHECK((*pit.begin()).getInterest() == *interestABC1); |
| 475 | |
| 476 | auto i = pit.begin(); |
| 477 | auto j = pit.begin(); |
| 478 | BOOST_CHECK(++i == pit.end()); |
| 479 | BOOST_CHECK(j++ == pit.begin()); |
| 480 | BOOST_CHECK(j == pit.end()); |
| 481 | |
| 482 | pit.insert(*interestA); |
| 483 | pit.insert(*interestABC2); |
| 484 | pit.insert(*interestD); |
| 485 | |
| 486 | std::set<const Interest*> expected = {&*interestA, &*interestABC1, &*interestABC2, &*interestD}; |
| 487 | std::set<const Interest*> actual; |
| 488 | for (const auto& pitEntry : pit) { |
| 489 | actual.insert(&pitEntry.getInterest()); |
| 490 | } |
| 491 | BOOST_CHECK(actual == expected); |
| 492 | for (auto actualIt = actual.begin(), expectedIt = expected.begin(); |
| 493 | actualIt != actual.end() && expectedIt != expected.end(); ++actualIt, ++expectedIt) { |
| 494 | BOOST_CHECK_EQUAL(**actualIt, **expectedIt); |
| 495 | } |
| 496 | } |
| 497 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 498 | BOOST_AUTO_TEST_SUITE_END() |
| 499 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 500 | } // namespace tests |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 501 | } // namespace pit |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 502 | } // namespace nfd |