blob: 8668368bef0821b01658dc5fb34477842a92a13d [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 Shi1c93cae2014-12-09 22:52:17 -070030#include "../fw/dummy-strategy.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070031
32namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070033namespace tests {
Junxiao Shidbe71732014-02-21 22:23:28 -070034
Junxiao Shid9ee45c2014-02-27 15:38:11 -070035BOOST_FIXTURE_TEST_SUITE(TableMeasurementsAccessor, BaseFixture)
Junxiao Shidbe71732014-02-21 22:23:28 -070036
Junxiao Shi1c93cae2014-12-09 22:52:17 -070037class MeasurementsAccessorTestStrategy : public DummyStrategy
Junxiao Shidbe71732014-02-21 22:23:28 -070038{
39public:
Junxiao Shi7bb01512014-03-05 21:34:09 -070040 MeasurementsAccessorTestStrategy(Forwarder& forwarder, const Name& name)
Junxiao Shi1c93cae2014-12-09 22:52:17 -070041 : DummyStrategy(forwarder, name)
Junxiao Shidbe71732014-02-21 22:23:28 -070042 {
43 }
Junxiao Shic041ca32014-02-25 20:01:15 -070044
Junxiao Shidbe71732014-02-21 22:23:28 -070045 virtual
46 ~MeasurementsAccessorTestStrategy()
Junxiao Shidbe71732014-02-21 22:23:28 -070047 {
48 }
49
Junxiao Shidbe71732014-02-21 22:23:28 -070050public: // accessors
51 MeasurementsAccessor&
52 getMeasurements_accessor()
53 {
54 return this->getMeasurements();
55 }
56};
57
58BOOST_AUTO_TEST_CASE(Access)
59{
Junxiao Shic041ca32014-02-25 20:01:15 -070060 Forwarder forwarder;
61
Junxiao Shie368d992014-12-02 23:44:31 -070062 auto strategy1 = make_shared<MeasurementsAccessorTestStrategy>(ref(forwarder), "ndn:/strategy1");
63 auto strategy2 = make_shared<MeasurementsAccessorTestStrategy>(ref(forwarder), "ndn:/strategy2");
Junxiao Shic041ca32014-02-25 20:01:15 -070064
Junxiao Shidbe71732014-02-21 22:23:28 -070065 Name nameRoot("ndn:/");
66 Name nameA ("ndn:/A");
67 Name nameAB ("ndn:/A/B");
68 Name nameABC ("ndn:/A/B/C");
69 Name nameAD ("ndn:/A/D");
Junxiao Shic041ca32014-02-25 20:01:15 -070070
Junxiao Shi7bb01512014-03-05 21:34:09 -070071 StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
72 strategyChoice.install(strategy1);
73 strategyChoice.install(strategy2);
74 strategyChoice.insert(nameRoot, strategy1->getName());
75 strategyChoice.insert(nameA , strategy2->getName());
76 strategyChoice.insert(nameAB , strategy1->getName());
Junxiao Shic041ca32014-02-25 20:01:15 -070077
Junxiao Shidbe71732014-02-21 22:23:28 -070078 MeasurementsAccessor& accessor1 = strategy1->getMeasurements_accessor();
79 MeasurementsAccessor& accessor2 = strategy2->getMeasurements_accessor();
Junxiao Shic041ca32014-02-25 20:01:15 -070080
Junxiao Shidbe71732014-02-21 22:23:28 -070081 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameRoot)), true);
82 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameA )), false);
83 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameAB )), true);
84 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameABC )), true);
85 BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameAD )), false);
Junxiao Shic041ca32014-02-25 20:01:15 -070086
Junxiao Shidbe71732014-02-21 22:23:28 -070087 shared_ptr<measurements::Entry> entryRoot = forwarder.getMeasurements().get(nameRoot);
Junxiao Shie368d992014-12-02 23:44:31 -070088 BOOST_CHECK_NO_THROW(accessor1.getParent(*entryRoot));
Junxiao Shic041ca32014-02-25 20:01:15 -070089
Junxiao Shidbe71732014-02-21 22:23:28 -070090 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameRoot)), false);
91 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameA )), true);
92 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameAB )), false);
93 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameABC )), false);
94 BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameAD )), true);
95}
96
97BOOST_AUTO_TEST_SUITE_END()
98
Junxiao Shid9ee45c2014-02-27 15:38:11 -070099} // namespace tests
Junxiao Shidbe71732014-02-21 22:23:28 -0700100} // namespace nfd