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