25 #ifndef WMODULECONNECTOR_TEST_H
26 #define WMODULECONNECTOR_TEST_H
31 #include <boost/shared_ptr.hpp>
33 #include <cxxtest/TestSuite.h>
35 #include "../WModuleConnector.h"
36 #include "../WModuleInputData.h"
37 #include "../WModuleOutputData.h"
38 #include "../WModuleInputConnector.h"
39 #include "../WModuleOutputConnector.h"
40 #include "../WModule.h"
41 #include "../../common/WSegmentationFault.h"
42 #include "../../common/WTransferable.h"
43 #include "../../common/WPrototyped.h"
44 #include "../../common/WLogger.h"
45 #include "../exceptions/WModuleConnectorInitFailed.h"
46 #include "../exceptions/WModuleConnectionFailed.h"
47 #include "../exceptions/WModuleConnectorsIncompatible.h"
48 #include "../exceptions/WModuleException.h"
49 #include "../exceptions/WModuleConnectorUnconnected.h"
75 return "WTestTransferableBase";
85 return "Test class for testing transfer of data.";
149 return "WTestTransferableDerived";
159 return "Test class for testing transfer of data.";
207 virtual boost::shared_ptr< WModule >
factory()
const
209 return boost::shared_ptr< WModule >(
new WModuleImpl() );
237 m_input = boost::shared_ptr< WModuleInputData< WTestTransferableBase > >(
243 m_output = boost::shared_ptr< WModuleOutputData< WTestTransferableBase > >(
250 m_inputDerived = boost::shared_ptr< WModuleInputData< WTestTransferableDerived > >(
256 m_outputDerived = boost::shared_ptr< WModuleOutputData< WTestTransferableDerived > >(
284 boost::shared_ptr< WModuleConnector > )
294 boost::shared_ptr< WModuleConnector > )
307 boost::shared_ptr< WModuleConnector > output )
310 boost::shared_ptr< WModuleOutputData< WTestTransferableBase > > o =
317 boost::shared_ptr< WTestTransferableBase > ds = o->
getData();
320 data = ds->get() + 1;
336 boost::shared_ptr< WModuleInputData< WTestTransferableBase > >
m_input;
341 boost::shared_ptr< WModuleInputData< WTestTransferableDerived > >
m_inputDerived;
346 boost::shared_ptr< WModuleOutputData< WTestTransferableBase > >
m_output;
373 boost::shared_ptr< WModuleImpl >
m1;
378 boost::shared_ptr< WModuleImpl >
m2;
383 boost::shared_ptr< WModuleImpl >
m3;
391 m1 = boost::shared_ptr< WModuleImpl >(
new WModuleImpl(
"m1" ) );
392 m2 = boost::shared_ptr< WModuleImpl >(
new WModuleImpl(
"m2" ) );
393 m3 = boost::shared_ptr< WModuleImpl >(
new WModuleImpl(
"m3" ) );
412 m1->m_output->connect(
m2->m_input );
413 m1->m_input->connect(
m2->m_output );
426 TS_ASSERT(
m1->m_inputConnectors.size() == 0 );
427 TS_ASSERT(
m1->m_outputConnectors.size() == 0 );
440 TS_ASSERT(
m1->m_inputConnectors.size() == 2 );
441 TS_ASSERT(
m1->m_outputConnectors.size() == 2 );
442 TS_ASSERT(
m2->m_inputConnectors.size() == 2 );
443 TS_ASSERT(
m2->m_outputConnectors.size() == 2 );
444 TS_ASSERT(
m3->m_inputConnectors.size() == 2 );
445 TS_ASSERT(
m3->m_outputConnectors.size() == 2 );
448 TS_ASSERT(
m1->isInitialized()() );
449 TS_ASSERT(
m2->isInitialized()() );
450 TS_ASSERT(
m3->isInitialized()() );
465 TS_ASSERT(
m1->isInitialized()() );
483 TS_ASSERT(
m1->m_output->m_connected.size() == 0 );
484 TS_ASSERT(
m1->m_input->m_connected.size() == 0 );
485 TS_ASSERT(
m2->m_output->m_connected.size() == 0 );
486 TS_ASSERT(
m2->m_input->m_connected.size() == 0 );
499 TS_ASSERT(
m1->m_input->m_connected.size() == 0 );
500 TS_ASSERT(
m1->m_output->m_connected.size() == 0 );
501 TS_ASSERT(
m1->m_inputDerived->m_connected.size() == 0 );
502 TS_ASSERT(
m1->m_outputDerived->m_connected.size() == 0 );
505 TS_ASSERT_THROWS_NOTHING(
m1->m_input->connect(
m2->m_outputDerived ) );
506 TS_ASSERT(
m1->m_input->m_connected.size() == 1 );
507 TS_ASSERT(
m2->m_outputDerived->m_connected.size() == 1 );
511 TS_ASSERT(
m1->m_output->m_connected.size() == 0 );
512 TS_ASSERT(
m1->m_inputDerived->m_connected.size() == 0 );
526 TS_ASSERT(
m1->m_output->m_connected.size() == 1 );
527 TS_ASSERT(
m1->m_input->m_connected.size() == 1 );
528 TS_ASSERT(
m2->m_output->m_connected.size() == 1 );
529 TS_ASSERT(
m2->m_input->m_connected.size() == 1 );
542 TS_ASSERT_THROWS_NOTHING(
m1->m_output->connect(
m2->m_input ) );
543 TS_ASSERT_THROWS_NOTHING(
m1->m_input->connect(
m2->m_output ) );
544 TS_ASSERT(
m1->m_output->m_connected.size() == 1 );
545 TS_ASSERT(
m1->m_input->m_connected.size() == 1 );
546 TS_ASSERT(
m2->m_output->m_connected.size() == 1 );
547 TS_ASSERT(
m2->m_input->m_connected.size() == 1 );
560 TS_ASSERT_THROWS_NOTHING(
m1->m_output->disconnect(
m1->m_input ) );
561 TS_ASSERT(
m1->m_output->m_connected.size() == 1 );
562 TS_ASSERT(
m1->m_input->m_connected.size() == 1 );
565 TS_ASSERT_THROWS_NOTHING(
m1->m_output->disconnect(
m2->m_input ) );
566 TS_ASSERT(
m1->m_output->m_connected.size() == 0 );
567 TS_ASSERT(
m1->m_input->m_connected.size() == 1 );
568 TS_ASSERT(
m2->m_output->m_connected.size() == 1 );
569 TS_ASSERT(
m2->m_input->m_connected.size() == 0 );
582 TS_ASSERT_THROWS_NOTHING(
m3->m_input->connect(
m2->m_output ) );
585 TS_ASSERT(
m2->m_output->m_connected.size() == 2 );
586 TS_ASSERT(
m3->m_input->m_connected.size() == 1 );
589 m2->m_output->disconnectAll();
590 TS_ASSERT(
m2->m_output->m_connected.size() == 0 );
591 TS_ASSERT(
m1->m_input->m_connected.size() == 0 );
592 TS_ASSERT(
m3->m_input->m_connected.size() == 0 );
604 TS_ASSERT_THROWS_NOTHING(
m1->cleanup() );
605 TS_ASSERT(
m1->m_inputConnectors.size() == 0 );
606 TS_ASSERT(
m1->m_outputConnectors.size() == 0 );
622 TS_ASSERT_THROWS_NOTHING(
m1->m_output->updateData( data ) );
625 TS_ASSERT(
m1->m_output->getData()->get() == d );
626 TS_ASSERT(
m2->m_input->getData()->get() == d );
627 TS_ASSERT(
m2->data == d + 1 );
642 TS_ASSERT( !
m3->m_input->getData().get() );
645 TS_ASSERT(
m2->m_input->getData() == boost::shared_ptr< WTestTransferableBase >() );
649 #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.