LCOV - code coverage report
Current view: top level - basebmp/test - masktest.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 53 53 100.0 %
Date: 2014-11-03 Functions: 12 12 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/b2ibox.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          12 : class MaskTest : public CppUnit::TestFixture
      42             : {
      43             : private:
      44             :     BitmapDeviceSharedPtr mpDevice1bpp;
      45             :     BitmapDeviceSharedPtr mpDevice32bpp;
      46             :     BitmapDeviceSharedPtr mpMask;
      47             : 
      48           4 :     void implTestMaskBasics(const BitmapDeviceSharedPtr& rDevice,
      49             :                             const BitmapDeviceSharedPtr& rBmp)
      50             :     {
      51           4 :         const Color aCol(0);
      52           4 :         const Color aCol2(0xF0F0F0F0);
      53             : 
      54           4 :         const basegfx::B2IBox aSourceRect(0,0,10,10);
      55           4 :         const basegfx::B2IPoint aDestLeftTop(0,0);
      56           8 :         const basegfx::B2IPoint aDestRightTop(5,0);
      57           8 :         const basegfx::B2IPoint aDestLeftBottom(0,5);
      58           8 :         const basegfx::B2IPoint aDestRightBottom(5,5);
      59             : 
      60           4 :         rDevice->clear(aCol);
      61             :         rDevice->setPixel(
      62             :             basegfx::B2IPoint(1,1),
      63             :             aCol2,
      64           4 :             DrawMode_PAINT);
      65             :         rDevice->drawMaskedColor(
      66             :             aCol2,
      67             :             rBmp,
      68             :             aSourceRect,
      69           4 :             aDestLeftTop );
      70           8 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 50",
      71           4 :                                countPixel( rDevice, aCol ) == 100-50);
      72             : 
      73           4 :         rDevice->clear(aCol);
      74             :         rDevice->drawMaskedColor(
      75             :             aCol2,
      76             :             rBmp,
      77             :             aSourceRect,
      78           4 :             aDestRightTop );
      79           8 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25",
      80           4 :                                countPixel( rDevice, aCol ) == 100-25);
      81             : 
      82           4 :         rDevice->clear(aCol);
      83             :         rDevice->drawMaskedColor(
      84             :             aCol2,
      85             :             rBmp,
      86             :             aSourceRect,
      87           4 :             aDestLeftBottom );
      88           8 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25(b)",
      89           4 :                                countPixel( rDevice, aCol ) == 100-25);
      90             : 
      91           4 :         rDevice->clear(aCol);
      92             :         rDevice->drawMaskedColor(
      93             :             aCol2,
      94             :             rBmp,
      95             :             aSourceRect,
      96           4 :             aDestRightBottom );
      97           8 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25(c)",
      98           8 :                                countPixel( rDevice, aCol ) == 100-25);
      99           4 :     }
     100             : 
     101             : public:
     102           4 :     void setUp() SAL_OVERRIDE
     103             :     {
     104           4 :         const basegfx::B2ISize aSize(10,10);
     105           8 :         mpDevice1bpp = createBitmapDevice( aSize,
     106             :                                            true,
     107           4 :                                            FORMAT_ONE_BIT_MSB_PAL );
     108           8 :         mpDevice32bpp = createBitmapDevice( aSize,
     109             :                                             true,
     110           4 :                                             FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA );
     111             : 
     112           8 :         mpMask = createBitmapDevice( aSize,
     113             :                                      true,
     114           4 :                                      FORMAT_EIGHT_BIT_GREY );
     115             : 
     116           8 :         OUString aSvg( "m 0 0h5v10h5v-5h-10z" );
     117             : 
     118           8 :         basegfx::B2DPolyPolygon aPoly;
     119           4 :         basegfx::tools::importFromSvgD( aPoly, aSvg, false, NULL );
     120           4 :         const Color aCol(0xFF);
     121             :         mpMask->fillPolyPolygon(
     122             :             aPoly,
     123             :             aCol,
     124           8 :             DrawMode_PAINT );
     125           4 :     }
     126             : 
     127           2 :     void testMaskBasics()
     128             :     {
     129           2 :         implTestMaskBasics( mpDevice32bpp, mpMask );
     130           2 :         implTestMaskBasics( mpDevice1bpp, mpMask );
     131           2 :     }
     132             : 
     133           2 :     void testMaskClip()
     134             :     {
     135           2 :     }
     136             : 
     137             :     // Change the following lines only, if you add, remove or rename
     138             :     // member functions of the current class,
     139             :     // because these macros are need by auto register mechanism.
     140             : 
     141           4 :     CPPUNIT_TEST_SUITE(MaskTest);
     142           2 :     CPPUNIT_TEST(testMaskBasics);
     143           2 :     CPPUNIT_TEST(testMaskClip);
     144           4 :     CPPUNIT_TEST_SUITE_END();
     145             : };
     146             : 
     147           2 : CPPUNIT_TEST_SUITE_REGISTRATION(MaskTest);
     148           6 : }
     149             : 
     150             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10