face: introduce NullTransport and use it in several places
Refs: #4528
Change-Id: Icc7a77232bca1a700ce1319493c15a85d05d7488
diff --git a/tests/daemon/face/dummy-transport.hpp b/tests/daemon/face/dummy-transport.hpp
index 08a7141..1594df8 100644
--- a/tests/daemon/face/dummy-transport.hpp
+++ b/tests/daemon/face/dummy-transport.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -28,47 +28,39 @@
#include "core/common.hpp"
-#include "face/transport.hpp"
+#include "face/null-transport.hpp"
namespace nfd {
namespace face {
namespace tests {
-/** \brief dummy Transport used in unit tests
+/** \brief Dummy Transport type used in unit tests.
+ *
+ * All packets sent through this transport are stored in `sentPackets`.
+ * Reception of a packet can be simulated by invoking `receivePacket()`.
+ * All persistency changes are recorded in `persistencyHistory`.
*/
-class DummyTransport : public Transport
+template<bool CAN_CHANGE_PERSISTENCY>
+class DummyTransportBase : public NullTransport
{
public:
- DummyTransport(const std::string& localUri = "dummy://",
- const std::string& remoteUri = "dummy://",
- ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL,
- ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT,
- ssize_t mtu = MTU_UNLIMITED,
- ssize_t sendQueueCapacity = QUEUE_UNSUPPORTED)
- : isClosed(false)
- , m_sendQueueLength(0)
+ explicit
+ DummyTransportBase(const std::string& localUri = "dummy://",
+ const std::string& remoteUri = "dummy://",
+ ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT,
+ ssize_t mtu = MTU_UNLIMITED,
+ ssize_t sendQueueCapacity = QUEUE_UNSUPPORTED)
+ : NullTransport(FaceUri(localUri), FaceUri(remoteUri), scope, persistency)
{
- this->setLocalUri(FaceUri(localUri));
- this->setRemoteUri(FaceUri(remoteUri));
- this->setScope(scope);
- this->setPersistency(persistency);
this->setLinkType(linkType);
this->setMtu(mtu);
this->setSendQueueCapacity(sendQueueCapacity);
}
- void
- setMtu(ssize_t mtu)
- {
- this->Transport::setMtu(mtu);
- }
-
- void
- setState(FaceState state)
- {
- this->Transport::setState(state);
- }
+ using NullTransport::setMtu;
+ using NullTransport::setState;
ssize_t
getSendQueueLength() override
@@ -83,46 +75,41 @@
}
void
- receivePacket(Packet&& packet)
- {
- this->receive(std::move(packet));
- }
-
- void
receivePacket(Block block)
{
- this->receive(Packet(std::move(block)));
+ receive(Packet(std::move(block)));
}
protected:
bool
- canChangePersistencyToImpl(ndn::nfd::FacePersistency newPersistency) const override
+ canChangePersistencyToImpl(ndn::nfd::FacePersistency) const override
{
- return true;
+ return CAN_CHANGE_PERSISTENCY;
+ }
+
+ void
+ afterChangePersistency(ndn::nfd::FacePersistency old) override
+ {
+ persistencyHistory.push_back(old);
}
private:
void
- doClose() override
- {
- isClosed = true;
- this->setState(TransportState::CLOSED);
- }
-
- void
doSend(Packet&& packet) override
{
sentPackets.push_back(std::move(packet));
}
public:
- bool isClosed;
+ std::vector<ndn::nfd::FacePersistency> persistencyHistory;
std::vector<Packet> sentPackets;
private:
- ssize_t m_sendQueueLength;
+ ssize_t m_sendQueueLength = 0;
};
+using DummyTransport = DummyTransportBase<true>;
+
} // namespace tests
} // namespace face
} // namespace nfd