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