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_SUITE_END(); |
24 |
|
25 |
private: |
26 |
class ConcurrentThread : public Thread { |
27 |
public: |
28 |
int resource; |
29 |
Mutex mutex; |
30 |
|
31 |
ConcurrentThread(); |
32 |
int Main(); |
33 |
}; |
34 |
public: |
35 |
void setUp(); |
36 |
void tearDown(); |
37 |
|
38 |
void testLockAndUnlockBySingleThread(); |
39 |
void testLock(); |
40 |
void testUnlock(); |
41 |
void testDoubleLock(); |
42 |
}; |
43 |
|
44 |
#endif // __LS_MUTEXTEST_H__ |