blob: 78d7c6792217a00be321c781d8b08b2de461229e [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 Pesaventof6b45892023-03-13 15:00:51 -04003 * Copyright (c) 2013-2023 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>
33
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040034namespace ndn::tests {
Junxiao Shia60d9362014-11-12 09:38:21 -070035
Junxiao Shiec475a72019-01-13 21:53:55 +000036struct WantPrefixRegReply;
37struct NoPrefixRegReply;
38
39template<typename PrefixRegReply = WantPrefixRegReply>
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050040class FaceFixture : public IoKeyChainFixture
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040041{
Davide Pesaventod247d492020-01-28 21:30:20 -050042protected:
Junxiao Shiec475a72019-01-13 21:53:55 +000043 FaceFixture()
Davide Pesavento187e9f92023-03-20 22:46:22 -040044 : face(m_io, m_keyChain, {true, !std::is_same_v<PrefixRegReply, NoPrefixRegReply>})
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040045 {
Davide Pesavento187e9f92023-03-20 22:46:22 -040046 static_assert(std::is_same_v<PrefixRegReply, WantPrefixRegReply> ||
Davide Pesaventofffdd622023-08-28 22:50:43 -040047 std::is_same_v<PrefixRegReply, NoPrefixRegReply>);
Junxiao Shiec475a72019-01-13 21:53:55 +000048 }
49
50 /** \brief Execute a prefix registration, and optionally check the name in callback.
51 * \return whether the prefix registration succeeded.
52 */
53 bool
Davide Pesaventoeb87c282023-03-15 21:07:02 -040054 runPrefixReg(std::function<void(const RegisterPrefixSuccessCallback&,
55 const RegisterPrefixFailureCallback&)> f)
Junxiao Shiec475a72019-01-13 21:53:55 +000056 {
57 boost::logic::tribool result = boost::logic::indeterminate;
Davide Pesaventod247d492020-01-28 21:30:20 -050058 f([&] (auto) { result = true; },
59 [&] (auto, auto) { result = false; });
Junxiao Shiec475a72019-01-13 21:53:55 +000060
61 advanceClocks(1_ms);
62 BOOST_REQUIRE(!boost::logic::indeterminate(result));
63 return static_cast<bool>(result);
64 }
65
66 /** \brief Execute a prefix unregistration, and optionally check the name in callback.
67 * \return whether the prefix unregistration succeeded.
68 */
69 bool
Davide Pesaventoeb87c282023-03-15 21:07:02 -040070 runPrefixUnreg(std::function<void(const UnregisterPrefixSuccessCallback&,
71 const UnregisterPrefixFailureCallback&)> f)
Junxiao Shiec475a72019-01-13 21:53:55 +000072 {
73 boost::logic::tribool result = boost::logic::indeterminate;
Davide Pesaventod247d492020-01-28 21:30:20 -050074 f([&] { result = true; },
75 [&] (auto) { result = false; });
Junxiao Shiec475a72019-01-13 21:53:55 +000076
77 advanceClocks(1_ms);
78 BOOST_REQUIRE(!boost::logic::indeterminate(result));
79 return static_cast<bool>(result);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040080 }
81
Davide Pesaventod247d492020-01-28 21:30:20 -050082protected:
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080083 DummyClientFace face;
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040084};
85
Junxiao Shiec475a72019-01-13 21:53:55 +000086BOOST_FIXTURE_TEST_SUITE(TestFace, FaceFixture<>)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040087
Davide Pesaventod247d492020-01-28 21:30:20 -050088BOOST_AUTO_TEST_SUITE(ExpressInterest)
Junxiao Shi103d8ed2016-08-07 20:34:10 +000089
Davide Pesaventod247d492020-01-28 21:30:20 -050090BOOST_AUTO_TEST_CASE(ReplyData)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040091{
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -080092 size_t nData = 0;
Junxiao Shib55e5d32018-07-18 13:32:00 -060093 face.expressInterest(*makeInterest("/Hello/World", true, 50_ms),
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080094 [&] (const Interest& i, const Data& d) {
95 BOOST_CHECK(i.getName().isPrefixOf(d.getName()));
96 BOOST_CHECK_EQUAL(i.getName(), "/Hello/World");
97 ++nData;
98 },
Davide Pesavento2f46d652023-11-09 23:40:01 -050099 [] (auto&&...) { BOOST_FAIL("Unexpected Nack"); },
100 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Eric Newberry83872fd2015-08-06 17:01:24 -0700101
Davide Pesavento0f830802018-01-16 23:58:58 -0500102 advanceClocks(40_ms);
Eric Newberry83872fd2015-08-06 17:01:24 -0700103
Junxiao Shi85d90832016-08-04 03:19:46 +0000104 face.receive(*makeData("/Bye/World/a"));
105 face.receive(*makeData("/Hello/World/a"));
Eric Newberry83872fd2015-08-06 17:01:24 -0700106
Davide Pesavento0f830802018-01-16 23:58:58 -0500107 advanceClocks(50_ms, 2);
Eric Newberry83872fd2015-08-06 17:01:24 -0700108
109 BOOST_CHECK_EQUAL(nData, 1);
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800110 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
111 BOOST_CHECK_EQUAL(face.sentData.size(), 0);
Eric Newberry83872fd2015-08-06 17:01:24 -0700112
113 size_t nTimeouts = 0;
Junxiao Shib55e5d32018-07-18 13:32:00 -0600114 face.expressInterest(*makeInterest("/Hello/World/a/2", false, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500115 [] (auto&&...) {},
116 [] (auto&&...) {},
117 [&] (auto&&...) { ++nTimeouts; });
Davide Pesavento0f830802018-01-16 23:58:58 -0500118 advanceClocks(200_ms, 5);
Eric Newberry83872fd2015-08-06 17:01:24 -0700119 BOOST_CHECK_EQUAL(nTimeouts, 1);
120}
121
Davide Pesaventod247d492020-01-28 21:30:20 -0500122BOOST_AUTO_TEST_CASE(MultipleData)
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800123{
124 size_t nData = 0;
125
Junxiao Shib55e5d32018-07-18 13:32:00 -0600126 face.expressInterest(*makeInterest("/Hello/World", true, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500127 [&] (auto&&...) { ++nData; },
128 [] (auto&&...) { BOOST_FAIL("Unexpected Nack"); },
129 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800130
Junxiao Shib55e5d32018-07-18 13:32:00 -0600131 face.expressInterest(*makeInterest("/Hello/World/a", true, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500132 [&] (auto&&...) { ++nData; },
133 [] (auto&&...) { BOOST_FAIL("Unexpected Nack"); },
134 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800135
Davide Pesavento0f830802018-01-16 23:58:58 -0500136 advanceClocks(40_ms);
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800137
138 face.receive(*makeData("/Hello/World/a/b"));
139
Davide Pesavento0f830802018-01-16 23:58:58 -0500140 advanceClocks(50_ms, 2);
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800141
142 BOOST_CHECK_EQUAL(nData, 2);
143 BOOST_CHECK_EQUAL(face.sentInterests.size(), 2);
144 BOOST_CHECK_EQUAL(face.sentData.size(), 0);
145}
146
Davide Pesaventod247d492020-01-28 21:30:20 -0500147BOOST_AUTO_TEST_CASE(EmptyDataCallback)
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000148{
Junxiao Shib55e5d32018-07-18 13:32:00 -0600149 face.expressInterest(*makeInterest("/Hello/World", true),
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000150 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500151 [] (auto&&...) { BOOST_FAIL("Unexpected Nack"); },
152 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500153 advanceClocks(1_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000154
155 BOOST_CHECK_NO_THROW(do {
156 face.receive(*makeData("/Hello/World/a"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500157 advanceClocks(1_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000158 } while (false));
159}
160
Davide Pesaventod247d492020-01-28 21:30:20 -0500161BOOST_AUTO_TEST_CASE(Timeout)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400162{
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800163 size_t nTimeouts = 0;
Junxiao Shib55e5d32018-07-18 13:32:00 -0600164 face.expressInterest(*makeInterest("/Hello/World", false, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500165 [] (auto&&...) { BOOST_FAIL("Unexpected Data"); },
166 [] (auto&&...) { BOOST_FAIL("Unexpected Nack"); },
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800167 [&nTimeouts] (const Interest& i) {
168 BOOST_CHECK_EQUAL(i.getName(), "/Hello/World");
169 ++nTimeouts;
170 });
Davide Pesavento0f830802018-01-16 23:58:58 -0500171 advanceClocks(200_ms, 5);
Eric Newberry83872fd2015-08-06 17:01:24 -0700172
173 BOOST_CHECK_EQUAL(nTimeouts, 1);
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800174 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
175 BOOST_CHECK_EQUAL(face.sentData.size(), 0);
176 BOOST_CHECK_EQUAL(face.sentNacks.size(), 0);
Eric Newberry83872fd2015-08-06 17:01:24 -0700177}
178
Davide Pesaventod247d492020-01-28 21:30:20 -0500179BOOST_AUTO_TEST_CASE(EmptyTimeoutCallback)
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000180{
Junxiao Shib55e5d32018-07-18 13:32:00 -0600181 face.expressInterest(*makeInterest("/Hello/World", false, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500182 [] (auto&&...) { BOOST_FAIL("Unexpected Data"); },
183 [] (auto&&...) { BOOST_FAIL("Unexpected Nack"); },
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000184 nullptr);
Davide Pesavento0f830802018-01-16 23:58:58 -0500185 advanceClocks(40_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000186
187 BOOST_CHECK_NO_THROW(do {
Davide Pesavento0f830802018-01-16 23:58:58 -0500188 advanceClocks(6_ms, 2);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000189 } while (false));
190}
191
Davide Pesaventod247d492020-01-28 21:30:20 -0500192BOOST_AUTO_TEST_CASE(ReplyNack)
Eric Newberry83872fd2015-08-06 17:01:24 -0700193{
194 size_t nNacks = 0;
195
Junxiao Shib55e5d32018-07-18 13:32:00 -0600196 auto interest = makeInterest("/Hello/World", false, 50_ms);
Junxiao Shib55e5d32018-07-18 13:32:00 -0600197 face.expressInterest(*interest,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500198 [] (auto&&...) { BOOST_FAIL("Unexpected Data"); },
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800199 [&] (const Interest& i, const lp::Nack& n) {
200 BOOST_CHECK(i.getName().isPrefixOf(n.getInterest().getName()));
201 BOOST_CHECK_EQUAL(i.getName(), "/Hello/World");
202 BOOST_CHECK_EQUAL(n.getReason(), lp::NackReason::DUPLICATE);
203 ++nNacks;
204 },
Davide Pesavento2f46d652023-11-09 23:40:01 -0500205 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Eric Newberry83872fd2015-08-06 17:01:24 -0700206
Davide Pesavento0f830802018-01-16 23:58:58 -0500207 advanceClocks(40_ms);
Eric Newberry83872fd2015-08-06 17:01:24 -0700208
Junxiao Shif5b5ae22016-08-08 05:54:41 +0000209 face.receive(makeNack(face.sentInterests.at(0), lp::NackReason::DUPLICATE));
Eric Newberry83872fd2015-08-06 17:01:24 -0700210
Davide Pesavento0f830802018-01-16 23:58:58 -0500211 advanceClocks(50_ms, 2);
Eric Newberry83872fd2015-08-06 17:01:24 -0700212
213 BOOST_CHECK_EQUAL(nNacks, 1);
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800214 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
Eric Newberry83872fd2015-08-06 17:01:24 -0700215}
216
Davide Pesaventod247d492020-01-28 21:30:20 -0500217BOOST_AUTO_TEST_CASE(MultipleNacks)
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800218{
219 size_t nNacks = 0;
220
Junxiao Shib55e5d32018-07-18 13:32:00 -0600221 auto interest = makeInterest("/Hello/World", false, 50_ms, 1);
222 face.expressInterest(*interest,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500223 [] (auto&&...) { BOOST_FAIL("Unexpected Data"); },
Davide Pesaventod247d492020-01-28 21:30:20 -0500224 [&] (const auto&, const auto&) { ++nNacks; },
Davide Pesavento2f46d652023-11-09 23:40:01 -0500225 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800226
Junxiao Shib55e5d32018-07-18 13:32:00 -0600227 interest->setNonce(2);
228 face.expressInterest(*interest,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500229 [] (auto&&...) { BOOST_FAIL("Unexpected Data"); },
Davide Pesaventod247d492020-01-28 21:30:20 -0500230 [&] (const auto&, const auto&) { ++nNacks; },
Davide Pesavento2f46d652023-11-09 23:40:01 -0500231 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800232
Davide Pesavento0f830802018-01-16 23:58:58 -0500233 advanceClocks(40_ms);
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800234
235 face.receive(makeNack(face.sentInterests.at(1), lp::NackReason::DUPLICATE));
236
Davide Pesavento0f830802018-01-16 23:58:58 -0500237 advanceClocks(50_ms, 2);
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800238
239 BOOST_CHECK_EQUAL(nNacks, 2);
240 BOOST_CHECK_EQUAL(face.sentInterests.size(), 2);
241}
242
Davide Pesaventod247d492020-01-28 21:30:20 -0500243BOOST_AUTO_TEST_CASE(EmptyNackCallback)
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000244{
Junxiao Shib55e5d32018-07-18 13:32:00 -0600245 face.expressInterest(*makeInterest("/Hello/World"),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500246 [] (auto&&...) { BOOST_FAIL("Unexpected Data"); },
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000247 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500248 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500249 advanceClocks(1_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000250
251 BOOST_CHECK_NO_THROW(do {
252 face.receive(makeNack(face.sentInterests.at(0), lp::NackReason::DUPLICATE));
Davide Pesavento0f830802018-01-16 23:58:58 -0500253 advanceClocks(1_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000254 } while (false));
255}
256
Davide Pesaventod247d492020-01-28 21:30:20 -0500257BOOST_AUTO_TEST_CASE(PutDataFromDataCallback) // Bug 4596
258{
259 face.expressInterest(*makeInterest("/localhost/notification/1"),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500260 [&] (auto&&...) {
Davide Pesaventod247d492020-01-28 21:30:20 -0500261 face.put(*makeData("/chronosync/sampleDigest/1"));
262 }, nullptr, nullptr);
263 advanceClocks(10_ms);
264 BOOST_CHECK_EQUAL(face.sentInterests.back().getName(), "/localhost/notification/1");
265
266 face.receive(*makeInterest("/chronosync/sampleDigest", true));
267 advanceClocks(10_ms);
268
269 face.put(*makeData("/localhost/notification/1"));
270 advanceClocks(10_ms);
271 BOOST_CHECK_EQUAL(face.sentData.back().getName(), "/chronosync/sampleDigest/1");
272}
273
274BOOST_AUTO_TEST_CASE(DestroyWithPendingInterest)
275{
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500276 auto face2 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500277 face2->expressInterest(*makeInterest("/Hello/World", false, 50_ms),
278 nullptr, nullptr, nullptr);
279 advanceClocks(50_ms, 2);
280 face2.reset();
281
282 advanceClocks(50_ms, 2); // should not crash - Bug 2518
283
284 // avoid "test case [...] did not check any assertions" message from Boost.Test
285 BOOST_CHECK(true);
286}
287
288BOOST_AUTO_TEST_CASE(Handle)
Junxiao Shi80609d42019-01-29 18:15:22 +0000289{
290 auto hdl = face.expressInterest(*makeInterest("/Hello/World", true, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500291 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
292 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
293 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500294 advanceClocks(1_ms);
Junxiao Shi80609d42019-01-29 18:15:22 +0000295 hdl.cancel();
Davide Pesaventod247d492020-01-28 21:30:20 -0500296 advanceClocks(1_ms);
Junxiao Shi80609d42019-01-29 18:15:22 +0000297 face.receive(*makeData("/Hello/World/%21"));
298 advanceClocks(200_ms, 5);
299
Davide Pesaventod247d492020-01-28 21:30:20 -0500300 // cancel after destructing face
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500301 auto face2 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500302 auto hdl2 = face2->expressInterest(*makeInterest("/Hello/World", true, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500303 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
304 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
305 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500306 advanceClocks(1_ms);
307 face2.reset();
308 advanceClocks(1_ms);
309 hdl2.cancel(); // should not crash
310 advanceClocks(1_ms);
311
Junxiao Shi80609d42019-01-29 18:15:22 +0000312 // avoid "test case [...] did not check any assertions" message from Boost.Test
313 BOOST_CHECK(true);
314}
315
Davide Pesaventod247d492020-01-28 21:30:20 -0500316BOOST_AUTO_TEST_SUITE_END() // ExpressInterest
317
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000318BOOST_AUTO_TEST_CASE(RemoveAllPendingInterests)
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500319{
Junxiao Shib55e5d32018-07-18 13:32:00 -0600320 face.expressInterest(*makeInterest("/Hello/World/0", false, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500321 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
322 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
323 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500324
Junxiao Shib55e5d32018-07-18 13:32:00 -0600325 face.expressInterest(*makeInterest("/Hello/World/1", false, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500326 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
327 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
328 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500329
Davide Pesavento0f830802018-01-16 23:58:58 -0500330 advanceClocks(10_ms);
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500331
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800332 face.removeAllPendingInterests();
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 BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0);
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500336
Junxiao Shi85d90832016-08-04 03:19:46 +0000337 face.receive(*makeData("/Hello/World/0"));
338 face.receive(*makeData("/Hello/World/1"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500339 advanceClocks(200_ms, 5);
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500340}
341
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000342BOOST_AUTO_TEST_SUITE(Producer)
343
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000344BOOST_AUTO_TEST_CASE(PutData)
345{
346 BOOST_CHECK_EQUAL(face.sentData.size(), 0);
347
348 Data data("/4g7xxcuEow/KFvK5Kf2m");
349 signData(data);
350 face.put(data);
351
352 lp::CachePolicy cachePolicy;
353 cachePolicy.setPolicy(lp::CachePolicyType::NO_CACHE);
354 data.setTag(make_shared<lp::CachePolicyTag>(cachePolicy));
Eric Newberry4d261b62016-11-10 13:40:09 -0700355 data.setTag(make_shared<lp::CongestionMarkTag>(1));
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000356 face.put(data);
357
Davide Pesavento0f830802018-01-16 23:58:58 -0500358 advanceClocks(10_ms);
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000359 BOOST_REQUIRE_EQUAL(face.sentData.size(), 2);
360 BOOST_CHECK(face.sentData[0].getTag<lp::CachePolicyTag>() == nullptr);
Eric Newberry4d261b62016-11-10 13:40:09 -0700361 BOOST_CHECK(face.sentData[0].getTag<lp::CongestionMarkTag>() == nullptr);
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000362 BOOST_CHECK(face.sentData[1].getTag<lp::CachePolicyTag>() != nullptr);
Eric Newberry4d261b62016-11-10 13:40:09 -0700363 BOOST_CHECK(face.sentData[1].getTag<lp::CongestionMarkTag>() != nullptr);
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000364}
365
Junxiao Shib6828912017-11-20 14:06:32 +0000366BOOST_AUTO_TEST_CASE(PutDataLoopback)
367{
368 bool hasInterest1 = false, hasData = false;
369
370 // first InterestFilter allows loopback and should receive Interest
Davide Pesavento2f46d652023-11-09 23:40:01 -0500371 face.setInterestFilter("/", [&] (auto&&...) {
Junxiao Shib6828912017-11-20 14:06:32 +0000372 hasInterest1 = true;
373 // do not respond with Data right away, so Face must send Interest to forwarder
374 });
Davide Pesavento2f46d652023-11-09 23:40:01 -0500375
Junxiao Shib6828912017-11-20 14:06:32 +0000376 // second InterestFilter disallows loopback and should not receive Interest
377 face.setInterestFilter(InterestFilter("/").allowLoopback(false),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500378 [] (auto&&...) { BOOST_ERROR("Unexpected Interest on second InterestFilter"); });
Junxiao Shib6828912017-11-20 14:06:32 +0000379
Junxiao Shib55e5d32018-07-18 13:32:00 -0600380 face.expressInterest(*makeInterest("/A", true),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500381 [&] (auto&&...) { hasData = true; },
382 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
383 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500384 advanceClocks(1_ms);
Junxiao Shib6828912017-11-20 14:06:32 +0000385 BOOST_CHECK_EQUAL(hasInterest1, true); // Interest looped back
386 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); // Interest sent to forwarder
387 BOOST_CHECK_EQUAL(hasData, false); // waiting for Data
388
389 face.put(*makeData("/A/B")); // first InterestFilter responds with Data
Davide Pesavento0f830802018-01-16 23:58:58 -0500390 advanceClocks(1_ms);
Junxiao Shib6828912017-11-20 14:06:32 +0000391 BOOST_CHECK_EQUAL(hasData, true);
392 BOOST_CHECK_EQUAL(face.sentData.size(), 0); // do not spill Data to forwarder
393}
394
Junxiao Shi859888f2017-09-12 14:29:16 +0000395BOOST_AUTO_TEST_CASE(PutMultipleData)
396{
397 bool hasInterest1 = false;
398 // register two Interest destinations
Davide Pesavento2f46d652023-11-09 23:40:01 -0500399 face.setInterestFilter("/", [&] (auto&&...) {
Junxiao Shi859888f2017-09-12 14:29:16 +0000400 hasInterest1 = true;
401 // sending Data right away from the first destination, don't care whether Interest goes to second destination
402 face.put(*makeData("/A/B"));
Davide Pesavento2f46d652023-11-09 23:40:01 -0500403 });
404 face.setInterestFilter("/", [] (auto&&...) {});
Davide Pesavento0f830802018-01-16 23:58:58 -0500405 advanceClocks(10_ms);
Junxiao Shi859888f2017-09-12 14:29:16 +0000406
Junxiao Shib55e5d32018-07-18 13:32:00 -0600407 face.receive(*makeInterest("/A", true));
Davide Pesavento0f830802018-01-16 23:58:58 -0500408 advanceClocks(10_ms);
Junxiao Shi859888f2017-09-12 14:29:16 +0000409 BOOST_CHECK(hasInterest1);
410 BOOST_CHECK_EQUAL(face.sentData.size(), 1);
411 BOOST_CHECK_EQUAL(face.sentData.at(0).getName(), "/A/B");
412
413 face.put(*makeData("/A/C"));
414 BOOST_CHECK_EQUAL(face.sentData.size(), 1); // additional Data are ignored
415}
416
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000417BOOST_AUTO_TEST_CASE(PutNack)
418{
Davide Pesavento2f46d652023-11-09 23:40:01 -0500419 // register one Interest destination so that face can accept Nacks
420 face.setInterestFilter("/", [] (auto&&...) {});
Davide Pesavento0f830802018-01-16 23:58:58 -0500421 advanceClocks(10_ms);
Junxiao Shi79a7a162017-09-09 08:33:57 +0000422
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000423 BOOST_CHECK_EQUAL(face.sentNacks.size(), 0);
424
Davide Pesaventof6b45892023-03-13 15:00:51 -0400425 face.put(makeNack(*makeInterest("/unsolicited", false, std::nullopt, 18645250),
Junxiao Shib55e5d32018-07-18 13:32:00 -0600426 lp::NackReason::NO_ROUTE));
Davide Pesavento0f830802018-01-16 23:58:58 -0500427 advanceClocks(10_ms);
Junxiao Shi1ad0b4b2017-08-18 14:19:14 +0000428 BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); // unsolicited Nack would not be sent
Eric Newberry4d261b62016-11-10 13:40:09 -0700429
Davide Pesaventof6b45892023-03-13 15:00:51 -0400430 auto interest1 = makeInterest("/Hello/World", false, std::nullopt, 14247162);
Junxiao Shib55e5d32018-07-18 13:32:00 -0600431 face.receive(*interest1);
Davide Pesaventof6b45892023-03-13 15:00:51 -0400432 auto interest2 = makeInterest("/another/prefix", false, std::nullopt, 92203002);
Junxiao Shib55e5d32018-07-18 13:32:00 -0600433 face.receive(*interest2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500434 advanceClocks(10_ms);
Junxiao Shi1ad0b4b2017-08-18 14:19:14 +0000435
Junxiao Shib55e5d32018-07-18 13:32:00 -0600436 face.put(makeNack(*interest1, lp::NackReason::DUPLICATE));
Davide Pesavento0f830802018-01-16 23:58:58 -0500437 advanceClocks(10_ms);
Junxiao Shi1ad0b4b2017-08-18 14:19:14 +0000438 BOOST_REQUIRE_EQUAL(face.sentNacks.size(), 1);
439 BOOST_CHECK_EQUAL(face.sentNacks[0].getReason(), lp::NackReason::DUPLICATE);
440 BOOST_CHECK(face.sentNacks[0].getTag<lp::CongestionMarkTag>() == nullptr);
441
Junxiao Shib55e5d32018-07-18 13:32:00 -0600442 auto nack = makeNack(*interest2, lp::NackReason::NO_ROUTE);
Eric Newberry4d261b62016-11-10 13:40:09 -0700443 nack.setTag(make_shared<lp::CongestionMarkTag>(1));
444 face.put(nack);
Davide Pesavento0f830802018-01-16 23:58:58 -0500445 advanceClocks(10_ms);
Eric Newberry4d261b62016-11-10 13:40:09 -0700446 BOOST_REQUIRE_EQUAL(face.sentNacks.size(), 2);
Junxiao Shi1ad0b4b2017-08-18 14:19:14 +0000447 BOOST_CHECK_EQUAL(face.sentNacks[1].getReason(), lp::NackReason::NO_ROUTE);
Eric Newberry4d261b62016-11-10 13:40:09 -0700448 BOOST_CHECK(face.sentNacks[1].getTag<lp::CongestionMarkTag>() != nullptr);
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000449}
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500450
Junxiao Shi79a7a162017-09-09 08:33:57 +0000451BOOST_AUTO_TEST_CASE(PutMultipleNack)
452{
Junxiao Shi859888f2017-09-12 14:29:16 +0000453 bool hasInterest1 = false, hasInterest2 = false;
454 // register two Interest destinations
455 face.setInterestFilter("/", [&] (const InterestFilter&, const Interest& interest) {
456 hasInterest1 = true;
457 // sending Nack right away from the first destination, Interest should still go to second destination
458 face.put(makeNack(interest, lp::NackReason::CONGESTION));
459 });
Davide Pesavento2f46d652023-11-09 23:40:01 -0500460 face.setInterestFilter("/", [&] (auto&&...) { hasInterest2 = true; });
Davide Pesavento0f830802018-01-16 23:58:58 -0500461 advanceClocks(10_ms);
Junxiao Shi79a7a162017-09-09 08:33:57 +0000462
Davide Pesaventof6b45892023-03-13 15:00:51 -0400463 auto interest = makeInterest("/A", false, std::nullopt, 14333271);
Junxiao Shib55e5d32018-07-18 13:32:00 -0600464 face.receive(*interest);
Davide Pesavento0f830802018-01-16 23:58:58 -0500465 advanceClocks(10_ms);
Junxiao Shi859888f2017-09-12 14:29:16 +0000466 BOOST_CHECK(hasInterest1);
467 BOOST_CHECK(hasInterest2);
Junxiao Shi79a7a162017-09-09 08:33:57 +0000468
Junxiao Shi859888f2017-09-12 14:29:16 +0000469 // Nack from first destination is received, should wait for a response from the other destination
470 BOOST_CHECK_EQUAL(face.sentNacks.size(), 0);
Junxiao Shi79a7a162017-09-09 08:33:57 +0000471
Junxiao Shib55e5d32018-07-18 13:32:00 -0600472 face.put(makeNack(*interest, lp::NackReason::NO_ROUTE)); // Nack from second destination
Davide Pesavento0f830802018-01-16 23:58:58 -0500473 advanceClocks(10_ms);
Junxiao Shi859888f2017-09-12 14:29:16 +0000474 BOOST_CHECK_EQUAL(face.sentNacks.size(), 1); // sending Nack after both destinations Nacked
Junxiao Shi79a7a162017-09-09 08:33:57 +0000475 BOOST_CHECK_EQUAL(face.sentNacks.at(0).getReason(), lp::NackReason::CONGESTION); // least severe reason
476
Junxiao Shib55e5d32018-07-18 13:32:00 -0600477 face.put(makeNack(*interest, lp::NackReason::DUPLICATE));
Junxiao Shi79a7a162017-09-09 08:33:57 +0000478 BOOST_CHECK_EQUAL(face.sentNacks.size(), 1); // additional Nacks are ignored
479}
480
Junxiao Shib6828912017-11-20 14:06:32 +0000481BOOST_AUTO_TEST_CASE(PutMultipleNackLoopback)
482{
483 bool hasInterest1 = false, hasNack = false;
484
485 // first InterestFilter allows loopback and should receive Interest
486 face.setInterestFilter("/", [&] (const InterestFilter&, const Interest& interest) {
487 hasInterest1 = true;
488 face.put(makeNack(interest, lp::NackReason::CONGESTION));
489 });
Davide Pesavento2f46d652023-11-09 23:40:01 -0500490
Junxiao Shib6828912017-11-20 14:06:32 +0000491 // second InterestFilter disallows loopback and should not receive Interest
492 face.setInterestFilter(InterestFilter("/").allowLoopback(false),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500493 [] (auto&&...) { BOOST_ERROR("Unexpected Interest on second InterestFilter"); });
Junxiao Shib6828912017-11-20 14:06:32 +0000494
Davide Pesaventof6b45892023-03-13 15:00:51 -0400495 auto interest = makeInterest("/A", false, std::nullopt, 28395852);
Junxiao Shib55e5d32018-07-18 13:32:00 -0600496 face.expressInterest(*interest,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500497 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
Junxiao Shib6828912017-11-20 14:06:32 +0000498 [&] (const Interest&, const lp::Nack& nack) {
499 hasNack = true;
500 BOOST_CHECK_EQUAL(nack.getReason(), lp::NackReason::CONGESTION);
501 },
Davide Pesavento2f46d652023-11-09 23:40:01 -0500502 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500503 advanceClocks(1_ms);
Junxiao Shib6828912017-11-20 14:06:32 +0000504 BOOST_CHECK_EQUAL(hasInterest1, true); // Interest looped back
505 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); // Interest sent to forwarder
506 BOOST_CHECK_EQUAL(hasNack, false); // waiting for Nack from forwarder
507
Junxiao Shib55e5d32018-07-18 13:32:00 -0600508 face.receive(makeNack(*interest, lp::NackReason::NO_ROUTE));
Davide Pesavento0f830802018-01-16 23:58:58 -0500509 advanceClocks(1_ms);
Junxiao Shib6828912017-11-20 14:06:32 +0000510 BOOST_CHECK_EQUAL(hasNack, true);
511}
512
Davide Pesaventod247d492020-01-28 21:30:20 -0500513BOOST_AUTO_TEST_SUITE_END() // Producer
514
515BOOST_AUTO_TEST_SUITE(RegisterPrefix)
516
517BOOST_FIXTURE_TEST_CASE(Failure, FaceFixture<NoPrefixRegReply>)
518{
519 BOOST_CHECK(!runPrefixReg([&] (const auto& success, const auto& failure) {
520 face.registerPrefix("/Hello/World", success, failure);
521 this->advanceClocks(5_s, 20); // wait for command timeout
522 }));
523}
524
525BOOST_AUTO_TEST_CASE(Handle)
526{
527 RegisteredPrefixHandle hdl;
528 auto doReg = [&] {
529 return runPrefixReg([&] (const auto& success, const auto& failure) {
530 hdl = face.registerPrefix("/Hello/World", success, failure);
531 });
532 };
533 auto doUnreg = [&] {
534 return runPrefixUnreg([&] (const auto& success, const auto& failure) {
535 hdl.unregister(success, failure);
536 });
537 };
538
539 // despite the "undefined behavior" warning, we try not to crash, but no API guarantee for this
540 BOOST_CHECK(!doUnreg());
541
542 // cancel after unregister
543 BOOST_CHECK(doReg());
544 BOOST_CHECK(doUnreg());
545 hdl.cancel();
546 advanceClocks(1_ms);
547
548 // unregister after cancel
549 BOOST_CHECK(doReg());
550 hdl.cancel();
551 advanceClocks(1_ms);
552 BOOST_CHECK(!doUnreg());
553
554 // cancel after destructing face
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500555 auto face2 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500556 hdl = face2->registerPrefix("/Hello/World/2", nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500557 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500558 advanceClocks(1_ms);
559 face2.reset();
560 advanceClocks(1_ms);
561 hdl.cancel(); // should not crash
562 advanceClocks(1_ms);
563
564 // unregister after destructing face
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500565 auto face3 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500566 hdl = face3->registerPrefix("/Hello/World/3", nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500567 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500568 advanceClocks(1_ms);
569 face3.reset();
570 advanceClocks(1_ms);
571 BOOST_CHECK(!doUnreg());
572}
573
574BOOST_AUTO_TEST_SUITE_END() // RegisterPrefix
575
576BOOST_AUTO_TEST_SUITE(SetInterestFilter)
577
578BOOST_AUTO_TEST_CASE(SetAndCancel)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400579{
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800580 size_t nInterests = 0;
581 size_t nRegs = 0;
Davide Pesavento720e25c2019-07-14 01:33:52 -0400582 auto hdl = face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500583 [&] (auto&&...) { ++nInterests; },
584 [&] (auto&&...) { ++nRegs; },
585 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500586 advanceClocks(25_ms, 4);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800587 BOOST_CHECK_EQUAL(nRegs, 1);
588 BOOST_CHECK_EQUAL(nInterests, 0);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400589
Junxiao Shib55e5d32018-07-18 13:32:00 -0600590 face.receive(*makeInterest("/Hello/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500591 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400592
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800593 BOOST_CHECK_EQUAL(nRegs, 1);
594 BOOST_CHECK_EQUAL(nInterests, 1);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400595
Junxiao Shib55e5d32018-07-18 13:32:00 -0600596 face.receive(*makeInterest("/Bye/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500597 advanceClocks(10000_ms, 10);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800598 BOOST_CHECK_EQUAL(nInterests, 1);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400599
Junxiao Shib55e5d32018-07-18 13:32:00 -0600600 face.receive(*makeInterest("/Hello/World/%21/2"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500601 advanceClocks(25_ms, 4);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800602 BOOST_CHECK_EQUAL(nInterests, 2);
603
604 // removing filter
Davide Pesavento720e25c2019-07-14 01:33:52 -0400605 hdl.cancel();
Davide Pesavento0f830802018-01-16 23:58:58 -0500606 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400607
Junxiao Shib55e5d32018-07-18 13:32:00 -0600608 face.receive(*makeInterest("/Hello/World/%21/3"));
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800609 BOOST_CHECK_EQUAL(nInterests, 2);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800610}
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400611
Davide Pesaventod247d492020-01-28 21:30:20 -0500612BOOST_AUTO_TEST_CASE(EmptyInterestCallback)
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000613{
614 face.setInterestFilter("/A", nullptr);
Davide Pesavento0f830802018-01-16 23:58:58 -0500615 advanceClocks(1_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000616
617 BOOST_CHECK_NO_THROW(do {
618 face.receive(*makeInterest("/A/1"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500619 advanceClocks(1_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000620 } while (false));
621}
622
Davide Pesaventod247d492020-01-28 21:30:20 -0500623BOOST_AUTO_TEST_CASE(WithoutSuccessCallback)
Joao Pereira0b3cac52015-07-02 14:49:49 -0400624{
625 size_t nInterests = 0;
Davide Pesavento720e25c2019-07-14 01:33:52 -0400626 auto hdl = face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500627 [&] (auto&&...) { ++nInterests; },
628 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500629 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400630 BOOST_CHECK_EQUAL(nInterests, 0);
631
Junxiao Shib55e5d32018-07-18 13:32:00 -0600632 face.receive(*makeInterest("/Hello/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500633 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400634
635 BOOST_CHECK_EQUAL(nInterests, 1);
636
Junxiao Shib55e5d32018-07-18 13:32:00 -0600637 face.receive(*makeInterest("/Bye/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500638 advanceClocks(10000_ms, 10);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400639 BOOST_CHECK_EQUAL(nInterests, 1);
640
Junxiao Shib55e5d32018-07-18 13:32:00 -0600641 face.receive(*makeInterest("/Hello/World/%21/2"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500642 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400643 BOOST_CHECK_EQUAL(nInterests, 2);
644
645 // removing filter
Davide Pesavento720e25c2019-07-14 01:33:52 -0400646 hdl.cancel();
Davide Pesavento0f830802018-01-16 23:58:58 -0500647 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400648
Junxiao Shib55e5d32018-07-18 13:32:00 -0600649 face.receive(*makeInterest("/Hello/World/%21/3"));
Joao Pereira0b3cac52015-07-02 14:49:49 -0400650 BOOST_CHECK_EQUAL(nInterests, 2);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400651}
652
Davide Pesaventod247d492020-01-28 21:30:20 -0500653BOOST_FIXTURE_TEST_CASE(Failure, FaceFixture<NoPrefixRegReply>)
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800654{
655 // don't enable registration reply
656 size_t nRegFailed = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800657 face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500658 [] (auto&&...) { BOOST_FAIL("Unexpected Interest"); },
659 [] (auto&&...) { BOOST_FAIL("Unexpected success"); },
660 [&] (auto&&...) { ++nRegFailed; });
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800661
Davide Pesavento0f830802018-01-16 23:58:58 -0500662 advanceClocks(25_ms, 4);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800663 BOOST_CHECK_EQUAL(nRegFailed, 0);
664
Davide Pesavento0f830802018-01-16 23:58:58 -0500665 advanceClocks(2000_ms, 5);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800666 BOOST_CHECK_EQUAL(nRegFailed, 1);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400667}
668
Davide Pesaventod247d492020-01-28 21:30:20 -0500669BOOST_FIXTURE_TEST_CASE(FailureWithoutSuccessCallback, FaceFixture<NoPrefixRegReply>)
Joao Pereira0b3cac52015-07-02 14:49:49 -0400670{
671 // don't enable registration reply
672 size_t nRegFailed = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800673 face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500674 [] (auto&&...) { BOOST_FAIL("Unexpected Interest"); },
675 [&] (auto&&...) { ++nRegFailed; });
Joao Pereira0b3cac52015-07-02 14:49:49 -0400676
Davide Pesavento0f830802018-01-16 23:58:58 -0500677 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400678 BOOST_CHECK_EQUAL(nRegFailed, 0);
679
Davide Pesavento0f830802018-01-16 23:58:58 -0500680 advanceClocks(2000_ms, 5);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400681 BOOST_CHECK_EQUAL(nRegFailed, 1);
682}
683
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800684BOOST_AUTO_TEST_CASE(SimilarFilters)
685{
686 size_t nInInterests1 = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800687 face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500688 [&nInInterests1] (auto&&...) { ++nInInterests1; },
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000689 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500690 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800691
692 size_t nInInterests2 = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800693 face.setInterestFilter("/Hello",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500694 [&nInInterests2] (auto&&...) { ++nInInterests2; },
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000695 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500696 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400697
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800698 size_t nInInterests3 = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800699 face.setInterestFilter("/Los/Angeles/Lakers",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500700 [&nInInterests3] (auto&&...) { ++nInInterests3; },
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000701 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500702 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400703
Davide Pesavento0f830802018-01-16 23:58:58 -0500704 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400705
Junxiao Shib55e5d32018-07-18 13:32:00 -0600706 face.receive(*makeInterest("/Hello/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500707 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400708
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800709 BOOST_CHECK_EQUAL(nInInterests1, 1);
710 BOOST_CHECK_EQUAL(nInInterests2, 1);
711 BOOST_CHECK_EQUAL(nInInterests3, 0);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400712}
713
Davide Pesaventod247d492020-01-28 21:30:20 -0500714BOOST_AUTO_TEST_CASE(RegexFilter)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400715{
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800716 size_t nInInterests = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800717 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500718 [&nInInterests] (auto&&...) { ++nInInterests; },
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000719 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500720 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400721
Davide Pesavento0f830802018-01-16 23:58:58 -0500722 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400723
Junxiao Shib55e5d32018-07-18 13:32:00 -0600724 face.receive(*makeInterest("/Hello/World/a")); // shouldn't match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400725 BOOST_CHECK_EQUAL(nInInterests, 0);
726
Junxiao Shib55e5d32018-07-18 13:32:00 -0600727 face.receive(*makeInterest("/Hello/World/a/b")); // should match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400728 BOOST_CHECK_EQUAL(nInInterests, 1);
729
Junxiao Shib55e5d32018-07-18 13:32:00 -0600730 face.receive(*makeInterest("/Hello/World/a/b/c")); // should match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400731 BOOST_CHECK_EQUAL(nInInterests, 2);
732
Junxiao Shib55e5d32018-07-18 13:32:00 -0600733 face.receive(*makeInterest("/Hello/World/a/b/d")); // should not match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400734 BOOST_CHECK_EQUAL(nInInterests, 2);
735}
736
Davide Pesaventod247d492020-01-28 21:30:20 -0500737BOOST_AUTO_TEST_CASE(RegexFilterError)
738{
739 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500740 // Do NOT use 'auto' for this lambda. This is testing the (failure of)
741 // implicit conversion from InterestFilter to Name, therefore the type
742 // of the first parameter must be explicit.
Davide Pesaventod247d492020-01-28 21:30:20 -0500743 [] (const Name&, const Interest&) {
Davide Pesavento2f46d652023-11-09 23:40:01 -0500744 BOOST_FAIL("InterestFilter::Error should have been raised");
Davide Pesaventod247d492020-01-28 21:30:20 -0500745 },
746 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500747 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500748
749 advanceClocks(25_ms, 4);
750
751 BOOST_CHECK_THROW(face.receive(*makeInterest("/Hello/World/XXX/b/c")), InterestFilter::Error);
752}
753
754BOOST_AUTO_TEST_CASE(RegexFilterAndRegisterPrefix)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400755{
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800756 size_t nInInterests = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800757 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500758 [&] (auto&&...) { ++nInInterests; });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400759
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800760 size_t nRegSuccesses = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800761 face.registerPrefix("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500762 [&] (auto&&...) { ++nRegSuccesses; },
763 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400764
Davide Pesavento0f830802018-01-16 23:58:58 -0500765 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400766 BOOST_CHECK_EQUAL(nRegSuccesses, 1);
767
Junxiao Shib55e5d32018-07-18 13:32:00 -0600768 face.receive(*makeInterest("/Hello/World/a")); // shouldn't match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400769 BOOST_CHECK_EQUAL(nInInterests, 0);
770
Junxiao Shib55e5d32018-07-18 13:32:00 -0600771 face.receive(*makeInterest("/Hello/World/a/b")); // should match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400772 BOOST_CHECK_EQUAL(nInInterests, 1);
773
Junxiao Shib55e5d32018-07-18 13:32:00 -0600774 face.receive(*makeInterest("/Hello/World/a/b/c")); // should match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400775 BOOST_CHECK_EQUAL(nInInterests, 2);
776
Junxiao Shib55e5d32018-07-18 13:32:00 -0600777 face.receive(*makeInterest("/Hello/World/a/b/d")); // should not match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400778 BOOST_CHECK_EQUAL(nInInterests, 2);
779}
780
Davide Pesaventod247d492020-01-28 21:30:20 -0500781BOOST_FIXTURE_TEST_CASE(WithoutRegisterPrefix, FaceFixture<NoPrefixRegReply>) // Bug 2318
Junxiao Shia1ea5062014-12-27 22:33:39 -0700782{
783 // This behavior is specific to DummyClientFace.
784 // Regular Face won't accept incoming packets until something is sent.
785
786 int hit = 0;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500787 face.setInterestFilter(Name("/"), [&hit] (auto&&...) { ++hit; });
788 face.processEvents(-1_ms);
Junxiao Shia1ea5062014-12-27 22:33:39 -0700789
Junxiao Shib55e5d32018-07-18 13:32:00 -0600790 face.receive(*makeInterest("/A"));
Davide Pesavento2f46d652023-11-09 23:40:01 -0500791 face.processEvents(-1_ms);
Junxiao Shia1ea5062014-12-27 22:33:39 -0700792
793 BOOST_CHECK_EQUAL(hit, 1);
794}
795
Davide Pesaventod247d492020-01-28 21:30:20 -0500796BOOST_AUTO_TEST_CASE(Handle)
Junxiao Shi60aaef02019-01-14 04:59:30 +0000797{
798 int hit = 0;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500799 InterestFilterHandle hdl = face.setInterestFilter(Name("/"), [&hit] (auto&&...) { ++hit; });
Junxiao Shi60aaef02019-01-14 04:59:30 +0000800 face.processEvents(-1_ms);
801
802 face.receive(*makeInterest("/A"));
803 face.processEvents(-1_ms);
804 BOOST_CHECK_EQUAL(hit, 1);
805
806 hdl.cancel();
807 face.processEvents(-1_ms);
808
809 face.receive(*makeInterest("/B"));
810 face.processEvents(-1_ms);
811 BOOST_CHECK_EQUAL(hit, 1);
Davide Pesaventod247d492020-01-28 21:30:20 -0500812
813 // cancel after destructing face
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500814 auto face2 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500815 InterestFilterHandle hdl2 = face2->setInterestFilter("/Hello/World/2", nullptr);
816 advanceClocks(1_ms);
817 face2.reset();
818 advanceClocks(1_ms);
819 hdl2.cancel(); // should not crash
820 advanceClocks(1_ms);
Junxiao Shi60aaef02019-01-14 04:59:30 +0000821}
822
Davide Pesaventod247d492020-01-28 21:30:20 -0500823BOOST_AUTO_TEST_SUITE_END() // SetInterestFilter
Junxiao Shiae0b4182016-08-08 22:53:17 +0000824
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500825BOOST_AUTO_TEST_CASE(ProcessEvents)
826{
Davide Pesavento2f46d652023-11-09 23:40:01 -0500827 face.processEvents(-1_ms); // io_context::restart()/poll() inside
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500828
Davide Pesavento2f46d652023-11-09 23:40:01 -0500829 int nRegSuccesses = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800830 face.registerPrefix("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500831 [&] (auto&&...) { ++nRegSuccesses; },
832 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500833
Davide Pesavento2f46d652023-11-09 23:40:01 -0500834 // io_context::poll() without reset
835 face.getIoContext().poll();
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500836 BOOST_CHECK_EQUAL(nRegSuccesses, 0);
837
Davide Pesavento2f46d652023-11-09 23:40:01 -0500838 face.processEvents(-1_ms); // io_context::restart()/poll() inside
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500839 BOOST_CHECK_EQUAL(nRegSuccesses, 1);
840}
841
Junxiao Shiae0b4182016-08-08 22:53:17 +0000842BOOST_AUTO_TEST_CASE(DestroyWithoutProcessEvents) // Bug 3248
843{
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500844 auto face2 = make_unique<Face>(m_io);
Junxiao Shiae0b4182016-08-08 22:53:17 +0000845 face2.reset();
846
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500847 m_io.poll(); // should not crash
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100848
849 // avoid "test case [...] did not check any assertions" message from Boost.Test
850 BOOST_CHECK(true);
Junxiao Shiae0b4182016-08-08 22:53:17 +0000851}
852
Junxiao Shiae0b4182016-08-08 22:53:17 +0000853BOOST_AUTO_TEST_SUITE(Transport)
854
855using ndn::Transport;
856
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500857BOOST_FIXTURE_TEST_CASE(FaceTransport, IoKeyChainFixture)
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800858{
Davide Pesavento2f46d652023-11-09 23:40:01 -0500859 BOOST_CHECK_NO_THROW(Face(shared_ptr<Transport>()));
860 BOOST_CHECK_NO_THROW(Face(shared_ptr<Transport>(), m_io));
861 BOOST_CHECK_NO_THROW(Face(shared_ptr<Transport>(), m_io, m_keyChain));
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800862
863 auto transport = make_shared<TcpTransport>("localhost", "6363"); // no real io operations will be scheduled
Davide Pesavento2f46d652023-11-09 23:40:01 -0500864 BOOST_CHECK(&Face(transport).getTransport() == transport.get());
865 BOOST_CHECK(&Face(transport, m_io).getTransport() == transport.get());
866 BOOST_CHECK(&Face(transport, m_io, m_keyChain).getTransport() == transport.get());
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800867}
868
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500869class WithEnv
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700870{
871public:
872 WithEnv()
873 {
874 if (getenv("NDN_CLIENT_TRANSPORT") != nullptr) {
875 m_oldTransport = getenv("NDN_CLIENT_TRANSPORT");
876 unsetenv("NDN_CLIENT_TRANSPORT");
877 }
878 }
879
880 void
881 configure(const std::string& faceUri)
882 {
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500883 setenv("NDN_CLIENT_TRANSPORT", faceUri.data(), true);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700884 }
885
886 ~WithEnv()
887 {
888 if (!m_oldTransport.empty()) {
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500889 setenv("NDN_CLIENT_TRANSPORT", m_oldTransport.data(), true);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700890 }
891 else {
892 unsetenv("NDN_CLIENT_TRANSPORT");
893 }
894 }
895
896private:
897 std::string m_oldTransport;
898};
899
900class WithConfig : private TestHomeFixture<DefaultPibDir>
901{
902public:
903 void
904 configure(const std::string& faceUri)
905 {
906 createClientConf({"transport=" + faceUri});
907 }
908};
909
910class WithEnvAndConfig : public WithEnv, public WithConfig
911{
912};
913
Davide Pesavento47ce2ee2023-05-09 01:33:33 -0400914using ConfigOptions = boost::mpl::vector<WithEnv, WithConfig>;
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700915
916BOOST_FIXTURE_TEST_CASE(NoConfig, WithEnvAndConfig) // fixture configures test HOME and PIB/TPM path
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700917{
918 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500919 BOOST_CHECK_NO_THROW(face = make_shared<Face>());
920 BOOST_CHECK(dynamic_cast<UnixTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700921}
922
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700923BOOST_FIXTURE_TEST_CASE_TEMPLATE(Unix, T, ConfigOptions, T)
924{
925 this->configure("unix://some/path");
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700926
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700927 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500928 BOOST_CHECK_NO_THROW(face = make_shared<Face>());
929 BOOST_CHECK(dynamic_cast<UnixTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700930}
931
932BOOST_FIXTURE_TEST_CASE_TEMPLATE(Tcp, T, ConfigOptions, T)
933{
934 this->configure("tcp://127.0.0.1:6000");
935
936 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500937 BOOST_CHECK_NO_THROW(face = make_shared<Face>());
938 BOOST_CHECK(dynamic_cast<TcpTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700939}
940
941BOOST_FIXTURE_TEST_CASE_TEMPLATE(WrongTransport, T, ConfigOptions, T)
942{
943 this->configure("wrong-transport:");
944
945 BOOST_CHECK_THROW(make_shared<Face>(), ConfigFile::Error);
946}
947
948BOOST_FIXTURE_TEST_CASE_TEMPLATE(WrongUri, T, ConfigOptions, T)
949{
950 this->configure("wrong-uri");
951
952 BOOST_CHECK_THROW(make_shared<Face>(), ConfigFile::Error);
953}
954
955BOOST_FIXTURE_TEST_CASE(EnvOverride, WithEnvAndConfig)
956{
957 this->WithEnv::configure("tcp://127.0.0.1:6000");
958 this->WithConfig::configure("unix://some/path");
959
960 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500961 BOOST_CHECK_NO_THROW(face = make_shared<Face>());
962 BOOST_CHECK(dynamic_cast<TcpTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700963}
964
965BOOST_FIXTURE_TEST_CASE(ExplicitTransport, WithEnvAndConfig)
966{
967 this->WithEnv::configure("wrong-uri");
968 this->WithConfig::configure("wrong-transport:");
969
970 auto transport = make_shared<UnixTransport>("unix://some/path");
971 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500972 BOOST_CHECK_NO_THROW(face = make_shared<Face>(transport));
973 BOOST_CHECK(dynamic_cast<UnixTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700974}
975
Junxiao Shiae0b4182016-08-08 22:53:17 +0000976BOOST_AUTO_TEST_SUITE_END() // Transport
977
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700978BOOST_AUTO_TEST_SUITE_END() // TestFace
979
Davide Pesavento47ce2ee2023-05-09 01:33:33 -0400980} // namespace ndn::tests