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