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