blob: c86cd62b0db114cfe3520e9b246461f9650a53a9 [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 Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 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 Afanasyev09c613f2014-01-29 00:23:58 -080022#include "face.hpp"
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -080023#include "util/scheduler.hpp"
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080024
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070025#include "boost-test.hpp"
26
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080027namespace ndn {
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080028
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080029
Alexander Afanasyev90164962014-03-06 08:29:59 +000030class FacesFixture
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080031{
Alexander Afanasyev90164962014-03-06 08:29:59 +000032public:
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080033 FacesFixture()
Alexander Afanasyev90164962014-03-06 08:29:59 +000034 : nData(0)
35 , nTimeouts(0)
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -080036 , regPrefixId(0)
Alexander Afanasyev90164962014-03-06 08:29:59 +000037 , nInInterests(0)
38 , nInInterests2(0)
39 , nRegFailures(0)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080040 {
41 }
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070042
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080043 void
44 onData()
45 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000046 ++nData;
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080047 }
48
49 void
50 onTimeout()
51 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000052 ++nTimeouts;
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080053 }
54
55 void
Alexander Afanasyev90164962014-03-06 08:29:59 +000056 onInterest(Face& face,
57 const Name&, const Interest&)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080058 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000059 ++nInInterests;
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -080060
61 face.unsetInterestFilter(regPrefixId);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080062 }
63
64 void
Alexander Afanasyev90164962014-03-06 08:29:59 +000065 onInterest2(Face& face,
66 const Name&, const Interest&)
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -080067 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000068 ++nInInterests2;
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -080069
70 face.unsetInterestFilter(regPrefixId2);
71 }
72
73 void
Alexander Afanasyev90164962014-03-06 08:29:59 +000074 onInterestRegex(Face& face,
75 const InterestFilter&, const Interest&)
76 {
77 ++nInInterests;
78 }
79
80 void
81 onInterestRegexError(Face& face,
82 const Name&, const Interest&)
83 {
84 BOOST_FAIL("InterestFilter::Error should have been triggered");
85 }
86
87 void
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080088 onRegFailed()
89 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000090 ++nRegFailures;
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -080091 }
92
93 void
94 expressInterest(Face& face, const Name& name)
95 {
96 Interest i(name);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070097 i.setInterestLifetime(time::milliseconds(50));
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -080098 face.expressInterest(i,
99 bind(&FacesFixture::onData, this),
100 bind(&FacesFixture::onTimeout, this));
101 }
102
103 void
104 terminate(Face& face)
105 {
106 face.shutdown();
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800107 }
108
Alexander Afanasyev90164962014-03-06 08:29:59 +0000109 uint32_t nData;
110 uint32_t nTimeouts;
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800111
112 const RegisteredPrefixId* regPrefixId;
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800113 const RegisteredPrefixId* regPrefixId2;
Alexander Afanasyev90164962014-03-06 08:29:59 +0000114 uint32_t nInInterests;
115 uint32_t nInInterests2;
116 uint32_t nRegFailures;
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800117};
118
Alexander Afanasyev90164962014-03-06 08:29:59 +0000119BOOST_FIXTURE_TEST_SUITE(TestFaces, FacesFixture)
120
121BOOST_AUTO_TEST_CASE(Unix)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800122{
123 Face face;
124
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700125 face.expressInterest(Interest("/", time::milliseconds(1000)),
126 bind(&FacesFixture::onData, this),
127 bind(&FacesFixture::onTimeout, this));
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800128
129 BOOST_REQUIRE_NO_THROW(face.processEvents());
130
Alexander Afanasyev90164962014-03-06 08:29:59 +0000131 BOOST_CHECK_EQUAL(nData, 1);
132 BOOST_CHECK_EQUAL(nTimeouts, 0);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800133
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700134 face.expressInterest(Interest("/localhost/non-existing/data/should/not/exist/anywhere",
135 time::milliseconds(50)),
136 bind(&FacesFixture::onData, this),
137 bind(&FacesFixture::onTimeout, this));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700138
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800139 BOOST_REQUIRE_NO_THROW(face.processEvents());
140
Alexander Afanasyev90164962014-03-06 08:29:59 +0000141 BOOST_CHECK_EQUAL(nData, 1);
142 BOOST_CHECK_EQUAL(nTimeouts, 1);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800143}
144
Alexander Afanasyev90164962014-03-06 08:29:59 +0000145BOOST_AUTO_TEST_CASE(Tcp)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800146{
147 Face face("localhost");
148
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700149 face.expressInterest(Interest("/", time::milliseconds(1000)),
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800150 bind(&FacesFixture::onData, this),
151 bind(&FacesFixture::onTimeout, this));
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800152
153 BOOST_REQUIRE_NO_THROW(face.processEvents());
154
Alexander Afanasyev90164962014-03-06 08:29:59 +0000155 BOOST_CHECK_EQUAL(nData, 1);
156 BOOST_CHECK_EQUAL(nTimeouts, 0);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800157
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700158 face.expressInterest(Interest("/localhost/non-existing/data/should/not/exist/anywhere",
159 time::milliseconds(50)),
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800160 bind(&FacesFixture::onData, this),
161 bind(&FacesFixture::onTimeout, this));
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800162
163 BOOST_REQUIRE_NO_THROW(face.processEvents());
164
Alexander Afanasyev90164962014-03-06 08:29:59 +0000165 BOOST_CHECK_EQUAL(nData, 1);
166 BOOST_CHECK_EQUAL(nTimeouts, 1);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800167}
168
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800169
Alexander Afanasyev90164962014-03-06 08:29:59 +0000170BOOST_AUTO_TEST_CASE(SetFilter)
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800171{
172 Face face;
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700173 Face face2(face.getIoService());
174 Scheduler scheduler(face.getIoService());
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700175 scheduler.scheduleEvent(time::milliseconds(300),
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700176 bind(&FacesFixture::terminate, this, ref(face)));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700177
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800178 regPrefixId = face.setInterestFilter("/Hello/World",
Alexander Afanasyev90164962014-03-06 08:29:59 +0000179 bind(&FacesFixture::onInterest, this, ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700180 RegisterPrefixSuccessCallback(),
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800181 bind(&FacesFixture::onRegFailed, this));
182
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700183 scheduler.scheduleEvent(time::milliseconds(200),
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800184 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700185 ref(face2), Name("/Hello/World/!")));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700186
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800187 BOOST_REQUIRE_NO_THROW(face.processEvents());
188
Alexander Afanasyev90164962014-03-06 08:29:59 +0000189 BOOST_CHECK_EQUAL(nRegFailures, 0);
190 BOOST_CHECK_EQUAL(nInInterests, 1);
191 BOOST_CHECK_EQUAL(nTimeouts, 1);
192 BOOST_CHECK_EQUAL(nData, 0);
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800193}
194
Alexander Afanasyev90164962014-03-06 08:29:59 +0000195BOOST_AUTO_TEST_CASE(SetTwoFilters)
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800196{
197 Face face;
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700198 Face face2(face.getIoService());
199 Scheduler scheduler(face.getIoService());
Obaid6e7f5f12014-03-11 14:46:10 -0500200 scheduler.scheduleEvent(time::seconds(1),
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700201 bind(&FacesFixture::terminate, this, ref(face)));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700202
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800203 regPrefixId = face.setInterestFilter("/Hello/World",
Alexander Afanasyev90164962014-03-06 08:29:59 +0000204 bind(&FacesFixture::onInterest, this, ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700205 RegisterPrefixSuccessCallback(),
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800206 bind(&FacesFixture::onRegFailed, this));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700207
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800208 regPrefixId2 = face.setInterestFilter("/Los/Angeles/Lakers",
Alexander Afanasyev90164962014-03-06 08:29:59 +0000209 bind(&FacesFixture::onInterest2, this, ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700210 RegisterPrefixSuccessCallback(),
Alexander Afanasyev90164962014-03-06 08:29:59 +0000211 bind(&FacesFixture::onRegFailed, this));
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800212
213
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700214 scheduler.scheduleEvent(time::milliseconds(200),
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800215 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700216 ref(face2), Name("/Hello/World/!")));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700217
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800218 BOOST_REQUIRE_NO_THROW(face.processEvents());
219
Alexander Afanasyev90164962014-03-06 08:29:59 +0000220 BOOST_CHECK_EQUAL(nRegFailures, 0);
221 BOOST_CHECK_EQUAL(nInInterests, 1);
222 BOOST_CHECK_EQUAL(nInInterests2, 0);
223 BOOST_CHECK_EQUAL(nTimeouts, 1);
224 BOOST_CHECK_EQUAL(nData, 0);
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800225}
226
Alexander Afanasyev90164962014-03-06 08:29:59 +0000227BOOST_AUTO_TEST_CASE(SetRegexFilterError)
228{
229 Face face;
230 Face face2(face.getIoService());
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700231 Scheduler scheduler(face.getIoService());
Alexander Afanasyev90164962014-03-06 08:29:59 +0000232 scheduler.scheduleEvent(time::seconds(1),
233 bind(&FacesFixture::terminate, this, ref(face)));
234
235 regPrefixId = face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
236 bind(&FacesFixture::onInterestRegexError, this,
237 ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700238 RegisterPrefixSuccessCallback(),
Alexander Afanasyev90164962014-03-06 08:29:59 +0000239 bind(&FacesFixture::onRegFailed, this));
240
241 scheduler.scheduleEvent(time::milliseconds(300),
242 bind(&FacesFixture::expressInterest, this,
243 ref(face2), Name("/Hello/World/XXX/b/c"))); // should match
244
245 BOOST_REQUIRE_THROW(face.processEvents(), InterestFilter::Error);
246}
247
248BOOST_AUTO_TEST_CASE(SetRegexFilter)
249{
250 Face face;
251 Face face2(face.getIoService());
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700252 Scheduler scheduler(face.getIoService());
Alexander Afanasyev90164962014-03-06 08:29:59 +0000253 scheduler.scheduleEvent(time::seconds(2),
254 bind(&FacesFixture::terminate, this, ref(face)));
255
256 regPrefixId = face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
257 bind(&FacesFixture::onInterestRegex, this,
258 ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700259 RegisterPrefixSuccessCallback(),
Alexander Afanasyev90164962014-03-06 08:29:59 +0000260 bind(&FacesFixture::onRegFailed, this));
261
262 scheduler.scheduleEvent(time::milliseconds(200),
263 bind(&FacesFixture::expressInterest, this,
264 ref(face2), Name("/Hello/World/a"))); // shouldn't match
265
266 scheduler.scheduleEvent(time::milliseconds(300),
267 bind(&FacesFixture::expressInterest, this,
268 ref(face2), Name("/Hello/World/a/b"))); // should match
269
270 scheduler.scheduleEvent(time::milliseconds(400),
271 bind(&FacesFixture::expressInterest, this,
272 ref(face2), Name("/Hello/World/a/b/c"))); // should match
273
274 scheduler.scheduleEvent(time::milliseconds(500),
275 bind(&FacesFixture::expressInterest, this,
276 ref(face2), Name("/Hello/World/a/b/d"))); // should not match
277
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700278 BOOST_REQUIRE_NO_THROW(face.processEvents());
Alexander Afanasyev90164962014-03-06 08:29:59 +0000279
280 BOOST_CHECK_EQUAL(nRegFailures, 0);
281 BOOST_CHECK_EQUAL(nInInterests, 2);
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700282 BOOST_CHECK_EQUAL(nTimeouts, 4);
Alexander Afanasyev90164962014-03-06 08:29:59 +0000283 BOOST_CHECK_EQUAL(nData, 0);
284}
285
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700286class FacesFixture2 : public FacesFixture
287{
288public:
289 void
290 checkPrefix(bool doesExist)
291 {
292 int result = std::system("nfd-status | grep /Hello/World >/dev/null");
293
294 if (doesExist) {
295 BOOST_CHECK_EQUAL(result, 0);
296 }
297 else {
298 BOOST_CHECK_NE(result, 0);
299 }
300 }
301};
302
303BOOST_FIXTURE_TEST_CASE(RegisterUnregisterPrefix, FacesFixture2)
304{
305 Face face;
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700306 Scheduler scheduler(face.getIoService());
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700307 scheduler.scheduleEvent(time::seconds(2),
308 bind(&FacesFixture::terminate, this, ref(face)));
309
310 regPrefixId = face.setInterestFilter(InterestFilter("/Hello/World"),
311 bind(&FacesFixture::onInterest, this,
312 ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700313 RegisterPrefixSuccessCallback(),
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700314 bind(&FacesFixture::onRegFailed, this));
315
316 scheduler.scheduleEvent(time::milliseconds(500),
317 bind(&FacesFixture2::checkPrefix, this, true));
318
319 scheduler.scheduleEvent(time::seconds(1),
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700320 bind(static_cast<void(Face::*)(const RegisteredPrefixId*)>(&Face::unsetInterestFilter),
321 &face,
322 regPrefixId)); // shouldn't match
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700323
324 scheduler.scheduleEvent(time::milliseconds(1500),
325 bind(&FacesFixture2::checkPrefix, this, false));
326
327 BOOST_REQUIRE_NO_THROW(face.processEvents());
328}
Alexander Afanasyev90164962014-03-06 08:29:59 +0000329
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700330
331class FacesFixture3 : public FacesFixture2
332{
333public:
334 FacesFixture3()
335 : nRegSuccesses(0)
336 , nUnregSuccesses(0)
337 , nUnregFailures(0)
338 {
339 }
340
341 void
342 onRegSucceeded()
343 {
344 ++nRegSuccesses;
345 }
346
347 void
348 onUnregSucceeded()
349 {
350 ++nUnregSuccesses;
351 }
352
353 void
354 onUnregFailed()
355 {
356 ++nUnregFailures;
357 }
358
359public:
360 uint64_t nRegSuccesses;
361 uint64_t nUnregSuccesses;
362 uint64_t nUnregFailures;
363};
364
365BOOST_FIXTURE_TEST_CASE(RegisterPrefix, FacesFixture3)
366{
367 Face face;
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700368 Face face2(face.getIoService());
369 Scheduler scheduler(face.getIoService());
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700370 scheduler.scheduleEvent(time::seconds(2),
371 bind(&FacesFixture::terminate, this, ref(face)));
372
373 scheduler.scheduleEvent(time::milliseconds(500),
374 bind(&FacesFixture2::checkPrefix, this, true));
375
376 regPrefixId = face.registerPrefix("/Hello/World",
377 bind(&FacesFixture3::onRegSucceeded, this),
378 bind(&FacesFixture3::onRegFailed, this));
379
380 scheduler.scheduleEvent(time::seconds(1),
381 bind(&Face::unregisterPrefix, &face,
382 regPrefixId,
383 static_cast<UnregisterPrefixSuccessCallback>(bind(&FacesFixture3::onUnregSucceeded, this)),
384 static_cast<UnregisterPrefixFailureCallback>(bind(&FacesFixture3::onUnregFailed, this))));
385
386 scheduler.scheduleEvent(time::milliseconds(1500),
387 bind(&FacesFixture2::checkPrefix, this, false));
388
389 BOOST_REQUIRE_NO_THROW(face.processEvents());
390
391 BOOST_CHECK_EQUAL(nRegFailures, 0);
392 BOOST_CHECK_EQUAL(nRegSuccesses, 1);
393
394 BOOST_CHECK_EQUAL(nUnregFailures, 0);
395 BOOST_CHECK_EQUAL(nUnregSuccesses, 1);
396}
397
398BOOST_AUTO_TEST_CASE(SetRegexFilterButNoRegister)
399{
400 Face face;
401 Face face2(face.getIoService());
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700402 Scheduler scheduler(face.getIoService());
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700403 scheduler.scheduleEvent(time::seconds(2),
404 bind(&FacesFixture::terminate, this, ref(face)));
405
406 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
407 bind(&FacesFixture::onInterestRegex, this,
408 ref(face), _1, _2));
409
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700410 // prefix is not registered, and also does not match regex
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700411 scheduler.scheduleEvent(time::milliseconds(200),
412 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700413 ref(face2), Name("/Hello/World/a")));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700414
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700415 // matches regex, but prefix is not registered
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700416 scheduler.scheduleEvent(time::milliseconds(300),
417 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700418 ref(face2), Name("/Hello/World/a/b")));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700419
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700420 // matches regex, but prefix is not registered
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700421 scheduler.scheduleEvent(time::milliseconds(400),
422 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700423 ref(face2), Name("/Hello/World/a/b/c")));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700424
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700425 // prefix is not registered, and also does not match regex
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700426 scheduler.scheduleEvent(time::milliseconds(500),
427 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700428 ref(face2), Name("/Hello/World/a/b/d")));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700429
430 BOOST_REQUIRE_NO_THROW(face.processEvents());
431
432 BOOST_CHECK_EQUAL(nRegFailures, 0);
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700433 BOOST_CHECK_EQUAL(nInInterests, 0);
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700434 BOOST_CHECK_EQUAL(nTimeouts, 4);
435 BOOST_CHECK_EQUAL(nData, 0);
436}
437
438
439BOOST_FIXTURE_TEST_CASE(SetRegexFilterAndRegister, FacesFixture3)
440{
441 Face face;
442 Face face2(face.getIoService());
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700443 Scheduler scheduler(face.getIoService());
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700444 scheduler.scheduleEvent(time::seconds(2),
445 bind(&FacesFixture::terminate, this, ref(face)));
446
447 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
448 bind(&FacesFixture::onInterestRegex, this,
449 ref(face), _1, _2));
450
451 face.registerPrefix("/Hello/World",
452 bind(&FacesFixture3::onRegSucceeded, this),
453 bind(&FacesFixture3::onRegFailed, this));
454
455 scheduler.scheduleEvent(time::milliseconds(200),
456 bind(&FacesFixture::expressInterest, this,
457 ref(face2), Name("/Hello/World/a"))); // shouldn't match
458
459 scheduler.scheduleEvent(time::milliseconds(300),
460 bind(&FacesFixture::expressInterest, this,
461 ref(face2), Name("/Hello/World/a/b"))); // should match
462
463 scheduler.scheduleEvent(time::milliseconds(400),
464 bind(&FacesFixture::expressInterest, this,
465 ref(face2), Name("/Hello/World/a/b/c"))); // should match
466
467 scheduler.scheduleEvent(time::milliseconds(500),
468 bind(&FacesFixture::expressInterest, this,
469 ref(face2), Name("/Hello/World/a/b/d"))); // should not match
470
471 BOOST_REQUIRE_NO_THROW(face.processEvents());
472
473 BOOST_CHECK_EQUAL(nRegFailures, 0);
474 BOOST_CHECK_EQUAL(nRegSuccesses, 1);
475
476 BOOST_CHECK_EQUAL(nInInterests, 2);
477 BOOST_CHECK_EQUAL(nTimeouts, 4);
478}
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800479BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -0800480
481} // namespace ndn