X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=PPI%2FConnectors.test.cc;h=6b95fc2700035283aeeb73b5bfbc1f4f30dce578;hb=d8c2d9d478b8808e5b76e4688aea4f840b6a1df7;hp=53ef5643baaa6e05c03c8cae2be46fd734af783c;hpb=f73fa16ed5abdce272ac77f8b8b9ef2b9922c266;p=senf.git diff --git a/PPI/Connectors.test.cc b/PPI/Connectors.test.cc index 53ef564..6b95fc2 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 @@ -164,7 +164,7 @@ namespace { SENF_PPI_MODULE(PassiveInputTest); public: - ppi::connector::PassiveInput input; + ppi::connector::PassiveInput<> input; PassiveInputTest() : counter() { noroute(input); @@ -284,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_