diff --git a/PPI/Connectors.test.cc b/PPI/Connectors.test.cc index feb7266ff6b77db613655024eef39c264b726255..3a4b621bd645fdb80efe68d1d60377251790110f 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 0fc70ccd8845b95b3132d12c08f46a90469c6e48..fdde4c0922942fcf424996eac4dcba58ce4c5753 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 4e143b2387252d40d41090771a2fa1439cba8b6b..a61dec521e002f39e12d160f07f1e13375d16e4d 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<IOEventInfo> diff --git a/PPI/IOEvent.test.cc b/PPI/IOEvent.test.cc new file mode 100644 index 0000000000000000000000000000000000000000..cdd97b7f1fb100649973b059f696ca14c57734bd --- /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 <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: diff --git a/PPI/Module.test.cc b/PPI/Module.test.cc index c54ef51f0447e9843293863d7c94e8bc635de6e4..bfb2201a8c8964e8efc81e770f13b28719d997e8 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 0000000000000000000000000000000000000000..0693b0cabef27d558229be460d60b0e3e8546df9 --- /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 <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: diff --git a/PPI/Queueing.test.cc b/PPI/Queueing.test.cc new file mode 100644 index 0000000000000000000000000000000000000000..cd256b6ef22392d5171ccf8c7bffa1a2656e1e5a --- /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 <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: diff --git a/PPI/Route.test.cc b/PPI/Route.test.cc index f31b8a9d7cfb548db2618c81f220d3ba3d5e3047..be33ee6e6c2ec8375ee56392e6cb1a3bf4e7faaa 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 01c31681abcdb8f8285550a631cddc884e2dc2c8..f8f556b1e28c32aa9c33ee1ca8132c868ec665d3 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 0000000000000000000000000000000000000000..fa119e68a43ab0ee7fa3e3135f5aa7e6155959f0 --- /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 <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: diff --git a/PPI/Setup.hh b/PPI/Setup.hh index 2920e1eb76647fc94d7e7e7c1930b6051afe6361..12e7d905fc98c534df3cec4762003e718869067e 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 <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 diff --git a/PPI/SocketReader.test.cc b/PPI/SocketReader.test.cc index 1d58e1c77e30046866f052830b73d0fca7e55873..8a28946b21eab6c2be9fc470e70fa887e90b6ea5 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 78814ca812ab363fad96de12ae9582e657568422..25c1a5dd0957ed4713c5a743d37876e9cc6bd982 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));