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

Contents of /linuxsampler/trunk/src/testcases/MutexTest.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: 1671 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_MUTEXTEST_H__
2 #define __LS_MUTEXTEST_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 Mutex class we want to test
11 #include "../common/Mutex.h"
12
13 // we need an additional thread to test the Mutex class
14 #include "../common/Thread.h"
15
16 class MutexTest : public CppUnit::TestFixture {
17
18 CPPUNIT_TEST_SUITE(MutexTest);
19 CPPUNIT_TEST(testLockAndUnlockBySingleThread);
20 CPPUNIT_TEST(testLock);
21 CPPUNIT_TEST(testUnlock);
22 CPPUNIT_TEST(testDoubleLock);
23 CPPUNIT_TEST(testDoubleLockStillBlocksConcurrentThread);
24 CPPUNIT_TEST_SUITE_END();
25
26 private:
27 // dummy thread to simulate usage of a shared resource
28 class ConcurrentThread : public Thread {
29 public:
30 int resource;
31 Mutex mutex;
32
33 ConcurrentThread();
34 int Main();
35 };
36
37 // dummy thread we use to check if the Mutex falsely blcoks if we do a double lock and to avoid that our unit test main thread gets blocked
38 class DummyThread : public Thread {
39 public:
40 int resource;
41
42 DummyThread();
43 int Main();
44 private:
45 Mutex mutex;
46 };
47
48 bool doubleLockSucceeded; // true if testDoubleLock() was successful
49 public:
50 void setUp();
51 void tearDown();
52
53 void testLockAndUnlockBySingleThread();
54 void testLock();
55 void testUnlock();
56 void testDoubleLock();
57 void testDoubleLockStillBlocksConcurrentThread();
58 };
59
60 #endif // __LS_MUTEXTEST_H__

  ViewVC Help
Powered by ViewVC