X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=PPI%2FConnectors.test.cc;h=20b7e3e405b21d715d3b8197b35e06fc44c188f9;hb=a1fdb7bb122f0b05be809a922d4b7ef5e125fa67;hp=16c76eab550956d1835a2302fb7dee1cdabfe66f;hpb=69255c0f1669fc80b0e4a2bf524715f336b127ad;p=senf.git diff --git a/PPI/Connectors.test.cc b/PPI/Connectors.test.cc index 16c76ea..20b7e3e 100644 --- a/PPI/Connectors.test.cc +++ b/PPI/Connectors.test.cc @@ -1,8 +1,8 @@ // $Id$ // -// Copyright (C) 2007 -// Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY +// 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 @@ -21,7 +21,7 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief Connectors.test unit tests */ + \brief Connectors unit tests */ //#include "Connectors.test.hh" //#include "Connectors.test.ih" @@ -284,6 +284,259 @@ 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; + SENF_CHECK_NO_THROW( ppi::connect(output, input) ); + } + { + TypedPassiveInput<> input; + debug::ActiveSource output; + SENF_CHECK_NO_THROW( ppi::connect(output, input) ); + } + { + debug::ActiveSink input; + TypedPassiveOutput<> output; + SENF_CHECK_NO_THROW( ppi::connect(output, input) ); + } + { + debug::ActiveSink input; + debug::PassiveSource output; + SENF_CHECK_NO_THROW( ppi::connect(output, input) ); + } +} + +BOOST_AUTO_UNIT_TEST(delayedConnect) +{ + { + debug::PassiveSource source; + debug::ActiveSink target; + + ppi::init(); + + BOOST_CHECK( ! target.input ); + BOOST_CHECK( ! target.request() ); + + ppi::connect(source, target); + ppi::init(); + + BOOST_CHECK( ! target.input ); + + senf::Packet p (senf::DataPacket::create()); + source.submit(p); + BOOST_CHECK( target.request() == p ); + } + + { + debug::PassiveSource source; + debug::ActiveSink target; + + ppi::init(); + + senf::Packet p (senf::DataPacket::create()); + source.submit(p); + + BOOST_CHECK( ! target.input ); + BOOST_CHECK( ! target.request() ); + + ppi::connect(source, target); + ppi::init(); + + BOOST_CHECK( target.input ); + BOOST_CHECK( target.request() == p ); + } + + { + debug::ActiveSource source; + debug::PassiveSink target; + + ppi::init(); + + BOOST_CHECK( ! source.output ); + SENF_CHECK_NO_THROW( source.output(senf::DataPacket::create()) ); + + ppi::connect(source, target); + ppi::init(); + + BOOST_CHECK( source.output ); + + senf::Packet p (senf::DataPacket::create()); + source.submit(p); + + BOOST_CHECK( target.front() == p ); + BOOST_CHECK_EQUAL( target.size(), 1u ); + } + + { + debug::ActiveSource source; + debug::PassiveSink target; + + ppi::init(); + + BOOST_CHECK( ! source.output ); + SENF_CHECK_NO_THROW( source.output(senf::DataPacket::create()) ); + target.throttle(); + + ppi::connect(source, target); + ppi::init(); + + BOOST_CHECK( ! source.output ); + target.unthrottle(); + BOOST_CHECK( source.output ); + } +} + +BOOST_AUTO_UNIT_TEST(disconnect) +{ + { + debug::PassiveSource source; + debug::ActiveSink target; + + ppi::connect(source, target); + ppi::init(); + + BOOST_CHECK( ! target.input ); + + senf::Packet p (senf::DataPacket::create()); + source.submit(p); + + BOOST_CHECK( target.input ); + + target.input.disconnect(); + ppi::init(); + + BOOST_CHECK( ! target.input ); + } + { + debug::ActiveSource source; + debug::PassiveSink target; + + ppi::connect(source, target); + ppi::init(); + + BOOST_CHECK( source.output ); + + source.output.disconnect(); + ppi::init(); + + BOOST_CHECK( ! source.output ); + } +} ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_