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