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