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 |
using Thread::SignalStartThread; // make method public |
38 |
protected: |
39 |
bool waitFor; |
40 |
}; |
41 |
|
42 |
// simulates a thread which sets the condition |
43 |
class ConditionSetter : public Thread { |
44 |
public: |
45 |
int resource; |
46 |
Condition* condition; |
47 |
|
48 |
ConditionSetter(Condition* condition, bool toSet); |
49 |
int Main(); |
50 |
using Thread::SignalStartThread; // make method public |
51 |
private: |
52 |
bool toSet; |
53 |
}; |
54 |
|
55 |
// same as 'ConditionChecker' except that this one uses WaitIf() instead of WaitAndUnlockIf() |
56 |
class ConditionCheckerLocking : public ConditionChecker { |
57 |
public: |
58 |
bool doUnlock; |
59 |
static Condition staticcondition; |
60 |
|
61 |
ConditionCheckerLocking(bool waitFor); |
62 |
int Main(); |
63 |
}; |
64 |
public: |
65 |
void setUp(); |
66 |
void tearDown(); |
67 |
|
68 |
void printTestSuiteName(); |
69 |
|
70 |
void testDoesntBlockOnDesiredCondtion(); |
71 |
void testBlocksIfNotDesiredCondition(); |
72 |
void testBlocksUntilDesiredCondition(); |
73 |
void testWaitIFBlocksConcurrentThread(); |
74 |
}; |
75 |
|
76 |
#endif // __LS_CONDITIONTEST_H__ |