blob: 77f052651abe1ce50716730cabd4e2b8f48df4e4 [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:
20 explicit
21 MeasurementsAccessorTestStrategy(Forwarder& forwarder)
Junxiao Shibb5105f2014-03-03 12:06:45 -070022 : Strategy(forwarder, "ndn:/MeasurementsAccessorTestStrategy")
Junxiao Shidbe71732014-02-21 22:23:28 -070023 {
24 }
Junxiao Shic041ca32014-02-25 20:01:15 -070025
Junxiao Shidbe71732014-02-21 22:23:28 -070026 virtual
27 ~MeasurementsAccessorTestStrategy()
Junxiao Shic041ca32014-02-25 20:01:15 -070028
Junxiao Shidbe71732014-02-21 22:23:28 -070029 {
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 Shic041ca32014-02-25 20:01:15 -070040
Junxiao Shidbe71732014-02-21 22:23:28 -070041public: // accessors
42 MeasurementsAccessor&
43 getMeasurements_accessor()
44 {
45 return this->getMeasurements();
46 }
47};
48
49BOOST_AUTO_TEST_CASE(Access)
50{
Junxiao Shic041ca32014-02-25 20:01:15 -070051 Forwarder forwarder;
52
Junxiao Shidbe71732014-02-21 22:23:28 -070053 shared_ptr<MeasurementsAccessorTestStrategy> strategy1 =
54 make_shared<MeasurementsAccessorTestStrategy>(boost::ref(forwarder));
55 shared_ptr<MeasurementsAccessorTestStrategy> strategy2 =
56 make_shared<MeasurementsAccessorTestStrategy>(boost::ref(forwarder));
Junxiao Shic041ca32014-02-25 20:01:15 -070057
Junxiao Shidbe71732014-02-21 22:23:28 -070058 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 Shic041ca32014-02-25 20:01:15 -070063
Junxiao Shidbe71732014-02-21 22:23:28 -070064 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 Shic041ca32014-02-25 20:01:15 -070068
Junxiao Shidbe71732014-02-21 22:23:28 -070069 MeasurementsAccessor& accessor1 = strategy1->getMeasurements_accessor();
70 MeasurementsAccessor& accessor2 = strategy2->getMeasurements_accessor();
Junxiao Shic041ca32014-02-25 20:01:15 -070071
Junxiao Shidbe71732014-02-21 22:23:28 -070072 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 Shic041ca32014-02-25 20:01:15 -070077
Junxiao Shidbe71732014-02-21 22:23:28 -070078 shared_ptr<measurements::Entry> entryRoot = forwarder.getMeasurements().get(nameRoot);
79 BOOST_CHECK_NO_THROW(accessor1.getParent(entryRoot));
Junxiao Shic041ca32014-02-25 20:01:15 -070080
Junxiao Shidbe71732014-02-21 22:23:28 -070081 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
88BOOST_AUTO_TEST_SUITE_END()
89
Junxiao Shid9ee45c2014-02-27 15:38:11 -070090} // namespace tests
Junxiao Shidbe71732014-02-21 22:23:28 -070091} // namespace nfd