2 $Id: MessageQueueTestCase.h 383 2002-07-22 09:28:00Z tylerdauwalder $
4 This file defines a set of classes for testing BMessageQueue
10 #ifndef MessageQueueTestCase_H
11 #define MessageQueueTestCase_H
17 #include <MessageQueue.h>
18 #include "ThreadedTestCase.h"
22 // The SafetyLock class is a utility class for use in actual tests
23 // of the BMessageQueue interfaces. It is used to make sure that if the
24 // test fails and an exception is thrown with the lock held on the message
25 // queue, that lock will be released. Without this SafetyLock, there
26 // could be deadlocks if one thread in a test has a failure while holding
27 // the lock. It should be used like so:
29 // void myTestClass::myTestFunc(void)
31 // SafetyLock mySafetyLock(theMessageQueue);
32 // ...perform tests without worrying about holding the lock on assert...
37 BMessageQueue
*theMessageQueue
;
40 SafetyLock(BMessageQueue
*aMessageQueue
) {theMessageQueue
= aMessageQueue
;}
41 virtual ~SafetyLock() {if (theMessageQueue
!= NULL
) theMessageQueue
->Unlock(); };
46 // The testMessageClass is used to count the number of messages that are
47 // deleted. This is used to check that all messages on the message queue
48 // were properly free'ed.
51 class testMessageClass
: public BMessage
54 static int messageDestructorCount
;
55 virtual ~testMessageClass() { messageDestructorCount
++; };
56 testMessageClass(int what
) : BMessage(what
) { };
60 class MessageQueueTestCase
: public BThreadedTestCase
{
66 BMessageQueue
*theMessageQueue
;
68 void AddMessage(BMessage
*message
);
69 void RemoveMessage(BMessage
*message
);
70 BMessage
*NextMessage(void);
71 BMessage
*FindMessage(uint32 what
, int index
);
73 void CheckQueueAgainstList(void);
76 MessageQueueTestCase(std::string
);
77 virtual ~MessageQueueTestCase();