blob: cbcbe5ad813dcfc6ea6665eb0255766c18670990 [file] [log] [blame]
Junxiao Shidbe71732014-02-21 22:23:28 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Junxiao Shidbe71732014-02-21 22:23:28 -070024
25#include "table/measurements-accessor.hpp"
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070026#include "fw/strategy.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070027
Junxiao Shid9ee45c2014-02-27 15:38:11 -070028#include "tests/test-common.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070029
30namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070031namespace tests {
Junxiao Shidbe71732014-02-21 22:23:28 -070032
Junxiao Shid9ee45c2014-02-27 15:38:11 -070033BOOST_FIXTURE_TEST_SUITE(TableMeasurementsAccessor, BaseFixture)
Junxiao Shidbe71732014-02-21 22:23:28 -070034
35class MeasurementsAccessorTestStrategy : public fw::Strategy
36{
37public:
Junxiao Shi7bb01512014-03-05 21:34:09 -070038 MeasurementsAccessorTestStrategy(Forwarder& forwarder, const Name& name)
39 : Strategy(forwarder, name)
Junxiao Shidbe71732014-02-21 22:23:28 -070040 {
41 }
Junxiao Shic041ca32014-02-25 20:01:15 -070042
Junxiao Shidbe71732014-02-21 22:23:28 -070043 virtual
44 ~MeasurementsAccessorTestStrategy()
Junxiao Shic041ca32014-02-25 20:01:15 -070045
Junxiao Shidbe71732014-02-21 22:23:28 -070046 {
47 }
48
49 virtual void
50 afterReceiveInterest(const Face& inFace,
51 const Interest& interest,
52 shared_ptr<fib::Entry> fibEntry,
53 shared_ptr<pit::Entry> pitEntry)
54 {
55 BOOST_ASSERT(false);
56 }
Junxiao Shic041ca32014-02-25 20:01:15 -070057
Junxiao Shidbe71732014-02-21 22:23:28 -070058public: // accessors
59 MeasurementsAccessor&
60 getMeasurements_accessor()
61 {
62 return this->getMeasurements();
63 }
64};
65
66BOOST_AUTO_TEST_CASE(Access)
67{
Junxiao Shic041ca32014-02-25 20:01:15 -070068 Forwarder forwarder;
69
Junxiao Shidbe71732014-02-21 22:23:28 -070070 shared_ptr<MeasurementsAccessorTestStrategy> strategy1 =
Alexander Afanasyevf6980282014-05-13 18:28:40 -070071 make_shared<MeasurementsAccessorTestStrategy>(ref(forwarder), "ndn:/strategy1");
Junxiao Shidbe71732014-02-21 22:23:28 -070072 shared_ptr<MeasurementsAccessorTestStrategy> strategy2 =
Alexander Afanasyevf6980282014-05-13 18:28:40 -070073 make_shared<MeasurementsAccessorTestStrategy>(ref(forwarder), "ndn:/strategy2");
Junxiao Shic041ca32014-02-25 20:01:15 -070074
Junxiao Shidbe71732014-02-21 22:23:28 -070075 Name nameRoot("ndn:/");
76 Name nameA ("ndn:/A");
77 Name nameAB ("ndn:/A/B");
78 Name nameABC ("ndn:/A/B/C");
79 Name nameAD ("ndn:/A/D");
Junxiao Shic041ca32014-02-25 20:01:15 -070080
Junxiao Shi7bb01512014-03-05 21:34:09 -070081 StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
82 strategyChoice.install(strategy1);
83 strategyChoice.install(strategy2);
84 strategyChoice.insert(nameRoot, strategy1->getName());
85 strategyChoice.insert(nameA , strategy2->getName());
86 strategyChoice.insert(nameAB , strategy1->getName());
Junxiao Shic041ca32014-02-25 20:01:15 -070087
Junxiao Shidbe71732014-02-21 22:23:28 -070088 MeasurementsAccessor& accessor1 = strategy1->getMeasurements_accessor();
89 MeasurementsAccessor& accessor2 = strategy2->getMeasurements_accessor();
Junxiao Shic041ca32014-02-25 20:01:15 -070090
Junxiao Shidbe71732014-02-21 22:23:28 -070091 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameRoot)), true);
92 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameA )), false);
93 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameAB )), true);
94 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameABC )), true);
95 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameAD )), false);
Junxiao Shic041ca32014-02-25 20:01:15 -070096
Junxiao Shidbe71732014-02-21 22:23:28 -070097 shared_ptr<measurements::Entry> entryRoot = forwarder.getMeasurements().get(nameRoot);
98 BOOST_CHECK_NO_THROW(accessor1.getParent(entryRoot));
Junxiao Shic041ca32014-02-25 20:01:15 -070099
Junxiao Shidbe71732014-02-21 22:23:28 -0700100 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameRoot)), false);
101 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameA )), true);
102 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameAB )), false);
103 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameABC )), false);
104 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameAD )), true);
105}
106
107BOOST_AUTO_TEST_SUITE_END()
108
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700109} // namespace tests
Junxiao Shidbe71732014-02-21 22:23:28 -0700110} // namespace nfd