Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2015 Regents of the University of California. |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #include "face.hpp" |
| 23 | #include "util/scheduler.hpp" |
| 24 | #include "security/key-chain.hpp" |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 25 | #include "util/dummy-client-face.hpp" |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 26 | |
| 27 | #include "boost-test.hpp" |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 28 | #include "unit-test-time-fixture.hpp" |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 29 | #include "make-interest-data.hpp" |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 30 | |
| 31 | namespace ndn { |
| 32 | namespace tests { |
| 33 | |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 34 | using ndn::util::DummyClientFace; |
| 35 | using ndn::util::makeDummyClientFace; |
| 36 | |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 37 | class FaceFixture : public UnitTestTimeFixture |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 38 | { |
| 39 | public: |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 40 | explicit |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 41 | FaceFixture(bool enableRegistrationReply = true) |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 42 | : face(makeDummyClientFace(io, { true, enableRegistrationReply })) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 43 | { |
| 44 | } |
| 45 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 46 | public: |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 47 | shared_ptr<DummyClientFace> face; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 50 | class FacesNoRegistrationReplyFixture : public FaceFixture |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 51 | { |
| 52 | public: |
| 53 | FacesNoRegistrationReplyFixture() |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 54 | : FaceFixture(false) |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 55 | { |
| 56 | } |
| 57 | }; |
| 58 | |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 59 | BOOST_FIXTURE_TEST_SUITE(TestFace, FaceFixture) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 60 | |
| 61 | BOOST_AUTO_TEST_CASE(ExpressInterestData) |
| 62 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 63 | size_t nData = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 64 | face->expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 65 | [&] (const Interest& i, const Data& d) { |
| 66 | BOOST_CHECK(i.getName().isPrefixOf(d.getName())); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame^] | 67 | BOOST_CHECK_EQUAL(i.getName(), "/Hello/World"); |
| 68 | ++nData; |
| 69 | }, |
| 70 | bind([] { |
| 71 | BOOST_FAIL("Unexpected Nack"); |
| 72 | }), |
| 73 | bind([] { |
| 74 | BOOST_FAIL("Unexpected timeout"); |
| 75 | })); |
| 76 | |
| 77 | advanceClocks(time::milliseconds(1), 40); |
| 78 | |
| 79 | face->receive(*util::makeData("/Bye/World/a")); |
| 80 | face->receive(*util::makeData("/Hello/World/a")); |
| 81 | |
| 82 | advanceClocks(time::milliseconds(1), 100); |
| 83 | |
| 84 | BOOST_CHECK_EQUAL(nData, 1); |
| 85 | BOOST_CHECK_EQUAL(face->sentInterests.size(), 1); |
| 86 | BOOST_CHECK_EQUAL(face->sentDatas.size(), 0); |
| 87 | |
| 88 | size_t nTimeouts = 0; |
| 89 | face->expressInterest(Interest("/Hello/World/a/2", time::milliseconds(50)), |
| 90 | bind([]{}), |
| 91 | bind([]{}), |
| 92 | bind([&nTimeouts] { |
| 93 | ++nTimeouts; |
| 94 | })); |
| 95 | advanceClocks(time::milliseconds(10), 100); |
| 96 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
| 97 | } |
| 98 | |
| 99 | // test case for deprecated expressInterest implementation |
| 100 | BOOST_AUTO_TEST_CASE(DeprecatedExpressInterestData) |
| 101 | { |
| 102 | size_t nData = 0; |
| 103 | face->expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 104 | [&] (const Interest& i, const Data& d) { |
| 105 | BOOST_CHECK(i.getName().isPrefixOf(d.getName())); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 106 | ++nData; |
| 107 | }, |
| 108 | bind([] { |
| 109 | BOOST_FAIL("Unexpected timeout"); |
| 110 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 111 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 112 | advanceClocks(time::milliseconds(1), 40); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 113 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame^] | 114 | face->receive(*util::makeData("/Bye/World/a")); |
| 115 | face->receive(*util::makeData("/Hello/World/a")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 116 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 117 | advanceClocks(time::milliseconds(1), 100); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 118 | |
| 119 | BOOST_CHECK_EQUAL(nData, 1); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 120 | BOOST_CHECK_EQUAL(face->sentInterests.size(), 1); |
| 121 | BOOST_CHECK_EQUAL(face->sentDatas.size(), 0); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 122 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame^] | 123 | face->expressInterest(Interest("/Hello/World/a", time::milliseconds(50)), |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 124 | [&] (const Interest& i, const Data& d) { |
| 125 | BOOST_CHECK(i.getName().isPrefixOf(d.getName())); |
| 126 | ++nData; |
| 127 | }, |
| 128 | bind([] { |
| 129 | BOOST_FAIL("Unexpected timeout"); |
| 130 | })); |
| 131 | advanceClocks(time::milliseconds(1), 40); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame^] | 132 | face->receive(*util::makeData("/Hello/World/a/1/xxxxx")); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 133 | |
| 134 | advanceClocks(time::milliseconds(1), 100); |
| 135 | |
| 136 | BOOST_CHECK_EQUAL(nData, 2); |
| 137 | BOOST_CHECK_EQUAL(face->sentInterests.size(), 2); |
| 138 | BOOST_CHECK_EQUAL(face->sentDatas.size(), 0); |
| 139 | |
| 140 | size_t nTimeouts = 0; |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame^] | 141 | face->expressInterest(Interest("/Hello/World/a/2", time::milliseconds(50)), |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 142 | bind([]{}), |
| 143 | bind([&nTimeouts] { |
| 144 | ++nTimeouts; |
| 145 | })); |
| 146 | advanceClocks(time::milliseconds(10), 100); |
| 147 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | BOOST_AUTO_TEST_CASE(ExpressInterestTimeout) |
| 151 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 152 | size_t nTimeouts = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 153 | face->expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 154 | bind([] { |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame^] | 155 | BOOST_FAIL("Unexpected ata"); |
| 156 | }), |
| 157 | bind([] { |
| 158 | BOOST_FAIL("Unexpected Nack"); |
| 159 | }), |
| 160 | [&nTimeouts] (const Interest& i) { |
| 161 | BOOST_CHECK_EQUAL(i.getName(), "/Hello/World"); |
| 162 | ++nTimeouts; |
| 163 | }); |
| 164 | |
| 165 | advanceClocks(time::milliseconds(10), 100); |
| 166 | |
| 167 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
| 168 | BOOST_CHECK_EQUAL(face->sentInterests.size(), 1); |
| 169 | BOOST_CHECK_EQUAL(face->sentDatas.size(), 0); |
| 170 | BOOST_CHECK_EQUAL(face->sentNacks.size(), 0); |
| 171 | } |
| 172 | |
| 173 | // test case for deprecated expressInterest implementation |
| 174 | BOOST_AUTO_TEST_CASE(DeprecatedExpressInterestTimeout) |
| 175 | { |
| 176 | size_t nTimeouts = 0; |
| 177 | face->expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 178 | bind([] { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 179 | BOOST_FAIL("Unexpected data"); |
| 180 | }), |
| 181 | bind([&nTimeouts] { |
| 182 | ++nTimeouts; |
| 183 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 184 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 185 | advanceClocks(time::milliseconds(10), 100); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 186 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 187 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 188 | BOOST_CHECK_EQUAL(face->sentInterests.size(), 1); |
| 189 | BOOST_CHECK_EQUAL(face->sentDatas.size(), 0); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 190 | } |
| 191 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame^] | 192 | BOOST_AUTO_TEST_CASE(ExpressInterestNack) |
| 193 | { |
| 194 | size_t nNacks = 0; |
| 195 | |
| 196 | Interest interest("/Hello/World", time::milliseconds(50)); |
| 197 | |
| 198 | face->expressInterest(interest, |
| 199 | bind([] { |
| 200 | BOOST_FAIL("Unexpected Data"); |
| 201 | }), |
| 202 | [&] (const Interest& i, const lp::Nack& n) { |
| 203 | BOOST_CHECK(i.getName().isPrefixOf(n.getInterest().getName())); |
| 204 | BOOST_CHECK_EQUAL(i.getName(), "/Hello/World"); |
| 205 | BOOST_CHECK_EQUAL(n.getReason(), lp::NackReason::DUPLICATE); |
| 206 | ++nNacks; |
| 207 | }, |
| 208 | bind([] { |
| 209 | BOOST_FAIL("Unexpected timeout"); |
| 210 | })); |
| 211 | |
| 212 | advanceClocks(time::milliseconds(1), 40); |
| 213 | |
| 214 | lp::Nack nack(face->sentInterests[0]); |
| 215 | nack.setReason(lp::NackReason::DUPLICATE); |
| 216 | |
| 217 | BOOST_CHECK_EQUAL(face->sentNacks.size(), 0); |
| 218 | |
| 219 | face->receive(nack); |
| 220 | |
| 221 | advanceClocks(time::milliseconds(1), 100); |
| 222 | |
| 223 | BOOST_CHECK_EQUAL(nNacks, 1); |
| 224 | BOOST_CHECK_EQUAL(face->sentInterests.size(), 1); |
| 225 | } |
| 226 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 227 | BOOST_AUTO_TEST_CASE(RemovePendingInterest) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 228 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 229 | const PendingInterestId* interestId = |
| 230 | face->expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 231 | bind([] { |
| 232 | BOOST_FAIL("Unexpected data"); |
| 233 | }), |
| 234 | bind([] { |
| 235 | BOOST_FAIL("Unexpected timeout"); |
| 236 | })); |
| 237 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 238 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 239 | face->removePendingInterest(interestId); |
| 240 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 241 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 242 | face->receive(*util::makeData("/Hello/World/!")); |
| 243 | advanceClocks(time::milliseconds(10), 100); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | BOOST_AUTO_TEST_CASE(SetUnsetInterestFilter) |
| 247 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 248 | size_t nInterests = 0; |
| 249 | size_t nRegs = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 250 | const RegisteredPrefixId* regPrefixId = |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 251 | face->setInterestFilter("/Hello/World", |
| 252 | bind([&nInterests] { ++nInterests; }), |
| 253 | bind([&nRegs] { ++nRegs; }), |
| 254 | bind([] { |
| 255 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 256 | })); |
| 257 | advanceClocks(time::milliseconds(10), 10); |
| 258 | BOOST_CHECK_EQUAL(nRegs, 1); |
| 259 | BOOST_CHECK_EQUAL(nInterests, 0); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 260 | |
| 261 | face->receive(Interest("/Hello/World/!")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 262 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 263 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 264 | BOOST_CHECK_EQUAL(nRegs, 1); |
| 265 | BOOST_CHECK_EQUAL(nInterests, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 266 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 267 | face->receive(Interest("/Bye/World/!")); |
| 268 | advanceClocks(time::milliseconds(10000), 10); |
| 269 | BOOST_CHECK_EQUAL(nInterests, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 270 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 271 | face->receive(Interest("/Hello/World/!/2")); |
| 272 | advanceClocks(time::milliseconds(10), 10); |
| 273 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 274 | |
| 275 | // removing filter |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 276 | face->unsetInterestFilter(regPrefixId); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 277 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 278 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 279 | face->receive(Interest("/Hello/World/!/3")); |
| 280 | BOOST_CHECK_EQUAL(nInterests, 2); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 281 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 282 | face->unsetInterestFilter(static_cast<const RegisteredPrefixId*>(0)); |
| 283 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 284 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 285 | face->unsetInterestFilter(static_cast<const InterestFilterId*>(0)); |
| 286 | advanceClocks(time::milliseconds(10), 10); |
| 287 | } |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 288 | |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 289 | BOOST_AUTO_TEST_CASE(SetUnsetInterestFilterWithoutSucessCallback) |
| 290 | { |
| 291 | size_t nInterests = 0; |
| 292 | const RegisteredPrefixId* regPrefixId = |
| 293 | face->setInterestFilter("/Hello/World", |
| 294 | bind([&nInterests] { ++nInterests; }), |
| 295 | bind([] { |
| 296 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 297 | })); |
| 298 | advanceClocks(time::milliseconds(10), 10); |
| 299 | BOOST_CHECK_EQUAL(nInterests, 0); |
| 300 | |
| 301 | face->receive(Interest("/Hello/World/!")); |
| 302 | advanceClocks(time::milliseconds(10), 10); |
| 303 | |
| 304 | BOOST_CHECK_EQUAL(nInterests, 1); |
| 305 | |
| 306 | face->receive(Interest("/Bye/World/!")); |
| 307 | advanceClocks(time::milliseconds(10000), 10); |
| 308 | BOOST_CHECK_EQUAL(nInterests, 1); |
| 309 | |
| 310 | face->receive(Interest("/Hello/World/!/2")); |
| 311 | advanceClocks(time::milliseconds(10), 10); |
| 312 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 313 | |
| 314 | // removing filter |
| 315 | face->unsetInterestFilter(regPrefixId); |
| 316 | advanceClocks(time::milliseconds(10), 10); |
| 317 | |
| 318 | face->receive(Interest("/Hello/World/!/3")); |
| 319 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 320 | |
| 321 | face->unsetInterestFilter(static_cast<const RegisteredPrefixId*>(0)); |
| 322 | advanceClocks(time::milliseconds(10), 10); |
| 323 | |
| 324 | face->unsetInterestFilter(static_cast<const InterestFilterId*>(0)); |
| 325 | advanceClocks(time::milliseconds(10), 10); |
| 326 | } |
| 327 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 328 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterFail, FacesNoRegistrationReplyFixture) |
| 329 | { |
| 330 | // don't enable registration reply |
| 331 | size_t nRegFailed = 0; |
| 332 | face->setInterestFilter("/Hello/World", |
| 333 | bind([] { |
| 334 | BOOST_FAIL("Unexpected Interest"); |
| 335 | }), |
| 336 | bind([] { |
| 337 | BOOST_FAIL("Unexpected success of setInterestFilter"); |
| 338 | }), |
| 339 | bind([&nRegFailed] { |
| 340 | ++nRegFailed; |
| 341 | })); |
| 342 | |
| 343 | advanceClocks(time::milliseconds(10), 10); |
| 344 | BOOST_CHECK_EQUAL(nRegFailed, 0); |
| 345 | |
| 346 | advanceClocks(time::milliseconds(1000), 10); |
| 347 | BOOST_CHECK_EQUAL(nRegFailed, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 348 | } |
| 349 | |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 350 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterFailWithoutSuccessCallback, FacesNoRegistrationReplyFixture) |
| 351 | { |
| 352 | // don't enable registration reply |
| 353 | size_t nRegFailed = 0; |
| 354 | face->setInterestFilter("/Hello/World", |
| 355 | bind([] { |
| 356 | BOOST_FAIL("Unexpected Interest"); |
| 357 | }), |
| 358 | bind([&nRegFailed] { |
| 359 | ++nRegFailed; |
| 360 | })); |
| 361 | |
| 362 | advanceClocks(time::milliseconds(10), 10); |
| 363 | BOOST_CHECK_EQUAL(nRegFailed, 0); |
| 364 | |
| 365 | advanceClocks(time::milliseconds(1000), 10); |
| 366 | BOOST_CHECK_EQUAL(nRegFailed, 1); |
| 367 | } |
| 368 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 369 | BOOST_AUTO_TEST_CASE(RegisterUnregisterPrefix) |
| 370 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 371 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 372 | const RegisteredPrefixId* regPrefixId = |
| 373 | face->registerPrefix("/Hello/World", |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 374 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
| 375 | bind([] { |
| 376 | BOOST_FAIL("Unexpected registerPrefix failure"); |
| 377 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 378 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 379 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 380 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 381 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 382 | size_t nUnregSuccesses = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 383 | face->unregisterPrefix(regPrefixId, |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 384 | bind([&nUnregSuccesses] { ++nUnregSuccesses; }), |
| 385 | bind([] { |
| 386 | BOOST_FAIL("Unexpected unregisterPrefix failure"); |
| 387 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 388 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 389 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 390 | BOOST_CHECK_EQUAL(nUnregSuccesses, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 391 | } |
| 392 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 393 | BOOST_FIXTURE_TEST_CASE(RegisterUnregisterPrefixFail, FacesNoRegistrationReplyFixture) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 394 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 395 | size_t nRegFailures = 0; |
| 396 | face->registerPrefix("/Hello/World", |
| 397 | bind([] { |
| 398 | BOOST_FAIL("Unexpected registerPrefix success"); |
| 399 | }), |
| 400 | bind([&nRegFailures] { ++nRegFailures; })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 401 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 402 | advanceClocks(time::milliseconds(1000), 100); |
| 403 | BOOST_CHECK_EQUAL(nRegFailures, 1); |
| 404 | } |
| 405 | |
| 406 | BOOST_AUTO_TEST_CASE(SimilarFilters) |
| 407 | { |
| 408 | size_t nInInterests1 = 0; |
| 409 | face->setInterestFilter("/Hello/World", |
| 410 | bind([&nInInterests1] { ++nInInterests1; }), |
| 411 | RegisterPrefixSuccessCallback(), |
| 412 | bind([] { |
| 413 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 414 | })); |
| 415 | |
| 416 | size_t nInInterests2 = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 417 | face->setInterestFilter("/Hello", |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 418 | bind([&nInInterests2] { ++nInInterests2; }), |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 419 | RegisterPrefixSuccessCallback(), |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 420 | bind([] { |
| 421 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 422 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 423 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 424 | size_t nInInterests3 = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 425 | face->setInterestFilter("/Los/Angeles/Lakers", |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 426 | bind([&nInInterests3] { ++nInInterests3; }), |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 427 | RegisterPrefixSuccessCallback(), |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 428 | bind([] { |
| 429 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 430 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 431 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 432 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 433 | |
| 434 | face->receive(Interest("/Hello/World/!")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 435 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 436 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 437 | BOOST_CHECK_EQUAL(nInInterests1, 1); |
| 438 | BOOST_CHECK_EQUAL(nInInterests2, 1); |
| 439 | BOOST_CHECK_EQUAL(nInInterests3, 0); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | BOOST_AUTO_TEST_CASE(SetRegexFilterError) |
| 443 | { |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 444 | face->setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 445 | [] (const Name&, const Interest&) { |
| 446 | BOOST_FAIL("InterestFilter::Error should have been triggered"); |
| 447 | }, |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 448 | RegisterPrefixSuccessCallback(), |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 449 | bind([] { |
| 450 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 451 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 452 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 453 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 454 | |
| 455 | BOOST_REQUIRE_THROW(face->receive(Interest("/Hello/World/XXX/b/c")), InterestFilter::Error); |
| 456 | } |
| 457 | |
| 458 | BOOST_AUTO_TEST_CASE(SetRegexFilter) |
| 459 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 460 | size_t nInInterests = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 461 | face->setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 462 | bind([&nInInterests] { ++nInInterests; }), |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 463 | RegisterPrefixSuccessCallback(), |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 464 | bind([] { |
| 465 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 466 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 467 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 468 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 469 | |
| 470 | face->receive(Interest("/Hello/World/a")); // shouldn't match |
| 471 | BOOST_CHECK_EQUAL(nInInterests, 0); |
| 472 | |
| 473 | face->receive(Interest("/Hello/World/a/b")); // should match |
| 474 | BOOST_CHECK_EQUAL(nInInterests, 1); |
| 475 | |
| 476 | face->receive(Interest("/Hello/World/a/b/c")); // should match |
| 477 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 478 | |
| 479 | face->receive(Interest("/Hello/World/a/b/d")); // should not match |
| 480 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 481 | } |
| 482 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 483 | BOOST_AUTO_TEST_CASE(SetRegexFilterAndRegister) |
| 484 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 485 | size_t nInInterests = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 486 | face->setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 487 | bind([&nInInterests] { ++nInInterests; })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 488 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 489 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 490 | face->registerPrefix("/Hello/World", |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 491 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
| 492 | bind([] { |
| 493 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 494 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 495 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 496 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 497 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 498 | |
| 499 | face->receive(Interest("/Hello/World/a")); // shouldn't match |
| 500 | BOOST_CHECK_EQUAL(nInInterests, 0); |
| 501 | |
| 502 | face->receive(Interest("/Hello/World/a/b")); // should match |
| 503 | BOOST_CHECK_EQUAL(nInInterests, 1); |
| 504 | |
| 505 | face->receive(Interest("/Hello/World/a/b/c")); // should match |
| 506 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 507 | |
| 508 | face->receive(Interest("/Hello/World/a/b/d")); // should not match |
| 509 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 510 | } |
| 511 | |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 512 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterNoReg, FacesNoRegistrationReplyFixture) // Bug 2318 |
| 513 | { |
| 514 | // This behavior is specific to DummyClientFace. |
| 515 | // Regular Face won't accept incoming packets until something is sent. |
| 516 | |
| 517 | int hit = 0; |
| 518 | face->setInterestFilter(Name("/"), bind([&hit] { ++hit; })); |
| 519 | face->processEvents(time::milliseconds(-1)); |
| 520 | |
| 521 | auto interest = make_shared<Interest>("/A"); |
| 522 | face->receive(*interest); |
| 523 | face->processEvents(time::milliseconds(-1)); |
| 524 | |
| 525 | BOOST_CHECK_EQUAL(hit, 1); |
| 526 | } |
| 527 | |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 528 | BOOST_AUTO_TEST_CASE(ProcessEvents) |
| 529 | { |
| 530 | face->processEvents(time::milliseconds(-1)); // io_service::reset()/poll() inside |
| 531 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 532 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 533 | face->registerPrefix("/Hello/World", |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 534 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
| 535 | bind([] { |
| 536 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 537 | })); |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 538 | |
| 539 | // io_service::poll() without reset |
| 540 | face->getIoService().poll(); |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 541 | BOOST_CHECK_EQUAL(nRegSuccesses, 0); |
| 542 | |
| 543 | face->processEvents(time::milliseconds(-1)); // io_service::reset()/poll() inside |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 544 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 545 | } |
| 546 | |
Alexander Afanasyev | ea71967 | 2015-02-10 20:25:23 -0800 | [diff] [blame] | 547 | BOOST_AUTO_TEST_CASE(ExpressInterestWithLocalControlHeader) |
| 548 | { |
| 549 | Interest i("/Hello/World"); |
| 550 | i.setNextHopFaceId(1000); |
| 551 | i.setIncomingFaceId(2000); |
| 552 | |
| 553 | face->expressInterest(i, bind([]{}), bind([]{})); |
| 554 | advanceClocks(time::milliseconds(10)); |
| 555 | |
| 556 | BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1); |
| 557 | // only NextHopFaceId is allowed to go out |
| 558 | BOOST_CHECK(face->sentInterests[0].getLocalControlHeader().hasNextHopFaceId()); |
| 559 | BOOST_CHECK(!face->sentInterests[0].getLocalControlHeader().hasIncomingFaceId()); |
| 560 | BOOST_CHECK_EQUAL(face->sentInterests[0].getNextHopFaceId(), 1000); |
| 561 | } |
| 562 | |
| 563 | BOOST_AUTO_TEST_CASE(ReceiveInterestWithLocalControlHeader) |
| 564 | { |
| 565 | face->setInterestFilter("/Hello/World", |
| 566 | [] (const InterestFilter&, const Interest& i) { |
Alexander Afanasyev | ea71967 | 2015-02-10 20:25:23 -0800 | [diff] [blame] | 567 | BOOST_CHECK(i.getLocalControlHeader().hasIncomingFaceId()); |
Alexander Afanasyev | ea71967 | 2015-02-10 20:25:23 -0800 | [diff] [blame] | 568 | BOOST_CHECK_EQUAL(i.getIncomingFaceId(), 2000); |
| 569 | }, |
| 570 | bind([]{}), |
| 571 | bind([] { |
| 572 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 573 | })); |
| 574 | advanceClocks(time::milliseconds(10)); |
| 575 | |
| 576 | Interest i("/Hello/World/!"); |
| 577 | i.setNextHopFaceId(1000); |
| 578 | i.setIncomingFaceId(2000); |
| 579 | |
| 580 | face->receive(i); |
| 581 | advanceClocks(time::milliseconds(10)); |
| 582 | } |
| 583 | |
| 584 | BOOST_AUTO_TEST_CASE(PutDataWithLocalControlHeader) |
| 585 | { |
| 586 | shared_ptr<Data> d = util::makeData("/Bye/World/!"); |
| 587 | d->setIncomingFaceId(2000); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 588 | d->getLocalControlHeader().setNextHopFaceId(1000); // setNextHopFaceId is intentionally |
| 589 | // not exposed directly |
Alexander Afanasyev | ea71967 | 2015-02-10 20:25:23 -0800 | [diff] [blame] | 590 | |
| 591 | face->put(*d); |
| 592 | advanceClocks(time::milliseconds(10)); |
| 593 | |
| 594 | BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1); |
| 595 | BOOST_CHECK(!face->sentDatas[0].getLocalControlHeader().hasNextHopFaceId()); |
| 596 | BOOST_CHECK(!face->sentDatas[0].getLocalControlHeader().hasIncomingFaceId()); |
| 597 | } |
| 598 | |
| 599 | BOOST_AUTO_TEST_CASE(ReceiveDataWithLocalControlHeader) |
| 600 | { |
| 601 | face->expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 602 | [&] (const Interest& i, const Data& d) { |
Alexander Afanasyev | ea71967 | 2015-02-10 20:25:23 -0800 | [diff] [blame] | 603 | BOOST_CHECK(d.getLocalControlHeader().hasIncomingFaceId()); |
| 604 | BOOST_CHECK_EQUAL(d.getIncomingFaceId(), 2000); |
Alexander Afanasyev | ea71967 | 2015-02-10 20:25:23 -0800 | [diff] [blame] | 605 | }, |
| 606 | bind([] { |
| 607 | BOOST_FAIL("Unexpected timeout"); |
| 608 | })); |
| 609 | |
| 610 | advanceClocks(time::milliseconds(10)); |
| 611 | |
| 612 | shared_ptr<Data> d = util::makeData("/Hello/World/!"); |
| 613 | d->setIncomingFaceId(2000); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 614 | d->getLocalControlHeader().setNextHopFaceId(1000); // setNextHopFaceId is intentionally |
| 615 | // not exposed directly |
Alexander Afanasyev | ea71967 | 2015-02-10 20:25:23 -0800 | [diff] [blame] | 616 | face->receive(*d); |
| 617 | |
| 618 | advanceClocks(time::milliseconds(10), 100); |
| 619 | } |
| 620 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame^] | 621 | BOOST_AUTO_TEST_CASE(PutNack) |
| 622 | { |
| 623 | lp::Nack nack(Interest("/Hello/World", time::milliseconds(50))); |
| 624 | nack.setReason(lp::NackReason::NO_ROUTE); |
| 625 | |
| 626 | BOOST_CHECK_EQUAL(face->sentNacks.size(), 0); |
| 627 | |
| 628 | face->put(nack); |
| 629 | |
| 630 | advanceClocks(time::milliseconds(10)); |
| 631 | |
| 632 | BOOST_CHECK_EQUAL(face->sentNacks.size(), 1); |
| 633 | } |
| 634 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 635 | BOOST_AUTO_TEST_CASE(DestructionWithoutCancellingPendingInterests) // Bug #2518 |
| 636 | { |
| 637 | face->expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 638 | bind([]{}), bind([]{})); |
| 639 | advanceClocks(time::milliseconds(10), 10); |
| 640 | |
| 641 | face.reset(); |
| 642 | |
| 643 | advanceClocks(time::milliseconds(10), 10); |
| 644 | // should not segfault |
| 645 | } |
| 646 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 647 | BOOST_AUTO_TEST_SUITE_END() |
| 648 | |
| 649 | } // tests |
| 650 | } // namespace ndn |