xref: /haiku/src/tests/kits/interface/bdeskbar/DeskbarGetItemTest.cpp (revision 7f3de5c3628a5f11246ed040178417d277298536)
146231beeSjrand /*
2*7f3de5c3Sjrand 	$Id: DeskbarGetItemTest.cpp,v 1.2 2002/09/13 03:51:09 jrand Exp $
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()
43*7f3de5c3Sjrand  *   Descr:  This member function iterates over all of the items in the
44*7f3de5c3Sjrand  *           deskbar shelf and gets information about each item and confirms
45*7f3de5c3Sjrand  *           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 
7146231beeSjrand 			name = NULL;
7246231beeSjrand 			assert(myDeskbar.GetItemInfo(id, &name) == B_BAD_VALUE);
7346231beeSjrand 
7446231beeSjrand 			name = buffer;
7546231beeSjrand 			assert(myDeskbar.GetItemInfo(id, &name) == B_OK);
7646231beeSjrand 
7746231beeSjrand 			assert(name != buffer);
7846231beeSjrand 			assert(myDeskbar.HasItem(name));
7946231beeSjrand 			assert(myDeskbar.GetItemInfo(name, &tmpId) == B_OK);
8046231beeSjrand 			delete[] name;
8146231beeSjrand 			name = buffer;
8246231beeSjrand 			assert(tmpId == id);
8346231beeSjrand 			lastFoundId = id;
8446231beeSjrand 		} else {
8546231beeSjrand 			assert(myDeskbar.GetItemInfo(id, &name) == B_NAME_NOT_FOUND);
8646231beeSjrand 			assert(name == buffer);
8746231beeSjrand 		}
8846231beeSjrand 	}
8946231beeSjrand 	assert(itemCount == 0);
9046231beeSjrand 	if (lastFoundId >= 0) {
9146231beeSjrand 		for(id = lastFoundId + 1; id < lastFoundId + 200; id++) {
9246231beeSjrand 			assert(!myDeskbar.HasItem(id));
9346231beeSjrand 			assert(myDeskbar.GetItemInfo(id, &name) == B_NAME_NOT_FOUND);
9446231beeSjrand 			assert(name == buffer);
9546231beeSjrand 		}
9646231beeSjrand 	}
9746231beeSjrand }
9846231beeSjrand 
9946231beeSjrand 
10046231beeSjrand /*
10146231beeSjrand  *  Method:  PropertyConstructionTest::suite()
10246231beeSjrand  *   Descr:  This static member function returns a test caller for performing
10346231beeSjrand  *           all combinations of "DeskbarGetItemTest".
10446231beeSjrand  */
10546231beeSjrand 
10646231beeSjrand  Test *DeskbarGetItemTest::suite(void)
10746231beeSjrand {
10846231beeSjrand 	typedef CppUnit::TestCaller<DeskbarGetItemTest>
10946231beeSjrand 		DeskbarGetItemTestCaller;
11046231beeSjrand 
11146231beeSjrand 	return(new DeskbarGetItemTestCaller("BDeskbar::Get Item Test", &DeskbarGetItemTest::PerformTest));
11246231beeSjrand 	}