blob: 44fead20f3542fef4e7d4ca824e003bee632b188 [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 Shi49e11e72014-12-14 19:46:05 -070039BOOST_FIXTURE_TEST_SUITE(FwStrategy, BaseFixture)
40
41class FaceTableAccessTestStrategy : public DummyStrategy
42{
43public:
44 explicit
45 FaceTableAccessTestStrategy(Forwarder& forwarder)
46 : DummyStrategy(forwarder, Name("ndn:/strategy"))
47 {
48 this->afterAddFace.connect([this] (shared_ptr<Face> face) {
49 this->addedFaces.push_back(face->getId());
50 });
51 this->beforeRemoveFace.connect([this] (shared_ptr<Face> face) {
52 this->removedFaces.push_back(face->getId());
53 });
54 }
55
56 std::vector<FaceId>
57 getLocalFaces()
58 {
59 auto enumerable = this->getFaceTable() |
60 boost::adaptors::filtered([] (shared_ptr<Face> face) {
61 return face->isLocal();
62 });
63
64 std::vector<FaceId> results;
65 for (shared_ptr<Face> face : enumerable) {
66 results.push_back(face->getId());
67 }
68 return results;
69 }
70
71public:
72 std::vector<FaceId> addedFaces;
73 std::vector<FaceId> removedFaces;
74};
75
76BOOST_AUTO_TEST_CASE(FaceTableAccess)
77{
78 Forwarder forwarder;
79 FaceTableAccessTestStrategy strategy(forwarder);
80
81 auto face1 = make_shared<DummyFace>();
82 auto face2 = make_shared<DummyLocalFace>();
83 forwarder.addFace(face1);
84 forwarder.addFace(face2);
85 FaceId id1 = face1->getId();
86 FaceId id2 = face2->getId();
87
88 BOOST_CHECK(strategy.getLocalFaces() == std::vector<FaceId>{id2});
89
90 face2->close();
91 face1->close();
92
93 BOOST_CHECK((strategy.addedFaces == std::vector<FaceId>{id1, id2}));
94 BOOST_CHECK((strategy.removedFaces == std::vector<FaceId>{id2, id1}));
95}
96
97BOOST_AUTO_TEST_SUITE_END()
98
99} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800100} // namespace fw
Junxiao Shi49e11e72014-12-14 19:46:05 -0700101} // namespace nfd