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