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/point/b2ipoint.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <basebmp/color.hxx> 40*cdf0e10cSrcweir #include <basebmp/scanlineformats.hxx> 41*cdf0e10cSrcweir #include <basebmp/bitmapdevice.hxx> 42*cdf0e10cSrcweir #include <basebmp/debug.hxx> 43*cdf0e10cSrcweir #include "tools.hxx" 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #include <iostream> 46*cdf0e10cSrcweir #include <fstream> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir using namespace ::basebmp; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir namespace 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir /* 53*cdf0e10cSrcweir std::ofstream output("32bpp_test.dump"); 54*cdf0e10cSrcweir debugDump( mpDevice32bpp, output ); 55*cdf0e10cSrcweir */ 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir class LineTest : public CppUnit::TestFixture 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir private: 60*cdf0e10cSrcweir BitmapDeviceSharedPtr mpDevice1bpp; 61*cdf0e10cSrcweir BitmapDeviceSharedPtr mpDevice32bpp; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir void implTestBasicDiagonalLines(const BitmapDeviceSharedPtr& rDevice) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir rDevice->clear(Color(0)); 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir const basegfx::B2IPoint aPt1(1,1); 68*cdf0e10cSrcweir const basegfx::B2IPoint aPt2(9,9); 69*cdf0e10cSrcweir const Color aCol(0xFFFFFFFF); 70*cdf0e10cSrcweir rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); 71*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("first pixel set", 72*cdf0e10cSrcweir rDevice->getPixel(aPt1) == aCol); 73*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("last pixel set", 74*cdf0e10cSrcweir rDevice->getPixel(aPt2) == aCol); 75*cdf0e10cSrcweir const basegfx::B2IPoint aPt3(0,0); 76*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("topmost pixel not set", 77*cdf0e10cSrcweir rDevice->getPixel(aPt3) != aCol); 78*cdf0e10cSrcweir const basegfx::B2IPoint aPt4(10,10); 79*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set", 80*cdf0e10cSrcweir rDevice->getPixel(aPt4) != aCol); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9", 83*cdf0e10cSrcweir countPixel( rDevice, aCol ) == 9); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT ); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after " 88*cdf0e10cSrcweir "reversed paint is not 9", 89*cdf0e10cSrcweir countPixel( rDevice, aCol ) == 9); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir void implTestBasicHorizontalLines(const BitmapDeviceSharedPtr& rDevice) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir rDevice->clear(Color(0)); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir const basegfx::B2IPoint aPt1(10,10); 97*cdf0e10cSrcweir const basegfx::B2IPoint aPt2(0,10); 98*cdf0e10cSrcweir const Color aCol(0xFFFFFFFF); 99*cdf0e10cSrcweir rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); 100*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("first pixel set", 101*cdf0e10cSrcweir rDevice->getPixel(aPt1) == aCol); 102*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("last pixel set", 103*cdf0e10cSrcweir rDevice->getPixel(aPt2) == aCol); 104*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11", 105*cdf0e10cSrcweir countPixel( rDevice, aCol ) == 11); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir rDevice->clear(Color(0)); 108*cdf0e10cSrcweir rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT ); 109*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("first pixel set", 110*cdf0e10cSrcweir rDevice->getPixel(aPt1) == aCol); 111*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("last pixel set", 112*cdf0e10cSrcweir rDevice->getPixel(aPt2) == aCol); 113*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11", 114*cdf0e10cSrcweir countPixel( rDevice, aCol ) == 11); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir void implTestBasicVerticalLines(const BitmapDeviceSharedPtr& rDevice) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir rDevice->clear(Color(0)); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir const basegfx::B2IPoint aPt1(1,1); 122*cdf0e10cSrcweir const basegfx::B2IPoint aPt2(1,9); 123*cdf0e10cSrcweir const Color aCol(0xFFFFFFFF); 124*cdf0e10cSrcweir rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); 125*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("first pixel set", 126*cdf0e10cSrcweir rDevice->getPixel(aPt1) == aCol); 127*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("last pixel set", 128*cdf0e10cSrcweir rDevice->getPixel(aPt2) == aCol); 129*cdf0e10cSrcweir const basegfx::B2IPoint aPt3(0,0); 130*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("topmost pixel not set", 131*cdf0e10cSrcweir rDevice->getPixel(aPt3) != aCol); 132*cdf0e10cSrcweir const basegfx::B2IPoint aPt4(0,10); 133*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set", 134*cdf0e10cSrcweir rDevice->getPixel(aPt4) != aCol); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9", 137*cdf0e10cSrcweir countPixel( rDevice, aCol ) == 9); 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir // test pixel rounding (should always tend towards start point of 141*cdf0e10cSrcweir // the line) 142*cdf0e10cSrcweir void implTestTieBreaking(const BitmapDeviceSharedPtr& rDevice) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir rDevice->clear(Color(0)); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir const basegfx::B2IPoint aPt1(1,1); 147*cdf0e10cSrcweir const basegfx::B2IPoint aPt2(3,2); 148*cdf0e10cSrcweir const Color aCol(0xFFFFFFFF); 149*cdf0e10cSrcweir rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); 150*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("first pixel set", 151*cdf0e10cSrcweir rDevice->getPixel(aPt1) == aCol); 152*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("second pixel set", 153*cdf0e10cSrcweir rDevice->getPixel(basegfx::B2IPoint(2,1)) == aCol); 154*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("last pixel set", 155*cdf0e10cSrcweir rDevice->getPixel(aPt2) == aCol); 156*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after " 157*cdf0e10cSrcweir "reversed paint is not 3", 158*cdf0e10cSrcweir countPixel( rDevice, aCol ) == 3); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT ); 161*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("alternate second pixel set", 162*cdf0e10cSrcweir rDevice->getPixel(basegfx::B2IPoint(2,2)) == aCol); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after " 165*cdf0e10cSrcweir "reversed paint is not 4", 166*cdf0e10cSrcweir countPixel( rDevice, aCol ) == 4); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir public: 170*cdf0e10cSrcweir void setUp() 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir const basegfx::B2ISize aSize(11,11); 173*cdf0e10cSrcweir mpDevice1bpp = createBitmapDevice( aSize, 174*cdf0e10cSrcweir true, 175*cdf0e10cSrcweir Format::ONE_BIT_MSB_PAL ); 176*cdf0e10cSrcweir mpDevice32bpp = createBitmapDevice( aSize, 177*cdf0e10cSrcweir true, 178*cdf0e10cSrcweir Format::THIRTYTWO_BIT_TC_MASK ); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir void testBasicDiagonalLines() 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir implTestBasicDiagonalLines( mpDevice1bpp ); 184*cdf0e10cSrcweir implTestBasicDiagonalLines( mpDevice32bpp ); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir void testBasicHorizontalLines() 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir implTestBasicHorizontalLines( mpDevice1bpp ); 190*cdf0e10cSrcweir implTestBasicHorizontalLines( mpDevice32bpp ); 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir void testBasicVerticalLines() 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir implTestBasicVerticalLines( mpDevice1bpp ); 196*cdf0e10cSrcweir implTestBasicVerticalLines( mpDevice32bpp ); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir // test pixel rounding (should always tend towards start point of 200*cdf0e10cSrcweir // the line) 201*cdf0e10cSrcweir void testTieBreaking() 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir implTestTieBreaking( mpDevice1bpp ); 204*cdf0e10cSrcweir implTestTieBreaking( mpDevice32bpp ); 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 208*cdf0e10cSrcweir // member functions of the current class, 209*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(LineTest); 212*cdf0e10cSrcweir CPPUNIT_TEST(testBasicDiagonalLines); 213*cdf0e10cSrcweir CPPUNIT_TEST(testBasicHorizontalLines); 214*cdf0e10cSrcweir CPPUNIT_TEST(testBasicVerticalLines); 215*cdf0e10cSrcweir CPPUNIT_TEST(testTieBreaking); 216*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 217*cdf0e10cSrcweir }; 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 220*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(LineTest); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions() 227*cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand. 228*cdf0e10cSrcweir //NOADDITIONAL; 229*cdf0e10cSrcweir 230