blob: 8d09ca4010eab8fee0dd8c77e91de905a536c2fe [file] [log] [blame]
Junxiao Shidbe71732014-02-21 22:23:28 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shie368d992014-12-02 23:44:31 -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 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -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/>.
Junxiao Shie368d992014-12-02 23:44:31 -070024 */
Junxiao Shidbe71732014-02-21 22:23:28 -070025
26#include "table/measurements-accessor.hpp"
Junxiao Shi2d9bdc82014-03-02 20:55:42 -070027#include "fw/strategy.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070028
Junxiao Shid9ee45c2014-02-27 15:38:11 -070029#include "tests/test-common.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070030
31namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070032namespace tests {
Junxiao Shidbe71732014-02-21 22:23:28 -070033
Junxiao Shid9ee45c2014-02-27 15:38:11 -070034BOOST_FIXTURE_TEST_SUITE(TableMeasurementsAccessor, BaseFixture)
Junxiao Shidbe71732014-02-21 22:23:28 -070035
36class MeasurementsAccessorTestStrategy : public fw::Strategy
37{
38public:
Junxiao Shi7bb01512014-03-05 21:34:09 -070039 MeasurementsAccessorTestStrategy(Forwarder& forwarder, const Name& name)
40 : Strategy(forwarder, name)
Junxiao Shidbe71732014-02-21 22:23:28 -070041 {
42 }
Junxiao Shic041ca32014-02-25 20:01:15 -070043
Junxiao Shidbe71732014-02-21 22:23:28 -070044 virtual
45 ~MeasurementsAccessorTestStrategy()
Junxiao Shic041ca32014-02-25 20:01:15 -070046
Junxiao Shidbe71732014-02-21 22:23:28 -070047 {
48 }
49
50 virtual void
51 afterReceiveInterest(const Face& inFace,
52 const Interest& interest,
53 shared_ptr<fib::Entry> fibEntry,
54 shared_ptr<pit::Entry> pitEntry)
55 {
56 BOOST_ASSERT(false);
57 }
Junxiao Shic041ca32014-02-25 20:01:15 -070058
Junxiao Shidbe71732014-02-21 22:23:28 -070059public: // accessors
60 MeasurementsAccessor&
61 getMeasurements_accessor()
62 {
63 return this->getMeasurements();
64 }
65};
66
67BOOST_AUTO_TEST_CASE(Access)
68{
Junxiao Shic041ca32014-02-25 20:01:15 -070069 Forwarder forwarder;
70
Junxiao Shie368d992014-12-02 23:44:31 -070071 auto strategy1 = make_shared<MeasurementsAccessorTestStrategy>(ref(forwarder), "ndn:/strategy1");
72 auto strategy2 = make_shared<MeasurementsAccessorTestStrategy>(ref(forwarder), "ndn:/strategy2");
Junxiao Shic041ca32014-02-25 20:01:15 -070073
Junxiao Shidbe71732014-02-21 22:23:28 -070074 Name nameRoot("ndn:/");
75 Name nameA ("ndn:/A");
76 Name nameAB ("ndn:/A/B");
77 Name nameABC ("ndn:/A/B/C");
78 Name nameAD ("ndn:/A/D");
Junxiao Shic041ca32014-02-25 20:01:15 -070079
Junxiao Shi7bb01512014-03-05 21:34:09 -070080 StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
81 strategyChoice.install(strategy1);
82 strategyChoice.install(strategy2);
83 strategyChoice.insert(nameRoot, strategy1->getName());
84 strategyChoice.insert(nameA , strategy2->getName());
85 strategyChoice.insert(nameAB , strategy1->getName());
Junxiao Shic041ca32014-02-25 20:01:15 -070086
Junxiao Shidbe71732014-02-21 22:23:28 -070087 MeasurementsAccessor& accessor1 = strategy1->getMeasurements_accessor();
88 MeasurementsAccessor& accessor2 = strategy2->getMeasurements_accessor();
Junxiao Shic041ca32014-02-25 20:01:15 -070089
Junxiao Shidbe71732014-02-21 22:23:28 -070090 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameRoot)), true);
91 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameA )), false);
92 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameAB )), true);
93 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameABC )), true);
94 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameAD )), false);
Junxiao Shic041ca32014-02-25 20:01:15 -070095
Junxiao Shidbe71732014-02-21 22:23:28 -070096 shared_ptr<measurements::Entry> entryRoot = forwarder.getMeasurements().get(nameRoot);
Junxiao Shie368d992014-12-02 23:44:31 -070097 BOOST_CHECK_NO_THROW(accessor1.getParent(*entryRoot));
Junxiao Shic041ca32014-02-25 20:01:15 -070098
Junxiao Shidbe71732014-02-21 22:23:28 -070099 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameRoot)), false);
100 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameA )), true);
101 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameAB )), false);
102 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameABC )), false);
103 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameAD )), true);
104}
105
106BOOST_AUTO_TEST_SUITE_END()
107
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700108} // namespace tests
Junxiao Shidbe71732014-02-21 22:23:28 -0700109} // namespace nfd