blob: 82d4fccffd1921e9bdc0f73baf302cff526adac8 [file] [log] [blame]
Junxiao Shie5e2fce2014-02-10 20:01:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology
9 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Junxiao Shie5e2fce2014-02-10 20:01:53 -070024
25#include "table/strategy-info-host.hpp"
26
Junxiao Shid9ee45c2014-02-27 15:38:11 -070027#include "tests/test-common.hpp"
Junxiao Shie5e2fce2014-02-10 20:01:53 -070028
29namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070030namespace tests {
Junxiao Shie5e2fce2014-02-10 20:01:53 -070031
32static int g_DummyStrategyInfo_count = 0;
33
34class DummyStrategyInfo : public fw::StrategyInfo
35{
36public:
37 DummyStrategyInfo(int id)
38 : m_id(id)
39 {
40 ++g_DummyStrategyInfo_count;
41 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070042
Junxiao Shie5e2fce2014-02-10 20:01:53 -070043 virtual ~DummyStrategyInfo()
44 {
45 --g_DummyStrategyInfo_count;
46 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070047
Junxiao Shie5e2fce2014-02-10 20:01:53 -070048 int m_id;
49};
50
Junxiao Shid9ee45c2014-02-27 15:38:11 -070051BOOST_FIXTURE_TEST_SUITE(TableStrategyInfoHost, BaseFixture)
Junxiao Shie5e2fce2014-02-10 20:01:53 -070052
53BOOST_AUTO_TEST_CASE(SetGetClear)
54{
55 StrategyInfoHost host;
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070056
Junxiao Shie5e2fce2014-02-10 20:01:53 -070057 BOOST_CHECK(!static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070058
Junxiao Shie5e2fce2014-02-10 20:01:53 -070059 g_DummyStrategyInfo_count = 0;
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070060
Junxiao Shie5e2fce2014-02-10 20:01:53 -070061 shared_ptr<DummyStrategyInfo> info = make_shared<DummyStrategyInfo>(7591);
62 host.setStrategyInfo(info);
63 BOOST_REQUIRE(static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
64 BOOST_CHECK_EQUAL(host.getStrategyInfo<DummyStrategyInfo>()->m_id, 7591);
65
66 info.reset(); // unlink local reference
67 // host should still have a reference to info
68 BOOST_REQUIRE(static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
69 BOOST_CHECK_EQUAL(host.getStrategyInfo<DummyStrategyInfo>()->m_id, 7591);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070070
Junxiao Shie5e2fce2014-02-10 20:01:53 -070071 host.clearStrategyInfo();
72 BOOST_CHECK(!static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
73 BOOST_CHECK_EQUAL(g_DummyStrategyInfo_count, 0);
74}
75
76BOOST_AUTO_TEST_SUITE_END()
77
Junxiao Shid9ee45c2014-02-27 15:38:11 -070078} // namespace tests
Junxiao Shie5e2fce2014-02-10 20:01:53 -070079} // namespace nfd