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