LCOV - code coverage report
Current view: top level - basebmp/test - linetest.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 135 135 100.0 %
Date: 2014-11-03 Functions: 18 18 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <cppunit/TestAssert.h>
      21             : #include <cppunit/TestFixture.h>
      22             : #include <cppunit/extensions/HelperMacros.h>
      23             : 
      24             : #include <basegfx/vector/b2isize.hxx>
      25             : #include <basegfx/point/b2ipoint.hxx>
      26             : 
      27             : #include <basebmp/color.hxx>
      28             : #include <basebmp/scanlineformats.hxx>
      29             : #include <basebmp/bitmapdevice.hxx>
      30             : #include "tools.hxx"
      31             : 
      32             : using namespace ::basebmp;
      33             : 
      34             : namespace
      35             : {
      36          30 : class LineTest : public CppUnit::TestFixture
      37             : {
      38             : private:
      39             :     BitmapDeviceSharedPtr mpDevice1bpp;
      40             :     BitmapDeviceSharedPtr mpDevice32bpp;
      41             : 
      42           4 :     void implTestBasicDiagonalLines(const BitmapDeviceSharedPtr& rDevice)
      43             :     {
      44           4 :         rDevice->clear(Color(0));
      45             : 
      46           4 :         const basegfx::B2IPoint aPt1(1,1);
      47           8 :         const basegfx::B2IPoint aPt2(9,9);
      48           4 :         const Color aCol(0xFFFFFFFF);
      49           4 :         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
      50           8 :         CPPUNIT_ASSERT_MESSAGE("first pixel set",
      51           4 :                                rDevice->getPixel(aPt1) == aCol);
      52           8 :         CPPUNIT_ASSERT_MESSAGE("last pixel set",
      53           4 :                                rDevice->getPixel(aPt2) == aCol);
      54           8 :         const basegfx::B2IPoint aPt3(0,0);
      55           8 :         CPPUNIT_ASSERT_MESSAGE("topmost pixel not set",
      56           4 :                                rDevice->getPixel(aPt3) != aCol);
      57           8 :         const basegfx::B2IPoint aPt4(10,10);
      58           8 :         CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set",
      59           4 :                                rDevice->getPixel(aPt4) != aCol);
      60             : 
      61           8 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9",
      62           4 :                                countPixel( rDevice, aCol ) == 9);
      63             : 
      64           4 :         rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
      65             : 
      66           8 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
      67             :                                "reversed paint is not 9",
      68           8 :                                countPixel( rDevice, aCol ) == 9);
      69           4 :     }
      70             : 
      71           4 :     void implTestBasicHorizontalLines(const BitmapDeviceSharedPtr& rDevice)
      72             :     {
      73           4 :         rDevice->clear(Color(0));
      74             : 
      75           4 :         const basegfx::B2IPoint aPt1(10,10);
      76           8 :         const basegfx::B2IPoint aPt2(0,10);
      77           4 :         const Color aCol(0xFFFFFFFF);
      78           4 :         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
      79           8 :         CPPUNIT_ASSERT_MESSAGE("first pixel set",
      80           4 :                                rDevice->getPixel(aPt1) == aCol);
      81           8 :         CPPUNIT_ASSERT_MESSAGE("last pixel set",
      82           4 :                                rDevice->getPixel(aPt2) == aCol);
      83           8 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11",
      84           4 :                                countPixel( rDevice, aCol ) == 11);
      85             : 
      86           4 :         rDevice->clear(Color(0));
      87           4 :         rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
      88           8 :         CPPUNIT_ASSERT_MESSAGE("first pixel set",
      89           4 :                                rDevice->getPixel(aPt1) == aCol);
      90           8 :         CPPUNIT_ASSERT_MESSAGE("last pixel set",
      91           4 :                                rDevice->getPixel(aPt2) == aCol);
      92           8 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11",
      93           8 :                                countPixel( rDevice, aCol ) == 11);
      94           4 :     }
      95             : 
      96           4 :     void implTestBasicVerticalLines(const BitmapDeviceSharedPtr& rDevice)
      97             :     {
      98           4 :         rDevice->clear(Color(0));
      99             : 
     100           4 :         const basegfx::B2IPoint aPt1(1,1);
     101           8 :         const basegfx::B2IPoint aPt2(1,9);
     102           4 :         const Color aCol(0xFFFFFFFF);
     103           4 :         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
     104           8 :         CPPUNIT_ASSERT_MESSAGE("first pixel set",
     105           4 :                                rDevice->getPixel(aPt1) == aCol);
     106           8 :         CPPUNIT_ASSERT_MESSAGE("last pixel set",
     107           4 :                                rDevice->getPixel(aPt2) == aCol);
     108           8 :         const basegfx::B2IPoint aPt3(0,0);
     109           8 :         CPPUNIT_ASSERT_MESSAGE("topmost pixel not set",
     110           4 :                                rDevice->getPixel(aPt3) != aCol);
     111           8 :         const basegfx::B2IPoint aPt4(0,10);
     112           8 :         CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set",
     113           4 :                                rDevice->getPixel(aPt4) != aCol);
     114             : 
     115           8 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9",
     116           8 :                                countPixel( rDevice, aCol ) == 9);
     117           4 :     }
     118             : 
     119             :     // test pixel rounding (should always tend towards start point of
     120             :     // the line)
     121           4 :     void implTestTieBreaking(const BitmapDeviceSharedPtr& rDevice)
     122             :     {
     123           4 :         rDevice->clear(Color(0));
     124             : 
     125           4 :         const basegfx::B2IPoint aPt1(1,1);
     126           8 :         const basegfx::B2IPoint aPt2(3,2);
     127           4 :         const Color aCol(0xFFFFFFFF);
     128           4 :         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
     129           8 :         CPPUNIT_ASSERT_MESSAGE("first pixel set",
     130           4 :                                rDevice->getPixel(aPt1) == aCol);
     131           8 :         CPPUNIT_ASSERT_MESSAGE("second pixel set",
     132           4 :                                rDevice->getPixel(basegfx::B2IPoint(2,1)) == aCol);
     133           8 :         CPPUNIT_ASSERT_MESSAGE("last pixel set",
     134           4 :                                rDevice->getPixel(aPt2) == aCol);
     135           8 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
     136             :                                "reversed paint is not 3",
     137           4 :                                countPixel( rDevice, aCol ) == 3);
     138             : 
     139           4 :         rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
     140           8 :         CPPUNIT_ASSERT_MESSAGE("alternate second pixel set",
     141           4 :                                rDevice->getPixel(basegfx::B2IPoint(2,2)) == aCol);
     142             : 
     143           8 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
     144             :                                "reversed paint is not 4",
     145           8 :                                countPixel( rDevice, aCol ) == 4);
     146           4 :     }
     147             : 
     148             : public:
     149          10 :     void setUp() SAL_OVERRIDE
     150             :     {
     151          10 :         const basegfx::B2ISize aSize(11,11);
     152          20 :         mpDevice1bpp = createBitmapDevice( aSize,
     153             :                                            true,
     154          10 :                                            FORMAT_ONE_BIT_MSB_PAL );
     155          20 :         mpDevice32bpp = createBitmapDevice( aSize,
     156             :                                            true,
     157          20 :                                            FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA );
     158          10 :     }
     159             : 
     160           2 :     void testCornerCases()
     161             :     {
     162           2 :         const basegfx::B2ISize aSize(1,1);
     163             :         BitmapDeviceSharedPtr pDevice = createBitmapDevice(
     164             :             aSize,
     165             :             true,
     166           4 :             FORMAT_ONE_BIT_MSB_PAL );
     167             : 
     168           4 :         const basegfx::B2IPoint aPt1(0,0);
     169           4 :         const basegfx::B2IPoint aPt2(10,10);
     170           4 :         CPPUNIT_ASSERT_MESSAGE("only pixel cleared",
     171           2 :                                 pDevice->getPixelData(aPt1) == 0);
     172             : 
     173           2 :         const Color aCol(0xFFFFFFFF);
     174           2 :         pDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
     175           4 :         CPPUNIT_ASSERT_MESSAGE("only pixel set",
     176           2 :                                pDevice->getPixelData(aPt1) == 1);
     177             : 
     178           4 :         const basegfx::B2ISize aSize2(1,0);
     179           4 :         pDevice = createBitmapDevice(
     180             :             aSize2,
     181             :             true,
     182           2 :             FORMAT_ONE_BIT_MSB_PAL );
     183             : 
     184           4 :         CPPUNIT_ASSERT_MESSAGE("only pixel cleared",
     185           2 :                                 pDevice->getPixelData(aPt1) == 0);
     186             : 
     187           2 :         pDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
     188           4 :         CPPUNIT_ASSERT_MESSAGE("only pixel still cleared",
     189           4 :                                pDevice->getPixelData(aPt1) == 0);
     190           2 :     }
     191             : 
     192           2 :     void testBasicDiagonalLines()
     193             :     {
     194           2 :         implTestBasicDiagonalLines( mpDevice1bpp );
     195           2 :         implTestBasicDiagonalLines( mpDevice32bpp );
     196           2 :     }
     197             : 
     198           2 :     void testBasicHorizontalLines()
     199             :     {
     200           2 :         implTestBasicHorizontalLines( mpDevice1bpp );
     201           2 :         implTestBasicHorizontalLines( mpDevice32bpp );
     202           2 :     }
     203             : 
     204           2 :     void testBasicVerticalLines()
     205             :     {
     206           2 :         implTestBasicVerticalLines( mpDevice1bpp );
     207           2 :         implTestBasicVerticalLines( mpDevice32bpp );
     208           2 :     }
     209             : 
     210             :     // test pixel rounding (should always tend towards start point of
     211             :     // the line)
     212           2 :     void testTieBreaking()
     213             :     {
     214           2 :         implTestTieBreaking( mpDevice1bpp );
     215           2 :         implTestTieBreaking( mpDevice32bpp );
     216           2 :     }
     217             : 
     218             :     // Change the following lines only, if you add, remove or rename
     219             :     // member functions of the current class,
     220             :     // because these macros are need by auto register mechanism.
     221             : 
     222           4 :     CPPUNIT_TEST_SUITE(LineTest);
     223           2 :     CPPUNIT_TEST(testCornerCases);
     224           2 :     CPPUNIT_TEST(testBasicDiagonalLines);
     225           2 :     CPPUNIT_TEST(testBasicHorizontalLines);
     226           2 :     CPPUNIT_TEST(testBasicVerticalLines);
     227           2 :     CPPUNIT_TEST(testTieBreaking);
     228           4 :     CPPUNIT_TEST_SUITE_END();
     229             : };
     230             : 
     231           2 : CPPUNIT_TEST_SUITE_REGISTRATION(LineTest);
     232           6 : }
     233             : 
     234             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10