PPI: optimized internal connector packet handling (queuing only if necessary, pass...
[senf.git] / senf / PPI / Connectors.test.cc
index 20b7e3e..eae2acd 100644 (file)
@@ -2,23 +2,28 @@
 //
 // Copyright (C) 2007
 // Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
-//     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.
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at 
+// http://senf.berlios.de/license.html
 //
-// 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.
+// The Fraunhofer FOKUS Public License Version 1.0 is based on, 
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
 //
-// 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.
+// Software distributed under the License is distributed on an "AS IS" basis, 
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+//   Stefan Bund <g0dil@berlios.de>
 
 /** \file
     \brief Connectors unit tests */
 #include "DebugModules.hh"
 #include "Setup.hh"
 
-#include "../Utils/auto_unit_test.hh"
+#include <senf/Utils/auto_unit_test.hh>
 #include <boost/test/test_tools.hpp>
 
 #define prefix_
-///////////////////////////////cc.p////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 
 namespace ppi = senf::ppi;
 namespace debug = ppi::module::debug;
@@ -44,7 +49,7 @@ namespace debug = ppi::module::debug;
 // the corresponding connected module since otherwise the connectors cannot be connected anywhere
 // and will be unusable.
 
-BOOST_AUTO_UNIT_TEST(connector)
+SENF_AUTO_UNIT_TEST(connector)
 {
     // It doesn't matter, which type of connectors we use here since they are all based on
     // Connector.
@@ -61,7 +66,7 @@ BOOST_AUTO_UNIT_TEST(connector)
     BOOST_CHECK_EQUAL( & target.input.peer(), & source.output );
 }
 
-BOOST_AUTO_UNIT_TEST(passiveConnector)
+SENF_AUTO_UNIT_TEST(passiveConnector)
 {
     debug::ActiveSource source;
     debug::PassiveSink target;
@@ -75,7 +80,7 @@ BOOST_AUTO_UNIT_TEST(passiveConnector)
     target.input.throttle();
     BOOST_CHECK( target.input.throttled() );
     BOOST_CHECK( target.input.nativeThrottled() );
-    
+
     target.input.unthrottle();
     BOOST_CHECK( ! target.input.throttled() );
     BOOST_CHECK( ! target.input.nativeThrottled() );
@@ -84,13 +89,13 @@ BOOST_AUTO_UNIT_TEST(passiveConnector)
 }
 
 namespace {
-    
+
     bool called = false;
-    
+
     void handler() { called = true; }
 }
 
-BOOST_AUTO_UNIT_TEST(activeConnector)
+SENF_AUTO_UNIT_TEST(activeConnector)
 {
     debug::ActiveSource source;
     debug::PassiveSink target;
@@ -122,7 +127,7 @@ BOOST_AUTO_UNIT_TEST(activeConnector)
     BOOST_CHECK_EQUAL( & source.output.peer(), & target.input );
 }
 
-BOOST_AUTO_UNIT_TEST(inputConnector)
+SENF_AUTO_UNIT_TEST(inputConnector)
 {
     debug::ActiveSource source;
     debug::PassiveSink target;
@@ -136,13 +141,12 @@ BOOST_AUTO_UNIT_TEST(inputConnector)
     // peek() is implicitly tested within the Active/PassiveSink implementation
 
     BOOST_CHECK_EQUAL ( & target.input.peer(), & source.output );
-    
-    BOOST_CHECK( target.input.begin() == target.input.end() );
+
     BOOST_CHECK_EQUAL( target.input.queueSize(), 0u );
     BOOST_CHECK( target.input.empty() );
 }
 
-BOOST_AUTO_UNIT_TEST(outputConnector)
+SENF_AUTO_UNIT_TEST(outputConnector)
 {
     debug::ActiveSource source;
     debug::PassiveSink target;
@@ -179,7 +183,7 @@ namespace {
     };
 }
 
-BOOST_AUTO_UNIT_TEST(passiveInput)
+SENF_AUTO_UNIT_TEST(passiveInput)
 {
     debug::ActiveSource source;
     PassiveInputTest target;
@@ -188,23 +192,23 @@ BOOST_AUTO_UNIT_TEST(passiveInput)
     ppi::init();
 
     BOOST_CHECK_EQUAL( & target.input.peer(), & source.output );
-    
+
     target.input.throttle();
     senf::Packet p (senf::DataPacket::create());
     source.submit(p);
-    
+
     BOOST_CHECK_EQUAL( target.counter, 0u );
     BOOST_CHECK( target.input );
     BOOST_CHECK_EQUAL( target.input.queueSize(), 1u );
     target.input.unthrottle();
     BOOST_CHECK( target.input );
     BOOST_CHECK_EQUAL( target.counter, 1u );
-    
+
     BOOST_CHECK( target.input() == p );
     BOOST_CHECK( ! target.input );
-    
+
     source.submit(p);
-    
+
     BOOST_CHECK_EQUAL( target.counter, 2u );
     BOOST_CHECK( target.input.throttled() );
     BOOST_CHECK( target.input() == p );
@@ -222,7 +226,7 @@ BOOST_AUTO_UNIT_TEST(passiveInput)
     BOOST_CHECK( ! target.input.throttled() );
 }
 
-BOOST_AUTO_UNIT_TEST(passiveOutput)
+SENF_AUTO_UNIT_TEST(passiveOutput)
 {
     debug::PassiveSource source;
     debug::ActiveSink target;
@@ -239,11 +243,11 @@ BOOST_AUTO_UNIT_TEST(passiveOutput)
 
     source.submit(p);
     BOOST_CHECK( target.request() == p );
-    
+
     // connect() is tested indirectly via ppi::connect
 }
 
-BOOST_AUTO_UNIT_TEST(activeInput)
+SENF_AUTO_UNIT_TEST(activeInput)
 {
     debug::PassiveSource source;
     debug::ActiveSink target;
@@ -268,14 +272,14 @@ BOOST_AUTO_UNIT_TEST(activeInput)
     BOOST_CHECK( target.request() == p );
 }
 
-BOOST_AUTO_UNIT_TEST(activeOutput)
+SENF_AUTO_UNIT_TEST(activeOutput)
 {
     debug::ActiveSource source;
     debug::PassiveSink target;
 
     ppi::connect(source,target);
     ppi::init();
-    
+
     BOOST_CHECK_EQUAL( & source.output.peer(), & target.input );
     BOOST_CHECK( source.output );
     target.input.throttle();
@@ -301,8 +305,8 @@ namespace {
         }
 
         void request() {
-            (void) input();
-            (void) input.read();
+            senf::IGNORE( input() );
+            senf::IGNORE( input.read() );
         }
     };
 
@@ -362,7 +366,7 @@ namespace {
 
 }
 
-BOOST_AUTO_UNIT_TEST(typedInput)
+SENF_AUTO_UNIT_TEST(typedInput)
 {
     debug::ActiveSource source;
     TypedPassiveInput<> target;
@@ -372,31 +376,35 @@ BOOST_AUTO_UNIT_TEST(typedInput)
 
     senf::Packet p (senf::DataPacket::create());
     source.submit(p);
+
+    BOOST_CHECK( true );
 }
 
-BOOST_AUTO_UNIT_TEST(tyepdOutput)
+SENF_AUTO_UNIT_TEST(tyepdOutput)
 {
     TypedPassiveOutput<> source;
     debug::ActiveSink target;
 
     ppi::connect(source,target);
     ppi::init();
-    
-    (void) target.request();
+
+    senf::IGNORE( target.request() );
+
+    BOOST_CHECK( true );
 }
 
-BOOST_AUTO_UNIT_TEST(connectorTest)
+SENF_AUTO_UNIT_TEST(connectorTest)
 {
     {
         TypedPassiveInput<> input;
         TypedActiveOutput<MyPacket> output;
-        BOOST_CHECK_THROW( ppi::connect(output, input), 
+        BOOST_CHECK_THROW( ppi::connect(output, input),
                            ppi::connector::IncompatibleConnectorsException );
     }
     {
         TypedPassiveInput<MyPacket> input;
         TypedActiveOutput<> output;
-        BOOST_CHECK_THROW( ppi::connect(output, input), 
+        BOOST_CHECK_THROW( ppi::connect(output, input),
                            ppi::connector::IncompatibleConnectorsException );
     }
     {
@@ -404,7 +412,7 @@ BOOST_AUTO_UNIT_TEST(connectorTest)
         TypedActiveOutput<> output;
         SENF_CHECK_NO_THROW( ppi::connect(output, input) );
     }
-    { 
+    {
         TypedPassiveInput<> input;
         debug::ActiveSource output;
         SENF_CHECK_NO_THROW( ppi::connect(output, input) );
@@ -421,7 +429,7 @@ BOOST_AUTO_UNIT_TEST(connectorTest)
     }
 }
 
-BOOST_AUTO_UNIT_TEST(delayedConnect)
+SENF_AUTO_UNIT_TEST(delayedConnect)
 {
     {
         debug::PassiveSource source;
@@ -472,13 +480,13 @@ BOOST_AUTO_UNIT_TEST(delayedConnect)
 
         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( target.front() == p );
         BOOST_CHECK_EQUAL( target.size(), 1u );
     }
 
@@ -494,14 +502,14 @@ BOOST_AUTO_UNIT_TEST(delayedConnect)
 
         ppi::connect(source, target);
         ppi::init();
-        
+
         BOOST_CHECK( ! source.output );
         target.unthrottle();
         BOOST_CHECK( source.output );
     }
 }
 
-BOOST_AUTO_UNIT_TEST(disconnect)
+SENF_AUTO_UNIT_TEST(disconnect)
 {
     {
         debug::PassiveSource source;
@@ -516,10 +524,10 @@ BOOST_AUTO_UNIT_TEST(disconnect)
         source.submit(p);
 
         BOOST_CHECK( target.input );
-        
+
         target.input.disconnect();
         ppi::init();
-        
+
         BOOST_CHECK( ! target.input );
     }
     {
@@ -538,7 +546,7 @@ BOOST_AUTO_UNIT_TEST(disconnect)
     }
 }
 
-///////////////////////////////cc.e////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 #undef prefix_
 
 \f