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