xref: /haiku/src/tests/kits/interface/bdeskbar/DeskbarGetItemTest.cpp (revision 77aa0e2a5ef8e6d00570dbeb7a12aeb23e9e5cf0)
146231beeSjrand /*
2571d840aSOliver 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 
17*77aa0e2aSOliver Tappe #include <assert.h>
18*77aa0e2aSOliver Tappe 
1946231beeSjrand 
2046231beeSjrand /*
2146231beeSjrand  *  Method:  DeskbarGetItemTest::DeskbarGetItemTest()
2246231beeSjrand  *   Descr:  This is the constructor for this class.
2346231beeSjrand  */
2446231beeSjrand 
2546231beeSjrand 
2646231beeSjrand 	DeskbarGetItemTest::DeskbarGetItemTest(std::string name) :
2746231beeSjrand 		TestCase(name)
2846231beeSjrand {
2946231beeSjrand 	}
3046231beeSjrand 
3146231beeSjrand 
3246231beeSjrand /*
3346231beeSjrand  *  Method:  DeskbarGetItemTest::~DeskbarGetItemTest()
3446231beeSjrand  *   Descr:  This is the destructor for this class.
3546231beeSjrand  */
3646231beeSjrand 
3746231beeSjrand 
3846231beeSjrand 	DeskbarGetItemTest::~DeskbarGetItemTest()
3946231beeSjrand {
4046231beeSjrand 	}
4146231beeSjrand 
4246231beeSjrand 
4346231beeSjrand /*
4446231beeSjrand  *  Method:  DeskbarGetItemTest::PerformTest()
457f3de5c3Sjrand  *   Descr:  This member function iterates over all of the items in the
467f3de5c3Sjrand  *           deskbar shelf and gets information about each item and confirms
477f3de5c3Sjrand  *           that all of the information is self-consistent.
4846231beeSjrand  */
4946231beeSjrand 
5046231beeSjrand 
5146231beeSjrand 	void DeskbarGetItemTest::PerformTest(void)
5246231beeSjrand {
5346231beeSjrand 	BDeskbar myDeskbar;
5446231beeSjrand 
5546231beeSjrand 	int32 itemCount = myDeskbar.CountItems();
5646231beeSjrand 	assert(itemCount >= 0);
5746231beeSjrand 
5846231beeSjrand 
5946231beeSjrand 	int32 id=0;
6046231beeSjrand 	int32 lastFoundId = -1;
6146231beeSjrand 	char buffer[1024];
6246231beeSjrand 	const char *name = buffer;
6346231beeSjrand 
6446231beeSjrand 	assert(!myDeskbar.HasItem("NameThatDoesNotExistWeHope!!"));
6546231beeSjrand 	assert(myDeskbar.GetItemInfo("NameThatDoesNotExistWeHope!!", &id) == B_NAME_NOT_FOUND);
6646231beeSjrand 
6746231beeSjrand 	for(id = 0; ((id < 10000) && (itemCount > 0)); id++) {
6846231beeSjrand 		int32 tmpId;
6946231beeSjrand 
7046231beeSjrand 		if (myDeskbar.HasItem(id)) {
7146231beeSjrand 			itemCount--;
7246231beeSjrand 
73b5b2bdaeSjrand 			/* In Be's implementation, if the char * points to NULL, it
74b5b2bdaeSjrand 			   returns B_BAD_VALUE.  However, no matter what it points to
75b5b2bdaeSjrand 			   before you start, it is changed by the call to GetItemInfo().
76b5b2bdaeSjrand 			   So, if it points to allocated memory, there is a good chance
77b5b2bdaeSjrand 			   for a leak.  I would argue that Be should return B_BAD_VALUE
78b5b2bdaeSjrand 			   if it points to non-NULL.  The OpenBeOS implementation does
79b5b2bdaeSjrand 			   not return B_BAD_VALUE in this case so this assert would fail
80b5b2bdaeSjrand 			   from OpenBeOS.  However, this is considered to be an acceptable
81b5b2bdaeSjrand 			   deviation from Be's implementation.
8246231beeSjrand 			name = NULL;
83b5b2bdaeSjrand 			assert(myDeskbar.GetItemInfo(id, &name) == B_BAD_VALUE); */
8446231beeSjrand 
8546231beeSjrand 			name = buffer;
8646231beeSjrand 			assert(myDeskbar.GetItemInfo(id, &name) == B_OK);
8746231beeSjrand 
8846231beeSjrand 			assert(name != buffer);
8946231beeSjrand 			assert(myDeskbar.HasItem(name));
9046231beeSjrand 			assert(myDeskbar.GetItemInfo(name, &tmpId) == B_OK);
9146231beeSjrand 			delete[] name;
9246231beeSjrand 			name = buffer;
9346231beeSjrand 			assert(tmpId == id);
9446231beeSjrand 			lastFoundId = id;
9546231beeSjrand 		} else {
9646231beeSjrand 			assert(myDeskbar.GetItemInfo(id, &name) == B_NAME_NOT_FOUND);
9746231beeSjrand 			assert(name == buffer);
9846231beeSjrand 		}
9946231beeSjrand 	}
10046231beeSjrand 	assert(itemCount == 0);
10146231beeSjrand 	if (lastFoundId >= 0) {
10246231beeSjrand 		for(id = lastFoundId + 1; id < lastFoundId + 200; id++) {
10346231beeSjrand 			assert(!myDeskbar.HasItem(id));
10446231beeSjrand 			assert(myDeskbar.GetItemInfo(id, &name) == B_NAME_NOT_FOUND);
10546231beeSjrand 			assert(name == buffer);
10646231beeSjrand 		}
10746231beeSjrand 	}
10846231beeSjrand }
10946231beeSjrand 
11046231beeSjrand 
11146231beeSjrand /*
11246231beeSjrand  *  Method:  PropertyConstructionTest::suite()
11346231beeSjrand  *   Descr:  This static member function returns a test caller for performing
11446231beeSjrand  *           all combinations of "DeskbarGetItemTest".
11546231beeSjrand  */
11646231beeSjrand 
11746231beeSjrand  Test *DeskbarGetItemTest::suite(void)
11846231beeSjrand {
11946231beeSjrand 	typedef CppUnit::TestCaller<DeskbarGetItemTest>
12046231beeSjrand 		DeskbarGetItemTestCaller;
12146231beeSjrand 
12246231beeSjrand 	return(new DeskbarGetItemTestCaller("BDeskbar::Get Item Test", &DeskbarGetItemTest::PerformTest));
12346231beeSjrand 	}
124