use DummyClientFace from ndn-cxx
Change-Id: I82bd668662a790d6e336bbcad9a6357606323658
diff --git a/src/validator.cpp b/src/validator.cpp
index 721b311..8bd4a4a 100644
--- a/src/validator.cpp
+++ b/src/validator.cpp
@@ -92,17 +92,14 @@
NDNS_LOG_TRACE("[* ?? *] verify data: " << data.getName() << ". KeyLocator: "
<< data.getSignature().getKeyLocator().getName());
ValidatorConfig::validate(data,
- [this, onValidated](const shared_ptr<const Data>& data)
- // onValidated here cannot use reference, since this is non-block
- {
- onValidated(data);
+ [this, onValidated] (const shared_ptr<const Data>& data) {
this->onDataValidated(data);
+ onValidated(data);
},
- [this, onValidationFailed](const shared_ptr<const Data>& data,
- const std::string& str)
- {
- onValidationFailed(data, str);
+ [this, onValidationFailed] (const shared_ptr<const Data>& data,
+ const std::string& str) {
this->onDataValidationFailed(data, str);
+ onValidationFailed(data, str);
}
);
}
diff --git a/tests/unit/dummy-client-face.hpp b/tests/unit/dummy-client-face.hpp
deleted file mode 100644
index 649e714..0000000
--- a/tests/unit/dummy-client-face.hpp
+++ /dev/null
@@ -1,236 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014, Regents of the University of California.
- *
- * This file is part of NDNS (Named Data Networking Domain Name Service).
- * See AUTHORS.md for complete list of NDNS authors and contributors.
- *
- * NDNS is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * Copyright (c) 2013-2014 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#ifndef NDNS_TESTS_UNIT_DUMMY_CLIENT_FACE_HPP
-#define NDNS_TESTS_UNIT_DUMMY_CLIENT_FACE_HPP
-
-#include <ndn-cxx/face.hpp>
-#include <ndn-cxx/transport/transport.hpp>
-#include <ndn-cxx/management/nfd-controller.hpp>
-#include <ndn-cxx/management/nfd-control-response.hpp>
-#include <ndn-cxx/util/event-emitter.hpp>
-
-
-namespace ndn {
-namespace tests {
-
-class DummyClientTransport : public ndn::Transport
-{
-public:
- void
- receive(const Block& block)
- {
- if (static_cast<bool>(m_receiveCallback))
- m_receiveCallback(block);
- }
-
- virtual void
- close()
- {
- }
-
- virtual void
- pause()
- {
- }
-
- virtual void
- resume()
- {
- }
-
- virtual void
- send(const Block& wire)
- {
- if (wire.type() == tlv::Interest) {
- shared_ptr<Interest> interest = make_shared<Interest>(wire);
- (*m_onInterest)(*interest, this);
- }
- else if (wire.type() == tlv::Data) {
- shared_ptr<Data> data = make_shared<Data>(wire);
- (*m_onData)(*data, this);
- }
- }
-
- virtual void
- send(const Block& header, const Block& payload)
- {
- this->send(payload);
- }
-
- boost::asio::io_service&
- getIoService()
- {
- return *m_ioService;
- }
-
-private:
- friend class DummyClientFace;
- util::EventEmitter<Interest, DummyClientTransport*>* m_onInterest;
- util::EventEmitter<Data, DummyClientTransport*>* m_onData;
-};
-
-
-/** \brief Callback to connect
- */
-inline void
-replyNfdRibCommands(const Interest& interest, DummyClientTransport* transport)
-{
- static const Name localhostRegistration("/localhost/nfd/rib");
- if (localhostRegistration.isPrefixOf(interest.getName())) {
- shared_ptr<Data> okResponse = make_shared<Data>(interest.getName());
- nfd::ControlParameters params(interest.getName().get(-5).blockFromValue());
- params.setFaceId(1);
- params.setOrigin(0);
- if (interest.getName().get(3) == name::Component("register")) {
- params.setCost(0);
- }
- nfd::ControlResponse resp;
- resp.setCode(200);
- resp.setBody(params.wireEncode());
- okResponse->setContent(resp.wireEncode());
- KeyChain keyChain;
- keyChain.signWithSha256(*okResponse);
-
- transport->getIoService().post(bind(&DummyClientTransport::receive, transport,
- okResponse->wireEncode()));
- }
-}
-
-/** \brief a client-side face for unit testing
- */
-class DummyClientFace : public ndn::Face
-{
-public:
- explicit
- DummyClientFace(shared_ptr<DummyClientTransport> transport)
- : Face(transport)
- , m_transport(transport)
- {
- m_transport->m_onInterest = &onInterest;
- m_transport->m_onData = &onData;
-
- enablePacketLogging();
- }
-
- DummyClientFace(shared_ptr<DummyClientTransport> transport, boost::asio::io_service& ioService)
- : Face(transport, ioService)
- , m_transport(transport)
- {
- m_transport->m_onInterest = &onInterest;
- m_transport->m_onData = &onData;
-
- enablePacketLogging();
- }
-
- /** \brief cause the Face to receive a packet
- */
- template<typename Packet>
- void
- receive(const Packet& packet)
- {
- m_transport->receive(packet.wireEncode());
- }
-
- void
- enablePacketLogging()
- {
- // @todo Replace with C++11 lambdas
-
- onInterest += bind(static_cast<void(std::vector<Interest>::*)(const Interest&)>(
- &std::vector<Interest>::push_back),
- &m_sentInterests, _1);
-
- onData += bind(static_cast<void(std::vector<Data>::*)(const Data&)>(
- &std::vector<Data>::push_back),
- &m_sentDatas, _1);
- }
-
- void
- enableRegistrationReply()
- {
- onInterest += &replyNfdRibCommands;
- }
-
-public:
- /** \brief sent Interests
- * \note After .expressInterest, .processEvents must be called before
- * the Interest would show up here.
- */
- std::vector<Interest> m_sentInterests;
- /** \brief sent Datas
- * \note After .put, .processEvents must be called before
- * the Interest would show up here.
- */
- std::vector<Data> m_sentDatas;
-
-public:
- /** \brief Event to be called whenever an Interest is received
- * \note After .expressInterest, .processEvents must be called before
- * the Interest would show up here.
- */
- util::EventEmitter<Interest, DummyClientTransport*> onInterest;
-
- /** \brief Event to be called whenever a Data packet is received
- * \note After .put, .processEvents must be called before
- * the Interest would show up here.
- */
- util::EventEmitter<Data, DummyClientTransport*> onData;
-
-private:
- shared_ptr<DummyClientTransport> m_transport;
-};
-
-inline shared_ptr<DummyClientFace>
-makeDummyClientFace()
-{
- return make_shared<DummyClientFace>(make_shared<DummyClientTransport>());
-}
-
-inline shared_ptr<DummyClientFace>
-makeDummyClientFace(boost::asio::io_service& ioService)
-{
- return make_shared<DummyClientFace>(make_shared<DummyClientTransport>(), ref(ioService));
-}
-
-
-} // namespace tests
-} // namespace ndn
-
-#endif // NDNS_TESTS_UNIT_DUMMY_CLIENT_FACE_HPP
diff --git a/tests/unit/validator.cpp b/tests/unit/validator.cpp
index 26c25ac..2525113 100644
--- a/tests/unit/validator.cpp
+++ b/tests/unit/validator.cpp
@@ -18,9 +18,10 @@
*/
#include "validator.hpp"
-#include "dummy-client-face.hpp"
-#include <ndn-cxx/security/key-chain.hpp>
#include "../boost-test.hpp"
+#include <ndn-cxx/util/dummy-client-face.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
+#include <boost/asio.hpp>
namespace ndn {
namespace ndns {
@@ -38,7 +39,7 @@
, m_testId3("/test02/ndn/edu")
, m_randomId("/test03")
, m_version(name::Component::fromVersion(0))
- , m_face(::ndn::tests::makeDummyClientFace())
+ , m_face(ndn::util::makeDummyClientFace(ndn::util::DummyClientFace::Options { false, true }))
{
m_keyChain.deleteIdentity(m_testId1);
m_keyChain.deleteIdentity(m_testId2);
@@ -57,7 +58,7 @@
m_keyChain.addCertificate(*cert);
NDNS_LOG_TRACE("add cert: " << cert->getName() << " to KeyChain");
- m_face->onInterest += bind(&Fixture::respondInterest, this, _1, _2);
+ m_face->onInterest += bind(&Fixture::respondInterest, this, _1);
}
~Fixture()
@@ -118,7 +119,7 @@
void
- respondInterest(const Interest& interest, ndn::tests::DummyClientTransport* transport)
+ respondInterest(const Interest& interest)
{
Name certName = interest.getName();
if (certName.isPrefixOf(m_selfSignCert)) {
@@ -130,7 +131,7 @@
NDNS_LOG_TRACE("validator needs: " << certName);
BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName), true);
auto cert = m_keyChain.getCertificate(certName);
- transport->receive(cert->wireEncode());
+ m_face->receive<Data>(*cert);
}
public:
@@ -153,7 +154,7 @@
name::Component m_version;
- shared_ptr<ndn::tests::DummyClientFace> m_face;
+ shared_ptr<ndn::util::DummyClientFace> m_face;
};