1 /* 2 $Id: DeskbarGetItemTest.cpp 1236 2002-09-28 07:27:00Z shatty $ 3 4 This file implements tests for the following use cases of BDeskbar: 5 - Count Items 6 - Has Item 1 7 - Has Item 2 8 - Get Item Info 1 9 - Get Item Info 2 10 11 */ 12 13 14 #include "DeskbarGetItemTest.h" 15 #include <Deskbar.h> 16 17 18 /* 19 * Method: DeskbarGetItemTest::DeskbarGetItemTest() 20 * Descr: This is the constructor for this class. 21 */ 22 23 24 DeskbarGetItemTest::DeskbarGetItemTest(std::string name) : 25 TestCase(name) 26 { 27 } 28 29 30 /* 31 * Method: DeskbarGetItemTest::~DeskbarGetItemTest() 32 * Descr: This is the destructor for this class. 33 */ 34 35 36 DeskbarGetItemTest::~DeskbarGetItemTest() 37 { 38 } 39 40 41 /* 42 * Method: DeskbarGetItemTest::PerformTest() 43 * Descr: This member function iterates over all of the items in the 44 * deskbar shelf and gets information about each item and confirms 45 * that all of the information is self-consistent. 46 */ 47 48 49 void DeskbarGetItemTest::PerformTest(void) 50 { 51 BDeskbar myDeskbar; 52 53 int32 itemCount = myDeskbar.CountItems(); 54 assert(itemCount >= 0); 55 56 57 int32 id=0; 58 int32 lastFoundId = -1; 59 char buffer[1024]; 60 const char *name = buffer; 61 62 assert(!myDeskbar.HasItem("NameThatDoesNotExistWeHope!!")); 63 assert(myDeskbar.GetItemInfo("NameThatDoesNotExistWeHope!!", &id) == B_NAME_NOT_FOUND); 64 65 for(id = 0; ((id < 10000) && (itemCount > 0)); id++) { 66 int32 tmpId; 67 68 if (myDeskbar.HasItem(id)) { 69 itemCount--; 70 71 /* In Be's implementation, if the char * points to NULL, it 72 returns B_BAD_VALUE. However, no matter what it points to 73 before you start, it is changed by the call to GetItemInfo(). 74 So, if it points to allocated memory, there is a good chance 75 for a leak. I would argue that Be should return B_BAD_VALUE 76 if it points to non-NULL. The OpenBeOS implementation does 77 not return B_BAD_VALUE in this case so this assert would fail 78 from OpenBeOS. However, this is considered to be an acceptable 79 deviation from Be's implementation. 80 name = NULL; 81 assert(myDeskbar.GetItemInfo(id, &name) == B_BAD_VALUE); */ 82 83 name = buffer; 84 assert(myDeskbar.GetItemInfo(id, &name) == B_OK); 85 86 assert(name != buffer); 87 assert(myDeskbar.HasItem(name)); 88 assert(myDeskbar.GetItemInfo(name, &tmpId) == B_OK); 89 delete[] name; 90 name = buffer; 91 assert(tmpId == id); 92 lastFoundId = id; 93 } else { 94 assert(myDeskbar.GetItemInfo(id, &name) == B_NAME_NOT_FOUND); 95 assert(name == buffer); 96 } 97 } 98 assert(itemCount == 0); 99 if (lastFoundId >= 0) { 100 for(id = lastFoundId + 1; id < lastFoundId + 200; id++) { 101 assert(!myDeskbar.HasItem(id)); 102 assert(myDeskbar.GetItemInfo(id, &name) == B_NAME_NOT_FOUND); 103 assert(name == buffer); 104 } 105 } 106 } 107 108 109 /* 110 * Method: PropertyConstructionTest::suite() 111 * Descr: This static member function returns a test caller for performing 112 * all combinations of "DeskbarGetItemTest". 113 */ 114 115 Test *DeskbarGetItemTest::suite(void) 116 { 117 typedef CppUnit::TestCaller<DeskbarGetItemTest> 118 DeskbarGetItemTestCaller; 119 120 return(new DeskbarGetItemTestCaller("BDeskbar::Get Item Test", &DeskbarGetItemTest::PerformTest)); 121 } 122