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