Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "table/measurements-accessor.hpp" |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 8 | #include "fw/strategy.hpp" |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 9 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 10 | #include "tests/test-common.hpp" |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 11 | |
| 12 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 13 | namespace tests { |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 14 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 15 | BOOST_FIXTURE_TEST_SUITE(TableMeasurementsAccessor, BaseFixture) |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 16 | |
| 17 | class MeasurementsAccessorTestStrategy : public fw::Strategy |
| 18 | { |
| 19 | public: |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 20 | MeasurementsAccessorTestStrategy(Forwarder& forwarder, const Name& name) |
| 21 | : Strategy(forwarder, name) |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 22 | { |
| 23 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 24 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 25 | virtual |
| 26 | ~MeasurementsAccessorTestStrategy() |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 27 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 28 | { |
| 29 | } |
| 30 | |
| 31 | virtual void |
| 32 | afterReceiveInterest(const Face& inFace, |
| 33 | const Interest& interest, |
| 34 | shared_ptr<fib::Entry> fibEntry, |
| 35 | shared_ptr<pit::Entry> pitEntry) |
| 36 | { |
| 37 | BOOST_ASSERT(false); |
| 38 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 39 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 40 | public: // accessors |
| 41 | MeasurementsAccessor& |
| 42 | getMeasurements_accessor() |
| 43 | { |
| 44 | return this->getMeasurements(); |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | BOOST_AUTO_TEST_CASE(Access) |
| 49 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 50 | Forwarder forwarder; |
| 51 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 52 | shared_ptr<MeasurementsAccessorTestStrategy> strategy1 = |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 53 | make_shared<MeasurementsAccessorTestStrategy>(boost::ref(forwarder), "ndn:/strategy1"); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 54 | shared_ptr<MeasurementsAccessorTestStrategy> strategy2 = |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 55 | make_shared<MeasurementsAccessorTestStrategy>(boost::ref(forwarder), "ndn:/strategy2"); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 56 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 57 | Name nameRoot("ndn:/"); |
| 58 | Name nameA ("ndn:/A"); |
| 59 | Name nameAB ("ndn:/A/B"); |
| 60 | Name nameABC ("ndn:/A/B/C"); |
| 61 | Name nameAD ("ndn:/A/D"); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 62 | |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 63 | StrategyChoice& strategyChoice = forwarder.getStrategyChoice(); |
| 64 | strategyChoice.install(strategy1); |
| 65 | strategyChoice.install(strategy2); |
| 66 | strategyChoice.insert(nameRoot, strategy1->getName()); |
| 67 | strategyChoice.insert(nameA , strategy2->getName()); |
| 68 | strategyChoice.insert(nameAB , strategy1->getName()); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 69 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 70 | MeasurementsAccessor& accessor1 = strategy1->getMeasurements_accessor(); |
| 71 | MeasurementsAccessor& accessor2 = strategy2->getMeasurements_accessor(); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 72 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 73 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameRoot)), true); |
| 74 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameA )), false); |
| 75 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameAB )), true); |
| 76 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameABC )), true); |
| 77 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameAD )), false); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 78 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 79 | shared_ptr<measurements::Entry> entryRoot = forwarder.getMeasurements().get(nameRoot); |
| 80 | BOOST_CHECK_NO_THROW(accessor1.getParent(entryRoot)); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 81 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 82 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameRoot)), false); |
| 83 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameA )), true); |
| 84 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameAB )), false); |
| 85 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameABC )), false); |
| 86 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameAD )), true); |
| 87 | } |
| 88 | |
| 89 | BOOST_AUTO_TEST_SUITE_END() |
| 90 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 91 | } // namespace tests |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 92 | } // namespace nfd |