xref: /haiku/src/tests/kits/app/blooper/RemoveHandlerTest.cpp (revision be2939cab7f324704e9aa1eaad2be8a42f8290e7)
1 //------------------------------------------------------------------------------
2 //	RemoveHandlerTest.cpp
3 //
4 //------------------------------------------------------------------------------
5 
6 // Standard Includes -----------------------------------------------------------
7 
8 // System Includes -------------------------------------------------------------
9 #include <Handler.h>
10 #include <Looper.h>
11 #include <MessageFilter.h>
12 
13 // Project Includes ------------------------------------------------------------
14 
15 // Local Includes --------------------------------------------------------------
16 #include "RemoveHandlerTest.h"
17 
18 // Local Defines ---------------------------------------------------------------
19 
20 // Globals ---------------------------------------------------------------------
21 
22 //------------------------------------------------------------------------------
23 /**
24 	RemoveHandler(BHandler* handler)
25 	@case		handler is NULL
26 	@param		handler	NULL
27 	@results	RemoveHandler() returns false.  R5 implementation seg faults;
28 				we've fixed that.
29  */
RemoveHandler1()30 void TRemoveHandlerTest::RemoveHandler1()
31 {
32 	BLooper Looper;
33 #ifndef TEST_R5
34 	CPPUNIT_ASSERT(!Looper.RemoveHandler(NULL));
35 #endif
36 }
37 //------------------------------------------------------------------------------
38 /**
39 	RemoveHandler(BHandler* handler)
40 	@case		handler doesn't belong to this looper
41 	@param		handler	Valid BHandler pointer, not assigned to looper
42 	@results
43  */
RemoveHandler2()44 void TRemoveHandlerTest::RemoveHandler2()
45 {
46 	BLooper Looper;
47 	BHandler Handler;
48 	CPPUNIT_ASSERT(!Looper.RemoveHandler(&Handler));
49 }
50 //------------------------------------------------------------------------------
51 /**
52 	RemoveHandler(BHandler* handler)
53 	@case		handler is valid, looper is unlocked
54 	@param		handler	Valid BHandler pointer, assigned to looper
55 	@results	goes to debugger, but removes handler anyway
56  */
RemoveHandler3()57 void TRemoveHandlerTest::RemoveHandler3()
58 {
59 	DEBUGGER_ESCAPE;
60 
61 	BLooper Looper;
62 	BHandler Handler;
63 	Looper.AddHandler(&Handler);
64 	Looper.Unlock();
65 	CPPUNIT_ASSERT(Looper.RemoveHandler(&Handler));
66 }
67 //------------------------------------------------------------------------------
68 /**
69 	RemoveHandler(BHandler* handler)
70 	@case		handler doesn't belong to this looper, looper is unlocked
71 	@param		handler Valid BHandler pointer, not assigned to looper
72 	@results
73  */
RemoveHandler4()74 void TRemoveHandlerTest::RemoveHandler4()
75 {
76 	DEBUGGER_ESCAPE;
77 
78 	BLooper Looper;
79 	BHandler Handler;
80 	Looper.Unlock();
81 	CPPUNIT_ASSERT(!Looper.RemoveHandler(&Handler));
82 }
83 //------------------------------------------------------------------------------
84 /**
85 	RemoveHandler(BHandler* handler)
86 	@case		Valid looper and handler; handler has filters
87 	@param		handler	Valid BHandler pointer
88 	@results	RemoveHandler() returns true
89 				handler->FilterList() returns NULL after removal
90  */
RemoveHandler5()91 void TRemoveHandlerTest::RemoveHandler5()
92 {
93 	BLooper Looper;
94 	BHandler Handler;
95 	BMessageFilter* MessageFilter = new BMessageFilter('1234');
96 
97 	Handler.AddFilter(MessageFilter);
98 	Looper.AddHandler(&Handler);
99 	CPPUNIT_ASSERT(Looper.RemoveHandler(&Handler));
100 	CPPUNIT_ASSERT(Handler.FilterList());
101 }
102 //------------------------------------------------------------------------------
Suite()103 Test* TRemoveHandlerTest::Suite()
104 {
105 	TestSuite* suite = new TestSuite("BLooper::RemoveHandler(BHandler* handler)");
106 
107 	ADD_TEST4(BLooper, suite, TRemoveHandlerTest, RemoveHandler1);
108 	ADD_TEST4(BLooper, suite, TRemoveHandlerTest, RemoveHandler2);
109 	ADD_TEST4(BLooper, suite, TRemoveHandlerTest, RemoveHandler3);
110 	ADD_TEST4(BLooper, suite, TRemoveHandlerTest, RemoveHandler4);
111 	ADD_TEST4(BLooper, suite, TRemoveHandlerTest, RemoveHandler5);
112 
113 	return suite;
114 }
115 //------------------------------------------------------------------------------
116 
117 /*
118  * $Log $
119  *
120  * $Id  $
121  *
122  */
123 
124 
125