PPI: Add missing TargetDgramWriter doku
[senf.git] / PPI / Connectors.test.cc
index 639f58b..20b7e3e 100644 (file)
@@ -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"
@@ -286,17 +286,18 @@ BOOST_AUTO_UNIT_TEST(activeOutput)
 
 namespace {
 
-    class TypedInputTest
+    template <class PacketType = senf::DataPacket>
+    class TypedPassiveInput
         : public ppi::module::Module
     {
-        SENF_PPI_MODULE(TypedInputTest);
+        SENF_PPI_MODULE(TypedPassiveInput);
 
     public:
-        ppi::connector::PassiveInput<senf::DataPacket> input;
+        ppi::connector::PassiveInput<PacketType> input;
 
-        TypedInputTest() {
+        TypedPassiveInput() {
             noroute(input);
-            input.onRequest(&TypedInputTest::request);
+            input.onRequest(&TypedPassiveInput::request);
         }
 
         void request() {
@@ -305,17 +306,32 @@ namespace {
         }
     };
 
-    class TypedOutputTest
+    template <class PacketType = senf::DataPacket>
+    class TypedActiveInput
         : public ppi::module::Module
     {
-        SENF_PPI_MODULE(TypedOutputTest);
+        SENF_PPI_MODULE(TypedActiveInput);
 
     public:
-        ppi::connector::PassiveOutput<senf::DataPacket> output;
+        ppi::connector::ActiveInput<PacketType> input;
 
-        TypedOutputTest() {
+        TypedActiveInput() {
+            noroute(input);
+        }
+    };
+
+    template <class PacketType = senf::DataPacket>
+    class TypedPassiveOutput
+        : public ppi::module::Module
+    {
+        SENF_PPI_MODULE(TypedPassiveOutput);
+
+    public:
+        ppi::connector::PassiveOutput<PacketType> output;
+
+        TypedPassiveOutput() {
             noroute(output);
-            output.onRequest(&TypedOutputTest::request);
+            output.onRequest(&TypedPassiveOutput::request);
         }
 
         void request() {
@@ -325,12 +341,31 @@ namespace {
         }
     };
 
+    template <class PacketType = senf::DataPacket>
+    class TypedActiveOutput
+        : public ppi::module::Module
+    {
+        SENF_PPI_MODULE(TypedActiveOutput);
+
+    public:
+        ppi::connector::ActiveOutput<PacketType> output;
+
+        TypedActiveOutput() {
+            noroute(output);
+        }
+    };
+
+    struct MyPacketType : public senf::PacketTypeBase
+    {};
+
+    typedef senf::ConcretePacket<MyPacketType> MyPacket;
+
 }
 
 BOOST_AUTO_UNIT_TEST(typedInput)
 {
     debug::ActiveSource source;
-    TypedInputTest target;
+    TypedPassiveInput<> target;
 
     ppi::connect(source,target);
     ppi::init();
@@ -341,7 +376,7 @@ BOOST_AUTO_UNIT_TEST(typedInput)
 
 BOOST_AUTO_UNIT_TEST(tyepdOutput)
 {
-    TypedOutputTest source;
+    TypedPassiveOutput<> source;
     debug::ActiveSink target;
 
     ppi::connect(source,target);
@@ -350,6 +385,159 @@ BOOST_AUTO_UNIT_TEST(tyepdOutput)
     (void) target.request();
 }
 
+BOOST_AUTO_UNIT_TEST(connectorTest)
+{
+    {
+        TypedPassiveInput<> input;
+        TypedActiveOutput<MyPacket> output;
+        BOOST_CHECK_THROW( ppi::connect(output, input), 
+                           ppi::connector::IncompatibleConnectorsException );
+    }
+    {
+        TypedPassiveInput<MyPacket> 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_