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