1 //------------------------------------------------------------------------------
2 // RemoveFilterTest.cpp
3 //
4 //------------------------------------------------------------------------------
5
6 // Standard Includes -----------------------------------------------------------
7
8 // System Includes -------------------------------------------------------------
9 #include <Looper.h>
10 #include <MessageFilter.h>
11
12 // Project Includes ------------------------------------------------------------
13
14 // Local Includes --------------------------------------------------------------
15 #include "RemoveFilterTest.h"
16
17 // Local Defines ---------------------------------------------------------------
18
19 // Globals ---------------------------------------------------------------------
20
21 //------------------------------------------------------------------------------
22 /**
23 RemoveFilter(BMessageFilter* filter)
24 @case filter is NULL
25 @param filter NULL
26 @results Returns false
27 */
RemoveFilter1()28 void TRemoveFilterTest::RemoveFilter1()
29 {
30 BHandler Handler;
31 CPPUNIT_ASSERT(!Handler.RemoveFilter(NULL));
32 }
33 //------------------------------------------------------------------------------
34 /**
35 RemoveFilter(BMessageFilter* filter)
36 @case filter is valid, handler has no looper
37 @param filter Valid BMessageFilter pointer
38 @results Returns true. Contrary to documentation, original
39 implementation of BHandler doesn't care if it belongs to a
40 looper or not.
41 */
RemoveFilter2()42 void TRemoveFilterTest::RemoveFilter2()
43 {
44 BHandler Handler;
45 BMessageFilter* Filter = new BMessageFilter('1234');
46 Handler.AddFilter(Filter);
47 CPPUNIT_ASSERT(Handler.RemoveFilter(Filter));
48 }
49 //------------------------------------------------------------------------------
50 /**
51 RemoveFilter(BMessageFilter* filter)
52 @case filter is valid, handler has looper, looper isn't locked
53 @param filter Valid BMessageFilter pointer
54 @results Returns true. Contrary to documentation, original
55 implementation of BHandler doesn't care if it belongs to a
56 looper or not.
57 */
RemoveFilter3()58 void TRemoveFilterTest::RemoveFilter3()
59 {
60 BLooper Looper;
61 BHandler Handler;
62 Looper.AddHandler(&Handler);
63 BMessageFilter* Filter = new BMessageFilter('1234');
64 Handler.AddFilter(Filter);
65 CPPUNIT_ASSERT(Handler.RemoveFilter(Filter));
66 }
67 //------------------------------------------------------------------------------
68 /**
69 RemoveFilter(BMessageFilter* filter)
70 @case filter is valid, handler has looper, looper is locked
71 @param filter Valid BMessageFilter pointer
72 @results Return true.
73 */
RemoveFilter4()74 void TRemoveFilterTest::RemoveFilter4()
75 {
76 BLooper Looper;
77 BHandler Handler;
78 Looper.AddHandler(&Handler);
79 Looper.Lock();
80 BMessageFilter* Filter = new BMessageFilter('1234');
81 Handler.AddFilter(Filter);
82 CPPUNIT_ASSERT(Handler.RemoveFilter(Filter));
83 }
84 //------------------------------------------------------------------------------
85 /**
86 RemoveFilter(BMessageFilter* filter)
87 @case filter is valid, but not owned by handler, handler has no looper
88 @param filter Valid BMessageFilter pointer
89 @results Returns false. Contrary to documentation, original
90 implementation of BHandler doesn't care if it belongs to a
91 looper or not.
92 */
RemoveFilter5()93 void TRemoveFilterTest::RemoveFilter5()
94 {
95 BHandler Handler;
96 BMessageFilter* Filter = new BMessageFilter('1234');
97 CPPUNIT_ASSERT(!Handler.RemoveFilter(Filter));
98 }
99 //------------------------------------------------------------------------------
100 /**
101 RemoveFilter(BMessageFilter* filter)
102 @case filter is valid, but not owned by handler, handler has
103 looper, looper isn't locked
104 @param filter Valid BMessageFilter pointer
105 @results Returns false. Contrary to documentation, original
106 implementation of BHandler doesn't care if its looper is
107 locked or not.
108 */
RemoveFilter6()109 void TRemoveFilterTest::RemoveFilter6()
110 {
111 BLooper Looper;
112 BHandler Handler;
113 Looper.AddHandler(&Handler);
114 BMessageFilter* Filter = new BMessageFilter('1234');
115 CPPUNIT_ASSERT(!Handler.RemoveFilter(Filter));
116 }
117 //------------------------------------------------------------------------------
118 /**
119 RemoveFilter(BMessageFilter* filter)
120 @case filter is valid, but not owned by handler, handler has
121 looper, looper is locked
122 @param filter Valid BMessageFilter pointer
123 @results Returns false.
124 */
RemoveFilter7()125 void TRemoveFilterTest::RemoveFilter7()
126 {
127 BLooper Looper;
128 BHandler Handler;
129 Looper.AddHandler(&Handler);
130 Looper.Lock();
131 BMessageFilter* Filter = new BMessageFilter('1234');
132 CPPUNIT_ASSERT(!Handler.RemoveFilter(Filter));
133 }
134 //------------------------------------------------------------------------------
Suite()135 Test* TRemoveFilterTest::Suite()
136 {
137 TestSuite* SuiteOfTests = new TestSuite("BHandler::RemoveFilter");
138
139 ADD_TEST4(BHandler, SuiteOfTests, TRemoveFilterTest, RemoveFilter1);
140 ADD_TEST4(BHandler, SuiteOfTests, TRemoveFilterTest, RemoveFilter2);
141 ADD_TEST4(BHandler, SuiteOfTests, TRemoveFilterTest, RemoveFilter3);
142 ADD_TEST4(BHandler, SuiteOfTests, TRemoveFilterTest, RemoveFilter4);
143 ADD_TEST4(BHandler, SuiteOfTests, TRemoveFilterTest, RemoveFilter5);
144 ADD_TEST4(BHandler, SuiteOfTests, TRemoveFilterTest, RemoveFilter6);
145 ADD_TEST4(BHandler, SuiteOfTests, TRemoveFilterTest, RemoveFilter7);
146
147 return SuiteOfTests;
148 }
149 //------------------------------------------------------------------------------
150
151 /*
152 * $Log $
153 *
154 * $Id $
155 *
156 */
157
158
159