25 #ifndef WWORKERTHREAD_TEST_H
26 #define WWORKERTHREAD_TEST_H
31 #include <cxxtest/TestSuite.h>
33 #include "../WSharedObject.h"
34 #include "../WWorkerThread.h"
72 for(
int i = 1; i <= *
m_input.get() && !shutdown(); ++i )
144 std::shared_ptr< FuncType > func(
new FuncType( 6 ) );
152 TS_ASSERT_EQUALS( func->getResult(), 21 );
163 std::shared_ptr< FuncType > func(
new FuncType( 100000000 ) );
171 TS_ASSERT( func->stopped() );
180 std::shared_ptr< FuncType > func(
new FuncType( 5 ) );
192 TS_ASSERT_EQUALS( func->getResult(), 45 );
196 #ifdef WASSERT_AS_CASSERT
197 #define WASSERT_FLAG_CHANGED
198 #undef WASSERT_AS_CASSERT
205 std::shared_ptr< FuncType > func;
214 std::shared_ptr< FuncType > func(
new FuncType( 5 ) );
218 #ifdef WASSERT_FLAG_CHANGED
219 #define WASSERT_AS_CASSERT
220 #undef WASSERT_FLAG_CHANGED
256 if( strcmp( e.
what(),
"Test!" ) == 0 )
virtual const char * what() const
Returns the message string set on throw.
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.
virtual void run()
Run thread.
virtual void requestStop()
This method's purpose is to request a stop without waiting for it.
void wait(bool requestFinish=false)
Wait for the thread to be finished.
A function that throws exceptions.
void operator()(std::size_t, std::size_t, WBoolFlag &)
The function.
std::shared_ptr< int const > m_input
the input data
WSharedObject< int > m_result
the result
bool stopped()
Check if the thread was ordered to stop.
FuncType(int value)
Constructor, initialize some stuff.
int getResult()
A method to extract the result.
void reset()
Reset everything.
void operator()(std::size_t, std::size_t, WBoolFlag const &shutdown)
This is the actual thread function.
WSharedObject< bool > m_stopped
thread stopped?
Tests the WWorkerThread class.
void testSingleThread(void)
Test if calculation with a single thread works.
void testThreadId()
An invalid thread id should cause an exception.
void testNoFunction()
Providing a zero-Pointer as function should cause an exception.
void handleException(WException const &e)
Another one.
bool m_exceptionHandled
the exception was handled?
void testStopThread()
Test if the thread gets shutdown correctly.
bool m_stopped
the thread was stopped?
void testExceptions()
Test if exceptions get handled correctly.
void stopTestDone()
A utility function.
void testMultipleThreads()
Test if multiple threads correctly compute the result.
A worker thread that belongs to a.
void subscribeStopSignal(StopFunction func)
Subscribe a function to the stop signal.
void subscribeExceptionSignal(ExceptionFunction func)
Subscribe a function to the exception signal.