blob: 55d824537477f1d12ecedde091906b70bf40b65d [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>
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 Pesaventod247d492020-01-28 21:30:20 -0500258BOOST_AUTO_TEST_CASE(PutDataFromDataCallback) // Bug 4596
259{
260 face.expressInterest(*makeInterest("/localhost/notification/1"),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500261 [&] (auto&&...) {
Davide Pesaventod247d492020-01-28 21:30:20 -0500262 face.put(*makeData("/chronosync/sampleDigest/1"));
263 }, nullptr, nullptr);
264 advanceClocks(10_ms);
265 BOOST_CHECK_EQUAL(face.sentInterests.back().getName(), "/localhost/notification/1");
266
267 face.receive(*makeInterest("/chronosync/sampleDigest", true));
268 advanceClocks(10_ms);
269
270 face.put(*makeData("/localhost/notification/1"));
271 advanceClocks(10_ms);
272 BOOST_CHECK_EQUAL(face.sentData.back().getName(), "/chronosync/sampleDigest/1");
273}
274
275BOOST_AUTO_TEST_CASE(DestroyWithPendingInterest)
276{
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500277 auto face2 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500278 face2->expressInterest(*makeInterest("/Hello/World", false, 50_ms),
279 nullptr, nullptr, nullptr);
280 advanceClocks(50_ms, 2);
281 face2.reset();
282
283 advanceClocks(50_ms, 2); // should not crash - Bug 2518
284
285 // avoid "test case [...] did not check any assertions" message from Boost.Test
286 BOOST_CHECK(true);
287}
288
289BOOST_AUTO_TEST_CASE(Handle)
Junxiao Shi80609d42019-01-29 18:15:22 +0000290{
291 auto hdl = face.expressInterest(*makeInterest("/Hello/World", true, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500292 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
293 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
294 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500295 advanceClocks(1_ms);
Junxiao Shi80609d42019-01-29 18:15:22 +0000296 hdl.cancel();
Davide Pesaventod247d492020-01-28 21:30:20 -0500297 advanceClocks(1_ms);
Junxiao Shi80609d42019-01-29 18:15:22 +0000298 face.receive(*makeData("/Hello/World/%21"));
299 advanceClocks(200_ms, 5);
300
Davide Pesaventod247d492020-01-28 21:30:20 -0500301 // cancel after destructing face
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500302 auto face2 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500303 auto hdl2 = face2->expressInterest(*makeInterest("/Hello/World", true, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500304 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
305 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
306 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500307 advanceClocks(1_ms);
308 face2.reset();
309 advanceClocks(1_ms);
310 hdl2.cancel(); // should not crash
311 advanceClocks(1_ms);
312
Junxiao Shi80609d42019-01-29 18:15:22 +0000313 // avoid "test case [...] did not check any assertions" message from Boost.Test
314 BOOST_CHECK(true);
315}
316
Davide Pesaventod247d492020-01-28 21:30:20 -0500317BOOST_AUTO_TEST_SUITE_END() // ExpressInterest
318
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000319BOOST_AUTO_TEST_CASE(RemoveAllPendingInterests)
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500320{
Junxiao Shib55e5d32018-07-18 13:32:00 -0600321 face.expressInterest(*makeInterest("/Hello/World/0", false, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500322 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
323 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
324 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500325
Junxiao Shib55e5d32018-07-18 13:32:00 -0600326 face.expressInterest(*makeInterest("/Hello/World/1", false, 50_ms),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500327 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
328 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
329 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500330
Davide Pesavento0f830802018-01-16 23:58:58 -0500331 advanceClocks(10_ms);
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500332
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800333 face.removeAllPendingInterests();
Davide Pesavento0f830802018-01-16 23:58:58 -0500334 advanceClocks(10_ms);
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500335
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800336 BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0);
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500337
Junxiao Shi85d90832016-08-04 03:19:46 +0000338 face.receive(*makeData("/Hello/World/0"));
339 face.receive(*makeData("/Hello/World/1"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500340 advanceClocks(200_ms, 5);
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500341}
342
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000343BOOST_AUTO_TEST_SUITE(Producer)
344
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000345BOOST_AUTO_TEST_CASE(PutData)
346{
347 BOOST_CHECK_EQUAL(face.sentData.size(), 0);
348
349 Data data("/4g7xxcuEow/KFvK5Kf2m");
350 signData(data);
351 face.put(data);
352
353 lp::CachePolicy cachePolicy;
354 cachePolicy.setPolicy(lp::CachePolicyType::NO_CACHE);
355 data.setTag(make_shared<lp::CachePolicyTag>(cachePolicy));
Eric Newberry4d261b62016-11-10 13:40:09 -0700356 data.setTag(make_shared<lp::CongestionMarkTag>(1));
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000357 face.put(data);
358
Davide Pesavento0f830802018-01-16 23:58:58 -0500359 advanceClocks(10_ms);
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000360 BOOST_REQUIRE_EQUAL(face.sentData.size(), 2);
361 BOOST_CHECK(face.sentData[0].getTag<lp::CachePolicyTag>() == nullptr);
Eric Newberry4d261b62016-11-10 13:40:09 -0700362 BOOST_CHECK(face.sentData[0].getTag<lp::CongestionMarkTag>() == nullptr);
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000363 BOOST_CHECK(face.sentData[1].getTag<lp::CachePolicyTag>() != nullptr);
Eric Newberry4d261b62016-11-10 13:40:09 -0700364 BOOST_CHECK(face.sentData[1].getTag<lp::CongestionMarkTag>() != nullptr);
Junxiao Shie7bb6c82016-08-08 23:16:35 +0000365}
366
Junxiao Shib6828912017-11-20 14:06:32 +0000367BOOST_AUTO_TEST_CASE(PutDataLoopback)
368{
369 bool hasInterest1 = false, hasData = false;
370
371 // first InterestFilter allows loopback and should receive Interest
Davide Pesavento2f46d652023-11-09 23:40:01 -0500372 face.setInterestFilter("/", [&] (auto&&...) {
Junxiao Shib6828912017-11-20 14:06:32 +0000373 hasInterest1 = true;
374 // do not respond with Data right away, so Face must send Interest to forwarder
375 });
Davide Pesavento2f46d652023-11-09 23:40:01 -0500376
Junxiao Shib6828912017-11-20 14:06:32 +0000377 // second InterestFilter disallows loopback and should not receive Interest
378 face.setInterestFilter(InterestFilter("/").allowLoopback(false),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500379 [] (auto&&...) { BOOST_ERROR("Unexpected Interest on second InterestFilter"); });
Junxiao Shib6828912017-11-20 14:06:32 +0000380
Junxiao Shib55e5d32018-07-18 13:32:00 -0600381 face.expressInterest(*makeInterest("/A", true),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500382 [&] (auto&&...) { hasData = true; },
383 [] (auto&&...) { BOOST_FAIL("Unexpected nack"); },
384 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500385 advanceClocks(1_ms);
Junxiao Shib6828912017-11-20 14:06:32 +0000386 BOOST_CHECK_EQUAL(hasInterest1, true); // Interest looped back
387 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); // Interest sent to forwarder
388 BOOST_CHECK_EQUAL(hasData, false); // waiting for Data
389
390 face.put(*makeData("/A/B")); // first InterestFilter responds with Data
Davide Pesavento0f830802018-01-16 23:58:58 -0500391 advanceClocks(1_ms);
Junxiao Shib6828912017-11-20 14:06:32 +0000392 BOOST_CHECK_EQUAL(hasData, true);
393 BOOST_CHECK_EQUAL(face.sentData.size(), 0); // do not spill Data to forwarder
394}
395
Junxiao Shi859888f2017-09-12 14:29:16 +0000396BOOST_AUTO_TEST_CASE(PutMultipleData)
397{
398 bool hasInterest1 = false;
399 // register two Interest destinations
Davide Pesavento2f46d652023-11-09 23:40:01 -0500400 face.setInterestFilter("/", [&] (auto&&...) {
Junxiao Shi859888f2017-09-12 14:29:16 +0000401 hasInterest1 = true;
402 // sending Data right away from the first destination, don't care whether Interest goes to second destination
403 face.put(*makeData("/A/B"));
Davide Pesavento2f46d652023-11-09 23:40:01 -0500404 });
405 face.setInterestFilter("/", [] (auto&&...) {});
Davide Pesavento0f830802018-01-16 23:58:58 -0500406 advanceClocks(10_ms);
Junxiao Shi859888f2017-09-12 14:29:16 +0000407
Junxiao Shib55e5d32018-07-18 13:32:00 -0600408 face.receive(*makeInterest("/A", true));
Davide Pesavento0f830802018-01-16 23:58:58 -0500409 advanceClocks(10_ms);
Junxiao Shi859888f2017-09-12 14:29:16 +0000410 BOOST_CHECK(hasInterest1);
411 BOOST_CHECK_EQUAL(face.sentData.size(), 1);
412 BOOST_CHECK_EQUAL(face.sentData.at(0).getName(), "/A/B");
413
414 face.put(*makeData("/A/C"));
415 BOOST_CHECK_EQUAL(face.sentData.size(), 1); // additional Data are ignored
416}
417
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000418BOOST_AUTO_TEST_CASE(PutNack)
419{
Davide Pesavento2f46d652023-11-09 23:40:01 -0500420 // register one Interest destination so that face can accept Nacks
421 face.setInterestFilter("/", [] (auto&&...) {});
Davide Pesavento0f830802018-01-16 23:58:58 -0500422 advanceClocks(10_ms);
Junxiao Shi79a7a162017-09-09 08:33:57 +0000423
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000424 BOOST_CHECK_EQUAL(face.sentNacks.size(), 0);
425
Davide Pesaventof6b45892023-03-13 15:00:51 -0400426 face.put(makeNack(*makeInterest("/unsolicited", false, std::nullopt, 18645250),
Junxiao Shib55e5d32018-07-18 13:32:00 -0600427 lp::NackReason::NO_ROUTE));
Davide Pesavento0f830802018-01-16 23:58:58 -0500428 advanceClocks(10_ms);
Junxiao Shi1ad0b4b2017-08-18 14:19:14 +0000429 BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); // unsolicited Nack would not be sent
Eric Newberry4d261b62016-11-10 13:40:09 -0700430
Davide Pesaventof6b45892023-03-13 15:00:51 -0400431 auto interest1 = makeInterest("/Hello/World", false, std::nullopt, 14247162);
Junxiao Shib55e5d32018-07-18 13:32:00 -0600432 face.receive(*interest1);
Davide Pesaventof6b45892023-03-13 15:00:51 -0400433 auto interest2 = makeInterest("/another/prefix", false, std::nullopt, 92203002);
Junxiao Shib55e5d32018-07-18 13:32:00 -0600434 face.receive(*interest2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500435 advanceClocks(10_ms);
Junxiao Shi1ad0b4b2017-08-18 14:19:14 +0000436
Junxiao Shib55e5d32018-07-18 13:32:00 -0600437 face.put(makeNack(*interest1, lp::NackReason::DUPLICATE));
Davide Pesavento0f830802018-01-16 23:58:58 -0500438 advanceClocks(10_ms);
Junxiao Shi1ad0b4b2017-08-18 14:19:14 +0000439 BOOST_REQUIRE_EQUAL(face.sentNacks.size(), 1);
440 BOOST_CHECK_EQUAL(face.sentNacks[0].getReason(), lp::NackReason::DUPLICATE);
441 BOOST_CHECK(face.sentNacks[0].getTag<lp::CongestionMarkTag>() == nullptr);
442
Junxiao Shib55e5d32018-07-18 13:32:00 -0600443 auto nack = makeNack(*interest2, lp::NackReason::NO_ROUTE);
Eric Newberry4d261b62016-11-10 13:40:09 -0700444 nack.setTag(make_shared<lp::CongestionMarkTag>(1));
445 face.put(nack);
Davide Pesavento0f830802018-01-16 23:58:58 -0500446 advanceClocks(10_ms);
Eric Newberry4d261b62016-11-10 13:40:09 -0700447 BOOST_REQUIRE_EQUAL(face.sentNacks.size(), 2);
Junxiao Shi1ad0b4b2017-08-18 14:19:14 +0000448 BOOST_CHECK_EQUAL(face.sentNacks[1].getReason(), lp::NackReason::NO_ROUTE);
Eric Newberry4d261b62016-11-10 13:40:09 -0700449 BOOST_CHECK(face.sentNacks[1].getTag<lp::CongestionMarkTag>() != nullptr);
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000450}
Ilya Moiseenko56b0bf82015-11-08 11:14:28 -0500451
Junxiao Shi79a7a162017-09-09 08:33:57 +0000452BOOST_AUTO_TEST_CASE(PutMultipleNack)
453{
Junxiao Shi859888f2017-09-12 14:29:16 +0000454 bool hasInterest1 = false, hasInterest2 = false;
455 // register two Interest destinations
456 face.setInterestFilter("/", [&] (const InterestFilter&, const Interest& interest) {
457 hasInterest1 = true;
458 // sending Nack right away from the first destination, Interest should still go to second destination
459 face.put(makeNack(interest, lp::NackReason::CONGESTION));
460 });
Davide Pesavento2f46d652023-11-09 23:40:01 -0500461 face.setInterestFilter("/", [&] (auto&&...) { hasInterest2 = true; });
Davide Pesavento0f830802018-01-16 23:58:58 -0500462 advanceClocks(10_ms);
Junxiao Shi79a7a162017-09-09 08:33:57 +0000463
Davide Pesaventof6b45892023-03-13 15:00:51 -0400464 auto interest = makeInterest("/A", false, std::nullopt, 14333271);
Junxiao Shib55e5d32018-07-18 13:32:00 -0600465 face.receive(*interest);
Davide Pesavento0f830802018-01-16 23:58:58 -0500466 advanceClocks(10_ms);
Junxiao Shi859888f2017-09-12 14:29:16 +0000467 BOOST_CHECK(hasInterest1);
468 BOOST_CHECK(hasInterest2);
Junxiao Shi79a7a162017-09-09 08:33:57 +0000469
Junxiao Shi859888f2017-09-12 14:29:16 +0000470 // Nack from first destination is received, should wait for a response from the other destination
471 BOOST_CHECK_EQUAL(face.sentNacks.size(), 0);
Junxiao Shi79a7a162017-09-09 08:33:57 +0000472
Junxiao Shib55e5d32018-07-18 13:32:00 -0600473 face.put(makeNack(*interest, lp::NackReason::NO_ROUTE)); // Nack from second destination
Davide Pesavento0f830802018-01-16 23:58:58 -0500474 advanceClocks(10_ms);
Junxiao Shi859888f2017-09-12 14:29:16 +0000475 BOOST_CHECK_EQUAL(face.sentNacks.size(), 1); // sending Nack after both destinations Nacked
Junxiao Shi79a7a162017-09-09 08:33:57 +0000476 BOOST_CHECK_EQUAL(face.sentNacks.at(0).getReason(), lp::NackReason::CONGESTION); // least severe reason
477
Junxiao Shib55e5d32018-07-18 13:32:00 -0600478 face.put(makeNack(*interest, lp::NackReason::DUPLICATE));
Junxiao Shi79a7a162017-09-09 08:33:57 +0000479 BOOST_CHECK_EQUAL(face.sentNacks.size(), 1); // additional Nacks are ignored
480}
481
Junxiao Shib6828912017-11-20 14:06:32 +0000482BOOST_AUTO_TEST_CASE(PutMultipleNackLoopback)
483{
484 bool hasInterest1 = false, hasNack = false;
485
486 // first InterestFilter allows loopback and should receive Interest
487 face.setInterestFilter("/", [&] (const InterestFilter&, const Interest& interest) {
488 hasInterest1 = true;
489 face.put(makeNack(interest, lp::NackReason::CONGESTION));
490 });
Davide Pesavento2f46d652023-11-09 23:40:01 -0500491
Junxiao Shib6828912017-11-20 14:06:32 +0000492 // second InterestFilter disallows loopback and should not receive Interest
493 face.setInterestFilter(InterestFilter("/").allowLoopback(false),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500494 [] (auto&&...) { BOOST_ERROR("Unexpected Interest on second InterestFilter"); });
Junxiao Shib6828912017-11-20 14:06:32 +0000495
Davide Pesaventof6b45892023-03-13 15:00:51 -0400496 auto interest = makeInterest("/A", false, std::nullopt, 28395852);
Junxiao Shib55e5d32018-07-18 13:32:00 -0600497 face.expressInterest(*interest,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500498 [] (auto&&...) { BOOST_FAIL("Unexpected data"); },
Junxiao Shib6828912017-11-20 14:06:32 +0000499 [&] (const Interest&, const lp::Nack& nack) {
500 hasNack = true;
501 BOOST_CHECK_EQUAL(nack.getReason(), lp::NackReason::CONGESTION);
502 },
Davide Pesavento2f46d652023-11-09 23:40:01 -0500503 [] (auto&&...) { BOOST_FAIL("Unexpected timeout"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500504 advanceClocks(1_ms);
Junxiao Shib6828912017-11-20 14:06:32 +0000505 BOOST_CHECK_EQUAL(hasInterest1, true); // Interest looped back
506 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); // Interest sent to forwarder
507 BOOST_CHECK_EQUAL(hasNack, false); // waiting for Nack from forwarder
508
Junxiao Shib55e5d32018-07-18 13:32:00 -0600509 face.receive(makeNack(*interest, lp::NackReason::NO_ROUTE));
Davide Pesavento0f830802018-01-16 23:58:58 -0500510 advanceClocks(1_ms);
Junxiao Shib6828912017-11-20 14:06:32 +0000511 BOOST_CHECK_EQUAL(hasNack, true);
512}
513
Davide Pesaventod247d492020-01-28 21:30:20 -0500514BOOST_AUTO_TEST_SUITE_END() // Producer
515
516BOOST_AUTO_TEST_SUITE(RegisterPrefix)
517
518BOOST_FIXTURE_TEST_CASE(Failure, FaceFixture<NoPrefixRegReply>)
519{
520 BOOST_CHECK(!runPrefixReg([&] (const auto& success, const auto& failure) {
521 face.registerPrefix("/Hello/World", success, failure);
522 this->advanceClocks(5_s, 20); // wait for command timeout
523 }));
524}
525
526BOOST_AUTO_TEST_CASE(Handle)
527{
528 RegisteredPrefixHandle hdl;
529 auto doReg = [&] {
530 return runPrefixReg([&] (const auto& success, const auto& failure) {
531 hdl = face.registerPrefix("/Hello/World", success, failure);
532 });
533 };
534 auto doUnreg = [&] {
535 return runPrefixUnreg([&] (const auto& success, const auto& failure) {
536 hdl.unregister(success, failure);
537 });
538 };
539
540 // despite the "undefined behavior" warning, we try not to crash, but no API guarantee for this
541 BOOST_CHECK(!doUnreg());
542
543 // cancel after unregister
544 BOOST_CHECK(doReg());
545 BOOST_CHECK(doUnreg());
546 hdl.cancel();
547 advanceClocks(1_ms);
548
549 // unregister after cancel
550 BOOST_CHECK(doReg());
551 hdl.cancel();
552 advanceClocks(1_ms);
553 BOOST_CHECK(!doUnreg());
554
555 // cancel after destructing face
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500556 auto face2 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500557 hdl = face2->registerPrefix("/Hello/World/2", nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500558 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500559 advanceClocks(1_ms);
560 face2.reset();
561 advanceClocks(1_ms);
562 hdl.cancel(); // should not crash
563 advanceClocks(1_ms);
564
565 // unregister after destructing face
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500566 auto face3 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500567 hdl = face3->registerPrefix("/Hello/World/3", nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500568 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500569 advanceClocks(1_ms);
570 face3.reset();
571 advanceClocks(1_ms);
572 BOOST_CHECK(!doUnreg());
573}
574
575BOOST_AUTO_TEST_SUITE_END() // RegisterPrefix
576
577BOOST_AUTO_TEST_SUITE(SetInterestFilter)
578
579BOOST_AUTO_TEST_CASE(SetAndCancel)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400580{
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800581 size_t nInterests = 0;
582 size_t nRegs = 0;
Davide Pesavento720e25c2019-07-14 01:33:52 -0400583 auto hdl = face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500584 [&] (auto&&...) { ++nInterests; },
585 [&] (auto&&...) { ++nRegs; },
586 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500587 advanceClocks(25_ms, 4);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800588 BOOST_CHECK_EQUAL(nRegs, 1);
589 BOOST_CHECK_EQUAL(nInterests, 0);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400590
Junxiao Shib55e5d32018-07-18 13:32:00 -0600591 face.receive(*makeInterest("/Hello/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500592 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400593
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800594 BOOST_CHECK_EQUAL(nRegs, 1);
595 BOOST_CHECK_EQUAL(nInterests, 1);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400596
Junxiao Shib55e5d32018-07-18 13:32:00 -0600597 face.receive(*makeInterest("/Bye/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500598 advanceClocks(10000_ms, 10);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800599 BOOST_CHECK_EQUAL(nInterests, 1);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400600
Junxiao Shib55e5d32018-07-18 13:32:00 -0600601 face.receive(*makeInterest("/Hello/World/%21/2"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500602 advanceClocks(25_ms, 4);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800603 BOOST_CHECK_EQUAL(nInterests, 2);
604
605 // removing filter
Davide Pesavento720e25c2019-07-14 01:33:52 -0400606 hdl.cancel();
Davide Pesavento0f830802018-01-16 23:58:58 -0500607 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400608
Junxiao Shib55e5d32018-07-18 13:32:00 -0600609 face.receive(*makeInterest("/Hello/World/%21/3"));
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800610 BOOST_CHECK_EQUAL(nInterests, 2);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800611}
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400612
Davide Pesaventod247d492020-01-28 21:30:20 -0500613BOOST_AUTO_TEST_CASE(EmptyInterestCallback)
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000614{
615 face.setInterestFilter("/A", nullptr);
Davide Pesavento0f830802018-01-16 23:58:58 -0500616 advanceClocks(1_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000617
618 BOOST_CHECK_NO_THROW(do {
619 face.receive(*makeInterest("/A/1"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500620 advanceClocks(1_ms);
Junxiao Shi76e0eb22016-08-08 05:54:10 +0000621 } while (false));
622}
623
Davide Pesaventod247d492020-01-28 21:30:20 -0500624BOOST_AUTO_TEST_CASE(WithoutSuccessCallback)
Joao Pereira0b3cac52015-07-02 14:49:49 -0400625{
626 size_t nInterests = 0;
Davide Pesavento720e25c2019-07-14 01:33:52 -0400627 auto hdl = face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500628 [&] (auto&&...) { ++nInterests; },
629 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesavento0f830802018-01-16 23:58:58 -0500630 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400631 BOOST_CHECK_EQUAL(nInterests, 0);
632
Junxiao Shib55e5d32018-07-18 13:32:00 -0600633 face.receive(*makeInterest("/Hello/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500634 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400635
636 BOOST_CHECK_EQUAL(nInterests, 1);
637
Junxiao Shib55e5d32018-07-18 13:32:00 -0600638 face.receive(*makeInterest("/Bye/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500639 advanceClocks(10000_ms, 10);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400640 BOOST_CHECK_EQUAL(nInterests, 1);
641
Junxiao Shib55e5d32018-07-18 13:32:00 -0600642 face.receive(*makeInterest("/Hello/World/%21/2"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500643 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400644 BOOST_CHECK_EQUAL(nInterests, 2);
645
646 // removing filter
Davide Pesavento720e25c2019-07-14 01:33:52 -0400647 hdl.cancel();
Davide Pesavento0f830802018-01-16 23:58:58 -0500648 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400649
Junxiao Shib55e5d32018-07-18 13:32:00 -0600650 face.receive(*makeInterest("/Hello/World/%21/3"));
Joao Pereira0b3cac52015-07-02 14:49:49 -0400651 BOOST_CHECK_EQUAL(nInterests, 2);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400652}
653
Davide Pesaventod247d492020-01-28 21:30:20 -0500654BOOST_FIXTURE_TEST_CASE(Failure, FaceFixture<NoPrefixRegReply>)
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800655{
656 // don't enable registration reply
657 size_t nRegFailed = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800658 face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500659 [] (auto&&...) { BOOST_FAIL("Unexpected Interest"); },
660 [] (auto&&...) { BOOST_FAIL("Unexpected success"); },
661 [&] (auto&&...) { ++nRegFailed; });
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800662
Davide Pesavento0f830802018-01-16 23:58:58 -0500663 advanceClocks(25_ms, 4);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800664 BOOST_CHECK_EQUAL(nRegFailed, 0);
665
Davide Pesavento0f830802018-01-16 23:58:58 -0500666 advanceClocks(2000_ms, 5);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800667 BOOST_CHECK_EQUAL(nRegFailed, 1);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400668}
669
Davide Pesaventod247d492020-01-28 21:30:20 -0500670BOOST_FIXTURE_TEST_CASE(FailureWithoutSuccessCallback, FaceFixture<NoPrefixRegReply>)
Joao Pereira0b3cac52015-07-02 14:49:49 -0400671{
672 // don't enable registration reply
673 size_t nRegFailed = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800674 face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500675 [] (auto&&...) { BOOST_FAIL("Unexpected Interest"); },
676 [&] (auto&&...) { ++nRegFailed; });
Joao Pereira0b3cac52015-07-02 14:49:49 -0400677
Davide Pesavento0f830802018-01-16 23:58:58 -0500678 advanceClocks(25_ms, 4);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400679 BOOST_CHECK_EQUAL(nRegFailed, 0);
680
Davide Pesavento0f830802018-01-16 23:58:58 -0500681 advanceClocks(2000_ms, 5);
Joao Pereira0b3cac52015-07-02 14:49:49 -0400682 BOOST_CHECK_EQUAL(nRegFailed, 1);
683}
684
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800685BOOST_AUTO_TEST_CASE(SimilarFilters)
686{
687 size_t nInInterests1 = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800688 face.setInterestFilter("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500689 [&nInInterests1] (auto&&...) { ++nInInterests1; },
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000690 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500691 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800692
693 size_t nInInterests2 = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800694 face.setInterestFilter("/Hello",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500695 [&nInInterests2] (auto&&...) { ++nInInterests2; },
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000696 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500697 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400698
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800699 size_t nInInterests3 = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800700 face.setInterestFilter("/Los/Angeles/Lakers",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500701 [&nInInterests3] (auto&&...) { ++nInInterests3; },
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000702 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500703 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400704
Davide Pesavento0f830802018-01-16 23:58:58 -0500705 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400706
Junxiao Shib55e5d32018-07-18 13:32:00 -0600707 face.receive(*makeInterest("/Hello/World/%21"));
Davide Pesavento0f830802018-01-16 23:58:58 -0500708 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400709
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800710 BOOST_CHECK_EQUAL(nInInterests1, 1);
711 BOOST_CHECK_EQUAL(nInInterests2, 1);
712 BOOST_CHECK_EQUAL(nInInterests3, 0);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400713}
714
Davide Pesaventod247d492020-01-28 21:30:20 -0500715BOOST_AUTO_TEST_CASE(RegexFilter)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400716{
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800717 size_t nInInterests = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800718 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500719 [&nInInterests] (auto&&...) { ++nInInterests; },
Junxiao Shi103d8ed2016-08-07 20:34:10 +0000720 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500721 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400722
Davide Pesavento0f830802018-01-16 23:58:58 -0500723 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400724
Junxiao Shib55e5d32018-07-18 13:32:00 -0600725 face.receive(*makeInterest("/Hello/World/a")); // shouldn't match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400726 BOOST_CHECK_EQUAL(nInInterests, 0);
727
Junxiao Shib55e5d32018-07-18 13:32:00 -0600728 face.receive(*makeInterest("/Hello/World/a/b")); // should match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400729 BOOST_CHECK_EQUAL(nInInterests, 1);
730
Junxiao Shib55e5d32018-07-18 13:32:00 -0600731 face.receive(*makeInterest("/Hello/World/a/b/c")); // should match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400732 BOOST_CHECK_EQUAL(nInInterests, 2);
733
Junxiao Shib55e5d32018-07-18 13:32:00 -0600734 face.receive(*makeInterest("/Hello/World/a/b/d")); // should not match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400735 BOOST_CHECK_EQUAL(nInInterests, 2);
736}
737
Davide Pesaventod247d492020-01-28 21:30:20 -0500738BOOST_AUTO_TEST_CASE(RegexFilterError)
739{
740 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500741 // Do NOT use 'auto' for this lambda. This is testing the (failure of)
742 // implicit conversion from InterestFilter to Name, therefore the type
743 // of the first parameter must be explicit.
Davide Pesaventod247d492020-01-28 21:30:20 -0500744 [] (const Name&, const Interest&) {
Davide Pesavento2f46d652023-11-09 23:40:01 -0500745 BOOST_FAIL("InterestFilter::Error should have been raised");
Davide Pesaventod247d492020-01-28 21:30:20 -0500746 },
747 nullptr,
Davide Pesavento2f46d652023-11-09 23:40:01 -0500748 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Davide Pesaventod247d492020-01-28 21:30:20 -0500749
750 advanceClocks(25_ms, 4);
751
752 BOOST_CHECK_THROW(face.receive(*makeInterest("/Hello/World/XXX/b/c")), InterestFilter::Error);
753}
754
755BOOST_AUTO_TEST_CASE(RegexFilterAndRegisterPrefix)
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400756{
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800757 size_t nInInterests = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800758 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
Davide Pesavento2f46d652023-11-09 23:40:01 -0500759 [&] (auto&&...) { ++nInInterests; });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400760
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -0800761 size_t nRegSuccesses = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800762 face.registerPrefix("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500763 [&] (auto&&...) { ++nRegSuccesses; },
764 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400765
Davide Pesavento0f830802018-01-16 23:58:58 -0500766 advanceClocks(25_ms, 4);
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400767 BOOST_CHECK_EQUAL(nRegSuccesses, 1);
768
Junxiao Shib55e5d32018-07-18 13:32:00 -0600769 face.receive(*makeInterest("/Hello/World/a")); // shouldn't match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400770 BOOST_CHECK_EQUAL(nInInterests, 0);
771
Junxiao Shib55e5d32018-07-18 13:32:00 -0600772 face.receive(*makeInterest("/Hello/World/a/b")); // should match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400773 BOOST_CHECK_EQUAL(nInInterests, 1);
774
Junxiao Shib55e5d32018-07-18 13:32:00 -0600775 face.receive(*makeInterest("/Hello/World/a/b/c")); // should match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400776 BOOST_CHECK_EQUAL(nInInterests, 2);
777
Junxiao Shib55e5d32018-07-18 13:32:00 -0600778 face.receive(*makeInterest("/Hello/World/a/b/d")); // should not match
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400779 BOOST_CHECK_EQUAL(nInInterests, 2);
780}
781
Davide Pesaventod247d492020-01-28 21:30:20 -0500782BOOST_FIXTURE_TEST_CASE(WithoutRegisterPrefix, FaceFixture<NoPrefixRegReply>) // Bug 2318
Junxiao Shia1ea5062014-12-27 22:33:39 -0700783{
784 // This behavior is specific to DummyClientFace.
785 // Regular Face won't accept incoming packets until something is sent.
786
787 int hit = 0;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500788 face.setInterestFilter(Name("/"), [&hit] (auto&&...) { ++hit; });
789 face.processEvents(-1_ms);
Junxiao Shia1ea5062014-12-27 22:33:39 -0700790
Junxiao Shib55e5d32018-07-18 13:32:00 -0600791 face.receive(*makeInterest("/A"));
Davide Pesavento2f46d652023-11-09 23:40:01 -0500792 face.processEvents(-1_ms);
Junxiao Shia1ea5062014-12-27 22:33:39 -0700793
794 BOOST_CHECK_EQUAL(hit, 1);
795}
796
Davide Pesaventod247d492020-01-28 21:30:20 -0500797BOOST_AUTO_TEST_CASE(Handle)
Junxiao Shi60aaef02019-01-14 04:59:30 +0000798{
799 int hit = 0;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500800 InterestFilterHandle hdl = face.setInterestFilter(Name("/"), [&hit] (auto&&...) { ++hit; });
Junxiao Shi60aaef02019-01-14 04:59:30 +0000801 face.processEvents(-1_ms);
802
803 face.receive(*makeInterest("/A"));
804 face.processEvents(-1_ms);
805 BOOST_CHECK_EQUAL(hit, 1);
806
807 hdl.cancel();
808 face.processEvents(-1_ms);
809
810 face.receive(*makeInterest("/B"));
811 face.processEvents(-1_ms);
812 BOOST_CHECK_EQUAL(hit, 1);
Davide Pesaventod247d492020-01-28 21:30:20 -0500813
814 // cancel after destructing face
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500815 auto face2 = make_unique<DummyClientFace>(m_io, m_keyChain);
Davide Pesaventod247d492020-01-28 21:30:20 -0500816 InterestFilterHandle hdl2 = face2->setInterestFilter("/Hello/World/2", nullptr);
817 advanceClocks(1_ms);
818 face2.reset();
819 advanceClocks(1_ms);
820 hdl2.cancel(); // should not crash
821 advanceClocks(1_ms);
Junxiao Shi60aaef02019-01-14 04:59:30 +0000822}
823
Davide Pesaventod247d492020-01-28 21:30:20 -0500824BOOST_AUTO_TEST_SUITE_END() // SetInterestFilter
Junxiao Shiae0b4182016-08-08 22:53:17 +0000825
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500826BOOST_AUTO_TEST_CASE(ProcessEvents)
827{
Davide Pesavento2f46d652023-11-09 23:40:01 -0500828 face.processEvents(-1_ms); // io_context::restart()/poll() inside
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500829
Davide Pesavento2f46d652023-11-09 23:40:01 -0500830 int nRegSuccesses = 0;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800831 face.registerPrefix("/Hello/World",
Davide Pesavento2f46d652023-11-09 23:40:01 -0500832 [&] (auto&&...) { ++nRegSuccesses; },
833 [] (auto&&...) { BOOST_FAIL("Unexpected failure"); });
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500834
Davide Pesavento2f46d652023-11-09 23:40:01 -0500835 // io_context::poll() without reset
836 face.getIoContext().poll();
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500837 BOOST_CHECK_EQUAL(nRegSuccesses, 0);
838
Davide Pesavento2f46d652023-11-09 23:40:01 -0500839 face.processEvents(-1_ms); // io_context::restart()/poll() inside
Alexander Afanasyev8e158542014-11-18 00:47:18 -0500840 BOOST_CHECK_EQUAL(nRegSuccesses, 1);
841}
842
Junxiao Shiae0b4182016-08-08 22:53:17 +0000843BOOST_AUTO_TEST_CASE(DestroyWithoutProcessEvents) // Bug 3248
844{
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500845 auto face2 = make_unique<Face>(m_io);
Junxiao Shiae0b4182016-08-08 22:53:17 +0000846 face2.reset();
847
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500848 m_io.poll(); // should not crash
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100849
850 // avoid "test case [...] did not check any assertions" message from Boost.Test
851 BOOST_CHECK(true);
Junxiao Shiae0b4182016-08-08 22:53:17 +0000852}
853
Junxiao Shiae0b4182016-08-08 22:53:17 +0000854BOOST_AUTO_TEST_SUITE(Transport)
855
856using ndn::Transport;
857
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500858BOOST_FIXTURE_TEST_CASE(FaceTransport, IoKeyChainFixture)
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800859{
Davide Pesavento2f46d652023-11-09 23:40:01 -0500860 BOOST_CHECK_NO_THROW(Face(shared_ptr<Transport>()));
861 BOOST_CHECK_NO_THROW(Face(shared_ptr<Transport>(), m_io));
862 BOOST_CHECK_NO_THROW(Face(shared_ptr<Transport>(), m_io, m_keyChain));
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800863
864 auto transport = make_shared<TcpTransport>("localhost", "6363"); // no real io operations will be scheduled
Davide Pesavento2f46d652023-11-09 23:40:01 -0500865 BOOST_CHECK(&Face(transport).getTransport() == transport.get());
866 BOOST_CHECK(&Face(transport, m_io).getTransport() == transport.get());
867 BOOST_CHECK(&Face(transport, m_io, m_keyChain).getTransport() == transport.get());
Alexander Afanasyev3a6da362015-12-29 20:31:03 -0800868}
869
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500870class WithEnv
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700871{
872public:
873 WithEnv()
874 {
875 if (getenv("NDN_CLIENT_TRANSPORT") != nullptr) {
876 m_oldTransport = getenv("NDN_CLIENT_TRANSPORT");
877 unsetenv("NDN_CLIENT_TRANSPORT");
878 }
879 }
880
881 void
882 configure(const std::string& faceUri)
883 {
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500884 setenv("NDN_CLIENT_TRANSPORT", faceUri.data(), true);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700885 }
886
887 ~WithEnv()
888 {
889 if (!m_oldTransport.empty()) {
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500890 setenv("NDN_CLIENT_TRANSPORT", m_oldTransport.data(), true);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700891 }
892 else {
893 unsetenv("NDN_CLIENT_TRANSPORT");
894 }
895 }
896
897private:
898 std::string m_oldTransport;
899};
900
901class WithConfig : private TestHomeFixture<DefaultPibDir>
902{
903public:
904 void
905 configure(const std::string& faceUri)
906 {
907 createClientConf({"transport=" + faceUri});
908 }
909};
910
911class WithEnvAndConfig : public WithEnv, public WithConfig
912{
913};
914
Davide Pesavento49e1e872023-11-11 00:45:23 -0500915using ConfigOptions = boost::mp11::mp_list<WithEnv, WithConfig>;
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700916
917BOOST_FIXTURE_TEST_CASE(NoConfig, WithEnvAndConfig) // fixture configures test HOME and PIB/TPM path
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700918{
919 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500920 BOOST_CHECK_NO_THROW(face = make_shared<Face>());
921 BOOST_CHECK(dynamic_cast<UnixTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700922}
923
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700924BOOST_FIXTURE_TEST_CASE_TEMPLATE(Unix, T, ConfigOptions, T)
925{
926 this->configure("unix://some/path");
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700927
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700928 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500929 BOOST_CHECK_NO_THROW(face = make_shared<Face>());
930 BOOST_CHECK(dynamic_cast<UnixTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700931}
932
933BOOST_FIXTURE_TEST_CASE_TEMPLATE(Tcp, T, ConfigOptions, T)
934{
935 this->configure("tcp://127.0.0.1:6000");
936
937 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500938 BOOST_CHECK_NO_THROW(face = make_shared<Face>());
939 BOOST_CHECK(dynamic_cast<TcpTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700940}
941
942BOOST_FIXTURE_TEST_CASE_TEMPLATE(WrongTransport, T, ConfigOptions, T)
943{
944 this->configure("wrong-transport:");
945
946 BOOST_CHECK_THROW(make_shared<Face>(), ConfigFile::Error);
947}
948
949BOOST_FIXTURE_TEST_CASE_TEMPLATE(WrongUri, T, ConfigOptions, T)
950{
951 this->configure("wrong-uri");
952
953 BOOST_CHECK_THROW(make_shared<Face>(), ConfigFile::Error);
954}
955
956BOOST_FIXTURE_TEST_CASE(EnvOverride, WithEnvAndConfig)
957{
958 this->WithEnv::configure("tcp://127.0.0.1:6000");
959 this->WithConfig::configure("unix://some/path");
960
961 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500962 BOOST_CHECK_NO_THROW(face = make_shared<Face>());
963 BOOST_CHECK(dynamic_cast<TcpTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700964}
965
966BOOST_FIXTURE_TEST_CASE(ExplicitTransport, WithEnvAndConfig)
967{
968 this->WithEnv::configure("wrong-uri");
969 this->WithConfig::configure("wrong-transport:");
970
971 auto transport = make_shared<UnixTransport>("unix://some/path");
972 shared_ptr<Face> face;
Davide Pesavento2f46d652023-11-09 23:40:01 -0500973 BOOST_CHECK_NO_THROW(face = make_shared<Face>(transport));
974 BOOST_CHECK(dynamic_cast<UnixTransport*>(&face->getTransport()) != nullptr);
Alexander Afanasyevcf490552016-06-27 22:51:36 -0700975}
976
Junxiao Shiae0b4182016-08-08 22:53:17 +0000977BOOST_AUTO_TEST_SUITE_END() // Transport
978
Alexander Afanasyev57e00362016-06-23 13:22:54 -0700979BOOST_AUTO_TEST_SUITE_END() // TestFace
980
Davide Pesavento47ce2ee2023-05-09 01:33:33 -0400981} // namespace ndn::tests