prefix_ void senf::ppi::module::debug::PassivePacketSource::init()
{
- output.throttle();
+ if (empty())
+ output.throttle();
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////cc.p////////////////////////////////////////
BOOST_AUTO_UNIT_TEST(eventManager)
-{}
+{
+ // Tested indirectly by Route.test.cc and Module.test.cc
+}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
///////////////////////////////cc.p////////////////////////////////////////
BOOST_AUTO_UNIT_TEST(events)
-{}
+{
+ // Tested in Route.test.cc
+}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "Module.test.ih"
// Custom includes
+#include "DebugEvent.hh"
+#include "DebugModules.hh"
+#include "Setup.hh"
#include "Module.hh"
#include <boost/test/auto_unit_test.hpp>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
+namespace ppi = senf::ppi;
+namespace connector = ppi::connector;
+namespace debug = ppi::module::debug;
+
+namespace {
+ class TestModule : public ppi::module::Module
+ {
+ public:
+ connector::ActiveOutput output;
+
+ ppi::DebugEvent event;
+
+ TestModule() {
+ noroute(output);
+ registerEvent(&TestModule::onEvent, event);
+ }
+
+ void onEvent() {
+ output(senf::DataPacket::create());
+ }
+
+ using ppi::module::Module::eventTime;
+ };
+}
+
BOOST_AUTO_UNIT_TEST(module)
-{}
+{
+ // route and registerEvent are tested in Route.test.cc
+
+ TestModule tester;
+ debug::PassivePacketSink sink;
+ ppi::connect(tester.output, sink.input);
+ ppi::init();
+
+ tester.event.trigger();
+ BOOST_CHECK_EQUAL( sink.size(), 1u );
+ BOOST_CHECK_EQUAL( (boost::posix_time::microsec_clock::universal_time() -
+ tester.eventTime()).total_seconds(), 0 );
+}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "SocketReader.test.ih"
// Custom includes
+#include <algorithm>
+#include "Socket/Protocols/INet/UDPSocketHandle.hh"
+#include "Scheduler/Scheduler.hh"
#include "SocketReader.hh"
+#include "DebugModules.hh"
+#include "Setup.hh"
#include <boost/test/auto_unit_test.hpp>
#include <boost/test/test_tools.hpp>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
+namespace ppi = senf::ppi;
+namespace connector = ppi::connector;
+namespace module = ppi::module;
+namespace debug = module::debug;
+
+namespace {
+ void timeout() {
+ senf::Scheduler::instance().terminate();
+ }
+}
+
BOOST_AUTO_UNIT_TEST(socketReader)
-{}
+{
+ senf::UDPv4ClientSocketHandle inputSocket;
+ inputSocket.bind(senf::INet4SocketAddress("localhost:44344"));
+ inputSocket.blocking(false);
+ module::ActiveSocketReader<> udpReader(inputSocket);
+ debug::PassivePacketSink sink;
+ ppi::connect(udpReader.output, sink.input);
+
+ std::string data ("TEST");
+
+ senf::UDPv4ClientSocketHandle outputSocket;
+ outputSocket.writeto(senf::INet4SocketAddress("localhost:44344"),data);
+ senf::Scheduler::instance().timeout(1000, &timeout);
+ senf::ppi::run();
+
+ BOOST_REQUIRE( ! sink.empty() );
+ BOOST_CHECK_EQUAL( sink.front().data().size(), data.size() );
+ BOOST_CHECK( std::equal( sink.front().data().begin(), sink.front().data().end(),
+ data.begin()) );
+}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
///////////////////////////////ct.p////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
+// senf::ppi::module::ActiveSocketWriter<Writer>
+
+template <class Writer>
+prefix_ senf::ppi::module::ActiveSocketWriter<Writer>::ActiveSocketWriter(Handle handle)
+ : handle_(handle), event_(handle_, IOEvent::Write), writer_()
+{
+ registerEvent( &ActiveSocketWriter::write, event_ );
+ route(input, event_);
+}
+
+////////////////////////////////////////
+// private members
+
+template <class Writer>
+prefix_ void senf::ppi::module::ActiveSocketWriter<Writer>::write()
+{
+ writer_(handle_,input());
+}
+
+///////////////////////////////////////////////////////////////////////////
// senf::ppi::module::PassiveSocketWriter<Writer>
template <class Writer>
ActiveSocketWriter(Handle handle); ///< Create new writer for the given handle
/**< Data will be written to \a handle using \a Writer.
\param[in] handle Handle to write data to */
+ private:
+ void write();
+
+ Handle handle_;
+ IOEvent event_;
+ Writer writer_;
};
/** \brief Output module writing data to arbitrary FileHandle
//#include "SocketWriter.test.ih"
// Custom includes
+#include "Socket/Protocols/INet/UDPSocketHandle.hh"
+#include "Socket/Protocols/INet/ConnectedUDPSocketHandle.hh"
+#include "SocketReader.hh"
+#include "DebugModules.hh"
#include "SocketWriter.hh"
+#include "Setup.hh"
#include <boost/test/auto_unit_test.hpp>
#include <boost/test/test_tools.hpp>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-BOOST_AUTO_UNIT_TEST(socketWriter)
-{}
+namespace ppi = senf::ppi;
+namespace connector = ppi::connector;
+namespace module = ppi::module;
+namespace debug = module::debug;
+
+namespace {
+ void timeout() {
+ senf::Scheduler::instance().terminate();
+ }
+}
+
+BOOST_AUTO_UNIT_TEST(passiveSocketWriter)
+{
+ senf::ConnectedUDPv4ClientSocketHandle outputSocket (
+ senf::INet4SocketAddress("localhost:44344"));
+ module::PassiveSocketWriter<> udpWriter(outputSocket);
+ debug::ActivePacketSource source;
+ ppi::connect(source.output, udpWriter.input);
+
+ std::string data ("TEST");
+ senf::Packet p (senf::DataPacket::create(data));
+
+ senf::UDPv4ClientSocketHandle inputSocket;
+ inputSocket.bind(senf::INet4SocketAddress("localhost:44344"));
+ inputSocket.blocking(false);
+ senf::ppi::init();
+ source.submit(p);
+
+ std::string input (inputSocket.read());
+ BOOST_CHECK_EQUAL( data, input );
+}
+
+BOOST_AUTO_UNIT_TEST(activeSocketWriter)
+{
+ senf::ConnectedUDPv4ClientSocketHandle outputSocket (
+ senf::INet4SocketAddress("localhost:44344"));
+ module::ActiveSocketWriter<> udpWriter(outputSocket);
+ debug::PassivePacketSource source;
+ ppi::connect(source.output, udpWriter.input);
+
+ std::string data ("TEST");
+ senf::Packet p (senf::DataPacket::create(data));
+
+ senf::UDPv4ClientSocketHandle inputSocket;
+ inputSocket.bind(senf::INet4SocketAddress("localhost:44344"));
+ inputSocket.blocking(false);
+ senf::Scheduler::instance().timeout(1000, &timeout);
+ source.submit(p);
+ senf::ppi::run();
+
+ std::string input (inputSocket.read());
+ BOOST_CHECK_EQUAL( data, input );
+}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_