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