1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // autogenerated file with codegen.pl 25 26 #include "preextstl.h" 27 #include "cppunit/TestAssert.h" 28 #include "cppunit/TestFixture.h" 29 #include "cppunit/extensions/HelperMacros.h" 30 #include "postextstl.h" 31 32 #include <basegfx/vector/b2isize.hxx> 33 #include <basegfx/range/b2irange.hxx> 34 #include <basegfx/point/b2ipoint.hxx> 35 #include <basegfx/matrix/b2dhommatrix.hxx> 36 #include <basegfx/polygon/b2dpolygon.hxx> 37 #include <basegfx/polygon/b2dpolygontools.hxx> 38 #include <basegfx/polygon/b2dpolypolygon.hxx> 39 #include <basegfx/polygon/b2dpolypolygontools.hxx> 40 41 #include <basebmp/color.hxx> 42 #include <basebmp/scanlineformats.hxx> 43 #include <basebmp/bitmapdevice.hxx> 44 #include <basebmp/debug.hxx> 45 #include "tools.hxx" 46 47 #include <iostream> 48 #include <fstream> 49 50 using namespace ::basebmp; 51 52 namespace 53 { 54 /* 55 std::ofstream output("32bpp_test.dump"); 56 debugDump( rDevice, output ); 57 */ 58 59 class PolyTest : public CppUnit::TestFixture 60 { 61 private: 62 BitmapDeviceSharedPtr mpDevice1bpp; 63 BitmapDeviceSharedPtr mpDevice32bpp; 64 implTestEmpty(const BitmapDeviceSharedPtr & rDevice)65 void implTestEmpty(const BitmapDeviceSharedPtr& rDevice) 66 { 67 const Color aCol(0xFFFFFFFF); 68 const Color aBgCol(0); 69 rDevice->clear(aBgCol); 70 basegfx::B2DPolyPolygon aPoly; 71 ::rtl::OUString aSvg; 72 73 basegfx::tools::importFromSvgD( 74 aPoly, 75 rtl::OUString::createFromAscii( 76 "M2 2 l7 7 z" ) ); 77 rDevice->fillPolyPolygon( 78 aPoly, 79 aCol, 80 DrawMode_PAINT ); 81 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0", 82 countPixel( rDevice, aCol ) == 0); 83 84 // -------------------------------------------------- 85 86 rDevice->clear(aBgCol); 87 aPoly.clear(); 88 basegfx::tools::importFromSvgD( 89 aPoly, 90 rtl::OUString::createFromAscii( 91 "M7 2 l-6 6 z" ) ); 92 rDevice->fillPolyPolygon( 93 aPoly, 94 aCol, 95 DrawMode_PAINT ); 96 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0(b)", 97 countPixel( rDevice, aCol ) == 0); 98 } 99 implTestHairline(const BitmapDeviceSharedPtr & rDevice)100 void implTestHairline(const BitmapDeviceSharedPtr& rDevice) 101 { 102 const Color aCol(0xFFFFFFFF); 103 const Color aBgCol(0); 104 rDevice->clear(aBgCol); 105 basegfx::B2DPolyPolygon aPoly; 106 ::rtl::OUString aSvg; 107 108 basegfx::tools::importFromSvgD( 109 aPoly, 110 rtl::OUString::createFromAscii( 111 "M2 2 h1 l7 7 h-1 z" ) ); 112 rDevice->fillPolyPolygon( 113 aPoly, 114 aCol, 115 DrawMode_PAINT ); 116 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 7", 117 countPixel( rDevice, aCol ) == 7); 118 119 // -------------------------------------------------- 120 121 rDevice->clear(aBgCol); 122 aPoly.clear(); 123 basegfx::tools::importFromSvgD( 124 aPoly, 125 rtl::OUString::createFromAscii( 126 "M7 2 h-1 l-6 6 h1 z" ) ); 127 rDevice->fillPolyPolygon( 128 aPoly, 129 aCol, 130 DrawMode_PAINT ); 131 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 6", 132 countPixel( rDevice, aCol ) == 6); 133 134 // -------------------------------------------------- 135 136 rDevice->clear(aBgCol); 137 aPoly.clear(); 138 basegfx::tools::importFromSvgD( 139 aPoly, 140 rtl::OUString::createFromAscii( 141 "M0 0 l7 7 h-1 l-5-7 z" ) ); 142 rDevice->fillPolyPolygon( 143 aPoly, 144 aCol, 145 DrawMode_PAINT ); 146 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 3", 147 countPixel( rDevice, aCol ) == 3); 148 } 149 implTestPolyPoly(const BitmapDeviceSharedPtr & rDevice)150 void implTestPolyPoly(const BitmapDeviceSharedPtr& rDevice) 151 { 152 const Color aCol(0xFFFFFFFF); 153 const Color aBgCol(0); 154 rDevice->clear(aBgCol); 155 basegfx::B2DPolyPolygon aPoly; 156 ::rtl::OUString aSvg; 157 158 basegfx::tools::importFromSvgD( aPoly, 159 ::rtl::OUString::createFromAscii( 160 "M0 0 h7 v7 h-7 z M2 2 v3 h3 v-3 z" ) ); 161 162 rDevice->fillPolyPolygon( 163 aPoly, 164 aCol, 165 DrawMode_PAINT ); 166 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 40", 167 countPixel( rDevice, aCol ) == 40); 168 } 169 implTestPolyPolyClip(const BitmapDeviceSharedPtr & rDevice)170 void implTestPolyPolyClip(const BitmapDeviceSharedPtr& rDevice) 171 { 172 const Color aCol(0xFFFFFFFF); 173 const Color aBgCol(0); 174 rDevice->clear(aBgCol); 175 basegfx::B2DPolyPolygon aPoly; 176 ::rtl::OUString aSvg; 177 178 basegfx::tools::importFromSvgD( aPoly, 179 ::rtl::OUString::createFromAscii( 180 "M0 0 h7 v7 h-7 z M2 2 v3 h3 v-3 z" ) ); 181 basegfx::B2DHomMatrix aMat; 182 aMat.translate(-3,-3); 183 aMat.rotate( 1.7 ); 184 aMat.translate(6,5); 185 aPoly.transform(aMat); 186 187 rDevice->fillPolyPolygon( 188 aPoly, 189 aCol, 190 DrawMode_PAINT ); 191 192 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 39", 193 countPixel( rDevice, aCol ) == 39); 194 195 BitmapDeviceSharedPtr pClippedDevice( 196 subsetBitmapDevice( rDevice, 197 basegfx::B2IRange(3,3,5,8) )); 198 199 rDevice->clear(aBgCol); 200 pClippedDevice->fillPolyPolygon( 201 aPoly, 202 aCol, 203 DrawMode_PAINT ); 204 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 7", 205 countPixel( rDevice, aCol ) == 7); 206 } 207 implTestPolyPolyCrissCross(const BitmapDeviceSharedPtr & rDevice)208 void implTestPolyPolyCrissCross(const BitmapDeviceSharedPtr& rDevice) 209 { 210 const Color aCol(0xFFFFFFFF); 211 const Color aBgCol(0); 212 rDevice->clear(aBgCol); 213 basegfx::B2DPolyPolygon aPoly; 214 ::rtl::OUString aSvg; 215 216 basegfx::tools::importFromSvgD( aPoly, 217 ::rtl::OUString::createFromAscii( 218 "M0 0 v2 l10 2 v-2 z" 219 "M10 6 v-2 l-10 2 v2 z" 220 "M1 0 h1 v10 h-1 z" 221 "M4 0 h1 v10 h-1 z" 222 "M8 0 h1 v10 h-1 z" ) ); 223 rDevice->fillPolyPolygon( 224 aPoly, 225 aCol, 226 DrawMode_PAINT ); 227 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 46", 228 countPixel( rDevice, aCol ) == 46); 229 } 230 231 232 public: setUp()233 void setUp() 234 { 235 const basegfx::B2ISize aSize(10,10); 236 mpDevice1bpp = createBitmapDevice( aSize, 237 true, 238 Format::ONE_BIT_MSB_PAL ); 239 mpDevice32bpp = createBitmapDevice( aSize, 240 true, 241 Format::THIRTYTWO_BIT_TC_MASK ); 242 } 243 testEmpty()244 void testEmpty() 245 { 246 implTestEmpty( mpDevice1bpp ); 247 implTestEmpty( mpDevice32bpp ); 248 } 249 testHairline()250 void testHairline() 251 { 252 implTestHairline( mpDevice1bpp ); 253 implTestHairline( mpDevice32bpp ); 254 } 255 testPolyPoly()256 void testPolyPoly() 257 { 258 implTestPolyPoly( mpDevice1bpp ); 259 implTestPolyPoly( mpDevice32bpp ); 260 } 261 testPolyPolyClip()262 void testPolyPolyClip() 263 { 264 implTestPolyPolyClip(mpDevice1bpp); 265 implTestPolyPolyClip(mpDevice32bpp); 266 } 267 testPolyPolyCrissCross()268 void testPolyPolyCrissCross() 269 { 270 implTestPolyPolyCrissCross(mpDevice1bpp); 271 implTestPolyPolyCrissCross(mpDevice32bpp); 272 } 273 274 // Change the following lines only, if you add, remove or rename 275 // member functions of the current class, 276 // because these macros are need by auto register mechanism. 277 278 CPPUNIT_TEST_SUITE(PolyTest); 279 CPPUNIT_TEST(testEmpty); 280 CPPUNIT_TEST(testHairline); 281 CPPUNIT_TEST(testPolyPoly); 282 CPPUNIT_TEST(testPolyPolyClip); 283 CPPUNIT_TEST(testPolyPolyCrissCross); 284 CPPUNIT_TEST_SUITE_END(); 285 }; 286 287 // ----------------------------------------------------------------------------- 288 CPPUNIT_TEST_SUITE_REGISTRATION(PolyTest); 289 } 290 291 292 // ----------------------------------------------------------------------------- 293 294 // this macro creates an empty function, which will called by the RegisterAllFunctions() 295 // to let the user the possibility to also register some functions by hand. 296 //NOADDITIONAL; 297 298