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