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