blob: 3cb705adb766f19c8c267dc8542eda2a252c25bb [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 Shi84d62cb2017-07-12 16:15:18 +000041 return make_unique<EthernetChannel>(netifs.front(), 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();
Junxiao Shi84d62cb2017-07-12 16:15:18 +000053 BOOST_CHECK_EQUAL(channel->getUri(), FaceUri::fromDev(netifs.front()->getName()));
Davide Pesavento43ff2a92017-05-18 19:50:57 -040054}
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,
Eric Newberry2642cd22017-07-13 21:34:53 -040081 false,
Davide Pesavento43ff2a92017-05-18 19:50:57 -040082 [&face] (const shared_ptr<nfd::Face>& newFace) {
83 BOOST_REQUIRE(newFace != nullptr);
84 face = newFace;
85 },
86 [] (uint32_t status, const std::string& reason) {
87 BOOST_FAIL("No error expected, but got: [" << status << ": " << reason << "]");
88 });
89 BOOST_CHECK_EQUAL(channel->size(), 1);
90 BOOST_REQUIRE(face != nullptr);
91
92 face->close();
93 g_io.poll();
94 BOOST_CHECK_EQUAL(channel->size(), 0);
95}
96
97BOOST_AUTO_TEST_SUITE_END() // TestEthernetChannel
98BOOST_AUTO_TEST_SUITE_END() // Face
99
100} // namespace tests
101} // namespace face
102} // namespace nfd