More tests, more fixes.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@528 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+18
-2
@@ -747,11 +747,16 @@ void BLooper::AddCommonFilter(BMessageFilter* filter)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Locked())
|
||||
if (!IsLocked())
|
||||
{
|
||||
debugger("Owning Looper must be locked before calling AddCommonFilter");
|
||||
}
|
||||
|
||||
if (filter->Looper())
|
||||
{
|
||||
debugger("A MessageFilter can only be used once.");
|
||||
}
|
||||
|
||||
if (!fCommonFilters)
|
||||
{
|
||||
fCommonFilters = new BList(FILTER_LIST_BLOCK_SIZE);
|
||||
@@ -762,7 +767,18 @@ void BLooper::AddCommonFilter(BMessageFilter* filter)
|
||||
//------------------------------------------------------------------------------
|
||||
bool BLooper::RemoveCommonFilter(BMessageFilter* filter)
|
||||
{
|
||||
AssertLocked();
|
||||
if (!IsLocked())
|
||||
{
|
||||
debugger("Owning Looper must be locked before calling "
|
||||
"RemoveCommonFilter");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!fCommonFilters)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = fCommonFilters->RemoveItem(filter);
|
||||
if (result)
|
||||
{
|
||||
|
||||
@@ -36,6 +36,7 @@ CommonTestLib libapptest.so
|
||||
RunTest.cpp
|
||||
LooperForThreadTest.cpp
|
||||
AddCommonFilterTest.cpp
|
||||
RemoveCommonFilterTest.cpp
|
||||
|
||||
# BMessageQueue
|
||||
MessageQueueTest.cpp
|
||||
|
||||
@@ -43,10 +43,12 @@ void TAddCommonFilterTest::AddCommonFilterTest1()
|
||||
*/
|
||||
void TAddCommonFilterTest::AddCommonFilterTest2()
|
||||
{
|
||||
DEBUGGER_ESCAPE;
|
||||
|
||||
BLooper Looper;
|
||||
Looper.Unlock();
|
||||
BMessageFilter* Filter = new BMessageFilter('1234');
|
||||
Looper.AddCommonFilter(&Filter);
|
||||
Looper.AddCommonFilter(Filter);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
@@ -59,22 +61,24 @@ void TAddCommonFilterTest::AddCommonFilterTest3()
|
||||
{
|
||||
BLooper Looper;
|
||||
BMessageFilter* Filter = new BMessageFilter('1234');
|
||||
Looper.AddCommonFilter(&Filter);
|
||||
Looper.AddCommonFilter(Filter);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
AddCommonFilter(BMessageFilter* filter)
|
||||
@case Valid filter, looper locked, owned by another looper
|
||||
@param Valid BMessageFilter pointer
|
||||
@results
|
||||
@results Debugger message "A MessageFilter can only be used once."
|
||||
*/
|
||||
void TAddCommonFilterTest::AddCommonFilterTest4()
|
||||
{
|
||||
DEBUGGER_ESCAPE;
|
||||
|
||||
BLooper Looper1;
|
||||
BLooper Looper2;
|
||||
BMessageFilter* Filter = new BMessageFilter('1234');
|
||||
Looper1.AddCommonFilter(&Filter);
|
||||
Looper2.AddCommonFilter(&Filter);
|
||||
Looper1.AddCommonFilter(Filter);
|
||||
Looper2.AddCommonFilter(Filter);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
#ifdef ADD_TEST
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "RunTest.h"
|
||||
#include "LooperForThreadTest.h"
|
||||
#include "AddCommonFilterTest.h"
|
||||
#include "RemoveCommonFilterTest.h"
|
||||
|
||||
Test* LooperTestSuite()
|
||||
{
|
||||
@@ -25,6 +26,7 @@ Test* LooperTestSuite()
|
||||
tests->addTest(TRunTest::Suite());
|
||||
tests->addTest(TLooperForThreadTest::Suite());
|
||||
tests->addTest(TAddCommonFilterTest::Suite());
|
||||
tests->addTest(TRemoveCommonFilterTest::Suite());
|
||||
|
||||
return tests;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// RemoveCommonFilterTest.cpp
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include <Looper.h>
|
||||
#include <MessageFilter.h>
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "RemoveCommonFilterTest.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
RemoveCommonFilter(BMessageFilter* filter)
|
||||
@case NULL filter
|
||||
@param filter is NULL
|
||||
@results
|
||||
*/
|
||||
void TRemoveCommonFilterTest::RemoveCommonFilterTest1()
|
||||
{
|
||||
BLooper Looper;
|
||||
CPPUNIT_ASSERT(!Looper.RemoveCommonFilter(NULL));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
RemoveCommonFilter(BMessageFilter* filter)
|
||||
@case Valid filter, looper not locked
|
||||
@param Valid BMessageFilter pointer
|
||||
@results
|
||||
*/
|
||||
void TRemoveCommonFilterTest::RemoveCommonFilterTest2()
|
||||
{
|
||||
DEBUGGER_ESCAPE;
|
||||
|
||||
BLooper Looper;
|
||||
BMessageFilter* Filter = new BMessageFilter('1234');
|
||||
Looper.AddCommonFilter(Filter);
|
||||
Looper.Unlock();
|
||||
CPPUNIT_ASSERT(!Looper.RemoveCommonFilter(Filter));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
RemoveCommonFilter(BMessageFilter* filter)
|
||||
@case Valid filter, not owned by looper
|
||||
@param Valid BMessageFilter pointer
|
||||
@results
|
||||
*/
|
||||
void TRemoveCommonFilterTest::RemoveCommonFilterTest3()
|
||||
{
|
||||
BLooper Looper;
|
||||
BMessageFilter Filter('1234');
|
||||
CPPUNIT_ASSERT(!Looper.RemoveCommonFilter(&Filter));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
RemoveCommonFilter(BMessageFilter* filter)
|
||||
@case Valid filter, owned by looper
|
||||
@param Valid BMessageFilter pointer
|
||||
@results
|
||||
*/
|
||||
void TRemoveCommonFilterTest::RemoveCommonFilterTest4()
|
||||
{
|
||||
BLooper Looper;
|
||||
BMessageFilter Filter('1234');
|
||||
Looper.AddCommonFilter(&Filter);
|
||||
CPPUNIT_ASSERT(Looper.RemoveCommonFilter(&Filter));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
#ifdef ADD_TEST
|
||||
#undef ADD_TEST
|
||||
#endif
|
||||
#define ADD_TEST(__test_name__) \
|
||||
ADD_TEST4(BLooper, suite, TRemoveCommonFilterTest, __test_name__)
|
||||
TestSuite* TRemoveCommonFilterTest::Suite()
|
||||
{
|
||||
TestSuite* suite = new TestSuite("BLooper::RemoveCommonFilter(BMessageFilter*)");
|
||||
|
||||
ADD_TEST(RemoveCommonFilterTest1);
|
||||
ADD_TEST(RemoveCommonFilterTest2);
|
||||
ADD_TEST(RemoveCommonFilterTest3);
|
||||
ADD_TEST(RemoveCommonFilterTest4);
|
||||
|
||||
return suite;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// RemoveCommonFilterTest.h
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef REMOVECOMMONFILTERTEST_H
|
||||
#define REMOVECOMMONFILTERTEST_H
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "../common.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
class TRemoveCommonFilterTest : public TestCase
|
||||
{
|
||||
public:
|
||||
TRemoveCommonFilterTest() {;}
|
||||
TRemoveCommonFilterTest(std::string name) : TestCase(name) {;}
|
||||
|
||||
void RemoveCommonFilterTest1();
|
||||
void RemoveCommonFilterTest2();
|
||||
void RemoveCommonFilterTest3();
|
||||
void RemoveCommonFilterTest4();
|
||||
|
||||
static TestSuite* Suite();
|
||||
};
|
||||
|
||||
#endif //REMOVECOMMONFILTERTEST_H
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user