blob: 45152585351c9f7ff5d851f403631f96af343b9b [file] [log] [blame]
Davide Pesavento2bf35a62017-04-02 00:41:06 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento74daf742018-11-23 18:14:13 -05002/*
Davide Pesavento47ce2ee2023-05-09 01:33:33 -04003 * Copyright (c) 2013-2023 Regents of the University of California.
Davide Pesavento2bf35a62017-04-02 00:41:06 -04004 *
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 Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/net/network-monitor.hpp"
Davide Pesavento2bf35a62017-04-02 00:41:06 -040023
Davide Pesavento7e780642018-11-24 15:51:34 -050024#include "tests/boost-test.hpp"
25
Davide Pesavento2bf35a62017-04-02 00:41:06 -040026#include <boost/asio/io_service.hpp>
27
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040028namespace ndn::tests {
29
30using namespace ndn::net;
Davide Pesavento2bf35a62017-04-02 00:41:06 -040031
Junxiao Shi25467942017-06-30 02:53:14 +000032BOOST_AUTO_TEST_SUITE(Net)
Davide Pesavento2bf35a62017-04-02 00:41:06 -040033BOOST_AUTO_TEST_SUITE(TestNetworkMonitor)
34
Junxiao Shif4c1eb32017-05-30 17:05:10 +000035#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 Pesavento2bf35a62017-04-02 00:41:06 -040043BOOST_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
51BOOST_AUTO_TEST_CASE(DestructWhileEnumerating)
52{
Davide Pesavento2bf35a62017-04-02 00:41:06 -040053 boost::asio::io_service io;
54 auto nm = make_unique<NetworkMonitor>(io);
Junxiao Shif4c1eb32017-05-30 17:05:10 +000055 NM_REQUIRE_CAP(ENUM);
Davide Pesavento2bf35a62017-04-02 00:41:06 -040056
Junxiao Shi2dc416d2017-07-03 04:46:16 +000057 nm->onInterfaceAdded.connect([&] (const shared_ptr<const NetworkInterface>&) {
Davide Pesavento2bf35a62017-04-02 00:41:06 -040058 io.post([&] { nm.reset(); });
59 });
60 nm->onEnumerationCompleted.connect([&] {
Davide Pesavento2bf35a62017-04-02 00:41:06 -040061 // make sure the test case terminates even if we have zero interfaces
62 io.post([&] { nm.reset(); });
63 });
64
65 io.run();
Davide Pesavento2bf35a62017-04-02 00:41:06 -040066 BOOST_CHECK(true); // if we got this far, the test passed
67}
68
69BOOST_AUTO_TEST_SUITE_END() // TestNetworkMonitor
Junxiao Shi25467942017-06-30 02:53:14 +000070BOOST_AUTO_TEST_SUITE_END() // Net
Davide Pesavento2bf35a62017-04-02 00:41:06 -040071
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040072} // namespace ndn::tests