1 //------------------------------------------------------------------------------
2 // SetFilterListTest.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 "SetFilterListTest.h"
16
17 // Local Defines ---------------------------------------------------------------
18
19 // Globals ---------------------------------------------------------------------
20
21 //------------------------------------------------------------------------------
22 /**
23 SetFilterList(BList* filters)
24 @case filters is NULL
25 @param filters NULL
26 @results FilterList() returns NULL
27 */
SetFilterList1()28 void TSetFilterListTest::SetFilterList1()
29 {
30 BHandler Handler;
31 Handler.SetFilterList(NULL);
32 CPPUNIT_ASSERT(!Handler.FilterList());
33 }
34 //------------------------------------------------------------------------------
35 /**
36 SetFilterList(BList* filters)
37 @case filters is valid, handler has no looper
38 @param filters Valid pointer to BList of BMessageFilters
39 @results FilterList() returns assigned list
40 */
SetFilterList2()41 void TSetFilterListTest::SetFilterList2()
42 {
43 BList* Filters = new BList;
44 BMessageFilter* Filter = new BMessageFilter('1234');
45 Filters->AddItem((void*)Filter);
46 BHandler Handler;
47 Handler.SetFilterList(Filters);
48 CPPUNIT_ASSERT(Handler.FilterList() == Filters);
49 }
50 //------------------------------------------------------------------------------
51 /**
52 SetFilterList(BList* filters)
53 @case filters is valid, handler has looper, looper isn't locked
54 @param filters Valid pointer to BList of BMessageFilters
55 @results FilterList() returns NULL; list is not assigned
56 debug message "Owning Looper must be locked before calling
57 SetFilterList"
58 */
SetFilterList3()59 void TSetFilterListTest::SetFilterList3()
60 {
61 DEBUGGER_ESCAPE;
62
63 BLooper Looper;
64 BHandler Handler;
65
66 BList* Filters = new BList;
67 BMessageFilter* Filter = new BMessageFilter('1234');
68 Filters->AddItem((void*)Filter);
69
70 Looper.AddHandler(&Handler);
71 if (Looper.IsLocked())
72 {
73 Looper.Unlock();
74 }
75
76 Handler.SetFilterList(Filters);
77 CPPUNIT_ASSERT(!Handler.FilterList());
78 }
79 //------------------------------------------------------------------------------
80 /**
81 SetFilterList(BList* filters)
82 @case filters is valid, handler has looper, looper is locked
83 @param filters
84 @results
85 */
SetFilterList4()86 void TSetFilterListTest::SetFilterList4()
87 {
88 BList* Filters = new BList;
89 BMessageFilter* Filter = new BMessageFilter('1234');
90 Filters->AddItem((void*)Filter);
91 BLooper Looper;
92 BHandler Handler;
93 Looper.Lock();
94 Looper.AddHandler(&Handler);
95 Handler.SetFilterList(Filters);
96 CPPUNIT_ASSERT(Handler.FilterList() == Filters);
97 }
98 //------------------------------------------------------------------------------
99 /**
100 SetFilterList(BList* filters)
101 @case filters and handler are valid; then NULL filters is passed
102 @param filters
103 @results
104 */
SetFilterList5()105 void TSetFilterListTest::SetFilterList5()
106 {
107 BList* Filters = new BList;
108 BMessageFilter* Filter = new BMessageFilter('1234');
109 Filters->AddItem((void*)Filter);
110 BLooper Looper;
111 BHandler Handler;
112 Looper.Lock();
113 Looper.AddHandler(&Handler);
114 Handler.SetFilterList(Filters);
115 CPPUNIT_ASSERT(Handler.FilterList() == Filters);
116
117 Handler.SetFilterList(NULL);
118 CPPUNIT_ASSERT(!Handler.FilterList());
119 }
120 //------------------------------------------------------------------------------
Suite()121 Test* TSetFilterListTest::Suite()
122 {
123 TestSuite* SuiteOfTests = new TestSuite("BHandler::SetFilterList");
124
125 ADD_TEST4(BHandler, SuiteOfTests, TSetFilterListTest, SetFilterList1);
126 ADD_TEST4(BHandler, SuiteOfTests, TSetFilterListTest, SetFilterList2);
127 ADD_TEST4(BHandler, SuiteOfTests, TSetFilterListTest, SetFilterList3);
128 ADD_TEST4(BHandler, SuiteOfTests, TSetFilterListTest, SetFilterList4);
129 ADD_TEST4(BHandler, SuiteOfTests, TSetFilterListTest, SetFilterList5);
130
131 return SuiteOfTests;
132 }
133 //------------------------------------------------------------------------------
134
135 /*
136 * $Log $
137 *
138 * $Id $
139 *
140 */
141
142
143