1 /* 2 $Id: DeskbarAddItemTest.cpp,v 1.2 2002/09/28 07:27:00 shatty Exp $ 3 4 This file implements tests for the following use cases of BDeskbar: 5 - Add Item 1 6 - Add Item 2 7 - Remove Item 1 8 - Remove Item 2 9 10 */ 11 12 13 #include "DeskbarAddItemTest.h" 14 #include <Deskbar.h> 15 #include <View.h> 16 #include <Application.h> 17 #include <Entry.h> 18 #include <image.h> 19 20 21 const char *appName = "application/x-vnd.jsr-additemtest"; 22 const char *pulsePath = "/boot/apps/Pulse"; 23 24 25 /* 26 * Method: DeskbarAddItemTest::DeskbarAddItemTest() 27 * Descr: This is the constructor for this class. 28 */ 29 30 31 DeskbarAddItemTest::DeskbarAddItemTest(std::string name) : 32 TestCase(name) 33 { 34 } 35 36 37 /* 38 * Method: DeskbarAddItemTest::~DeskbarAddItemTest() 39 * Descr: This is the destructor for this class. 40 */ 41 42 43 DeskbarAddItemTest::~DeskbarAddItemTest() 44 { 45 } 46 47 48 /* 49 * Method: DeskbarAddItemTest::PerformTest() 50 * Descr: This member function tests the ability of the BDeskbar class 51 * when adding and removing an item from the shelf. It does so by 52 * adding and removing the pulse item. It is a good candidate 53 * it can be added both ways (Add Item 1 and Add Item 2). 54 * 55 * The code does the following: 56 * - loads the code for Pulse as an add-on 57 * - gets the "instantiate_deskbar_item()" function from the add-on 58 * - calls this function to get a pointer to a BView which can be 59 * used to test Add Item 1 and in order to get the name of the 60 * item so it can be removed etc. 61 * - it gets an entry_ref to the Pulse app in order to test Add 62 * Item 2 63 * - it stores in a boolean whether Pulse is in the deskbar at the 64 * start of the test in order to restore the users config when 65 * the test completes 66 * - it adds the item each different way and tests that it exists 67 * - between each, it removes the item and shows that it has 68 * been removed 69 */ 70 71 72 void DeskbarAddItemTest::PerformTest(void) 73 { 74 BApplication theApp(appName); 75 76 BView *(*funcPtr)(void); 77 image_id theImage; 78 assert((theImage = load_add_on(pulsePath)) != B_ERROR); 79 assert(get_image_symbol(theImage, "instantiate_deskbar_item", 80 B_SYMBOL_TYPE_TEXT, (void **)&funcPtr) == B_OK); 81 BView *theView = funcPtr(); 82 assert(theView != NULL); 83 84 BEntry entry(pulsePath); 85 entry_ref ref; 86 assert(entry.GetRef(&ref) == B_OK); 87 88 int32 theId1, theId2; 89 BDeskbar myDeskbar; 90 bool restorePulse = myDeskbar.HasItem(theView->Name()); 91 92 assert(myDeskbar.RemoveItem(theView->Name()) == B_OK); 93 assert(!myDeskbar.HasItem(theView->Name())); 94 95 assert(myDeskbar.AddItem(theView, &theId1) == B_OK); 96 assert(myDeskbar.HasItem(theView->Name())); 97 assert(myDeskbar.GetItemInfo(theView->Name(), &theId2) == B_OK); 98 assert(theId1 == theId2); 99 100 assert(myDeskbar.RemoveItem(theView->Name()) == B_OK); 101 assert(!myDeskbar.HasItem(theView->Name())); 102 103 assert(myDeskbar.AddItem(theView) == B_OK); 104 assert(myDeskbar.HasItem(theView->Name())); 105 106 assert(myDeskbar.RemoveItem(theView->Name()) == B_OK); 107 assert(!myDeskbar.HasItem(theView->Name())); 108 109 assert(myDeskbar.AddItem(&ref, &theId1) == B_OK); 110 assert(myDeskbar.HasItem(theView->Name())); 111 assert(myDeskbar.GetItemInfo(theView->Name(), &theId2) == B_OK); 112 assert(theId1 == theId2); 113 114 assert(myDeskbar.RemoveItem(theView->Name()) == B_OK); 115 assert(!myDeskbar.HasItem(theView->Name())); 116 117 assert(myDeskbar.AddItem(&ref) == B_OK); 118 assert(myDeskbar.HasItem(theView->Name())); 119 120 if (!restorePulse) { 121 assert(myDeskbar.RemoveItem(theView->Name()) == B_OK); 122 assert(!myDeskbar.HasItem(theView->Name())); 123 } 124 } 125 126 127 /* 128 * Method: PropertyConstructionTest::suite() 129 * Descr: This static member function returns a test caller for performing 130 * all combinations of "DeskbarAddItemTest". 131 */ 132 133 Test *DeskbarAddItemTest::suite(void) 134 { 135 typedef CppUnit::TestCaller<DeskbarAddItemTest> 136 DeskbarAddItemTestCaller; 137 138 return(new DeskbarAddItemTestCaller("BDeskbar::Add Item Test", &DeskbarAddItemTest::PerformTest)); 139 } 140