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