Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 0d82d04 | 2017-07-07 06:15:27 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [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/ethernet-channel.hpp" |
| 27 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 28 | #include "tests/test-common.hpp" |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 29 | #include "ethernet-fixture.hpp" |
| 30 | |
| 31 | namespace nfd { |
| 32 | namespace face { |
| 33 | namespace tests { |
| 34 | |
| 35 | class EthernetChannelFixture : public EthernetFixture |
| 36 | { |
| 37 | protected: |
| 38 | unique_ptr<EthernetChannel> |
| 39 | makeChannel() |
| 40 | { |
| 41 | BOOST_ASSERT(netifs.size() > 0); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 42 | return make_unique<EthernetChannel>(netifs.front(), 2_s); |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 43 | } |
| 44 | }; |
| 45 | |
| 46 | BOOST_AUTO_TEST_SUITE(Face) |
| 47 | BOOST_FIXTURE_TEST_SUITE(TestEthernetChannel, EthernetChannelFixture) |
| 48 | |
| 49 | BOOST_AUTO_TEST_CASE(Uri) |
| 50 | { |
| 51 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 52 | |
| 53 | auto channel = makeChannel(); |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 54 | BOOST_CHECK_EQUAL(channel->getUri(), FaceUri::fromDev(netifs.front()->getName())); |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | BOOST_AUTO_TEST_CASE(Listen) |
| 58 | { |
| 59 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 60 | |
| 61 | auto channel = makeChannel(); |
| 62 | BOOST_CHECK_EQUAL(channel->isListening(), false); |
| 63 | |
| 64 | channel->listen(nullptr, nullptr); |
| 65 | BOOST_CHECK_EQUAL(channel->isListening(), true); |
| 66 | |
| 67 | // listen() is idempotent |
| 68 | BOOST_CHECK_NO_THROW(channel->listen(nullptr, nullptr)); |
| 69 | BOOST_CHECK_EQUAL(channel->isListening(), true); |
| 70 | } |
| 71 | |
| 72 | BOOST_AUTO_TEST_CASE(FaceClosure) |
| 73 | { |
| 74 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 75 | |
| 76 | auto channel = makeChannel(); |
| 77 | BOOST_CHECK_EQUAL(channel->size(), 0); |
| 78 | |
| 79 | shared_ptr<nfd::Face> face; |
Davide Pesavento | 15b5505 | 2018-01-27 19:09:28 -0500 | [diff] [blame] | 80 | channel->connect({0x00, 0x00, 0x5e, 0x00, 0x53, 0x5e}, {}, |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 81 | [&face] (const shared_ptr<nfd::Face>& newFace) { |
| 82 | BOOST_REQUIRE(newFace != nullptr); |
| 83 | face = newFace; |
| 84 | }, |
| 85 | [] (uint32_t status, const std::string& reason) { |
| 86 | BOOST_FAIL("No error expected, but got: [" << status << ": " << reason << "]"); |
| 87 | }); |
| 88 | BOOST_CHECK_EQUAL(channel->size(), 1); |
| 89 | BOOST_REQUIRE(face != nullptr); |
| 90 | |
| 91 | face->close(); |
| 92 | g_io.poll(); |
| 93 | BOOST_CHECK_EQUAL(channel->size(), 0); |
| 94 | } |
| 95 | |
| 96 | BOOST_AUTO_TEST_SUITE_END() // TestEthernetChannel |
| 97 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 98 | |
| 99 | } // namespace tests |
| 100 | } // namespace face |
| 101 | } // namespace nfd |