blob: 90654d70d0890ea988e35e536374918f6b36a1a2 [file] [log] [blame]
Junxiao Shi49e11e72014-12-14 19:46:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -08003 * Copyright (c) 2014-2015, 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.
Junxiao Shi49e11e72014-12-14 19:46:05 -070010 *
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 "fw/strategy.hpp"
27#include "dummy-strategy.hpp"
28#include "tests/daemon/face/dummy-face.hpp"
29#include <boost/range/adaptor/filtered.hpp>
30
31#include "tests/test-common.hpp"
32
33namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080034namespace fw {
Junxiao Shi49e11e72014-12-14 19:46:05 -070035namespace tests {
36
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080037using namespace nfd::tests;
38
Junxiao Shicde37ad2015-12-24 01:02:05 -070039BOOST_AUTO_TEST_SUITE(Fw)
40BOOST_FIXTURE_TEST_SUITE(TestStrategy, BaseFixture)
Junxiao Shi49e11e72014-12-14 19:46:05 -070041
42class FaceTableAccessTestStrategy : public DummyStrategy
43{
44public:
45 explicit
46 FaceTableAccessTestStrategy(Forwarder& forwarder)
47 : DummyStrategy(forwarder, Name("ndn:/strategy"))
48 {
49 this->afterAddFace.connect([this] (shared_ptr<Face> face) {
50 this->addedFaces.push_back(face->getId());
51 });
52 this->beforeRemoveFace.connect([this] (shared_ptr<Face> face) {
53 this->removedFaces.push_back(face->getId());
54 });
55 }
56
57 std::vector<FaceId>
58 getLocalFaces()
59 {
60 auto enumerable = this->getFaceTable() |
61 boost::adaptors::filtered([] (shared_ptr<Face> face) {
Junxiao Shicde37ad2015-12-24 01:02:05 -070062 return face->getScope() == ndn::nfd::FACE_SCOPE_LOCAL;
Junxiao Shi49e11e72014-12-14 19:46:05 -070063 });
64
65 std::vector<FaceId> results;
66 for (shared_ptr<Face> face : enumerable) {
67 results.push_back(face->getId());
68 }
69 return results;
70 }
71
72public:
73 std::vector<FaceId> addedFaces;
74 std::vector<FaceId> removedFaces;
75};
76
77BOOST_AUTO_TEST_CASE(FaceTableAccess)
78{
79 Forwarder forwarder;
80 FaceTableAccessTestStrategy strategy(forwarder);
81
82 auto face1 = make_shared<DummyFace>();
Junxiao Shicde37ad2015-12-24 01:02:05 -070083 auto face2 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
Junxiao Shi49e11e72014-12-14 19:46:05 -070084 forwarder.addFace(face1);
85 forwarder.addFace(face2);
86 FaceId id1 = face1->getId();
87 FaceId id2 = face2->getId();
88
89 BOOST_CHECK(strategy.getLocalFaces() == std::vector<FaceId>{id2});
90
91 face2->close();
92 face1->close();
93
94 BOOST_CHECK((strategy.addedFaces == std::vector<FaceId>{id1, id2}));
95 BOOST_CHECK((strategy.removedFaces == std::vector<FaceId>{id2, id1}));
96}
97
Junxiao Shicde37ad2015-12-24 01:02:05 -070098BOOST_AUTO_TEST_SUITE_END() // TestStrategy
99BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi49e11e72014-12-14 19:46:05 -0700100
101} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800102} // namespace fw
Junxiao Shi49e11e72014-12-14 19:46:05 -0700103} // namespace nfd