xref: /haiku/src/tests/kits/interface/bdeskbar/DeskbarLocationTest.cpp (revision 77aa0e2a5ef8e6d00570dbeb7a12aeb23e9e5cf0)
1 /*
2 	$Id: DeskbarLocationTest.cpp 1236 2002-09-28 07:27:00Z shatty $
3 
4 	This file implements tests for the following use cases of BDeskbar:
5 	  - Frame
6 	  - Location
7 	  - Is Expanded
8 	  - Set Location
9 	  - Expand
10 
11 	*/
12 
13 
14 #include "DeskbarLocationTest.h"
15 #include <Deskbar.h>
16 #include <InterfaceDefs.h>
17 
18 #include <assert.h>
19 
20 
21 /*
22  *  Method:  DeskbarLocationTest::DeskbarLocationTest()
23  *   Descr:  This is the constructor for this class.
24  */
25 
26 
DeskbarLocationTest(std::string name)27 	DeskbarLocationTest::DeskbarLocationTest(std::string name) :
28 		TestCase(name)
29 {
30 	}
31 
32 
33 /*
34  *  Method:  DeskbarLocationTest::~DeskbarLocationTest()
35  *   Descr:  This is the destructor for this class.
36  */
37 
38 
~DeskbarLocationTest()39 	DeskbarLocationTest::~DeskbarLocationTest()
40 {
41 	}
42 
43 
44 /*
45  *  Method:  DeskbarLocationTest::CheckLocation()
46  *   Descr:  This member fuction checks that the passed in location and
47  *           expansion state is the actual deskbar state
48  */
49 
50 
CheckLocation(BDeskbar * myDeskbar,deskbar_location currLocation,bool currExpanded,bool expandedSetDirectly)51 	void DeskbarLocationTest::CheckLocation(BDeskbar *myDeskbar,
52 	                                        deskbar_location currLocation,
53 	                                        bool currExpanded,
54 	                                        bool expandedSetDirectly)
55 {
56 	bool isExpanded;
57 	assert(myDeskbar->Location() == currLocation);
58 	assert(myDeskbar->Location(&isExpanded) == currLocation);
59 
60 	if ((currLocation == B_DESKBAR_LEFT_TOP) ||
61 	    (currLocation == B_DESKBAR_RIGHT_TOP) ||
62 	    (expandedSetDirectly)) {
63 		assert(myDeskbar->IsExpanded() == currExpanded);
64 		assert(isExpanded == currExpanded);
65 	} else if ((currLocation == B_DESKBAR_LEFT_BOTTOM) ||
66 	           (currLocation == B_DESKBAR_RIGHT_BOTTOM)) {
67 		assert(!myDeskbar->IsExpanded());
68 		assert(!isExpanded);
69 	} else {
70 		assert(myDeskbar->IsExpanded());
71 		assert(isExpanded);
72 	}
73 
74 	BRect myRect(myDeskbar->Frame());
75 	switch (currLocation) {
76 		case B_DESKBAR_TOP:
77 		case B_DESKBAR_LEFT_TOP:
78 			assert(myRect.top == 0.0);
79 			assert(myRect.left == 0.0);
80 			break;
81 		case B_DESKBAR_BOTTOM:
82 		case B_DESKBAR_LEFT_BOTTOM:
83 			assert(myRect.left == 0.0);
84 			break;
85 		case B_DESKBAR_RIGHT_TOP:
86 		case B_DESKBAR_RIGHT_BOTTOM:
87 			break;
88 		default:
89 			assert(false);
90 			break;
91 	}
92 	assert(get_deskbar_frame(&myRect) == B_OK);
93 	switch (currLocation) {
94 		case B_DESKBAR_TOP:
95 		case B_DESKBAR_LEFT_TOP:
96 			assert(myRect.top == 0.0);
97 			assert(myRect.left == 0.0);
98 			break;
99 		case B_DESKBAR_BOTTOM:
100 		case B_DESKBAR_LEFT_BOTTOM:
101 			assert(myRect.left == 0.0);
102 			break;
103 		case B_DESKBAR_RIGHT_TOP:
104 		case B_DESKBAR_RIGHT_BOTTOM:
105 			break;
106 		default:
107 			assert(false);
108 			break;
109 	}
110 }
111 
112 /*
113  *  Method:  DeskbarLocationTest::TestLocation()
114  *   Descr:  This member fuction performs a test of one location of the
115  *           deskbar.
116  */
117 
118 
TestLocation(BDeskbar * myDeskbar,deskbar_location newLocation)119 	void DeskbarLocationTest::TestLocation(BDeskbar *myDeskbar,
120 	                                       deskbar_location newLocation)
121 {
122 	assert(myDeskbar->SetLocation(newLocation) == B_OK);
123 	CheckLocation(myDeskbar, newLocation, false, false);
124 
125 	assert(myDeskbar->SetLocation(B_DESKBAR_TOP) == B_OK);
126 	CheckLocation(myDeskbar, B_DESKBAR_TOP, false, false);
127 
128 	assert(myDeskbar->SetLocation(newLocation, false) == B_OK);
129 	CheckLocation(myDeskbar, newLocation, false, false);
130 
131 	assert(myDeskbar->SetLocation(B_DESKBAR_TOP) == B_OK);
132 	CheckLocation(myDeskbar, B_DESKBAR_TOP, false, false);
133 
134 	assert(myDeskbar->SetLocation(newLocation, true) == B_OK);
135 	CheckLocation(myDeskbar, newLocation, true, false);
136 
137 	assert(myDeskbar->Expand(false) == B_OK);
138 	CheckLocation(myDeskbar, newLocation, false, true);
139 
140 	assert(myDeskbar->Expand(true) == B_OK);
141 	CheckLocation(myDeskbar, newLocation, true, true);
142 	}
143 
144 
145 /*
146  *  Method:  DeskbarLocationTest::PerformTest()
147  *   Descr:  This member function saves the starting state of the deskbar
148  *           and then sets the deskbar location to each individual allowed
149  *           state.  Finally, it restores the original location at the end
150  *           of the test.
151  */
152 
153 
PerformTest(void)154 	void DeskbarLocationTest::PerformTest(void)
155 {
156 	BDeskbar myDeskbar;
157 	bool origExpanded;
158 	deskbar_location origLocation = myDeskbar.Location(&origExpanded);
159 
160 	assert((origLocation == B_DESKBAR_TOP) ||
161 	       (origLocation == B_DESKBAR_BOTTOM) ||
162 	       (origLocation == B_DESKBAR_LEFT_BOTTOM) ||
163 	       (origLocation == B_DESKBAR_RIGHT_BOTTOM) ||
164 	       (origLocation == B_DESKBAR_LEFT_TOP) ||
165 	       (origLocation == B_DESKBAR_RIGHT_TOP));
166 
167 	TestLocation(&myDeskbar, B_DESKBAR_TOP);
168 	TestLocation(&myDeskbar, B_DESKBAR_BOTTOM);
169 	TestLocation(&myDeskbar, B_DESKBAR_LEFT_BOTTOM);
170 	TestLocation(&myDeskbar, B_DESKBAR_RIGHT_BOTTOM);
171 	TestLocation(&myDeskbar, B_DESKBAR_LEFT_TOP);
172 	TestLocation(&myDeskbar, B_DESKBAR_RIGHT_TOP);
173 
174 	assert(myDeskbar.SetLocation(origLocation, origExpanded) == B_OK);
175 	assert(myDeskbar.Location() == origLocation);
176 	assert(myDeskbar.IsExpanded() == origExpanded);
177 	}
178 
179 
180 /*
181  *  Method:  PropertyConstructionTest::suite()
182  *   Descr:  This static member function returns a test caller for performing
183  *           all combinations of "DeskbarLocationTest".
184  */
185 
suite(void)186  Test *DeskbarLocationTest::suite(void)
187 {
188 	typedef CppUnit::TestCaller<DeskbarLocationTest>
189 		DeskbarLocationTestCaller;
190 
191 	return(new DeskbarLocationTestCaller("BDeskbar::Location Test", &DeskbarLocationTest::PerformTest));
192 	}
193