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