X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=PPI%2FConnectors.test.cc;h=6b95fc2700035283aeeb73b5bfbc1f4f30dce578;hb=40fa3e3f1e0f639c68bd15bf469e35045f94abee;hp=80548f2d69caf85c81cee650208805dd9f651b29;hpb=f539f4271d470794a773a92bacd8ba086c9bc1cd;p=senf.git diff --git a/PPI/Connectors.test.cc b/PPI/Connectors.test.cc index 80548f2..6b95fc2 100644 --- a/PPI/Connectors.test.cc +++ b/PPI/Connectors.test.cc @@ -1,8 +1,8 @@ // $Id$ // -// Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -31,7 +31,7 @@ #include "DebugModules.hh" #include "Setup.hh" -#include +#include "../Utils/auto_unit_test.hh" #include #define prefix_ @@ -49,8 +49,8 @@ BOOST_AUTO_UNIT_TEST(connector) // It doesn't matter, which type of connectors we use here since they are all based on // Connector. - debug::ActivePacketSource source; - debug::PassivePacketSink target; + debug::ActiveSource source; + debug::PassiveSink target; ppi::connect(source.output,target.input); ppi::init(); @@ -63,13 +63,13 @@ BOOST_AUTO_UNIT_TEST(connector) BOOST_AUTO_UNIT_TEST(passiveConnector) { - debug::ActivePacketSource source; - debug::PassivePacketSink target; + debug::ActiveSource source; + debug::PassiveSink target; ppi::connect(source.output,target.input); ppi::init(); - // onRequest is implicitly tested within the PassivePacketSink implementation which is tested + // onRequest is implicitly tested within the PassiveSink implementation which is tested // in DebugModules.test.cc target.input.throttle(); @@ -92,8 +92,8 @@ namespace { BOOST_AUTO_UNIT_TEST(activeConnector) { - debug::ActivePacketSource source; - debug::PassivePacketSink target; + debug::ActiveSource source; + debug::PassiveSink target; ppi::connect(source.output,target.input); ppi::init(); @@ -124,16 +124,16 @@ BOOST_AUTO_UNIT_TEST(activeConnector) BOOST_AUTO_UNIT_TEST(inputConnector) { - debug::ActivePacketSource source; - debug::PassivePacketSink target; + debug::ActiveSource source; + debug::PassiveSink target; ppi::connect(source.output,target.input); ppi::init(); - // operator() is implicitly tested within the Active/PassivePacketSink implementation which is + // operator() is implicitly tested within the Active/PassiveSink implementation which is // tested in DebugModules.test.cc - // peek() is implicitly tested within the Active/PassivePacketSink implementation + // peek() is implicitly tested within the Active/PassiveSink implementation BOOST_CHECK_EQUAL ( & target.input.peer(), & source.output ); @@ -144,13 +144,13 @@ BOOST_AUTO_UNIT_TEST(inputConnector) BOOST_AUTO_UNIT_TEST(outputConnector) { - debug::ActivePacketSource source; - debug::PassivePacketSink target; + debug::ActiveSource source; + debug::PassiveSink target; ppi::connect(source.output,target.input); ppi::init(); - // operator() is implicitly tested within the Active/PassivePacketSource implementation which is + // operator() is implicitly tested within the Active/PassiveSource implementation which is // tested in DebugModules.test.cc BOOST_CHECK_EQUAL( & source.output.peer(), & target.input ); @@ -161,8 +161,10 @@ namespace { class PassiveInputTest : public ppi::module::Module { + SENF_PPI_MODULE(PassiveInputTest); + public: - ppi::connector::PassiveInput input; + ppi::connector::PassiveInput<> input; PassiveInputTest() : counter() { noroute(input); @@ -179,10 +181,10 @@ namespace { BOOST_AUTO_UNIT_TEST(passiveInput) { - debug::ActivePacketSource source; + debug::ActiveSource source; PassiveInputTest target; - ppi::connect(source.output,target.input); + ppi::connect(source,target); ppi::init(); BOOST_CHECK_EQUAL( & target.input.peer(), & source.output ); @@ -222,10 +224,10 @@ BOOST_AUTO_UNIT_TEST(passiveInput) BOOST_AUTO_UNIT_TEST(passiveOutput) { - debug::PassivePacketSource source; - debug::ActivePacketSink target; + debug::PassiveSource source; + debug::ActiveSink target; - ppi::connect(source.output,target.input); + ppi::connect(source,target); ppi::init(); senf::Packet p (senf::DataPacket::create()); @@ -243,10 +245,10 @@ BOOST_AUTO_UNIT_TEST(passiveOutput) BOOST_AUTO_UNIT_TEST(activeInput) { - debug::PassivePacketSource source; - debug::ActivePacketSink target; + debug::PassiveSource source; + debug::ActiveSink target; - ppi::connect(source.output,target.input); + ppi::connect(source,target); ppi::init(); BOOST_CHECK_EQUAL( & target.input.peer(), & source.output ); @@ -268,10 +270,10 @@ BOOST_AUTO_UNIT_TEST(activeInput) BOOST_AUTO_UNIT_TEST(activeOutput) { - debug::ActivePacketSource source; - debug::PassivePacketSink target; + debug::ActiveSource source; + debug::PassiveSink target; - ppi::connect(source.output,target.input); + ppi::connect(source,target); ppi::init(); BOOST_CHECK_EQUAL( & source.output.peer(), & target.input ); @@ -282,6 +284,142 @@ BOOST_AUTO_UNIT_TEST(activeOutput) // connect() is tested indirectly via ppi::connect } +namespace { + + template + class TypedPassiveInput + : public ppi::module::Module + { + SENF_PPI_MODULE(TypedPassiveInput); + + public: + ppi::connector::PassiveInput input; + + TypedPassiveInput() { + noroute(input); + input.onRequest(&TypedPassiveInput::request); + } + + void request() { + (void) input(); + (void) input.read(); + } + }; + + template + class TypedActiveInput + : public ppi::module::Module + { + SENF_PPI_MODULE(TypedActiveInput); + + public: + ppi::connector::ActiveInput input; + + TypedActiveInput() { + noroute(input); + } + }; + + template + class TypedPassiveOutput + : public ppi::module::Module + { + SENF_PPI_MODULE(TypedPassiveOutput); + + public: + ppi::connector::PassiveOutput output; + + TypedPassiveOutput() { + noroute(output); + output.onRequest(&TypedPassiveOutput::request); + } + + void request() { + senf::DataPacket pkg (senf::DataPacket::create()); + output(pkg); + output.write(pkg); + } + }; + + template + class TypedActiveOutput + : public ppi::module::Module + { + SENF_PPI_MODULE(TypedActiveOutput); + + public: + ppi::connector::ActiveOutput output; + + TypedActiveOutput() { + noroute(output); + } + }; + + struct MyPacketType : public senf::PacketTypeBase + {}; + + typedef senf::ConcretePacket MyPacket; + +} + +BOOST_AUTO_UNIT_TEST(typedInput) +{ + debug::ActiveSource source; + TypedPassiveInput<> target; + + ppi::connect(source,target); + ppi::init(); + + senf::Packet p (senf::DataPacket::create()); + source.submit(p); +} + +BOOST_AUTO_UNIT_TEST(tyepdOutput) +{ + TypedPassiveOutput<> source; + debug::ActiveSink target; + + ppi::connect(source,target); + ppi::init(); + + (void) target.request(); +} + +BOOST_AUTO_UNIT_TEST(connectorTest) +{ + { + TypedPassiveInput<> input; + TypedActiveOutput output; + BOOST_CHECK_THROW( ppi::connect(output, input), + ppi::connector::IncompatibleConnectorsException ); + } + { + TypedPassiveInput input; + TypedActiveOutput<> output; + BOOST_CHECK_THROW( ppi::connect(output, input), + ppi::connector::IncompatibleConnectorsException ); + } + { + TypedPassiveInput<> input; + TypedActiveOutput<> output; + BOOST_CHECK_NO_THROW( ppi::connect(output, input) ); + } + { + TypedPassiveInput<> input; + debug::ActiveSource output; + BOOST_CHECK_NO_THROW( ppi::connect(output, input) ); + } + { + debug::ActiveSink input; + TypedPassiveOutput<> output; + BOOST_CHECK_NO_THROW( ppi::connect(output, input) ); + } + { + debug::ActiveSink input; + debug::PassiveSource output; + BOOST_CHECK_NO_THROW( ppi::connect(output, input) ); + } +} ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_