Adding final test for BDeskbar which tests adding and removing items from the deskbar.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1113 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
jrand 2002-09-22 05:27:25 +00:00
parent 8271683e44
commit 5025cfce1b
4 changed files with 174 additions and 0 deletions

View File

@ -20,6 +20,7 @@ CommonTestLib libinterfacetest.so
DeskbarTest.cpp
DeskbarGetItemTest.cpp
DeskbarLocationTest.cpp
DeskbarAddItemTest.cpp
: <boot!home!config!lib>libopenbeos.so
be stdc++.r4

View File

@ -0,0 +1,139 @@
/*
$Id: DeskbarAddItemTest.cpp,v 1.1 2002/09/22 05:27:25 jrand Exp $
This file implements tests for the following use cases of BDeskbar:
- Add Item 1
- Add Item 2
- Remove Item 1
- Remove Item 2
*/
#include "DeskbarAddItemTest.h"
#include <Deskbar.h>
#include <View.h>
#include <Application.h>
#include <Entry.h>
#include <image.h>
const char *appName = "application/x-vnd.jsr-additemtest";
const char *pulsePath = "/boot/apps/Pulse";
/*
* Method: DeskbarAddItemTest::DeskbarAddItemTest()
* Descr: This is the constructor for this class.
*/
DeskbarAddItemTest::DeskbarAddItemTest(std::string name) :
TestCase(name)
{
}
/*
* Method: DeskbarAddItemTest::~DeskbarAddItemTest()
* Descr: This is the destructor for this class.
*/
DeskbarAddItemTest::~DeskbarAddItemTest()
{
}
/*
* Method: DeskbarAddItemTest::PerformTest()
* Descr: This member function tests the ability of the BDeskbar class
* when adding and removing an item from the shelf. It does so by
* adding and removing the pulse item. It is a good candidate
* it can be added both ways (Add Item 1 and Add Item 2).
*
* The code does the following:
* - loads the code for Pulse as an add-on
* - gets the "instantiate_deskbar_item()" function from the add-on
* - calls this function to get a pointer to a BView which can be
* used to test Add Item 1 and in order to get the name of the
* item so it can be removed etc.
* - it gets an entry_ref to the Pulse app in order to test Add
* Item 2
* - it stores in a boolean whether Pulse is in the deskbar at the
* start of the test in order to restore the users config when
* the test completes
* - it adds the item each different way and tests that it exists
* - between each, it removes the item and shows that it has
* been removed
*/
void DeskbarAddItemTest::PerformTest(void)
{
BApplication theApp(appName);
BView *(*funcPtr)(void);
image_id theImage;
assert((theImage = load_add_on(pulsePath)) != B_ERROR);
assert(get_image_symbol(theImage, "instantiate_deskbar_item",
B_SYMBOL_TYPE_TEXT, (void **)&funcPtr) == B_OK);
BView *theView = funcPtr();
assert(theView != NULL);
BEntry entry(pulsePath);
entry_ref ref;
assert(entry.GetRef(&ref) == B_OK);
int32 theId1, theId2;
BDeskbar myDeskbar;
bool restorePulse = myDeskbar.HasItem(theView->Name());
assert(myDeskbar.RemoveItem(theView->Name()) == B_OK);
assert(!myDeskbar.HasItem(theView->Name()));
assert(myDeskbar.AddItem(theView, &theId1) == B_OK);
assert(myDeskbar.HasItem(theView->Name()));
assert(myDeskbar.GetItemInfo(theView->Name(), &theId2) == B_OK);
assert(theId1 == theId2);
assert(myDeskbar.RemoveItem(theView->Name()) == B_OK);
assert(!myDeskbar.HasItem(theView->Name()));
assert(myDeskbar.AddItem(theView) == B_OK);
assert(myDeskbar.HasItem(theView->Name()));
assert(myDeskbar.RemoveItem(theView->Name()) == B_OK);
assert(!myDeskbar.HasItem(theView->Name()));
assert(myDeskbar.AddItem(&ref, &theId1) == B_OK);
assert(myDeskbar.HasItem(theView->Name()));
assert(myDeskbar.GetItemInfo(theView->Name(), &theId2) == B_OK);
assert(theId1 == theId2);
assert(myDeskbar.RemoveItem(theView->Name()) == B_OK);
assert(!myDeskbar.HasItem(theView->Name()));
assert(myDeskbar.AddItem(&ref) == B_OK);
assert(myDeskbar.HasItem(theView->Name()));
if (!restorePulse) {
assert(myDeskbar.RemoveItem(theView->Name()) == B_OK);
assert(!myDeskbar.HasItem(theView->Name()));
}
}
/*
* Method: PropertyConstructionTest::suite()
* Descr: This static member function returns a test caller for performing
* all combinations of "DeskbarAddItemTest".
*/
Test *DeskbarAddItemTest::suite(void)
{
typedef CppUnit::TestCaller<DeskbarAddItemTest>
DeskbarAddItemTestCaller;
return(new DeskbarAddItemTestCaller("BDeskbar::Add Item Test", &DeskbarAddItemTest::PerformTest));
}

View File

@ -0,0 +1,32 @@
/*
$Id: DeskbarAddItemTest.h,v 1.1 2002/09/22 05:27:25 jrand Exp $
This file defines a class for performing a test of BDeskbar
functionality.
*/
#ifndef DeskbarAddItemTest_H
#define DeskbarAddItemTest_H
#include "../common.h"
#include <Deskbar.h>
class DeskbarAddItemTest :
public TestCase {
private:
protected:
public:
static Test *suite(void);
void PerformTest(void);
DeskbarAddItemTest(std::string name = "");
virtual ~DeskbarAddItemTest();
};
#endif

View File

@ -1,6 +1,7 @@
#include "../common.h"
#include "DeskbarGetItemTest.h"
#include "DeskbarLocationTest.h"
#include "DeskbarAddItemTest.h"
Test *DeskbarTestSuite()
{
@ -8,6 +9,7 @@ Test *DeskbarTestSuite()
testSuite->addTest(DeskbarGetItemTest::suite());
testSuite->addTest(DeskbarLocationTest::suite());
testSuite->addTest(DeskbarAddItemTest::suite());
return(testSuite);
}