#include "CreatePolygonTest.h"
#include "DummyPolygon.h"
#include <Point.h>
#include <Rect.h>
#include <Polygon.h>
#include <assert.h>
CreatePolygonTest::CreatePolygonTest(std::string name) :
TestCase(name)
{
}
CreatePolygonTest::~CreatePolygonTest()
{
}
void CreatePolygonTest::polygonMatches(BPolygon *srcPoly, const BPoint *pointArray,
int numPoints, const BRect expectedFrame)
{
assert(numPoints == srcPoly->CountPoints());
assert(expectedFrame == srcPoly->Frame());
const BPoint *srcPointArray = ((DummyPolygon *)srcPoly)->GetPoints();
int i;
for(i = 0; i < numPoints; i++) {
assert(srcPointArray[i] == pointArray[i]);
}
}
void CreatePolygonTest::PerformTest(void)
{
const int numPoints = 7;
BPoint pointArray[numPoints];
pointArray[0].x = 0.0; pointArray[0].y = 10.0;
pointArray[1].x = 10.0; pointArray[1].y = 0.0;
pointArray[2].x = 10.0; pointArray[2].y = 5.0;
pointArray[3].x = 30.0; pointArray[3].y = 5.0;
pointArray[4].x = 30.0; pointArray[4].y = 15.0;
pointArray[5].x = 10.0; pointArray[5].y = 15.0;
pointArray[6].x = 10.0; pointArray[6].y = 20.0;
BRect pointArrayFrame(0.0, 0.0, 30.0, 20.0);
BPolygon testPoly1(pointArray, numPoints);
polygonMatches(&testPoly1, pointArray, numPoints, pointArrayFrame);
BPolygon testPoly2(&testPoly1);
polygonMatches(&testPoly2, pointArray, numPoints, pointArrayFrame);
BPolygon testPoly3;
testPoly3.AddPoints(pointArray, numPoints);
polygonMatches(&testPoly3, pointArray, numPoints, pointArrayFrame);
BPolygon testPoly4;
testPoly4.AddPoints(&pointArray[2], 2);
testPoly4 = testPoly1;
polygonMatches(&testPoly4, pointArray, numPoints, pointArrayFrame);
BPolygon testPoly5(pointArray, 3);
testPoly5.AddPoints(&pointArray[3], numPoints - 3);
polygonMatches(&testPoly5, pointArray, numPoints, pointArrayFrame);
}
Test *CreatePolygonTest::suite(void)
{
typedef CppUnit::TestCaller<CreatePolygonTest>
CreatePolygonTestCaller;
return(new CreatePolygonTestCaller("BPolygon::Create Polygon Test", &CreatePolygonTest::PerformTest));
}