1 /* 2 * Copyright 2015 Julian Harnath <julian.harnath@rwth-aachen.de> 3 * All rights reserved. Distributed under the terms of the MIT license. 4 */ 5 6 #include "SimpleTransformTest.h" 7 8 #include "IntPoint.h" 9 #include "IntRect.h" 10 11 #include <cppunit/TestCaller.h> 12 #include <cppunit/TestSuite.h> 13 14 15 void 16 SimpleTransformTest::TransformPoint() 17 { 18 BPoint point(1.0, 1.0); 19 SimpleTransform specimen; 20 specimen.AddOffset(10.0, 10.0); 21 specimen.Apply(&point); 22 CPPUNIT_ASSERT(point == BPoint(11.0, 11.0)); 23 24 specimen.AddOffset(10.0, 10.0); 25 point.Set(0.0, 0.0); 26 specimen.Apply(&point); 27 CPPUNIT_ASSERT(point == BPoint(20.0, 20.0)); 28 } 29 30 31 void 32 SimpleTransformTest::TransformIntPoint() 33 { 34 IntPoint point(1, 1); 35 SimpleTransform specimen; 36 specimen.AddOffset(10.0, 10.0); 37 specimen.Apply(&point); 38 CPPUNIT_ASSERT(point == BPoint(11.0, 11.0)); 39 } 40 41 42 void 43 SimpleTransformTest::TransformRect() 44 { 45 BRect rect(5.0, 10.0, 15.0, 20.0); 46 SimpleTransform specimen; 47 specimen.AddOffset(10.0, 10.0); 48 specimen.Apply(&rect); 49 CPPUNIT_ASSERT(rect == BRect(15.0, 20.0, 25.0, 30.0)); 50 51 specimen.SetScale(2.5); 52 specimen.Apply(&rect); 53 CPPUNIT_ASSERT(rect == BRect(47.5, 60.0, 72.5, 85.0)); 54 } 55 56 57 void 58 SimpleTransformTest::TransformIntRect() 59 { 60 IntRect rect(5, 10, 15, 20); 61 SimpleTransform specimen; 62 specimen.AddOffset(10.0, 10.0); 63 specimen.Apply(&rect); 64 CPPUNIT_ASSERT(rect == IntRect(15, 20, 25, 30)); 65 66 specimen.SetScale(2); 67 specimen.Apply(&rect); 68 CPPUNIT_ASSERT(rect == BRect(40, 50, 60, 70)); 69 } 70 71 72 void 73 SimpleTransformTest::TransformRegion() 74 { 75 BRegion region; 76 region.Include(BRect( 5.0, 5.0, 20.0, 20.0)); 77 region.Include(BRect(10.0, 10.0, 30.0, 30.0)); 78 region.Exclude(BRect(10.0, 20.0, 20.0, 25.0)); 79 80 BRegion reference1 = region; 81 reference1.OffsetBy(10, 20); 82 83 SimpleTransform specimen; 84 specimen.AddOffset(10.0, 20.0); 85 specimen.Apply(®ion); 86 CPPUNIT_ASSERT(region == reference1); 87 88 specimen.SetScale(2.5); 89 90 BRegion reference2; 91 reference2.Include(BRect(47.0, 82.0, 87.0, 122.0)); 92 reference2.Include(BRect(60.0, 95.0, 112.0, 147.0)); 93 reference2.Exclude(BRect(60.0, 120.0, 86.0, 134.0)); 94 95 specimen.Apply(®ion); 96 CPPUNIT_ASSERT(region == reference2); 97 } 98 99 100 void 101 SimpleTransformTest::TransformGradientLinear() 102 { 103 BGradientLinear gradient(10.0, 20.0, 30.0, 40.0); 104 SimpleTransform specimen; 105 specimen.AddOffset(10.0, 20.0); 106 specimen.SetScale(2.5); 107 specimen.Apply(&gradient); 108 CPPUNIT_ASSERT(gradient.Start() == BPoint(35.0, 70.0)); 109 CPPUNIT_ASSERT(gradient.End() == BPoint(85.0, 120.0)); 110 } 111 112 113 void 114 SimpleTransformTest::TransformGradientRadial() 115 { 116 BGradientRadial gradient(10.0, 20.0, 10.0); 117 SimpleTransform specimen; 118 specimen.AddOffset(10.0, 20.0); 119 specimen.SetScale(2.5); 120 specimen.Apply(&gradient); 121 CPPUNIT_ASSERT(gradient.Center() == BPoint(35.0, 70.0)); 122 } 123 124 125 void 126 SimpleTransformTest::TransformGradientRadialFocus() 127 { 128 BGradientRadialFocus gradient(10.0, 20.0, 10.0, 30.0, 40.0); 129 SimpleTransform specimen; 130 specimen.AddOffset(10.0, 20.0); 131 specimen.SetScale(2.5); 132 specimen.Apply(&gradient); 133 CPPUNIT_ASSERT(gradient.Center() == BPoint(35.0, 70.0)); 134 CPPUNIT_ASSERT(gradient.Focal() == BPoint(85.0, 120.0)); 135 } 136 137 138 void 139 SimpleTransformTest::TransformGradientDiamond() 140 { 141 BGradientDiamond gradient(10.0, 20.0); 142 SimpleTransform specimen; 143 specimen.AddOffset(10.0, 20.0); 144 specimen.SetScale(2.5); 145 specimen.Apply(&gradient); 146 CPPUNIT_ASSERT(gradient.Center() == BPoint(35.0, 70.0)); 147 } 148 149 150 void 151 SimpleTransformTest::TransformGradientConic() 152 { 153 BGradientConic gradient(10.0, 20.0, 10.0); 154 SimpleTransform specimen; 155 specimen.AddOffset(10.0, 20.0); 156 specimen.SetScale(2.5); 157 specimen.Apply(&gradient); 158 CPPUNIT_ASSERT(gradient.Center() == BPoint(35.0, 70.0)); 159 } 160 161 162 void 163 SimpleTransformTest::TransformPointArray() 164 { 165 BPoint points[3]; 166 points[0].Set(10.0, 20.0); 167 points[1].Set(30.0, 40.0); 168 points[2].Set(50.0, 60.0); 169 BPoint transformedPoints[3]; 170 SimpleTransform specimen; 171 specimen.AddOffset(10.0, 20.0); 172 specimen.Apply(&transformedPoints[0], &points[0], 3); 173 CPPUNIT_ASSERT(transformedPoints[0] == BPoint(20.0, 40.0)); 174 CPPUNIT_ASSERT(transformedPoints[1] == BPoint(40.0, 60.0)); 175 CPPUNIT_ASSERT(transformedPoints[2] == BPoint(60.0, 80.0)); 176 } 177 178 179 void 180 SimpleTransformTest::TransformRectArray() 181 { 182 BRect rects[3]; 183 rects[0].Set( 5.0, 10.0, 15.0, 20.0); 184 rects[1].Set(15.0, 20.0, 25.0, 30.0); 185 rects[2].Set(25.0, 30.0, 35.0, 40.0); 186 BRect transformedRects[3]; 187 SimpleTransform specimen; 188 specimen.AddOffset(10.0, 20.0); 189 specimen.SetScale(2.5); 190 specimen.Apply(&transformedRects[0], &rects[0], 3); 191 CPPUNIT_ASSERT(transformedRects[0] == BRect(22.5, 45.0, 47.5, 70.0)); 192 CPPUNIT_ASSERT(transformedRects[1] == BRect(47.5, 70.0, 72.5, 95.0)); 193 CPPUNIT_ASSERT(transformedRects[2] == BRect(72.5, 95.0, 97.5, 120.0)); 194 } 195 196 197 void 198 SimpleTransformTest::TransformRegionArray() 199 { 200 BRegion regions[2]; 201 regions[0].Include(BRect( 5.0, 5.0, 20.0, 20.0)); 202 regions[0].Include(BRect(10.0, 10.0, 30.0, 30.0)); 203 regions[0].Exclude(BRect(10.0, 20.0, 20.0, 25.0)); 204 regions[1].Include(BRect( 5.0, 5.0, 20.0, 20.0)); 205 regions[1].Include(BRect(10.0, 10.0, 30.0, 30.0)); 206 regions[1].Exclude(BRect(10.0, 20.0, 20.0, 25.0)); 207 BRegion transformedRegions[3]; 208 SimpleTransform specimen; 209 specimen.AddOffset(10.0, 20.0); 210 specimen.SetScale(2.5); 211 specimen.Apply(&transformedRegions[0], ®ions[0], 2); 212 BRegion reference; 213 reference.Include(BRect(22.0, 32.0, 62.0, 72.0)); 214 reference.Include(BRect(35.0, 45.0, 87.0, 97.0)); 215 reference.Exclude(BRect(35.0, 70.0, 61.0, 84.0)); 216 217 CPPUNIT_ASSERT(transformedRegions[0] == reference); 218 CPPUNIT_ASSERT(transformedRegions[1] == reference); 219 } 220 221 222 /* static */ void 223 SimpleTransformTest::AddTests(BTestSuite& parent) 224 { 225 CppUnit::TestSuite* const suite = new CppUnit::TestSuite( 226 "SimpleTransformTest"); 227 228 suite->addTest(new CppUnit::TestCaller<SimpleTransformTest>( 229 "SimpleTransformTest::TransformPoint", 230 &SimpleTransformTest::TransformPoint)); 231 suite->addTest(new CppUnit::TestCaller<SimpleTransformTest>( 232 "SimpleTransformTest::TransformIntPoint", 233 &SimpleTransformTest::TransformIntPoint)); 234 suite->addTest(new CppUnit::TestCaller<SimpleTransformTest>( 235 "SimpleTransformTest::TransformRect", 236 &SimpleTransformTest::TransformRect)); 237 suite->addTest(new CppUnit::TestCaller<SimpleTransformTest>( 238 "SimpleTransformTest::TransformIntRect", 239 &SimpleTransformTest::TransformIntRect)); 240 suite->addTest(new CppUnit::TestCaller<SimpleTransformTest>( 241 "SimpleTransformTest::TransformRegion", 242 &SimpleTransformTest::TransformRegion)); 243 suite->addTest(new CppUnit::TestCaller<SimpleTransformTest>( 244 "SimpleTransformTest::TransformGradientLinear", 245 &SimpleTransformTest::TransformGradientLinear)); 246 suite->addTest(new CppUnit::TestCaller<SimpleTransformTest>( 247 "SimpleTransformTest::TransformGradientRadial", 248 &SimpleTransformTest::TransformGradientRadial)); 249 suite->addTest(new CppUnit::TestCaller<SimpleTransformTest>( 250 "SimpleTransformTest::TransformGradientRadialFocus", 251 &SimpleTransformTest::TransformGradientRadialFocus)); 252 suite->addTest(new CppUnit::TestCaller<SimpleTransformTest>( 253 "SimpleTransformTest::TransformGradientDiamond", 254 &SimpleTransformTest::TransformGradientDiamond)); 255 suite->addTest(new CppUnit::TestCaller<SimpleTransformTest>( 256 "SimpleTransformTest::TransformGradientConic", 257 &SimpleTransformTest::TransformGradientConic)); 258 suite->addTest(new CppUnit::TestCaller<SimpleTransformTest>( 259 "SimpleTransformTest::TransformPointArray", 260 &SimpleTransformTest::TransformPointArray)); 261 suite->addTest(new CppUnit::TestCaller<SimpleTransformTest>( 262 "SimpleTransformTest::TransformRectArray", 263 &SimpleTransformTest::TransformRectArray)); 264 suite->addTest(new CppUnit::TestCaller<SimpleTransformTest>( 265 "SimpleTransformTest::TransformRegionArray", 266 &SimpleTransformTest::TransformRegionArray)); 267 268 parent.addTest("SimpleTransformTest", suite); 269 } 270