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 | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 26 | #include "transport/tcp-transport.hpp" |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 27 | |
| 28 | #include "boost-test.hpp" |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 29 | #include "unit-test-time-fixture.hpp" |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 30 | #include "make-interest-data.hpp" |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 31 | |
| 32 | namespace ndn { |
| 33 | namespace tests { |
| 34 | |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 35 | using ndn::util::DummyClientFace; |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 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 | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 42 | : face(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 | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 47 | 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 | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 64 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 65 | [&] (const Interest& i, const Data& d) { |
| 66 | BOOST_CHECK(i.getName().isPrefixOf(d.getName())); |
| 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 | })); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 76 | |
| 77 | advanceClocks(time::milliseconds(1), 40); |
| 78 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 79 | face.receive(*util::makeData("/Bye/World/a")); |
| 80 | face.receive(*util::makeData("/Hello/World/a")); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 81 | |
| 82 | advanceClocks(time::milliseconds(1), 100); |
| 83 | |
| 84 | BOOST_CHECK_EQUAL(nData, 1); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 85 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 86 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 87 | |
| 88 | size_t nTimeouts = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 89 | face.expressInterest(Interest("/Hello/World/a/2", time::milliseconds(50)), |
| 90 | bind([]{}), |
| 91 | bind([]{}), |
| 92 | bind([&nTimeouts] { |
| 93 | ++nTimeouts; |
| 94 | })); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 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; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 103 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 104 | [&] (const Interest& i, const Data& d) { |
| 105 | BOOST_CHECK(i.getName().isPrefixOf(d.getName())); |
| 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 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [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 | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 120 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 121 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 122 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 123 | face.expressInterest(Interest("/Hello/World/a", time::milliseconds(50)), |
| 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 | })); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 131 | advanceClocks(time::milliseconds(1), 40); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [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); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 137 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 2); |
| 138 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 139 | |
| 140 | size_t nTimeouts = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 141 | face.expressInterest(Interest("/Hello/World/a/2", time::milliseconds(50)), |
| 142 | bind([]{}), |
| 143 | bind([&nTimeouts] { |
| 144 | ++nTimeouts; |
| 145 | })); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 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 | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 153 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 154 | bind([] { |
| 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 | }); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 164 | |
| 165 | advanceClocks(time::milliseconds(10), 100); |
| 166 | |
| 167 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 168 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 169 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
| 170 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | // test case for deprecated expressInterest implementation |
| 174 | BOOST_AUTO_TEST_CASE(DeprecatedExpressInterestTimeout) |
| 175 | { |
| 176 | size_t nTimeouts = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 177 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 178 | bind([] { |
| 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 | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 188 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 189 | BOOST_CHECK_EQUAL(face.sentData.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 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 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 | })); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 211 | |
| 212 | advanceClocks(time::milliseconds(1), 40); |
| 213 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 214 | lp::Nack nack(face.sentInterests[0]); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 215 | nack.setReason(lp::NackReason::DUPLICATE); |
| 216 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 217 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 218 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 219 | face.receive(nack); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 220 | |
| 221 | advanceClocks(time::milliseconds(1), 100); |
| 222 | |
| 223 | BOOST_CHECK_EQUAL(nNacks, 1); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 224 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 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 = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 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 | })); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 237 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 238 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 239 | face.removePendingInterest(interestId); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 240 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 241 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 242 | face.receive(*util::makeData("/Hello/World/!")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 243 | advanceClocks(time::milliseconds(10), 100); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 244 | } |
| 245 | |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 246 | BOOST_AUTO_TEST_CASE(removeAllPendingInterests) |
| 247 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 248 | face.expressInterest(Interest("/Hello/World/0", time::milliseconds(50)), |
| 249 | bind([] { BOOST_FAIL("Unexpected data"); }), |
| 250 | bind([] { BOOST_FAIL("Unexpected nack"); }), |
| 251 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 252 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 253 | face.expressInterest(Interest("/Hello/World/1", time::milliseconds(50)), |
| 254 | bind([] { BOOST_FAIL("Unexpected data"); }), |
| 255 | bind([] { BOOST_FAIL("Unexpected nack"); }), |
| 256 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 257 | |
| 258 | advanceClocks(time::milliseconds(10)); |
| 259 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 260 | face.removeAllPendingInterests(); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 261 | advanceClocks(time::milliseconds(10)); |
| 262 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 263 | BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 264 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 265 | face.receive(*util::makeData("/Hello/World/0")); |
| 266 | face.receive(*util::makeData("/Hello/World/1")); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 267 | advanceClocks(time::milliseconds(10), 100); |
| 268 | } |
| 269 | |
| 270 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 271 | BOOST_AUTO_TEST_CASE(SetUnsetInterestFilter) |
| 272 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 273 | size_t nInterests = 0; |
| 274 | size_t nRegs = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 275 | const RegisteredPrefixId* regPrefixId = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 276 | face.setInterestFilter("/Hello/World", |
| 277 | bind([&nInterests] { ++nInterests; }), |
| 278 | bind([&nRegs] { ++nRegs; }), |
| 279 | bind([] { |
| 280 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 281 | })); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 282 | advanceClocks(time::milliseconds(10), 10); |
| 283 | BOOST_CHECK_EQUAL(nRegs, 1); |
| 284 | BOOST_CHECK_EQUAL(nInterests, 0); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 285 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 286 | face.receive(Interest("/Hello/World/!")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 287 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 288 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 289 | BOOST_CHECK_EQUAL(nRegs, 1); |
| 290 | BOOST_CHECK_EQUAL(nInterests, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 291 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 292 | face.receive(Interest("/Bye/World/!")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 293 | advanceClocks(time::milliseconds(10000), 10); |
| 294 | BOOST_CHECK_EQUAL(nInterests, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 295 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 296 | face.receive(Interest("/Hello/World/!/2")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 297 | advanceClocks(time::milliseconds(10), 10); |
| 298 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 299 | |
| 300 | // removing filter |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 301 | face.unsetInterestFilter(regPrefixId); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 302 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 303 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 304 | face.receive(Interest("/Hello/World/!/3")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 305 | BOOST_CHECK_EQUAL(nInterests, 2); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 306 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 307 | face.unsetInterestFilter(static_cast<const RegisteredPrefixId*>(0)); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 308 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 309 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 310 | face.unsetInterestFilter(static_cast<const InterestFilterId*>(0)); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 311 | advanceClocks(time::milliseconds(10), 10); |
| 312 | } |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 313 | |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 314 | BOOST_AUTO_TEST_CASE(SetUnsetInterestFilterWithoutSucessCallback) |
| 315 | { |
| 316 | size_t nInterests = 0; |
| 317 | const RegisteredPrefixId* regPrefixId = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 318 | face.setInterestFilter("/Hello/World", |
| 319 | bind([&nInterests] { ++nInterests; }), |
| 320 | bind([] { |
| 321 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 322 | })); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 323 | advanceClocks(time::milliseconds(10), 10); |
| 324 | BOOST_CHECK_EQUAL(nInterests, 0); |
| 325 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 326 | face.receive(Interest("/Hello/World/!")); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 327 | advanceClocks(time::milliseconds(10), 10); |
| 328 | |
| 329 | BOOST_CHECK_EQUAL(nInterests, 1); |
| 330 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 331 | face.receive(Interest("/Bye/World/!")); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 332 | advanceClocks(time::milliseconds(10000), 10); |
| 333 | BOOST_CHECK_EQUAL(nInterests, 1); |
| 334 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 335 | face.receive(Interest("/Hello/World/!/2")); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 336 | advanceClocks(time::milliseconds(10), 10); |
| 337 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 338 | |
| 339 | // removing filter |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 340 | face.unsetInterestFilter(regPrefixId); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 341 | advanceClocks(time::milliseconds(10), 10); |
| 342 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 343 | face.receive(Interest("/Hello/World/!/3")); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 344 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 345 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 346 | face.unsetInterestFilter(static_cast<const RegisteredPrefixId*>(0)); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 347 | advanceClocks(time::milliseconds(10), 10); |
| 348 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 349 | face.unsetInterestFilter(static_cast<const InterestFilterId*>(0)); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 350 | advanceClocks(time::milliseconds(10), 10); |
| 351 | } |
| 352 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 353 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterFail, FacesNoRegistrationReplyFixture) |
| 354 | { |
| 355 | // don't enable registration reply |
| 356 | size_t nRegFailed = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 357 | face.setInterestFilter("/Hello/World", |
| 358 | bind([] { |
| 359 | BOOST_FAIL("Unexpected Interest"); |
| 360 | }), |
| 361 | bind([] { |
| 362 | BOOST_FAIL("Unexpected success of setInterestFilter"); |
| 363 | }), |
| 364 | bind([&nRegFailed] { |
| 365 | ++nRegFailed; |
| 366 | })); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 367 | |
| 368 | advanceClocks(time::milliseconds(10), 10); |
| 369 | BOOST_CHECK_EQUAL(nRegFailed, 0); |
| 370 | |
| 371 | advanceClocks(time::milliseconds(1000), 10); |
| 372 | BOOST_CHECK_EQUAL(nRegFailed, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 373 | } |
| 374 | |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 375 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterFailWithoutSuccessCallback, FacesNoRegistrationReplyFixture) |
| 376 | { |
| 377 | // don't enable registration reply |
| 378 | size_t nRegFailed = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 379 | face.setInterestFilter("/Hello/World", |
| 380 | bind([] { |
| 381 | BOOST_FAIL("Unexpected Interest"); |
| 382 | }), |
| 383 | bind([&nRegFailed] { |
| 384 | ++nRegFailed; |
| 385 | })); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 386 | |
| 387 | advanceClocks(time::milliseconds(10), 10); |
| 388 | BOOST_CHECK_EQUAL(nRegFailed, 0); |
| 389 | |
| 390 | advanceClocks(time::milliseconds(1000), 10); |
| 391 | BOOST_CHECK_EQUAL(nRegFailed, 1); |
| 392 | } |
| 393 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 394 | BOOST_AUTO_TEST_CASE(RegisterUnregisterPrefix) |
| 395 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 396 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 397 | const RegisteredPrefixId* regPrefixId = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 398 | face.registerPrefix("/Hello/World", |
| 399 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
| 400 | bind([] { |
| 401 | BOOST_FAIL("Unexpected registerPrefix failure"); |
| 402 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 403 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 404 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 405 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 406 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 407 | size_t nUnregSuccesses = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 408 | face.unregisterPrefix(regPrefixId, |
| 409 | bind([&nUnregSuccesses] { ++nUnregSuccesses; }), |
| 410 | bind([] { |
| 411 | BOOST_FAIL("Unexpected unregisterPrefix failure"); |
| 412 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 413 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 414 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 415 | BOOST_CHECK_EQUAL(nUnregSuccesses, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 416 | } |
| 417 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 418 | BOOST_FIXTURE_TEST_CASE(RegisterUnregisterPrefixFail, FacesNoRegistrationReplyFixture) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 419 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 420 | size_t nRegFailures = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 421 | face.registerPrefix("/Hello/World", |
| 422 | bind([] { |
| 423 | BOOST_FAIL("Unexpected registerPrefix success"); |
| 424 | }), |
| 425 | bind([&nRegFailures] { ++nRegFailures; })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 426 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 427 | advanceClocks(time::milliseconds(1000), 100); |
| 428 | BOOST_CHECK_EQUAL(nRegFailures, 1); |
| 429 | } |
| 430 | |
| 431 | BOOST_AUTO_TEST_CASE(SimilarFilters) |
| 432 | { |
| 433 | size_t nInInterests1 = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 434 | face.setInterestFilter("/Hello/World", |
| 435 | bind([&nInInterests1] { ++nInInterests1; }), |
| 436 | RegisterPrefixSuccessCallback(), |
| 437 | bind([] { |
| 438 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 439 | })); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 440 | |
| 441 | size_t nInInterests2 = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 442 | face.setInterestFilter("/Hello", |
| 443 | bind([&nInInterests2] { ++nInInterests2; }), |
| 444 | RegisterPrefixSuccessCallback(), |
| 445 | bind([] { |
| 446 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 447 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 448 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 449 | size_t nInInterests3 = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 450 | face.setInterestFilter("/Los/Angeles/Lakers", |
| 451 | bind([&nInInterests3] { ++nInInterests3; }), |
| 452 | RegisterPrefixSuccessCallback(), |
| 453 | bind([] { |
| 454 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 455 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 456 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 457 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 458 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 459 | face.receive(Interest("/Hello/World/!")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 460 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 461 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 462 | BOOST_CHECK_EQUAL(nInInterests1, 1); |
| 463 | BOOST_CHECK_EQUAL(nInInterests2, 1); |
| 464 | BOOST_CHECK_EQUAL(nInInterests3, 0); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | BOOST_AUTO_TEST_CASE(SetRegexFilterError) |
| 468 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 469 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 470 | [] (const Name&, const Interest&) { |
| 471 | BOOST_FAIL("InterestFilter::Error should have been triggered"); |
| 472 | }, |
| 473 | RegisterPrefixSuccessCallback(), |
| 474 | bind([] { |
| 475 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 476 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 477 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 478 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 479 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 480 | BOOST_REQUIRE_THROW(face.receive(Interest("/Hello/World/XXX/b/c")), InterestFilter::Error); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | BOOST_AUTO_TEST_CASE(SetRegexFilter) |
| 484 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 485 | size_t nInInterests = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 486 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 487 | bind([&nInInterests] { ++nInInterests; }), |
| 488 | RegisterPrefixSuccessCallback(), |
| 489 | bind([] { |
| 490 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 491 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 492 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 493 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 494 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 495 | face.receive(Interest("/Hello/World/a")); // shouldn't match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 496 | BOOST_CHECK_EQUAL(nInInterests, 0); |
| 497 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 498 | face.receive(Interest("/Hello/World/a/b")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 499 | BOOST_CHECK_EQUAL(nInInterests, 1); |
| 500 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 501 | face.receive(Interest("/Hello/World/a/b/c")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 502 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 503 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 504 | face.receive(Interest("/Hello/World/a/b/d")); // should not match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 505 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 506 | } |
| 507 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 508 | BOOST_AUTO_TEST_CASE(SetRegexFilterAndRegister) |
| 509 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 510 | size_t nInInterests = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 511 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 512 | bind([&nInInterests] { ++nInInterests; })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 513 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 514 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 515 | face.registerPrefix("/Hello/World", |
| 516 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
| 517 | bind([] { |
| 518 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 519 | })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 520 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 521 | advanceClocks(time::milliseconds(10), 10); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 522 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 523 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 524 | face.receive(Interest("/Hello/World/a")); // shouldn't match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 525 | BOOST_CHECK_EQUAL(nInInterests, 0); |
| 526 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 527 | face.receive(Interest("/Hello/World/a/b")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 528 | BOOST_CHECK_EQUAL(nInInterests, 1); |
| 529 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 530 | face.receive(Interest("/Hello/World/a/b/c")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 531 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 532 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 533 | face.receive(Interest("/Hello/World/a/b/d")); // should not match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 534 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 535 | } |
| 536 | |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 537 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterNoReg, FacesNoRegistrationReplyFixture) // Bug 2318 |
| 538 | { |
| 539 | // This behavior is specific to DummyClientFace. |
| 540 | // Regular Face won't accept incoming packets until something is sent. |
| 541 | |
| 542 | int hit = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 543 | face.setInterestFilter(Name("/"), bind([&hit] { ++hit; })); |
| 544 | face.processEvents(time::milliseconds(-1)); |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 545 | |
| 546 | auto interest = make_shared<Interest>("/A"); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 547 | face.receive(*interest); |
| 548 | face.processEvents(time::milliseconds(-1)); |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 549 | |
| 550 | BOOST_CHECK_EQUAL(hit, 1); |
| 551 | } |
| 552 | |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 553 | BOOST_AUTO_TEST_CASE(ProcessEvents) |
| 554 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 555 | face.processEvents(time::milliseconds(-1)); // io_service::reset()/poll() inside |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 556 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 557 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 558 | face.registerPrefix("/Hello/World", |
| 559 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
| 560 | bind([] { |
| 561 | BOOST_FAIL("Unexpected setInterestFilter failure"); |
| 562 | })); |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 563 | |
| 564 | // io_service::poll() without reset |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 565 | face.getIoService().poll(); |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 566 | BOOST_CHECK_EQUAL(nRegSuccesses, 0); |
| 567 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 568 | face.processEvents(time::milliseconds(-1)); // io_service::reset()/poll() inside |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 569 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 570 | } |
| 571 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 572 | BOOST_AUTO_TEST_CASE(PutNack) |
| 573 | { |
| 574 | lp::Nack nack(Interest("/Hello/World", time::milliseconds(50))); |
| 575 | nack.setReason(lp::NackReason::NO_ROUTE); |
| 576 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 577 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 578 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 579 | face.put(nack); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 580 | |
| 581 | advanceClocks(time::milliseconds(10)); |
| 582 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 583 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 1); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 586 | BOOST_AUTO_TEST_CASE(DestructionWithoutCancellingPendingInterests) // Bug #2518 |
| 587 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame^] | 588 | { |
| 589 | DummyClientFace face2(io); |
| 590 | face2.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 591 | bind([]{}), bind([]{})); |
| 592 | advanceClocks(time::milliseconds(10), 10); |
| 593 | } |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 594 | |
| 595 | advanceClocks(time::milliseconds(10), 10); |
| 596 | // should not segfault |
| 597 | } |
| 598 | |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 599 | BOOST_AUTO_TEST_CASE(FaceTransport) |
| 600 | { |
| 601 | KeyChain keyChain; |
| 602 | |
| 603 | BOOST_CHECK(Face().getTransport() != nullptr); |
| 604 | |
| 605 | BOOST_CHECK(Face(shared_ptr<Transport>()).getTransport() == nullptr); |
| 606 | BOOST_CHECK(Face(shared_ptr<Transport>(), io).getTransport() == nullptr); |
| 607 | BOOST_CHECK(Face(shared_ptr<Transport>(), io, keyChain).getTransport() == nullptr); |
| 608 | |
| 609 | auto transport = make_shared<TcpTransport>("localhost", "6363"); // no real io operations will be scheduled |
| 610 | BOOST_CHECK(Face(transport).getTransport() == transport); |
| 611 | BOOST_CHECK(Face(transport, io).getTransport() == transport); |
| 612 | BOOST_CHECK(Face(transport, io, keyChain).getTransport() == transport); |
| 613 | } |
| 614 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 615 | BOOST_AUTO_TEST_SUITE_END() |
| 616 | |
| 617 | } // tests |
| 618 | } // namespace ndn |