X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=PPI%2FConnectors.test.cc;h=16c76eab550956d1835a2302fb7dee1cdabfe66f;hb=e7ac3fef18af5ec0076f02290ad439a9d6e05491;hp=acf957f56326e14e17140d8927521c5217483c0f;hpb=81ffa1c459b96dd44472bcef37e1e373934ee138;p=senf.git diff --git a/PPI/Connectors.test.cc b/PPI/Connectors.test.cc index acf957f..16c76ea 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) +// 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 @@ -28,15 +28,262 @@ // Custom includes #include "Connectors.hh" +#include "DebugModules.hh" +#include "Setup.hh" -#include +#include "../Utils/auto_unit_test.hh" #include #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -BOOST_AUTO_UNIT_TEST(connectors) -{} +namespace ppi = senf::ppi; +namespace debug = ppi::module::debug; + +// For each type of connector we use the corresponding debug module. Additionally, we always need +// the corresponding connected module since otherwise the connectors cannot be connected anywhere +// and will be unusable. + +BOOST_AUTO_UNIT_TEST(connector) +{ + // It doesn't matter, which type of connectors we use here since they are all based on + // Connector. + + debug::ActiveSource source; + debug::PassiveSink target; + + ppi::connect(source.output,target.input); + ppi::init(); + + BOOST_CHECK_EQUAL( & source.output.module(), & source ); + BOOST_CHECK_EQUAL( & target.input.module(), & target ); + BOOST_CHECK_EQUAL( & source.output.peer(), & target.input ); + BOOST_CHECK_EQUAL( & target.input.peer(), & source.output ); +} + +BOOST_AUTO_UNIT_TEST(passiveConnector) +{ + debug::ActiveSource source; + debug::PassiveSink target; + + ppi::connect(source.output,target.input); + ppi::init(); + + // onRequest is implicitly tested within the PassiveSink implementation which is tested + // in DebugModules.test.cc + + 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() ); + + BOOST_CHECK_EQUAL( & target.input.peer(), & source.output ); +} + +namespace { + + bool called = false; + + void handler() { called = true; } +} + +BOOST_AUTO_UNIT_TEST(activeConnector) +{ + debug::ActiveSource source; + debug::PassiveSink target; + + ppi::connect(source.output,target.input); + ppi::init(); + + source.output.onThrottle(handler); + BOOST_CHECK( ! called ); + target.input.throttle(); + BOOST_CHECK( called ); + called = false; + target.input.unthrottle(); + BOOST_CHECK( ! called ); + source.output.onThrottle(); + source.output.onUnthrottle(handler); + BOOST_CHECK( ! called ); + target.input.throttle(); + BOOST_CHECK( ! called ); + target.input.unthrottle(); + BOOST_CHECK( called ); + source.output.onUnthrottle(); + called = false; + BOOST_CHECK( ! called ); + target.input.throttle(); + target.input.unthrottle(); + BOOST_CHECK( ! called ); + + BOOST_CHECK_EQUAL( & source.output.peer(), & target.input ); +} + +BOOST_AUTO_UNIT_TEST(inputConnector) +{ + debug::ActiveSource source; + debug::PassiveSink target; + + ppi::connect(source.output,target.input); + ppi::init(); + + // operator() is implicitly tested within the Active/PassiveSink implementation which is + // tested in DebugModules.test.cc + + // 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) +{ + debug::ActiveSource source; + debug::PassiveSink target; + + ppi::connect(source.output,target.input); + ppi::init(); + + // operator() is implicitly tested within the Active/PassiveSource implementation which is + // tested in DebugModules.test.cc + + BOOST_CHECK_EQUAL( & source.output.peer(), & target.input ); +} + +namespace { + + class PassiveInputTest + : public ppi::module::Module + { + SENF_PPI_MODULE(PassiveInputTest); + + public: + ppi::connector::PassiveInput<> input; + + PassiveInputTest() : counter() { + noroute(input); + input.onRequest(&PassiveInputTest::request); + } + + void request() { + ++ counter; + } + + unsigned counter; + }; +} + +BOOST_AUTO_UNIT_TEST(passiveInput) +{ + debug::ActiveSource source; + PassiveInputTest target; + + ppi::connect(source,target); + 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 ); + BOOST_CHECK( ! target.input.throttled() ); + + target.input.qdisc(ppi::ThresholdQueueing(2,0)); + + source.submit(p); + BOOST_CHECK ( ! target.input.throttled() ); + source.submit(p); + BOOST_CHECK( target.input.throttled() ); + target.input(); + BOOST_CHECK( target.input.throttled() ); + target.input(); + BOOST_CHECK( ! target.input.throttled() ); +} + +BOOST_AUTO_UNIT_TEST(passiveOutput) +{ + debug::PassiveSource source; + debug::ActiveSink target; + + ppi::connect(source,target); + ppi::init(); + + senf::Packet p (senf::DataPacket::create()); + source.submit(p); + + BOOST_CHECK_EQUAL( & source.output.peer(), & target.input ); + + BOOST_CHECK( source.output ); + + source.submit(p); + BOOST_CHECK( target.request() == p ); + + // connect() is tested indirectly via ppi::connect +} + +BOOST_AUTO_UNIT_TEST(activeInput) +{ + debug::PassiveSource source; + debug::ActiveSink target; + + ppi::connect(source,target); + ppi::init(); + + BOOST_CHECK_EQUAL( & target.input.peer(), & source.output ); + + BOOST_CHECK ( ! target.input ); + + senf::Packet p (senf::DataPacket::create()); + source.submit(p); + + BOOST_CHECK( target.input ); + BOOST_CHECK( target.request() == p ); + + source.submit(p); + target.input.request(); + BOOST_CHECK_EQUAL( target.input.queueSize(), 1u ); + BOOST_CHECK( target.input ); + BOOST_CHECK( target.request() == p ); +} + +BOOST_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(); + BOOST_CHECK( ! source.output ); + + // connect() is tested indirectly via ppi::connect +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_