LCOV - code coverage report
Current view: top level - basebmp/test - filltest.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 115 115 100.0 %
Date: 2012-08-25 Functions: 15 15 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 334 670 49.9 %

           Branch data     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/range/b2drange.hxx>
      26                 :            : #include <basegfx/point/b2ipoint.hxx>
      27                 :            : #include <basegfx/polygon/b2dpolygon.hxx>
      28                 :            : #include <basegfx/polygon/b2dpolygontools.hxx>
      29                 :            : #include <basegfx/polygon/b2dpolypolygon.hxx>
      30                 :            : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      31                 :            : 
      32                 :            : #include <basebmp/color.hxx>
      33                 :            : #include <basebmp/scanlineformats.hxx>
      34                 :            : #include <basebmp/bitmapdevice.hxx>
      35                 :            : #include "tools.hxx"
      36                 :            : 
      37                 :            : using namespace ::basebmp;
      38                 :            : 
      39                 :            : namespace
      40                 :            : {
      41 [ +  - ][ +  - ]:         45 : class FillTest : public CppUnit::TestFixture
         [ -  + ][ +  - ]
                 [ +  - ]
      42                 :            : {
      43                 :            : private:
      44                 :            :     BitmapDeviceSharedPtr mpDevice1bpp;
      45                 :            :     BitmapDeviceSharedPtr mpDevice32bpp;
      46                 :            : 
      47                 :         10 :     void implTestRectFill(const BitmapDeviceSharedPtr& rDevice)
      48                 :            :     {
      49         [ +  - ]:         10 :         rDevice->clear(Color(0));
      50                 :            : 
      51         [ +  - ]:         10 :         const basegfx::B2DRange   aRect(1,1,10,10);
      52                 :            : 
      53                 :         10 :         const Color aCol(0xFFFFFFFF);
      54                 :            :         rDevice->fillPolyPolygon(
      55                 :            :             basegfx::B2DPolyPolygon(
      56                 :            :                 basegfx::tools::createPolygonFromRect( aRect )),
      57                 :            :             aCol,
      58 [ +  - ][ +  - ]:         10 :             DrawMode_PAINT );
         [ +  - ][ +  - ]
                 [ +  - ]
      59                 :            : 
      60                 :         10 :         const basegfx::B2IPoint aPt1(1,1);
      61 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("first pixel set",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      62         [ +  - ]:         10 :                                rDevice->getPixel(aPt1) == aCol);
      63                 :         10 :         const basegfx::B2IPoint aPt2(9,9);
      64 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("last pixel set",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      65         [ +  - ]:         10 :                                rDevice->getPixel(aPt2) == aCol);
      66                 :         10 :         const basegfx::B2IPoint aPt3(0,0);
      67 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("topmost pixel not set",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      68         [ +  - ]:         10 :                                rDevice->getPixel(aPt3) != aCol);
      69                 :         10 :         const basegfx::B2IPoint aPt4(10,10);
      70 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      71         [ +  - ]:         10 :                                rDevice->getPixel(aPt4) != aCol);
      72                 :            : 
      73 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 81",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      74         [ +  - ]:         20 :                                countPixel( rDevice, aCol ) == 81);
      75                 :         10 :     }
      76                 :            : 
      77                 :         10 :     void implTestCornerCases(const BitmapDeviceSharedPtr& rDevice)
      78                 :            :     {
      79         [ +  - ]:         10 :         rDevice->clear(Color(0));
      80                 :            : 
      81         [ +  - ]:         10 :         const basegfx::B2DRange aEmpty1(0,0,0,11);
      82         [ +  - ]:         10 :         const basegfx::B2DRange aEmpty2(0,0,11,0);
      83         [ +  - ]:         10 :         const basegfx::B2DRange aVertLineLeft(0,0,1,11);
      84         [ +  - ]:         10 :         const basegfx::B2DRange aVertLineRight(10,0,11,11);
      85         [ +  - ]:         10 :         const basegfx::B2DRange aHorzLineTop(0,0,11,1);
      86         [ +  - ]:         10 :         const basegfx::B2DRange aHorzLineBottom(0,10,11,11);
      87                 :            : 
      88                 :         10 :         const Color aCol(0xFFFFFFFF);
      89                 :            :         rDevice->fillPolyPolygon(
      90                 :            :             basegfx::B2DPolyPolygon(
      91                 :            :                 basegfx::tools::createPolygonFromRect( aEmpty1 )),
      92                 :            :             aCol,
      93 [ +  - ][ +  - ]:         10 :             DrawMode_PAINT );
         [ +  - ][ +  - ]
                 [ +  - ]
      94 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      95         [ +  - ]:         10 :                                countPixel( rDevice, aCol ) == 0);
      96                 :            : 
      97                 :            :         rDevice->fillPolyPolygon(
      98                 :            :             basegfx::B2DPolyPolygon(
      99                 :            :                 basegfx::tools::createPolygonFromRect( aEmpty2 )),
     100                 :            :             aCol,
     101 [ +  - ][ +  - ]:         10 :             DrawMode_PAINT );
         [ +  - ][ +  - ]
                 [ +  - ]
     102 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     103         [ +  - ]:         10 :                                countPixel( rDevice, aCol ) == 0);
     104                 :            : 
     105                 :            :         rDevice->fillPolyPolygon(
     106                 :            :             basegfx::B2DPolyPolygon(
     107                 :            :                 basegfx::tools::createPolygonFromRect( aVertLineLeft )),
     108                 :            :             aCol,
     109 [ +  - ][ +  - ]:         10 :             DrawMode_PAINT );
         [ +  - ][ +  - ]
                 [ +  - ]
     110 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     111         [ +  - ]:         10 :                                countPixel( rDevice, aCol ) == 11);
     112                 :         10 :         const basegfx::B2IPoint aPt1(0,0);
     113 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("first pixel set",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     114         [ +  - ]:         10 :                                rDevice->getPixel(aPt1) == aCol);
     115                 :            : 
     116                 :            :         rDevice->fillPolyPolygon(
     117                 :            :             basegfx::B2DPolyPolygon(
     118                 :            :                 basegfx::tools::createPolygonFromRect( aVertLineRight )),
     119                 :            :             aCol,
     120 [ +  - ][ +  - ]:         10 :             DrawMode_PAINT );
         [ +  - ][ +  - ]
                 [ +  - ]
     121 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 22",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     122         [ +  - ]:         10 :                                countPixel( rDevice, aCol ) == 22);
     123                 :         10 :         const basegfx::B2IPoint aPt2(10,10);
     124 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("last pixel set",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     125         [ +  - ]:         10 :                                rDevice->getPixel(aPt2) == aCol);
     126                 :            : 
     127                 :            :         rDevice->fillPolyPolygon(
     128                 :            :             basegfx::B2DPolyPolygon(
     129                 :            :                 basegfx::tools::createPolygonFromRect( aHorzLineTop )),
     130                 :            :             aCol,
     131 [ +  - ][ +  - ]:         10 :             DrawMode_PAINT );
         [ +  - ][ +  - ]
                 [ +  - ]
     132 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 31",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     133         [ +  - ]:         10 :                                countPixel( rDevice, aCol ) == 31);
     134                 :         10 :         const basegfx::B2IPoint aPt3(5,0);
     135 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("top-middle pixel set",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     136         [ +  - ]:         10 :                                rDevice->getPixel(aPt3) == aCol);
     137                 :            : 
     138                 :            :         rDevice->fillPolyPolygon(
     139                 :            :             basegfx::B2DPolyPolygon(
     140                 :            :                 basegfx::tools::createPolygonFromRect( aHorzLineBottom )),
     141                 :            :             aCol,
     142 [ +  - ][ +  - ]:         10 :             DrawMode_PAINT );
         [ +  - ][ +  - ]
                 [ +  - ]
     143 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 40",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     144         [ +  - ]:         10 :                                countPixel( rDevice, aCol ) == 40);
     145                 :         10 :         const basegfx::B2IPoint aPt4(5,10);
     146 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("bottom-middle pixel set",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     147         [ +  - ]:         10 :                                rDevice->getPixel(aPt4) == aCol);
     148                 :            : 
     149         [ +  - ]:         10 :         ::rtl::OUString aSvg( RTL_CONSTASCII_USTRINGPARAM( "m 0 0l7 7h-1z" ));
     150                 :            : 
     151         [ +  - ]:         10 :         basegfx::B2DPolyPolygon aPoly;
     152         [ +  - ]:         10 :         basegfx::tools::importFromSvgD( aPoly, aSvg );
     153                 :            :         rDevice->fillPolyPolygon(
     154                 :            :             aPoly,
     155                 :            :             aCol,
     156         [ +  - ]:         10 :             DrawMode_PAINT );
     157 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 43",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     158   [ +  -  +  - ]:         20 :                                countPixel( rDevice, aCol ) == 43);
     159                 :         10 :     }
     160                 :            : 
     161                 :         10 :     void implTestClipping(const BitmapDeviceSharedPtr& rDevice)
     162                 :            :     {
     163         [ +  - ]:         10 :         rDevice->clear(Color(0));
     164                 :            : 
     165         [ +  - ]:         10 :         const basegfx::B2DRange   aLeftTop(-10,-10,1,1);
     166         [ +  - ]:         10 :         const basegfx::B2DRange   aRightTop(10,-10,20,1);
     167         [ +  - ]:         10 :         const basegfx::B2DRange   aLeftBottom(-10,10,1,20);
     168         [ +  - ]:         10 :         const basegfx::B2DRange   aRightBottom(10,10,20,20);
     169         [ +  - ]:         10 :         const basegfx::B2DRange   aAllOver(-10,-10,20,20);
     170                 :            : 
     171                 :         10 :         const Color aCol(0xFFFFFFFF);
     172                 :            :         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
     173                 :            :                                       basegfx::tools::createPolygonFromRect(aLeftTop)),
     174                 :            :                                   aCol,
     175 [ +  - ][ +  - ]:         10 :                                   DrawMode_PAINT );
         [ +  - ][ +  - ]
                 [ +  - ]
     176 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 1",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     177         [ +  - ]:         10 :                                countPixel( rDevice, aCol ) == 1);
     178                 :            : 
     179                 :            :         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
     180                 :            :                                       basegfx::tools::createPolygonFromRect(aRightTop)),
     181                 :            :                                   aCol,
     182 [ +  - ][ +  - ]:         10 :                                   DrawMode_PAINT );
         [ +  - ][ +  - ]
                 [ +  - ]
     183 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 2",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     184         [ +  - ]:         10 :                                countPixel( rDevice, aCol ) == 2);
     185                 :            : 
     186                 :            :         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
     187                 :            :                                       basegfx::tools::createPolygonFromRect(aLeftBottom)),
     188                 :            :                                   aCol,
     189 [ +  - ][ +  - ]:         10 :                                   DrawMode_PAINT );
         [ +  - ][ +  - ]
                 [ +  - ]
     190 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 3",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     191         [ +  - ]:         10 :                                countPixel( rDevice, aCol ) == 3);
     192                 :            : 
     193                 :            :         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
     194                 :            :                                       basegfx::tools::createPolygonFromRect(aRightBottom)),
     195                 :            :                                   aCol,
     196 [ +  - ][ +  - ]:         10 :                                   DrawMode_PAINT );
         [ +  - ][ +  - ]
                 [ +  - ]
     197 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     198         [ +  - ]:         10 :                                countPixel( rDevice, aCol ) == 4);
     199                 :            : 
     200                 :            :         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
     201                 :            :                                       basegfx::tools::createPolygonFromRect(aAllOver)),
     202                 :            :                                   aCol,
     203 [ +  - ][ +  - ]:         10 :                                   DrawMode_PAINT );
         [ +  - ][ +  - ]
                 [ +  - ]
     204 [ +  - ][ +  - ]:         20 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 121",
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     205         [ +  - ]:         10 :                                countPixel( rDevice, aCol ) == 121);
     206                 :         10 :     }
     207                 :            : 
     208                 :            : public:
     209                 :         15 :     void setUp()
     210                 :            :     {
     211                 :         15 :         const basegfx::B2ISize aSize(11,11);
     212                 :            :         mpDevice1bpp = createBitmapDevice( aSize,
     213                 :            :                                            true,
     214 [ +  - ][ +  - ]:         15 :                                            Format::ONE_BIT_MSB_PAL );
                 [ +  - ]
     215                 :            :         mpDevice32bpp = createBitmapDevice( aSize,
     216                 :            :                                            true,
     217 [ +  - ][ +  - ]:         15 :                                            Format::THIRTYTWO_BIT_TC_MASK );
                 [ +  - ]
     218                 :         15 :     }
     219                 :            : 
     220                 :          5 :     void testRectFill()
     221                 :            :     {
     222                 :          5 :         implTestRectFill( mpDevice1bpp );
     223                 :          5 :         implTestRectFill( mpDevice32bpp );
     224                 :          5 :     }
     225                 :            : 
     226                 :          5 :     void testClipping()
     227                 :            :     {
     228                 :          5 :         implTestClipping( mpDevice1bpp );
     229                 :          5 :         implTestClipping( mpDevice32bpp );
     230                 :          5 :     }
     231                 :            : 
     232                 :          5 :     void testCornerCases()
     233                 :            :     {
     234                 :          5 :         implTestCornerCases( mpDevice1bpp );
     235                 :          5 :         implTestCornerCases( mpDevice32bpp );
     236                 :          5 :     }
     237                 :            : 
     238                 :            :     // Change the following lines only, if you add, remove or rename
     239                 :            :     // member functions of the current class,
     240                 :            :     // because these macros are need by auto register mechanism.
     241                 :            : 
     242 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE(FillTest);
         [ +  - ][ +  - ]
                 [ #  # ]
     243 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(testRectFill);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     244 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(testClipping);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     245 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(testCornerCases);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     246 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     247                 :            : };
     248                 :            : 
     249                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(FillTest);
     250 [ +  - ][ +  - ]:         15 : }
     251                 :            : 
     252                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10