LCOV - code coverage report
Current view: top level - basebmp/test - cliptest.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 123 123 100.0 %
Date: 2012-08-25 Functions: 19 19 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 242 486 49.8 %

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

Generated by: LCOV version 1.10