1 /* 2 $Id: AddMessageTest1.cpp 383 2002-07-22 09:28:00Z tylerdauwalder $ 3 4 This file implements the first test for the Haiku BMessageQueue code. 5 It tests the Construction, Destruction, Add Message 1, Count Messages, 6 Is Empty and Find Message 1 use cases. It does so by doing the following: 7 - checks that the queue is empty according to IsEmpty() and CountMessages() 8 - adds 10000 messages to the queue and a BList 9 - as each is added, checks that IsEmpty() is false and CountMessages() 10 returns what is expected 11 - the BList contents is compared to the queue contents (uses FindMessage()) 12 - the number of BMessages destructed is checked, no messages should have been 13 deleted so far. 14 - the queue is deleted 15 - the number of BMessages destructed should now be 10000 16 17 */ 18 19 20 #include "AddMessageTest1.h" 21 22 #include <assert.h> 23 24 #include <Message.h> 25 #include <MessageQueue.h> 26 27 #include "ThreadedTestCaller.h" 28 29 30 /* 31 * Method: AddMessageTest1::AddMessageTest1() 32 * Descr: This is the constructor for this class. 33 */ 34 35 36 AddMessageTest1::AddMessageTest1(std::string name) : 37 MessageQueueTestCase(name) 38 { 39 } 40 41 42 /* 43 * Method: AddMessageTest1::~AddMessageTest1() 44 * Descr: This is the destructor for this class. 45 */ 46 47 48 AddMessageTest1::~AddMessageTest1() 49 { 50 } 51 52 53 /* 54 * Method: AddMessageTest1::setUp() 55 * Descr: This member function is called just prior to running the test. 56 * It resets the destructor count for testMessageClass. 57 */ 58 59 60 void AddMessageTest1::setUp(void) 61 { 62 testMessageClass::messageDestructorCount = 0; 63 } 64 65 66 /* 67 * Method: AddMessageTest1::PerformTest() 68 * Descr: This member function performs this test. It adds 69 * 10000 messages to the message queue and confirms that 70 * the queue contains the right messages. Then it confirms 71 * that all 10000 messages are deleted when the message 72 * queue is deleted. 73 */ 74 75 76 void AddMessageTest1::PerformTest(void) 77 { 78 assert(theMessageQueue->IsEmpty()); 79 assert(theMessageQueue->CountMessages() == 0); 80 81 int i; 82 for(i = 0; i < 10000; i++) { 83 if (i % (10000 / 10) == 0) 84 NextSubTest(); 85 BMessage *theMessage = new testMessageClass(i); 86 AddMessage(theMessage); 87 assert(!theMessageQueue->IsEmpty()); 88 assert(theMessageQueue->CountMessages() == i + 1); 89 } 90 91 NextSubTest(); 92 CheckQueueAgainstList(); 93 94 assert(testMessageClass::messageDestructorCount == 0); 95 delete theMessageQueue; 96 theMessageQueue = NULL; 97 NextSubTest(); 98 assert(testMessageClass::messageDestructorCount == 10000); 99 } 100 101 102 /* 103 * Method: AddMessageTest1::suite() 104 * Descr: This static member function returns a test caller for performing 105 * all combinations of "AddMessageTest1". The test 106 * is created as a ThreadedTestCase (typedef'd as 107 * AddMessageTest1Caller) with only one thread. 108 */ 109 110 Test *AddMessageTest1::suite(void) 111 { 112 typedef BThreadedTestCaller<AddMessageTest1> 113 AddMessageTest1Caller; 114 115 AddMessageTest1 *theTest = new AddMessageTest1(""); 116 AddMessageTest1Caller *testCaller = new AddMessageTest1Caller("BMessageQueue::Add Message Test #1", theTest); 117 testCaller->addThread("A", &AddMessageTest1::PerformTest); 118 119 return(testCaller); 120 } 121 122 123