Files
NFD/tests/table/strategy-info-host.cpp
T
Junxiao Shi d9ee45c952 tests: resetGlobalIoService for every test
All tests must use BaseFixture or a fixture derived from it to get this feature.

This commit also fixes a few warnings in tests/mgmt, and moves test cases into nfd::tests namespace.

refs #1290

Change-Id: I891441a5abce170e35648d463f7157b18429f79f
2014-02-27 19:36:19 -07:00

62 lines
1.5 KiB
C++

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (C) 2014 Named Data Networking Project
* See COPYING for copyright and distribution information.
*/
#include "table/strategy-info-host.hpp"
#include "tests/test-common.hpp"
namespace nfd {
namespace tests {
static int g_DummyStrategyInfo_count = 0;
class DummyStrategyInfo : public fw::StrategyInfo
{
public:
DummyStrategyInfo(int id)
: m_id(id)
{
++g_DummyStrategyInfo_count;
}
virtual ~DummyStrategyInfo()
{
--g_DummyStrategyInfo_count;
}
int m_id;
};
BOOST_FIXTURE_TEST_SUITE(TableStrategyInfoHost, BaseFixture)
BOOST_AUTO_TEST_CASE(SetGetClear)
{
StrategyInfoHost host;
BOOST_CHECK(!static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
g_DummyStrategyInfo_count = 0;
shared_ptr<DummyStrategyInfo> info = make_shared<DummyStrategyInfo>(7591);
host.setStrategyInfo(info);
BOOST_REQUIRE(static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
BOOST_CHECK_EQUAL(host.getStrategyInfo<DummyStrategyInfo>()->m_id, 7591);
info.reset(); // unlink local reference
// host should still have a reference to info
BOOST_REQUIRE(static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
BOOST_CHECK_EQUAL(host.getStrategyInfo<DummyStrategyInfo>()->m_id, 7591);
host.clearStrategyInfo();
BOOST_CHECK(!static_cast<bool>(host.getStrategyInfo<DummyStrategyInfo>()));
BOOST_CHECK_EQUAL(g_DummyStrategyInfo_count, 0);
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
} // namespace nfd