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" |
| 8 | #include "fw/forwarder.hpp" |
| 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: |
| 20 | explicit |
| 21 | MeasurementsAccessorTestStrategy(Forwarder& forwarder) |
| 22 | : Strategy(forwarder) |
| 23 | { |
| 24 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 25 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 26 | virtual |
| 27 | ~MeasurementsAccessorTestStrategy() |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 28 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 29 | { |
| 30 | } |
| 31 | |
| 32 | virtual void |
| 33 | afterReceiveInterest(const Face& inFace, |
| 34 | const Interest& interest, |
| 35 | shared_ptr<fib::Entry> fibEntry, |
| 36 | shared_ptr<pit::Entry> pitEntry) |
| 37 | { |
| 38 | BOOST_ASSERT(false); |
| 39 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 40 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 41 | public: // accessors |
| 42 | MeasurementsAccessor& |
| 43 | getMeasurements_accessor() |
| 44 | { |
| 45 | return this->getMeasurements(); |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | BOOST_AUTO_TEST_CASE(Access) |
| 50 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 51 | Forwarder forwarder; |
| 52 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 53 | shared_ptr<MeasurementsAccessorTestStrategy> strategy1 = |
| 54 | make_shared<MeasurementsAccessorTestStrategy>(boost::ref(forwarder)); |
| 55 | shared_ptr<MeasurementsAccessorTestStrategy> strategy2 = |
| 56 | make_shared<MeasurementsAccessorTestStrategy>(boost::ref(forwarder)); |
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 | Name nameRoot("ndn:/"); |
| 59 | Name nameA ("ndn:/A"); |
| 60 | Name nameAB ("ndn:/A/B"); |
| 61 | Name nameABC ("ndn:/A/B/C"); |
| 62 | Name nameAD ("ndn:/A/D"); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 63 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 64 | Fib& fib = forwarder.getFib(); |
| 65 | fib.insert(nameRoot).first->setStrategy(strategy1); |
| 66 | fib.insert(nameA ).first->setStrategy(strategy2); |
| 67 | fib.insert(nameAB ).first->setStrategy(strategy1); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 68 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 69 | MeasurementsAccessor& accessor1 = strategy1->getMeasurements_accessor(); |
| 70 | MeasurementsAccessor& accessor2 = strategy2->getMeasurements_accessor(); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 71 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 72 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameRoot)), true); |
| 73 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameA )), false); |
| 74 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameAB )), true); |
| 75 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameABC )), true); |
| 76 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameAD )), false); |
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 | shared_ptr<measurements::Entry> entryRoot = forwarder.getMeasurements().get(nameRoot); |
| 79 | BOOST_CHECK_NO_THROW(accessor1.getParent(entryRoot)); |
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>(accessor2.get(nameRoot)), false); |
| 82 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameA )), true); |
| 83 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameAB )), false); |
| 84 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameABC )), false); |
| 85 | BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameAD )), true); |
| 86 | } |
| 87 | |
| 88 | BOOST_AUTO_TEST_SUITE_END() |
| 89 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame^] | 90 | } // namespace tests |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 91 | } // namespace nfd |