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