1/*
2	$Id: LockerTestCase.h 301 2002-07-18 05:32:00Z tylerdauwalder $
3
4	This file defines a couple of common classes for testing BLocker
5	functionality.
6
7	*/
8
9
10#ifndef LockerTestCase_H
11#define LockerTestCase_H
12
13#include <ThreadedTestCase.h>
14#include <string>
15
16class BLocker;
17
18//
19// The SafetyLock class is a utility class for use in actual tests
20// of the BLocker interfaces.  It is used to make sure that if the
21// test fails and an exception is thrown with the lock held, that
22// lock will be released.  Without this SafetyLock, there could be
23// deadlocks if one thread in a test has a failure while holding the
24// lock.  It should be used like so:
25//
26// void myTestClass::myTestFunc(void)
27// {
28//   SafetyLock mySafetyLock(theLocker);
29//   ...perform tests without worrying about holding the lock on assert...
30//
31
32class SafetyLock {
33private:
34	BLocker *theLocker;
35
36public:
37	SafetyLock(BLocker *aLock) {theLocker = aLock;};
38	virtual ~SafetyLock() {if (theLocker != NULL) theLocker->Unlock(); };
39};
40
41
42//
43// All BLocker tests should be derived from the LockerTestCase class.
44// This class provides a BLocker allocated on construction to the
45// derived class.  This BLocker is the member "theLocker".  Also,
46// there is a member function called CheckLock() which ensures that
47// the lock is sane.
48//
49
50class LockerTestCase : public BThreadedTestCase {
51
52protected:
53	BLocker *theLocker;
54
55	void CheckLock(int);
56
57public:
58	LockerTestCase(std::string name, bool);
59	virtual ~LockerTestCase();
60};
61
62#endif
63
64
65
66