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