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 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 9 | #include "tests/test-common.hpp" |
Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 10 | |
| 11 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 12 | namespace tests { |
Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 13 | |
| 14 | static int g_DummyStrategyInfo_count = 0; |
| 15 | |
| 16 | class DummyStrategyInfo : public fw::StrategyInfo |
| 17 | { |
| 18 | public: |
| 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 Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 33 | BOOST_FIXTURE_TEST_SUITE(TableStrategyInfoHost, BaseFixture) |
Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 34 | |
| 35 | BOOST_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 | |
| 58 | BOOST_AUTO_TEST_SUITE_END() |
| 59 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 60 | } // namespace tests |
Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 61 | } // namespace nfd |