vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / app / bmessagequeue / MessageQueueTestCase.h
blob8f333062175b9ad05638867671b560d55e55074b
1 /*
2 $Id: MessageQueueTestCase.h 383 2002-07-22 09:28:00Z tylerdauwalder $
4 This file defines a set of classes for testing BMessageQueue
5 functionality.
7 */
10 #ifndef MessageQueueTestCase_H
11 #define MessageQueueTestCase_H
14 #include <List.h>
15 #include <Locker.h>
16 #include <Message.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)
30 // {
31 // SafetyLock mySafetyLock(theMessageQueue);
32 // ...perform tests without worrying about holding the lock on assert...
35 class SafetyLock {
36 private:
37 BMessageQueue *theMessageQueue;
39 public:
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
53 public:
54 static int messageDestructorCount;
55 virtual ~testMessageClass() { messageDestructorCount++; };
56 testMessageClass(int what) : BMessage(what) { };
60 class MessageQueueTestCase : public BThreadedTestCase {
62 private:
63 BList messageList;
65 protected:
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);
75 public:
76 MessageQueueTestCase(std::string);
77 virtual ~MessageQueueTestCase();
80 #endif