blob: 2198c7e0cf9ad9a60afea1f14455a3545af9414c [file] [log] [blame]
Junxiao Shi38b24c72017-01-05 02:59:31 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
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#ifndef NFD_TESTS_DAEMON_FACE_FACE_SYSTEM_FIXTURE_HPP
27#define NFD_TESTS_DAEMON_FACE_FACE_SYSTEM_FIXTURE_HPP
28
Junxiao Shi7003c602017-01-10 13:35:28 +000029#include "face/face.hpp"
Junxiao Shi38b24c72017-01-05 02:59:31 +000030#include "face/face-system.hpp"
31#include "fw/face-table.hpp"
32
33#include "tests/test-common.hpp"
34
35namespace nfd {
36namespace face {
37namespace tests {
38
39using namespace nfd::tests;
40
Junxiao Shi7003c602017-01-10 13:35:28 +000041class FaceSystemFixture : public virtual BaseFixture
Junxiao Shi38b24c72017-01-05 02:59:31 +000042{
43public:
44 FaceSystemFixture()
45 : faceSystem(faceTable)
46 {
47 faceSystem.setConfigFile(configFile);
48 }
49
50 void
51 parseConfig(const std::string& text, bool isDryRun)
52 {
53 configFile.parse(text, isDryRun, "test-config");
54 }
55
56 /** \brief get ProtocolFactory from FaceSystem
57 * \tparam F ProtocolFactory subclass
58 *
59 * If ProtocolFactory with \p scheme does not exist or has an incompatible type,
60 * this fails the test case.
61 */
62 template<typename F>
63 F&
64 getFactoryById(const std::string& id)
65 {
66 F* factory = dynamic_cast<F*>(faceSystem.getFactoryById(id));
67 BOOST_REQUIRE(factory != nullptr);
68 return *factory;
69 }
70
71 /** \brief get ProtocolFactory from FaceSystem
72 * \tparam F ProtocolFactory subclass
73 *
74 * If ProtocolFactory with \p scheme does not exist or has an incompatible type,
75 * this fails the test case.
76 */
77 template<typename F>
78 F&
79 getFactoryByScheme(const std::string& scheme)
80 {
81 F* factory = dynamic_cast<F*>(faceSystem.getFactoryByScheme(scheme));
82 BOOST_REQUIRE(factory != nullptr);
83 return *factory;
84 }
85
Junxiao Shi7003c602017-01-10 13:35:28 +000086 /** \brief list faces of specified scheme from FaceTable
87 * \param scheme local or remote FaceUri scheme
88 * \param linkType if not NONE, filter by specified LinkType
89 */
90 std::vector<const Face*>
91 listFacesByScheme(const std::string& scheme,
92 ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_NONE) const
93 {
94 std::vector<const Face*> faces;
95 for (const Face& face : faceTable) {
96 if ((face.getLocalUri().getScheme() == scheme ||
97 face.getRemoteUri().getScheme() == scheme) &&
98 (linkType == ndn::nfd::LINK_TYPE_NONE ||
99 face.getLinkType() == linkType)) {
100 faces.push_back(&face);
101 }
102 }
103 return faces;
104 }
105
Junxiao Shi38b24c72017-01-05 02:59:31 +0000106protected:
107 ConfigFile configFile;
108 FaceTable faceTable;
109 FaceSystem faceSystem;
110};
111
112} // namespace tests
113} // namespace face
114} // namespace nfd
115
116#endif // NFD_TESTS_DAEMON_FACE_FACE_SYSTEM_FIXTURE_HPP