1 /* 2 $Id: RegionExclude.cpp 4235 2003-08-06 06:46:06Z jackburton $ 3 4 This file implements the exclude test for the Haiku BRegion 5 code. 6 7 */ 8 9 10 #include "RegionExclude.h" 11 #include <Region.h> 12 #include <Rect.h> 13 14 #include <assert.h> 15 16 17 /* 18 * Method: RegionExclude::RegionExclude() 19 * Descr: This is the constructor for this class. 20 */ 21 22 RegionExclude::RegionExclude(std::string name) : 23 RegionTestcase(name) 24 { 25 } 26 27 28 /* 29 * Method: RegionExclude::~RegionExclude() 30 * Descr: This is the destructor for this class. 31 */ 32 33 RegionExclude::~RegionExclude() 34 { 35 } 36 37 38 /* 39 * Method: RegionExclude::CheckExclude() 40 * Descr: This member function checks that the result region is in fact 41 * region A with region B excluded. 42 */ 43 44 void RegionExclude::CheckExclude(BRegion *resultRegion, BRegion *testRegionA, 45 BRegion *testRegionB) 46 { 47 bool resultRegionEmpty = RegionIsEmpty(resultRegion); 48 bool testRegionAEmpty = RegionIsEmpty(testRegionA); 49 bool testRegionBEmpty = RegionIsEmpty(testRegionB); 50 51 if (RegionsAreEqual(testRegionA, testRegionB)) { 52 assert(resultRegionEmpty); 53 } 54 55 if (RegionsAreEqual(resultRegion, testRegionA)) { 56 BRegion tempRegion(*testRegionA); 57 tempRegion.IntersectWith(testRegionB); 58 assert(RegionIsEmpty(&tempRegion)); 59 } 60 61 if (RegionsAreEqual(resultRegion, testRegionB)) { 62 assert(resultRegionEmpty); 63 assert(testRegionAEmpty); 64 assert(testRegionBEmpty); 65 } 66 67 if ((!resultRegionEmpty) && (!testRegionAEmpty) && (!testRegionBEmpty)) { 68 BRect resultRegionFrame(resultRegion->Frame()); 69 BRect testRegionAFrame(testRegionA->Frame()); 70 BRect testRegionBFrame(testRegionB->Frame()); 71 72 if (!testRegionAFrame.Intersects(testRegionBFrame)) { 73 assert(testRegionAFrame == resultRegionFrame); 74 assert(RegionsAreEqual(resultRegion, testRegionA)); 75 } else { 76 assert(testRegionAFrame.Contains(resultRegionFrame)); 77 } 78 } 79 80 if (testRegionBEmpty) { 81 assert(RegionsAreEqual(resultRegion, testRegionA)); 82 } else { 83 assert(!RegionsAreEqual(resultRegion, testRegionB)); 84 for(int i = 0; i < testRegionB->CountRects(); i++) { 85 BRect tempRect = testRegionB->RectAt(i); 86 87 assert(testRegionB->Intersects(tempRect)); 88 assert(!resultRegion->Intersects(tempRect)); 89 90 BPoint *pointArray; 91 int numPoints = GetPointsInRect(tempRect, &pointArray); 92 for (int j = 0; j < numPoints; j++) { 93 assert(testRegionB->Contains(pointArray[j])); 94 assert(!resultRegion->Contains(pointArray[j])); 95 } 96 } 97 } 98 99 if (testRegionAEmpty) { 100 assert(resultRegionEmpty); 101 } else { 102 for(int i = 0; i < testRegionA->CountRects(); i++) { 103 BRect tempRect = testRegionA->RectAt(i); 104 105 assert(testRegionA->Intersects(tempRect)); 106 if (!testRegionB->Intersects(tempRect)) { 107 assert(resultRegion->Intersects(tempRect)); 108 } 109 110 BPoint *pointArray; 111 int numPoints = GetPointsInRect(tempRect, &pointArray); 112 for (int j = 0; j < numPoints; j++) { 113 assert(testRegionA->Contains(pointArray[j])); 114 if (testRegionB->Contains(pointArray[j])) { 115 assert(!resultRegion->Contains(pointArray[j])); 116 } else { 117 assert(resultRegion->Contains(pointArray[j])); 118 } 119 } 120 } 121 } 122 123 if (resultRegionEmpty) { 124 BRegion tempRegion(*testRegionA); 125 tempRegion.IntersectWith(testRegionB); 126 assert(RegionsAreEqual(&tempRegion, testRegionA)); 127 } else { 128 assert(!RegionsAreEqual(resultRegion, testRegionB)); 129 for(int i = 0; i < resultRegion->CountRects(); i++) { 130 BRect tempRect = resultRegion->RectAt(i); 131 132 assert(resultRegion->Intersects(tempRect)); 133 assert(testRegionA->Intersects(tempRect)); 134 assert(!testRegionB->Intersects(tempRect)); 135 136 BPoint *pointArray; 137 int numPoints = GetPointsInRect(tempRect, &pointArray); 138 for (int j = 0; j < numPoints; j++) { 139 assert(resultRegion->Contains(pointArray[j])); 140 assert(testRegionA->Contains(pointArray[j])); 141 assert(!testRegionB->Contains(pointArray[j])); 142 } 143 } 144 } 145 } 146 147 148 /* 149 * Method: RegionExclude::testOneRegion() 150 * Descr: This member function performs a test on a single passed in 151 * region. 152 */ 153 154 void RegionExclude::testOneRegion(BRegion *testRegion) 155 { 156 157 } 158 159 160 /* 161 * Method: RegionExclude::testTwoRegions() 162 * Descr: This member function performs a test on two regions passed in. 163 */ 164 165 void RegionExclude::testTwoRegions(BRegion *testRegionA, BRegion *testRegionB) 166 { 167 BRegion tempRegion1(*testRegionA); 168 CheckFrame(&tempRegion1); 169 assert(RegionsAreEqual(&tempRegion1, testRegionA)); 170 171 tempRegion1.Exclude(testRegionB); 172 CheckFrame(&tempRegion1); 173 CheckExclude(&tempRegion1, testRegionA, testRegionB); 174 175 tempRegion1 = *testRegionA; 176 CheckFrame(&tempRegion1); 177 assert(RegionsAreEqual(&tempRegion1, testRegionA)); 178 179 for(int i = 0; i < testRegionB->CountRects(); i++) { 180 tempRegion1.Exclude(testRegionB->RectAt(i)); 181 CheckFrame(&tempRegion1); 182 } 183 CheckExclude(&tempRegion1, testRegionA, testRegionB); 184 } 185 186 187 /* 188 * Method: RegionExclude::suite() 189 * Descr: This static member function returns a test caller for performing 190 * all combinations of "RegionExclude". 191 */ 192 193 Test *RegionExclude::suite(void) 194 { 195 typedef CppUnit::TestCaller<RegionExclude> 196 RegionExcludeCaller; 197 198 return(new RegionExcludeCaller("BRegion::Exclude Test", &RegionExclude::PerformTest)); 199 } 200