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