xref: /haiku/src/tests/kits/app/bhandler/SetNextHandlerTest.cpp (revision 76a5f3484abd9a293483b45f40455c0b58e6f3f0)
1 //------------------------------------------------------------------------------
2 //	SetNextHandlerTest.cpp
3 //
4 //------------------------------------------------------------------------------
5 
6 // Standard Includes -----------------------------------------------------------
7 
8 // System Includes -------------------------------------------------------------
9 #include <Looper.h>
10 
11 // Project Includes ------------------------------------------------------------
12 
13 // Local Includes --------------------------------------------------------------
14 #include "SetNextHandlerTest.h"
15 
16 // Local Defines ---------------------------------------------------------------
17 
18 // Globals ---------------------------------------------------------------------
19 
20 //------------------------------------------------------------------------------
21 /**
22 	SetNextHandler(BHandler* handler);
23 	NextHandler();
24 	@case			Clear the next handler
25 	@param	handler	Valid BHandler pointer, then NULL
26 	@results		NextHandler() returns Handler2, then NULL
27  */
SetNextHandler0()28 void TSetNextHandlerTest::SetNextHandler0()
29 {
30 	BLooper Looper;
31 	BHandler Handler1;
32 	BHandler Handler2;
33 
34 	Looper.AddHandler(&Handler1);
35 	Looper.AddHandler(&Handler2);
36 
37 	Handler1.SetNextHandler(&Handler2);
38 	CPPUNIT_ASSERT(Handler1.NextHandler() == &Handler2);
39 
40 	Handler1.SetNextHandler(NULL);
41 	CPPUNIT_ASSERT(!Handler1.NextHandler());
42 }
43 //------------------------------------------------------------------------------
44 /**
45 	SetNextHandler(BHandler* handler);
46 	NextHandler();
47 	@case			Handler1 and Handler2 do not belong to a BLooper
48 	@param	handler	Valid BHandler pointer
49 	@results		NextHandler() returns NULL
50 					debug message "handler must belong to looper before setting
51 					NextHandler"
52  */
SetNextHandler1()53 void TSetNextHandlerTest::SetNextHandler1()
54 {
55 	DEBUGGER_ESCAPE;
56 
57 	BHandler Handler1;
58 	BHandler Handler2;
59 	Handler1.SetNextHandler(&Handler2);
60 	CPPUNIT_ASSERT(Handler1.NextHandler() == NULL);
61 }
62 //------------------------------------------------------------------------------
63 /**
64 	SetNextHandler(BHandler* handler);
65 	NextHandler();
66 	@case			Handler1 belongs to a unlocked BLooper, Handler2 does not
67 	@param	handler	Valid BHandler pointer
68 	@results		NextHandler() returns BLooper
69 					debug message "The handler's looper must be locked before
70 					setting NextHandler"
71  */
SetNextHandler2()72 void TSetNextHandlerTest::SetNextHandler2()
73 {
74 	DEBUGGER_ESCAPE;
75 
76 	BHandler Handler1;
77 	BHandler Handler2;
78 	BLooper Looper;
79 	Looper.AddHandler(&Handler1);
80 	Looper.Unlock();
81 	Handler1.SetNextHandler(&Handler2);
82 	CPPUNIT_ASSERT(Handler1.NextHandler() == &Looper);
83 }
84 //------------------------------------------------------------------------------
85 /**
86 	SetNextHandler(BHandler* handler);
87 	NextHandler();
88 	@case			Handler1 belongs to a locked BLooper, Handler2 does not
89 	@param	handler	Valid BHandler pointer
90 	@results		NextHandler() returns BLooper
91 					debug message "The handler and its NextHandler must have
92 					the same looper"
93  */
SetNextHandler3()94 void TSetNextHandlerTest::SetNextHandler3()
95 {
96 	DEBUGGER_ESCAPE;
97 
98 	BHandler Handler1;
99 	BHandler Handler2;
100 	BLooper Looper;
101 	Looper.AddHandler(&Handler1);
102 	Handler1.SetNextHandler(&Handler2);
103 	CPPUNIT_ASSERT(Handler1.NextHandler() == &Looper);
104 }
105 //------------------------------------------------------------------------------
106 /**
107 	SetNextHandler(BHandler* handler);
108 	NextHandler();
109 	@case			Handler2 belongs to a unlocked BLooper, Handler1 does not
110 	@param	handler	Valid BHandler pointer
111 	@results		NextHandler() returns NULL
112 					debug message "handler must belong to looper before setting
113 					NextHandler"
114  */
SetNextHandler4()115 void TSetNextHandlerTest::SetNextHandler4()
116 {
117 	DEBUGGER_ESCAPE;
118 
119 	BHandler Handler1;
120 	BHandler Handler2;
121 	BLooper Looper;
122 	Looper.AddHandler(&Handler2);
123 	Looper.Unlock();
124 	Handler1.SetNextHandler(&Handler2);
125 	CPPUNIT_ASSERT(Handler1.NextHandler() == NULL);
126 }
127 //------------------------------------------------------------------------------
128 /**
129 	SetNextHandler(BHandler* handler);
130 	NextHandler();
131 	@case			Handler2 belongs to a locked BLooper, Handler1 does not
132 	@param	handler	Valid BHandler pointer
133 	@results		NextHandler() returns NULL
134 					debug message "handler must belong to looper before setting
135 					NextHandler"
136  */
SetNextHandler5()137 void TSetNextHandlerTest::SetNextHandler5()
138 {
139 	DEBUGGER_ESCAPE;
140 
141 	BHandler Handler1;
142 	BHandler Handler2;
143 	BLooper Looper;
144 	Looper.AddHandler(&Handler2);
145 	Handler1.SetNextHandler(&Handler2);
146 	CPPUNIT_ASSERT(Handler1.NextHandler() == NULL);
147 }
148 //------------------------------------------------------------------------------
149 /**
150 	SetNextHandler(BHandler* handler);
151 	NextHandler();
152 	@case			Handler1 and Handler2 belong to different unlocked BLoopers
153 	@param	handler	Valid BHandler pointer
154 	@results		Returns BLooper;
155 					debug message "The handler and its NextHandler must have the
156 					same looper"
157  */
SetNextHandler6()158 void TSetNextHandlerTest::SetNextHandler6()
159 {
160 	DEBUGGER_ESCAPE;
161 
162 	BHandler Handler1;
163 	BHandler Handler2;
164 	BLooper Looper1;
165 	BLooper Looper2;
166 	Looper1.AddHandler(&Handler1);
167 	Looper2.AddHandler(&Handler2);
168 	Looper1.Unlock();
169 	Looper2.Unlock();
170 	Handler1.SetNextHandler(&Handler2);
171 	CPPUNIT_ASSERT(Handler1.NextHandler() == &Looper1);
172 }
173 //------------------------------------------------------------------------------
174 /**
175 	SetNextHandler(BHandler* handler);
176 	NextHandler();
177 	@case			Handler1 and Handler2 belong to different BLoopers;
178 					Handler1's is locked; Handler2's is not
179 	@param	handler	Valid BHandler pointer
180 	@result			Returns BLooper;
181 					debug message "The handler and its NextHandler must have the
182 					same looper"
183  */
SetNextHandler7()184 void TSetNextHandlerTest::SetNextHandler7()
185 {
186 	DEBUGGER_ESCAPE;
187 
188 	BHandler Handler1;
189 	BHandler Handler2;
190 	BLooper Looper1;
191 	BLooper Looper2;
192 	Looper1.AddHandler(&Handler1);
193 	Looper2.AddHandler(&Handler2);
194 	Looper2.Unlock();
195 	Handler1.SetNextHandler(&Handler2);
196 	CPPUNIT_ASSERT(Handler1.NextHandler() == &Looper1);
197 }
198 //------------------------------------------------------------------------------
199 /**
200 	SetNextHandler(BHandler* handler);
201 	NextHandler();
202 	@case			Handler1 and Handler2 belong to different BLoopers;
203 					Handler1's is unlocked; Handler2's is locked
204 	@param	handler	Valid BHandler pointer
205 	@results		Returns BLooper
206 					debug message "The handler and its NextHandler must have the
207 					same looper"
208  */
SetNextHandler8()209 void TSetNextHandlerTest::SetNextHandler8()
210 {
211 	DEBUGGER_ESCAPE;
212 
213 	BHandler Handler1;
214 	BHandler Handler2;
215 	BLooper Looper1;
216 	BLooper Looper2;
217 	Looper1.AddHandler(&Handler1);
218 	Looper2.AddHandler(&Handler2);
219 	Looper1.Unlock();
220 	Handler1.SetNextHandler(&Handler2);
221 	CPPUNIT_ASSERT(Handler1.NextHandler() == &Looper1);
222 }
223 //------------------------------------------------------------------------------
224 /**
225 	SetNextHandler(BHandler* handler);
226 	NextHandler();
227 	@case			Handler1 and Handler2 belong to different locked BLoopers
228 	@param	handler	Valid BHandler pointer
229 	@results		Returns BLooper
230 					debug message "The handler and its NextHandler must have the
231 					same looper"
232  */
SetNextHandler9()233 void TSetNextHandlerTest::SetNextHandler9()
234 {
235 	DEBUGGER_ESCAPE;
236 
237 	BHandler Handler1;
238 	BHandler Handler2;
239 	BLooper Looper1;
240 	BLooper Looper2;
241 	Looper1.AddHandler(&Handler1);
242 	Looper2.AddHandler(&Handler2);
243 	Handler1.SetNextHandler(&Handler2);
244 	CPPUNIT_ASSERT(Handler1.NextHandler() == &Looper1);
245 }
246 //------------------------------------------------------------------------------
247 /**
248 	SetNextHandler(BHandler* handler);
249 	NextHandler();
250 	@case			Handler1 and Handler2 belong to the same unlocked BLooper
251 	@param	handler	Valid BHandler pointer
252 	@results		Returns Handler2
253 					debug message "The handler's looper must be locked before
254 					setting NextHandler"
255 	@note			R5 implementation allows the next handler to be set anyway;
256 					we do the same.
257  */
SetNextHandler10()258 void TSetNextHandlerTest::SetNextHandler10()
259 {
260 	DEBUGGER_ESCAPE;
261 
262 	BLooper Looper;
263 	BHandler Handler1;
264 	BHandler Handler2;
265 	Looper.AddHandler(&Handler1);
266 	Looper.AddHandler(&Handler2);
267 	Looper.Unlock();
268 	Handler1.SetNextHandler(&Handler2);
269 	CPPUNIT_ASSERT(Handler1.NextHandler() == &Looper);
270 }
271 //------------------------------------------------------------------------------
272 /**
273 	SetNextHandler(BHandler* handler);
274 	NextHandler();
275 	@case			Handler1 and Handler2 belong to the same locked BLooper
276 	@param	handler	Valid BHandler pointer
277 	@results		Returns Handler2
278  */
SetNextHandler11()279 void TSetNextHandlerTest::SetNextHandler11()
280 {
281 	BLooper Looper;
282 	BHandler Handler1;
283 	BHandler Handler2;
284 	Looper.AddHandler(&Handler1);
285 	Looper.AddHandler(&Handler2);
286 	Handler1.SetNextHandler(&Handler2);
287 	CPPUNIT_ASSERT(Handler1.NextHandler() == &Handler2);
288 }
289 //------------------------------------------------------------------------------
Suite()290 Test* TSetNextHandlerTest::Suite()
291 {
292 	TestSuite* SuiteOfTests = new TestSuite("BHandler::SetNextHandler");
293 
294 	ADD_TEST4(BHandler, SuiteOfTests, TSetNextHandlerTest, SetNextHandler0);
295 	ADD_TEST4(BHandler, SuiteOfTests, TSetNextHandlerTest, SetNextHandler1);
296 	ADD_TEST4(BHandler, SuiteOfTests, TSetNextHandlerTest, SetNextHandler2);
297 	ADD_TEST4(BHandler, SuiteOfTests, TSetNextHandlerTest, SetNextHandler3);
298 	ADD_TEST4(BHandler, SuiteOfTests, TSetNextHandlerTest, SetNextHandler4);
299 	ADD_TEST4(BHandler, SuiteOfTests, TSetNextHandlerTest, SetNextHandler5);
300 	ADD_TEST4(BHandler, SuiteOfTests, TSetNextHandlerTest, SetNextHandler6);
301 	ADD_TEST4(BHandler, SuiteOfTests, TSetNextHandlerTest, SetNextHandler7);
302 	ADD_TEST4(BHandler, SuiteOfTests, TSetNextHandlerTest, SetNextHandler8);
303 	ADD_TEST4(BHandler, SuiteOfTests, TSetNextHandlerTest, SetNextHandler9);
304 	ADD_TEST4(BHandler, SuiteOfTests, TSetNextHandlerTest, SetNextHandler10);
305 	ADD_TEST4(BHandler, SuiteOfTests, TSetNextHandlerTest, SetNextHandler11);
306 
307 	return SuiteOfTests;
308 }
309 //------------------------------------------------------------------------------
310 
311 /*
312  * $Log $
313  *
314  * $Id  $
315  *
316  */
317 
318 
319