blob: caeb6d41d21a28fd94661e3a4dfb777f00e8b570 [file] [log] [blame]
Junxiao Shidbe71732014-02-21 22:23:28 -07001/* -*- 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 Shi2d9bdc82014-03-02 20:55:42 -07008#include "fw/strategy.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -07009
Junxiao Shid9ee45c2014-02-27 15:38:11 -070010#include "tests/test-common.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070011
12namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070013namespace tests {
Junxiao Shidbe71732014-02-21 22:23:28 -070014
Junxiao Shid9ee45c2014-02-27 15:38:11 -070015BOOST_FIXTURE_TEST_SUITE(TableMeasurementsAccessor, BaseFixture)
Junxiao Shidbe71732014-02-21 22:23:28 -070016
17class MeasurementsAccessorTestStrategy : public fw::Strategy
18{
19public:
Junxiao Shi7bb01512014-03-05 21:34:09 -070020 MeasurementsAccessorTestStrategy(Forwarder& forwarder, const Name& name)
21 : Strategy(forwarder, name)
Junxiao Shidbe71732014-02-21 22:23:28 -070022 {
23 }
Junxiao Shic041ca32014-02-25 20:01:15 -070024
Junxiao Shidbe71732014-02-21 22:23:28 -070025 virtual
26 ~MeasurementsAccessorTestStrategy()
Junxiao Shic041ca32014-02-25 20:01:15 -070027
Junxiao Shidbe71732014-02-21 22:23:28 -070028 {
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 Shic041ca32014-02-25 20:01:15 -070039
Junxiao Shidbe71732014-02-21 22:23:28 -070040public: // accessors
41 MeasurementsAccessor&
42 getMeasurements_accessor()
43 {
44 return this->getMeasurements();
45 }
46};
47
48BOOST_AUTO_TEST_CASE(Access)
49{
Junxiao Shic041ca32014-02-25 20:01:15 -070050 Forwarder forwarder;
51
Junxiao Shidbe71732014-02-21 22:23:28 -070052 shared_ptr<MeasurementsAccessorTestStrategy> strategy1 =
Junxiao Shi7bb01512014-03-05 21:34:09 -070053 make_shared<MeasurementsAccessorTestStrategy>(boost::ref(forwarder), "ndn:/strategy1");
Junxiao Shidbe71732014-02-21 22:23:28 -070054 shared_ptr<MeasurementsAccessorTestStrategy> strategy2 =
Junxiao Shi7bb01512014-03-05 21:34:09 -070055 make_shared<MeasurementsAccessorTestStrategy>(boost::ref(forwarder), "ndn:/strategy2");
Junxiao Shic041ca32014-02-25 20:01:15 -070056
Junxiao Shidbe71732014-02-21 22:23:28 -070057 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 Shic041ca32014-02-25 20:01:15 -070062
Junxiao Shi7bb01512014-03-05 21:34:09 -070063 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 Shic041ca32014-02-25 20:01:15 -070069
Junxiao Shidbe71732014-02-21 22:23:28 -070070 MeasurementsAccessor& accessor1 = strategy1->getMeasurements_accessor();
71 MeasurementsAccessor& accessor2 = strategy2->getMeasurements_accessor();
Junxiao Shic041ca32014-02-25 20:01:15 -070072
Junxiao Shidbe71732014-02-21 22:23:28 -070073 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 Shic041ca32014-02-25 20:01:15 -070078
Junxiao Shidbe71732014-02-21 22:23:28 -070079 shared_ptr<measurements::Entry> entryRoot = forwarder.getMeasurements().get(nameRoot);
80 BOOST_CHECK_NO_THROW(accessor1.getParent(entryRoot));
Junxiao Shic041ca32014-02-25 20:01:15 -070081
Junxiao Shidbe71732014-02-21 22:23:28 -070082 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
89BOOST_AUTO_TEST_SUITE_END()
90
Junxiao Shid9ee45c2014-02-27 15:38:11 -070091} // namespace tests
Junxiao Shidbe71732014-02-21 22:23:28 -070092} // namespace nfd