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