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