1 /* 2 $Id: LockerTestCase.cpp 301 2002-07-18 05:32:00Z tylerdauwalder $ 3 4 This file implements a base class for testing BLocker functionality. 5 6 */ 7 8 9 #include "LockerTestCase.h" 10 #include <Locker.h> 11 12 13 /* 14 * Method: LockerTestCase::LockerTestCase() 15 * Descr: This method is the only constructore for the LockerTestCase 16 * class. It takes a test name and a flag to indicate whether 17 * the locker should be a benaphore or a semaphore. 18 */ 19 20 LockerTestCase(std::string name,bool isBenaphore)21 LockerTestCase::LockerTestCase(std::string name, bool isBenaphore) : 22 BThreadedTestCase(name), theLocker(new BLocker(isBenaphore)) 23 { 24 } 25 26 27 /* 28 * Method: LockerTestCase::~LockerTestCase() 29 * Descr: This method is the destructor for the LockerTestCase class. 30 * It only deallocates the locker allocated in the constructor. 31 */ 32 33 ~LockerTestCase()34 LockerTestCase::~LockerTestCase() 35 { 36 delete theLocker; 37 theLocker = NULL; 38 } 39 40 41 /* 42 * Method: LockerTestCase::CheckLock() 43 * Descr: This method confirms that the lock is currently in a sane 44 * state. If the lock is not sane, then an assertion is 45 * raised. The caller provides the number of times the 46 * thread has successfully acquired the lock. If the caller 47 * indicates that the lock has been acquired one or more times 48 * by the current thread, then the function confirms that. If 49 * the caller indicates the lock has not been acquired 50 * (expectedCount = 0), then it checks to make sure that the 51 * lock is not held by the current thread. If it is, it 52 * raises an assertion. 53 */ 54 CheckLock(int expectedCount)55void LockerTestCase::CheckLock(int expectedCount) 56 { 57 bool isLocked = theLocker->IsLocked(); 58 thread_id actualThread = theLocker->LockingThread(); 59 thread_id expectedThread = find_thread(NULL); 60 int32 actualCount = theLocker->CountLocks(); 61 62 if (expectedCount > 0) { 63 CPPUNIT_ASSERT(isLocked); 64 CPPUNIT_ASSERT(expectedThread == actualThread); 65 CPPUNIT_ASSERT(expectedCount == actualCount); 66 } else { 67 CPPUNIT_ASSERT(!((isLocked) && (actualThread == expectedThread))); 68 } 69 return; 70 } 71 72 73 74 75