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