1 /* 2 $Id: LockerTestCase.h,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $ 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 16 class 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 32 class SafetyLock { 33 private: 34 BLocker *theLocker; 35 36 public: 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 50 class LockerTestCase : public BThreadedTestCase { 51 52 protected: 53 BLocker *theLocker; 54 55 void CheckLock(int); 56 57 public: 58 LockerTestCase(std::string name, bool); 59 virtual ~LockerTestCase(); 60 }; 61 62 #endif 63 64 65 66