blob: e99f0fc8e5b59ea4f2d98468112482ad7456d4a1 [file] [log] [blame]
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev20d2c582014-01-26 15:32:51 -08002/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080011 */
12
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080013#include "face.hpp"
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -080014#include "util/scheduler.hpp"
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080015
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070016#include "boost-test.hpp"
17
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080018namespace ndn {
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080019
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080020
Alexander Afanasyev90164962014-03-06 08:29:59 +000021class FacesFixture
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080022{
Alexander Afanasyev90164962014-03-06 08:29:59 +000023public:
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080024 FacesFixture()
Alexander Afanasyev90164962014-03-06 08:29:59 +000025 : nData(0)
26 , nTimeouts(0)
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -080027 , regPrefixId(0)
Alexander Afanasyev90164962014-03-06 08:29:59 +000028 , nInInterests(0)
29 , nInInterests2(0)
30 , nRegFailures(0)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080031 {
32 }
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070033
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080034 void
35 onData()
36 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000037 ++nData;
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080038 }
39
40 void
41 onTimeout()
42 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000043 ++nTimeouts;
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080044 }
45
46 void
Alexander Afanasyev90164962014-03-06 08:29:59 +000047 onInterest(Face& face,
48 const Name&, const Interest&)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080049 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000050 ++nInInterests;
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -080051
52 face.unsetInterestFilter(regPrefixId);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080053 }
54
55 void
Alexander Afanasyev90164962014-03-06 08:29:59 +000056 onInterest2(Face& face,
57 const Name&, const Interest&)
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -080058 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000059 ++nInInterests2;
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -080060
61 face.unsetInterestFilter(regPrefixId2);
62 }
63
64 void
Alexander Afanasyev90164962014-03-06 08:29:59 +000065 onInterestRegex(Face& face,
66 const InterestFilter&, const Interest&)
67 {
68 ++nInInterests;
69 }
70
71 void
72 onInterestRegexError(Face& face,
73 const Name&, const Interest&)
74 {
75 BOOST_FAIL("InterestFilter::Error should have been triggered");
76 }
77
78 void
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080079 onRegFailed()
80 {
Alexander Afanasyev90164962014-03-06 08:29:59 +000081 ++nRegFailures;
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -080082 }
83
84 void
85 expressInterest(Face& face, const Name& name)
86 {
87 Interest i(name);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070088 i.setInterestLifetime(time::milliseconds(50));
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -080089 face.expressInterest(i,
90 bind(&FacesFixture::onData, this),
91 bind(&FacesFixture::onTimeout, this));
92 }
93
94 void
95 terminate(Face& face)
96 {
97 face.shutdown();
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080098 }
99
Alexander Afanasyev90164962014-03-06 08:29:59 +0000100 uint32_t nData;
101 uint32_t nTimeouts;
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800102
103 const RegisteredPrefixId* regPrefixId;
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800104 const RegisteredPrefixId* regPrefixId2;
Alexander Afanasyev90164962014-03-06 08:29:59 +0000105 uint32_t nInInterests;
106 uint32_t nInInterests2;
107 uint32_t nRegFailures;
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800108};
109
Alexander Afanasyev90164962014-03-06 08:29:59 +0000110BOOST_FIXTURE_TEST_SUITE(TestFaces, FacesFixture)
111
112BOOST_AUTO_TEST_CASE(Unix)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800113{
114 Face face;
115
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700116 face.expressInterest(Interest("/", time::milliseconds(1000)),
117 bind(&FacesFixture::onData, this),
118 bind(&FacesFixture::onTimeout, this));
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800119
120 BOOST_REQUIRE_NO_THROW(face.processEvents());
121
Alexander Afanasyev90164962014-03-06 08:29:59 +0000122 BOOST_CHECK_EQUAL(nData, 1);
123 BOOST_CHECK_EQUAL(nTimeouts, 0);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800124
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700125 face.expressInterest(Interest("/localhost/non-existing/data/should/not/exist/anywhere",
126 time::milliseconds(50)),
127 bind(&FacesFixture::onData, this),
128 bind(&FacesFixture::onTimeout, this));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700129
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800130 BOOST_REQUIRE_NO_THROW(face.processEvents());
131
Alexander Afanasyev90164962014-03-06 08:29:59 +0000132 BOOST_CHECK_EQUAL(nData, 1);
133 BOOST_CHECK_EQUAL(nTimeouts, 1);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800134}
135
Alexander Afanasyev90164962014-03-06 08:29:59 +0000136BOOST_AUTO_TEST_CASE(Tcp)
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800137{
138 Face face("localhost");
139
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700140 face.expressInterest(Interest("/", time::milliseconds(1000)),
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800141 bind(&FacesFixture::onData, this),
142 bind(&FacesFixture::onTimeout, this));
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800143
144 BOOST_REQUIRE_NO_THROW(face.processEvents());
145
Alexander Afanasyev90164962014-03-06 08:29:59 +0000146 BOOST_CHECK_EQUAL(nData, 1);
147 BOOST_CHECK_EQUAL(nTimeouts, 0);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800148
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700149 face.expressInterest(Interest("/localhost/non-existing/data/should/not/exist/anywhere",
150 time::milliseconds(50)),
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800151 bind(&FacesFixture::onData, this),
152 bind(&FacesFixture::onTimeout, this));
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800153
154 BOOST_REQUIRE_NO_THROW(face.processEvents());
155
Alexander Afanasyev90164962014-03-06 08:29:59 +0000156 BOOST_CHECK_EQUAL(nData, 1);
157 BOOST_CHECK_EQUAL(nTimeouts, 1);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800158}
159
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800160
Alexander Afanasyev90164962014-03-06 08:29:59 +0000161BOOST_AUTO_TEST_CASE(SetFilter)
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800162{
163 Face face;
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700164 Face face2(face.getIoService());
165 Scheduler scheduler(face.getIoService());
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700166 scheduler.scheduleEvent(time::milliseconds(300),
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700167 bind(&FacesFixture::terminate, this, ref(face)));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700168
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800169 regPrefixId = face.setInterestFilter("/Hello/World",
Alexander Afanasyev90164962014-03-06 08:29:59 +0000170 bind(&FacesFixture::onInterest, this, ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700171 RegisterPrefixSuccessCallback(),
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800172 bind(&FacesFixture::onRegFailed, this));
173
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700174 scheduler.scheduleEvent(time::milliseconds(200),
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800175 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700176 ref(face2), Name("/Hello/World/!")));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700177
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800178 BOOST_REQUIRE_NO_THROW(face.processEvents());
179
Alexander Afanasyev90164962014-03-06 08:29:59 +0000180 BOOST_CHECK_EQUAL(nRegFailures, 0);
181 BOOST_CHECK_EQUAL(nInInterests, 1);
182 BOOST_CHECK_EQUAL(nTimeouts, 1);
183 BOOST_CHECK_EQUAL(nData, 0);
Alexander Afanasyevbf9671d2014-02-11 13:44:13 -0800184}
185
Alexander Afanasyev90164962014-03-06 08:29:59 +0000186BOOST_AUTO_TEST_CASE(SetTwoFilters)
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800187{
188 Face face;
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700189 Face face2(face.getIoService());
190 Scheduler scheduler(face.getIoService());
Obaid6e7f5f12014-03-11 14:46:10 -0500191 scheduler.scheduleEvent(time::seconds(1),
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700192 bind(&FacesFixture::terminate, this, ref(face)));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700193
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800194 regPrefixId = face.setInterestFilter("/Hello/World",
Alexander Afanasyev90164962014-03-06 08:29:59 +0000195 bind(&FacesFixture::onInterest, this, ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700196 RegisterPrefixSuccessCallback(),
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800197 bind(&FacesFixture::onRegFailed, this));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700198
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800199 regPrefixId2 = face.setInterestFilter("/Los/Angeles/Lakers",
Alexander Afanasyev90164962014-03-06 08:29:59 +0000200 bind(&FacesFixture::onInterest2, this, ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700201 RegisterPrefixSuccessCallback(),
Alexander Afanasyev90164962014-03-06 08:29:59 +0000202 bind(&FacesFixture::onRegFailed, this));
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800203
204
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700205 scheduler.scheduleEvent(time::milliseconds(200),
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800206 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyevb67090a2014-04-29 22:31:01 -0700207 ref(face2), Name("/Hello/World/!")));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700208
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800209 BOOST_REQUIRE_NO_THROW(face.processEvents());
210
Alexander Afanasyev90164962014-03-06 08:29:59 +0000211 BOOST_CHECK_EQUAL(nRegFailures, 0);
212 BOOST_CHECK_EQUAL(nInInterests, 1);
213 BOOST_CHECK_EQUAL(nInInterests2, 0);
214 BOOST_CHECK_EQUAL(nTimeouts, 1);
215 BOOST_CHECK_EQUAL(nData, 0);
Alexander Afanasyeva68aa7f2014-02-11 15:42:33 -0800216}
217
Alexander Afanasyev90164962014-03-06 08:29:59 +0000218BOOST_AUTO_TEST_CASE(SetRegexFilterError)
219{
220 Face face;
221 Face face2(face.getIoService());
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700222 Scheduler scheduler(face.getIoService());
Alexander Afanasyev90164962014-03-06 08:29:59 +0000223 scheduler.scheduleEvent(time::seconds(1),
224 bind(&FacesFixture::terminate, this, ref(face)));
225
226 regPrefixId = face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
227 bind(&FacesFixture::onInterestRegexError, this,
228 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));
231
232 scheduler.scheduleEvent(time::milliseconds(300),
233 bind(&FacesFixture::expressInterest, this,
234 ref(face2), Name("/Hello/World/XXX/b/c"))); // should match
235
236 BOOST_REQUIRE_THROW(face.processEvents(), InterestFilter::Error);
237}
238
239BOOST_AUTO_TEST_CASE(SetRegexFilter)
240{
241 Face face;
242 Face face2(face.getIoService());
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700243 Scheduler scheduler(face.getIoService());
Alexander Afanasyev90164962014-03-06 08:29:59 +0000244 scheduler.scheduleEvent(time::seconds(2),
245 bind(&FacesFixture::terminate, this, ref(face)));
246
247 regPrefixId = face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
248 bind(&FacesFixture::onInterestRegex, this,
249 ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700250 RegisterPrefixSuccessCallback(),
Alexander Afanasyev90164962014-03-06 08:29:59 +0000251 bind(&FacesFixture::onRegFailed, this));
252
253 scheduler.scheduleEvent(time::milliseconds(200),
254 bind(&FacesFixture::expressInterest, this,
255 ref(face2), Name("/Hello/World/a"))); // shouldn't match
256
257 scheduler.scheduleEvent(time::milliseconds(300),
258 bind(&FacesFixture::expressInterest, this,
259 ref(face2), Name("/Hello/World/a/b"))); // should match
260
261 scheduler.scheduleEvent(time::milliseconds(400),
262 bind(&FacesFixture::expressInterest, this,
263 ref(face2), Name("/Hello/World/a/b/c"))); // should match
264
265 scheduler.scheduleEvent(time::milliseconds(500),
266 bind(&FacesFixture::expressInterest, this,
267 ref(face2), Name("/Hello/World/a/b/d"))); // should not match
268
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700269 BOOST_REQUIRE_NO_THROW(face.processEvents());
Alexander Afanasyev90164962014-03-06 08:29:59 +0000270
271 BOOST_CHECK_EQUAL(nRegFailures, 0);
272 BOOST_CHECK_EQUAL(nInInterests, 2);
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700273 BOOST_CHECK_EQUAL(nTimeouts, 4);
Alexander Afanasyev90164962014-03-06 08:29:59 +0000274 BOOST_CHECK_EQUAL(nData, 0);
275}
276
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700277class FacesFixture2 : public FacesFixture
278{
279public:
280 void
281 checkPrefix(bool doesExist)
282 {
283 int result = std::system("nfd-status | grep /Hello/World >/dev/null");
284
285 if (doesExist) {
286 BOOST_CHECK_EQUAL(result, 0);
287 }
288 else {
289 BOOST_CHECK_NE(result, 0);
290 }
291 }
292};
293
294BOOST_FIXTURE_TEST_CASE(RegisterUnregisterPrefix, FacesFixture2)
295{
296 Face face;
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700297 Scheduler scheduler(face.getIoService());
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700298 scheduler.scheduleEvent(time::seconds(2),
299 bind(&FacesFixture::terminate, this, ref(face)));
300
301 regPrefixId = face.setInterestFilter(InterestFilter("/Hello/World"),
302 bind(&FacesFixture::onInterest, this,
303 ref(face), _1, _2),
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700304 RegisterPrefixSuccessCallback(),
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700305 bind(&FacesFixture::onRegFailed, this));
306
307 scheduler.scheduleEvent(time::milliseconds(500),
308 bind(&FacesFixture2::checkPrefix, this, true));
309
310 scheduler.scheduleEvent(time::seconds(1),
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700311 bind(static_cast<void(Face::*)(const RegisteredPrefixId*)>(&Face::unsetInterestFilter),
312 &face,
313 regPrefixId)); // shouldn't match
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -0700314
315 scheduler.scheduleEvent(time::milliseconds(1500),
316 bind(&FacesFixture2::checkPrefix, this, false));
317
318 BOOST_REQUIRE_NO_THROW(face.processEvents());
319}
Alexander Afanasyev90164962014-03-06 08:29:59 +0000320
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700321
322class FacesFixture3 : public FacesFixture2
323{
324public:
325 FacesFixture3()
326 : nRegSuccesses(0)
327 , nUnregSuccesses(0)
328 , nUnregFailures(0)
329 {
330 }
331
332 void
333 onRegSucceeded()
334 {
335 ++nRegSuccesses;
336 }
337
338 void
339 onUnregSucceeded()
340 {
341 ++nUnregSuccesses;
342 }
343
344 void
345 onUnregFailed()
346 {
347 ++nUnregFailures;
348 }
349
350public:
351 uint64_t nRegSuccesses;
352 uint64_t nUnregSuccesses;
353 uint64_t nUnregFailures;
354};
355
356BOOST_FIXTURE_TEST_CASE(RegisterPrefix, FacesFixture3)
357{
358 Face face;
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700359 Face face2(face.getIoService());
360 Scheduler scheduler(face.getIoService());
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700361 scheduler.scheduleEvent(time::seconds(2),
362 bind(&FacesFixture::terminate, this, ref(face)));
363
364 scheduler.scheduleEvent(time::milliseconds(500),
365 bind(&FacesFixture2::checkPrefix, this, true));
366
367 regPrefixId = face.registerPrefix("/Hello/World",
368 bind(&FacesFixture3::onRegSucceeded, this),
369 bind(&FacesFixture3::onRegFailed, this));
370
371 scheduler.scheduleEvent(time::seconds(1),
372 bind(&Face::unregisterPrefix, &face,
373 regPrefixId,
374 static_cast<UnregisterPrefixSuccessCallback>(bind(&FacesFixture3::onUnregSucceeded, this)),
375 static_cast<UnregisterPrefixFailureCallback>(bind(&FacesFixture3::onUnregFailed, this))));
376
377 scheduler.scheduleEvent(time::milliseconds(1500),
378 bind(&FacesFixture2::checkPrefix, this, false));
379
380 BOOST_REQUIRE_NO_THROW(face.processEvents());
381
382 BOOST_CHECK_EQUAL(nRegFailures, 0);
383 BOOST_CHECK_EQUAL(nRegSuccesses, 1);
384
385 BOOST_CHECK_EQUAL(nUnregFailures, 0);
386 BOOST_CHECK_EQUAL(nUnregSuccesses, 1);
387}
388
389BOOST_AUTO_TEST_CASE(SetRegexFilterButNoRegister)
390{
391 Face face;
392 Face face2(face.getIoService());
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700393 Scheduler scheduler(face.getIoService());
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700394 scheduler.scheduleEvent(time::seconds(2),
395 bind(&FacesFixture::terminate, this, ref(face)));
396
397 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
398 bind(&FacesFixture::onInterestRegex, this,
399 ref(face), _1, _2));
400
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700401 // prefix is not registered, and also does not match regex
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700402 scheduler.scheduleEvent(time::milliseconds(200),
403 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700404 ref(face2), Name("/Hello/World/a")));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700405
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700406 // matches regex, but prefix is not registered
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700407 scheduler.scheduleEvent(time::milliseconds(300),
408 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700409 ref(face2), Name("/Hello/World/a/b")));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700410
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700411 // matches regex, but prefix is not registered
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700412 scheduler.scheduleEvent(time::milliseconds(400),
413 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700414 ref(face2), Name("/Hello/World/a/b/c")));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700415
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700416 // prefix is not registered, and also does not match regex
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700417 scheduler.scheduleEvent(time::milliseconds(500),
418 bind(&FacesFixture::expressInterest, this,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700419 ref(face2), Name("/Hello/World/a/b/d")));
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700420
421 BOOST_REQUIRE_NO_THROW(face.processEvents());
422
423 BOOST_CHECK_EQUAL(nRegFailures, 0);
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700424 BOOST_CHECK_EQUAL(nInInterests, 0);
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700425 BOOST_CHECK_EQUAL(nTimeouts, 4);
426 BOOST_CHECK_EQUAL(nData, 0);
427}
428
429
430BOOST_FIXTURE_TEST_CASE(SetRegexFilterAndRegister, FacesFixture3)
431{
432 Face face;
433 Face face2(face.getIoService());
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700434 Scheduler scheduler(face.getIoService());
Alexander Afanasyev984ad192014-05-02 19:11:15 -0700435 scheduler.scheduleEvent(time::seconds(2),
436 bind(&FacesFixture::terminate, this, ref(face)));
437
438 face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
439 bind(&FacesFixture::onInterestRegex, this,
440 ref(face), _1, _2));
441
442 face.registerPrefix("/Hello/World",
443 bind(&FacesFixture3::onRegSucceeded, this),
444 bind(&FacesFixture3::onRegFailed, this));
445
446 scheduler.scheduleEvent(time::milliseconds(200),
447 bind(&FacesFixture::expressInterest, this,
448 ref(face2), Name("/Hello/World/a"))); // shouldn't match
449
450 scheduler.scheduleEvent(time::milliseconds(300),
451 bind(&FacesFixture::expressInterest, this,
452 ref(face2), Name("/Hello/World/a/b"))); // should match
453
454 scheduler.scheduleEvent(time::milliseconds(400),
455 bind(&FacesFixture::expressInterest, this,
456 ref(face2), Name("/Hello/World/a/b/c"))); // should match
457
458 scheduler.scheduleEvent(time::milliseconds(500),
459 bind(&FacesFixture::expressInterest, this,
460 ref(face2), Name("/Hello/World/a/b/d"))); // should not match
461
462 BOOST_REQUIRE_NO_THROW(face.processEvents());
463
464 BOOST_CHECK_EQUAL(nRegFailures, 0);
465 BOOST_CHECK_EQUAL(nRegSuccesses, 1);
466
467 BOOST_CHECK_EQUAL(nInInterests, 2);
468 BOOST_CHECK_EQUAL(nTimeouts, 4);
469}
Alexander Afanasyev20d2c582014-01-26 15:32:51 -0800470BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -0800471
472} // namespace ndn