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

Generated by: LCOV version 1.11