/[svn]/linuxsampler/trunk/src/testcases/ConditionTest.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/testcases/ConditionTest.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 63 - (show annotations) (download) (as text)
Tue May 4 18:52:24 2004 UTC (19 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 2041 byte(s)
* src/common/Thread.cpp: threads are now stoppable even if they are
  waiting for a condition
* src/common/Condition.cpp: fixed little misbehavior of Set() method,
  which locked the Condition object on return
* src/testcases: added a couple of new unit tests (against classes
  'Mutex', 'Condition' and 'Thread')

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

  ViewVC Help
Powered by ViewVC