More tests for BLooper.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@286 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
ejakowatz
2002-07-17 19:50:28 +00:00
parent 16ba498087
commit 04de1897ed
6 changed files with 153 additions and 1 deletions
+4 -1
View File
@@ -360,7 +360,10 @@ int32 BLooper::CountHandlers() const
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BHandler* BLooper::HandlerAt(int32 index) const BHandler* BLooper::HandlerAt(int32 index) const
{ {
AssertLocked(); if (!IsLocked())
{
debugger("Looper must be locked before calling HandlerAt.");
}
return (BHandler*)fHandlers.ItemAt(index); return (BHandler*)fHandlers.ItemAt(index);
} }
+1
View File
@@ -47,6 +47,7 @@ HandlerAt(int32 index) const;
case : No handlers added, check for looper itself case : No handlers added, check for looper itself
case : Index out of range (CountHandlers() + 1) case : Index out of range (CountHandlers() + 1)
case : Several handlers added, checked against expected indices case : Several handlers added, checked against expected indices
case : Looper is not locked
IndexOf(BHandler* handler) const; IndexOf(BHandler* handler) const;
-------------- --------------
@@ -0,0 +1,101 @@
//------------------------------------------------------------------------------
// HandlerAtTest.cpp
//
//------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <Handler.h>
#include <Looper.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
#include "HandlerAtTest.h"
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
//------------------------------------------------------------------------------
/**
HandlerAt(int32 index)
@case No handlers added, check for looper itself
@param index 0
@results HandlerAt() returns pointer to Looper.
*/
void THandlerAtTest::HandlerAtTest1()
{
BLooper Looper;
CPPUNIT_ASSERT(Looper.HandlerAt(0) == &Looper);
}
//------------------------------------------------------------------------------
/**
HandlerAt(int32 index)
@case Index out of range (CountHandlers() + 1)
@param index 1 & -1
@results HandlerAt() returns NULL
*/
void THandlerAtTest::HandlerAtTest2()
{
BLooper Looper;
CPPUNIT_ASSERT(Looper.HandlerAt(1) == NULL);
CPPUNIT_ASSERT(Looper.HandlerAt(-1) == NULL);
}
//------------------------------------------------------------------------------
/**
HandlerAt(int32 index)
@case Several handlers added, checked against expected indices
@param index Various
@results
*/
#define CREATE_AND_ADD(XHANDLER) \
BHandler XHANDLER; \
Looper.AddHandler(&XHANDLER);
void THandlerAtTest::HandlerAtTest3()
{
BLooper Looper;
CREATE_AND_ADD(Handler1);
CREATE_AND_ADD(Handler2);
CREATE_AND_ADD(Handler3);
CPPUNIT_ASSERT(Looper.HandlerAt(0) == &Looper);
CPPUNIT_ASSERT(Looper.HandlerAt(1) == &Handler1);
CPPUNIT_ASSERT(Looper.HandlerAt(2) == &Handler2);
CPPUNIT_ASSERT(Looper.HandlerAt(3) == &Handler3);
}
//------------------------------------------------------------------------------
/**
HandlerAt(int32 index)
@case Looper is not locked
@param index 0
@results
*/
void THandlerAtTest::HandlerAtTest4()
{
BLooper Looper;
Looper.Unlock();
CPPUNIT_ASSERT(Looper.HandlerAt(0) == &Looper);
}
//------------------------------------------------------------------------------
TestSuite* THandlerAtTest::Suite()
{
TestSuite* suite = new TestSuite("BLooper::HandlerAt(int32)");
ADD_TEST(suite, THandlerAtTest, HandlerAtTest1);
ADD_TEST(suite, THandlerAtTest, HandlerAtTest2);
ADD_TEST(suite, THandlerAtTest, HandlerAtTest3);
ADD_TEST(suite, THandlerAtTest, HandlerAtTest4);
return suite;
}
//------------------------------------------------------------------------------
/*
* $Log $
*
* $Id $
*
*/
@@ -0,0 +1,44 @@
//------------------------------------------------------------------------------
// HandlerAtTest.h
//
//------------------------------------------------------------------------------
#ifndef HANDLERATTEST_H
#define HANDLERATTEST_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
#include "../common.h"
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
class THandlerAtTest : public TestCase
{
public:
THandlerAtTest() {;}
THandlerAtTest(std::string name) : TestCase(name) {;}
void HandlerAtTest1();
void HandlerAtTest2();
void HandlerAtTest3();
void HandlerAtTest4();
static TestSuite* Suite();
};
#endif //HANDLERATTEST_H
/*
* $Log $
*
* $Id $
*
*/
+1
View File
@@ -6,6 +6,7 @@ CommonUnitTest BLooperTester
RemoveHandlerTest.cpp RemoveHandlerTest.cpp
IndexOfTest.cpp IndexOfTest.cpp
CountHandlersTest.cpp CountHandlersTest.cpp
HandlerAtTest.cpp
: kits app : kits app
: <boot!home!config!lib>libopenbeos.so be stdc++.r4 : <boot!home!config!lib>libopenbeos.so be stdc++.r4
: be stdc++.r4 : be stdc++.r4
+2
View File
@@ -20,6 +20,7 @@
#include "RemoveHandlerTest.h" #include "RemoveHandlerTest.h"
#include "IndexOfTest.h" #include "IndexOfTest.h"
#include "CountHandlersTest.h" #include "CountHandlersTest.h"
#include "HandlerAtTest.h"
// Local Defines --------------------------------------------------------------- // Local Defines ---------------------------------------------------------------
@@ -43,6 +44,7 @@ Test* addonTestFunc(void)
tests->addTest(TRemoveHandlerTest::Suite()); tests->addTest(TRemoveHandlerTest::Suite());
tests->addTest(TIndexOfTest::Suite()); tests->addTest(TIndexOfTest::Suite());
tests->addTest(TCountHandlersTest::Suite()); tests->addTest(TCountHandlersTest::Suite());
tests->addTest(THandlerAtTest::Suite());
return tests; return tests;
} }