1 /*
2 $Id: MapPolygonTest.cpp 2136 2002-12-03 04:07:21Z jrand $
3
4 This file contains the implementation of the tests which show
5 that BPolygons can be created successfully a number of
6 different ways. The following use cases are tested:
7 - Map To
8
9 */
10
11
12 #include "MapPolygonTest.h"
13 #include "DummyPolygon.h"
14 #include <Point.h>
15 #include <Rect.h>
16 #include <Polygon.h>
17
18 #include <assert.h>
19
20
21 /*
22 * Method: MapPolygonTest::MapPolygonTest()
23 * Descr: This is the constructor for this class.
24 */
25
26
MapPolygonTest(std::string name)27 MapPolygonTest::MapPolygonTest(std::string name) :
28 TestCase(name)
29 {
30 }
31
32
33 /*
34 * Method: MapPolygonTest::~MapPolygonTest()
35 * Descr: This is the destructor for this class.
36 */
37
38
~MapPolygonTest()39 MapPolygonTest::~MapPolygonTest()
40 {
41 }
42
43
44 /*
45 * Method: MapPolygonTest::polygonMatches()
46 * Descr: This member function compares the passed in polygon to the
47 * set of points and the expected frame rectangle.
48 */
49
polygonMatches(BPolygon * srcPoly,const BPoint * pointArray,int numPoints,const BRect expectedFrame)50 void MapPolygonTest::polygonMatches(BPolygon *srcPoly, const BPoint *pointArray,
51 int numPoints, const BRect expectedFrame)
52 {
53 assert(numPoints == srcPoly->CountPoints());
54 assert(expectedFrame == srcPoly->Frame());
55
56 const BPoint *srcPointArray = ((DummyPolygon *)srcPoly)->GetPoints();
57 int i;
58 for(i = 0; i < numPoints; i++) {
59 assert(srcPointArray[i] == pointArray[i]);
60 }
61 }
62
63
64 /*
65 * Method: MapPolygonTest::PerformTest()
66 * Descr: This member function tests the creation of BPolygon's.
67 *
68 * The code does the following:
69 */
70
71
PerformTest(void)72 void MapPolygonTest::PerformTest(void)
73 {
74 const int numPoints = 7;
75 BPoint pointArray[numPoints];
76 pointArray[0].x = 0.0; pointArray[0].y = 10.0;
77 pointArray[1].x = 10.0; pointArray[1].y = 0.0;
78 pointArray[2].x = 10.0; pointArray[2].y = 5.0;
79 pointArray[3].x = 30.0; pointArray[3].y = 5.0;
80 pointArray[4].x = 30.0; pointArray[4].y = 15.0;
81 pointArray[5].x = 10.0; pointArray[5].y = 15.0;
82 pointArray[6].x = 10.0; pointArray[6].y = 20.0;
83 BRect pointArrayFrame(0.0, 0.0, 30.0, 20.0);
84
85 BRect fromRect(1.0, 1.0, 3.0, 3.0);
86 BRect toRect(1.0, 4.0, 5.0, 10.0);
87
88 BPoint mapPointArray[numPoints];
89 mapPointArray[0].x = -1.0; mapPointArray[0].y = 31.0;
90 mapPointArray[1].x = 19.0; mapPointArray[1].y = 1.0;
91 mapPointArray[2].x = 19.0; mapPointArray[2].y = 16.0;
92 mapPointArray[3].x = 59.0; mapPointArray[3].y = 16.0;
93 mapPointArray[4].x = 59.0; mapPointArray[4].y = 46.0;
94 mapPointArray[5].x = 19.0; mapPointArray[5].y = 46.0;
95 mapPointArray[6].x = 19.0; mapPointArray[6].y = 61.0;
96 BRect mapPointArrayFrame(-1.0, 1.0, 59.0, 61.0);
97
98 BPolygon testPoly1(pointArray, numPoints);
99 polygonMatches(&testPoly1, pointArray, numPoints, pointArrayFrame);
100 testPoly1.MapTo(fromRect, toRect);
101 polygonMatches(&testPoly1, mapPointArray, numPoints, mapPointArrayFrame);
102 }
103
104
105 /*
106 * Method: PropertyConstructionTest::suite()
107 * Descr: This static member function returns a test caller for performing
108 * all combinations of "MapPolygonTest".
109 */
110
suite(void)111 Test *MapPolygonTest::suite(void)
112 {
113 typedef CppUnit::TestCaller<MapPolygonTest>
114 MapPolygonTestCaller;
115
116 return(new MapPolygonTestCaller("BPolygon::Map Polygon Test", &MapPolygonTest::PerformTest));
117 }
118