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

Generated by: LCOV version 1.10