Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | e368d99 | 2014-12-02 23:44:31 -0700 | [diff] [blame] | 3 | * 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 Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Junxiao Shi | e368d99 | 2014-12-02 23:44:31 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 25 | |
| 26 | #include "table/measurements-accessor.hpp" |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 27 | #include "fw/strategy.hpp" |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 28 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
Junxiao Shi | 1c93cae | 2014-12-09 22:52:17 -0700 | [diff] [blame^] | 30 | #include "../fw/dummy-strategy.hpp" |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 33 | namespace tests { |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 34 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 35 | BOOST_FIXTURE_TEST_SUITE(TableMeasurementsAccessor, BaseFixture) |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 36 | |
Junxiao Shi | 1c93cae | 2014-12-09 22:52:17 -0700 | [diff] [blame^] | 37 | class MeasurementsAccessorTestStrategy : public DummyStrategy |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 38 | { |
| 39 | public: |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 40 | MeasurementsAccessorTestStrategy(Forwarder& forwarder, const Name& name) |
Junxiao Shi | 1c93cae | 2014-12-09 22:52:17 -0700 | [diff] [blame^] | 41 | : DummyStrategy(forwarder, name) |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 42 | { |
| 43 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 44 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 45 | virtual |
| 46 | ~MeasurementsAccessorTestStrategy() |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 47 | { |
| 48 | } |
| 49 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 50 | public: // accessors |
| 51 | MeasurementsAccessor& |
| 52 | getMeasurements_accessor() |
| 53 | { |
| 54 | return this->getMeasurements(); |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | BOOST_AUTO_TEST_CASE(Access) |
| 59 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 60 | Forwarder forwarder; |
| 61 | |
Junxiao Shi | e368d99 | 2014-12-02 23:44:31 -0700 | [diff] [blame] | 62 | auto strategy1 = make_shared<MeasurementsAccessorTestStrategy>(ref(forwarder), "ndn:/strategy1"); |
| 63 | auto strategy2 = make_shared<MeasurementsAccessorTestStrategy>(ref(forwarder), "ndn:/strategy2"); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 64 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 65 | 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 Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 70 | |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 71 | 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 Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 77 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 78 | MeasurementsAccessor& accessor1 = strategy1->getMeasurements_accessor(); |
| 79 | MeasurementsAccessor& accessor2 = strategy2->getMeasurements_accessor(); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 80 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 81 | 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 Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 86 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 87 | shared_ptr<measurements::Entry> entryRoot = forwarder.getMeasurements().get(nameRoot); |
Junxiao Shi | e368d99 | 2014-12-02 23:44:31 -0700 | [diff] [blame] | 88 | BOOST_CHECK_NO_THROW(accessor1.getParent(*entryRoot)); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 89 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 90 | 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 | |
| 97 | BOOST_AUTO_TEST_SUITE_END() |
| 98 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 99 | } // namespace tests |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 100 | } // namespace nfd |