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 | |
| 10 | #include <boost/test/unit_test.hpp> |
| 11 | |
| 12 | namespace nfd { |
| 13 | |
| 14 | BOOST_AUTO_TEST_SUITE(TableMeasurementsAccessor) |
| 15 | |
| 16 | class MeasurementsAccessorTestStrategy : public fw::Strategy |
| 17 | { |
| 18 | public: |
| 19 | explicit |
| 20 | MeasurementsAccessorTestStrategy(Forwarder& forwarder) |
| 21 | : Strategy(forwarder) |
| 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 | resetGlobalIoService(); |
| 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 | |
| 90 | } // namespace nfd |