xref: /haiku/src/tests/kits/app/blooper/AddCommonFilterTest.cpp (revision 858b08a4fb0a7554775afc8b44fc66791f39a44a)
1 //------------------------------------------------------------------------------
2 //	AddCommonFilterTest.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 "AddCommonFilterTest.h"
16 
17 // Local Defines ---------------------------------------------------------------
18 
19 // Globals ---------------------------------------------------------------------
20 
21 //------------------------------------------------------------------------------
22 /**
23 	AddCommonFilter(BMessageFilter* filter)
24 	@case		NULL filter
25 	@param		filter is NULL
26 	@results	none
27 	@note		R5 chokes on this test; doesn't param check, apparently.
28  */
AddCommonFilterTest1()29 void TAddCommonFilterTest::AddCommonFilterTest1()
30 {
31 #ifndef TEST_R5
32 	BLooper Looper;
33 	Looper.AddCommonFilter(NULL);
34 #endif
35 }
36 //------------------------------------------------------------------------------
37 /**
38 	AddCommonFilter(BMessageFilter* filter)
39 	@case		Valid filter, looper not locked
40 	@param		Valid BMessageFilter pointer
41 	@results	Debugger message "Owning Looper must be locked before calling
42 				AddCommonFilter".  Also, since internal filter list construction
43 				is delayed until a filter is added, CommonFilterList() should
44 				return NULL.
45  */
AddCommonFilterTest2()46 void TAddCommonFilterTest::AddCommonFilterTest2()
47 {
48 	DEBUGGER_ESCAPE;
49 
50 	BLooper Looper;
51 	Looper.Unlock();
52 	BMessageFilter* Filter = new BMessageFilter('1234');
53 	Looper.AddCommonFilter(Filter);
54 	CPPUNIT_ASSERT(Looper.CommonFilterList() == NULL);
55 }
56 //------------------------------------------------------------------------------
57 /**
58 	AddCommonFilter(BMessageFilter* filter)
59 	@case		Valid filter, looper locked
60 	@param		Valid BMessageFilter pointer
61 	@results	Filter is successfully added to the common filter list
62  */
AddCommonFilterTest3()63 void TAddCommonFilterTest::AddCommonFilterTest3()
64 {
65 	BLooper Looper;
66 	BMessageFilter* Filter = new BMessageFilter('1234');
67 	Looper.AddCommonFilter(Filter);
68 	CPPUNIT_ASSERT(Looper.CommonFilterList()->HasItem(Filter));
69 }
70 //------------------------------------------------------------------------------
71 /**
72 	AddCommonFilter(BMessageFilter* filter)
73 	@case		Valid filter, looper locked, owned by another looper
74 	@param		Valid BMessageFilter pointer
75 	@results	Debugger message "A MessageFilter can only be used once."  Also,
76 				since internal filter list construction is delayed until a
77 				filter is added, Looper2.CommonFilterList() should return NULL.
78  */
AddCommonFilterTest4()79 void TAddCommonFilterTest::AddCommonFilterTest4()
80 {
81 	DEBUGGER_ESCAPE;
82 
83 	BLooper Looper1;
84 	BLooper Looper2;
85 	BMessageFilter* Filter = new BMessageFilter('1234');
86 	Looper1.AddCommonFilter(Filter);
87 	CPPUNIT_ASSERT(Looper1.CommonFilterList()->HasItem(Filter));
88 	Looper2.AddCommonFilter(Filter);
89 	CPPUNIT_ASSERT(Looper2.CommonFilterList() == NULL);
90 }
91 //------------------------------------------------------------------------------
92 #ifdef ADD_TEST
93 #undef ADD_TEST
94 #endif
95 #define ADD_TEST(__test_name__)	\
96 	ADD_TEST4(BLooper, suite, TAddCommonFilterTest, __test_name__);
Suite()97 TestSuite* TAddCommonFilterTest::Suite()
98 {
99 	TestSuite* suite =
100 		new TestSuite("BLooper::AddCommonFilter(BMessageFilter*)");
101 
102 	ADD_TEST(AddCommonFilterTest1);
103 	ADD_TEST(AddCommonFilterTest2);
104 	ADD_TEST(AddCommonFilterTest3);
105 	ADD_TEST(AddCommonFilterTest4);
106 
107 	return suite;
108 }
109 //------------------------------------------------------------------------------
110 
111 /*
112  * $Log $
113  *
114  * $Id  $
115  *
116  */
117 
118