tests: don't use makeDummyClientFace

refs #3383

Change-Id: I1803a6f482a4e6bf43363cd08a73c4bbcb26d0a2
This commit is contained in:
Junxiao Shi committed 2016-07-14 18:21:56 +00:00
1 parent ff10da6575
commit 221b6fec69
9 files changed
+95 -94

No files matched your search

+28 -34
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, Regents of the University of California,
* Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,6 +27,7 @@
#include <ndn-cxx/encoding/tlv.hpp>
#include "tests/test-common.hpp"
#include "tests/identity-management-fixture.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
namespace nfd {
@@ -39,9 +40,9 @@ class SegmentPublisherTester : public SegmentPublisher<ndn::util::DummyClientFac
{
public:
SegmentPublisherTester(ndn::util::DummyClientFace& face,
const Name& prefix,
ndn::KeyChain& keyChain,
const time::milliseconds freshnessPeriod)
const Name& prefix,
ndn::KeyChain& keyChain,
const time::milliseconds freshnessPeriod)
: SegmentPublisher(face, prefix, keyChain, freshnessPeriod)
, m_totalPayloadLength(0)
{
@@ -49,9 +50,7 @@ public:
}
virtual
~SegmentPublisherTester()
{
}
~SegmentPublisherTester() = default;
uint16_t
getLimit() const
@@ -71,10 +70,9 @@ protected:
generate(ndn::EncodingBuffer& outBuffer)
{
size_t totalLength = 0;
for (int64_t i = 0; i < N; i++)
{
totalLength += prependNonNegativeIntegerBlock(outBuffer, tlv::Content, i);
}
for (int64_t i = 0; i < N; ++i) {
totalLength += prependNonNegativeIntegerBlock(outBuffer, tlv::Content, i);
}
m_totalPayloadLength += totalLength;
return totalLength;
}
@@ -84,13 +82,13 @@ protected:
};
template<int64_t N>
class SegmentPublisherFixture : public BaseFixture
class SegmentPublisherFixture : public IdentityManagementFixture
{
public:
SegmentPublisherFixture()
: m_face(ndn::util::makeDummyClientFace())
: m_face(m_keyChain)
, m_expectedFreshnessPeriod(time::milliseconds(111))
, m_publisher(*m_face, "/localhost/nfd/SegmentPublisherFixture",
, m_publisher(m_face, "/localhost/nfd/SegmentPublisherFixture",
m_keyChain, m_expectedFreshnessPeriod)
{
}
@@ -106,10 +104,9 @@ public:
m_buffer.appendByteArray(payload.value(), payload.value_size());
uint64_t segmentNo = data.getName()[-1].toSegment();
if (data.getFinalBlockId() != data.getName()[-1])
{
return;
}
if (data.getFinalBlockId() != data.getName()[-1]) {
return;
}
NFD_LOG_DEBUG("got final block: #" << segmentNo);
@@ -125,18 +122,16 @@ public:
BOOST_REQUIRE_EQUAL(parser.elements_size(), m_publisher.getLimit());
uint64_t expectedNo = m_publisher.getLimit() - 1;
for (Block::element_const_iterator i = parser.elements_begin();
i != parser.elements_end();
++i)
{
uint64_t number = readNonNegativeInteger(*i);
std::for_each(parser.elements_begin(), parser.elements_end(),
[&expectedNo] (const Block& element) {
uint64_t number = readNonNegativeInteger(element);
BOOST_REQUIRE_EQUAL(number, expectedNo);
--expectedNo;
}
});
}
protected:
shared_ptr<ndn::util::DummyClientFace> m_face;
ndn::util::DummyClientFace m_face;
const time::milliseconds m_expectedFreshnessPeriod;
SegmentPublisherTester<N> m_publisher;
ndn::EncodingBuffer m_buffer;
@@ -144,23 +139,22 @@ protected:
};
using boost::mpl::int_;
typedef boost::mpl::vector<int_<10000>, int_<100>, int_<10>, int_<0> > DatasetSizes;
typedef boost::mpl::vector<int_<10000>, int_<100>, int_<10>, int_<0>> DatasetSizes;
BOOST_AUTO_TEST_SUITE(TestSegmentPublisher)
BOOST_FIXTURE_TEST_CASE_TEMPLATE(Generate, T, DatasetSizes, SegmentPublisherFixture<T::value>)
{
this->m_publisher.publish();
this->m_face->processEvents();
this->m_face.processEvents();
size_t nSegments = this->m_publisher.getTotalPayloadLength() /
this->m_publisher.getMaxSegmentSize();
if (this->m_publisher.getTotalPayloadLength() % this->m_publisher.getMaxSegmentSize() != 0 ||
nSegments == 0)
++nSegments;
size_t nSegments =
this->m_publisher.getTotalPayloadLength() / this->m_publisher.getMaxSegmentSize() +
(this->m_publisher.getTotalPayloadLength() % this->m_publisher.getMaxSegmentSize() != 0 ||
this->m_publisher.getTotalPayloadLength() == 0);
BOOST_CHECK_EQUAL(this->m_face->sentDatas.size(), nSegments);
for (const Data& data : this->m_face->sentDatas) {
BOOST_CHECK_EQUAL(this->m_face.sentData.size(), nSegments);
for (const Data& data : this->m_face.sentData) {
this->validate(data);
}
}
@@ -27,6 +27,7 @@
#include "fw/forwarder.hpp"
#include "tests/test-common.hpp"
#include "tests/identity-management-fixture.hpp"
#include <ndn-cxx/mgmt/dispatcher.hpp>
#include <ndn-cxx/util/dummy-client-face.hpp>
@@ -46,8 +47,8 @@ class FaceManagerNode
{
public:
FaceManagerNode(ndn::KeyChain& keyChain, const std::string& port = "6363")
: face(ndn::util::makeDummyClientFace(getGlobalIoService(), {true, true}))
, dispatcher(*face, keyChain, ndn::security::SigningInfo())
: face(getGlobalIoService(), keyChain, {true, true})
, dispatcher(face, keyChain, ndn::security::SigningInfo())
, manager(forwarder.getFaceTable(), dispatcher, validator)
{
dispatcher.addTopPrefix("/localhost/nfd");
@@ -104,18 +105,19 @@ public:
public:
Forwarder forwarder;
shared_ptr<ndn::util::DummyClientFace> face;
ndn::util::DummyClientFace face;
ndn::mgmt::Dispatcher dispatcher;
CommandValidator validator;
FaceManager manager;
};
class FaceManagerFixture : public UnitTestTimeFixture
, public IdentityManagementFixture
{
public:
FaceManagerFixture()
: node1(keyChain, "16363")
, node2(keyChain, "26363")
: node1(m_keyChain, "16363")
, node2(m_keyChain, "26363")
{
advanceClocks(time::milliseconds(1), 100);
}
@@ -128,7 +130,6 @@ public:
}
public:
ndn::KeyChain keyChain;
FaceManagerNode node1; // used to test FaceManager
FaceManagerNode node2; // acts as a remote endpoint
};
@@ -263,10 +264,10 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(NewFace, T, Faces, FaceManagerFixture)
commandName.append(FaceType().getParameters().wireEncode());
shared_ptr<Interest> command(make_shared<Interest>(commandName));
this->keyChain.sign(*command);
m_keyChain.sign(*command);
bool hasCallbackFired = false;
this->node1.face->onSendData.connect([this, command, &hasCallbackFired] (const Data& response) {
this->node1.face.onSendData.connect([this, command, &hasCallbackFired] (const Data& response) {
// std::cout << response << std::endl;
if (!command->getName().isPrefixOf(response.getName())) {
return;
@@ -287,7 +288,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(NewFace, T, Faces, FaceManagerFixture)
hasCallbackFired = true;
});
this->node1.face->receive(*command);
this->node1.face.receive(*command);
this->advanceClocks(time::milliseconds(1), 100);
BOOST_CHECK(hasCallbackFired);
@@ -314,9 +315,9 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(ExistingFace, T, FaceTransitions, FaceManagerFi
commandName.append(FaceType1().getParameters().wireEncode());
shared_ptr<Interest> command(make_shared<Interest>(commandName));
this->keyChain.sign(*command);
m_keyChain.sign(*command);
this->node1.face->receive(*command);
this->node1.face.receive(*command);
this->advanceClocks(time::milliseconds(1), 10);
}
@@ -329,10 +330,10 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(ExistingFace, T, FaceTransitions, FaceManagerFi
commandName.append(FaceType2().getParameters().wireEncode());
shared_ptr<Interest> command(make_shared<Interest>(commandName));
this->keyChain.sign(*command);
m_keyChain.sign(*command);
bool hasCallbackFired = false;
this->node1.face->onSendData.connect([this, command, &hasCallbackFired] (const Data& response) {
this->node1.face.onSendData.connect([this, command, &hasCallbackFired] (const Data& response) {
if (!command->getName().isPrefixOf(response.getName())) {
return;
}
@@ -347,7 +348,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(ExistingFace, T, FaceTransitions, FaceManagerFi
hasCallbackFired = true;
});
this->node1.face->receive(*command);
this->node1.face.receive(*command);
this->advanceClocks(time::milliseconds(1), 10);
BOOST_CHECK(hasCallbackFired);
@@ -390,10 +391,10 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(ExistingFaceOnDemand, T, OnDemandFaceTransition
commandName.append(OtherNodeFace().getParameters().wireEncode());
shared_ptr<Interest> command(make_shared<Interest>(commandName));
this->keyChain.sign(*command);
m_keyChain.sign(*command);
ndn::util::signal::ScopedConnection connection =
this->node2.face->onSendData.connect([this, command] (const Data& response) {
this->node2.face.onSendData.connect([this, command] (const Data& response) {
if (!command->getName().isPrefixOf(response.getName())) {
return;
}
@@ -409,7 +410,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(ExistingFaceOnDemand, T, OnDemandFaceTransition
face->sendInterest(*dummyInterest);
});
this->node2.face->receive(*command);
this->node2.face.receive(*command);
this->advanceClocks(time::milliseconds(1), 10);
}
@@ -433,10 +434,10 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(ExistingFaceOnDemand, T, OnDemandFaceTransition
commandName.append(FaceType().getParameters().wireEncode());
shared_ptr<Interest> command(make_shared<Interest>(commandName));
this->keyChain.sign(*command);
m_keyChain.sign(*command);
bool hasCallbackFired = false;
this->node1.face->onSendData.connect([this, command, &hasCallbackFired] (const Data& response) {
this->node1.face.onSendData.connect([this, command, &hasCallbackFired] (const Data& response) {
if (!command->getName().isPrefixOf(response.getName())) {
return;
}
@@ -451,7 +452,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(ExistingFaceOnDemand, T, OnDemandFaceTransition
hasCallbackFired = true;
});
this->node1.face->receive(*command);
this->node1.face.receive(*command);
this->advanceClocks(time::milliseconds(1), 10);
BOOST_CHECK(hasCallbackFired);
+4 -4
View File
@@ -29,9 +29,9 @@ namespace nfd {
namespace tests {
ManagerCommonFixture::ManagerCommonFixture()
: m_face(ndn::util::makeDummyClientFace(UnitTestTimeFixture::g_io, {true, true}))
, m_dispatcher(*m_face, m_keyChain, ndn::security::SigningInfo())
, m_responses(m_face->sentDatas)
: m_face(getGlobalIoService(), m_keyChain, {true, true})
, m_dispatcher(m_face, m_keyChain, ndn::security::SigningInfo())
, m_responses(m_face.sentData)
, m_identityName("/unit-test/ManagerCommonFixture/identity")
, m_certificate(m_keyChain.getCertificate(m_keyChain.createIdentity(m_identityName)))
{
@@ -63,7 +63,7 @@ ManagerCommonFixture::makeControlCommandRequest(Name commandName,
void
ManagerCommonFixture::receiveInterest(shared_ptr<Interest> interest)
{
m_face->receive<Interest>(*interest);
m_face.receive(*interest);
advanceClocks(time::milliseconds(1));
}
+5 -5
View File
@@ -143,11 +143,11 @@ public: // verify
concatenateResponses(size_t startIndex = 0, size_t nResponses = 0);
protected:
shared_ptr<ndn::util::DummyClientFace> m_face;
ndn::mgmt::Dispatcher m_dispatcher;
std::vector<Data>& m_responses; // a reference of m_face->sentDatas
Name m_identityName; // the identity used to sign request
shared_ptr<ndn::IdentityCertificate> m_certificate; // the certificate used to sign request
ndn::util::DummyClientFace m_face;
ndn::mgmt::Dispatcher m_dispatcher;
std::vector<Data>& m_responses; ///< a reference of m_face->sentData
Name m_identityName; ///< the identity used to sign request
shared_ptr<ndn::IdentityCertificate> m_certificate; ///< the certificate used to sign request
};
std::ostream&
+13 -11
View File
@@ -33,20 +33,22 @@ namespace nfd {
namespace rib {
namespace tests {
using namespace nfd::tests;
NFD_LOG_INIT("AutoPrefixPropagatorTest");
const Name TEST_LINK_LOCAL_NFD_PREFIX("/localhop/nfd");
const time::milliseconds TEST_PREFIX_PROPAGATION_TIMEOUT(1000);
class AutoPrefixPropagatorFixture : public nfd::tests::IdentityManagementFixture
, public nfd::tests::UnitTestTimeFixture
class AutoPrefixPropagatorFixture : public IdentityManagementFixture
, public UnitTestTimeFixture
{
public:
AutoPrefixPropagatorFixture()
: m_face(ndn::util::makeDummyClientFace(nfd::tests::UnitTestTimeFixture::g_io, {true, true}))
, m_controller(*m_face, m_keyChain)
: m_face(getGlobalIoService(), m_keyChain, {true, true})
, m_controller(m_face, m_keyChain)
, m_propagator(m_controller, m_keyChain, m_rib)
, m_requests(m_face->sentInterests)
, m_requests(m_face.sentInterests)
, m_entries(m_propagator.m_propagatedEntries)
{
m_propagator.enable();
@@ -173,12 +175,12 @@ public: // helpers for check
}
protected:
shared_ptr<ndn::util::DummyClientFace> m_face;
ndn::nfd::Controller m_controller;
Rib m_rib;
AutoPrefixPropagator m_propagator;
std::vector<Interest>& m_requests; // store sent out requests
AutoPrefixPropagator::PropagatedEntryList& m_entries; // store propagated entries
ndn::util::DummyClientFace m_face;
ndn::nfd::Controller m_controller;
Rib m_rib;
AutoPrefixPropagator m_propagator;
std::vector<Interest>& m_requests; ///< store sent out requests
AutoPrefixPropagator::PropagatedEntryList& m_entries; ///< store propagated entries
};
std::ostream&
+9 -7
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, Regents of the University of California,
* Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -23,8 +23,9 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#include "rib-test-common.hpp"
#include "rib/fib-updater.hpp"
#include "rib-test-common.hpp"
#include "tests/identity-management-fixture.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
@@ -32,6 +33,8 @@ namespace nfd {
namespace rib {
namespace tests {
using namespace nfd::tests;
inline bool
compareNameFaceIdCostAction(const FibUpdate& lhs, const FibUpdate& rhs)
{
@@ -55,12 +58,12 @@ compareNameFaceIdCostAction(const FibUpdate& lhs, const FibUpdate& rhs)
return false;
}
class FibUpdatesFixture : public nfd::tests::BaseFixture
class FibUpdatesFixture : public IdentityManagementFixture
{
public:
FibUpdatesFixture()
: face(ndn::util::makeDummyClientFace())
, controller(*face, keyChain)
: face(getGlobalIoService(), m_keyChain)
, controller(face, m_keyChain)
, fibUpdater(rib, controller)
{
}
@@ -163,8 +166,7 @@ public:
}
public:
shared_ptr<ndn::util::DummyClientFace> face;
ndn::KeyChain keyChain;
ndn::util::DummyClientFace face;
ndn::nfd::Controller controller;
rib::FibUpdater fibUpdater;
rib::Rib rib;
+3 -3
View File
@@ -49,9 +49,9 @@ public:
explicit
RibManagerFixture(const ConfigurationStatus& status,
bool shouldClearRib)
: m_commands(m_face->sentInterests)
: m_commands(m_face.sentInterests)
, m_status(status)
, m_manager(m_dispatcher, *m_face, m_keyChain)
, m_manager(m_dispatcher, m_face, m_keyChain)
, m_rib(m_manager.m_rib)
{
m_rib.m_onSendBatchFromQueue = bind(&RibManagerFixture::onSendBatchFromQueue, this, _1);
@@ -112,7 +112,7 @@ private:
m_keyChain.sign(*data, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_SHA256));
m_face->getIoService().post([this, data] { m_face->receive(*data); });
m_face.getIoService().post([this, data] { m_face.receive(*data); });
};
Name commandPrefix("/localhost/nfd/fib/add-nexthop");
+6 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, Regents of the University of California,
* Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,9 +27,10 @@
#define RIB_TESTS_UNIT_TESTS_RIB_STATUS_PUBLISHER_COMMON_HPP
#include "rib/rib-status-publisher.hpp"
#include "rib/rib.hpp"
#include "tests/test-common.hpp"
#include "rib/rib.hpp"
#include "tests/identity-management-fixture.hpp"
#include <ndn-cxx/management/nfd-control-parameters.hpp>
#include <ndn-cxx/management/nfd-rib-entry.hpp>
@@ -40,9 +41,11 @@ namespace nfd {
namespace rib {
namespace tests {
using namespace nfd::tests;
using ndn::nfd::ControlParameters;
class RibStatusPublisherFixture : public nfd::tests::BaseFixture
class RibStatusPublisherFixture : public IdentityManagementFixture
{
public:
static void
+6 -7
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, Regents of the University of California,
* Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -47,15 +47,14 @@ BOOST_AUTO_TEST_CASE(Basic)
route.flags = ndn::nfd::ROUTE_FLAG_CAPTURE;
rib.insert(name, route);
ndn::KeyChain keyChain;
shared_ptr<ndn::util::DummyClientFace> face = ndn::util::makeDummyClientFace();
RibStatusPublisher publisher(rib, *face, "/localhost/nfd/rib/list", keyChain);
ndn::util::DummyClientFace face(getGlobalIoService(), m_keyChain);
RibStatusPublisher publisher(rib, face, "/localhost/nfd/rib/list", m_keyChain);
publisher.publish();
face->processEvents(time::milliseconds(1));
face.processEvents(time::milliseconds(1));
BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
decodeRibEntryBlock(face->sentDatas[0], name, route);
BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
decodeRibEntryBlock(face.sentData[0], name, route);
}