Skip to content
Snippets Groups Projects
Commit e7ba33b0 authored by g0dil's avatar g0dil
Browse files

PPI: Make connect auto-expand module arguments

PPI: Add additional unit testing
parent 4023263d
No related branches found
No related tags found
No related merge requests found
......@@ -184,7 +184,7 @@ BOOST_AUTO_UNIT_TEST(passiveInput)
debug::ActivePacketSource source;
PassiveInputTest target;
ppi::connect(source.output,target.input);
ppi::connect(source,target);
ppi::init();
BOOST_CHECK_EQUAL( & target.input.peer(), & source.output );
......@@ -227,7 +227,7 @@ BOOST_AUTO_UNIT_TEST(passiveOutput)
debug::PassivePacketSource source;
debug::ActivePacketSink target;
ppi::connect(source.output,target.input);
ppi::connect(source,target);
ppi::init();
senf::Packet p (senf::DataPacket::create());
......@@ -248,7 +248,7 @@ BOOST_AUTO_UNIT_TEST(activeInput)
debug::PassivePacketSource source;
debug::ActivePacketSink target;
ppi::connect(source.output,target.input);
ppi::connect(source,target);
ppi::init();
BOOST_CHECK_EQUAL( & target.input.peer(), & source.output );
......@@ -273,7 +273,7 @@ BOOST_AUTO_UNIT_TEST(activeOutput)
debug::ActivePacketSource source;
debug::PassivePacketSink target;
ppi::connect(source.output,target.input);
ppi::connect(source,target);
ppi::init();
BOOST_CHECK_EQUAL( & source.output.peer(), & target.input );
......
......@@ -47,7 +47,7 @@ BOOST_AUTO_UNIT_TEST(debugModules)
debug::ActivePacketSource source;
debug::PassivePacketSink sink;
ppi::connect(source.output, sink.input);
ppi::connect(source, sink);
ppi::init();
senf::PacketData::byte data[] = { 0x13u, 0x24u, 0x35u };
......@@ -76,7 +76,7 @@ BOOST_AUTO_UNIT_TEST(debugModules)
debug::PassivePacketSource source;
debug::ActivePacketSink sink;
ppi::connect(source.output, sink.input);
ppi::connect(source, sink);
ppi::init();
senf::PacketData::byte data[] = { 0x13u, 0x24u, 0x35u };
......
......@@ -42,6 +42,8 @@ namespace ppi {
};
/** \brief
\fixme Implement error/EOF handling
*/
class IOEvent
: public EventImplementation<IOEventInfo>
......
// $Id$
//
// Copyright (C) 2007
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
// Stefan Bund <g0dil@berlios.de>
//
// This program 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 2 of the License, or
// (at your option) any later version.
//
// This program 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 this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/** \file
\brief IOEvent.test unit tests */
//#include "IOEvent.test.hh"
//#include "IOEvent.test.ih"
// Custom includes
#include "IOEvent.hh"
#include <boost/test/auto_unit_test.hpp>
#include <boost/test/test_tools.hpp>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
BOOST_AUTO_UNIT_TEST(ioEvent)
{
// Tested in SocketReader.test.cc and SocketWriter.test.cc
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
// Local Variables:
// mode: c++
// fill-column: 100
// comment-column: 40
// c-file-style: "senf"
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
// compile-command: "scons -u test"
// End:
......@@ -70,7 +70,7 @@ BOOST_AUTO_UNIT_TEST(module)
TestModule tester;
debug::PassivePacketSink sink;
ppi::connect(tester.output, sink.input);
ppi::connect(tester, sink);
ppi::init();
tester.event.trigger();
......
// $Id$
//
// Copyright (C) 2007
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
// Stefan Bund <g0dil@berlios.de>
//
// This program 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 2 of the License, or
// (at your option) any later version.
//
// This program 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 this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/** \file
\brief ModuleManager.test unit tests */
//#include "ModuleManager.test.hh"
//#include "ModuleManager.test.ih"
// Custom includes
#include "ModuleManager.hh"
#include <boost/test/auto_unit_test.hpp>
#include <boost/test/test_tools.hpp>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
BOOST_AUTO_UNIT_TEST(moduleManager)
{
// Tested in Module.test.cc
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
// Local Variables:
// mode: c++
// fill-column: 100
// comment-column: 40
// c-file-style: "senf"
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
// compile-command: "scons -u test"
// End:
// $Id$
//
// Copyright (C) 2007
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
// Stefan Bund <g0dil@berlios.de>
//
// This program 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 2 of the License, or
// (at your option) any later version.
//
// This program 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 this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/** \file
\brief Queueing.test unit tests */
//#include "Queueing.test.hh"
//#include "Queueing.test.ih"
// Custom includes
#include "Queueing.hh"
#include "Module.hh"
#include "Connectors.hh"
#include "DebugModules.hh"
#include "Packets/Packets.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 {
class QueueTester : public module::Module
{
SENF_PPI_MODULE(QueueTester);
public:
connector::PassiveInput input;
connector::ActiveOutput output;
QueueTester() {
route(input, output);
input.qdisc(ppi::ThresholdQueueing(2,1));
input.onRequest(&QueueTester::nop);
}
void nop() {}
void forward() {
if (input && output)
output(input());
}
};
}
BOOST_AUTO_UNIT_TEST(thresholdQueueing)
{
debug::ActivePacketSource source;
QueueTester tester;
debug::PassivePacketSink sink;
ppi::connect(source, tester);
ppi::connect(tester, sink);
ppi::init();
senf::Packet p (senf::DataPacket::create());
BOOST_CHECK( source );
source.submit(p);
BOOST_CHECK( source );
source.submit(p);
BOOST_CHECK( ! source );
BOOST_CHECK_EQUAL( tester.input.queueSize(), 2u );
tester.forward();
BOOST_CHECK_EQUAL( tester.input.queueSize(), 1u );
BOOST_CHECK( source );
tester.forward();
BOOST_CHECK_EQUAL( tester.input.queueSize(), 0u );
BOOST_CHECK( source );
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
// Local Variables:
// mode: c++
// fill-column: 100
// comment-column: 40
// c-file-style: "senf"
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
// compile-command: "scons -u test"
// End:
......@@ -111,10 +111,10 @@ BOOST_AUTO_UNIT_TEST(route)
debug::ActivePacketSink activeSink;
RouteTester tester;
ppi::connect(passiveSource.output, tester.activeIn);
ppi::connect(activeSource.output, tester.passiveIn);
ppi::connect(tester.activeOut, passiveSink.input);
ppi::connect(tester.passiveOut, activeSink.input);
ppi::connect(passiveSource, tester.activeIn);
ppi::connect(activeSource, tester.passiveIn);
ppi::connect(tester.activeOut, passiveSink);
ppi::connect(tester.passiveOut, activeSink);
ppi::init();
......
......@@ -23,6 +23,8 @@
/** \file
\brief Setup inline non-template implementation */
//#include "Setup.ih"
// Custom includes
#include "Connectors.hh"
#include "ModuleManager.hh"
......
// $Id$
//
// Copyright (C) 2007
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
// Stefan Bund <g0dil@berlios.de>
//
// This program 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 2 of the License, or
// (at your option) any later version.
//
// This program 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 this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/** \file
\brief Setup inline template implementation */
//#include "Setup.ih"
// Custom includes
#define prefix_ inline
///////////////////////////////cti.p///////////////////////////////////////
template <class M, class C>
prefix_ void
senf::ppi::connect(M & source, C & target,
typename boost::enable_if< boost::is_base_of<module::Module, M> >::type *,
typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type *)
{
connect(source.output, target);
}
template <class C, class M>
prefix_ void
senf::ppi::connect(C & source, M & target,
typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type *,
typename boost::enable_if< boost::is_base_of<module::Module, M> >::type *)
{
connect(source, target.input);
}
template <class M1, class M2>
prefix_ void
senf::ppi::connect(M1 & source, M2 & target,
typename boost::enable_if< boost::is_base_of<module::Module, M1> >::type *,
typename boost::enable_if< boost::is_base_of<module::Module, M2> >::type *)
{
connect(source.output, target.input);
}
///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_
// Local Variables:
// mode: c++
// fill-column: 100
// comment-column: 40
// c-file-style: "senf"
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
// compile-command: "scons -u test"
// End:
......@@ -34,10 +34,25 @@
namespace senf {
namespace ppi {
void connect(connector::ActiveOutput & source, connector::PassiveInput & target);
void connect(connector::PassiveOutput & source, connector::ActiveInput & target);
template <class M, class C>
void connect(M & source, C & target,
typename boost::enable_if< boost::is_base_of<module::Module, M> >::type * = 0,
typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type * = 0);
template <class C, class M>
void connect(C & source, M & target,
typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type * = 0,
typename boost::enable_if< boost::is_base_of<module::Module, M> >::type * = 0);
template <class M1, class M2>
void connect(M1 & source, M2 & target,
typename boost::enable_if< boost::is_base_of<module::Module, M1> >::type * = 0,
typename boost::enable_if< boost::is_base_of<module::Module, M2> >::type * = 0);
void run();
void init();
......@@ -46,7 +61,7 @@ namespace ppi {
///////////////////////////////hh.e////////////////////////////////////////
#include "Setup.cci"
//#include "Setup.ct"
//#include "Setup.cti"
#include "Setup.cti"
#endif
......
......@@ -58,13 +58,13 @@ BOOST_AUTO_UNIT_TEST(socketReader)
inputSocket.blocking(false);
module::ActiveSocketReader<> udpReader(inputSocket);
debug::PassivePacketSink sink;
ppi::connect(udpReader.output, sink.input);
ppi::connect(udpReader, sink);
std::string data ("TEST");
senf::UDPv4ClientSocketHandle outputSocket;
outputSocket.writeto(senf::INet4SocketAddress("localhost:44344"),data);
senf::Scheduler::instance().timeout(1000, &timeout);
senf::Scheduler::instance().timeout(100, &timeout);
senf::ppi::run();
BOOST_REQUIRE( ! sink.empty() );
......
......@@ -57,7 +57,7 @@ BOOST_AUTO_UNIT_TEST(passiveSocketWriter)
senf::INet4SocketAddress("localhost:44344"));
module::PassiveSocketWriter<> udpWriter(outputSocket);
debug::ActivePacketSource source;
ppi::connect(source.output, udpWriter.input);
ppi::connect(source, udpWriter);
std::string data ("TEST");
senf::Packet p (senf::DataPacket::create(data));
......@@ -77,7 +77,7 @@ BOOST_AUTO_UNIT_TEST(activeSocketWriter)
senf::INet4SocketAddress("localhost:44344"));
module::ActiveSocketWriter<> udpWriter(outputSocket);
debug::PassivePacketSource source;
ppi::connect(source.output, udpWriter.input);
ppi::connect(source, udpWriter);
std::string data ("TEST");
senf::Packet p (senf::DataPacket::create(data));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment