146231beeSjrand /* 2*571d840aSOliver Tappe $Id: DeskbarGetItemTest.cpp 1236 2002-09-28 07:27:00Z shatty $ 346231beeSjrand 446231beeSjrand This file implements tests for the following use cases of BDeskbar: 546231beeSjrand - Count Items 646231beeSjrand - Has Item 1 746231beeSjrand - Has Item 2 846231beeSjrand - Get Item Info 1 946231beeSjrand - Get Item Info 2 1046231beeSjrand 1146231beeSjrand */ 1246231beeSjrand 1346231beeSjrand 1446231beeSjrand #include "DeskbarGetItemTest.h" 1546231beeSjrand #include <Deskbar.h> 1646231beeSjrand 1746231beeSjrand 1846231beeSjrand /* 1946231beeSjrand * Method: DeskbarGetItemTest::DeskbarGetItemTest() 2046231beeSjrand * Descr: This is the constructor for this class. 2146231beeSjrand */ 2246231beeSjrand 2346231beeSjrand 2446231beeSjrand DeskbarGetItemTest::DeskbarGetItemTest(std::string name) : 2546231beeSjrand TestCase(name) 2646231beeSjrand { 2746231beeSjrand } 2846231beeSjrand 2946231beeSjrand 3046231beeSjrand /* 3146231beeSjrand * Method: DeskbarGetItemTest::~DeskbarGetItemTest() 3246231beeSjrand * Descr: This is the destructor for this class. 3346231beeSjrand */ 3446231beeSjrand 3546231beeSjrand 3646231beeSjrand DeskbarGetItemTest::~DeskbarGetItemTest() 3746231beeSjrand { 3846231beeSjrand } 3946231beeSjrand 4046231beeSjrand 4146231beeSjrand /* 4246231beeSjrand * Method: DeskbarGetItemTest::PerformTest() 437f3de5c3Sjrand * Descr: This member function iterates over all of the items in the 447f3de5c3Sjrand * deskbar shelf and gets information about each item and confirms 457f3de5c3Sjrand * that all of the information is self-consistent. 4646231beeSjrand */ 4746231beeSjrand 4846231beeSjrand 4946231beeSjrand void DeskbarGetItemTest::PerformTest(void) 5046231beeSjrand { 5146231beeSjrand BDeskbar myDeskbar; 5246231beeSjrand 5346231beeSjrand int32 itemCount = myDeskbar.CountItems(); 5446231beeSjrand assert(itemCount >= 0); 5546231beeSjrand 5646231beeSjrand 5746231beeSjrand int32 id=0; 5846231beeSjrand int32 lastFoundId = -1; 5946231beeSjrand char buffer[1024]; 6046231beeSjrand const char *name = buffer; 6146231beeSjrand 6246231beeSjrand assert(!myDeskbar.HasItem("NameThatDoesNotExistWeHope!!")); 6346231beeSjrand assert(myDeskbar.GetItemInfo("NameThatDoesNotExistWeHope!!", &id) == B_NAME_NOT_FOUND); 6446231beeSjrand 6546231beeSjrand for(id = 0; ((id < 10000) && (itemCount > 0)); id++) { 6646231beeSjrand int32 tmpId; 6746231beeSjrand 6846231beeSjrand if (myDeskbar.HasItem(id)) { 6946231beeSjrand itemCount--; 7046231beeSjrand 71b5b2bdaeSjrand /* In Be's implementation, if the char * points to NULL, it 72b5b2bdaeSjrand returns B_BAD_VALUE. However, no matter what it points to 73b5b2bdaeSjrand before you start, it is changed by the call to GetItemInfo(). 74b5b2bdaeSjrand So, if it points to allocated memory, there is a good chance 75b5b2bdaeSjrand for a leak. I would argue that Be should return B_BAD_VALUE 76b5b2bdaeSjrand if it points to non-NULL. The OpenBeOS implementation does 77b5b2bdaeSjrand not return B_BAD_VALUE in this case so this assert would fail 78b5b2bdaeSjrand from OpenBeOS. However, this is considered to be an acceptable 79b5b2bdaeSjrand deviation from Be's implementation. 8046231beeSjrand name = NULL; 81b5b2bdaeSjrand assert(myDeskbar.GetItemInfo(id, &name) == B_BAD_VALUE); */ 8246231beeSjrand 8346231beeSjrand name = buffer; 8446231beeSjrand assert(myDeskbar.GetItemInfo(id, &name) == B_OK); 8546231beeSjrand 8646231beeSjrand assert(name != buffer); 8746231beeSjrand assert(myDeskbar.HasItem(name)); 8846231beeSjrand assert(myDeskbar.GetItemInfo(name, &tmpId) == B_OK); 8946231beeSjrand delete[] name; 9046231beeSjrand name = buffer; 9146231beeSjrand assert(tmpId == id); 9246231beeSjrand lastFoundId = id; 9346231beeSjrand } else { 9446231beeSjrand assert(myDeskbar.GetItemInfo(id, &name) == B_NAME_NOT_FOUND); 9546231beeSjrand assert(name == buffer); 9646231beeSjrand } 9746231beeSjrand } 9846231beeSjrand assert(itemCount == 0); 9946231beeSjrand if (lastFoundId >= 0) { 10046231beeSjrand for(id = lastFoundId + 1; id < lastFoundId + 200; id++) { 10146231beeSjrand assert(!myDeskbar.HasItem(id)); 10246231beeSjrand assert(myDeskbar.GetItemInfo(id, &name) == B_NAME_NOT_FOUND); 10346231beeSjrand assert(name == buffer); 10446231beeSjrand } 10546231beeSjrand } 10646231beeSjrand } 10746231beeSjrand 10846231beeSjrand 10946231beeSjrand /* 11046231beeSjrand * Method: PropertyConstructionTest::suite() 11146231beeSjrand * Descr: This static member function returns a test caller for performing 11246231beeSjrand * all combinations of "DeskbarGetItemTest". 11346231beeSjrand */ 11446231beeSjrand 11546231beeSjrand Test *DeskbarGetItemTest::suite(void) 11646231beeSjrand { 11746231beeSjrand typedef CppUnit::TestCaller<DeskbarGetItemTest> 11846231beeSjrand DeskbarGetItemTestCaller; 11946231beeSjrand 12046231beeSjrand return(new DeskbarGetItemTestCaller("BDeskbar::Get Item Test", &DeskbarGetItemTest::PerformTest)); 12146231beeSjrand } 122