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 |
|
|
class ThreadTest : public CppUnit::TestFixture { |
14 |
|
|
|
15 |
|
|
CPPUNIT_TEST_SUITE(ThreadTest); |
16 |
|
|
CPPUNIT_TEST(testThreadRunning); |
17 |
|
|
CPPUNIT_TEST(testSignalStopThread); |
18 |
|
|
CPPUNIT_TEST(testRelaunchThread); |
19 |
|
|
CPPUNIT_TEST(testStopThread); |
20 |
|
|
CPPUNIT_TEST_SUITE_END(); |
21 |
|
|
|
22 |
|
|
private: |
23 |
|
|
// this is our test implementation of the abstract base class Thread which we will use to test class Thread |
24 |
|
|
class DummyThread : public Thread { |
25 |
|
|
public: |
26 |
|
|
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 |
27 |
|
|
|
28 |
|
|
DummyThread(); |
29 |
|
|
int Main(); |
30 |
|
|
} dummythread; |
31 |
|
|
|
32 |
|
|
// this is only a helper thread to avoid that the entire test case run hangs when we try to stop the dummy thread |
33 |
|
|
class HelperThread : public Thread { |
34 |
|
|
private: |
35 |
|
|
DummyThread* pDummyThread; |
36 |
|
|
public: |
37 |
|
|
bool returnedFromDummyStop; |
38 |
|
|
|
39 |
|
|
HelperThread(DummyThread* pDummyThread); |
40 |
|
|
int Main(); |
41 |
|
|
}; |
42 |
|
|
public: |
43 |
|
|
void setUp() { |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
void tearDown() { |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
void testThreadRunning(); |
50 |
|
|
void testSignalStopThread(); |
51 |
|
|
void testRelaunchThread(); |
52 |
|
|
void testStopThread(); |
53 |
|
|
}; |
54 |
|
|
|
55 |
|
|
#endif // __LS_THREADTEST_H__ |