blob: 7324b1c3f4ef29b69d06ef356e65f695c6727f73 [file] [log] [blame]
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi1ad0b4b2017-08-18 14:19:14 +00002/*
Davide Pesavento0c526032024-01-31 21:14:01 -05003 * Copyright (c) 2013-2024 Regents of the University of California.
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -04004 *
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 Pesavento7e780642018-11-24 15:51:34 -050022#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 Pesaventof135f152022-01-06 20:43:06 -050026#include "ndn-cxx/util/config-file.hpp"
Davide Pesavento7e780642018-11-24 15:51:34 -050027#include "ndn-cxx/util/dummy-client-face.hpp"
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040028
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050029#include "tests/test-common.hpp"
30#include "tests/unit/io-key-chain-fixture.hpp"
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040031
Junxiao Shiec475a72019-01-13 21:53:55 +000032#include <boost/logic/tribool.hpp>
Davide Pesavento49e1e872023-11-11 00:45:23 -050033#include <boost/mp11/list.hpp>
Junxiao Shiec475a72019-01-13 21:53:55 +000034
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040035namespace ndn::tests {
Junxiao Shia60d9362014-11-12 09:38:21 -070036
Junxiao Shiec475a72019-01-13 21:53:55 +000037struct WantPrefixRegReply;
38struct NoPrefixRegReply;
39
40template<typename PrefixRegReply = WantPrefixRegReply>
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050041class FaceFixture : public IoKeyChainFixture
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040042{
Davide Pesaventod247d492020-01-28 21:30:20 -050043protected:
Junxiao Shiec475a72019-01-13 21:53:55 +000044 FaceFixture()
Davide Pesavento187e9f92023-03-20 22:46:22 -040045 : face(m_io, m_keyChain, {true, !std::is_same_v<PrefixRegReply, NoPrefixRegReply>})
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040046 {
Davide Pesavento187e9f92023-03-20 22:46:22 -040047 static_assert(std::is_same_v<PrefixRegReply, WantPrefixRegReply> ||
Davide Pesaventofffdd622023-08-28 22:50:43 -040048 std::is_same_v<PrefixRegReply, NoPrefixRegReply>);
Junxiao Shiec475a72019-01-13 21:53:55 +000049 }
50
51 /** \brief Execute a prefix registration, and optionally check the name in callback.
52 * \return whether the prefix registration succeeded.
53 */
54 bool
Davide Pesaventoeb87c282023-03-15 21:07:02 -040055 runPrefixReg(std::function<void(const RegisterPrefixSuccessCallback&,
56 const RegisterPrefixFailureCallback&)> f)
Junxiao Shiec475a72019-01-13 21:53:55 +000057 {
58 boost::logic::tribool result = boost::logic::indeterminate;
Davide Pesaventod247d492020-01-28 21:30:20 -050059 f([&] (auto) { result = true; },
60 [&] (auto, auto) { result = false; });
Junxiao Shiec475a72019-01-13 21:53:55 +000061
62 advanceClocks(1_ms);
63 BOOST_REQUIRE(!boost::logic::indeterminate(result));
64 return static_cast<bool>(result);
65 }
66
67 /** \brief Execute a prefix unregistration, and optionally check the name in callback.
68 * \return whether the prefix unregistration succeeded.
69 */
70 bool
Davide Pesaventoeb87c282023-03-15 21:07:02 -040071 runPrefixUnreg(std::function<void(const UnregisterPrefixSuccessCallback&,
72 const UnregisterPrefixFailureCallback&)> f)
Junxiao Shiec475a72019-01-13 21:53:55 +000073 {
74 boost::logic::tribool result = boost::logic::indeterminate;
Davide Pesaventod247d492020-01-28 21:30:20 -050075 f([&] { result = true; },
76 [&] (auto) { result = false; });
Junxiao Shiec475a72019-01-13 21:53:55 +000077
78 advanceClocks(1_ms);
79 BOOST_REQUIRE(!boost::logic::indeterminate(result));
80 return static_cast<bool>(result);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040081 }
82
Davide Pesaventod247d492020-01-28 21:30:20 -050083protected:
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080084 DummyClientFace face;
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040085};
86
Junxiao Shiec475a72019-01-13 21:53:55 +000087BOOST_FIXTURE_TEST_SUITE(TestFace, FaceFixture<>)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040088
Davide Pesaventod247d492020-01-28 21:30:20 -050089BOOST_AUTO_TEST_SUITE(ExpressInterest)
Junxiao Shi103d8ed2016-08-07 20:34:10 +000090
Davide Pesaventod247d492020-01-28 21:30:20 -050091BOOST_AUTO_TEST_CASE(ReplyData)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040092{
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -080093 size_t nData = 0;
Junxiao Shib55e5d32018-07-18 13:32:00 -060094 face.expressInterest(*makeInterest("/Hello/World", true, 50_ms),
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080095 [&] (const Interest& i, const Data& d) {
96 BOOST_CHECK(i.getName().isPrefixOf(d.getName()));
97 BOOST_CHECK_EQUAL(i.getName(), "/Hello/World");
98 ++nData;
99 },
Davide Pesavento2f46d652023-11-09 23:40:01 -0500100 [] (auto&&...) { BOOST_FAIL("Unexpected Nack"); },
101 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Eric Newberry83872fd2015-08-06 17:01:24 -0700102
Davide Pesavento0f830802018-01-16 23:58:58 -0500103 advanceClocks(40_ms);
Eric Newberry83872fd2015-08-06 17:01:24 -0700104
Junxiao Shi85d90832016-08-04 03:19:46 +0000105 face.receive(*makeData("/Bye/World/a"));
106 face.receive(*makeData("/Hello/World/a"));
Eric Newberry83872fd2015-08-06 17:01:24 -0700107
Davide Pesavento0f830802018-01-16 23:58:58 -0500108 advanceClocks(50_ms, 2);
Eric Newberry83872fd2015-08-06 17:01:24 -0700109
110 BOOST_CHECK_EQUAL(nData, 1);
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800111 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
112 BOOST_CHECK_EQUAL(face.sentData.size(), 0);
Eric Newberry83872fd2015-08-06 17:01:24 -0700113
114 size_t nTimeouts = 0;
Junxiao Shib55e5d32018-07-18 13:32:00 -0600115 face.expressInterest(*makeInterest("/Hello/World/a/2", false, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500116 [] (auto&&...) {},
117 [] (auto&&...) {},
118 [&] (auto&&...) { ++nTimeouts; });
Davide Pesavento0f830802018-01-16 23:58:58 -0500119 advanceClocks(200_ms, 5);
Eric Newberry83872fd2015-08-06 17:01:24 -0700120 BOOST_CHECK_EQUAL(nTimeouts, 1);
121}
122
Davide Pesaventod247d492020-01-28 21:30:20 -0500123BOOST_AUTO_TEST_CASE(MultipleData)
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800124{
125 size_t nData = 0;
126
Junxiao Shib55e5d32018-07-18 13:32:00 -0600127 face.expressInterest(*makeInterest("/Hello/World", true, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500128 [&] (auto&&...) { ++nData; },
129 [] (auto&&...) { BOOST_FAIL("Unexpected Nack"); },
130 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800131
Junxiao Shib55e5d32018-07-18 13:32:00 -0600132 face.expressInterest(*makeInterest("/Hello/World/a", true, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500133 [&] (auto&&...) { ++nData; },
134 [] (auto&&...) { BOOST_FAIL("Unexpected Nack"); },
135 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800136
Davide Pesavento0f830802018-01-16 23:58:58 -0500137 advanceClocks(40_ms);
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800138
139 face.receive(*makeData("/Hello/World/a/b"));
140
Davide Pesavento0f830802018-01-16 23:58:58 -0500141 advanceClocks(50_ms, 2);
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800142
143 BOOST_CHECK_EQUAL(nData, 2);
144 BOOST_CHECK_EQUAL(face.sentInterests.size(), 2);
145 BOOST_CHECK_EQUAL(face.sentData.size(), 0);
146}
147
Davide Pesaventod247d492020-01-28 21:30:20 -0500148BOOST_AUTO_TEST_CASE(EmptyDataCallback)
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000149{
Junxiao Shib55e5d32018-07-18 13:32:00 -0600150 face.expressInterest(*makeInterest("/Hello/World", true),
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000151 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500152 [] (auto&&...) { BOOST_FAIL("Unexpected Nack"); },
153 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500154 advanceClocks(1_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000155
156 BOOST_CHECK_NO_THROW(do {
157 face.receive(*makeData("/Hello/World/a"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500158 advanceClocks(1_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000159 } while (false));
160}
161
Davide Pesaventod247d492020-01-28 21:30:20 -0500162BOOST_AUTO_TEST_CASE(Timeout)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400163{
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800164 size_t nTimeouts = 0;
Junxiao Shib55e5d32018-07-18 13:32:00 -0600165 face.expressInterest(*makeInterest("/Hello/World", false, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500166 [] (auto&&...) { BOOST_FAIL("Unexpected Data"); },
167 [] (auto&&...) { BOOST_FAIL("Unexpected Nack"); },
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800168 [&nTimeouts] (const Interest& i) {
169 BOOST_CHECK_EQUAL(i.getName(), "/Hello/World");
170 ++nTimeouts;
171 });
Davide Pesavento0f830802018-01-16 23:58:58 -0500172 advanceClocks(200_ms, 5);
Eric Newberry83872fd2015-08-06 17:01:24 -0700173
174 BOOST_CHECK_EQUAL(nTimeouts, 1);
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800175 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
176 BOOST_CHECK_EQUAL(face.sentData.size(), 0);
177 BOOST_CHECK_EQUAL(face.sentNacks.size(), 0);
Eric Newberry83872fd2015-08-06 17:01:24 -0700178}
179
Davide Pesaventod247d492020-01-28 21:30:20 -0500180BOOST_AUTO_TEST_CASE(EmptyTimeoutCallback)
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000181{
Junxiao Shib55e5d32018-07-18 13:32:00 -0600182 face.expressInterest(*makeInterest("/Hello/World", false, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500183 [] (auto&&...) { BOOST_FAIL("Unexpected Data"); },
184 [] (auto&&...) { BOOST_FAIL("Unexpected Nack"); },
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000185 nullptr);
Davide Pesavento0f830802018-01-16 23:58:58 -0500186 advanceClocks(40_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000187
188 BOOST_CHECK_NO_THROW(do {
Davide Pesavento0f830802018-01-16 23:58:58 -0500189 advanceClocks(6_ms, 2);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000190 } while (false));
191}
192
Davide Pesaventod247d492020-01-28 21:30:20 -0500193BOOST_AUTO_TEST_CASE(ReplyNack)
Eric Newberry83872fd2015-08-06 17:01:24 -0700194{
195 size_t nNacks = 0;
196
Junxiao Shib55e5d32018-07-18 13:32:00 -0600197 auto interest = makeInterest("/Hello/World", false, 50_ms);
Junxiao Shib55e5d32018-07-18 13:32:00 -0600198 face.expressInterest(*interest,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500199 [] (auto&&...) { BOOST_FAIL("Unexpected Data"); },
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800200 [&] (const Interest& i, const lp::Nack& n) {
201 BOOST_CHECK(i.getName().isPrefixOf(n.getInterest().getName()));
202 BOOST_CHECK_EQUAL(i.getName(), "/Hello/World");
203 BOOST_CHECK_EQUAL(n.getReason(), lp::NackReason::DUPLICATE);
204 ++nNacks;
205 },
Davide Pesavento2f46d652023-11-09 23:40:01 -0500206 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Eric Newberry83872fd2015-08-06 17:01:24 -0700207
Davide Pesavento0f830802018-01-16 23:58:58 -0500208 advanceClocks(40_ms);
Eric Newberry83872fd2015-08-06 17:01:24 -0700209
Junxiao Shif5b5ae22016-08-08 05:54:41 +0000210 face.receive(makeNack(face.sentInterests.at(0), lp::NackReason::DUPLICATE));
Eric Newberry83872fd2015-08-06 17:01:24 -0700211
Davide Pesavento0f830802018-01-16 23:58:58 -0500212 advanceClocks(50_ms, 2);
Eric Newberry83872fd2015-08-06 17:01:24 -0700213
214 BOOST_CHECK_EQUAL(nNacks, 1);
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800215 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
Eric Newberry83872fd2015-08-06 17:01:24 -0700216}
217
Davide Pesaventod247d492020-01-28 21:30:20 -0500218BOOST_AUTO_TEST_CASE(MultipleNacks)
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800219{
220 size_t nNacks = 0;
221
Junxiao Shib55e5d32018-07-18 13:32:00 -0600222 auto interest = makeInterest("/Hello/World", false, 50_ms, 1);
223 face.expressInterest(*interest,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500224 [] (auto&&...) { BOOST_FAIL("Unexpected Data"); },
Davide Pesaventod247d492020-01-28 21:30:20 -0500225 [&] (const auto&, const auto&) { ++nNacks; },
Davide Pesavento2f46d652023-11-09 23:40:01 -0500226 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800227
Junxiao Shib55e5d32018-07-18 13:32:00 -0600228 interest->setNonce(2);
229 face.expressInterest(*interest,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500230 [] (auto&&...) { BOOST_FAIL("Unexpected Data"); },
Davide Pesaventod247d492020-01-28 21:30:20 -0500231 [&] (const auto&, const auto&) { ++nNacks; },
Davide Pesavento2f46d652023-11-09 23:40:01 -0500232 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800233
Davide Pesavento0f830802018-01-16 23:58:58 -0500234 advanceClocks(40_ms);
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800235
236 face.receive(makeNack(face.sentInterests.at(1), lp::NackReason::DUPLICATE));
237
Davide Pesavento0f830802018-01-16 23:58:58 -0500238 advanceClocks(50_ms, 2);
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800239
240 BOOST_CHECK_EQUAL(nNacks, 2);
241 BOOST_CHECK_EQUAL(face.sentInterests.size(), 2);
242}
243
Davide Pesaventod247d492020-01-28 21:30:20 -0500244BOOST_AUTO_TEST_CASE(EmptyNackCallback)
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000245{
Junxiao Shib55e5d32018-07-18 13:32:00 -0600246 face.expressInterest(*makeInterest("/Hello/World"),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500247 [] (auto&&...) { BOOST_FAIL("Unexpected Data"); },
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000248 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500249 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500250 advanceClocks(1_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000251
252 BOOST_CHECK_NO_THROW(do {
253 face.receive(makeNack(face.sentInterests.at(0), lp::NackReason::DUPLICATE));
Davide Pesavento0f830802018-01-16 23:58:58 -0500254 advanceClocks(1_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000255 } while (false));
256}
257
Davide Pesavento0c526032024-01-31 21:14:01 -0500258BOOST_AUTO_TEST_CASE(PutDataFromDataCallback,
259 * ut::description("test for bug #4596"))
Davide Pesaventod247d492020-01-28 21:30:20 -0500260{
261 face.expressInterest(*makeInterest("/localhost/notification/1"),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500262 [&] (auto&&...) {
Davide Pesaventod247d492020-01-28 21:30:20 -0500263 face.put(*makeData("/chronosync/sampleDigest/1"));
264 }, nullptr, nullptr);
265 advanceClocks(10_ms);
266 BOOST_CHECK_EQUAL(face.sentInterests.back().getName(), "/localhost/notification/1");
267
268 face.receive(*makeInterest("/chronosync/sampleDigest", true));
269 advanceClocks(10_ms);
270
271 face.put(*makeData("/localhost/notification/1"));
272 advanceClocks(10_ms);
273 BOOST_CHECK_EQUAL(face.sentData.back().getName(), "/chronosync/sampleDigest/1");
274}
275
Davide Pesavento0c526032024-01-31 21:14:01 -0500276BOOST_AUTO_TEST_CASE(DestroyWithPendingInterest,
277 * ut::description("test for bug #2518"))
Davide Pesaventod247d492020-01-28 21:30:20 -0500278{
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500279 auto face2 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500280 face2->expressInterest(*makeInterest("/Hello/World", false, 50_ms),
281 nullptr, nullptr, nullptr);
282 advanceClocks(50_ms, 2);
283 face2.reset();
284
Davide Pesavento0c526032024-01-31 21:14:01 -0500285 advanceClocks(50_ms, 2); // should not crash
Davide Pesaventod247d492020-01-28 21:30:20 -0500286
287 // avoid "test case [...] did not check any assertions" message from Boost.Test
288 BOOST_CHECK(true);
289}
290
291BOOST_AUTO_TEST_CASE(Handle)
Junxiao Shi80609d42019-01-29 18:15:22 +0000292{
293 auto hdl = face.expressInterest(*makeInterest("/Hello/World", true, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500294 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
295 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
296 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500297 advanceClocks(1_ms);
Junxiao Shi80609d42019-01-29 18:15:22 +0000298 hdl.cancel();
Davide Pesaventod247d492020-01-28 21:30:20 -0500299 advanceClocks(1_ms);
Junxiao Shi80609d42019-01-29 18:15:22 +0000300 face.receive(*makeData("/Hello/World/%21"));
301 advanceClocks(200_ms, 5);
302
Davide Pesaventod247d492020-01-28 21:30:20 -0500303 // cancel after destructing face
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500304 auto face2 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500305 auto hdl2 = face2->expressInterest(*makeInterest("/Hello/World", true, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500306 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
307 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
308 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500309 advanceClocks(1_ms);
310 face2.reset();
311 advanceClocks(1_ms);
312 hdl2.cancel(); // should not crash
313 advanceClocks(1_ms);
314
Junxiao Shi80609d42019-01-29 18:15:22 +0000315 // avoid "test case [...] did not check any assertions" message from Boost.Test
316 BOOST_CHECK(true);
317}
318
Davide Pesaventod247d492020-01-28 21:30:20 -0500319BOOST_AUTO_TEST_SUITE_END() // ExpressInterest
320
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000321BOOST_AUTO_TEST_CASE(RemoveAllPendingInterests)
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500322{
Junxiao Shib55e5d32018-07-18 13:32:00 -0600323 face.expressInterest(*makeInterest("/Hello/World/0", false, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500324 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
325 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
326 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500327
Junxiao Shib55e5d32018-07-18 13:32:00 -0600328 face.expressInterest(*makeInterest("/Hello/World/1", false, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500329 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
330 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
331 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500332
Davide Pesavento0f830802018-01-16 23:58:58 -0500333 advanceClocks(10_ms);
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500334
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800335 face.removeAllPendingInterests();
Davide Pesavento0f830802018-01-16 23:58:58 -0500336 advanceClocks(10_ms);
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500337
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800338 BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0);
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500339
Junxiao Shi85d90832016-08-04 03:19:46 +0000340 face.receive(*makeData("/Hello/World/0"));
341 face.receive(*makeData("/Hello/World/1"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500342 advanceClocks(200_ms, 5);
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500343}
344
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000345BOOST_AUTO_TEST_SUITE(Producer)
346
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000347BOOST_AUTO_TEST_CASE(PutData)
348{
349 BOOST_CHECK_EQUAL(face.sentData.size(), 0);
350
351 Data data("/4g7xxcuEow/KFvK5Kf2m");
352 signData(data);
353 face.put(data);
354
355 lp::CachePolicy cachePolicy;
356 cachePolicy.setPolicy(lp::CachePolicyType::NO_CACHE);
357 data.setTag(make_shared<lp::CachePolicyTag>(cachePolicy));
Eric Newberry4d261b62016-11-10 13:40:09 -0700358 data.setTag(make_shared<lp::CongestionMarkTag>(1));
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000359 face.put(data);
360
Davide Pesavento0f830802018-01-16 23:58:58 -0500361 advanceClocks(10_ms);
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000362 BOOST_REQUIRE_EQUAL(face.sentData.size(), 2);
363 BOOST_CHECK(face.sentData[0].getTag<lp::CachePolicyTag>() == nullptr);
Eric Newberry4d261b62016-11-10 13:40:09 -0700364 BOOST_CHECK(face.sentData[0].getTag<lp::CongestionMarkTag>() == nullptr);
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000365 BOOST_CHECK(face.sentData[1].getTag<lp::CachePolicyTag>() != nullptr);
Eric Newberry4d261b62016-11-10 13:40:09 -0700366 BOOST_CHECK(face.sentData[1].getTag<lp::CongestionMarkTag>() != nullptr);
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000367}
368
Junxiao Shib6828912017-11-20 14:06:32 +0000369BOOST_AUTO_TEST_CASE(PutDataLoopback)
370{
371 bool hasInterest1 = false, hasData = false;
372
373 // first InterestFilter allows loopback and should receive Interest
Davide Pesavento2f46d652023-11-09 23:40:01 -0500374 face.setInterestFilter("/", [&] (auto&&...) {
Junxiao Shib6828912017-11-20 14:06:32 +0000375 hasInterest1 = true;
376 // do not respond with Data right away, so Face must send Interest to forwarder
377 });
Davide Pesavento2f46d652023-11-09 23:40:01 -0500378
Junxiao Shib6828912017-11-20 14:06:32 +0000379 // second InterestFilter disallows loopback and should not receive Interest
380 face.setInterestFilter(InterestFilter("/").allowLoopback(false),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500381 [] (auto&&...) { BOOST_ERROR("Unexpected Interest on second InterestFilter"); });
Junxiao Shib6828912017-11-20 14:06:32 +0000382
Junxiao Shib55e5d32018-07-18 13:32:00 -0600383 face.expressInterest(*makeInterest("/A", true),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500384 [&] (auto&&...) { hasData = true; },
385 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
386 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500387 advanceClocks(1_ms);
Junxiao Shib6828912017-11-20 14:06:32 +0000388 BOOST_CHECK_EQUAL(hasInterest1, true); // Interest looped back
389 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); // Interest sent to forwarder
390 BOOST_CHECK_EQUAL(hasData, false); // waiting for Data
391
392 face.put(*makeData("/A/B")); // first InterestFilter responds with Data
Davide Pesavento0f830802018-01-16 23:58:58 -0500393 advanceClocks(1_ms);
Junxiao Shib6828912017-11-20 14:06:32 +0000394 BOOST_CHECK_EQUAL(hasData, true);
395 BOOST_CHECK_EQUAL(face.sentData.size(), 0); // do not spill Data to forwarder
396}
397
Junxiao Shi859888f2017-09-12 14:29:16 +0000398BOOST_AUTO_TEST_CASE(PutMultipleData)
399{
400 bool hasInterest1 = false;
401 // register two Interest destinations
Davide Pesavento2f46d652023-11-09 23:40:01 -0500402 face.setInterestFilter("/", [&] (auto&&...) {
Junxiao Shi859888f2017-09-12 14:29:16 +0000403 hasInterest1 = true;
404 // sending Data right away from the first destination, don't care whether Interest goes to second destination
405 face.put(*makeData("/A/B"));
Davide Pesavento2f46d652023-11-09 23:40:01 -0500406 });
407 face.setInterestFilter("/", [] (auto&&...) {});
Davide Pesavento0f830802018-01-16 23:58:58 -0500408 advanceClocks(10_ms);
Junxiao Shi859888f2017-09-12 14:29:16 +0000409
Junxiao Shib55e5d32018-07-18 13:32:00 -0600410 face.receive(*makeInterest("/A", true));
Davide Pesavento0f830802018-01-16 23:58:58 -0500411 advanceClocks(10_ms);
Junxiao Shi859888f2017-09-12 14:29:16 +0000412 BOOST_CHECK(hasInterest1);
413 BOOST_CHECK_EQUAL(face.sentData.size(), 1);
414 BOOST_CHECK_EQUAL(face.sentData.at(0).getName(), "/A/B");
415
416 face.put(*makeData("/A/C"));
417 BOOST_CHECK_EQUAL(face.sentData.size(), 1); // additional Data are ignored
418}
419
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000420BOOST_AUTO_TEST_CASE(PutNack)
421{
Davide Pesavento2f46d652023-11-09 23:40:01 -0500422 // register one Interest destination so that face can accept Nacks
423 face.setInterestFilter("/", [] (auto&&...) {});
Davide Pesavento0f830802018-01-16 23:58:58 -0500424 advanceClocks(10_ms);
Junxiao Shi79a7a162017-09-09 08:33:57 +0000425
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000426 BOOST_CHECK_EQUAL(face.sentNacks.size(), 0);
427
Davide Pesaventof6b45892023-03-13 15:00:51 -0400428 face.put(makeNack(*makeInterest("/unsolicited", false, std::nullopt, 18645250),
Junxiao Shib55e5d32018-07-18 13:32:00 -0600429 lp::NackReason::NO_ROUTE));
Davide Pesavento0f830802018-01-16 23:58:58 -0500430 advanceClocks(10_ms);
Junxiao Shi1ad0b4b2017-08-18 14:19:14 +0000431 BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); // unsolicited Nack would not be sent
Eric Newberry4d261b62016-11-10 13:40:09 -0700432
Davide Pesaventof6b45892023-03-13 15:00:51 -0400433 auto interest1 = makeInterest("/Hello/World", false, std::nullopt, 14247162);
Junxiao Shib55e5d32018-07-18 13:32:00 -0600434 face.receive(*interest1);
Davide Pesaventof6b45892023-03-13 15:00:51 -0400435 auto interest2 = makeInterest("/another/prefix", false, std::nullopt, 92203002);
Junxiao Shib55e5d32018-07-18 13:32:00 -0600436 face.receive(*interest2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500437 advanceClocks(10_ms);
Junxiao Shi1ad0b4b2017-08-18 14:19:14 +0000438
Junxiao Shib55e5d32018-07-18 13:32:00 -0600439 face.put(makeNack(*interest1, lp::NackReason::DUPLICATE));
Davide Pesavento0f830802018-01-16 23:58:58 -0500440 advanceClocks(10_ms);
Junxiao Shi1ad0b4b2017-08-18 14:19:14 +0000441 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 Shib55e5d32018-07-18 13:32:00 -0600445 auto nack = makeNack(*interest2, lp::NackReason::NO_ROUTE);
Eric Newberry4d261b62016-11-10 13:40:09 -0700446 nack.setTag(make_shared<lp::CongestionMarkTag>(1));
447 face.put(nack);
Davide Pesavento0f830802018-01-16 23:58:58 -0500448 advanceClocks(10_ms);
Eric Newberry4d261b62016-11-10 13:40:09 -0700449 BOOST_REQUIRE_EQUAL(face.sentNacks.size(), 2);
Junxiao Shi1ad0b4b2017-08-18 14:19:14 +0000450 BOOST_CHECK_EQUAL(face.sentNacks[1].getReason(), lp::NackReason::NO_ROUTE);
Eric Newberry4d261b62016-11-10 13:40:09 -0700451 BOOST_CHECK(face.sentNacks[1].getTag<lp::CongestionMarkTag>() != nullptr);
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000452}
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500453
Junxiao Shi79a7a162017-09-09 08:33:57 +0000454BOOST_AUTO_TEST_CASE(PutMultipleNack)
455{
Junxiao Shi859888f2017-09-12 14:29:16 +0000456 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 Pesavento2f46d652023-11-09 23:40:01 -0500463 face.setInterestFilter("/", [&] (auto&&...) { hasInterest2 = true; });
Davide Pesavento0f830802018-01-16 23:58:58 -0500464 advanceClocks(10_ms);
Junxiao Shi79a7a162017-09-09 08:33:57 +0000465
Davide Pesaventof6b45892023-03-13 15:00:51 -0400466 auto interest = makeInterest("/A", false, std::nullopt, 14333271);
Junxiao Shib55e5d32018-07-18 13:32:00 -0600467 face.receive(*interest);
Davide Pesavento0f830802018-01-16 23:58:58 -0500468 advanceClocks(10_ms);
Junxiao Shi859888f2017-09-12 14:29:16 +0000469 BOOST_CHECK(hasInterest1);
470 BOOST_CHECK(hasInterest2);
Junxiao Shi79a7a162017-09-09 08:33:57 +0000471
Junxiao Shi859888f2017-09-12 14:29:16 +0000472 // Nack from first destination is received, should wait for a response from the other destination
473 BOOST_CHECK_EQUAL(face.sentNacks.size(), 0);
Junxiao Shi79a7a162017-09-09 08:33:57 +0000474
Junxiao Shib55e5d32018-07-18 13:32:00 -0600475 face.put(makeNack(*interest, lp::NackReason::NO_ROUTE)); // Nack from second destination
Davide Pesavento0f830802018-01-16 23:58:58 -0500476 advanceClocks(10_ms);
Junxiao Shi859888f2017-09-12 14:29:16 +0000477 BOOST_CHECK_EQUAL(face.sentNacks.size(), 1); // sending Nack after both destinations Nacked
Junxiao Shi79a7a162017-09-09 08:33:57 +0000478 BOOST_CHECK_EQUAL(face.sentNacks.at(0).getReason(), lp::NackReason::CONGESTION); // least severe reason
479
Junxiao Shib55e5d32018-07-18 13:32:00 -0600480 face.put(makeNack(*interest, lp::NackReason::DUPLICATE));
Junxiao Shi79a7a162017-09-09 08:33:57 +0000481 BOOST_CHECK_EQUAL(face.sentNacks.size(), 1); // additional Nacks are ignored
482}
483
Junxiao Shib6828912017-11-20 14:06:32 +0000484BOOST_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 });
Davide Pesavento2f46d652023-11-09 23:40:01 -0500493
Junxiao Shib6828912017-11-20 14:06:32 +0000494 // second InterestFilter disallows loopback and should not receive Interest
495 face.setInterestFilter(InterestFilter("/").allowLoopback(false),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500496 [] (auto&&...) { BOOST_ERROR("Unexpected Interest on second InterestFilter"); });
Junxiao Shib6828912017-11-20 14:06:32 +0000497
Davide Pesaventof6b45892023-03-13 15:00:51 -0400498 auto interest = makeInterest("/A", false, std::nullopt, 28395852);
Junxiao Shib55e5d32018-07-18 13:32:00 -0600499 face.expressInterest(*interest,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500500 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
Junxiao Shib6828912017-11-20 14:06:32 +0000501 [&] (const Interest&, const lp::Nack& nack) {
502 hasNack = true;
503 BOOST_CHECK_EQUAL(nack.getReason(), lp::NackReason::CONGESTION);
504 },
Davide Pesavento2f46d652023-11-09 23:40:01 -0500505 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500506 advanceClocks(1_ms);
Junxiao Shib6828912017-11-20 14:06:32 +0000507 BOOST_CHECK_EQUAL(hasInterest1, true); // Interest looped back
508 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); // Interest sent to forwarder
509 BOOST_CHECK_EQUAL(hasNack, false); // waiting for Nack from forwarder
510
Junxiao Shib55e5d32018-07-18 13:32:00 -0600511 face.receive(makeNack(*interest, lp::NackReason::NO_ROUTE));
Davide Pesavento0f830802018-01-16 23:58:58 -0500512 advanceClocks(1_ms);
Junxiao Shib6828912017-11-20 14:06:32 +0000513 BOOST_CHECK_EQUAL(hasNack, true);
514}
515
Davide Pesaventod247d492020-01-28 21:30:20 -0500516BOOST_AUTO_TEST_SUITE_END() // Producer
517
518BOOST_AUTO_TEST_SUITE(RegisterPrefix)
519
520BOOST_FIXTURE_TEST_CASE(Failure, FaceFixture<NoPrefixRegReply>)
521{
522 BOOST_CHECK(!runPrefixReg([&] (const auto& success, const auto& failure) {
523 face.registerPrefix("/Hello/World", success, failure);
524 this->advanceClocks(5_s, 20); // wait for command timeout
525 }));
526}
527
528BOOST_AUTO_TEST_CASE(Handle)
529{
530 RegisteredPrefixHandle hdl;
531 auto doReg = [&] {
532 return runPrefixReg([&] (const auto& success, const auto& failure) {
533 hdl = face.registerPrefix("/Hello/World", success, failure);
534 });
535 };
536 auto doUnreg = [&] {
537 return runPrefixUnreg([&] (const auto& success, const auto& failure) {
538 hdl.unregister(success, failure);
539 });
540 };
541
542 // despite the "undefined behavior" warning, we try not to crash, but no API guarantee for this
543 BOOST_CHECK(!doUnreg());
544
545 // cancel after unregister
546 BOOST_CHECK(doReg());
547 BOOST_CHECK(doUnreg());
548 hdl.cancel();
549 advanceClocks(1_ms);
550
551 // unregister after cancel
552 BOOST_CHECK(doReg());
553 hdl.cancel();
554 advanceClocks(1_ms);
555 BOOST_CHECK(!doUnreg());
556
557 // cancel after destructing face
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500558 auto face2 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500559 hdl = face2->registerPrefix("/Hello/World/2", nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500560 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500561 advanceClocks(1_ms);
562 face2.reset();
563 advanceClocks(1_ms);
564 hdl.cancel(); // should not crash
565 advanceClocks(1_ms);
566
567 // unregister after destructing face
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500568 auto face3 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500569 hdl = face3->registerPrefix("/Hello/World/3", nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500570 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500571 advanceClocks(1_ms);
572 face3.reset();
573 advanceClocks(1_ms);
574 BOOST_CHECK(!doUnreg());
575}
576
577BOOST_AUTO_TEST_SUITE_END() // RegisterPrefix
578
579BOOST_AUTO_TEST_SUITE(SetInterestFilter)
580
581BOOST_AUTO_TEST_CASE(SetAndCancel)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400582{
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800583 size_t nInterests = 0;
584 size_t nRegs = 0;
Davide Pesavento720e25c2019-07-14 01:33:52 -0400585 auto hdl = face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500586 [&] (auto&&...) { ++nInterests; },
587 [&] (auto&&...) { ++nRegs; },
588 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500589 advanceClocks(25_ms, 4);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800590 BOOST_CHECK_EQUAL(nRegs, 1);
591 BOOST_CHECK_EQUAL(nInterests, 0);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400592
Junxiao Shib55e5d32018-07-18 13:32:00 -0600593 face.receive(*makeInterest("/Hello/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500594 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400595
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800596 BOOST_CHECK_EQUAL(nRegs, 1);
597 BOOST_CHECK_EQUAL(nInterests, 1);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400598
Junxiao Shib55e5d32018-07-18 13:32:00 -0600599 face.receive(*makeInterest("/Bye/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500600 advanceClocks(10000_ms, 10);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800601 BOOST_CHECK_EQUAL(nInterests, 1);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400602
Junxiao Shib55e5d32018-07-18 13:32:00 -0600603 face.receive(*makeInterest("/Hello/World/%21/2"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500604 advanceClocks(25_ms, 4);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800605 BOOST_CHECK_EQUAL(nInterests, 2);
606
607 // removing filter
Davide Pesavento720e25c2019-07-14 01:33:52 -0400608 hdl.cancel();
Davide Pesavento0f830802018-01-16 23:58:58 -0500609 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400610
Junxiao Shib55e5d32018-07-18 13:32:00 -0600611 face.receive(*makeInterest("/Hello/World/%21/3"));
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800612 BOOST_CHECK_EQUAL(nInterests, 2);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800613}
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400614
Davide Pesaventod247d492020-01-28 21:30:20 -0500615BOOST_AUTO_TEST_CASE(EmptyInterestCallback)
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000616{
617 face.setInterestFilter("/A", nullptr);
Davide Pesavento0f830802018-01-16 23:58:58 -0500618 advanceClocks(1_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000619
620 BOOST_CHECK_NO_THROW(do {
621 face.receive(*makeInterest("/A/1"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500622 advanceClocks(1_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000623 } while (false));
624}
625
Davide Pesaventod247d492020-01-28 21:30:20 -0500626BOOST_AUTO_TEST_CASE(WithoutSuccessCallback)
Joao Pereira0b3cac52015-07-02 14:49:49 -0400627{
628 size_t nInterests = 0;
Davide Pesavento720e25c2019-07-14 01:33:52 -0400629 auto hdl = face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500630 [&] (auto&&...) { ++nInterests; },
631 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500632 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400633 BOOST_CHECK_EQUAL(nInterests, 0);
634
Junxiao Shib55e5d32018-07-18 13:32:00 -0600635 face.receive(*makeInterest("/Hello/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500636 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400637
638 BOOST_CHECK_EQUAL(nInterests, 1);
639
Junxiao Shib55e5d32018-07-18 13:32:00 -0600640 face.receive(*makeInterest("/Bye/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500641 advanceClocks(10000_ms, 10);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400642 BOOST_CHECK_EQUAL(nInterests, 1);
643
Junxiao Shib55e5d32018-07-18 13:32:00 -0600644 face.receive(*makeInterest("/Hello/World/%21/2"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500645 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400646 BOOST_CHECK_EQUAL(nInterests, 2);
647
648 // removing filter
Davide Pesavento720e25c2019-07-14 01:33:52 -0400649 hdl.cancel();
Davide Pesavento0f830802018-01-16 23:58:58 -0500650 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400651
Junxiao Shib55e5d32018-07-18 13:32:00 -0600652 face.receive(*makeInterest("/Hello/World/%21/3"));
Joao Pereira0b3cac52015-07-02 14:49:49 -0400653 BOOST_CHECK_EQUAL(nInterests, 2);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400654}
655
Davide Pesaventod247d492020-01-28 21:30:20 -0500656BOOST_FIXTURE_TEST_CASE(Failure, FaceFixture<NoPrefixRegReply>)
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800657{
658 // don't enable registration reply
659 size_t nRegFailed = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800660 face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500661 [] (auto&&...) { BOOST_FAIL("Unexpected Interest"); },
662 [] (auto&&...) { BOOST_FAIL("Unexpected success"); },
663 [&] (auto&&...) { ++nRegFailed; });
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800664
Davide Pesavento0f830802018-01-16 23:58:58 -0500665 advanceClocks(25_ms, 4);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800666 BOOST_CHECK_EQUAL(nRegFailed, 0);
667
Davide Pesavento0f830802018-01-16 23:58:58 -0500668 advanceClocks(2000_ms, 5);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800669 BOOST_CHECK_EQUAL(nRegFailed, 1);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400670}
671
Davide Pesaventod247d492020-01-28 21:30:20 -0500672BOOST_FIXTURE_TEST_CASE(FailureWithoutSuccessCallback, FaceFixture<NoPrefixRegReply>)
Joao Pereira0b3cac52015-07-02 14:49:49 -0400673{
674 // don't enable registration reply
675 size_t nRegFailed = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800676 face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500677 [] (auto&&...) { BOOST_FAIL("Unexpected Interest"); },
678 [&] (auto&&...) { ++nRegFailed; });
Joao Pereira0b3cac52015-07-02 14:49:49 -0400679
Davide Pesavento0f830802018-01-16 23:58:58 -0500680 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400681 BOOST_CHECK_EQUAL(nRegFailed, 0);
682
Davide Pesavento0f830802018-01-16 23:58:58 -0500683 advanceClocks(2000_ms, 5);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400684 BOOST_CHECK_EQUAL(nRegFailed, 1);
685}
686
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800687BOOST_AUTO_TEST_CASE(SimilarFilters)
688{
689 size_t nInInterests1 = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800690 face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500691 [&nInInterests1] (auto&&...) { ++nInInterests1; },
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000692 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500693 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800694
695 size_t nInInterests2 = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800696 face.setInterestFilter("/Hello",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500697 [&nInInterests2] (auto&&...) { ++nInInterests2; },
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000698 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500699 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400700
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800701 size_t nInInterests3 = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800702 face.setInterestFilter("/Los/Angeles/Lakers",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500703 [&nInInterests3] (auto&&...) { ++nInInterests3; },
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000704 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500705 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400706
Davide Pesavento0f830802018-01-16 23:58:58 -0500707 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400708
Junxiao Shib55e5d32018-07-18 13:32:00 -0600709 face.receive(*makeInterest("/Hello/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500710 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400711
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800712 BOOST_CHECK_EQUAL(nInInterests1, 1);
713 BOOST_CHECK_EQUAL(nInInterests2, 1);
714 BOOST_CHECK_EQUAL(nInInterests3, 0);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400715}
716
Davide Pesaventod247d492020-01-28 21:30:20 -0500717BOOST_AUTO_TEST_CASE(RegexFilter)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400718{
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800719 size_t nInInterests = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800720 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500721 [&nInInterests] (auto&&...) { ++nInInterests; },
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000722 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500723 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400724
Davide Pesavento0f830802018-01-16 23:58:58 -0500725 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400726
Junxiao Shib55e5d32018-07-18 13:32:00 -0600727 face.receive(*makeInterest("/Hello/World/a")); // shouldn't match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400728 BOOST_CHECK_EQUAL(nInInterests, 0);
729
Junxiao Shib55e5d32018-07-18 13:32:00 -0600730 face.receive(*makeInterest("/Hello/World/a/b")); // should match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400731 BOOST_CHECK_EQUAL(nInInterests, 1);
732
Junxiao Shib55e5d32018-07-18 13:32:00 -0600733 face.receive(*makeInterest("/Hello/World/a/b/c")); // should match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400734 BOOST_CHECK_EQUAL(nInInterests, 2);
735
Junxiao Shib55e5d32018-07-18 13:32:00 -0600736 face.receive(*makeInterest("/Hello/World/a/b/d")); // should not match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400737 BOOST_CHECK_EQUAL(nInInterests, 2);
738}
739
Davide Pesaventod247d492020-01-28 21:30:20 -0500740BOOST_AUTO_TEST_CASE(RegexFilterError)
741{
742 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500743 // Do NOT use 'auto' for this lambda. This is testing the (failure of)
744 // implicit conversion from InterestFilter to Name, therefore the type
745 // of the first parameter must be explicit.
Davide Pesaventod247d492020-01-28 21:30:20 -0500746 [] (const Name&, const Interest&) {
Davide Pesavento2f46d652023-11-09 23:40:01 -0500747 BOOST_FAIL("InterestFilter::Error should have been raised");
Davide Pesaventod247d492020-01-28 21:30:20 -0500748 },
749 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500750 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500751
752 advanceClocks(25_ms, 4);
753
754 BOOST_CHECK_THROW(face.receive(*makeInterest("/Hello/World/XXX/b/c")), InterestFilter::Error);
755}
756
757BOOST_AUTO_TEST_CASE(RegexFilterAndRegisterPrefix)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400758{
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800759 size_t nInInterests = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800760 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500761 [&] (auto&&...) { ++nInInterests; });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400762
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800763 size_t nRegSuccesses = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800764 face.registerPrefix("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500765 [&] (auto&&...) { ++nRegSuccesses; },
766 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400767
Davide Pesavento0f830802018-01-16 23:58:58 -0500768 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400769 BOOST_CHECK_EQUAL(nRegSuccesses, 1);
770
Junxiao Shib55e5d32018-07-18 13:32:00 -0600771 face.receive(*makeInterest("/Hello/World/a")); // shouldn't match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400772 BOOST_CHECK_EQUAL(nInInterests, 0);
773
Junxiao Shib55e5d32018-07-18 13:32:00 -0600774 face.receive(*makeInterest("/Hello/World/a/b")); // should match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400775 BOOST_CHECK_EQUAL(nInInterests, 1);
776
Junxiao Shib55e5d32018-07-18 13:32:00 -0600777 face.receive(*makeInterest("/Hello/World/a/b/c")); // should match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400778 BOOST_CHECK_EQUAL(nInInterests, 2);
779
Junxiao Shib55e5d32018-07-18 13:32:00 -0600780 face.receive(*makeInterest("/Hello/World/a/b/d")); // should not match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400781 BOOST_CHECK_EQUAL(nInInterests, 2);
782}
783
Davide Pesavento0c526032024-01-31 21:14:01 -0500784BOOST_FIXTURE_TEST_CASE(WithoutRegisterPrefix, FaceFixture<NoPrefixRegReply>,
785 * ut::description("test for bug #2318"))
Junxiao Shia1ea5062014-12-27 22:33:39 -0700786{
787 // This behavior is specific to DummyClientFace.
788 // Regular Face won't accept incoming packets until something is sent.
789
790 int hit = 0;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500791 face.setInterestFilter(Name("/"), [&hit] (auto&&...) { ++hit; });
792 face.processEvents(-1_ms);
Junxiao Shia1ea5062014-12-27 22:33:39 -0700793
Junxiao Shib55e5d32018-07-18 13:32:00 -0600794 face.receive(*makeInterest("/A"));
Davide Pesavento2f46d652023-11-09 23:40:01 -0500795 face.processEvents(-1_ms);
Junxiao Shia1ea5062014-12-27 22:33:39 -0700796
797 BOOST_CHECK_EQUAL(hit, 1);
798}
799
Davide Pesaventod247d492020-01-28 21:30:20 -0500800BOOST_AUTO_TEST_CASE(Handle)
Junxiao Shi60aaef02019-01-14 04:59:30 +0000801{
802 int hit = 0;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500803 InterestFilterHandle hdl = face.setInterestFilter(Name("/"), [&hit] (auto&&...) { ++hit; });
Junxiao Shi60aaef02019-01-14 04:59:30 +0000804 face.processEvents(-1_ms);
805
806 face.receive(*makeInterest("/A"));
807 face.processEvents(-1_ms);
808 BOOST_CHECK_EQUAL(hit, 1);
809
810 hdl.cancel();
811 face.processEvents(-1_ms);
812
813 face.receive(*makeInterest("/B"));
814 face.processEvents(-1_ms);
815 BOOST_CHECK_EQUAL(hit, 1);
Davide Pesaventod247d492020-01-28 21:30:20 -0500816
817 // cancel after destructing face
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500818 auto face2 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500819 InterestFilterHandle hdl2 = face2->setInterestFilter("/Hello/World/2", nullptr);
820 advanceClocks(1_ms);
821 face2.reset();
822 advanceClocks(1_ms);
823 hdl2.cancel(); // should not crash
824 advanceClocks(1_ms);
Junxiao Shi60aaef02019-01-14 04:59:30 +0000825}
826
Davide Pesaventod247d492020-01-28 21:30:20 -0500827BOOST_AUTO_TEST_SUITE_END() // SetInterestFilter
Junxiao Shiae0b4182016-08-08 22:53:17 +0000828
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500829BOOST_AUTO_TEST_CASE(ProcessEvents)
830{
Davide Pesavento2f46d652023-11-09 23:40:01 -0500831 face.processEvents(-1_ms); // io_context::restart()/poll() inside
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500832
Davide Pesavento2f46d652023-11-09 23:40:01 -0500833 int nRegSuccesses = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800834 face.registerPrefix("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500835 [&] (auto&&...) { ++nRegSuccesses; },
836 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500837
Davide Pesavento2f46d652023-11-09 23:40:01 -0500838 // io_context::poll() without reset
839 face.getIoContext().poll();
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500840 BOOST_CHECK_EQUAL(nRegSuccesses, 0);
841
Davide Pesavento2f46d652023-11-09 23:40:01 -0500842 face.processEvents(-1_ms); // io_context::restart()/poll() inside
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500843 BOOST_CHECK_EQUAL(nRegSuccesses, 1);
844}
845
Davide Pesavento0c526032024-01-31 21:14:01 -0500846BOOST_AUTO_TEST_CASE(DestroyWithoutProcessEvents,
847 * ut::description("test for bug #3248"))
Junxiao Shiae0b4182016-08-08 22:53:17 +0000848{
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500849 auto face2 = make_unique<Face>(m_io);
Junxiao Shiae0b4182016-08-08 22:53:17 +0000850 face2.reset();
851
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500852 m_io.poll(); // should not crash
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100853
854 // avoid "test case [...] did not check any assertions" message from Boost.Test
855 BOOST_CHECK(true);
Junxiao Shiae0b4182016-08-08 22:53:17 +0000856}
857
Junxiao Shiae0b4182016-08-08 22:53:17 +0000858BOOST_AUTO_TEST_SUITE(Transport)
859
860using ndn::Transport;
861
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500862BOOST_FIXTURE_TEST_CASE(FaceTransport, IoKeyChainFixture)
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800863{
Davide Pesavento2f46d652023-11-09 23:40:01 -0500864 BOOST_CHECK_NO_THROW(Face(shared_ptr<Transport>()));
865 BOOST_CHECK_NO_THROW(Face(shared_ptr<Transport>(), m_io));
866 BOOST_CHECK_NO_THROW(Face(shared_ptr<Transport>(), m_io, m_keyChain));
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800867
868 auto transport = make_shared<TcpTransport>("localhost", "6363"); // no real io operations will be scheduled
Davide Pesavento2f46d652023-11-09 23:40:01 -0500869 BOOST_CHECK(&Face(transport).getTransport() == transport.get());
870 BOOST_CHECK(&Face(transport, m_io).getTransport() == transport.get());
871 BOOST_CHECK(&Face(transport, m_io, m_keyChain).getTransport() == transport.get());
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800872}
873
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500874class WithEnv
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700875{
876public:
877 WithEnv()
878 {
879 if (getenv("NDN_CLIENT_TRANSPORT") != nullptr) {
880 m_oldTransport = getenv("NDN_CLIENT_TRANSPORT");
881 unsetenv("NDN_CLIENT_TRANSPORT");
882 }
883 }
884
885 void
886 configure(const std::string& faceUri)
887 {
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500888 setenv("NDN_CLIENT_TRANSPORT", faceUri.data(), true);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700889 }
890
891 ~WithEnv()
892 {
893 if (!m_oldTransport.empty()) {
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500894 setenv("NDN_CLIENT_TRANSPORT", m_oldTransport.data(), true);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700895 }
896 else {
897 unsetenv("NDN_CLIENT_TRANSPORT");
898 }
899 }
900
901private:
902 std::string m_oldTransport;
903};
904
905class WithConfig : private TestHomeFixture<DefaultPibDir>
906{
907public:
908 void
909 configure(const std::string& faceUri)
910 {
911 createClientConf({"transport=" + faceUri});
912 }
913};
914
915class WithEnvAndConfig : public WithEnv, public WithConfig
916{
917};
918
Davide Pesavento49e1e872023-11-11 00:45:23 -0500919using ConfigOptions = boost::mp11::mp_list<WithEnv, WithConfig>;
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700920
921BOOST_FIXTURE_TEST_CASE(NoConfig, WithEnvAndConfig) // fixture configures test HOME and PIB/TPM path
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700922{
923 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500924 BOOST_CHECK_NO_THROW(face = make_shared<Face>());
925 BOOST_CHECK(dynamic_cast<UnixTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700926}
927
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700928BOOST_FIXTURE_TEST_CASE_TEMPLATE(Unix, T, ConfigOptions, T)
929{
930 this->configure("unix://some/path");
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700931
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700932 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500933 BOOST_CHECK_NO_THROW(face = make_shared<Face>());
934 BOOST_CHECK(dynamic_cast<UnixTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700935}
936
937BOOST_FIXTURE_TEST_CASE_TEMPLATE(Tcp, T, ConfigOptions, T)
938{
939 this->configure("tcp://127.0.0.1:6000");
940
941 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500942 BOOST_CHECK_NO_THROW(face = make_shared<Face>());
943 BOOST_CHECK(dynamic_cast<TcpTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700944}
945
946BOOST_FIXTURE_TEST_CASE_TEMPLATE(WrongTransport, T, ConfigOptions, T)
947{
948 this->configure("wrong-transport:");
949
950 BOOST_CHECK_THROW(make_shared<Face>(), ConfigFile::Error);
951}
952
953BOOST_FIXTURE_TEST_CASE_TEMPLATE(WrongUri, T, ConfigOptions, T)
954{
955 this->configure("wrong-uri");
956
957 BOOST_CHECK_THROW(make_shared<Face>(), ConfigFile::Error);
958}
959
960BOOST_FIXTURE_TEST_CASE(EnvOverride, WithEnvAndConfig)
961{
962 this->WithEnv::configure("tcp://127.0.0.1:6000");
963 this->WithConfig::configure("unix://some/path");
964
965 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500966 BOOST_CHECK_NO_THROW(face = make_shared<Face>());
967 BOOST_CHECK(dynamic_cast<TcpTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700968}
969
970BOOST_FIXTURE_TEST_CASE(ExplicitTransport, WithEnvAndConfig)
971{
972 this->WithEnv::configure("wrong-uri");
973 this->WithConfig::configure("wrong-transport:");
974
975 auto transport = make_shared<UnixTransport>("unix://some/path");
976 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500977 BOOST_CHECK_NO_THROW(face = make_shared<Face>(transport));
978 BOOST_CHECK(dynamic_cast<UnixTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700979}
980
Junxiao Shiae0b4182016-08-08 22:53:17 +0000981BOOST_AUTO_TEST_SUITE_END() // Transport
982
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700983BOOST_AUTO_TEST_SUITE_END() // TestFace
984
Davide Pesavento47ce2ee2023-05-09 01:33:33 -0400985} // namespace ndn::tests