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