Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame^] | 1 | /* -*- 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 | |
| 11 | namespace nfd { |
| 12 | |
| 13 | static int g_DummyStrategyInfo_count = 0; |
| 14 | |
| 15 | class DummyStrategyInfo : public fw::StrategyInfo |
| 16 | { |
| 17 | public: |
| 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 | |
| 32 | BOOST_AUTO_TEST_SUITE(TableStrategyInfoHost) |
| 33 | |
| 34 | BOOST_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 | |
| 57 | BOOST_AUTO_TEST_SUITE_END() |
| 58 | |
| 59 | } // namespace nfd |