blob: 26623656e22aed1fadea83929da8ade978c5fa49 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev20d2c582014-01-26 15:32:51 -08002/**
Alexander Afanasyevaf99f462015-01-19 21:43:09 -08003 * Copyright (c) 2013-2015 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080020 */
21
Alexander Afanasyeve6c65e22015-01-28 19:56:03 -080022#define BOOST_TEST_MAIN 1
23#define BOOST_TEST_DYN_LINK 1
24#define BOOST_TEST_MODULE ndn-cxx Integrated Tests (Face)
25
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080026#include "face.hpp"
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -080027#include "util/scheduler.hpp"
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -070028#include "security/key-chain.hpp"
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080029
Yingdi Yu41546342014-11-30 23:37:53 -080030#include "identity-management-fixture.hpp"
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070031#include "boost-test.hpp"
32
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080033namespace ndn {
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -040034namespace tests {
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080035
Yingdi Yu41546342014-11-30 23:37:53 -080036class FacesFixture : public security::IdentityManagementFixture
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080037{
Alexander Afanasyev90164962014-03-06 08:29:59 +000038public:
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080039 FacesFixture()
Alexander Afanasyev90164962014-03-06 08:29:59 +000040 : nData(0)
41 , nTimeouts(0)
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -080042 , regPrefixId(0)
Alexander Afanasyev90164962014-03-06 08:29:59 +000043 , nInInterests(0)
44 , nInInterests2(0)
45 , nRegFailures(0)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080046 {
47 }
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070048
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080049 void
50 onData()
51 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000052 ++nData;
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080053 }
54
55 void
56 onTimeout()
57 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000058 ++nTimeouts;
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080059 }
60
61 void
Alexander Afanasyev90164962014-03-06 08:29:59 +000062 onInterest(Face& face,
63 const Name&, const Interest&)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080064 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000065 ++nInInterests;
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -080066
67 face.unsetInterestFilter(regPrefixId);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080068 }
69
70 void
Alexander Afanasyev90164962014-03-06 08:29:59 +000071 onInterest2(Face& face,
72 const Name&, const Interest&)
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -080073 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000074 ++nInInterests2;
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -080075
76 face.unsetInterestFilter(regPrefixId2);
77 }
78
79 void
Alexander Afanasyev90164962014-03-06 08:29:59 +000080 onInterestRegex(Face& face,
81 const InterestFilter&, const Interest&)
82 {
83 ++nInInterests;
84 }
85
86 void
87 onInterestRegexError(Face& face,
88 const Name&, const Interest&)
89 {
90 BOOST_FAIL("InterestFilter::Error should have been triggered");
91 }
92
93 void
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080094 onRegFailed()
95 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000096 ++nRegFailures;
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -080097 }
98
99 void
100 expressInterest(Face& face, const Name& name)
101 {
102 Interest i(name);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700103 i.setInterestLifetime(time::milliseconds(50));
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800104 face.expressInterest(i,
105 bind(&FacesFixture::onData, this),
106 bind(&FacesFixture::onTimeout, this));
107 }
108
109 void
110 terminate(Face& face)
111 {
Alexander Afanasyev9d158f02015-02-17 21:30:19 -0800112 face.getIoService().stop();
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800113 }
114
Alexander Afanasyev90164962014-03-06 08:29:59 +0000115 uint32_t nData;
116 uint32_t nTimeouts;
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800117
118 const RegisteredPrefixId* regPrefixId;
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800119 const RegisteredPrefixId* regPrefixId2;
Alexander Afanasyev90164962014-03-06 08:29:59 +0000120 uint32_t nInInterests;
121 uint32_t nInInterests2;
122 uint32_t nRegFailures;
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800123};
124
Alexander Afanasyev90164962014-03-06 08:29:59 +0000125BOOST_FIXTURE_TEST_SUITE(TestFaces, FacesFixture)
126
127BOOST_AUTO_TEST_CASE(Unix)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800128{
129 Face face;
130
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700131 face.expressInterest(Interest("/", time::milliseconds(1000)),
132 bind(&FacesFixture::onData, this),
133 bind(&FacesFixture::onTimeout, this));
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800134
135 BOOST_REQUIRE_NO_THROW(face.processEvents());
136
Alexander Afanasyev90164962014-03-06 08:29:59 +0000137 BOOST_CHECK_EQUAL(nData, 1);
138 BOOST_CHECK_EQUAL(nTimeouts, 0);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800139
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700140 face.expressInterest(Interest("/localhost/non-existing/data/should/not/exist/anywhere",
141 time::milliseconds(50)),
142 bind(&FacesFixture::onData, this),
143 bind(&FacesFixture::onTimeout, this));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700144
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -0700145 Name veryLongName;
146 for (size_t i = 0; i <= MAX_NDN_PACKET_SIZE / 10; i++)
147 {
148 veryLongName.append("0123456789");
149 }
150
151 BOOST_CHECK_THROW(face.expressInterest(veryLongName, OnData(), OnTimeout()), Face::Error);
152
153 shared_ptr<Data> data = make_shared<Data>(veryLongName);
154 data->setContent(reinterpret_cast<const uint8_t*>("01234567890"), 10);
Yingdi Yu41546342014-11-30 23:37:53 -0800155 m_keyChain.sign(*data);
Alexander Afanasyev49bb1fb2014-07-21 12:54:01 -0700156 BOOST_CHECK_THROW(face.put(*data), Face::Error);
157
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800158 BOOST_REQUIRE_NO_THROW(face.processEvents());
159
Alexander Afanasyev90164962014-03-06 08:29:59 +0000160 BOOST_CHECK_EQUAL(nData, 1);
161 BOOST_CHECK_EQUAL(nTimeouts, 1);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800162}
163
Alexander Afanasyev90164962014-03-06 08:29:59 +0000164BOOST_AUTO_TEST_CASE(Tcp)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800165{
166 Face face("localhost");
167
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700168 face.expressInterest(Interest("/", time::milliseconds(1000)),
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800169 bind(&FacesFixture::onData, this),
170 bind(&FacesFixture::onTimeout, this));
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800171
172 BOOST_REQUIRE_NO_THROW(face.processEvents());
173
Alexander Afanasyev90164962014-03-06 08:29:59 +0000174 BOOST_CHECK_EQUAL(nData, 1);
175 BOOST_CHECK_EQUAL(nTimeouts, 0);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800176
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700177 face.expressInterest(Interest("/localhost/non-existing/data/should/not/exist/anywhere",
178 time::milliseconds(50)),
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800179 bind(&FacesFixture::onData, this),
180 bind(&FacesFixture::onTimeout, this));
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800181
182 BOOST_REQUIRE_NO_THROW(face.processEvents());
183
Alexander Afanasyev90164962014-03-06 08:29:59 +0000184 BOOST_CHECK_EQUAL(nData, 1);
185 BOOST_CHECK_EQUAL(nTimeouts, 1);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800186}
187
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800188
Alexander Afanasyev90164962014-03-06 08:29:59 +0000189BOOST_AUTO_TEST_CASE(SetFilter)
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800190{
191 Face face;
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700192 Face face2(face.getIoService());
193 Scheduler scheduler(face.getIoService());
Alexander Afanasyev9d158f02015-02-17 21:30:19 -0800194 scheduler.scheduleEvent(time::seconds(4),
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700195 bind(&FacesFixture::terminate, this, ref(face)));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700196
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800197 regPrefixId = face.setInterestFilter("/Hello/World",
Alexander Afanasyev90164962014-03-06 08:29:59 +0000198 bind(&FacesFixture::onInterest, this, ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700199 RegisterPrefixSuccessCallback(),
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800200 bind(&FacesFixture::onRegFailed, this));
201
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700202 scheduler.scheduleEvent(time::milliseconds(200),
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800203 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700204 ref(face2), Name("/Hello/World/!")));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700205
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800206 BOOST_REQUIRE_NO_THROW(face.processEvents());
207
Alexander Afanasyev90164962014-03-06 08:29:59 +0000208 BOOST_CHECK_EQUAL(nRegFailures, 0);
209 BOOST_CHECK_EQUAL(nInInterests, 1);
210 BOOST_CHECK_EQUAL(nTimeouts, 1);
211 BOOST_CHECK_EQUAL(nData, 0);
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800212}
213
Alexander Afanasyev90164962014-03-06 08:29:59 +0000214BOOST_AUTO_TEST_CASE(SetTwoFilters)
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800215{
216 Face face;
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700217 Face face2(face.getIoService());
218 Scheduler scheduler(face.getIoService());
Obaid6e7f5f12014-03-11 14:46:10 -0500219 scheduler.scheduleEvent(time::seconds(1),
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700220 bind(&FacesFixture::terminate, this, ref(face)));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700221
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800222 regPrefixId = face.setInterestFilter("/Hello/World",
Alexander Afanasyev90164962014-03-06 08:29:59 +0000223 bind(&FacesFixture::onInterest, this, ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700224 RegisterPrefixSuccessCallback(),
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800225 bind(&FacesFixture::onRegFailed, this));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700226
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800227 regPrefixId2 = face.setInterestFilter("/Los/Angeles/Lakers",
Alexander Afanasyev90164962014-03-06 08:29:59 +0000228 bind(&FacesFixture::onInterest2, this, ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700229 RegisterPrefixSuccessCallback(),
Alexander Afanasyev90164962014-03-06 08:29:59 +0000230 bind(&FacesFixture::onRegFailed, this));
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800231
232
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700233 scheduler.scheduleEvent(time::milliseconds(200),
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800234 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700235 ref(face2), Name("/Hello/World/!")));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700236
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800237 BOOST_REQUIRE_NO_THROW(face.processEvents());
238
Alexander Afanasyev90164962014-03-06 08:29:59 +0000239 BOOST_CHECK_EQUAL(nRegFailures, 0);
240 BOOST_CHECK_EQUAL(nInInterests, 1);
241 BOOST_CHECK_EQUAL(nInInterests2, 0);
242 BOOST_CHECK_EQUAL(nTimeouts, 1);
243 BOOST_CHECK_EQUAL(nData, 0);
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800244}
245
Alexander Afanasyev90164962014-03-06 08:29:59 +0000246BOOST_AUTO_TEST_CASE(SetRegexFilterError)
247{
248 Face face;
249 Face face2(face.getIoService());
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700250 Scheduler scheduler(face.getIoService());
Alexander Afanasyev9d158f02015-02-17 21:30:19 -0800251 scheduler.scheduleEvent(time::seconds(4),
Alexander Afanasyev90164962014-03-06 08:29:59 +0000252 bind(&FacesFixture::terminate, this, ref(face)));
253
254 regPrefixId = face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
255 bind(&FacesFixture::onInterestRegexError, this,
256 ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700257 RegisterPrefixSuccessCallback(),
Alexander Afanasyev90164962014-03-06 08:29:59 +0000258 bind(&FacesFixture::onRegFailed, this));
259
260 scheduler.scheduleEvent(time::milliseconds(300),
261 bind(&FacesFixture::expressInterest, this,
262 ref(face2), Name("/Hello/World/XXX/b/c"))); // should match
263
264 BOOST_REQUIRE_THROW(face.processEvents(), InterestFilter::Error);
265}
266
267BOOST_AUTO_TEST_CASE(SetRegexFilter)
268{
269 Face face;
270 Face face2(face.getIoService());
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700271 Scheduler scheduler(face.getIoService());
Alexander Afanasyev9d158f02015-02-17 21:30:19 -0800272 scheduler.scheduleEvent(time::seconds(4),
Alexander Afanasyev90164962014-03-06 08:29:59 +0000273 bind(&FacesFixture::terminate, this, ref(face)));
274
275 regPrefixId = face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
276 bind(&FacesFixture::onInterestRegex, this,
277 ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700278 RegisterPrefixSuccessCallback(),
Alexander Afanasyev90164962014-03-06 08:29:59 +0000279 bind(&FacesFixture::onRegFailed, this));
280
281 scheduler.scheduleEvent(time::milliseconds(200),
282 bind(&FacesFixture::expressInterest, this,
283 ref(face2), Name("/Hello/World/a"))); // shouldn't match
284
285 scheduler.scheduleEvent(time::milliseconds(300),
286 bind(&FacesFixture::expressInterest, this,
287 ref(face2), Name("/Hello/World/a/b"))); // should match
288
289 scheduler.scheduleEvent(time::milliseconds(400),
290 bind(&FacesFixture::expressInterest, this,
291 ref(face2), Name("/Hello/World/a/b/c"))); // should match
292
293 scheduler.scheduleEvent(time::milliseconds(500),
294 bind(&FacesFixture::expressInterest, this,
295 ref(face2), Name("/Hello/World/a/b/d"))); // should not match
296
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700297 BOOST_REQUIRE_NO_THROW(face.processEvents());
Alexander Afanasyev90164962014-03-06 08:29:59 +0000298
299 BOOST_CHECK_EQUAL(nRegFailures, 0);
300 BOOST_CHECK_EQUAL(nInInterests, 2);
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700301 BOOST_CHECK_EQUAL(nTimeouts, 4);
Alexander Afanasyev90164962014-03-06 08:29:59 +0000302 BOOST_CHECK_EQUAL(nData, 0);
303}
304
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700305class FacesFixture2 : public FacesFixture
306{
307public:
308 void
309 checkPrefix(bool doesExist)
310 {
Alexander Afanasyev9d158f02015-02-17 21:30:19 -0800311 int result = std::system("nfd-status -r | grep /Hello/World >/dev/null");
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700312
313 if (doesExist) {
314 BOOST_CHECK_EQUAL(result, 0);
315 }
316 else {
317 BOOST_CHECK_NE(result, 0);
318 }
319 }
320};
321
322BOOST_FIXTURE_TEST_CASE(RegisterUnregisterPrefix, FacesFixture2)
323{
324 Face face;
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700325 Scheduler scheduler(face.getIoService());
Alexander Afanasyev9d158f02015-02-17 21:30:19 -0800326 scheduler.scheduleEvent(time::seconds(4),
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700327 bind(&FacesFixture::terminate, this, ref(face)));
328
329 regPrefixId = face.setInterestFilter(InterestFilter("/Hello/World"),
330 bind(&FacesFixture::onInterest, this,
331 ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700332 RegisterPrefixSuccessCallback(),
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700333 bind(&FacesFixture::onRegFailed, this));
334
335 scheduler.scheduleEvent(time::milliseconds(500),
336 bind(&FacesFixture2::checkPrefix, this, true));
337
338 scheduler.scheduleEvent(time::seconds(1),
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700339 bind(static_cast<void(Face::*)(const RegisteredPrefixId*)>(&Face::unsetInterestFilter),
340 &face,
341 regPrefixId)); // shouldn't match
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700342
Alexander Afanasyev9d158f02015-02-17 21:30:19 -0800343 scheduler.scheduleEvent(time::milliseconds(2000),
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700344 bind(&FacesFixture2::checkPrefix, this, false));
345
346 BOOST_REQUIRE_NO_THROW(face.processEvents());
347}
Alexander Afanasyev90164962014-03-06 08:29:59 +0000348
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700349
350class FacesFixture3 : public FacesFixture2
351{
352public:
353 FacesFixture3()
354 : nRegSuccesses(0)
355 , nUnregSuccesses(0)
356 , nUnregFailures(0)
357 {
358 }
359
360 void
361 onRegSucceeded()
362 {
363 ++nRegSuccesses;
364 }
365
366 void
367 onUnregSucceeded()
368 {
369 ++nUnregSuccesses;
370 }
371
372 void
373 onUnregFailed()
374 {
375 ++nUnregFailures;
376 }
377
378public:
379 uint64_t nRegSuccesses;
380 uint64_t nUnregSuccesses;
381 uint64_t nUnregFailures;
382};
383
384BOOST_FIXTURE_TEST_CASE(RegisterPrefix, FacesFixture3)
385{
386 Face face;
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700387 Face face2(face.getIoService());
388 Scheduler scheduler(face.getIoService());
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700389 scheduler.scheduleEvent(time::seconds(2),
390 bind(&FacesFixture::terminate, this, ref(face)));
391
392 scheduler.scheduleEvent(time::milliseconds(500),
393 bind(&FacesFixture2::checkPrefix, this, true));
394
395 regPrefixId = face.registerPrefix("/Hello/World",
396 bind(&FacesFixture3::onRegSucceeded, this),
397 bind(&FacesFixture3::onRegFailed, this));
398
399 scheduler.scheduleEvent(time::seconds(1),
400 bind(&Face::unregisterPrefix, &face,
401 regPrefixId,
402 static_cast<UnregisterPrefixSuccessCallback>(bind(&FacesFixture3::onUnregSucceeded, this)),
403 static_cast<UnregisterPrefixFailureCallback>(bind(&FacesFixture3::onUnregFailed, this))));
404
Alexander Afanasyev9d158f02015-02-17 21:30:19 -0800405 scheduler.scheduleEvent(time::milliseconds(2500),
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700406 bind(&FacesFixture2::checkPrefix, this, false));
407
408 BOOST_REQUIRE_NO_THROW(face.processEvents());
409
410 BOOST_CHECK_EQUAL(nRegFailures, 0);
411 BOOST_CHECK_EQUAL(nRegSuccesses, 1);
412
413 BOOST_CHECK_EQUAL(nUnregFailures, 0);
414 BOOST_CHECK_EQUAL(nUnregSuccesses, 1);
415}
416
417BOOST_AUTO_TEST_CASE(SetRegexFilterButNoRegister)
418{
419 Face face;
420 Face face2(face.getIoService());
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700421 Scheduler scheduler(face.getIoService());
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700422 scheduler.scheduleEvent(time::seconds(2),
423 bind(&FacesFixture::terminate, this, ref(face)));
424
425 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
426 bind(&FacesFixture::onInterestRegex, this,
427 ref(face), _1, _2));
428
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700429 // prefix is not registered, and also does not match regex
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700430 scheduler.scheduleEvent(time::milliseconds(200),
431 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700432 ref(face2), Name("/Hello/World/a")));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700433
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700434 // matches regex, but prefix is not registered
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700435 scheduler.scheduleEvent(time::milliseconds(300),
436 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700437 ref(face2), Name("/Hello/World/a/b")));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700438
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700439 // matches regex, but prefix is not registered
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700440 scheduler.scheduleEvent(time::milliseconds(400),
441 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700442 ref(face2), Name("/Hello/World/a/b/c")));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700443
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700444 // prefix is not registered, and also does not match regex
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700445 scheduler.scheduleEvent(time::milliseconds(500),
446 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700447 ref(face2), Name("/Hello/World/a/b/d")));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700448
449 BOOST_REQUIRE_NO_THROW(face.processEvents());
450
451 BOOST_CHECK_EQUAL(nRegFailures, 0);
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700452 BOOST_CHECK_EQUAL(nInInterests, 0);
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700453 BOOST_CHECK_EQUAL(nTimeouts, 4);
454 BOOST_CHECK_EQUAL(nData, 0);
455}
456
457
458BOOST_FIXTURE_TEST_CASE(SetRegexFilterAndRegister, FacesFixture3)
459{
460 Face face;
461 Face face2(face.getIoService());
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700462 Scheduler scheduler(face.getIoService());
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700463 scheduler.scheduleEvent(time::seconds(2),
464 bind(&FacesFixture::terminate, this, ref(face)));
465
466 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
467 bind(&FacesFixture::onInterestRegex, this,
468 ref(face), _1, _2));
469
470 face.registerPrefix("/Hello/World",
471 bind(&FacesFixture3::onRegSucceeded, this),
472 bind(&FacesFixture3::onRegFailed, this));
473
474 scheduler.scheduleEvent(time::milliseconds(200),
475 bind(&FacesFixture::expressInterest, this,
476 ref(face2), Name("/Hello/World/a"))); // shouldn't match
477
478 scheduler.scheduleEvent(time::milliseconds(300),
479 bind(&FacesFixture::expressInterest, this,
480 ref(face2), Name("/Hello/World/a/b"))); // should match
481
482 scheduler.scheduleEvent(time::milliseconds(400),
483 bind(&FacesFixture::expressInterest, this,
484 ref(face2), Name("/Hello/World/a/b/c"))); // should match
485
486 scheduler.scheduleEvent(time::milliseconds(500),
487 bind(&FacesFixture::expressInterest, this,
488 ref(face2), Name("/Hello/World/a/b/d"))); // should not match
489
490 BOOST_REQUIRE_NO_THROW(face.processEvents());
491
492 BOOST_CHECK_EQUAL(nRegFailures, 0);
493 BOOST_CHECK_EQUAL(nRegSuccesses, 1);
494
495 BOOST_CHECK_EQUAL(nInInterests, 2);
496 BOOST_CHECK_EQUAL(nTimeouts, 4);
497}
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400498
Alexander Afanasyevfba1ac62015-08-26 15:19:13 -0700499BOOST_AUTO_TEST_CASE(ShutdownWhileSendInProgress) // Bug #3136
500{
501 Face face;
502 face.expressInterest(Name("/Hello/World/!"), bind([]{}), bind([]{}));
503 BOOST_REQUIRE_NO_THROW(face.processEvents(time::seconds(1)));
504
505 face.expressInterest(Name("/Bye/World/1"), bind([]{}), bind([]{}));
506 face.expressInterest(Name("/Bye/World/2"), bind([]{}), bind([]{}));
507 face.expressInterest(Name("/Bye/World/3"), bind([]{}), bind([]{}));
508 face.shutdown();
509
510 BOOST_REQUIRE_NO_THROW(face.processEvents(time::seconds(1)));
511 // should not segfault
512}
513
Alexander Afanasyeve508f142015-09-01 15:14:45 -0700514BOOST_AUTO_TEST_CASE(LargeDelayBetweenFaceConstructorAndProcessEvents) // Bug #2742
515{
516 ndn::Face face;
517
518 ::sleep(5); // simulate setup workload
519
520 BOOST_CHECK_NO_THROW(face.processEvents(time::seconds(1)));
521}
522
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800523BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -0800524
Alexander Afanasyev5fc795f2014-10-20 23:06:56 -0400525} // tests
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -0800526} // namespace ndn