blob: b2d1f0798fc414a5d95635d5bc5c032ac8d3a401 [file] [log] [blame]
Junxiao Shie5e2fce2014-02-10 20:01:53 -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/strategy-info-host.hpp"
8
Junxiao Shid9ee45c2014-02-27 15:38:11 -07009#include "tests/test-common.hpp"
Junxiao Shie5e2fce2014-02-10 20:01:53 -070010
11namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070012namespace tests {
Junxiao Shie5e2fce2014-02-10 20:01:53 -070013
14static int g_DummyStrategyInfo_count = 0;
15
16class DummyStrategyInfo : public fw::StrategyInfo
17{
18public:
19 DummyStrategyInfo(int id)
20 : m_id(id)
21 {
22 ++g_DummyStrategyInfo_count;
23 }
24
25 virtual ~DummyStrategyInfo()
26 {
27 --g_DummyStrategyInfo_count;
28 }
29
30 int m_id;
31};
32
Junxiao Shid9ee45c2014-02-27 15:38:11 -070033BOOST_FIXTURE_TEST_SUITE(TableStrategyInfoHost, BaseFixture)
Junxiao Shie5e2fce2014-02-10 20:01:53 -070034
35BOOST_AUTO_TEST_CASE(SetGetClear)
36{
37 StrategyInfoHost host;
38
39 BOOST_CHECK(!static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
40
41 g_DummyStrategyInfo_count = 0;
42
43 shared_ptr<DummyStrategyInfo> info = make_shared<DummyStrategyInfo>(7591);
44 host.setStrategyInfo(info);
45 BOOST_REQUIRE(static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
46 BOOST_CHECK_EQUAL(host.getStrategyInfo<DummyStrategyInfo>()->m_id, 7591);
47
48 info.reset(); // unlink local reference
49 // host should still have a reference to info
50 BOOST_REQUIRE(static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
51 BOOST_CHECK_EQUAL(host.getStrategyInfo<DummyStrategyInfo>()->m_id, 7591);
52
53 host.clearStrategyInfo();
54 BOOST_CHECK(!static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
55 BOOST_CHECK_EQUAL(g_DummyStrategyInfo_count, 0);
56}
57
58BOOST_AUTO_TEST_SUITE_END()
59
Junxiao Shid9ee45c2014-02-27 15:38:11 -070060} // namespace tests
Junxiao Shie5e2fce2014-02-10 20:01:53 -070061} // namespace nfd