Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 74daf74 | 2018-11-23 18:14:13 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 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. |
| 20 | */ |
| 21 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/net/network-monitor.hpp" |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 23 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
| 25 | |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 26 | #include <boost/asio/io_service.hpp> |
| 27 | |
| 28 | namespace ndn { |
Junxiao Shi | 2546794 | 2017-06-30 02:53:14 +0000 | [diff] [blame] | 29 | namespace net { |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 30 | namespace tests { |
| 31 | |
Junxiao Shi | 2546794 | 2017-06-30 02:53:14 +0000 | [diff] [blame] | 32 | BOOST_AUTO_TEST_SUITE(Net) |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 33 | BOOST_AUTO_TEST_SUITE(TestNetworkMonitor) |
| 34 | |
Junxiao Shi | f4c1eb3 | 2017-05-30 17:05:10 +0000 | [diff] [blame] | 35 | #define NM_REQUIRE_CAP(capability) \ |
| 36 | do { \ |
| 37 | if ((nm->getCapabilities() & NetworkMonitor::CAP_ ## capability) == 0) { \ |
| 38 | BOOST_WARN_MESSAGE(false, "skipping assertions that require " #capability " capability"); \ |
| 39 | return; \ |
| 40 | } \ |
| 41 | } while (false) |
| 42 | |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 43 | BOOST_AUTO_TEST_CASE(DestructWithoutRun) |
| 44 | { |
| 45 | boost::asio::io_service io; |
| 46 | auto nm = make_unique<NetworkMonitor>(io); |
| 47 | nm.reset(); |
| 48 | BOOST_CHECK(true); // if we got this far, the test passed |
| 49 | } |
| 50 | |
| 51 | BOOST_AUTO_TEST_CASE(DestructWhileEnumerating) |
| 52 | { |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 53 | boost::asio::io_service io; |
| 54 | auto nm = make_unique<NetworkMonitor>(io); |
Junxiao Shi | f4c1eb3 | 2017-05-30 17:05:10 +0000 | [diff] [blame] | 55 | NM_REQUIRE_CAP(ENUM); |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 56 | |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 57 | nm->onInterfaceAdded.connect([&] (const shared_ptr<const NetworkInterface>&) { |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 58 | io.post([&] { nm.reset(); }); |
| 59 | }); |
| 60 | nm->onEnumerationCompleted.connect([&] { |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 61 | // make sure the test case terminates even if we have zero interfaces |
| 62 | io.post([&] { nm.reset(); }); |
| 63 | }); |
| 64 | |
| 65 | io.run(); |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 66 | BOOST_CHECK(true); // if we got this far, the test passed |
| 67 | } |
| 68 | |
| 69 | BOOST_AUTO_TEST_SUITE_END() // TestNetworkMonitor |
Junxiao Shi | 2546794 | 2017-06-30 02:53:14 +0000 | [diff] [blame] | 70 | BOOST_AUTO_TEST_SUITE_END() // Net |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 71 | |
| 72 | } // namespace tests |
Junxiao Shi | 2546794 | 2017-06-30 02:53:14 +0000 | [diff] [blame] | 73 | } // namespace net |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 74 | } // namespace ndn |