1 |
#ifndef __LS_CONDITIONTEST_H__ |
2 |
#define __LS_CONDITIONTEST_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 Condition class we want to test |
11 |
#include "../common/Condition.h" |
12 |
|
13 |
// we need an additional thread to test the Mutex class |
14 |
#include "../common/Thread.h" |
15 |
|
16 |
class ConditionTest : public CppUnit::TestFixture { |
17 |
|
18 |
CPPUNIT_TEST_SUITE(ConditionTest); |
19 |
CPPUNIT_TEST(printTestSuiteName); |
20 |
CPPUNIT_TEST(testDoesntBlockOnDesiredCondtion); |
21 |
CPPUNIT_TEST(testBlocksIfNotDesiredCondition); |
22 |
CPPUNIT_TEST(testBlocksUntilDesiredCondition); |
23 |
CPPUNIT_TEST(testWaitIFBlocksConcurrentThread); |
24 |
CPPUNIT_TEST_SUITE_END(); |
25 |
|
26 |
private: |
27 |
// simulates a thread waiting for a condition |
28 |
class ConditionChecker : public Thread { |
29 |
public: |
30 |
int resource; |
31 |
Condition condition; |
32 |
|
33 |
ConditionChecker(bool waitFor); |
34 |
int Main(); |
35 |
protected: |
36 |
bool waitFor; |
37 |
}; |
38 |
|
39 |
// simulates a thread which sets the condition |
40 |
class ConditionSetter : public Thread { |
41 |
public: |
42 |
int resource; |
43 |
Condition* condition; |
44 |
|
45 |
ConditionSetter(Condition* condition, bool toSet); |
46 |
int Main(); |
47 |
private: |
48 |
bool toSet; |
49 |
}; |
50 |
|
51 |
// same as 'ConditionChecker' except that this one uses WaitIf() instead of WaitAndUnlockIf() |
52 |
class ConditionCheckerLocking : public ConditionChecker { |
53 |
public: |
54 |
bool doUnlock; |
55 |
static Condition staticcondition; |
56 |
|
57 |
ConditionCheckerLocking(bool waitFor); |
58 |
int Main(); |
59 |
}; |
60 |
public: |
61 |
void setUp(); |
62 |
void tearDown(); |
63 |
|
64 |
void printTestSuiteName(); |
65 |
|
66 |
void testDoesntBlockOnDesiredCondtion(); |
67 |
void testBlocksIfNotDesiredCondition(); |
68 |
void testBlocksUntilDesiredCondition(); |
69 |
void testWaitIFBlocksConcurrentThread(); |
70 |
}; |
71 |
|
72 |
#endif // __LS_CONDITIONTEST_H__ |