xref: /haiku/src/tests/kits/interface/bdeskbar/DeskbarGetItemTest.cpp (revision 46231bee2baef5d992ebe497b1f1ac9c54ae667b)
1*46231beeSjrand /*
2*46231beeSjrand 	$Id: DeskbarGetItemTest.cpp,v 1.1 2002/09/12 05:14:36 jrand Exp $
3*46231beeSjrand 
4*46231beeSjrand 	This file implements tests for the following use cases of BDeskbar:
5*46231beeSjrand 	  - Count Items
6*46231beeSjrand 	  - Has Item 1
7*46231beeSjrand 	  - Has Item 2
8*46231beeSjrand 	  - Get Item Info 1
9*46231beeSjrand 	  - Get Item Info 2
10*46231beeSjrand 
11*46231beeSjrand 	*/
12*46231beeSjrand 
13*46231beeSjrand 
14*46231beeSjrand #include "DeskbarGetItemTest.h"
15*46231beeSjrand #include <Deskbar.h>
16*46231beeSjrand 
17*46231beeSjrand 
18*46231beeSjrand /*
19*46231beeSjrand  *  Method:  DeskbarGetItemTest::DeskbarGetItemTest()
20*46231beeSjrand  *   Descr:  This is the constructor for this class.
21*46231beeSjrand  */
22*46231beeSjrand 
23*46231beeSjrand 
24*46231beeSjrand 	DeskbarGetItemTest::DeskbarGetItemTest(std::string name) :
25*46231beeSjrand 		TestCase(name)
26*46231beeSjrand {
27*46231beeSjrand 	}
28*46231beeSjrand 
29*46231beeSjrand 
30*46231beeSjrand /*
31*46231beeSjrand  *  Method:  DeskbarGetItemTest::~DeskbarGetItemTest()
32*46231beeSjrand  *   Descr:  This is the destructor for this class.
33*46231beeSjrand  */
34*46231beeSjrand 
35*46231beeSjrand 
36*46231beeSjrand 	DeskbarGetItemTest::~DeskbarGetItemTest()
37*46231beeSjrand {
38*46231beeSjrand 	}
39*46231beeSjrand 
40*46231beeSjrand 
41*46231beeSjrand /*
42*46231beeSjrand  *  Method:  DeskbarGetItemTest::PerformTest()
43*46231beeSjrand  *   Descr:  This member function
44*46231beeSjrand  */
45*46231beeSjrand 
46*46231beeSjrand 
47*46231beeSjrand 	void DeskbarGetItemTest::PerformTest(void)
48*46231beeSjrand {
49*46231beeSjrand 	BDeskbar myDeskbar;
50*46231beeSjrand 
51*46231beeSjrand 	int32 itemCount = myDeskbar.CountItems();
52*46231beeSjrand 	assert(itemCount >= 0);
53*46231beeSjrand 
54*46231beeSjrand 
55*46231beeSjrand 	int32 id=0;
56*46231beeSjrand 	int32 lastFoundId = -1;
57*46231beeSjrand 	char buffer[1024];
58*46231beeSjrand 	const char *name = buffer;
59*46231beeSjrand 
60*46231beeSjrand 	assert(!myDeskbar.HasItem("NameThatDoesNotExistWeHope!!"));
61*46231beeSjrand 	assert(myDeskbar.GetItemInfo("NameThatDoesNotExistWeHope!!", &id) == B_NAME_NOT_FOUND);
62*46231beeSjrand 
63*46231beeSjrand 	for(id = 0; ((id < 10000) && (itemCount > 0)); id++) {
64*46231beeSjrand 		int32 tmpId;
65*46231beeSjrand 
66*46231beeSjrand 		if (myDeskbar.HasItem(id)) {
67*46231beeSjrand 			itemCount--;
68*46231beeSjrand 
69*46231beeSjrand 			name = NULL;
70*46231beeSjrand 			assert(myDeskbar.GetItemInfo(id, &name) == B_BAD_VALUE);
71*46231beeSjrand 
72*46231beeSjrand 			name = buffer;
73*46231beeSjrand 			assert(myDeskbar.GetItemInfo(id, &name) == B_OK);
74*46231beeSjrand 
75*46231beeSjrand 			assert(name != buffer);
76*46231beeSjrand 			assert(myDeskbar.HasItem(name));
77*46231beeSjrand 			assert(myDeskbar.GetItemInfo(name, &tmpId) == B_OK);
78*46231beeSjrand 			delete[] name;
79*46231beeSjrand 			name = buffer;
80*46231beeSjrand 			assert(tmpId == id);
81*46231beeSjrand 			lastFoundId = id;
82*46231beeSjrand 		} else {
83*46231beeSjrand 			assert(myDeskbar.GetItemInfo(id, &name) == B_NAME_NOT_FOUND);
84*46231beeSjrand 			assert(name == buffer);
85*46231beeSjrand 		}
86*46231beeSjrand 	}
87*46231beeSjrand 	assert(itemCount == 0);
88*46231beeSjrand 	if (lastFoundId >= 0) {
89*46231beeSjrand 		for(id = lastFoundId + 1; id < lastFoundId + 200; id++) {
90*46231beeSjrand 			assert(!myDeskbar.HasItem(id));
91*46231beeSjrand 			assert(myDeskbar.GetItemInfo(id, &name) == B_NAME_NOT_FOUND);
92*46231beeSjrand 			assert(name == buffer);
93*46231beeSjrand 		}
94*46231beeSjrand 	}
95*46231beeSjrand }
96*46231beeSjrand 
97*46231beeSjrand 
98*46231beeSjrand /*
99*46231beeSjrand  *  Method:  PropertyConstructionTest::suite()
100*46231beeSjrand  *   Descr:  This static member function returns a test caller for performing
101*46231beeSjrand  *           all combinations of "DeskbarGetItemTest".
102*46231beeSjrand  */
103*46231beeSjrand 
104*46231beeSjrand  Test *DeskbarGetItemTest::suite(void)
105*46231beeSjrand {
106*46231beeSjrand 	typedef CppUnit::TestCaller<DeskbarGetItemTest>
107*46231beeSjrand 		DeskbarGetItemTestCaller;
108*46231beeSjrand 
109*46231beeSjrand 	return(new DeskbarGetItemTestCaller("BDeskbar::Get Item Test", &DeskbarGetItemTest::PerformTest));
110*46231beeSjrand 	}