blob: af9f788a7a939a1ed5618ec9ef994b249db6df95 [file] [log] [blame]
Davide Pesavento43ff2a92017-05-18 19:50:57 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi0d82d042017-07-07 06:15:27 +00002/*
Davide Pesavento43ff2a92017-05-18 19:50:57 -04003 * 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
30namespace nfd {
31namespace face {
32namespace tests {
33
34class EthernetChannelFixture : public EthernetFixture
35{
36protected:
37 unique_ptr<EthernetChannel>
38 makeChannel()
39 {
40 BOOST_ASSERT(netifs.size() > 0);
Junxiao Shi0d82d042017-07-07 06:15:27 +000041 return make_unique<EthernetChannel>(netifs.front().asNetworkInterface(), time::seconds(2));
Davide Pesavento43ff2a92017-05-18 19:50:57 -040042 }
43};
44
45BOOST_AUTO_TEST_SUITE(Face)
46BOOST_FIXTURE_TEST_SUITE(TestEthernetChannel, EthernetChannelFixture)
47
48BOOST_AUTO_TEST_CASE(Uri)
49{
50 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
51
52 auto channel = makeChannel();
53 BOOST_CHECK_EQUAL(channel->getUri(), FaceUri::fromDev(netifs.front().name));
54}
55
56BOOST_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
71BOOST_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
96BOOST_AUTO_TEST_SUITE_END() // TestEthernetChannel
97BOOST_AUTO_TEST_SUITE_END() // Face
98
99} // namespace tests
100} // namespace face
101} // namespace nfd