25 #ifndef WMODULECONNECTOR_TEST_H
26 #define WMODULECONNECTOR_TEST_H
32 #include <cxxtest/TestSuite.h>
34 #include "../../common/WLogger.h"
35 #include "../../common/WPrototyped.h"
36 #include "../../common/WSegmentationFault.h"
37 #include "../../common/WTransferable.h"
38 #include "../WModule.h"
39 #include "../WModuleConnector.h"
40 #include "../WModuleInputConnector.h"
41 #include "../WModuleInputData.h"
42 #include "../WModuleOutputConnector.h"
43 #include "../WModuleOutputData.h"
44 #include "../exceptions/WModuleConnectionFailed.h"
45 #include "../exceptions/WModuleConnectorInitFailed.h"
46 #include "../exceptions/WModuleConnectorUnconnected.h"
47 #include "../exceptions/WModuleConnectorsIncompatible.h"
48 #include "../exceptions/WModuleException.h"
74 return "WTestTransferableBase";
84 return "Test class for testing transfer of data.";
148 return "WTestTransferableDerived";
158 return "Test class for testing transfer of data.";
206 virtual std::shared_ptr< WModule >
factory()
const
208 return std::shared_ptr< WModule >(
new WModuleImpl() );
236 m_input = std::shared_ptr< WModuleInputData< WTestTransferableBase > >(
242 m_output = std::shared_ptr< WModuleOutputData< WTestTransferableBase > >(
249 m_inputDerived = std::shared_ptr< WModuleInputData< WTestTransferableDerived > >(
255 m_outputDerived = std::shared_ptr< WModuleOutputData< WTestTransferableDerived > >(
283 std::shared_ptr< WModuleConnector > )
293 std::shared_ptr< WModuleConnector > )
306 std::shared_ptr< WModuleConnector > output )
309 std::shared_ptr< WModuleOutputData< WTestTransferableBase > > o =
310 std::dynamic_pointer_cast< WModuleOutputData< WTestTransferableBase > >( output );
316 std::shared_ptr< WTestTransferableBase > ds = o->getData();
319 data = ds->get() + 1;
335 std::shared_ptr< WModuleInputData< WTestTransferableBase > >
m_input;
345 std::shared_ptr< WModuleOutputData< WTestTransferableBase > >
m_output;
372 std::shared_ptr< WModuleImpl >
m1;
377 std::shared_ptr< WModuleImpl >
m2;
382 std::shared_ptr< WModuleImpl >
m3;
390 m1 = std::shared_ptr< WModuleImpl >(
new WModuleImpl(
"m1" ) );
391 m2 = std::shared_ptr< WModuleImpl >(
new WModuleImpl(
"m2" ) );
392 m3 = std::shared_ptr< WModuleImpl >(
new WModuleImpl(
"m3" ) );
411 m1->m_output->connect(
m2->m_input );
412 m1->m_input->connect(
m2->m_output );
425 TS_ASSERT(
m1->m_inputConnectors.size() == 0 );
426 TS_ASSERT(
m1->m_outputConnectors.size() == 0 );
439 TS_ASSERT(
m1->m_inputConnectors.size() == 2 );
440 TS_ASSERT(
m1->m_outputConnectors.size() == 2 );
441 TS_ASSERT(
m2->m_inputConnectors.size() == 2 );
442 TS_ASSERT(
m2->m_outputConnectors.size() == 2 );
443 TS_ASSERT(
m3->m_inputConnectors.size() == 2 );
444 TS_ASSERT(
m3->m_outputConnectors.size() == 2 );
447 TS_ASSERT(
m1->isInitialized()() );
448 TS_ASSERT(
m2->isInitialized()() );
449 TS_ASSERT(
m3->isInitialized()() );
464 TS_ASSERT(
m1->isInitialized()() );
482 TS_ASSERT(
m1->m_output->m_connected.size() == 0 );
483 TS_ASSERT(
m1->m_input->m_connected.size() == 0 );
484 TS_ASSERT(
m2->m_output->m_connected.size() == 0 );
485 TS_ASSERT(
m2->m_input->m_connected.size() == 0 );
498 TS_ASSERT(
m1->m_input->m_connected.size() == 0 );
499 TS_ASSERT(
m1->m_output->m_connected.size() == 0 );
500 TS_ASSERT(
m1->m_inputDerived->m_connected.size() == 0 );
501 TS_ASSERT(
m1->m_outputDerived->m_connected.size() == 0 );
504 TS_ASSERT_THROWS_NOTHING(
m1->m_input->connect(
m2->m_outputDerived ) );
505 TS_ASSERT(
m1->m_input->m_connected.size() == 1 );
506 TS_ASSERT(
m2->m_outputDerived->m_connected.size() == 1 );
510 TS_ASSERT(
m1->m_output->m_connected.size() == 0 );
511 TS_ASSERT(
m1->m_inputDerived->m_connected.size() == 0 );
525 TS_ASSERT(
m1->m_output->m_connected.size() == 1 );
526 TS_ASSERT(
m1->m_input->m_connected.size() == 1 );
527 TS_ASSERT(
m2->m_output->m_connected.size() == 1 );
528 TS_ASSERT(
m2->m_input->m_connected.size() == 1 );
541 TS_ASSERT_THROWS_NOTHING(
m1->m_output->connect(
m2->m_input ) );
542 TS_ASSERT_THROWS_NOTHING(
m1->m_input->connect(
m2->m_output ) );
543 TS_ASSERT(
m1->m_output->m_connected.size() == 1 );
544 TS_ASSERT(
m1->m_input->m_connected.size() == 1 );
545 TS_ASSERT(
m2->m_output->m_connected.size() == 1 );
546 TS_ASSERT(
m2->m_input->m_connected.size() == 1 );
559 TS_ASSERT_THROWS_NOTHING(
m1->m_output->disconnect(
m1->m_input ) );
560 TS_ASSERT(
m1->m_output->m_connected.size() == 1 );
561 TS_ASSERT(
m1->m_input->m_connected.size() == 1 );
564 TS_ASSERT_THROWS_NOTHING(
m1->m_output->disconnect(
m2->m_input ) );
565 TS_ASSERT(
m1->m_output->m_connected.size() == 0 );
566 TS_ASSERT(
m1->m_input->m_connected.size() == 1 );
567 TS_ASSERT(
m2->m_output->m_connected.size() == 1 );
568 TS_ASSERT(
m2->m_input->m_connected.size() == 0 );
581 TS_ASSERT_THROWS_NOTHING(
m3->m_input->connect(
m2->m_output ) );
584 TS_ASSERT(
m2->m_output->m_connected.size() == 2 );
585 TS_ASSERT(
m3->m_input->m_connected.size() == 1 );
588 m2->m_output->disconnectAll();
589 TS_ASSERT(
m2->m_output->m_connected.size() == 0 );
590 TS_ASSERT(
m1->m_input->m_connected.size() == 0 );
591 TS_ASSERT(
m3->m_input->m_connected.size() == 0 );
603 TS_ASSERT_THROWS_NOTHING(
m1->cleanup() );
604 TS_ASSERT(
m1->m_inputConnectors.size() == 0 );
605 TS_ASSERT(
m1->m_outputConnectors.size() == 0 );
621 TS_ASSERT_THROWS_NOTHING(
m1->m_output->updateData( data ) );
624 TS_ASSERT(
m1->m_output->getData()->get() == d );
625 TS_ASSERT(
m2->m_input->getData()->get() == d );
626 TS_ASSERT(
m2->data == d + 1 );
641 TS_ASSERT( !
m3->m_input->getData().get() );
644 TS_ASSERT(
m2->m_input->getData() == std::shared_ptr< WTestTransferableBase >() );
static void disableBacktrace()
Function disables backtraces.
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.
General purpose exception and therefore base class for all kernel related exceptions.
Tests the WModuleConnector class.
void testModuleCleanup(void)
Test whether module clean up is working properly.
void createModules(void)
Initialized the test modules.
void initConnections(void)
Initialize some connections.
std::shared_ptr< WModuleImpl > m2
Simple module to test with.
void initModules(void)
Initializes modules.
void testModuleInitialization(void)
Test whether modules can be initialized without problems.
void testModuleCreation(void)
Test whether modules can be created without exception and proper initialization of connection lists.
void testModuleTwiceInitialization(void)
Test whether module initialization is robust against double init.
void testModuleDisconnect(void)
Test whether the connection can properly be disconnected.
void testModuleConnection(void)
Test whether connection works properly.
std::shared_ptr< WModuleImpl > m1
Simple module to test with.
void testModuleDisconnectAll(void)
Test whether all connections can be removed in one step.
void testModuleConnectorTypeCompatibility(void)
Test whether automatic type compatibility check works.
std::shared_ptr< WModuleImpl > m3
Simple module to test with.
void testModuleConnectorCompatibility(void)
Test whether automatic compatibility check works.
void setUp()
Setup logger and other stuff for each test.
void testModuleTwiceConnection(void)
Test whether connecting twice is not possible.
void testModulePropagateDataChange(void)
Tests the propagation of data.
void testModuleInvalidData(void)
Tests several cases of unset data.
General purpose exception and therefore base class for all kernel related exceptions.
Class implementing a simple module since WModuleConnector itself is not usable for proper testing its...
std::shared_ptr< WModuleOutputData< WTestTransferableDerived > > m_outputDerived
Output connection with a derived class as transferable.
const std::string getDescription() const
Returns description of module.
std::shared_ptr< WModuleInputData< WTestTransferableBase > > m_input
Input connection.
std::shared_ptr< WModuleOutputData< WTestTransferableBase > > m_output
Output connection.
virtual ~WModuleImpl()
Destructor.
virtual void notifyDataChange(std::shared_ptr< WModuleConnector >, std::shared_ptr< WModuleConnector > output)
Notifier called whenever a changed data was propagated to one of this modules connectors.
virtual const std::string getName() const
Returns name of this module.
virtual void moduleMain()
Entry point after loading the module.
virtual void notifyConnectionClosed(std::shared_ptr< WModuleConnector >, std::shared_ptr< WModuleConnector >)
Notifier called whenever a connection got closed.
virtual std::shared_ptr< WModule > factory() const
Create instance of this module class.
int data
The data lastly submitted.
std::string n
temporary name string
WModuleImpl(std::string n="?")
Constructor.
std::shared_ptr< WModuleInputData< WTestTransferableDerived > > m_inputDerived
Input connection with a derived class as transferable.
virtual void connectors()
Set up connectors.
virtual void notifyConnectionEstablished(std::shared_ptr< WModuleConnector >, std::shared_ptr< WModuleConnector >)
Notifier called whenever a connection got established.
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
void addConnector(std::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
Test class used to test data transfer and compatibility checks.
WTestTransferableBase()
Constructor.
virtual const std::string getName() const
Gets the name of this prototype.
static std::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
void set(int i)
Sets the new int.
int get() const
Gives the magic int.
virtual const std::string getDescription() const
Gets the description for this prototype.
Derived test class used to test data transfer and compatibility checks, especially the inheritance ch...
virtual const std::string getDescription() const
Gets the description for this prototype.
WTestTransferableDerived()
Constructor.
virtual const std::string getName() const
Gets the name of this prototype.
static std::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
void sleep(const int32_t t) const
Sets thread asleep.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
Class building the interface for classes that might be transferred using WModuleConnector.