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