Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 1ad0b4b | 2017-08-18 14:19:14 +0000 | [diff] [blame] | 2 | /* |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 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" |
Junxiao Shi | a1478db | 2016-09-09 04:13:15 +0000 | [diff] [blame] | 23 | #include "lp/tags.hpp" |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 24 | #include "transport/tcp-transport.hpp" |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 25 | #include "transport/unix-transport.hpp" |
Junxiao Shi | a1478db | 2016-09-09 04:13:15 +0000 | [diff] [blame] | 26 | #include "util/dummy-client-face.hpp" |
| 27 | #include "util/scheduler.hpp" |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 28 | |
| 29 | #include "boost-test.hpp" |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 30 | #include "identity-management-time-fixture.hpp" |
Alexander Afanasyev | fc99b51 | 2017-01-04 11:10:36 -0800 | [diff] [blame] | 31 | #include "test-home-fixture.hpp" |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 32 | #include "make-interest-data.hpp" |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 33 | |
| 34 | namespace ndn { |
| 35 | namespace tests { |
| 36 | |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 37 | using ndn::util::DummyClientFace; |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 38 | |
Alexander Afanasyev | 80782e0 | 2017-01-04 13:16:54 -0800 | [diff] [blame] | 39 | class FaceFixture : public IdentityManagementTimeFixture |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 40 | { |
| 41 | public: |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 42 | explicit |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 43 | FaceFixture(bool enableRegistrationReply = true) |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 44 | : face(io, m_keyChain, {true, enableRegistrationReply}) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 45 | { |
| 46 | } |
| 47 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 48 | public: |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 49 | DummyClientFace face; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 50 | }; |
| 51 | |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 52 | class FacesNoRegistrationReplyFixture : public FaceFixture |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 53 | { |
| 54 | public: |
| 55 | FacesNoRegistrationReplyFixture() |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 56 | : FaceFixture(false) |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 57 | { |
| 58 | } |
| 59 | }; |
| 60 | |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 61 | BOOST_FIXTURE_TEST_SUITE(TestFace, FaceFixture) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 62 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 63 | BOOST_AUTO_TEST_SUITE(Consumer) |
| 64 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 65 | BOOST_AUTO_TEST_CASE(ExpressInterestData) |
| 66 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 67 | size_t nData = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 68 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 69 | [&] (const Interest& i, const Data& d) { |
| 70 | BOOST_CHECK(i.getName().isPrefixOf(d.getName())); |
| 71 | BOOST_CHECK_EQUAL(i.getName(), "/Hello/World"); |
| 72 | ++nData; |
| 73 | }, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 74 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
| 75 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 76 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 77 | advanceClocks(time::milliseconds(40)); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 78 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 79 | face.receive(*makeData("/Bye/World/a")); |
| 80 | face.receive(*makeData("/Hello/World/a")); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 81 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 82 | advanceClocks(time::milliseconds(50), 2); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 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([]{}), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 92 | bind([&nTimeouts] { ++nTimeouts; })); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 93 | advanceClocks(time::milliseconds(200), 5); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 94 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
| 95 | } |
| 96 | |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 97 | BOOST_AUTO_TEST_CASE(ExpressMultipleInterestData) |
| 98 | { |
| 99 | size_t nData = 0; |
| 100 | |
| 101 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 102 | [&] (const Interest& i, const Data& d) { |
| 103 | ++nData; |
| 104 | }, |
| 105 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
| 106 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
| 107 | |
| 108 | face.expressInterest(Interest("/Hello/World/a", time::milliseconds(50)), |
| 109 | [&] (const Interest& i, const Data& d) { |
| 110 | ++nData; |
| 111 | }, |
| 112 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
| 113 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
| 114 | |
| 115 | advanceClocks(time::milliseconds(40)); |
| 116 | |
| 117 | face.receive(*makeData("/Hello/World/a/b")); |
| 118 | |
| 119 | advanceClocks(time::milliseconds(50), 2); |
| 120 | |
| 121 | BOOST_CHECK_EQUAL(nData, 2); |
| 122 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 2); |
| 123 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
| 124 | } |
| 125 | |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 126 | BOOST_AUTO_TEST_CASE(ExpressInterestEmptyDataCallback) |
| 127 | { |
| 128 | face.expressInterest(Interest("/Hello/World"), |
| 129 | nullptr, |
| 130 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
| 131 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
| 132 | advanceClocks(time::milliseconds(1)); |
| 133 | |
| 134 | BOOST_CHECK_NO_THROW(do { |
| 135 | face.receive(*makeData("/Hello/World/a")); |
| 136 | advanceClocks(time::milliseconds(1)); |
| 137 | } while (false)); |
| 138 | } |
| 139 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 140 | BOOST_AUTO_TEST_CASE(ExpressInterestTimeout) |
| 141 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 142 | size_t nTimeouts = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 143 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 144 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
| 145 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 146 | [&nTimeouts] (const Interest& i) { |
| 147 | BOOST_CHECK_EQUAL(i.getName(), "/Hello/World"); |
| 148 | ++nTimeouts; |
| 149 | }); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 150 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 151 | advanceClocks(time::milliseconds(200), 5); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 152 | |
| 153 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 154 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 155 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
| 156 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 159 | BOOST_AUTO_TEST_CASE(ExpressInterestEmptyTimeoutCallback) |
| 160 | { |
| 161 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 162 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
| 163 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
| 164 | nullptr); |
| 165 | advanceClocks(time::milliseconds(40)); |
| 166 | |
| 167 | BOOST_CHECK_NO_THROW(do { |
| 168 | advanceClocks(time::milliseconds(6), 2); |
| 169 | } while (false)); |
| 170 | } |
| 171 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 172 | BOOST_AUTO_TEST_CASE(ExpressInterestNack) |
| 173 | { |
| 174 | size_t nNacks = 0; |
| 175 | |
| 176 | Interest interest("/Hello/World", time::milliseconds(50)); |
| 177 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 178 | face.expressInterest(interest, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 179 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 180 | [&] (const Interest& i, const lp::Nack& n) { |
| 181 | BOOST_CHECK(i.getName().isPrefixOf(n.getInterest().getName())); |
| 182 | BOOST_CHECK_EQUAL(i.getName(), "/Hello/World"); |
| 183 | BOOST_CHECK_EQUAL(n.getReason(), lp::NackReason::DUPLICATE); |
| 184 | ++nNacks; |
| 185 | }, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 186 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 187 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 188 | advanceClocks(time::milliseconds(40)); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 189 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 190 | face.receive(makeNack(face.sentInterests.at(0), lp::NackReason::DUPLICATE)); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 191 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 192 | advanceClocks(time::milliseconds(50), 2); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 193 | |
| 194 | BOOST_CHECK_EQUAL(nNacks, 1); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 195 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 198 | BOOST_AUTO_TEST_CASE(ExpressMultipleInterestNack) |
| 199 | { |
| 200 | size_t nNacks = 0; |
| 201 | |
| 202 | Interest interest("/Hello/World", time::milliseconds(50)); |
| 203 | interest.setNonce(1); |
| 204 | |
| 205 | face.expressInterest(interest, |
| 206 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
| 207 | [&] (const Interest& i, const lp::Nack& n) { |
| 208 | ++nNacks; |
| 209 | }, |
| 210 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
| 211 | |
| 212 | interest.setNonce(2); |
| 213 | face.expressInterest(interest, |
| 214 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
| 215 | [&] (const Interest& i, const lp::Nack& n) { |
| 216 | ++nNacks; |
| 217 | }, |
| 218 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
| 219 | |
| 220 | advanceClocks(time::milliseconds(40)); |
| 221 | |
| 222 | face.receive(makeNack(face.sentInterests.at(1), lp::NackReason::DUPLICATE)); |
| 223 | |
| 224 | advanceClocks(time::milliseconds(50), 2); |
| 225 | |
| 226 | BOOST_CHECK_EQUAL(nNacks, 2); |
| 227 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 2); |
| 228 | } |
| 229 | |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 230 | BOOST_AUTO_TEST_CASE(ExpressInterestEmptyNackCallback) |
| 231 | { |
| 232 | face.expressInterest(Interest("/Hello/World"), |
| 233 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
| 234 | nullptr, |
| 235 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
| 236 | advanceClocks(time::milliseconds(1)); |
| 237 | |
| 238 | BOOST_CHECK_NO_THROW(do { |
| 239 | face.receive(makeNack(face.sentInterests.at(0), lp::NackReason::DUPLICATE)); |
| 240 | advanceClocks(time::milliseconds(1)); |
| 241 | } while (false)); |
| 242 | } |
| 243 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 244 | BOOST_AUTO_TEST_CASE(RemovePendingInterest) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 245 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 246 | const PendingInterestId* interestId = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 247 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 248 | bind([] { BOOST_FAIL("Unexpected data"); }), |
| 249 | bind([] { BOOST_FAIL("Unexpected nack"); }), |
| 250 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 251 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 252 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 253 | face.removePendingInterest(interestId); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 254 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 255 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 256 | face.receive(*makeData("/Hello/World/%21")); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 257 | advanceClocks(time::milliseconds(200), 5); |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 258 | |
| 259 | // avoid "test case [...] did not check any assertions" message from Boost.Test |
| 260 | BOOST_CHECK(true); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 261 | } |
| 262 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 263 | BOOST_AUTO_TEST_CASE(RemoveAllPendingInterests) |
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.expressInterest(Interest("/Hello/World/0", time::milliseconds(50)), |
| 266 | bind([] { BOOST_FAIL("Unexpected data"); }), |
| 267 | bind([] { BOOST_FAIL("Unexpected nack"); }), |
| 268 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 269 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 270 | face.expressInterest(Interest("/Hello/World/1", time::milliseconds(50)), |
| 271 | bind([] { BOOST_FAIL("Unexpected data"); }), |
| 272 | bind([] { BOOST_FAIL("Unexpected nack"); }), |
| 273 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 274 | |
| 275 | advanceClocks(time::milliseconds(10)); |
| 276 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 277 | face.removeAllPendingInterests(); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 278 | advanceClocks(time::milliseconds(10)); |
| 279 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 280 | BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 281 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 282 | face.receive(*makeData("/Hello/World/0")); |
| 283 | face.receive(*makeData("/Hello/World/1")); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 284 | advanceClocks(time::milliseconds(200), 5); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 285 | } |
| 286 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 287 | BOOST_AUTO_TEST_CASE(DestructionWithoutCancellingPendingInterests) // Bug #2518 |
| 288 | { |
| 289 | { |
| 290 | DummyClientFace face2(io, m_keyChain); |
| 291 | face2.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
Alexander Afanasyev | e6835fe | 2017-01-19 20:05:01 -0800 | [diff] [blame] | 292 | nullptr, nullptr, nullptr); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 293 | advanceClocks(time::milliseconds(50), 2); |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 296 | advanceClocks(time::milliseconds(50), 2); // should not crash |
| 297 | |
| 298 | // avoid "test case [...] did not check any assertions" message from Boost.Test |
| 299 | BOOST_CHECK(true); |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | BOOST_AUTO_TEST_SUITE_END() // Consumer |
| 303 | |
| 304 | BOOST_AUTO_TEST_SUITE(Producer) |
| 305 | |
Junxiao Shi | e7bb6c8 | 2016-08-08 23:16:35 +0000 | [diff] [blame] | 306 | BOOST_AUTO_TEST_CASE(PutData) |
| 307 | { |
| 308 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
| 309 | |
| 310 | Data data("/4g7xxcuEow/KFvK5Kf2m"); |
| 311 | signData(data); |
| 312 | face.put(data); |
| 313 | |
| 314 | lp::CachePolicy cachePolicy; |
| 315 | cachePolicy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 316 | data.setTag(make_shared<lp::CachePolicyTag>(cachePolicy)); |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 317 | data.setTag(make_shared<lp::CongestionMarkTag>(1)); |
Junxiao Shi | e7bb6c8 | 2016-08-08 23:16:35 +0000 | [diff] [blame] | 318 | face.put(data); |
| 319 | |
| 320 | advanceClocks(time::milliseconds(10)); |
| 321 | BOOST_REQUIRE_EQUAL(face.sentData.size(), 2); |
| 322 | BOOST_CHECK(face.sentData[0].getTag<lp::CachePolicyTag>() == nullptr); |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 323 | BOOST_CHECK(face.sentData[0].getTag<lp::CongestionMarkTag>() == nullptr); |
Junxiao Shi | e7bb6c8 | 2016-08-08 23:16:35 +0000 | [diff] [blame] | 324 | BOOST_CHECK(face.sentData[1].getTag<lp::CachePolicyTag>() != nullptr); |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 325 | BOOST_CHECK(face.sentData[1].getTag<lp::CongestionMarkTag>() != nullptr); |
Junxiao Shi | e7bb6c8 | 2016-08-08 23:16:35 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Junxiao Shi | b682891 | 2017-11-20 14:06:32 +0000 | [diff] [blame] | 328 | BOOST_AUTO_TEST_CASE(PutDataLoopback) |
| 329 | { |
| 330 | bool hasInterest1 = false, hasData = false; |
| 331 | |
| 332 | // first InterestFilter allows loopback and should receive Interest |
| 333 | face.setInterestFilter("/", [&] (const InterestFilter&, const Interest& interest) { |
| 334 | hasInterest1 = true; |
| 335 | // do not respond with Data right away, so Face must send Interest to forwarder |
| 336 | }); |
| 337 | // second InterestFilter disallows loopback and should not receive Interest |
| 338 | face.setInterestFilter(InterestFilter("/").allowLoopback(false), |
| 339 | bind([] { BOOST_ERROR("Unexpected Interest on second InterestFilter"); })); |
| 340 | |
| 341 | face.expressInterest(Interest("/A"), |
| 342 | bind([&] { hasData = true; }), |
| 343 | bind([] { BOOST_FAIL("Unexpected nack"); }), |
| 344 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
| 345 | advanceClocks(time::milliseconds(1)); |
| 346 | BOOST_CHECK_EQUAL(hasInterest1, true); // Interest looped back |
| 347 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); // Interest sent to forwarder |
| 348 | BOOST_CHECK_EQUAL(hasData, false); // waiting for Data |
| 349 | |
| 350 | face.put(*makeData("/A/B")); // first InterestFilter responds with Data |
| 351 | advanceClocks(time::milliseconds(1)); |
| 352 | BOOST_CHECK_EQUAL(hasData, true); |
| 353 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); // do not spill Data to forwarder |
| 354 | } |
| 355 | |
Junxiao Shi | 859888f | 2017-09-12 14:29:16 +0000 | [diff] [blame] | 356 | BOOST_AUTO_TEST_CASE(PutMultipleData) |
| 357 | { |
| 358 | bool hasInterest1 = false; |
| 359 | // register two Interest destinations |
| 360 | face.setInterestFilter("/", bind([&] { |
| 361 | hasInterest1 = true; |
| 362 | // sending Data right away from the first destination, don't care whether Interest goes to second destination |
| 363 | face.put(*makeData("/A/B")); |
| 364 | })); |
| 365 | face.setInterestFilter("/", bind([]{})); |
| 366 | advanceClocks(time::milliseconds(10)); |
| 367 | |
| 368 | face.receive(*makeInterest("/A")); |
| 369 | advanceClocks(time::milliseconds(10)); |
| 370 | BOOST_CHECK(hasInterest1); |
| 371 | BOOST_CHECK_EQUAL(face.sentData.size(), 1); |
| 372 | BOOST_CHECK_EQUAL(face.sentData.at(0).getName(), "/A/B"); |
| 373 | |
| 374 | face.put(*makeData("/A/C")); |
| 375 | BOOST_CHECK_EQUAL(face.sentData.size(), 1); // additional Data are ignored |
| 376 | } |
| 377 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 378 | BOOST_AUTO_TEST_CASE(PutNack) |
| 379 | { |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame] | 380 | face.setInterestFilter("/", bind([]{})); // register one Interest destination so that face can accept Nacks |
| 381 | advanceClocks(time::milliseconds(10)); |
| 382 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 383 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); |
| 384 | |
Junxiao Shi | 1ad0b4b | 2017-08-18 14:19:14 +0000 | [diff] [blame] | 385 | face.put(makeNack("/unsolicited", 18645250, lp::NackReason::NO_ROUTE)); |
Junxiao Shi | e7bb6c8 | 2016-08-08 23:16:35 +0000 | [diff] [blame] | 386 | advanceClocks(time::milliseconds(10)); |
Junxiao Shi | 1ad0b4b | 2017-08-18 14:19:14 +0000 | [diff] [blame] | 387 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); // unsolicited Nack would not be sent |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 388 | |
Junxiao Shi | 1ad0b4b | 2017-08-18 14:19:14 +0000 | [diff] [blame] | 389 | face.receive(*makeInterest("/Hello/World", 14247162)); |
| 390 | face.receive(*makeInterest("/another/prefix", 92203002)); |
| 391 | advanceClocks(time::milliseconds(10)); |
| 392 | |
| 393 | face.put(makeNack("/Hello/World", 14247162, lp::NackReason::DUPLICATE)); |
| 394 | advanceClocks(time::milliseconds(10)); |
| 395 | BOOST_REQUIRE_EQUAL(face.sentNacks.size(), 1); |
| 396 | BOOST_CHECK_EQUAL(face.sentNacks[0].getReason(), lp::NackReason::DUPLICATE); |
| 397 | BOOST_CHECK(face.sentNacks[0].getTag<lp::CongestionMarkTag>() == nullptr); |
| 398 | |
| 399 | auto nack = makeNack("/another/prefix", 92203002, lp::NackReason::NO_ROUTE); |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 400 | nack.setTag(make_shared<lp::CongestionMarkTag>(1)); |
| 401 | face.put(nack); |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 402 | advanceClocks(time::milliseconds(10)); |
| 403 | BOOST_REQUIRE_EQUAL(face.sentNacks.size(), 2); |
Junxiao Shi | 1ad0b4b | 2017-08-18 14:19:14 +0000 | [diff] [blame] | 404 | BOOST_CHECK_EQUAL(face.sentNacks[1].getReason(), lp::NackReason::NO_ROUTE); |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 405 | BOOST_CHECK(face.sentNacks[1].getTag<lp::CongestionMarkTag>() != nullptr); |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 406 | } |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 407 | |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame] | 408 | BOOST_AUTO_TEST_CASE(PutMultipleNack) |
| 409 | { |
Junxiao Shi | 859888f | 2017-09-12 14:29:16 +0000 | [diff] [blame] | 410 | bool hasInterest1 = false, hasInterest2 = false; |
| 411 | // register two Interest destinations |
| 412 | face.setInterestFilter("/", [&] (const InterestFilter&, const Interest& interest) { |
| 413 | hasInterest1 = true; |
| 414 | // sending Nack right away from the first destination, Interest should still go to second destination |
| 415 | face.put(makeNack(interest, lp::NackReason::CONGESTION)); |
| 416 | }); |
| 417 | face.setInterestFilter("/", bind([&] { hasInterest2 = true; })); |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame] | 418 | advanceClocks(time::milliseconds(10)); |
| 419 | |
| 420 | face.receive(*makeInterest("/A", 14333271)); |
| 421 | advanceClocks(time::milliseconds(10)); |
Junxiao Shi | 859888f | 2017-09-12 14:29:16 +0000 | [diff] [blame] | 422 | BOOST_CHECK(hasInterest1); |
| 423 | BOOST_CHECK(hasInterest2); |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame] | 424 | |
Junxiao Shi | 859888f | 2017-09-12 14:29:16 +0000 | [diff] [blame] | 425 | // Nack from first destination is received, should wait for a response from the other destination |
| 426 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame] | 427 | |
| 428 | face.put(makeNack("/A", 14333271, lp::NackReason::NO_ROUTE)); // Nack from second destination |
| 429 | advanceClocks(time::milliseconds(10)); |
Junxiao Shi | 859888f | 2017-09-12 14:29:16 +0000 | [diff] [blame] | 430 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 1); // sending Nack after both destinations Nacked |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame] | 431 | BOOST_CHECK_EQUAL(face.sentNacks.at(0).getReason(), lp::NackReason::CONGESTION); // least severe reason |
| 432 | |
| 433 | face.put(makeNack("/A", 14333271, lp::NackReason::DUPLICATE)); |
| 434 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 1); // additional Nacks are ignored |
| 435 | } |
| 436 | |
Junxiao Shi | b682891 | 2017-11-20 14:06:32 +0000 | [diff] [blame] | 437 | BOOST_AUTO_TEST_CASE(PutMultipleNackLoopback) |
| 438 | { |
| 439 | bool hasInterest1 = false, hasNack = false; |
| 440 | |
| 441 | // first InterestFilter allows loopback and should receive Interest |
| 442 | face.setInterestFilter("/", [&] (const InterestFilter&, const Interest& interest) { |
| 443 | hasInterest1 = true; |
| 444 | face.put(makeNack(interest, lp::NackReason::CONGESTION)); |
| 445 | }); |
| 446 | // second InterestFilter disallows loopback and should not receive Interest |
| 447 | face.setInterestFilter(InterestFilter("/").allowLoopback(false), |
| 448 | bind([] { BOOST_ERROR("Unexpected Interest on second InterestFilter"); })); |
| 449 | |
| 450 | face.expressInterest(*makeInterest("/A", 28395852), |
| 451 | bind([] { BOOST_FAIL("Unexpected data"); }), |
| 452 | [&] (const Interest&, const lp::Nack& nack) { |
| 453 | hasNack = true; |
| 454 | BOOST_CHECK_EQUAL(nack.getReason(), lp::NackReason::CONGESTION); |
| 455 | }, |
| 456 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
| 457 | advanceClocks(time::milliseconds(1)); |
| 458 | BOOST_CHECK_EQUAL(hasInterest1, true); // Interest looped back |
| 459 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); // Interest sent to forwarder |
| 460 | BOOST_CHECK_EQUAL(hasNack, false); // waiting for Nack from forwarder |
| 461 | |
| 462 | face.receive(makeNack("/A", 28395852, lp::NackReason::NO_ROUTE)); |
| 463 | advanceClocks(time::milliseconds(1)); |
| 464 | BOOST_CHECK_EQUAL(hasNack, true); |
| 465 | } |
| 466 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 467 | BOOST_AUTO_TEST_CASE(SetUnsetInterestFilter) |
| 468 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 469 | size_t nInterests = 0; |
| 470 | size_t nRegs = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 471 | const RegisteredPrefixId* regPrefixId = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 472 | face.setInterestFilter("/Hello/World", |
| 473 | bind([&nInterests] { ++nInterests; }), |
| 474 | bind([&nRegs] { ++nRegs; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 475 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 476 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 477 | BOOST_CHECK_EQUAL(nRegs, 1); |
| 478 | BOOST_CHECK_EQUAL(nInterests, 0); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 479 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 480 | face.receive(Interest("/Hello/World/%21")); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 481 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 482 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 483 | BOOST_CHECK_EQUAL(nRegs, 1); |
| 484 | BOOST_CHECK_EQUAL(nInterests, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 485 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 486 | face.receive(Interest("/Bye/World/%21")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 487 | advanceClocks(time::milliseconds(10000), 10); |
| 488 | BOOST_CHECK_EQUAL(nInterests, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 489 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 490 | face.receive(Interest("/Hello/World/%21/2")); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 491 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 492 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 493 | |
| 494 | // removing filter |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 495 | face.unsetInterestFilter(regPrefixId); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 496 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 497 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 498 | face.receive(Interest("/Hello/World/%21/3")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 499 | BOOST_CHECK_EQUAL(nInterests, 2); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 500 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 501 | face.unsetInterestFilter(static_cast<const RegisteredPrefixId*>(nullptr)); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 502 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 503 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 504 | face.unsetInterestFilter(static_cast<const InterestFilterId*>(nullptr)); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 505 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 506 | } |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 507 | |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 508 | BOOST_AUTO_TEST_CASE(SetInterestFilterEmptyInterestCallback) |
| 509 | { |
| 510 | face.setInterestFilter("/A", nullptr); |
| 511 | advanceClocks(time::milliseconds(1)); |
| 512 | |
| 513 | BOOST_CHECK_NO_THROW(do { |
| 514 | face.receive(*makeInterest("/A/1")); |
| 515 | advanceClocks(time::milliseconds(1)); |
| 516 | } while (false)); |
| 517 | } |
| 518 | |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 519 | BOOST_AUTO_TEST_CASE(SetUnsetInterestFilterWithoutSucessCallback) |
| 520 | { |
| 521 | size_t nInterests = 0; |
| 522 | const RegisteredPrefixId* regPrefixId = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 523 | face.setInterestFilter("/Hello/World", |
| 524 | bind([&nInterests] { ++nInterests; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 525 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 526 | advanceClocks(time::milliseconds(25), 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 527 | BOOST_CHECK_EQUAL(nInterests, 0); |
| 528 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 529 | face.receive(Interest("/Hello/World/%21")); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 530 | advanceClocks(time::milliseconds(25), 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 531 | |
| 532 | BOOST_CHECK_EQUAL(nInterests, 1); |
| 533 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 534 | face.receive(Interest("/Bye/World/%21")); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 535 | advanceClocks(time::milliseconds(10000), 10); |
| 536 | BOOST_CHECK_EQUAL(nInterests, 1); |
| 537 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 538 | face.receive(Interest("/Hello/World/%21/2")); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 539 | advanceClocks(time::milliseconds(25), 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 540 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 541 | |
| 542 | // removing filter |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 543 | face.unsetInterestFilter(regPrefixId); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 544 | advanceClocks(time::milliseconds(25), 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 545 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 546 | face.receive(Interest("/Hello/World/%21/3")); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 547 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 548 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 549 | face.unsetInterestFilter(static_cast<const RegisteredPrefixId*>(nullptr)); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 550 | advanceClocks(time::milliseconds(25), 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 551 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 552 | face.unsetInterestFilter(static_cast<const InterestFilterId*>(nullptr)); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 553 | advanceClocks(time::milliseconds(25), 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 554 | } |
| 555 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 556 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterFail, FacesNoRegistrationReplyFixture) |
| 557 | { |
| 558 | // don't enable registration reply |
| 559 | size_t nRegFailed = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 560 | face.setInterestFilter("/Hello/World", |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 561 | bind([] { BOOST_FAIL("Unexpected Interest"); }), |
| 562 | bind([] { BOOST_FAIL("Unexpected success of setInterestFilter"); }), |
| 563 | bind([&nRegFailed] { ++nRegFailed; })); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 564 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 565 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 566 | BOOST_CHECK_EQUAL(nRegFailed, 0); |
| 567 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 568 | advanceClocks(time::milliseconds(2000), 5); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 569 | BOOST_CHECK_EQUAL(nRegFailed, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 570 | } |
| 571 | |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 572 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterFailWithoutSuccessCallback, FacesNoRegistrationReplyFixture) |
| 573 | { |
| 574 | // don't enable registration reply |
| 575 | size_t nRegFailed = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 576 | face.setInterestFilter("/Hello/World", |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 577 | bind([] { BOOST_FAIL("Unexpected Interest"); }), |
| 578 | bind([&nRegFailed] { ++nRegFailed; })); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 579 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 580 | advanceClocks(time::milliseconds(25), 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 581 | BOOST_CHECK_EQUAL(nRegFailed, 0); |
| 582 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 583 | advanceClocks(time::milliseconds(2000), 5); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 584 | BOOST_CHECK_EQUAL(nRegFailed, 1); |
| 585 | } |
| 586 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 587 | BOOST_AUTO_TEST_CASE(RegisterUnregisterPrefix) |
| 588 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 589 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 590 | const RegisteredPrefixId* regPrefixId = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 591 | face.registerPrefix("/Hello/World", |
| 592 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 593 | bind([] { BOOST_FAIL("Unexpected registerPrefix failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 594 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 595 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 596 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 597 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 598 | size_t nUnregSuccesses = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 599 | face.unregisterPrefix(regPrefixId, |
| 600 | bind([&nUnregSuccesses] { ++nUnregSuccesses; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 601 | bind([] { BOOST_FAIL("Unexpected unregisterPrefix failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 602 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 603 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 604 | BOOST_CHECK_EQUAL(nUnregSuccesses, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 605 | } |
| 606 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 607 | BOOST_FIXTURE_TEST_CASE(RegisterUnregisterPrefixFail, FacesNoRegistrationReplyFixture) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 608 | { |
Junxiao Shi | b682891 | 2017-11-20 14:06:32 +0000 | [diff] [blame] | 609 | // don't enable registration reply |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 610 | size_t nRegFailures = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 611 | face.registerPrefix("/Hello/World", |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 612 | bind([] { BOOST_FAIL("Unexpected registerPrefix success"); }), |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 613 | bind([&nRegFailures] { ++nRegFailures; })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 614 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 615 | advanceClocks(time::milliseconds(5000), 20); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 616 | BOOST_CHECK_EQUAL(nRegFailures, 1); |
| 617 | } |
| 618 | |
| 619 | BOOST_AUTO_TEST_CASE(SimilarFilters) |
| 620 | { |
| 621 | size_t nInInterests1 = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 622 | face.setInterestFilter("/Hello/World", |
| 623 | bind([&nInInterests1] { ++nInInterests1; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 624 | nullptr, |
| 625 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 626 | |
| 627 | size_t nInInterests2 = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 628 | face.setInterestFilter("/Hello", |
| 629 | bind([&nInInterests2] { ++nInInterests2; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 630 | nullptr, |
| 631 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 632 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 633 | size_t nInInterests3 = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 634 | face.setInterestFilter("/Los/Angeles/Lakers", |
| 635 | bind([&nInInterests3] { ++nInInterests3; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 636 | nullptr, |
| 637 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 638 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 639 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 640 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 641 | face.receive(Interest("/Hello/World/%21")); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 642 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 643 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 644 | BOOST_CHECK_EQUAL(nInInterests1, 1); |
| 645 | BOOST_CHECK_EQUAL(nInInterests2, 1); |
| 646 | BOOST_CHECK_EQUAL(nInInterests3, 0); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | BOOST_AUTO_TEST_CASE(SetRegexFilterError) |
| 650 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 651 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 652 | [] (const Name&, const Interest&) { |
| 653 | BOOST_FAIL("InterestFilter::Error should have been triggered"); |
| 654 | }, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 655 | nullptr, |
| 656 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 657 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 658 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 659 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 660 | 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] | 661 | } |
| 662 | |
| 663 | BOOST_AUTO_TEST_CASE(SetRegexFilter) |
| 664 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 665 | size_t nInInterests = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 666 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 667 | bind([&nInInterests] { ++nInInterests; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 668 | nullptr, |
| 669 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 670 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 671 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 672 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 673 | face.receive(Interest("/Hello/World/a")); // shouldn't match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 674 | BOOST_CHECK_EQUAL(nInInterests, 0); |
| 675 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 676 | face.receive(Interest("/Hello/World/a/b")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 677 | BOOST_CHECK_EQUAL(nInInterests, 1); |
| 678 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 679 | face.receive(Interest("/Hello/World/a/b/c")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 680 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 681 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 682 | face.receive(Interest("/Hello/World/a/b/d")); // should not match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 683 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 684 | } |
| 685 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 686 | BOOST_AUTO_TEST_CASE(SetRegexFilterAndRegister) |
| 687 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 688 | size_t nInInterests = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 689 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 690 | bind([&nInInterests] { ++nInInterests; })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 691 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 692 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 693 | face.registerPrefix("/Hello/World", |
| 694 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 695 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 696 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 697 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 698 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 699 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 700 | face.receive(Interest("/Hello/World/a")); // shouldn't match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 701 | BOOST_CHECK_EQUAL(nInInterests, 0); |
| 702 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 703 | face.receive(Interest("/Hello/World/a/b")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 704 | BOOST_CHECK_EQUAL(nInInterests, 1); |
| 705 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 706 | face.receive(Interest("/Hello/World/a/b/c")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 707 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 708 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 709 | face.receive(Interest("/Hello/World/a/b/d")); // should not match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 710 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 711 | } |
| 712 | |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 713 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterNoReg, FacesNoRegistrationReplyFixture) // Bug 2318 |
| 714 | { |
| 715 | // This behavior is specific to DummyClientFace. |
| 716 | // Regular Face won't accept incoming packets until something is sent. |
| 717 | |
| 718 | int hit = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 719 | face.setInterestFilter(Name("/"), bind([&hit] { ++hit; })); |
| 720 | face.processEvents(time::milliseconds(-1)); |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 721 | |
| 722 | auto interest = make_shared<Interest>("/A"); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 723 | face.receive(*interest); |
| 724 | face.processEvents(time::milliseconds(-1)); |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 725 | |
| 726 | BOOST_CHECK_EQUAL(hit, 1); |
| 727 | } |
| 728 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 729 | BOOST_AUTO_TEST_SUITE_END() // Producer |
| 730 | |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 731 | BOOST_AUTO_TEST_SUITE(IoRoutines) |
| 732 | |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 733 | BOOST_AUTO_TEST_CASE(ProcessEvents) |
| 734 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 735 | face.processEvents(time::milliseconds(-1)); // io_service::reset()/poll() inside |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 736 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 737 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 738 | face.registerPrefix("/Hello/World", |
| 739 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 740 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 741 | |
| 742 | // io_service::poll() without reset |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 743 | face.getIoService().poll(); |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 744 | BOOST_CHECK_EQUAL(nRegSuccesses, 0); |
| 745 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 746 | face.processEvents(time::milliseconds(-1)); // io_service::reset()/poll() inside |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 747 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 748 | } |
| 749 | |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 750 | BOOST_AUTO_TEST_CASE(DestroyWithoutProcessEvents) // Bug 3248 |
| 751 | { |
| 752 | auto face2 = make_unique<Face>(io); |
| 753 | face2.reset(); |
| 754 | |
| 755 | io.poll(); // should not crash |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 756 | |
| 757 | // avoid "test case [...] did not check any assertions" message from Boost.Test |
| 758 | BOOST_CHECK(true); |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | BOOST_AUTO_TEST_SUITE_END() // IoRoutines |
| 762 | |
| 763 | BOOST_AUTO_TEST_SUITE(Transport) |
| 764 | |
| 765 | using ndn::Transport; |
| 766 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 767 | struct PibDirWithDefaultTpm |
| 768 | { |
| 769 | const std::string PATH = "build/keys-with-default-tpm"; |
| 770 | }; |
| 771 | |
Alexander Afanasyev | 80782e0 | 2017-01-04 13:16:54 -0800 | [diff] [blame] | 772 | BOOST_FIXTURE_TEST_CASE(FaceTransport, IdentityManagementTimeFixture) |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 773 | { |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 774 | BOOST_CHECK(Face().getTransport() != nullptr); |
| 775 | |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 776 | BOOST_CHECK(Face(shared_ptr<Transport>()).getTransport() != nullptr); |
| 777 | BOOST_CHECK(Face(shared_ptr<Transport>(), io).getTransport() != nullptr); |
Alexander Afanasyev | 80782e0 | 2017-01-04 13:16:54 -0800 | [diff] [blame] | 778 | BOOST_CHECK(Face(shared_ptr<Transport>(), io, m_keyChain).getTransport() != nullptr); |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 779 | |
| 780 | auto transport = make_shared<TcpTransport>("localhost", "6363"); // no real io operations will be scheduled |
| 781 | BOOST_CHECK(Face(transport).getTransport() == transport); |
| 782 | BOOST_CHECK(Face(transport, io).getTransport() == transport); |
Alexander Afanasyev | 80782e0 | 2017-01-04 13:16:54 -0800 | [diff] [blame] | 783 | BOOST_CHECK(Face(transport, io, m_keyChain).getTransport() == transport); |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 784 | } |
| 785 | |
Alexander Afanasyev | cf49055 | 2016-06-27 22:51:36 -0700 | [diff] [blame] | 786 | class WithEnv : private IdentityManagementTimeFixture |
| 787 | { |
| 788 | public: |
| 789 | WithEnv() |
| 790 | { |
| 791 | if (getenv("NDN_CLIENT_TRANSPORT") != nullptr) { |
| 792 | m_oldTransport = getenv("NDN_CLIENT_TRANSPORT"); |
| 793 | unsetenv("NDN_CLIENT_TRANSPORT"); |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | void |
| 798 | configure(const std::string& faceUri) |
| 799 | { |
| 800 | setenv("NDN_CLIENT_TRANSPORT", faceUri.c_str(), true); |
| 801 | } |
| 802 | |
| 803 | ~WithEnv() |
| 804 | { |
| 805 | if (!m_oldTransport.empty()) { |
| 806 | setenv("NDN_CLIENT_TRANSPORT", m_oldTransport.c_str(), true); |
| 807 | } |
| 808 | else { |
| 809 | unsetenv("NDN_CLIENT_TRANSPORT"); |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | private: |
| 814 | std::string m_oldTransport; |
| 815 | }; |
| 816 | |
| 817 | class WithConfig : private TestHomeFixture<DefaultPibDir> |
| 818 | { |
| 819 | public: |
| 820 | void |
| 821 | configure(const std::string& faceUri) |
| 822 | { |
| 823 | createClientConf({"transport=" + faceUri}); |
| 824 | } |
| 825 | }; |
| 826 | |
| 827 | class WithEnvAndConfig : public WithEnv, public WithConfig |
| 828 | { |
| 829 | }; |
| 830 | |
| 831 | typedef boost::mpl::vector<WithEnv, WithConfig> ConfigOptions; |
| 832 | |
| 833 | BOOST_FIXTURE_TEST_CASE(NoConfig, WithEnvAndConfig) // fixture configures test HOME and PIB/TPM path |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 834 | { |
| 835 | shared_ptr<Face> face; |
| 836 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>()); |
| 837 | BOOST_CHECK(dynamic_pointer_cast<UnixTransport>(face->getTransport()) != nullptr); |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Alexander Afanasyev | cf49055 | 2016-06-27 22:51:36 -0700 | [diff] [blame] | 840 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(Unix, T, ConfigOptions, T) |
| 841 | { |
| 842 | this->configure("unix://some/path"); |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 843 | |
Alexander Afanasyev | cf49055 | 2016-06-27 22:51:36 -0700 | [diff] [blame] | 844 | shared_ptr<Face> face; |
| 845 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>()); |
| 846 | BOOST_CHECK(dynamic_pointer_cast<UnixTransport>(face->getTransport()) != nullptr); |
| 847 | } |
| 848 | |
| 849 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(Tcp, T, ConfigOptions, T) |
| 850 | { |
| 851 | this->configure("tcp://127.0.0.1:6000"); |
| 852 | |
| 853 | shared_ptr<Face> face; |
| 854 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>()); |
| 855 | BOOST_CHECK(dynamic_pointer_cast<TcpTransport>(face->getTransport()) != nullptr); |
| 856 | } |
| 857 | |
| 858 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(WrongTransport, T, ConfigOptions, T) |
| 859 | { |
| 860 | this->configure("wrong-transport:"); |
| 861 | |
| 862 | BOOST_CHECK_THROW(make_shared<Face>(), ConfigFile::Error); |
| 863 | } |
| 864 | |
| 865 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(WrongUri, T, ConfigOptions, T) |
| 866 | { |
| 867 | this->configure("wrong-uri"); |
| 868 | |
| 869 | BOOST_CHECK_THROW(make_shared<Face>(), ConfigFile::Error); |
| 870 | } |
| 871 | |
| 872 | BOOST_FIXTURE_TEST_CASE(EnvOverride, WithEnvAndConfig) |
| 873 | { |
| 874 | this->WithEnv::configure("tcp://127.0.0.1:6000"); |
| 875 | this->WithConfig::configure("unix://some/path"); |
| 876 | |
| 877 | shared_ptr<Face> face; |
| 878 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>()); |
| 879 | BOOST_CHECK(dynamic_pointer_cast<TcpTransport>(face->getTransport()) != nullptr); |
| 880 | } |
| 881 | |
| 882 | BOOST_FIXTURE_TEST_CASE(ExplicitTransport, WithEnvAndConfig) |
| 883 | { |
| 884 | this->WithEnv::configure("wrong-uri"); |
| 885 | this->WithConfig::configure("wrong-transport:"); |
| 886 | |
| 887 | auto transport = make_shared<UnixTransport>("unix://some/path"); |
| 888 | shared_ptr<Face> face; |
| 889 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>(transport)); |
| 890 | BOOST_CHECK(dynamic_pointer_cast<UnixTransport>(face->getTransport()) != nullptr); |
| 891 | } |
| 892 | |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 893 | BOOST_AUTO_TEST_SUITE_END() // Transport |
| 894 | |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 895 | BOOST_AUTO_TEST_SUITE_END() // TestFace |
| 896 | |
| 897 | } // namespace tests |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 898 | } // namespace ndn |