Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 15b5505 | 2018-01-27 19:09:28 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "face/tcp-factory.hpp" |
| 27 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 28 | #include "face-system-fixture.hpp" |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 29 | #include "factory-test-common.hpp" |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 30 | #include "tests/limited-io.hpp" |
| 31 | |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 32 | #include <ndn-cxx/net/address-converter.hpp> |
| 33 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 34 | namespace nfd { |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 35 | namespace face { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 36 | namespace tests { |
| 37 | |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 38 | class TcpFactoryFixture : public FaceSystemFactoryFixture<TcpFactory> |
| 39 | { |
| 40 | protected: |
| 41 | shared_ptr<TcpChannel> |
| 42 | createChannel(const std::string& localIp, const std::string& localPort) |
| 43 | { |
| 44 | tcp::Endpoint endpoint(ndn::ip::addressFromString(localIp), |
| 45 | boost::lexical_cast<uint16_t>(localPort)); |
| 46 | return factory.createChannel(endpoint); |
| 47 | } |
| 48 | }; |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 49 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 50 | BOOST_AUTO_TEST_SUITE(Face) |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 51 | BOOST_FIXTURE_TEST_SUITE(TestTcpFactory, TcpFactoryFixture) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 52 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 53 | BOOST_AUTO_TEST_SUITE(ProcessConfig) |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 54 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame^] | 55 | BOOST_AUTO_TEST_CASE(Defaults) |
| 56 | { |
| 57 | const std::string CONFIG = R"CONFIG( |
| 58 | face_system |
| 59 | { |
| 60 | tcp |
| 61 | } |
| 62 | )CONFIG"; |
| 63 | |
| 64 | parseConfig(CONFIG, true); |
| 65 | parseConfig(CONFIG, false); |
| 66 | |
| 67 | checkChannelListEqual(factory, {"tcp4://0.0.0.0:6363", "tcp6://[::]:6363"}); |
| 68 | auto channels = factory.getChannels(); |
| 69 | BOOST_CHECK(std::all_of(channels.begin(), channels.end(), |
| 70 | [] (const shared_ptr<const Channel>& ch) { return ch->isListening(); })); |
| 71 | } |
| 72 | |
| 73 | BOOST_AUTO_TEST_CASE(DisableListen) |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 74 | { |
| 75 | const std::string CONFIG = R"CONFIG( |
| 76 | face_system |
| 77 | { |
| 78 | tcp |
| 79 | { |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame^] | 80 | listen no |
| 81 | port 7001 |
| 82 | } |
| 83 | } |
| 84 | )CONFIG"; |
| 85 | |
| 86 | parseConfig(CONFIG, true); |
| 87 | parseConfig(CONFIG, false); |
| 88 | |
| 89 | checkChannelListEqual(factory, {"tcp4://0.0.0.0:7001", "tcp6://[::]:7001"}); |
| 90 | auto channels = factory.getChannels(); |
| 91 | BOOST_CHECK(std::none_of(channels.begin(), channels.end(), |
| 92 | [] (const shared_ptr<const Channel>& ch) { return ch->isListening(); })); |
| 93 | } |
| 94 | |
| 95 | BOOST_AUTO_TEST_CASE(DisableV4) |
| 96 | { |
| 97 | const std::string CONFIG = R"CONFIG( |
| 98 | face_system |
| 99 | { |
| 100 | tcp |
| 101 | { |
| 102 | port 7001 |
| 103 | enable_v4 no |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 104 | enable_v6 yes |
| 105 | } |
| 106 | } |
| 107 | )CONFIG"; |
| 108 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 109 | parseConfig(CONFIG, true); |
| 110 | parseConfig(CONFIG, false); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 111 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame^] | 112 | checkChannelListEqual(factory, {"tcp6://[::]:7001"}); |
| 113 | } |
| 114 | |
| 115 | BOOST_AUTO_TEST_CASE(DisableV6) |
| 116 | { |
| 117 | const std::string CONFIG = R"CONFIG( |
| 118 | face_system |
| 119 | { |
| 120 | tcp |
| 121 | { |
| 122 | port 7001 |
| 123 | enable_v4 yes |
| 124 | enable_v6 no |
| 125 | } |
| 126 | } |
| 127 | )CONFIG"; |
| 128 | |
| 129 | parseConfig(CONFIG, true); |
| 130 | parseConfig(CONFIG, false); |
| 131 | |
| 132 | checkChannelListEqual(factory, {"tcp4://0.0.0.0:7001"}); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | BOOST_AUTO_TEST_CASE(Omitted) |
| 136 | { |
| 137 | const std::string CONFIG = R"CONFIG( |
| 138 | face_system |
| 139 | { |
| 140 | } |
| 141 | )CONFIG"; |
| 142 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 143 | parseConfig(CONFIG, true); |
| 144 | parseConfig(CONFIG, false); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 145 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 146 | BOOST_CHECK_EQUAL(factory.getChannels().size(), 0); |
| 147 | } |
| 148 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame^] | 149 | BOOST_AUTO_TEST_CASE(AllDisabled) |
| 150 | { |
| 151 | const std::string CONFIG = R"CONFIG( |
| 152 | face_system |
| 153 | { |
| 154 | tcp |
| 155 | { |
| 156 | enable_v4 no |
| 157 | enable_v6 no |
| 158 | } |
| 159 | } |
| 160 | )CONFIG"; |
| 161 | |
| 162 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 163 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 164 | } |
| 165 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 166 | BOOST_AUTO_TEST_CASE(BadListen) |
| 167 | { |
| 168 | const std::string CONFIG = R"CONFIG( |
| 169 | face_system |
| 170 | { |
| 171 | tcp |
| 172 | { |
| 173 | listen hello |
| 174 | } |
| 175 | } |
| 176 | )CONFIG"; |
| 177 | |
| 178 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 179 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 180 | } |
| 181 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame^] | 182 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(BadPort, 2) // Bug #4489 |
| 183 | BOOST_AUTO_TEST_CASE(BadPort) |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 184 | { |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame^] | 185 | // not a number |
| 186 | const std::string CONFIG1 = R"CONFIG( |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 187 | face_system |
| 188 | { |
| 189 | tcp |
| 190 | { |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame^] | 191 | port hello |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | )CONFIG"; |
| 195 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame^] | 196 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 197 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 198 | |
| 199 | // negative number |
| 200 | const std::string CONFIG2 = R"CONFIG( |
| 201 | face_system |
| 202 | { |
| 203 | tcp |
| 204 | { |
| 205 | port -1 |
| 206 | } |
| 207 | } |
| 208 | )CONFIG"; |
| 209 | |
| 210 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 211 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
| 212 | |
| 213 | // out of range |
| 214 | const std::string CONFIG3 = R"CONFIG( |
| 215 | face_system |
| 216 | { |
| 217 | tcp |
| 218 | { |
| 219 | port 65536 |
| 220 | } |
| 221 | } |
| 222 | )CONFIG"; |
| 223 | |
| 224 | BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error); |
| 225 | BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | BOOST_AUTO_TEST_CASE(UnknownOption) |
| 229 | { |
| 230 | const std::string CONFIG = R"CONFIG( |
| 231 | face_system |
| 232 | { |
| 233 | tcp |
| 234 | { |
| 235 | hello |
| 236 | } |
| 237 | } |
| 238 | )CONFIG"; |
| 239 | |
| 240 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 241 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 242 | } |
| 243 | |
| 244 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 245 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 246 | BOOST_AUTO_TEST_CASE(GetChannels) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 247 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 248 | BOOST_CHECK_EQUAL(factory.getChannels().empty(), true); |
| 249 | |
| 250 | std::set<std::string> expected; |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 251 | expected.insert(createChannel("127.0.0.1", "20070")->getUri().toString()); |
| 252 | expected.insert(createChannel("127.0.0.1", "20071")->getUri().toString()); |
| 253 | expected.insert(createChannel("::1", "20071")->getUri().toString()); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 254 | checkChannelListEqual(factory, expected); |
| 255 | } |
| 256 | |
| 257 | BOOST_AUTO_TEST_CASE(CreateChannel) |
| 258 | { |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 259 | auto channel1 = createChannel("127.0.0.1", "20070"); |
| 260 | auto channel1a = createChannel("127.0.0.1", "20070"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 261 | BOOST_CHECK_EQUAL(channel1, channel1a); |
| 262 | BOOST_CHECK_EQUAL(channel1->getUri().toString(), "tcp4://127.0.0.1:20070"); |
| 263 | |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 264 | auto channel2 = createChannel("127.0.0.1", "20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 265 | BOOST_CHECK_NE(channel1, channel2); |
| 266 | |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 267 | auto channel3 = createChannel("::1", "20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 268 | BOOST_CHECK_NE(channel2, channel3); |
| 269 | BOOST_CHECK_EQUAL(channel3->getUri().toString(), "tcp6://[::1]:20071"); |
| 270 | } |
| 271 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 272 | BOOST_AUTO_TEST_CASE(CreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 273 | { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 274 | createFace(factory, |
| 275 | FaceUri("tcp4://127.0.0.1:6363"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 276 | {}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 277 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 278 | {CreateFaceExpectedResult::FAILURE, 504, "No channels available to connect"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 279 | |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 280 | createChannel("127.0.0.1", "20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 281 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 282 | createFace(factory, |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 283 | FaceUri("tcp4://127.0.0.1:6363"), |
| 284 | {}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 285 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 286 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 287 | |
| 288 | createFace(factory, |
| 289 | FaceUri("tcp4://127.0.0.1:6363"), |
| 290 | {}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 291 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, false, false, false}, |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 292 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 293 | |
| 294 | createFace(factory, |
| 295 | FaceUri("tcp4://127.0.0.1:20072"), |
| 296 | {}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 297 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, false, false, false}, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 298 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 299 | |
| 300 | createFace(factory, |
| 301 | FaceUri("tcp4://127.0.0.1:20073"), |
| 302 | {}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 303 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, false, true, false}, |
| 304 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 305 | |
| 306 | createFace(factory, |
| 307 | FaceUri("tcp4://127.0.0.1:20073"), |
| 308 | {}, |
| 309 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, false, false, true}, |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 310 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 313 | BOOST_AUTO_TEST_CASE(UnsupportedCreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 314 | { |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 315 | createChannel("127.0.0.1", "20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 316 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 317 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 318 | FaceUri("tcp4://127.0.0.1:20072"), |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 319 | FaceUri("tcp4://127.0.0.1:20071"), |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 320 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, false, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 321 | {CreateFaceExpectedResult::FAILURE, 406, |
| 322 | "Unicast TCP faces cannot be created with a LocalUri"}); |
| 323 | |
| 324 | createFace(factory, |
| 325 | FaceUri("tcp4://127.0.0.1:20072"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 326 | {}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 327 | {ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 328 | {CreateFaceExpectedResult::FAILURE, 406, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 329 | "Outgoing TCP faces do not support on-demand persistency"}); |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 330 | |
| 331 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 332 | FaceUri("tcp4://198.51.100.100:6363"), |
| 333 | {}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 334 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, true, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 335 | {CreateFaceExpectedResult::FAILURE, 406, |
| 336 | "Local fields can only be enabled on faces with local scope"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 339 | class CreateFaceTimeoutFixture : public TcpFactoryFixture |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 340 | { |
| 341 | public: |
| 342 | void |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame^] | 343 | onFaceCreated(const shared_ptr<nfd::Face>& newFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 344 | { |
| 345 | BOOST_CHECK_MESSAGE(false, "Timeout expected"); |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 346 | face = newFace; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 347 | |
| 348 | limitedIo.afterOp(); |
| 349 | } |
| 350 | |
| 351 | void |
| 352 | onConnectFailed(const std::string& reason) |
| 353 | { |
| 354 | BOOST_CHECK_MESSAGE(true, reason); |
| 355 | |
| 356 | limitedIo.afterOp(); |
| 357 | } |
| 358 | |
| 359 | public: |
| 360 | LimitedIo limitedIo; |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame^] | 361 | shared_ptr<nfd::Face> face; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 362 | }; |
| 363 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 364 | BOOST_FIXTURE_TEST_CASE(CreateFaceTimeout, CreateFaceTimeoutFixture) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 365 | { |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 366 | createChannel("0.0.0.0", "20070"); |
Davide Pesavento | 15b5505 | 2018-01-27 19:09:28 -0500 | [diff] [blame] | 367 | factory.createFace({FaceUri("tcp4://192.0.2.1:20070"), {}, {}}, |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 368 | bind(&CreateFaceTimeoutFixture::onFaceCreated, this, _1), |
| 369 | bind(&CreateFaceTimeoutFixture::onConnectFailed, this, _2)); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 370 | |
Davide Pesavento | 15b5505 | 2018-01-27 19:09:28 -0500 | [diff] [blame] | 371 | BOOST_REQUIRE_EQUAL(limitedIo.run(1, 10_s), LimitedIo::EXCEED_OPS); |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 372 | BOOST_CHECK(face == nullptr); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 375 | BOOST_AUTO_TEST_SUITE_END() // TestTcpFactory |
| 376 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 377 | |
| 378 | } // namespace tests |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 379 | } // namespace face |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 380 | } // namespace nfd |