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