1//------------------------------------------------------------------------------
2//	SetCommonFilterListTest.cpp
3//
4//------------------------------------------------------------------------------
5
6// Standard Includes -----------------------------------------------------------
7
8// System Includes -------------------------------------------------------------
9#include <List.h>
10#include <Looper.h>
11#include <MessageFilter.h>
12
13// Project Includes ------------------------------------------------------------
14
15// Local Includes --------------------------------------------------------------
16#include "SetCommonFilterListTest.h"
17
18// Local Defines ---------------------------------------------------------------
19
20// Globals ---------------------------------------------------------------------
21
22//------------------------------------------------------------------------------
23/**
24	SetCommonFilterList(BList* filters)
25	@case			NULL list
26	@param	filters	NULL
27	@result			CommonFilterList() returns NULL
28 */
29void TSetCommonFilterListTest::SetCommonFilterListTest1()
30{
31	BLooper Looper;
32	Looper.SetCommonFilterList(NULL);
33	CPPUNIT_ASSERT(Looper.CommonFilterList() == NULL);
34}
35//------------------------------------------------------------------------------
36/**
37	SetCommonFilterList(BList* filters)
38	@case			Valid list, looper not locked
39	@param	filters	Valid pointer to BList containing BMessageFilter
40	@result			Debugger message: "Owning Looper must be locked before
41					calling SetCommonFilterList".  CommonFilterList() returns
42					NULL.
43 */
44void TSetCommonFilterListTest::SetCommonFilterListTest2()
45{
46	DEBUGGER_ESCAPE;
47
48	BLooper Looper;
49	BList* filters = new BList;
50	filters->AddItem(new BMessageFilter('1234'));
51	Looper.Unlock();
52	Looper.SetCommonFilterList(filters);
53	CPPUNIT_ASSERT(Looper.CommonFilterList() == NULL);
54}
55//------------------------------------------------------------------------------
56/**
57	SetCommonFilterList(BList* filters)
58	@case			Valid list, looper locked
59	@param	filters	Valid pointer to BList containing BMessageFilter
60	@result			CommonFilterList() returns filters.
61 */
62void TSetCommonFilterListTest::SetCommonFilterListTest3()
63{
64	BLooper Looper;
65	BList* filters = new BList;
66	filters->AddItem(new BMessageFilter('1234'));
67	Looper.SetCommonFilterList(filters);
68	CPPUNIT_ASSERT(Looper.CommonFilterList() == filters);
69}
70//------------------------------------------------------------------------------
71/**
72	SetCommonFilterList(BList* filters)
73	@case			Valid list, looper locked, owned by another looper
74	@param	filters	Valid pointer to BList containing BMessageFilter
75	@result			Looper2.CommonFilterList() returns NULL.
76	@note			R5 implementation segfaults when the first looper is
77					destroyed (it goes last because it was constructed first)
78					because it tries to clean up the filter list which has
79					already been cleaned up by the other looper.  Now fixed in
80					OpenBeOS.
81 */
82void TSetCommonFilterListTest::SetCommonFilterListTest4()
83{
84	DEBUGGER_ESCAPE;
85
86	BLooper Looper1;
87	BLooper Looper2;
88	BList* filters = new BList;
89	filters->AddItem(new BMessageFilter('1234'));
90	Looper1.SetCommonFilterList(filters);
91	Looper2.SetCommonFilterList(filters);
92	CPPUNIT_ASSERT(Looper1.CommonFilterList() == filters);
93#ifndef TEST_R5
94	CPPUNIT_ASSERT(Looper2.CommonFilterList() == NULL);
95#else
96	CPPUNIT_ASSERT(Looper2.CommonFilterList() == filters);
97#endif
98}
99//------------------------------------------------------------------------------
100#ifdef ADD_TEST
101#undef ADD_TEST
102#endif
103#define ADD_TEST(__test_name__)	\
104	ADD_TEST4(BLooper, suite, TSetCommonFilterListTest, __test_name__)
105TestSuite* TSetCommonFilterListTest::Suite()
106{
107	TestSuite* suite = new TestSuite("BLooper::SetCommonFilterList(BList*)");
108
109	ADD_TEST(SetCommonFilterListTest1);
110	ADD_TEST(SetCommonFilterListTest2);
111	ADD_TEST(SetCommonFilterListTest3);
112	ADD_TEST(SetCommonFilterListTest4);
113
114	return suite;
115}
116//------------------------------------------------------------------------------
117
118/*
119 * $Log $
120 *
121 * $Id  $
122 *
123 */
124
125