blob: af3351e23eceb55f708be2a6397a35326d7571c6 [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
9#include <boost/test/unit_test.hpp>
10
11namespace nfd {
12
13static int g_DummyStrategyInfo_count = 0;
14
15class DummyStrategyInfo : public fw::StrategyInfo
16{
17public:
18 DummyStrategyInfo(int id)
19 : m_id(id)
20 {
21 ++g_DummyStrategyInfo_count;
22 }
23
24 virtual ~DummyStrategyInfo()
25 {
26 --g_DummyStrategyInfo_count;
27 }
28
29 int m_id;
30};
31
32BOOST_AUTO_TEST_SUITE(TableStrategyInfoHost)
33
34BOOST_AUTO_TEST_CASE(SetGetClear)
35{
36 StrategyInfoHost host;
37
38 BOOST_CHECK(!static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
39
40 g_DummyStrategyInfo_count = 0;
41
42 shared_ptr<DummyStrategyInfo> info = make_shared<DummyStrategyInfo>(7591);
43 host.setStrategyInfo(info);
44 BOOST_REQUIRE(static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
45 BOOST_CHECK_EQUAL(host.getStrategyInfo<DummyStrategyInfo>()->m_id, 7591);
46
47 info.reset(); // unlink local reference
48 // host should still have a reference to info
49 BOOST_REQUIRE(static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
50 BOOST_CHECK_EQUAL(host.getStrategyInfo<DummyStrategyInfo>()->m_id, 7591);
51
52 host.clearStrategyInfo();
53 BOOST_CHECK(!static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
54 BOOST_CHECK_EQUAL(g_DummyStrategyInfo_count, 0);
55}
56
57BOOST_AUTO_TEST_SUITE_END()
58
59} // namespace nfd