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 | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
| 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 | |
| 28 | #include "ethernet-fixture.hpp" |
| 29 | |
| 30 | namespace nfd { |
| 31 | namespace face { |
| 32 | namespace tests { |
| 33 | |
| 34 | class EthernetChannelFixture : public EthernetFixture |
| 35 | { |
| 36 | protected: |
| 37 | unique_ptr<EthernetChannel> |
| 38 | makeChannel() |
| 39 | { |
| 40 | BOOST_ASSERT(netifs.size() > 0); |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame^] | 41 | return make_unique<EthernetChannel>(netifs.front(), time::seconds(2)); |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 42 | } |
| 43 | }; |
| 44 | |
| 45 | BOOST_AUTO_TEST_SUITE(Face) |
| 46 | BOOST_FIXTURE_TEST_SUITE(TestEthernetChannel, EthernetChannelFixture) |
| 47 | |
| 48 | BOOST_AUTO_TEST_CASE(Uri) |
| 49 | { |
| 50 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 51 | |
| 52 | auto channel = makeChannel(); |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame^] | 53 | BOOST_CHECK_EQUAL(channel->getUri(), FaceUri::fromDev(netifs.front()->getName())); |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | BOOST_AUTO_TEST_CASE(Listen) |
| 57 | { |
| 58 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 59 | |
| 60 | auto channel = makeChannel(); |
| 61 | BOOST_CHECK_EQUAL(channel->isListening(), false); |
| 62 | |
| 63 | channel->listen(nullptr, nullptr); |
| 64 | BOOST_CHECK_EQUAL(channel->isListening(), true); |
| 65 | |
| 66 | // listen() is idempotent |
| 67 | BOOST_CHECK_NO_THROW(channel->listen(nullptr, nullptr)); |
| 68 | BOOST_CHECK_EQUAL(channel->isListening(), true); |
| 69 | } |
| 70 | |
| 71 | BOOST_AUTO_TEST_CASE(FaceClosure) |
| 72 | { |
| 73 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 74 | |
| 75 | auto channel = makeChannel(); |
| 76 | BOOST_CHECK_EQUAL(channel->size(), 0); |
| 77 | |
| 78 | shared_ptr<nfd::Face> face; |
| 79 | channel->connect({0x00, 0x00, 0x5e, 0x00, 0x53, 0x5e}, |
| 80 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 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 |