25 #ifndef WWORKERTHREAD_TEST_H
26 #define WWORKERTHREAD_TEST_H
30 #include <cxxtest/TestSuite.h>
32 #include "../WWorkerThread.h"
33 #include "../WSharedObject.h"
71 for(
int i = 1; i <= *
m_input.get() && !shutdown(); ++i )
143 boost::shared_ptr< FuncType > func(
new FuncType( 6 ) );
151 TS_ASSERT_EQUALS( func->getResult(), 21 );
162 boost::shared_ptr< FuncType > func(
new FuncType( 100000000 ) );
170 TS_ASSERT( func->stopped() );
179 boost::shared_ptr< FuncType > func(
new FuncType( 5 ) );
191 TS_ASSERT_EQUALS( func->getResult(), 45 );
195 #ifdef WASSERT_AS_CASSERT
196 #define WASSERT_FLAG_CHANGED
197 #undefine WASSERT_AS_CASSERT
204 boost::shared_ptr< FuncType > func;
213 boost::shared_ptr< FuncType > func(
new FuncType( 5 ) );
217 #ifdef WASSERT_FLAG_CHANGED
218 #define WASSERT_AS_CASSERT
219 #undefine WASSERT_FLAG_CHANGED
255 if( strcmp( e.
what(),
"Test!" ) == 0 )
268 #endif // WWORKERTHREAD_TEST_H
WSharedObject< int > m_result
the result
boost::shared_ptr< int const > m_input
the input data
virtual void run()
Run thread.
void testStopThread()
Test if the thread gets shutdown correctly.
bool stopped()
Check if the thread was ordered to stop.
bool m_exceptionHandled
the exception was handled?
A worker thread that belongs to a.
void operator()(std::size_t, std::size_t, WBoolFlag &)
The function.
int getResult()
A method to extract the result.
void testSingleThread(void)
Test if calculation with a single thread works.
Tests the WWorkerThread class.
void subscribeExceptionSignal(ExceptionFunction func)
Subscribe a function to the exception signal.
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
WriteTicket getWriteTicket(bool suppressNotify=false) const
Returns a ticket to get write access to the contained data.
void testThreadId()
An invalid thread id should cause an exception.
void handleException(WException const &e)
Another one.
bool m_stopped
the thread was stopped?
void subscribeStopSignal(StopFunction func)
Subscribe a function to the stop signal.
void stopTestDone()
A utility function.
void testExceptions()
Test if exceptions get handled correctly.
void reset()
Reset everything.
A function that throws exceptions.
void testMultipleThreads()
Test if multiple threads correctly compute the result.
virtual const char * what() const
Returns the message string set on throw.
WSharedObject< bool > m_stopped
thread stopped?
virtual void requestStop()
This method's purpose is to request a stop without waiting for it.
void testNoFunction()
Providing a zero-Pointer as function should cause an exception.
void wait(bool requestFinish=false)
Wait for the thread to be finished.
FuncType(int value)
Constructor, initialize some stuff.
void operator()(std::size_t, std::size_t, WBoolFlag const &shutdown)
This is the actual thread function.