Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame^] | 3 | * 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 Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 24 | |
| 25 | #include "table/strategy-info-host.hpp" |
| 26 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 27 | #include "tests/test-common.hpp" |
Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 28 | |
| 29 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 30 | namespace tests { |
Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 31 | |
| 32 | static int g_DummyStrategyInfo_count = 0; |
| 33 | |
| 34 | class DummyStrategyInfo : public fw::StrategyInfo |
| 35 | { |
| 36 | public: |
| 37 | DummyStrategyInfo(int id) |
| 38 | : m_id(id) |
| 39 | { |
| 40 | ++g_DummyStrategyInfo_count; |
| 41 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame^] | 42 | |
Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 43 | virtual ~DummyStrategyInfo() |
| 44 | { |
| 45 | --g_DummyStrategyInfo_count; |
| 46 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame^] | 47 | |
Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 48 | int m_id; |
| 49 | }; |
| 50 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 51 | BOOST_FIXTURE_TEST_SUITE(TableStrategyInfoHost, BaseFixture) |
Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 52 | |
| 53 | BOOST_AUTO_TEST_CASE(SetGetClear) |
| 54 | { |
| 55 | StrategyInfoHost host; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame^] | 56 | |
Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 57 | BOOST_CHECK(!static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>())); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame^] | 58 | |
Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 59 | g_DummyStrategyInfo_count = 0; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame^] | 60 | |
Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 61 | 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 Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame^] | 70 | |
Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 71 | host.clearStrategyInfo(); |
| 72 | BOOST_CHECK(!static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>())); |
| 73 | BOOST_CHECK_EQUAL(g_DummyStrategyInfo_count, 0); |
| 74 | } |
| 75 | |
| 76 | BOOST_AUTO_TEST_SUITE_END() |
| 77 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 78 | } // namespace tests |
Junxiao Shi | e5e2fce | 2014-02-10 20:01:53 -0700 | [diff] [blame] | 79 | } // namespace nfd |