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