From: g0dil Date: Fri, 17 Aug 2007 11:57:27 +0000 (+0000) Subject: PPI: Make connect auto-expand module arguments X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=9e64a6d6a4840325f74502ba959ebd56fbb8441c;p=senf.git PPI: Make connect auto-expand module arguments PPI: Add additional unit testing git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@395 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/Connectors.test.cc b/PPI/Connectors.test.cc index feb7266..3a4b621 100644 --- a/PPI/Connectors.test.cc +++ b/PPI/Connectors.test.cc @@ -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 ); diff --git a/PPI/DebugModules.test.cc b/PPI/DebugModules.test.cc index 0fc70cc..fdde4c0 100644 --- a/PPI/DebugModules.test.cc +++ b/PPI/DebugModules.test.cc @@ -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 }; diff --git a/PPI/IOEvent.hh b/PPI/IOEvent.hh index 4e143b2..a61dec5 100644 --- a/PPI/IOEvent.hh +++ b/PPI/IOEvent.hh @@ -42,6 +42,8 @@ namespace ppi { }; /** \brief + + \fixme Implement error/EOF handling */ class IOEvent : public EventImplementation diff --git a/PPI/IOEvent.test.cc b/PPI/IOEvent.test.cc new file mode 100644 index 0000000..cdd97b7 --- /dev/null +++ b/PPI/IOEvent.test.cc @@ -0,0 +1,55 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund +// +// 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 +#include + +#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: diff --git a/PPI/Module.test.cc b/PPI/Module.test.cc index c54ef51..bfb2201 100644 --- a/PPI/Module.test.cc +++ b/PPI/Module.test.cc @@ -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(); diff --git a/PPI/ModuleManager.test.cc b/PPI/ModuleManager.test.cc new file mode 100644 index 0000000..0693b0c --- /dev/null +++ b/PPI/ModuleManager.test.cc @@ -0,0 +1,55 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund +// +// 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 +#include + +#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: diff --git a/PPI/Queueing.test.cc b/PPI/Queueing.test.cc new file mode 100644 index 0000000..cd256b6 --- /dev/null +++ b/PPI/Queueing.test.cc @@ -0,0 +1,109 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund +// +// 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 +#include + +#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: diff --git a/PPI/Route.test.cc b/PPI/Route.test.cc index f31b8a9..be33ee6 100644 --- a/PPI/Route.test.cc +++ b/PPI/Route.test.cc @@ -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(); diff --git a/PPI/Setup.cci b/PPI/Setup.cci index 01c3168..f8f556b 100644 --- a/PPI/Setup.cci +++ b/PPI/Setup.cci @@ -23,6 +23,8 @@ /** \file \brief Setup inline non-template implementation */ +//#include "Setup.ih" + // Custom includes #include "Connectors.hh" #include "ModuleManager.hh" diff --git a/PPI/Setup.cti b/PPI/Setup.cti new file mode 100644 index 0000000..fa119e6 --- /dev/null +++ b/PPI/Setup.cti @@ -0,0 +1,72 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund +// +// 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 +prefix_ void +senf::ppi::connect(M & source, C & target, + typename boost::enable_if< boost::is_base_of >::type *, + typename boost::enable_if< boost::is_base_of >::type *) +{ + connect(source.output, target); +} + +template +prefix_ void +senf::ppi::connect(C & source, M & target, + typename boost::enable_if< boost::is_base_of >::type *, + typename boost::enable_if< boost::is_base_of >::type *) +{ + connect(source, target.input); +} + +template +prefix_ void +senf::ppi::connect(M1 & source, M2 & target, + typename boost::enable_if< boost::is_base_of >::type *, + typename boost::enable_if< boost::is_base_of >::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: diff --git a/PPI/Setup.hh b/PPI/Setup.hh index 2920e1e..12e7d90 100644 --- a/PPI/Setup.hh +++ b/PPI/Setup.hh @@ -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 + void connect(M & source, C & target, + typename boost::enable_if< boost::is_base_of >::type * = 0, + typename boost::enable_if< boost::is_base_of >::type * = 0); + + template + void connect(C & source, M & target, + typename boost::enable_if< boost::is_base_of >::type * = 0, + typename boost::enable_if< boost::is_base_of >::type * = 0); + template + void connect(M1 & source, M2 & target, + typename boost::enable_if< boost::is_base_of >::type * = 0, + typename boost::enable_if< boost::is_base_of >::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 diff --git a/PPI/SocketReader.test.cc b/PPI/SocketReader.test.cc index 1d58e1c..8a28946 100644 --- a/PPI/SocketReader.test.cc +++ b/PPI/SocketReader.test.cc @@ -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() ); diff --git a/PPI/SocketWriter.test.cc b/PPI/SocketWriter.test.cc index 78814ca..25c1a5d 100644 --- a/PPI/SocketWriter.test.cc +++ b/PPI/SocketWriter.test.cc @@ -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));