On behalf of Jeremy Rand, BRegion tests
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4235 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
#include "bbitmap/BitmapTest.h"
|
#include "bbitmap/BitmapTest.h"
|
||||||
#include "bdeskbar/DeskbarTest.h"
|
#include "bdeskbar/DeskbarTest.h"
|
||||||
#include "bpolygon/PolygonTest.h"
|
#include "bpolygon/PolygonTest.h"
|
||||||
|
#include "bregion/RegionTest.h"
|
||||||
|
|
||||||
BTestSuite* getTestSuite() {
|
BTestSuite* getTestSuite() {
|
||||||
BTestSuite *suite = new BTestSuite("Interface");
|
BTestSuite *suite = new BTestSuite("Interface");
|
||||||
@@ -13,6 +14,7 @@ BTestSuite* getTestSuite() {
|
|||||||
suite->addTest("BBitmap", BitmapTestSuite());
|
suite->addTest("BBitmap", BitmapTestSuite());
|
||||||
suite->addTest("BDeskbar", DeskbarTestSuite());
|
suite->addTest("BDeskbar", DeskbarTestSuite());
|
||||||
suite->addTest("BPolygon", PolygonTestSuite());
|
suite->addTest("BPolygon", PolygonTestSuite());
|
||||||
|
suite->addTest("BRegion", RegionTestSuite());
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ SubDir OBOS_TOP src tests kits interface ;
|
|||||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) bbitmap ] ;
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) bbitmap ] ;
|
||||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) bdeskbar ] ;
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) bdeskbar ] ;
|
||||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) bpolygon ] ;
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) bpolygon ] ;
|
||||||
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) bregion ] ;
|
||||||
|
|
||||||
SEARCH_SOURCE += [ FDirName $(TOP) src kits interface ] ;
|
SEARCH_SOURCE += [ FDirName $(TOP) src kits interface ] ;
|
||||||
|
|
||||||
@@ -27,6 +28,15 @@ CommonTestLib libinterfacetest.so
|
|||||||
CreatePolygonTest.cpp
|
CreatePolygonTest.cpp
|
||||||
MapPolygonTest.cpp
|
MapPolygonTest.cpp
|
||||||
|
|
||||||
|
# BRegion
|
||||||
|
RegionTest.cpp
|
||||||
|
RegionTestcase.cpp
|
||||||
|
RegionConstruction.cpp
|
||||||
|
RegionExclude.cpp
|
||||||
|
RegionInclude.cpp
|
||||||
|
RegionIntersect.cpp
|
||||||
|
RegionOffsetBy.cpp
|
||||||
|
|
||||||
: <boot!home!config!lib>libopenbeos.so
|
: <boot!home!config!lib>libopenbeos.so
|
||||||
be stdc++.r4
|
be stdc++.r4
|
||||||
: be stdc++.r4
|
: be stdc++.r4
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
$Id: RegionConstruction.cpp,v 1.1 2003/08/06 06:46:06 jackburton Exp $
|
||||||
|
|
||||||
|
This file implements the construction test for the OpenBeOS BRegion
|
||||||
|
code.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "RegionConstruction.h"
|
||||||
|
#include <Region.h>
|
||||||
|
#include <Rect.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionConstruction::RegionConstruction()
|
||||||
|
* Descr: This is the constructor for this class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
RegionConstruction::RegionConstruction(std::string name) :
|
||||||
|
RegionTestcase(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionConstruction::~RegionConstruction()
|
||||||
|
* Descr: This is the destructor for this class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
RegionConstruction::~RegionConstruction()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionConstruction::testOneRegion()
|
||||||
|
* Descr: This member function performs a test on a single passed in
|
||||||
|
* region.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionConstruction::testOneRegion(BRegion *testRegion)
|
||||||
|
{
|
||||||
|
assert(!testRegion->RectAt(-1).IsValid());
|
||||||
|
assert(!testRegion->RectAt(testRegion->CountRects()).IsValid());
|
||||||
|
|
||||||
|
BRegion tempRegion1(*testRegion);
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, testRegion));
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
|
||||||
|
tempRegion1.MakeEmpty();
|
||||||
|
assert(RegionIsEmpty(&tempRegion1));
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
|
||||||
|
if (!RegionIsEmpty(testRegion)) {
|
||||||
|
assert(!RegionsAreEqual(&tempRegion1, testRegion));
|
||||||
|
for(int i = testRegion->CountRects() - 1; i >= 0; i--) {
|
||||||
|
tempRegion1.Include(testRegion->RectAt(i));
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, testRegion));
|
||||||
|
|
||||||
|
if (!RegionIsEmpty(testRegion)) {
|
||||||
|
BRegion tempRegion2(testRegion->RectAt(0));
|
||||||
|
CheckFrame(&tempRegion2);
|
||||||
|
assert(!RegionIsEmpty(&tempRegion2));
|
||||||
|
|
||||||
|
BRegion tempRegion3;
|
||||||
|
CheckFrame(&tempRegion3);
|
||||||
|
assert(RegionIsEmpty(&tempRegion3));
|
||||||
|
tempRegion3.Set(testRegion->RectAt(0));
|
||||||
|
CheckFrame(&tempRegion3);
|
||||||
|
assert(!RegionIsEmpty(&tempRegion3));
|
||||||
|
|
||||||
|
tempRegion1.Set(testRegion->RectAt(0));
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
assert(!RegionIsEmpty(&tempRegion1));
|
||||||
|
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, &tempRegion2));
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, &tempRegion3));
|
||||||
|
assert(RegionsAreEqual(&tempRegion2, &tempRegion3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionConstruction::testTwoRegions()
|
||||||
|
* Descr: This member function performs a test on two regions passed in.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionConstruction::testTwoRegions(BRegion *testRegionA, BRegion *testRegionB)
|
||||||
|
{
|
||||||
|
BRegion tempRegion1;
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
assert(RegionIsEmpty(&tempRegion1));
|
||||||
|
|
||||||
|
tempRegion1 = *testRegionA;
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, testRegionA));
|
||||||
|
|
||||||
|
tempRegion1 = *testRegionB;
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, testRegionB));
|
||||||
|
|
||||||
|
tempRegion1.MakeEmpty();
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
assert(RegionIsEmpty(&tempRegion1));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionConstruction::suite()
|
||||||
|
* Descr: This static member function returns a test caller for performing
|
||||||
|
* all combinations of "RegionConstruction".
|
||||||
|
*/
|
||||||
|
|
||||||
|
Test *RegionConstruction::suite(void)
|
||||||
|
{
|
||||||
|
typedef CppUnit::TestCaller<RegionConstruction>
|
||||||
|
RegionConstructionCaller;
|
||||||
|
|
||||||
|
return(new RegionConstructionCaller("BRegion::Construction Test", &RegionConstruction::PerformTest));
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
$Id: RegionConstruction.h,v 1.1 2003/08/06 06:46:06 jackburton Exp $
|
||||||
|
|
||||||
|
This file defines a class for performing one test of BRegion
|
||||||
|
functionality.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef RegionConstruction_H
|
||||||
|
#define RegionConstruction_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "RegionTestcase.h"
|
||||||
|
|
||||||
|
|
||||||
|
class RegionConstruction :
|
||||||
|
public RegionTestcase {
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void testOneRegion(BRegion *);
|
||||||
|
virtual void testTwoRegions(BRegion *, BRegion *);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Test *suite(void);
|
||||||
|
RegionConstruction(std::string name = "");
|
||||||
|
virtual ~RegionConstruction();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,197 @@
|
|||||||
|
/*
|
||||||
|
$Id: RegionExclude.cpp,v 1.1 2003/08/06 06:46:06 jackburton Exp $
|
||||||
|
|
||||||
|
This file implements the exclude test for the OpenBeOS BRegion
|
||||||
|
code.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "RegionExclude.h"
|
||||||
|
#include <Region.h>
|
||||||
|
#include <Rect.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionExclude::RegionExclude()
|
||||||
|
* Descr: This is the constructor for this class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
RegionExclude::RegionExclude(std::string name) :
|
||||||
|
RegionTestcase(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionExclude::~RegionExclude()
|
||||||
|
* Descr: This is the destructor for this class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
RegionExclude::~RegionExclude()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionExclude::CheckExclude()
|
||||||
|
* Descr: This member function checks that the result region is in fact
|
||||||
|
* region A with region B excluded.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionExclude::CheckExclude(BRegion *resultRegion, BRegion *testRegionA,
|
||||||
|
BRegion *testRegionB)
|
||||||
|
{
|
||||||
|
bool resultRegionEmpty = RegionIsEmpty(resultRegion);
|
||||||
|
bool testRegionAEmpty = RegionIsEmpty(testRegionA);
|
||||||
|
bool testRegionBEmpty = RegionIsEmpty(testRegionB);
|
||||||
|
|
||||||
|
if (RegionsAreEqual(testRegionA, testRegionB)) {
|
||||||
|
assert(resultRegionEmpty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RegionsAreEqual(resultRegion, testRegionA)) {
|
||||||
|
BRegion tempRegion(*testRegionA);
|
||||||
|
tempRegion.IntersectWith(testRegionB);
|
||||||
|
assert(RegionIsEmpty(&tempRegion));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RegionsAreEqual(resultRegion, testRegionB)) {
|
||||||
|
assert(resultRegionEmpty);
|
||||||
|
assert(testRegionAEmpty);
|
||||||
|
assert(testRegionBEmpty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!resultRegionEmpty) && (!testRegionAEmpty) && (!testRegionBEmpty)) {
|
||||||
|
BRect resultRegionFrame(resultRegion->Frame());
|
||||||
|
BRect testRegionAFrame(testRegionA->Frame());
|
||||||
|
BRect testRegionBFrame(testRegionB->Frame());
|
||||||
|
|
||||||
|
if (!testRegionAFrame.Intersects(testRegionBFrame)) {
|
||||||
|
assert(testRegionAFrame == resultRegionFrame);
|
||||||
|
assert(RegionsAreEqual(resultRegion, testRegionA));
|
||||||
|
} else {
|
||||||
|
assert(testRegionAFrame.Contains(resultRegionFrame));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (testRegionBEmpty) {
|
||||||
|
assert(RegionsAreEqual(resultRegion, testRegionA));
|
||||||
|
} else {
|
||||||
|
assert(!RegionsAreEqual(resultRegion, testRegionB));
|
||||||
|
for(int i = 0; i < testRegionB->CountRects(); i++) {
|
||||||
|
BRect tempRect = testRegionB->RectAt(i);
|
||||||
|
|
||||||
|
assert(testRegionB->Intersects(tempRect));
|
||||||
|
assert(!resultRegion->Intersects(tempRect));
|
||||||
|
|
||||||
|
BPoint *pointArray;
|
||||||
|
int numPoints = GetPointsInRect(tempRect, &pointArray);
|
||||||
|
for (int j = 0; j < numPoints; j++) {
|
||||||
|
assert(testRegionB->Contains(pointArray[j]));
|
||||||
|
assert(!resultRegion->Contains(pointArray[j]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (testRegionAEmpty) {
|
||||||
|
assert(resultRegionEmpty);
|
||||||
|
} else {
|
||||||
|
for(int i = 0; i < testRegionA->CountRects(); i++) {
|
||||||
|
BRect tempRect = testRegionA->RectAt(i);
|
||||||
|
|
||||||
|
assert(testRegionA->Intersects(tempRect));
|
||||||
|
if (!testRegionB->Intersects(tempRect)) {
|
||||||
|
assert(resultRegion->Intersects(tempRect));
|
||||||
|
}
|
||||||
|
|
||||||
|
BPoint *pointArray;
|
||||||
|
int numPoints = GetPointsInRect(tempRect, &pointArray);
|
||||||
|
for (int j = 0; j < numPoints; j++) {
|
||||||
|
assert(testRegionA->Contains(pointArray[j]));
|
||||||
|
if (testRegionB->Contains(pointArray[j])) {
|
||||||
|
assert(!resultRegion->Contains(pointArray[j]));
|
||||||
|
} else {
|
||||||
|
assert(resultRegion->Contains(pointArray[j]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resultRegionEmpty) {
|
||||||
|
BRegion tempRegion(*testRegionA);
|
||||||
|
tempRegion.IntersectWith(testRegionB);
|
||||||
|
assert(RegionsAreEqual(&tempRegion, testRegionA));
|
||||||
|
} else {
|
||||||
|
assert(!RegionsAreEqual(resultRegion, testRegionB));
|
||||||
|
for(int i = 0; i < resultRegion->CountRects(); i++) {
|
||||||
|
BRect tempRect = resultRegion->RectAt(i);
|
||||||
|
|
||||||
|
assert(resultRegion->Intersects(tempRect));
|
||||||
|
assert(testRegionA->Intersects(tempRect));
|
||||||
|
assert(!testRegionB->Intersects(tempRect));
|
||||||
|
|
||||||
|
BPoint *pointArray;
|
||||||
|
int numPoints = GetPointsInRect(tempRect, &pointArray);
|
||||||
|
for (int j = 0; j < numPoints; j++) {
|
||||||
|
assert(resultRegion->Contains(pointArray[j]));
|
||||||
|
assert(testRegionA->Contains(pointArray[j]));
|
||||||
|
assert(!testRegionB->Contains(pointArray[j]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionExclude::testOneRegion()
|
||||||
|
* Descr: This member function performs a test on a single passed in
|
||||||
|
* region.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionExclude::testOneRegion(BRegion *testRegion)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionExclude::testTwoRegions()
|
||||||
|
* Descr: This member function performs a test on two regions passed in.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionExclude::testTwoRegions(BRegion *testRegionA, BRegion *testRegionB)
|
||||||
|
{
|
||||||
|
BRegion tempRegion1(*testRegionA);
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, testRegionA));
|
||||||
|
|
||||||
|
tempRegion1.Exclude(testRegionB);
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
CheckExclude(&tempRegion1, testRegionA, testRegionB);
|
||||||
|
|
||||||
|
tempRegion1 = *testRegionA;
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, testRegionA));
|
||||||
|
|
||||||
|
for(int i = 0; i < testRegionB->CountRects(); i++) {
|
||||||
|
tempRegion1.Exclude(testRegionB->RectAt(i));
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
}
|
||||||
|
CheckExclude(&tempRegion1, testRegionA, testRegionB);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionExclude::suite()
|
||||||
|
* Descr: This static member function returns a test caller for performing
|
||||||
|
* all combinations of "RegionExclude".
|
||||||
|
*/
|
||||||
|
|
||||||
|
Test *RegionExclude::suite(void)
|
||||||
|
{
|
||||||
|
typedef CppUnit::TestCaller<RegionExclude>
|
||||||
|
RegionExcludeCaller;
|
||||||
|
|
||||||
|
return(new RegionExcludeCaller("BRegion::Exclude Test", &RegionExclude::PerformTest));
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
$Id: RegionExclude.h,v 1.1 2003/08/06 06:46:06 jackburton Exp $
|
||||||
|
|
||||||
|
This file defines a class for performing one test of BRegion
|
||||||
|
functionality.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef RegionExclude_H
|
||||||
|
#define RegionExclude_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "RegionTestcase.h"
|
||||||
|
|
||||||
|
|
||||||
|
class RegionExclude :
|
||||||
|
public RegionTestcase {
|
||||||
|
|
||||||
|
private:
|
||||||
|
void CheckExclude(BRegion *, BRegion *, BRegion *);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void testOneRegion(BRegion *);
|
||||||
|
virtual void testTwoRegions(BRegion *, BRegion *);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Test *suite(void);
|
||||||
|
RegionExclude(std::string name = "");
|
||||||
|
virtual ~RegionExclude();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,183 @@
|
|||||||
|
/*
|
||||||
|
$Id: RegionInclude.cpp,v 1.1 2003/08/06 06:46:06 jackburton Exp $
|
||||||
|
|
||||||
|
This file implements the include test for the OpenBeOS BRegion
|
||||||
|
code.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "RegionInclude.h"
|
||||||
|
#include <Region.h>
|
||||||
|
#include <Rect.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionInclude::RegionInclude()
|
||||||
|
* Descr: This is the constructor for this class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
RegionInclude::RegionInclude(std::string name) :
|
||||||
|
RegionTestcase(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionInclude::~RegionInclude()
|
||||||
|
* Descr: This is the destructor for this class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
RegionInclude::~RegionInclude()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionExclude::CheckInclude()
|
||||||
|
* Descr: This member function checks that the result region is in fact
|
||||||
|
* region A with region B included.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionInclude::CheckInclude(BRegion *resultRegion, BRegion *testRegionA,
|
||||||
|
BRegion *testRegionB)
|
||||||
|
{
|
||||||
|
bool resultRegionEmpty = RegionIsEmpty(resultRegion);
|
||||||
|
bool testRegionAEmpty = RegionIsEmpty(testRegionA);
|
||||||
|
bool testRegionBEmpty = RegionIsEmpty(testRegionB);
|
||||||
|
|
||||||
|
if (RegionsAreEqual(testRegionA, testRegionB)) {
|
||||||
|
assert(RegionsAreEqual(resultRegion, testRegionA));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RegionsAreEqual(resultRegion, testRegionA)) {
|
||||||
|
BRegion tempRegion(*testRegionA);
|
||||||
|
tempRegion.IntersectWith(testRegionB);
|
||||||
|
assert(RegionsAreEqual(&tempRegion, testRegionB));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RegionsAreEqual(resultRegion, testRegionB)) {
|
||||||
|
BRegion tempRegion(*testRegionA);
|
||||||
|
tempRegion.IntersectWith(testRegionB);
|
||||||
|
assert(RegionsAreEqual(&tempRegion, testRegionA));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!resultRegionEmpty) && (!testRegionAEmpty) && (!testRegionBEmpty)) {
|
||||||
|
BRect resultRegionFrame(resultRegion->Frame());
|
||||||
|
BRect testRegionAFrame(testRegionA->Frame());
|
||||||
|
BRect testRegionBFrame(testRegionB->Frame());
|
||||||
|
|
||||||
|
assert(resultRegionFrame == (testRegionAFrame | testRegionBFrame));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (testRegionBEmpty) {
|
||||||
|
assert(RegionsAreEqual(resultRegion, testRegionA));
|
||||||
|
} else {
|
||||||
|
for(int i = 0; i < testRegionB->CountRects(); i++) {
|
||||||
|
BRect tempRect = testRegionB->RectAt(i);
|
||||||
|
|
||||||
|
assert(testRegionB->Intersects(tempRect));
|
||||||
|
assert(resultRegion->Intersects(tempRect));
|
||||||
|
|
||||||
|
BPoint *pointArray;
|
||||||
|
int numPoints = GetPointsInRect(tempRect, &pointArray);
|
||||||
|
for (int j = 0; j < numPoints; j++) {
|
||||||
|
assert(testRegionB->Contains(pointArray[j]));
|
||||||
|
assert(resultRegion->Contains(pointArray[j]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (testRegionAEmpty) {
|
||||||
|
assert(RegionsAreEqual(resultRegion, testRegionB));
|
||||||
|
} else {
|
||||||
|
for(int i = 0; i < testRegionA->CountRects(); i++) {
|
||||||
|
BRect tempRect = testRegionA->RectAt(i);
|
||||||
|
|
||||||
|
assert(testRegionA->Intersects(tempRect));
|
||||||
|
assert(resultRegion->Intersects(tempRect));
|
||||||
|
|
||||||
|
BPoint *pointArray;
|
||||||
|
int numPoints = GetPointsInRect(tempRect, &pointArray);
|
||||||
|
for (int j = 0; j < numPoints; j++) {
|
||||||
|
assert(testRegionA->Contains(pointArray[j]));
|
||||||
|
assert(resultRegion->Contains(pointArray[j]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resultRegionEmpty) {
|
||||||
|
assert(testRegionAEmpty);
|
||||||
|
assert(testRegionBEmpty);
|
||||||
|
} else {
|
||||||
|
for(int i = 0; i < resultRegion->CountRects(); i++) {
|
||||||
|
BRect tempRect = resultRegion->RectAt(i);
|
||||||
|
|
||||||
|
assert(resultRegion->Intersects(tempRect));
|
||||||
|
assert((testRegionA->Intersects(tempRect)) ||
|
||||||
|
(testRegionB->Intersects(tempRect)));
|
||||||
|
|
||||||
|
BPoint *pointArray;
|
||||||
|
int numPoints = GetPointsInRect(tempRect, &pointArray);
|
||||||
|
for (int j = 0; j < numPoints; j++) {
|
||||||
|
assert(resultRegion->Contains(pointArray[j]));
|
||||||
|
assert((testRegionA->Contains(pointArray[j])) ||
|
||||||
|
(testRegionB->Contains(pointArray[j])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionInclude::testOneRegion()
|
||||||
|
* Descr: This member function performs a test on a single passed in
|
||||||
|
* region.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionInclude::testOneRegion(BRegion *testRegion)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionInclude::testTwoRegions()
|
||||||
|
* Descr: This member function performs a test on two regions passed in.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionInclude::testTwoRegions(BRegion *testRegionA, BRegion *testRegionB)
|
||||||
|
{
|
||||||
|
BRegion tempRegion1(*testRegionA);
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, testRegionA));
|
||||||
|
|
||||||
|
tempRegion1.Include(testRegionB);
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
CheckInclude(&tempRegion1, testRegionA, testRegionB);
|
||||||
|
|
||||||
|
tempRegion1 = *testRegionA;
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, testRegionA));
|
||||||
|
|
||||||
|
for(int i = 0; i < testRegionB->CountRects(); i++) {
|
||||||
|
tempRegion1.Include(testRegionB->RectAt(i));
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
}
|
||||||
|
CheckInclude(&tempRegion1, testRegionA, testRegionB);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionInclude::suite()
|
||||||
|
* Descr: This static member function returns a test caller for performing
|
||||||
|
* all combinations of "RegionInclude".
|
||||||
|
*/
|
||||||
|
|
||||||
|
Test *RegionInclude::suite(void)
|
||||||
|
{
|
||||||
|
typedef CppUnit::TestCaller<RegionInclude>
|
||||||
|
RegionIncludeCaller;
|
||||||
|
|
||||||
|
return(new RegionIncludeCaller("BRegion::Include Test", &RegionInclude::PerformTest));
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
$Id: RegionInclude.h,v 1.1 2003/08/06 06:46:06 jackburton Exp $
|
||||||
|
|
||||||
|
This file defines a class for performing one test of BRegion
|
||||||
|
functionality.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef RegionInclude_H
|
||||||
|
#define RegionInclude_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "RegionTestcase.h"
|
||||||
|
|
||||||
|
|
||||||
|
class RegionInclude :
|
||||||
|
public RegionTestcase {
|
||||||
|
|
||||||
|
private:
|
||||||
|
void CheckInclude(BRegion *, BRegion *, BRegion *);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void testOneRegion(BRegion *);
|
||||||
|
virtual void testTwoRegions(BRegion *, BRegion *);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Test *suite(void);
|
||||||
|
RegionInclude(std::string name = "");
|
||||||
|
virtual ~RegionInclude();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,195 @@
|
|||||||
|
/*
|
||||||
|
$Id: RegionIntersect.cpp,v 1.1 2003/08/06 06:46:06 jackburton Exp $
|
||||||
|
|
||||||
|
This file implements the intersect test for the OpenBeOS BRegion
|
||||||
|
code.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "RegionIntersect.h"
|
||||||
|
#include <Region.h>
|
||||||
|
#include <Rect.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionIntersect::RegionIntersect()
|
||||||
|
* Descr: This is the constructor for this class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
RegionIntersect::RegionIntersect(std::string name) :
|
||||||
|
RegionTestcase(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionIntersect::~RegionIntersect()
|
||||||
|
* Descr: This is the destructor for this class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
RegionIntersect::~RegionIntersect()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionExclude::CheckIntersect()
|
||||||
|
* Descr: This member function checks that the result region is in fact
|
||||||
|
* region A with region B intersected.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionIntersect::CheckIntersect(BRegion *resultRegion, BRegion *testRegionA,
|
||||||
|
BRegion *testRegionB)
|
||||||
|
{
|
||||||
|
bool resultRegionEmpty = RegionIsEmpty(resultRegion);
|
||||||
|
bool testRegionAEmpty = RegionIsEmpty(testRegionA);
|
||||||
|
bool testRegionBEmpty = RegionIsEmpty(testRegionB);
|
||||||
|
|
||||||
|
if (RegionsAreEqual(testRegionA, testRegionB)) {
|
||||||
|
assert(RegionsAreEqual(resultRegion, testRegionA));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RegionsAreEqual(resultRegion, testRegionA)) {
|
||||||
|
BRegion tempRegion(*testRegionA);
|
||||||
|
tempRegion.Include(testRegionB);
|
||||||
|
assert(RegionsAreEqual(&tempRegion, testRegionB));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RegionsAreEqual(resultRegion, testRegionB)) {
|
||||||
|
BRegion tempRegion(*testRegionA);
|
||||||
|
tempRegion.Include(testRegionB);
|
||||||
|
assert(RegionsAreEqual(&tempRegion, testRegionA));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!resultRegionEmpty) && (!testRegionAEmpty) && (!testRegionBEmpty)) {
|
||||||
|
BRect resultRegionFrame(resultRegion->Frame());
|
||||||
|
BRect testRegionAFrame(testRegionA->Frame());
|
||||||
|
BRect testRegionBFrame(testRegionB->Frame());
|
||||||
|
BRect tempRect = (testRegionAFrame & testRegionBFrame);
|
||||||
|
|
||||||
|
assert(tempRect.Contains(resultRegionFrame));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (testRegionBEmpty) {
|
||||||
|
assert(resultRegionEmpty);
|
||||||
|
} else {
|
||||||
|
for(int i = 0; i < testRegionB->CountRects(); i++) {
|
||||||
|
BRect tempRect = testRegionB->RectAt(i);
|
||||||
|
|
||||||
|
assert(testRegionB->Intersects(tempRect));
|
||||||
|
if (testRegionA->Intersects(tempRect)) {
|
||||||
|
assert(resultRegion->Intersects(tempRect));
|
||||||
|
} else {
|
||||||
|
assert(!resultRegion->Intersects(tempRect));
|
||||||
|
}
|
||||||
|
|
||||||
|
BPoint *pointArray;
|
||||||
|
int numPoints = GetPointsInRect(tempRect, &pointArray);
|
||||||
|
for (int j = 0; j < numPoints; j++) {
|
||||||
|
assert(testRegionB->Contains(pointArray[j]));
|
||||||
|
if (testRegionA->Contains(pointArray[j])) {
|
||||||
|
assert(resultRegion->Contains(pointArray[j]));
|
||||||
|
} else {
|
||||||
|
assert(!resultRegion->Contains(pointArray[j]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (testRegionAEmpty) {
|
||||||
|
assert(resultRegionEmpty);
|
||||||
|
} else {
|
||||||
|
for(int i = 0; i < testRegionA->CountRects(); i++) {
|
||||||
|
BRect tempRect = testRegionA->RectAt(i);
|
||||||
|
|
||||||
|
assert(testRegionA->Intersects(tempRect));
|
||||||
|
if (testRegionB->Intersects(tempRect)) {
|
||||||
|
assert(resultRegion->Intersects(tempRect));
|
||||||
|
} else {
|
||||||
|
assert(!resultRegion->Intersects(tempRect));
|
||||||
|
}
|
||||||
|
|
||||||
|
BPoint *pointArray;
|
||||||
|
int numPoints = GetPointsInRect(tempRect, &pointArray);
|
||||||
|
for (int j = 0; j < numPoints; j++) {
|
||||||
|
assert(testRegionA->Contains(pointArray[j]));
|
||||||
|
if (testRegionB->Contains(pointArray[j])) {
|
||||||
|
assert(resultRegion->Contains(pointArray[j]));
|
||||||
|
} else {
|
||||||
|
assert(!resultRegion->Contains(pointArray[j]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resultRegionEmpty) {
|
||||||
|
BRegion tempRegion(*testRegionA);
|
||||||
|
tempRegion.Exclude(testRegionB);
|
||||||
|
assert(RegionsAreEqual(&tempRegion, testRegionA));
|
||||||
|
|
||||||
|
tempRegion = *testRegionB;
|
||||||
|
tempRegion.Exclude(testRegionA);
|
||||||
|
assert(RegionsAreEqual(&tempRegion, testRegionB));
|
||||||
|
} else {
|
||||||
|
for(int i = 0; i < resultRegion->CountRects(); i++) {
|
||||||
|
BRect tempRect = resultRegion->RectAt(i);
|
||||||
|
|
||||||
|
assert(resultRegion->Intersects(tempRect));
|
||||||
|
assert(testRegionA->Intersects(tempRect));
|
||||||
|
assert(testRegionB->Intersects(tempRect));
|
||||||
|
|
||||||
|
BPoint *pointArray;
|
||||||
|
int numPoints = GetPointsInRect(tempRect, &pointArray);
|
||||||
|
for (int j = 0; j < numPoints; j++) {
|
||||||
|
assert(resultRegion->Contains(pointArray[j]));
|
||||||
|
assert(testRegionA->Contains(pointArray[j]));
|
||||||
|
assert(testRegionB->Contains(pointArray[j]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionIntersect::testOneRegion()
|
||||||
|
* Descr: This member function performs a test on a single passed in
|
||||||
|
* region.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionIntersect::testOneRegion(BRegion *testRegion)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionIntersect::testTwoRegions()
|
||||||
|
* Descr: This member function performs a test on two regions passed in.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionIntersect::testTwoRegions(BRegion *testRegionA, BRegion *testRegionB)
|
||||||
|
{
|
||||||
|
BRegion tempRegion1(*testRegionA);
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, testRegionA));
|
||||||
|
|
||||||
|
tempRegion1.IntersectWith(testRegionB);
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
CheckIntersect(&tempRegion1, testRegionA, testRegionB);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionIntersect::suite()
|
||||||
|
* Descr: This static member function returns a test caller for performing
|
||||||
|
* all combinations of "RegionIntersect".
|
||||||
|
*/
|
||||||
|
|
||||||
|
Test *RegionIntersect::suite(void)
|
||||||
|
{
|
||||||
|
typedef CppUnit::TestCaller<RegionIntersect>
|
||||||
|
RegionIntersectCaller;
|
||||||
|
|
||||||
|
return(new RegionIntersectCaller("BRegion::Intersect Test", &RegionIntersect::PerformTest));
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
$Id: RegionIntersect.h,v 1.1 2003/08/06 06:46:06 jackburton Exp $
|
||||||
|
|
||||||
|
This file defines a class for performing one test of BRegion
|
||||||
|
functionality.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef RegionIntersect_H
|
||||||
|
#define RegionIntersect_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "RegionTestcase.h"
|
||||||
|
|
||||||
|
|
||||||
|
class RegionIntersect :
|
||||||
|
public RegionTestcase {
|
||||||
|
|
||||||
|
private:
|
||||||
|
void CheckIntersect(BRegion *, BRegion *, BRegion *);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void testOneRegion(BRegion *);
|
||||||
|
virtual void testTwoRegions(BRegion *, BRegion *);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Test *suite(void);
|
||||||
|
RegionIntersect(std::string name = "");
|
||||||
|
virtual ~RegionIntersect();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
$Id: RegionOffsetBy.cpp,v 1.1 2003/08/06 06:46:06 jackburton Exp $
|
||||||
|
|
||||||
|
This file implements the OffsetBy test for the OpenBeOS BRegion
|
||||||
|
code.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "RegionOffsetBy.h"
|
||||||
|
#include <Region.h>
|
||||||
|
#include <Rect.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionOffsetBy::RegionOffsetBy()
|
||||||
|
* Descr: This is the constructor for this class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
RegionOffsetBy::RegionOffsetBy(std::string name) :
|
||||||
|
RegionTestcase(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionOffsetBy::~RegionOffsetBy()
|
||||||
|
* Descr: This is the destructor for this class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
RegionOffsetBy::~RegionOffsetBy()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionOffsetBy::testOneRegion()
|
||||||
|
* Descr: This member function performs a test on a single passed in
|
||||||
|
* region.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionOffsetBy::testOneRegion(BRegion *testRegion)
|
||||||
|
{
|
||||||
|
BRegion tempRegion1(*testRegion);
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
|
||||||
|
tempRegion1.OffsetBy(10.0, 20.0);
|
||||||
|
if (RegionIsEmpty(testRegion)) {
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, testRegion));
|
||||||
|
} else {
|
||||||
|
assert(!RegionsAreEqual(&tempRegion1, testRegion));
|
||||||
|
}
|
||||||
|
|
||||||
|
BRegion tempRegion2;
|
||||||
|
CheckFrame(&tempRegion2);
|
||||||
|
assert(RegionIsEmpty(&tempRegion2));
|
||||||
|
|
||||||
|
for(int i = testRegion->CountRects() - 1; i >= 0; i--) {
|
||||||
|
BRect tempRect = testRegion->RectAt(i);
|
||||||
|
tempRect.OffsetBy(10.0, 20.0);
|
||||||
|
tempRegion2.Include(tempRect);
|
||||||
|
CheckFrame(&tempRegion2);
|
||||||
|
assert(!RegionIsEmpty(&tempRegion2));
|
||||||
|
}
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, &tempRegion2));
|
||||||
|
if (RegionIsEmpty(testRegion)) {
|
||||||
|
assert(RegionsAreEqual(&tempRegion2, testRegion));
|
||||||
|
} else {
|
||||||
|
assert(!RegionsAreEqual(&tempRegion2, testRegion));
|
||||||
|
}
|
||||||
|
|
||||||
|
tempRegion1.OffsetBy(-10.0, -20.0);
|
||||||
|
CheckFrame(&tempRegion1);
|
||||||
|
if (RegionIsEmpty(testRegion)) {
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, testRegion));
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, &tempRegion2));
|
||||||
|
} else {
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, testRegion));
|
||||||
|
assert(!RegionsAreEqual(&tempRegion1, &tempRegion2));
|
||||||
|
}
|
||||||
|
|
||||||
|
tempRegion2.OffsetBy(-10.0, -20.0);
|
||||||
|
CheckFrame(&tempRegion2);
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, testRegion));
|
||||||
|
assert(RegionsAreEqual(&tempRegion2, testRegion));
|
||||||
|
assert(RegionsAreEqual(&tempRegion1, &tempRegion2));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionOffsetBy::testTwoRegions()
|
||||||
|
* Descr: This member function performs a test on two regions passed in.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionOffsetBy::testTwoRegions(BRegion *testRegionA, BRegion *testRegionB)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionOffsetBy::suite()
|
||||||
|
* Descr: This static member function returns a test caller for performing
|
||||||
|
* all combinations of "RegionOffsetBy".
|
||||||
|
*/
|
||||||
|
|
||||||
|
Test *RegionOffsetBy::suite(void)
|
||||||
|
{
|
||||||
|
typedef CppUnit::TestCaller<RegionOffsetBy>
|
||||||
|
RegionOffsetByCaller;
|
||||||
|
|
||||||
|
return(new RegionOffsetByCaller("BRegion::OffsetBy Test", &RegionOffsetBy::PerformTest));
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
$Id: RegionOffsetBy.h,v 1.1 2003/08/06 06:46:06 jackburton Exp $
|
||||||
|
|
||||||
|
This file defines a class for performing one test of BRegion
|
||||||
|
functionality.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef RegionOffsetBy_H
|
||||||
|
#define RegionOffsetBy_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "RegionTestcase.h"
|
||||||
|
|
||||||
|
|
||||||
|
class RegionOffsetBy :
|
||||||
|
public RegionTestcase {
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void testOneRegion(BRegion *);
|
||||||
|
virtual void testTwoRegions(BRegion *, BRegion *);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Test *suite(void);
|
||||||
|
RegionOffsetBy(std::string name = "");
|
||||||
|
virtual ~RegionOffsetBy();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
#include "RegionConstruction.h"
|
||||||
|
#include "RegionExclude.h"
|
||||||
|
#include "RegionInclude.h"
|
||||||
|
#include "RegionIntersect.h"
|
||||||
|
#include "RegionOffsetBy.h"
|
||||||
|
|
||||||
|
Test *RegionTestSuite()
|
||||||
|
{
|
||||||
|
TestSuite *testSuite = new TestSuite();
|
||||||
|
|
||||||
|
testSuite->addTest(RegionConstruction::suite());
|
||||||
|
testSuite->addTest(RegionExclude::suite());
|
||||||
|
testSuite->addTest(RegionInclude::suite());
|
||||||
|
testSuite->addTest(RegionIntersect::suite());
|
||||||
|
testSuite->addTest(RegionOffsetBy::suite());
|
||||||
|
|
||||||
|
return(testSuite);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef _region_test_h_
|
||||||
|
#define _region_test_h_
|
||||||
|
|
||||||
|
class CppUnit::Test;
|
||||||
|
|
||||||
|
CppUnit::Test *RegionTestSuite();
|
||||||
|
|
||||||
|
#endif // _region_test_h_
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,245 @@
|
|||||||
|
/*
|
||||||
|
$Id: RegionTestcase.cpp,v 1.1 2003/08/06 06:46:06 jackburton Exp $
|
||||||
|
|
||||||
|
This file implements a base class for all tests of the OpenBeOS
|
||||||
|
BRegion code.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "RegionTestcase.h"
|
||||||
|
#include <Region.h>
|
||||||
|
#include <Rect.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionTestcase::RegionTestcase()
|
||||||
|
* Descr: This is the constructor for this class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
RegionTestcase::RegionTestcase(std::string name) :
|
||||||
|
TestCase(name)
|
||||||
|
{
|
||||||
|
const int numTestRegions = 5;
|
||||||
|
const int numRectsPerRegion = 3;
|
||||||
|
|
||||||
|
float theRegions[numTestRegions][numRectsPerRegion][4] =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{10.0, 10.0, 50.0, 50.0},
|
||||||
|
{25.0, 10.0, 75.0, 40.0},
|
||||||
|
{70.0, 100.0, 90.0, 120.0}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{15.0, 15.0, 45.0, 45.0},
|
||||||
|
{30.0, 15.0, 70.0, 35.0},
|
||||||
|
{75.0, 105.0, 85.0, 115.0}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{15.0, 15.0, 55.0, 55.0},
|
||||||
|
{30.0, 15.0, 80.0, 45.0},
|
||||||
|
{75.0, 105.0, 95.0, 125.0}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{210.0, 210.0, 250.0, 250.0},
|
||||||
|
{225.0, 210.0, 275.0, 240.0},
|
||||||
|
{270.0, 300.0, 290.0, 320.0}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{-50.0, -50.0, -10.0, -10.0},
|
||||||
|
{-75.0, -40.0, -25.0, -10.0},
|
||||||
|
{-90.0, -120.0, -70.0, -100.0}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
listOfRegions.AddItem(new BRegion);
|
||||||
|
for(int regionNum = 0; regionNum < numTestRegions; regionNum++) {
|
||||||
|
BRegion *tempRegion = new BRegion;
|
||||||
|
for(int rectNum = 0; rectNum < numRectsPerRegion; rectNum++) {
|
||||||
|
tempRegion->Include(BRect(theRegions[regionNum][rectNum][0],
|
||||||
|
theRegions[regionNum][rectNum][1],
|
||||||
|
theRegions[regionNum][rectNum][2],
|
||||||
|
theRegions[regionNum][rectNum][3]));
|
||||||
|
}
|
||||||
|
listOfRegions.AddItem(tempRegion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionTestcase::~RegionTestcase()
|
||||||
|
* Descr: This is the destructor for this class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
RegionTestcase::~RegionTestcase()
|
||||||
|
{
|
||||||
|
while(!listOfRegions.IsEmpty()) {
|
||||||
|
delete static_cast<BRegion *>(listOfRegions.RemoveItem((long int)0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionTestcase::GetPointsInRect()
|
||||||
|
* Descr: This member function returns an array of BPoints on the edge and
|
||||||
|
* inside the passed in BRect. It also returns the number of points
|
||||||
|
* in the array.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int RegionTestcase::GetPointsInRect(BRect theRect, BPoint **pointArrayPtr)
|
||||||
|
{
|
||||||
|
*pointArrayPtr = pointArray;
|
||||||
|
if (!theRect.IsValid()) {
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float xIncrement = (theRect.Width() + 1.0) / (numPointsPerSide - 1);
|
||||||
|
float yIncrement = (theRect.Height() + 1.0) / (numPointsPerSide - 1);
|
||||||
|
|
||||||
|
int numPoints = 0;
|
||||||
|
|
||||||
|
for(int i = 0; i < numPointsPerSide; i++) {
|
||||||
|
float xCoord = theRect.left + (i * xIncrement);
|
||||||
|
if (i == numPointsPerSide - 1) {
|
||||||
|
xCoord = theRect.right;
|
||||||
|
}
|
||||||
|
for(int j = 0; j < numPointsPerSide; j++) {
|
||||||
|
float yCoord = theRect.top + (j * yIncrement);
|
||||||
|
if (j == numPointsPerSide - 1) {
|
||||||
|
yCoord = theRect.bottom;
|
||||||
|
}
|
||||||
|
pointArray[numPoints].Set(floor(xCoord), floor(yCoord));
|
||||||
|
assert(theRect.Contains(pointArray[numPoints]));
|
||||||
|
numPoints++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(numPoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionTestcase::CheckFrame()
|
||||||
|
* Descr: This member function checks that the BRegion's frame matches
|
||||||
|
* the regions contents.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionTestcase::CheckFrame(BRegion *theRegion)
|
||||||
|
{
|
||||||
|
BRect theFrame = theRegion->Frame();
|
||||||
|
if (theFrame.IsValid()) {
|
||||||
|
assert(!RegionIsEmpty(theRegion));
|
||||||
|
|
||||||
|
BRect testFrame = theRegion->RectAt(0);
|
||||||
|
assert(theFrame.Contains(testFrame));
|
||||||
|
|
||||||
|
for(int i = 1; i < theRegion->CountRects(); i++) {
|
||||||
|
BRect tempRect = theRegion->RectAt(i);
|
||||||
|
assert(theFrame.Contains(tempRect));
|
||||||
|
testFrame = testFrame | tempRect;
|
||||||
|
}
|
||||||
|
assert(testFrame == theFrame);
|
||||||
|
} else {
|
||||||
|
assert(RegionIsEmpty(theRegion));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionTestcase::RegionsAreEqual()
|
||||||
|
* Descr: This member function returns true if the two BRegion's passed
|
||||||
|
* in are the same, otherwise it returns false.
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool RegionTestcase::RegionsAreEqual(BRegion *regionA, BRegion *regionB)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
if (regionA->CountRects() == regionB->CountRects()) {
|
||||||
|
bool gotAMatch = true;
|
||||||
|
for(int i = 0; i < regionA->CountRects(); i++) {
|
||||||
|
gotAMatch = false;
|
||||||
|
for(int j = 0; j < regionB->CountRects(); j++) {
|
||||||
|
if (regionA->RectAt(i) == regionB->RectAt(j)) {
|
||||||
|
gotAMatch = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!gotAMatch) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (gotAMatch) {
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
BRegion tempRegion(*regionA);
|
||||||
|
|
||||||
|
tempRegion.Exclude(regionB);
|
||||||
|
if (RegionIsEmpty(&tempRegion)) {
|
||||||
|
tempRegion = *regionB;
|
||||||
|
tempRegion.Exclude(regionA);
|
||||||
|
if (RegionIsEmpty(&tempRegion)) {
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
assert(regionA->Frame() == regionB->Frame());
|
||||||
|
if (regionA->CountRects() == 0) {
|
||||||
|
assert(RegionIsEmpty(regionA));
|
||||||
|
assert(RegionIsEmpty(regionB));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionTestcase::RegionsIsEmpty()
|
||||||
|
* Descr: This member function returns true if the BRegion passed
|
||||||
|
* in is an empty region, otherwise it returns false.
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool RegionTestcase::RegionIsEmpty(BRegion *theRegion)
|
||||||
|
{
|
||||||
|
if (theRegion->CountRects() == 0) {
|
||||||
|
assert(!theRegion->Frame().IsValid());
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
assert(theRegion->Frame().IsValid());
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: RegionTestcase::PerformTest()
|
||||||
|
* Descr: This member function iterates over the set of BRegion's for
|
||||||
|
* testing and calls testOneRegion() for each region. Then it
|
||||||
|
* calls testTwoRegions() for each pair of regions (including
|
||||||
|
* when the two regions are the same).
|
||||||
|
*/
|
||||||
|
|
||||||
|
void RegionTestcase::PerformTest(void)
|
||||||
|
{
|
||||||
|
int numItems = listOfRegions.CountItems();
|
||||||
|
|
||||||
|
for(int i = 0; i < numItems; i++) {
|
||||||
|
BRegion *testRegion = static_cast<BRegion *>(listOfRegions.ItemAt(i));
|
||||||
|
|
||||||
|
CheckFrame(testRegion);
|
||||||
|
testOneRegion(testRegion);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < numItems; i++) {
|
||||||
|
BRegion *testRegionA = static_cast<BRegion *>(listOfRegions.ItemAt(i));
|
||||||
|
|
||||||
|
for(int j = 0; j < numItems; j++) {
|
||||||
|
BRegion *testRegionB = static_cast<BRegion *>(listOfRegions.ItemAt(j));
|
||||||
|
|
||||||
|
testTwoRegions(testRegionA, testRegionB);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
$Id: RegionTestcase.h,v 1.1 2003/08/06 06:46:06 jackburton Exp $
|
||||||
|
|
||||||
|
This file defines a base class for performing all tests of BRegion
|
||||||
|
functionality.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef RegionTestcase_H
|
||||||
|
#define RegionTestcase_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "../common.h"
|
||||||
|
#include <List.h>
|
||||||
|
#include <Rect.h>
|
||||||
|
#include <Point.h>
|
||||||
|
|
||||||
|
|
||||||
|
class BRegion;
|
||||||
|
|
||||||
|
|
||||||
|
class RegionTestcase :
|
||||||
|
public TestCase {
|
||||||
|
|
||||||
|
private:
|
||||||
|
BList listOfRegions;
|
||||||
|
|
||||||
|
#define numPointsPerSide 17
|
||||||
|
BPoint pointArray[numPointsPerSide * numPointsPerSide];
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int GetPointsInRect(BRect, BPoint **);
|
||||||
|
void CheckFrame(BRegion *);
|
||||||
|
bool RegionsAreEqual(BRegion *, BRegion *);
|
||||||
|
bool RegionIsEmpty(BRegion *);
|
||||||
|
|
||||||
|
virtual void testOneRegion(BRegion *) = 0;
|
||||||
|
virtual void testTwoRegions(BRegion *, BRegion *) = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void PerformTest(void);
|
||||||
|
RegionTestcase(std::string name = "");
|
||||||
|
virtual ~RegionTestcase();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user