1 |
schoenebeck |
57 |
#ifndef __LS_THREADTEST_H__ |
2 |
|
|
#define __LS_THREADTEST_H__ |
3 |
|
|
|
4 |
|
|
#include <cppunit/TestFixture.h> |
5 |
|
|
#include <cppunit/extensions/HelperMacros.h> |
6 |
|
|
|
7 |
|
|
// needed for sleep() and usleep() calls |
8 |
|
|
#include <unistd.h> |
9 |
|
|
|
10 |
|
|
// the Thread class we want to test |
11 |
|
|
#include "../common/Thread.h" |
12 |
|
|
|
13 |
schoenebeck |
63 |
// we need that to check if our thread is killable even if waiting for a condition |
14 |
|
|
#include "../common/Condition.h" |
15 |
|
|
|
16 |
schoenebeck |
57 |
class ThreadTest : public CppUnit::TestFixture { |
17 |
|
|
|
18 |
|
|
CPPUNIT_TEST_SUITE(ThreadTest); |
19 |
|
|
CPPUNIT_TEST(testThreadRunning); |
20 |
|
|
CPPUNIT_TEST(testSignalStopThread); |
21 |
|
|
CPPUNIT_TEST(testRelaunchThread); |
22 |
|
|
CPPUNIT_TEST(testStopThread); |
23 |
schoenebeck |
63 |
CPPUNIT_TEST(testThreadKillableWhenWaiting); |
24 |
schoenebeck |
57 |
CPPUNIT_TEST_SUITE_END(); |
25 |
|
|
|
26 |
|
|
private: |
27 |
|
|
// this is our test implementation of the abstract base class Thread which we will use to test class Thread |
28 |
|
|
class DummyThread : public Thread { |
29 |
|
|
public: |
30 |
|
|
bool wasRunning; // this variable is false on startup and will be switched to true by the thread, so we can check if the thread actually runs |
31 |
|
|
|
32 |
|
|
DummyThread(); |
33 |
|
|
int Main(); |
34 |
|
|
} dummythread; |
35 |
|
|
|
36 |
|
|
// this is only a helper thread to avoid that the entire test case run hangs when we try to stop the dummy thread |
37 |
|
|
class HelperThread : public Thread { |
38 |
|
|
private: |
39 |
|
|
DummyThread* pDummyThread; |
40 |
|
|
public: |
41 |
|
|
bool returnedFromDummyStop; |
42 |
|
|
|
43 |
|
|
HelperThread(DummyThread* pDummyThread); |
44 |
|
|
int Main(); |
45 |
|
|
}; |
46 |
schoenebeck |
63 |
|
47 |
|
|
// this simulates a thread that is waiting for a condition (thus sleeping til then) |
48 |
|
|
class WaitingThread : public Thread { |
49 |
|
|
public: |
50 |
|
|
WaitingThread(); |
51 |
|
|
int Main(); |
52 |
|
|
private: |
53 |
|
|
Condition condition; |
54 |
|
|
}; |
55 |
schoenebeck |
57 |
public: |
56 |
|
|
void setUp() { |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
void tearDown() { |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
void testThreadRunning(); |
63 |
|
|
void testSignalStopThread(); |
64 |
|
|
void testRelaunchThread(); |
65 |
|
|
void testStopThread(); |
66 |
schoenebeck |
63 |
void testThreadKillableWhenWaiting(); |
67 |
schoenebeck |
57 |
}; |
68 |
|
|
|
69 |
|
|
#endif // __LS_THREADTEST_H__ |