Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | e6c65e2 | 2015-01-28 19:56:03 -0800 | [diff] [blame] | 22 | #define BOOST_TEST_MAIN 1 |
| 23 | #define BOOST_TEST_DYN_LINK 1 |
| 24 | #define BOOST_TEST_MODULE ndn-cxx Integrated Tests (Face) |
| 25 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 26 | #include "face.hpp" |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 27 | #include "util/scheduler.hpp" |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 28 | |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 29 | #include "identity-management-fixture.hpp" |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 30 | #include "boost-test.hpp" |
| 31 | |
Junxiao Shi | cf9c6bb | 2016-07-27 02:18:19 +0000 | [diff] [blame] | 32 | #include <stdio.h> |
Alexander Afanasyev | a54d5a6 | 2017-02-11 19:01:34 -0800 | [diff] [blame] | 33 | #include <thread> |
| 34 | #include <mutex> |
| 35 | #include <condition_variable> |
Junxiao Shi | cf9c6bb | 2016-07-27 02:18:19 +0000 | [diff] [blame] | 36 | |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 37 | namespace ndn { |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 38 | namespace tests { |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 39 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 40 | struct PibDirWithDefaultTpm |
| 41 | { |
| 42 | const std::string PATH = "build/keys-with-default-tpm"; |
| 43 | }; |
| 44 | |
Alexander Afanasyev | fc99b51 | 2017-01-04 11:10:36 -0800 | [diff] [blame] | 45 | class FacesFixture : public IdentityManagementFixture |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 46 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 47 | public: |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 48 | FacesFixture() |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 49 | : nData(0) |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 50 | , nNacks(0) |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 51 | , nTimeouts(0) |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 52 | , regPrefixId(0) |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 53 | , nInInterests(0) |
| 54 | , nInInterests2(0) |
| 55 | , nRegFailures(0) |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 56 | { |
| 57 | } |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 58 | |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 59 | void |
| 60 | onData() |
| 61 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 62 | ++nData; |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 66 | onNack() |
| 67 | { |
| 68 | ++nNacks; |
| 69 | } |
| 70 | |
| 71 | void |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 72 | onTimeout() |
| 73 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 74 | ++nTimeouts; |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 78 | onInterest(Face& face, |
| 79 | const Name&, const Interest&) |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 80 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 81 | ++nInInterests; |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 82 | |
| 83 | face.unsetInterestFilter(regPrefixId); |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 87 | onInterest2(Face& face, |
| 88 | const Name&, const Interest&) |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 89 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 90 | ++nInInterests2; |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 91 | |
| 92 | face.unsetInterestFilter(regPrefixId2); |
| 93 | } |
| 94 | |
| 95 | void |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 96 | onInterestRegex(Face& face, |
| 97 | const InterestFilter&, const Interest&) |
| 98 | { |
| 99 | ++nInInterests; |
| 100 | } |
| 101 | |
| 102 | void |
| 103 | onInterestRegexError(Face& face, |
| 104 | const Name&, const Interest&) |
| 105 | { |
| 106 | BOOST_FAIL("InterestFilter::Error should have been triggered"); |
| 107 | } |
| 108 | |
| 109 | void |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 110 | onRegFailed() |
| 111 | { |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 112 | ++nRegFailures; |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void |
| 116 | expressInterest(Face& face, const Name& name) |
| 117 | { |
| 118 | Interest i(name); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 119 | i.setInterestLifetime(time::milliseconds(50)); |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 120 | face.expressInterest(i, |
| 121 | bind(&FacesFixture::onData, this), |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 122 | bind(&FacesFixture::onNack, this), |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 123 | bind(&FacesFixture::onTimeout, this)); |
| 124 | } |
| 125 | |
| 126 | void |
| 127 | terminate(Face& face) |
| 128 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 129 | face.getIoService().stop(); |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 130 | } |
| 131 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 132 | uint32_t nData; |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 133 | uint32_t nNacks; |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 134 | uint32_t nTimeouts; |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 135 | |
| 136 | const RegisteredPrefixId* regPrefixId; |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 137 | const RegisteredPrefixId* regPrefixId2; |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 138 | uint32_t nInInterests; |
| 139 | uint32_t nInInterests2; |
| 140 | uint32_t nRegFailures; |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 141 | }; |
| 142 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 143 | BOOST_FIXTURE_TEST_SUITE(TestFaces, FacesFixture) |
| 144 | |
| 145 | BOOST_AUTO_TEST_CASE(Unix) |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 146 | { |
| 147 | Face face; |
| 148 | |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 149 | face.expressInterest(Interest("/", time::milliseconds(1000)), |
| 150 | bind(&FacesFixture::onData, this), |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 151 | bind(&FacesFixture::onNack, this), |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 152 | bind(&FacesFixture::onTimeout, this)); |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 153 | |
| 154 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
| 155 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 156 | BOOST_CHECK_EQUAL(nData, 1); |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 157 | BOOST_CHECK_EQUAL(nNacks, 0); |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 158 | BOOST_CHECK_EQUAL(nTimeouts, 0); |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 159 | |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 160 | face.expressInterest(Interest("/localhost/non-existing/data/should/not/exist/anywhere", |
| 161 | time::milliseconds(50)), |
| 162 | bind(&FacesFixture::onData, this), |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 163 | bind(&FacesFixture::onNack, this), |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 164 | bind(&FacesFixture::onTimeout, this)); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 165 | |
Alexander Afanasyev | 49bb1fb | 2014-07-21 12:54:01 -0700 | [diff] [blame] | 166 | Name veryLongName; |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 167 | for (size_t i = 0; i <= MAX_NDN_PACKET_SIZE / 10; i++) { |
| 168 | veryLongName.append("0123456789"); |
| 169 | } |
Alexander Afanasyev | 49bb1fb | 2014-07-21 12:54:01 -0700 | [diff] [blame] | 170 | |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 171 | BOOST_CHECK_THROW(face.expressInterest(veryLongName, nullptr, nullptr, nullptr), Face::Error); |
Alexander Afanasyev | 49bb1fb | 2014-07-21 12:54:01 -0700 | [diff] [blame] | 172 | |
| 173 | shared_ptr<Data> data = make_shared<Data>(veryLongName); |
| 174 | data->setContent(reinterpret_cast<const uint8_t*>("01234567890"), 10); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 175 | m_keyChain.sign(*data); |
Alexander Afanasyev | 49bb1fb | 2014-07-21 12:54:01 -0700 | [diff] [blame] | 176 | BOOST_CHECK_THROW(face.put(*data), Face::Error); |
| 177 | |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 178 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
| 179 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 180 | BOOST_CHECK_EQUAL(nData, 1); |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 181 | BOOST_CHECK_EQUAL(nNacks, 0); |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 182 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 183 | } |
| 184 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 185 | BOOST_AUTO_TEST_CASE(Tcp) |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 186 | { |
| 187 | Face face("localhost"); |
| 188 | |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 189 | face.expressInterest(Interest("/", time::milliseconds(1000)), |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 190 | bind(&FacesFixture::onData, this), |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 191 | bind(&FacesFixture::onNack, this), |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 192 | bind(&FacesFixture::onTimeout, this)); |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 193 | |
| 194 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
| 195 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 196 | BOOST_CHECK_EQUAL(nData, 1); |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 197 | BOOST_CHECK_EQUAL(nNacks, 0); |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 198 | BOOST_CHECK_EQUAL(nTimeouts, 0); |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 199 | |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 200 | face.expressInterest(Interest("/localhost/non-existing/data/should/not/exist/anywhere", |
| 201 | time::milliseconds(50)), |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 202 | bind(&FacesFixture::onData, this), |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 203 | bind(&FacesFixture::onNack, this), |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 204 | bind(&FacesFixture::onTimeout, this)); |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 205 | |
| 206 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
| 207 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 208 | BOOST_CHECK_EQUAL(nData, 1); |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 209 | BOOST_CHECK_EQUAL(nNacks, 0); |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 210 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 211 | } |
| 212 | |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 213 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 214 | BOOST_AUTO_TEST_CASE(SetFilter) |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 215 | { |
| 216 | Face face; |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 217 | Face face2(face.getIoService()); |
| 218 | Scheduler scheduler(face.getIoService()); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 219 | scheduler.scheduleEvent(time::seconds(4), |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 220 | bind(&FacesFixture::terminate, this, ref(face))); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 221 | |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 222 | regPrefixId = face.setInterestFilter("/Hello/World", |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 223 | bind(&FacesFixture::onInterest, this, ref(face), _1, _2), |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 224 | nullptr, |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 225 | bind(&FacesFixture::onRegFailed, this)); |
| 226 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 227 | scheduler.scheduleEvent(time::milliseconds(200), |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 228 | bind(&FacesFixture::expressInterest, this, |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 229 | ref(face2), Name("/Hello/World/!"))); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 230 | |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 231 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
| 232 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 233 | BOOST_CHECK_EQUAL(nRegFailures, 0); |
| 234 | BOOST_CHECK_EQUAL(nInInterests, 1); |
| 235 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 236 | BOOST_CHECK_EQUAL(nNacks, 0); |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 237 | BOOST_CHECK_EQUAL(nData, 0); |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 240 | BOOST_AUTO_TEST_CASE(SetTwoFilters) |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 241 | { |
| 242 | Face face; |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 243 | Face face2(face.getIoService()); |
| 244 | Scheduler scheduler(face.getIoService()); |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 245 | scheduler.scheduleEvent(time::seconds(6), |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 246 | bind(&FacesFixture::terminate, this, ref(face))); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 247 | |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 248 | regPrefixId = face.setInterestFilter("/Hello/World", |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 249 | bind(&FacesFixture::onInterest, this, ref(face), _1, _2), |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 250 | nullptr, |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 251 | bind(&FacesFixture::onRegFailed, this)); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 252 | |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 253 | regPrefixId2 = face.setInterestFilter("/Los/Angeles/Lakers", |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 254 | bind(&FacesFixture::onInterest2, this, ref(face), _1, _2), |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 255 | nullptr, |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 256 | bind(&FacesFixture::onRegFailed, this)); |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 257 | |
| 258 | |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 259 | scheduler.scheduleEvent(time::seconds(2), |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 260 | bind(&FacesFixture::expressInterest, this, |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 261 | ref(face2), Name("/Hello/World/!"))); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 262 | |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 263 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
| 264 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 265 | BOOST_CHECK_EQUAL(nRegFailures, 0); |
| 266 | BOOST_CHECK_EQUAL(nInInterests, 1); |
| 267 | BOOST_CHECK_EQUAL(nInInterests2, 0); |
| 268 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 269 | BOOST_CHECK_EQUAL(nNacks, 0); |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 270 | BOOST_CHECK_EQUAL(nData, 0); |
Alexander Afanasyev | a68aa7f | 2014-02-11 15:42:33 -0800 | [diff] [blame] | 271 | } |
| 272 | |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 273 | BOOST_AUTO_TEST_CASE(SetRegexFilterError) |
| 274 | { |
| 275 | Face face; |
| 276 | Face face2(face.getIoService()); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 277 | Scheduler scheduler(face.getIoService()); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 278 | scheduler.scheduleEvent(time::seconds(4), |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 279 | bind(&FacesFixture::terminate, this, ref(face))); |
| 280 | |
| 281 | regPrefixId = face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 282 | bind(&FacesFixture::onInterestRegexError, this, |
| 283 | ref(face), _1, _2), |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 284 | nullptr, |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 285 | bind(&FacesFixture::onRegFailed, this)); |
| 286 | |
| 287 | scheduler.scheduleEvent(time::milliseconds(300), |
| 288 | bind(&FacesFixture::expressInterest, this, |
| 289 | ref(face2), Name("/Hello/World/XXX/b/c"))); // should match |
| 290 | |
| 291 | BOOST_REQUIRE_THROW(face.processEvents(), InterestFilter::Error); |
| 292 | } |
| 293 | |
| 294 | BOOST_AUTO_TEST_CASE(SetRegexFilter) |
| 295 | { |
| 296 | Face face; |
| 297 | Face face2(face.getIoService()); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 298 | Scheduler scheduler(face.getIoService()); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 299 | scheduler.scheduleEvent(time::seconds(4), |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 300 | bind(&FacesFixture::terminate, this, ref(face))); |
| 301 | |
| 302 | regPrefixId = face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 303 | bind(&FacesFixture::onInterestRegex, this, |
| 304 | ref(face), _1, _2), |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 305 | nullptr, |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 306 | bind(&FacesFixture::onRegFailed, this)); |
| 307 | |
| 308 | scheduler.scheduleEvent(time::milliseconds(200), |
| 309 | bind(&FacesFixture::expressInterest, this, |
| 310 | ref(face2), Name("/Hello/World/a"))); // shouldn't match |
| 311 | |
| 312 | scheduler.scheduleEvent(time::milliseconds(300), |
| 313 | bind(&FacesFixture::expressInterest, this, |
| 314 | ref(face2), Name("/Hello/World/a/b"))); // should match |
| 315 | |
| 316 | scheduler.scheduleEvent(time::milliseconds(400), |
| 317 | bind(&FacesFixture::expressInterest, this, |
| 318 | ref(face2), Name("/Hello/World/a/b/c"))); // should match |
| 319 | |
| 320 | scheduler.scheduleEvent(time::milliseconds(500), |
| 321 | bind(&FacesFixture::expressInterest, this, |
| 322 | ref(face2), Name("/Hello/World/a/b/d"))); // should not match |
| 323 | |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 324 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 325 | |
| 326 | BOOST_CHECK_EQUAL(nRegFailures, 0); |
| 327 | BOOST_CHECK_EQUAL(nInInterests, 2); |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 328 | BOOST_CHECK_EQUAL(nTimeouts, 4); |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 329 | BOOST_CHECK_EQUAL(nNacks, 0); |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 330 | BOOST_CHECK_EQUAL(nData, 0); |
| 331 | } |
| 332 | |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 333 | class FacesFixture2 : public FacesFixture |
| 334 | { |
| 335 | public: |
| 336 | void |
Junxiao Shi | cf9c6bb | 2016-07-27 02:18:19 +0000 | [diff] [blame] | 337 | checkPrefix(bool shouldExist) |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 338 | { |
Junxiao Shi | cf9c6bb | 2016-07-27 02:18:19 +0000 | [diff] [blame] | 339 | // Boost.Test fails if a child process exits with non-zero. |
| 340 | // http://stackoverflow.com/q/5325202 |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 341 | std::string output = this->executeCommand("nfdc route list | grep /Hello/World || true"); |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 342 | |
Junxiao Shi | cf9c6bb | 2016-07-27 02:18:19 +0000 | [diff] [blame] | 343 | if (shouldExist) { |
| 344 | BOOST_CHECK_NE(output.size(), 0); |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 345 | } |
| 346 | else { |
Junxiao Shi | cf9c6bb | 2016-07-27 02:18:19 +0000 | [diff] [blame] | 347 | BOOST_CHECK_EQUAL(output.size(), 0); |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 348 | } |
| 349 | } |
Junxiao Shi | cf9c6bb | 2016-07-27 02:18:19 +0000 | [diff] [blame] | 350 | |
| 351 | protected: |
| 352 | std::string |
| 353 | executeCommand(const std::string& cmd) |
| 354 | { |
| 355 | std::string output; |
| 356 | char buf[256]; |
| 357 | FILE* pipe = popen(cmd.c_str(), "r"); |
| 358 | BOOST_REQUIRE_MESSAGE(pipe != nullptr, "cannot execute '" << cmd << "'"); |
| 359 | while (fgets(buf, sizeof(buf), pipe) != nullptr) { |
| 360 | output += buf; |
| 361 | } |
| 362 | pclose(pipe); |
| 363 | return output; |
| 364 | } |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 365 | }; |
| 366 | |
| 367 | BOOST_FIXTURE_TEST_CASE(RegisterUnregisterPrefix, FacesFixture2) |
| 368 | { |
| 369 | Face face; |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 370 | Scheduler scheduler(face.getIoService()); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 371 | scheduler.scheduleEvent(time::seconds(4), |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 372 | bind(&FacesFixture::terminate, this, ref(face))); |
| 373 | |
| 374 | regPrefixId = face.setInterestFilter(InterestFilter("/Hello/World"), |
| 375 | bind(&FacesFixture::onInterest, this, |
| 376 | ref(face), _1, _2), |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 377 | nullptr, |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 378 | bind(&FacesFixture::onRegFailed, this)); |
| 379 | |
| 380 | scheduler.scheduleEvent(time::milliseconds(500), |
| 381 | bind(&FacesFixture2::checkPrefix, this, true)); |
| 382 | |
| 383 | scheduler.scheduleEvent(time::seconds(1), |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 384 | bind(static_cast<void(Face::*)(const RegisteredPrefixId*)>(&Face::unsetInterestFilter), |
| 385 | &face, |
| 386 | regPrefixId)); // shouldn't match |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 387 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 388 | scheduler.scheduleEvent(time::milliseconds(2000), |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 389 | bind(&FacesFixture2::checkPrefix, this, false)); |
| 390 | |
| 391 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
| 392 | } |
Alexander Afanasyev | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 393 | |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 394 | |
| 395 | class FacesFixture3 : public FacesFixture2 |
| 396 | { |
| 397 | public: |
| 398 | FacesFixture3() |
| 399 | : nRegSuccesses(0) |
| 400 | , nUnregSuccesses(0) |
| 401 | , nUnregFailures(0) |
| 402 | { |
| 403 | } |
| 404 | |
| 405 | void |
| 406 | onRegSucceeded() |
| 407 | { |
| 408 | ++nRegSuccesses; |
| 409 | } |
| 410 | |
| 411 | void |
| 412 | onUnregSucceeded() |
| 413 | { |
| 414 | ++nUnregSuccesses; |
| 415 | } |
| 416 | |
| 417 | void |
| 418 | onUnregFailed() |
| 419 | { |
| 420 | ++nUnregFailures; |
| 421 | } |
| 422 | |
| 423 | public: |
| 424 | uint64_t nRegSuccesses; |
| 425 | uint64_t nUnregSuccesses; |
| 426 | uint64_t nUnregFailures; |
| 427 | }; |
| 428 | |
| 429 | BOOST_FIXTURE_TEST_CASE(RegisterPrefix, FacesFixture3) |
| 430 | { |
| 431 | Face face; |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 432 | Face face2(face.getIoService()); |
| 433 | Scheduler scheduler(face.getIoService()); |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 434 | scheduler.scheduleEvent(time::seconds(6), |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 435 | bind(&FacesFixture::terminate, this, ref(face))); |
| 436 | |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 437 | scheduler.scheduleEvent(time::seconds(2), |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 438 | bind(&FacesFixture2::checkPrefix, this, true)); |
| 439 | |
| 440 | regPrefixId = face.registerPrefix("/Hello/World", |
| 441 | bind(&FacesFixture3::onRegSucceeded, this), |
| 442 | bind(&FacesFixture3::onRegFailed, this)); |
| 443 | |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 444 | scheduler.scheduleEvent(time::seconds(4), |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 445 | bind(&Face::unregisterPrefix, &face, |
| 446 | regPrefixId, |
| 447 | static_cast<UnregisterPrefixSuccessCallback>(bind(&FacesFixture3::onUnregSucceeded, this)), |
| 448 | static_cast<UnregisterPrefixFailureCallback>(bind(&FacesFixture3::onUnregFailed, this)))); |
| 449 | |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 450 | scheduler.scheduleEvent(time::milliseconds(6500), |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 451 | bind(&FacesFixture2::checkPrefix, this, false)); |
| 452 | |
| 453 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
| 454 | |
| 455 | BOOST_CHECK_EQUAL(nRegFailures, 0); |
| 456 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 457 | |
| 458 | BOOST_CHECK_EQUAL(nUnregFailures, 0); |
| 459 | BOOST_CHECK_EQUAL(nUnregSuccesses, 1); |
| 460 | } |
| 461 | |
| 462 | BOOST_AUTO_TEST_CASE(SetRegexFilterButNoRegister) |
| 463 | { |
| 464 | Face face; |
| 465 | Face face2(face.getIoService()); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 466 | Scheduler scheduler(face.getIoService()); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 467 | scheduler.scheduleEvent(time::seconds(2), |
| 468 | bind(&FacesFixture::terminate, this, ref(face))); |
| 469 | |
| 470 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 471 | bind(&FacesFixture::onInterestRegex, this, |
| 472 | ref(face), _1, _2)); |
| 473 | |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 474 | // prefix is not registered, and also does not match regex |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 475 | scheduler.scheduleEvent(time::milliseconds(200), |
| 476 | bind(&FacesFixture::expressInterest, this, |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 477 | ref(face2), Name("/Hello/World/a"))); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 478 | |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 479 | // matches regex, but prefix is not registered |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 480 | scheduler.scheduleEvent(time::milliseconds(300), |
| 481 | bind(&FacesFixture::expressInterest, this, |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 482 | ref(face2), Name("/Hello/World/a/b"))); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 483 | |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 484 | // matches regex, but prefix is not registered |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 485 | scheduler.scheduleEvent(time::milliseconds(400), |
| 486 | bind(&FacesFixture::expressInterest, this, |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 487 | ref(face2), Name("/Hello/World/a/b/c"))); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 488 | |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 489 | // prefix is not registered, and also does not match regex |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 490 | scheduler.scheduleEvent(time::milliseconds(500), |
| 491 | bind(&FacesFixture::expressInterest, this, |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 492 | ref(face2), Name("/Hello/World/a/b/d"))); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 493 | |
| 494 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
| 495 | |
| 496 | BOOST_CHECK_EQUAL(nRegFailures, 0); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 497 | BOOST_CHECK_EQUAL(nInInterests, 0); |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 498 | BOOST_CHECK_EQUAL(nTimeouts, 0); |
| 499 | BOOST_CHECK_EQUAL(nNacks, 4); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 500 | BOOST_CHECK_EQUAL(nData, 0); |
| 501 | } |
| 502 | |
| 503 | |
| 504 | BOOST_FIXTURE_TEST_CASE(SetRegexFilterAndRegister, FacesFixture3) |
| 505 | { |
| 506 | Face face; |
| 507 | Face face2(face.getIoService()); |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 508 | Scheduler scheduler(face.getIoService()); |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 509 | scheduler.scheduleEvent(time::seconds(4), |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 510 | bind(&FacesFixture::terminate, this, ref(face))); |
| 511 | |
| 512 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 513 | bind(&FacesFixture::onInterestRegex, this, |
| 514 | ref(face), _1, _2)); |
| 515 | |
| 516 | face.registerPrefix("/Hello/World", |
| 517 | bind(&FacesFixture3::onRegSucceeded, this), |
| 518 | bind(&FacesFixture3::onRegFailed, this)); |
| 519 | |
| 520 | scheduler.scheduleEvent(time::milliseconds(200), |
| 521 | bind(&FacesFixture::expressInterest, this, |
| 522 | ref(face2), Name("/Hello/World/a"))); // shouldn't match |
| 523 | |
| 524 | scheduler.scheduleEvent(time::milliseconds(300), |
| 525 | bind(&FacesFixture::expressInterest, this, |
| 526 | ref(face2), Name("/Hello/World/a/b"))); // should match |
| 527 | |
| 528 | scheduler.scheduleEvent(time::milliseconds(400), |
| 529 | bind(&FacesFixture::expressInterest, this, |
| 530 | ref(face2), Name("/Hello/World/a/b/c"))); // should match |
| 531 | |
| 532 | scheduler.scheduleEvent(time::milliseconds(500), |
| 533 | bind(&FacesFixture::expressInterest, this, |
| 534 | ref(face2), Name("/Hello/World/a/b/d"))); // should not match |
| 535 | |
| 536 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
| 537 | |
| 538 | BOOST_CHECK_EQUAL(nRegFailures, 0); |
| 539 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 540 | |
| 541 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 542 | BOOST_CHECK_EQUAL(nTimeouts, 4); |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 543 | BOOST_CHECK_EQUAL(nNacks, 0); |
| 544 | BOOST_CHECK_EQUAL(nData, 0); |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 545 | } |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 546 | |
Alexander Afanasyev | fba1ac6 | 2015-08-26 15:19:13 -0700 | [diff] [blame] | 547 | BOOST_AUTO_TEST_CASE(ShutdownWhileSendInProgress) // Bug #3136 |
| 548 | { |
| 549 | Face face; |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 550 | face.expressInterest(Name("/Hello/World/!"), nullptr, nullptr, nullptr); |
Alexander Afanasyev | fba1ac6 | 2015-08-26 15:19:13 -0700 | [diff] [blame] | 551 | BOOST_REQUIRE_NO_THROW(face.processEvents(time::seconds(1))); |
| 552 | |
Eric Newberry | 0669061 | 2016-12-27 12:50:15 -0700 | [diff] [blame] | 553 | face.expressInterest(Name("/Bye/World/1"), nullptr, nullptr, nullptr); |
| 554 | face.expressInterest(Name("/Bye/World/2"), nullptr, nullptr, nullptr); |
| 555 | face.expressInterest(Name("/Bye/World/3"), nullptr, nullptr, nullptr); |
Alexander Afanasyev | fba1ac6 | 2015-08-26 15:19:13 -0700 | [diff] [blame] | 556 | face.shutdown(); |
| 557 | |
| 558 | BOOST_REQUIRE_NO_THROW(face.processEvents(time::seconds(1))); |
| 559 | // should not segfault |
| 560 | } |
| 561 | |
Alexander Afanasyev | e508f14 | 2015-09-01 15:14:45 -0700 | [diff] [blame] | 562 | BOOST_AUTO_TEST_CASE(LargeDelayBetweenFaceConstructorAndProcessEvents) // Bug #2742 |
| 563 | { |
| 564 | ndn::Face face; |
| 565 | |
| 566 | ::sleep(5); // simulate setup workload |
| 567 | |
| 568 | BOOST_CHECK_NO_THROW(face.processEvents(time::seconds(1))); |
| 569 | } |
| 570 | |
Alexander Afanasyev | a54d5a6 | 2017-02-11 19:01:34 -0800 | [diff] [blame] | 571 | BOOST_AUTO_TEST_CASE(ProcessEventsBlocksForeverWhenNothingScheduled) // Bug #3957 |
| 572 | { |
| 573 | ndn::Face face; |
| 574 | std::mutex m; |
| 575 | std::condition_variable cv; |
| 576 | bool processEventsFinished = false; |
| 577 | |
| 578 | std::thread faceThread([&] { |
| 579 | face.processEvents(); |
| 580 | |
| 581 | processEventsFinished = true; |
| 582 | std::lock_guard<std::mutex> lk(m); |
| 583 | cv.notify_one(); |
| 584 | }); |
| 585 | |
| 586 | { |
| 587 | std::unique_lock<std::mutex> lk(m); |
| 588 | cv.wait_for(lk, std::chrono::seconds(5), [&] { return processEventsFinished; }); |
| 589 | } |
| 590 | |
| 591 | BOOST_CHECK_EQUAL(processEventsFinished, true); |
| 592 | if (!processEventsFinished) { |
| 593 | face.shutdown(); |
| 594 | } |
| 595 | faceThread.join(); |
| 596 | } |
| 597 | |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 598 | BOOST_AUTO_TEST_SUITE_END() |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 599 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 600 | } // namespace tests |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 601 | } // namespace ndn |