vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / app / bmessagequeue / AddMessageTest2.cpp
blob1c18466b8ac375b64d0d4a074265eec3c290450a
1 /*
2 $Id: AddMessageTest2.cpp 383 2002-07-22 09:28:00Z tylerdauwalder $
4 This file implements the second test for the OpenBeOS BMessageQueue code.
5 It tests the Add Message 2 use case. It does so by doing the following:
6 - creates 4 BMessages
7 - it adds them to the queue and a list
8 - it checks the queue against the list
9 - it adds the second one to the queue and the list again
10 - it checks the queue against the list again (expecting an error)
15 #include "ThreadedTestCaller.h"
16 #include "AddMessageTest2.h"
17 #include <Message.h>
18 #include <MessageQueue.h>
19 #include "MessageQueue.h"
23 * Method: AddMessageTest2::AddMessageTest2()
24 * Descr: This is the constructor for this class.
28 AddMessageTest2::AddMessageTest2(std::string name) :
29 MessageQueueTestCase(name)
35 * Method: AddMessageTest2::~AddMessageTest2()
36 * Descr: This is the destructor for this class.
40 AddMessageTest2::~AddMessageTest2()
46 * Method: AddMessageTest2::PerformTest()
47 * Descr: This member function performs this test. It adds
48 * 4 messages to the message queue and confirms that
49 * the queue contains the right messages. Then it re-adds
50 * the second message again. It checks the queue against
51 * the list and expects to find a difference. Then, it
52 * checks each element on the queue one by one.
56 void AddMessageTest2::PerformTest(void)
58 NextSubTest();
59 BMessage *firstMessage = new BMessage(1);
60 BMessage *secondMessage = new BMessage(2);
61 BMessage *thirdMessage = new BMessage(3);
62 BMessage *fourthMessage = new BMessage(4);
64 AddMessage(firstMessage);
65 AddMessage(secondMessage);
66 AddMessage(thirdMessage);
67 AddMessage(fourthMessage);
69 NextSubTest();
70 CheckQueueAgainstList();
72 AddMessage(secondMessage);
74 // Re-adding a message to the message queue will result in the list
75 // not matching the message queue. Therefore, we expect an exception
76 // to be raised. An error occurs if it doesn't get raised.
77 bool exceptionRaised = false;
78 try {
79 CheckQueueAgainstList();
81 catch (CppUnit::Exception e) {
82 exceptionRaised = true;
84 CPPUNIT_ASSERT(exceptionRaised);
86 NextSubTest();
87 CPPUNIT_ASSERT(theMessageQueue->FindMessage((int32)0) == firstMessage);
88 CPPUNIT_ASSERT(theMessageQueue->FindMessage((int32)1) == secondMessage);
89 CPPUNIT_ASSERT(theMessageQueue->FindMessage((int32)2) == NULL);
90 CPPUNIT_ASSERT(theMessageQueue->FindMessage((int32)3) == NULL);
91 CPPUNIT_ASSERT(theMessageQueue->FindMessage((int32)4) == NULL);
96 * Method: AddMessageTest2::suite()
97 * Descr: This static member function returns a test caller for performing
98 * all combinations of "AddMessageTest2". The test
99 * is created as a ThreadedTestCase (typedef'd as
100 * AddMessageTest2Caller) with only one thread.
103 Test *AddMessageTest2::suite(void)
105 typedef BThreadedTestCaller<AddMessageTest2>
106 AddMessageTest2Caller;
107 AddMessageTest2 *theTest = new AddMessageTest2("");
108 AddMessageTest2Caller *testCaller = new AddMessageTest2Caller("BMessageQueue::Add Message Test #2", theTest);
109 testCaller->addThread("A", &AddMessageTest2::PerformTest);
111 return(testCaller);