25 #ifndef WMODULECONNECTOR_TEST_H
26 #define WMODULECONNECTOR_TEST_H
32 #include <boost/shared_ptr.hpp>
35 #include <cxxtest/TestSuite.h>
37 #include "../WModuleConnector.h"
38 #include "../WModuleInputData.h"
39 #include "../WModuleOutputData.h"
40 #include "../WModuleInputConnector.h"
41 #include "../WModuleOutputConnector.h"
42 #include "../WModule.h"
43 #include "../../common/WSegmentationFault.h"
44 #include "../../common/WTransferable.h"
45 #include "../../common/WPrototyped.h"
46 #include "../../common/WLogger.h"
47 #include "../exceptions/WModuleConnectorInitFailed.h"
48 #include "../exceptions/WModuleConnectionFailed.h"
49 #include "../exceptions/WModuleConnectorsIncompatible.h"
50 #include "../exceptions/WModuleException.h"
51 #include "../exceptions/WModuleConnectorUnconnected.h"
77 return "WTestTransferableBase";
87 return "Test class for testing transfer of data.";
151 return "WTestTransferableDerived";
161 return "Test class for testing transfer of data.";
209 virtual boost::shared_ptr< WModule >
factory()
const
211 return boost::shared_ptr< WModule >(
new WModuleImpl() );
239 m_input = boost::shared_ptr< WModuleInputData< WTestTransferableBase > >(
245 m_output = boost::shared_ptr< WModuleOutputData< WTestTransferableBase > >(
252 m_inputDerived = boost::shared_ptr< WModuleInputData< WTestTransferableDerived > >(
258 m_outputDerived = boost::shared_ptr< WModuleOutputData< WTestTransferableDerived > >(
286 boost::shared_ptr< WModuleConnector > )
296 boost::shared_ptr< WModuleConnector > )
309 boost::shared_ptr< WModuleConnector > output )
312 boost::shared_ptr< WModuleOutputData< WTestTransferableBase > > o =
319 boost::shared_ptr< WTestTransferableBase > ds = o->
getData();
322 data = ds->get() + 1;
338 boost::shared_ptr< WModuleInputData< WTestTransferableBase > >
m_input;
343 boost::shared_ptr< WModuleInputData< WTestTransferableDerived > >
m_inputDerived;
348 boost::shared_ptr< WModuleOutputData< WTestTransferableBase > >
m_output;
375 boost::shared_ptr< WModuleImpl >
m1;
380 boost::shared_ptr< WModuleImpl >
m2;
385 boost::shared_ptr< WModuleImpl >
m3;
393 m1 = boost::shared_ptr< WModuleImpl >(
new WModuleImpl(
"m1" ) );
394 m2 = boost::shared_ptr< WModuleImpl >(
new WModuleImpl(
"m2" ) );
395 m3 = boost::shared_ptr< WModuleImpl >(
new WModuleImpl(
"m3" ) );
414 m1->m_output->connect( m2->m_input );
415 m1->m_input->connect( m2->m_output );
428 TS_ASSERT( m1->m_inputConnectors.size() == 0 );
429 TS_ASSERT( m1->m_outputConnectors.size() == 0 );
442 TS_ASSERT( m1->m_inputConnectors.size() == 2 );
443 TS_ASSERT( m1->m_outputConnectors.size() == 2 );
444 TS_ASSERT( m2->m_inputConnectors.size() == 2 );
445 TS_ASSERT( m2->m_outputConnectors.size() == 2 );
446 TS_ASSERT( m3->m_inputConnectors.size() == 2 );
447 TS_ASSERT( m3->m_outputConnectors.size() == 2 );
450 TS_ASSERT( m1->isInitialized()() );
451 TS_ASSERT( m2->isInitialized()() );
452 TS_ASSERT( m3->isInitialized()() );
467 TS_ASSERT( m1->isInitialized()() );
485 TS_ASSERT( m1->m_output->m_connected.size() == 0 );
486 TS_ASSERT( m1->m_input->m_connected.size() == 0 );
487 TS_ASSERT( m2->m_output->m_connected.size() == 0 );
488 TS_ASSERT( m2->m_input->m_connected.size() == 0 );
501 TS_ASSERT( m1->m_input->m_connected.size() == 0 );
502 TS_ASSERT( m1->m_output->m_connected.size() == 0 );
503 TS_ASSERT( m1->m_inputDerived->m_connected.size() == 0 );
504 TS_ASSERT( m1->m_outputDerived->m_connected.size() == 0 );
507 TS_ASSERT_THROWS_NOTHING( m1->m_input->connect( m2->m_outputDerived ) );
508 TS_ASSERT( m1->m_input->m_connected.size() == 1 );
509 TS_ASSERT( m2->m_outputDerived->m_connected.size() == 1 );
513 TS_ASSERT( m1->m_output->m_connected.size() == 0 );
514 TS_ASSERT( m1->m_inputDerived->m_connected.size() == 0 );
528 TS_ASSERT( m1->m_output->m_connected.size() == 1 );
529 TS_ASSERT( m1->m_input->m_connected.size() == 1 );
530 TS_ASSERT( m2->m_output->m_connected.size() == 1 );
531 TS_ASSERT( m2->m_input->m_connected.size() == 1 );
544 TS_ASSERT_THROWS_NOTHING( m1->m_output->connect( m2->m_input ) );
545 TS_ASSERT_THROWS_NOTHING( m1->m_input->connect( m2->m_output ) );
546 TS_ASSERT( m1->m_output->m_connected.size() == 1 );
547 TS_ASSERT( m1->m_input->m_connected.size() == 1 );
548 TS_ASSERT( m2->m_output->m_connected.size() == 1 );
549 TS_ASSERT( m2->m_input->m_connected.size() == 1 );
562 TS_ASSERT_THROWS_NOTHING( m1->m_output->disconnect( m1->m_input ) );
563 TS_ASSERT( m1->m_output->m_connected.size() == 1 );
564 TS_ASSERT( m1->m_input->m_connected.size() == 1 );
567 TS_ASSERT_THROWS_NOTHING( m1->m_output->disconnect( m2->m_input ) );
568 TS_ASSERT( m1->m_output->m_connected.size() == 0 );
569 TS_ASSERT( m1->m_input->m_connected.size() == 1 );
570 TS_ASSERT( m2->m_output->m_connected.size() == 1 );
571 TS_ASSERT( m2->m_input->m_connected.size() == 0 );
584 TS_ASSERT_THROWS_NOTHING( m3->m_input->connect( m2->m_output ) );
587 TS_ASSERT( m2->m_output->m_connected.size() == 2 );
588 TS_ASSERT( m3->m_input->m_connected.size() == 1 );
591 m2->m_output->disconnectAll();
592 TS_ASSERT( m2->m_output->m_connected.size() == 0 );
593 TS_ASSERT( m1->m_input->m_connected.size() == 0 );
594 TS_ASSERT( m3->m_input->m_connected.size() == 0 );
606 TS_ASSERT_THROWS_NOTHING( m1->cleanup() );
607 TS_ASSERT( m1->m_inputConnectors.size() == 0 );
608 TS_ASSERT( m1->m_outputConnectors.size() == 0 );
624 TS_ASSERT_THROWS_NOTHING( m1->m_output->updateData( data ) );
627 TS_ASSERT( m1->m_output->getData()->get() == d );
628 TS_ASSERT( m2->m_input->getData()->get() == d );
629 TS_ASSERT( m2->data == d + 1 );
644 TS_ASSERT( !m3->m_input->getData().get() );
647 TS_ASSERT( m2->m_input->getData() == boost::shared_ptr< WTestTransferableBase >() );
651 #endif // WMODULECONNECTOR_TEST_H
void createModules(void)
Initialized the test modules.
void setUp()
Setup logger and other stuff for each test.
static void disableBacktrace()
Function disables backtraces.
static boost::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
void testModuleTwiceInitialization(void)
Test whether module initialization is robust against double init.
Class representing a single module of OpenWalnut.
void testModuleConnection(void)
Test whether connection works properly.
boost::shared_ptr< WModuleImpl > m3
Simple module to test with.
Derived test class used to test data transfer and compatibility checks, especially the inheritance ch...
WTestTransferableBase()
Constructor.
virtual void notifyDataChange(boost::shared_ptr< WModuleConnector >, boost::shared_ptr< WModuleConnector > output)
Notifier called whenever a changed data was propagated to one of this modules connectors.
Class implementing a simple module since WModuleConnector itself is not usable for proper testing its...
void testModuleInitialization(void)
Test whether modules can be initialized without problems.
virtual void notifyConnectionClosed(boost::shared_ptr< WModuleConnector >, boost::shared_ptr< WModuleConnector >)
Notifier called whenever a connection got closed.
virtual ~WModuleImpl()
Destructor.
const boost::shared_ptr< T > getData() const
Gives back the currently set data.
std::string n
temporary name string
Class offering an instantiate-able data connection between modules.
void testModuleDisconnect(void)
Test whether the connection can properly be disconnected.
void sleep(const int32_t t) const
Sets thread asleep.
virtual const std::string getName() const
Gets the name of this prototype.
boost::shared_ptr< WModuleOutputData< WTestTransferableDerived > > m_outputDerived
Output connection with a derived class as transferable.
General purpose exception and therefore base class for all kernel related exceptions.
boost::shared_ptr< WModuleInputData< WTestTransferableDerived > > m_inputDerived
Input connection with a derived class as transferable.
static void startup(std::ostream &output=std::cout, LogLevel level=LL_DEBUG)
Create the first and only instance of the logger as it is a singleton.
virtual void connectors()
Set up connectors.
void testModuleCreation(void)
Test whether modules can be created without exception and proper initialization of connection lists...
boost::shared_ptr< WModuleInputData< WTestTransferableBase > > m_input
Input connection.
void testModuleCleanup(void)
Test whether module clean up is working properly.
Class building the interface for classes that might be transferred using WModuleConnector.
Tests the WModuleConnector class.
void testModuleInvalidData(void)
Tests several cases of unset data.
virtual const std::string getName() const
Gets the name of this prototype.
virtual void moduleMain()
Entry point after loading the module.
void testModulePropagateDataChange(void)
Tests the propagation of data.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
virtual const std::string getName() const
Returns name of this module.
virtual void notifyConnectionEstablished(boost::shared_ptr< WModuleConnector >, boost::shared_ptr< WModuleConnector >)
Notifier called whenever a connection got established.
void initConnections(void)
Initialize some connections.
virtual const std::string getDescription() const
Gets the description for this prototype.
WModuleImpl(std::string n="?")
Constructor.
virtual boost::shared_ptr< WModule > factory() const
Create instance of this module class.
WTestTransferableDerived()
Constructor.
Test class used to test data transfer and compatibility checks.
void testModuleConnectorCompatibility(void)
Test whether automatic compatibility check works.
int data
The data lastly submitted.
void set(int i)
Sets the new int.
void initModules(void)
Initializes modules.
const std::string getDescription() const
Returns description of module.
void testModuleTwiceConnection(void)
Test whether connecting twice is not possible.
boost::shared_ptr< WModuleImpl > m1
Simple module to test with.
void testModuleConnectorTypeCompatibility(void)
Test whether automatic type compatibility check works.
void testModuleDisconnectAll(void)
Test whether all connections can be removed in one step.
void addConnector(boost::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
boost::shared_ptr< WModuleOutputData< WTestTransferableBase > > m_output
Output connection.
General purpose exception and therefore base class for all kernel related exceptions.
virtual const std::string getDescription() const
Gets the description for this prototype.
boost::shared_ptr< WModuleImpl > m2
Simple module to test with.
static boost::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.