1*69de5a4cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*69de5a4cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*69de5a4cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*69de5a4cSAndrew Rist * distributed with this work for additional information 6*69de5a4cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*69de5a4cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*69de5a4cSAndrew Rist * "License"); you may not use this file except in compliance 9*69de5a4cSAndrew Rist * with the License. You may obtain a copy of the License at 10*69de5a4cSAndrew Rist * 11*69de5a4cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*69de5a4cSAndrew Rist * 13*69de5a4cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*69de5a4cSAndrew Rist * software distributed under the License is distributed on an 15*69de5a4cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*69de5a4cSAndrew Rist * KIND, either express or implied. See the License for the 17*69de5a4cSAndrew Rist * specific language governing permissions and limitations 18*69de5a4cSAndrew Rist * under the License. 19*69de5a4cSAndrew Rist * 20*69de5a4cSAndrew Rist *************************************************************/ 21*69de5a4cSAndrew Rist 22*69de5a4cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // autogenerated file with codegen.pl 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "preextstl.h" 27cdf0e10cSrcweir #include "cppunit/TestAssert.h" 28cdf0e10cSrcweir #include "cppunit/TestFixture.h" 29cdf0e10cSrcweir #include "cppunit/extensions/HelperMacros.h" 30cdf0e10cSrcweir #include "postextstl.h" 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <basegfx/vector/b2isize.hxx> 33cdf0e10cSrcweir #include <basegfx/point/b2ipoint.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <basebmp/color.hxx> 36cdf0e10cSrcweir #include <basebmp/scanlineformats.hxx> 37cdf0e10cSrcweir #include <basebmp/bitmapdevice.hxx> 38cdf0e10cSrcweir #include <basebmp/debug.hxx> 39cdf0e10cSrcweir #include "tools.hxx" 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include <iostream> 42cdf0e10cSrcweir #include <fstream> 43cdf0e10cSrcweir 44cdf0e10cSrcweir using namespace ::basebmp; 45cdf0e10cSrcweir 46cdf0e10cSrcweir namespace 47cdf0e10cSrcweir { 48cdf0e10cSrcweir /* 49cdf0e10cSrcweir std::ofstream output("32bpp_test.dump"); 50cdf0e10cSrcweir debugDump( mpDevice32bpp, output ); 51cdf0e10cSrcweir */ 52cdf0e10cSrcweir 53cdf0e10cSrcweir class LineTest : public CppUnit::TestFixture 54cdf0e10cSrcweir { 55cdf0e10cSrcweir private: 56cdf0e10cSrcweir BitmapDeviceSharedPtr mpDevice1bpp; 57cdf0e10cSrcweir BitmapDeviceSharedPtr mpDevice32bpp; 58cdf0e10cSrcweir implTestBasicDiagonalLines(const BitmapDeviceSharedPtr & rDevice)59cdf0e10cSrcweir void implTestBasicDiagonalLines(const BitmapDeviceSharedPtr& rDevice) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir rDevice->clear(Color(0)); 62cdf0e10cSrcweir 63cdf0e10cSrcweir const basegfx::B2IPoint aPt1(1,1); 64cdf0e10cSrcweir const basegfx::B2IPoint aPt2(9,9); 65cdf0e10cSrcweir const Color aCol(0xFFFFFFFF); 66cdf0e10cSrcweir rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); 67cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("first pixel set", 68cdf0e10cSrcweir rDevice->getPixel(aPt1) == aCol); 69cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("last pixel set", 70cdf0e10cSrcweir rDevice->getPixel(aPt2) == aCol); 71cdf0e10cSrcweir const basegfx::B2IPoint aPt3(0,0); 72cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("topmost pixel not set", 73cdf0e10cSrcweir rDevice->getPixel(aPt3) != aCol); 74cdf0e10cSrcweir const basegfx::B2IPoint aPt4(10,10); 75cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set", 76cdf0e10cSrcweir rDevice->getPixel(aPt4) != aCol); 77cdf0e10cSrcweir 78cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9", 79cdf0e10cSrcweir countPixel( rDevice, aCol ) == 9); 80cdf0e10cSrcweir 81cdf0e10cSrcweir rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT ); 82cdf0e10cSrcweir 83cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after " 84cdf0e10cSrcweir "reversed paint is not 9", 85cdf0e10cSrcweir countPixel( rDevice, aCol ) == 9); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir implTestBasicHorizontalLines(const BitmapDeviceSharedPtr & rDevice)88cdf0e10cSrcweir void implTestBasicHorizontalLines(const BitmapDeviceSharedPtr& rDevice) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir rDevice->clear(Color(0)); 91cdf0e10cSrcweir 92cdf0e10cSrcweir const basegfx::B2IPoint aPt1(10,10); 93cdf0e10cSrcweir const basegfx::B2IPoint aPt2(0,10); 94cdf0e10cSrcweir const Color aCol(0xFFFFFFFF); 95cdf0e10cSrcweir rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); 96cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("first pixel set", 97cdf0e10cSrcweir rDevice->getPixel(aPt1) == aCol); 98cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("last pixel set", 99cdf0e10cSrcweir rDevice->getPixel(aPt2) == aCol); 100cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11", 101cdf0e10cSrcweir countPixel( rDevice, aCol ) == 11); 102cdf0e10cSrcweir 103cdf0e10cSrcweir rDevice->clear(Color(0)); 104cdf0e10cSrcweir rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT ); 105cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("first pixel set", 106cdf0e10cSrcweir rDevice->getPixel(aPt1) == aCol); 107cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("last pixel set", 108cdf0e10cSrcweir rDevice->getPixel(aPt2) == aCol); 109cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11", 110cdf0e10cSrcweir countPixel( rDevice, aCol ) == 11); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir implTestBasicVerticalLines(const BitmapDeviceSharedPtr & rDevice)113cdf0e10cSrcweir void implTestBasicVerticalLines(const BitmapDeviceSharedPtr& rDevice) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir rDevice->clear(Color(0)); 116cdf0e10cSrcweir 117cdf0e10cSrcweir const basegfx::B2IPoint aPt1(1,1); 118cdf0e10cSrcweir const basegfx::B2IPoint aPt2(1,9); 119cdf0e10cSrcweir const Color aCol(0xFFFFFFFF); 120cdf0e10cSrcweir rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); 121cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("first pixel set", 122cdf0e10cSrcweir rDevice->getPixel(aPt1) == aCol); 123cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("last pixel set", 124cdf0e10cSrcweir rDevice->getPixel(aPt2) == aCol); 125cdf0e10cSrcweir const basegfx::B2IPoint aPt3(0,0); 126cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("topmost pixel not set", 127cdf0e10cSrcweir rDevice->getPixel(aPt3) != aCol); 128cdf0e10cSrcweir const basegfx::B2IPoint aPt4(0,10); 129cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set", 130cdf0e10cSrcweir rDevice->getPixel(aPt4) != aCol); 131cdf0e10cSrcweir 132cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9", 133cdf0e10cSrcweir countPixel( rDevice, aCol ) == 9); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir // test pixel rounding (should always tend towards start point of 137cdf0e10cSrcweir // the line) implTestTieBreaking(const BitmapDeviceSharedPtr & rDevice)138cdf0e10cSrcweir void implTestTieBreaking(const BitmapDeviceSharedPtr& rDevice) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir rDevice->clear(Color(0)); 141cdf0e10cSrcweir 142cdf0e10cSrcweir const basegfx::B2IPoint aPt1(1,1); 143cdf0e10cSrcweir const basegfx::B2IPoint aPt2(3,2); 144cdf0e10cSrcweir const Color aCol(0xFFFFFFFF); 145cdf0e10cSrcweir rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); 146cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("first pixel set", 147cdf0e10cSrcweir rDevice->getPixel(aPt1) == aCol); 148cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("second pixel set", 149cdf0e10cSrcweir rDevice->getPixel(basegfx::B2IPoint(2,1)) == aCol); 150cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("last pixel set", 151cdf0e10cSrcweir rDevice->getPixel(aPt2) == aCol); 152cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after " 153cdf0e10cSrcweir "reversed paint is not 3", 154cdf0e10cSrcweir countPixel( rDevice, aCol ) == 3); 155cdf0e10cSrcweir 156cdf0e10cSrcweir rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT ); 157cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("alternate second pixel set", 158cdf0e10cSrcweir rDevice->getPixel(basegfx::B2IPoint(2,2)) == aCol); 159cdf0e10cSrcweir 160cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after " 161cdf0e10cSrcweir "reversed paint is not 4", 162cdf0e10cSrcweir countPixel( rDevice, aCol ) == 4); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir public: setUp()166cdf0e10cSrcweir void setUp() 167cdf0e10cSrcweir { 168cdf0e10cSrcweir const basegfx::B2ISize aSize(11,11); 169cdf0e10cSrcweir mpDevice1bpp = createBitmapDevice( aSize, 170cdf0e10cSrcweir true, 171cdf0e10cSrcweir Format::ONE_BIT_MSB_PAL ); 172cdf0e10cSrcweir mpDevice32bpp = createBitmapDevice( aSize, 173cdf0e10cSrcweir true, 174cdf0e10cSrcweir Format::THIRTYTWO_BIT_TC_MASK ); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir testBasicDiagonalLines()177cdf0e10cSrcweir void testBasicDiagonalLines() 178cdf0e10cSrcweir { 179cdf0e10cSrcweir implTestBasicDiagonalLines( mpDevice1bpp ); 180cdf0e10cSrcweir implTestBasicDiagonalLines( mpDevice32bpp ); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir testBasicHorizontalLines()183cdf0e10cSrcweir void testBasicHorizontalLines() 184cdf0e10cSrcweir { 185cdf0e10cSrcweir implTestBasicHorizontalLines( mpDevice1bpp ); 186cdf0e10cSrcweir implTestBasicHorizontalLines( mpDevice32bpp ); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir testBasicVerticalLines()189cdf0e10cSrcweir void testBasicVerticalLines() 190cdf0e10cSrcweir { 191cdf0e10cSrcweir implTestBasicVerticalLines( mpDevice1bpp ); 192cdf0e10cSrcweir implTestBasicVerticalLines( mpDevice32bpp ); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir // test pixel rounding (should always tend towards start point of 196cdf0e10cSrcweir // the line) testTieBreaking()197cdf0e10cSrcweir void testTieBreaking() 198cdf0e10cSrcweir { 199cdf0e10cSrcweir implTestTieBreaking( mpDevice1bpp ); 200cdf0e10cSrcweir implTestTieBreaking( mpDevice32bpp ); 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 204cdf0e10cSrcweir // member functions of the current class, 205cdf0e10cSrcweir // because these macros are need by auto register mechanism. 206cdf0e10cSrcweir 207cdf0e10cSrcweir CPPUNIT_TEST_SUITE(LineTest); 208cdf0e10cSrcweir CPPUNIT_TEST(testBasicDiagonalLines); 209cdf0e10cSrcweir CPPUNIT_TEST(testBasicHorizontalLines); 210cdf0e10cSrcweir CPPUNIT_TEST(testBasicVerticalLines); 211cdf0e10cSrcweir CPPUNIT_TEST(testTieBreaking); 212cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 213cdf0e10cSrcweir }; 214cdf0e10cSrcweir 215cdf0e10cSrcweir // ----------------------------------------------------------------------------- 216cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(LineTest); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir 220cdf0e10cSrcweir // ----------------------------------------------------------------------------- 221cdf0e10cSrcweir 222cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions() 223cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand. 224cdf0e10cSrcweir //NOADDITIONAL; 225cdf0e10cSrcweir 226