xref: /haiku/src/tests/kits/interface/bregion/RegionOffsetBy.cpp (revision 4c8e85b316c35a9161f5a1c50ad70bc91c83a76f)
1 /*
2 	$Id: RegionOffsetBy.cpp 4235 2003-08-06 06:46:06Z jackburton $
3 
4 	This file implements the OffsetBy test for the Haiku BRegion
5 	code.
6 
7 	*/
8 
9 
10 #include "RegionOffsetBy.h"
11 #include <Region.h>
12 #include <Rect.h>
13 
14 #include <assert.h>
15 
16 
17 /*
18  *  Method:  RegionOffsetBy::RegionOffsetBy()
19  *   Descr:  This is the constructor for this class.
20  */
21 
22 RegionOffsetBy::RegionOffsetBy(std::string name) :
23 	RegionTestcase(name)
24 {
25 	}
26 
27 
28 /*
29  *  Method:  RegionOffsetBy::~RegionOffsetBy()
30  *   Descr:  This is the destructor for this class.
31  */
32 
33 RegionOffsetBy::~RegionOffsetBy()
34 {
35 	}
36 
37 
38 /*
39  *  Method:  RegionOffsetBy::testOneRegion()
40  *   Descr:  This member function performs a test on a single passed in
41  *           region.
42  */
43 
44 void RegionOffsetBy::testOneRegion(BRegion *testRegion)
45 {
46 	BRegion tempRegion1(*testRegion);
47 	CheckFrame(&tempRegion1);
48 
49 	tempRegion1.OffsetBy(10.0, 20.0);
50 	if (RegionIsEmpty(testRegion)) {
51 		assert(RegionsAreEqual(&tempRegion1, testRegion));
52 	} else {
53 		assert(!RegionsAreEqual(&tempRegion1, testRegion));
54 	}
55 
56 	BRegion tempRegion2;
57 	CheckFrame(&tempRegion2);
58 	assert(RegionIsEmpty(&tempRegion2));
59 
60 	for(int i = testRegion->CountRects() - 1; i >= 0; i--) {
61 		BRect tempRect = testRegion->RectAt(i);
62 		tempRect.OffsetBy(10.0, 20.0);
63 		tempRegion2.Include(tempRect);
64 		CheckFrame(&tempRegion2);
65 		assert(!RegionIsEmpty(&tempRegion2));
66 	}
67 	assert(RegionsAreEqual(&tempRegion1, &tempRegion2));
68 	if (RegionIsEmpty(testRegion)) {
69 		assert(RegionsAreEqual(&tempRegion2, testRegion));
70 	} else {
71 		assert(!RegionsAreEqual(&tempRegion2, testRegion));
72 	}
73 
74 	tempRegion1.OffsetBy(-10.0, -20.0);
75 	CheckFrame(&tempRegion1);
76 	if (RegionIsEmpty(testRegion)) {
77 		assert(RegionsAreEqual(&tempRegion1, testRegion));
78 		assert(RegionsAreEqual(&tempRegion1, &tempRegion2));
79 	} else {
80 		assert(RegionsAreEqual(&tempRegion1, testRegion));
81 		assert(!RegionsAreEqual(&tempRegion1, &tempRegion2));
82 	}
83 
84 	tempRegion2.OffsetBy(-10.0, -20.0);
85 	CheckFrame(&tempRegion2);
86 	assert(RegionsAreEqual(&tempRegion1, testRegion));
87 	assert(RegionsAreEqual(&tempRegion2, testRegion));
88 	assert(RegionsAreEqual(&tempRegion1, &tempRegion2));
89 }
90 
91 
92 /*
93  *  Method:  RegionOffsetBy::testTwoRegions()
94  *   Descr:  This member function performs a test on two regions passed in.
95  */
96 
97 void RegionOffsetBy::testTwoRegions(BRegion *testRegionA, BRegion *testRegionB)
98 {
99 
100 }
101 
102 
103 /*
104  *  Method:  RegionOffsetBy::suite()
105  *   Descr:  This static member function returns a test caller for performing
106  *           all combinations of "RegionOffsetBy".
107  */
108 
109  Test *RegionOffsetBy::suite(void)
110 {
111 	typedef CppUnit::TestCaller<RegionOffsetBy>
112 		RegionOffsetByCaller;
113 
114 	return(new RegionOffsetByCaller("BRegion::OffsetBy Test", &RegionOffsetBy::PerformTest));
115 	}
116