LCOV - code coverage report
Current view: top level - basebmp/test - bmptest.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 81 81 100.0 %
Date: 2015-06-13 12:38:46 Functions: 16 16 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           6 : class BmpTest : public CppUnit::TestFixture
      42             : {
      43             : private:
      44             :     BitmapDeviceSharedPtr mpDevice1bpp;
      45             :     BitmapDeviceSharedPtr mpBmp1bpp;
      46             :     BitmapDeviceSharedPtr mpDevice32bpp;
      47             :     BitmapDeviceSharedPtr mpBmp32bpp;
      48             : 
      49           2 :     void implTestBmpBasics(const BitmapDeviceSharedPtr& rDevice,
      50             :                            const BitmapDeviceSharedPtr& rBmp)
      51             :     {
      52           2 :         rDevice->clear(Color(0));
      53           2 :         const Color aCol(0xFFFFFFFF);
      54             : 
      55           2 :         const basegfx::B2IBox aSourceRect(0,0,10,10);
      56           2 :         const basegfx::B2IBox aDestLeftTop(0,0,4,4);
      57           2 :         const basegfx::B2IBox aDestRightTop(6,0,10,4);
      58           2 :         const basegfx::B2IBox aDestLeftBottom(0,6,4,10);
      59           2 :         const basegfx::B2IBox aDestRightBottom(6,6,10,10);
      60             : 
      61             :         rDevice->drawBitmap(
      62             :             rBmp,
      63             :             aSourceRect,
      64             :             aDestLeftTop,
      65           2 :             DrawMode::Paint );
      66           4 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
      67           2 :                                countPixel( rDevice, aCol ) == 8);
      68             : 
      69             :         rDevice->drawBitmap(
      70             :             rBmp,
      71             :             aSourceRect,
      72             :             aDestRightTop,
      73           2 :             DrawMode::Paint );
      74           4 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 16",
      75           2 :                                countPixel( rDevice, aCol ) == 16);
      76             : 
      77             :         rDevice->drawBitmap(
      78             :             rBmp,
      79             :             aSourceRect,
      80             :             aDestLeftBottom,
      81           2 :             DrawMode::Paint );
      82           4 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 24",
      83           2 :                                countPixel( rDevice, aCol ) == 24);
      84             : 
      85             :         rDevice->drawBitmap(
      86             :             rBmp,
      87             :             aSourceRect,
      88             :             aDestRightBottom,
      89           2 :             DrawMode::Paint );
      90           4 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 32",
      91           2 :                                countPixel( rDevice, aCol ) == 32);
      92             : 
      93             :         BitmapDeviceSharedPtr pClone = subsetBitmapDevice(
      94           2 :             rBmp, aSourceRect );
      95             : 
      96             :         // two overlapping areas within the same memory block, check
      97             :         // if we clobber the mem or properly detect the case
      98           2 :         const basegfx::B2IBox aSourceOverlap(0,0,6,10);
      99           2 :         const basegfx::B2IBox aDestOverlap(3,0,9,10);
     100             :         rBmp->drawBitmap(
     101             :             pClone,
     102             :             aSourceOverlap,
     103             :             aDestOverlap,
     104           2 :             DrawMode::Paint );
     105           4 :         CPPUNIT_ASSERT_MESSAGE("clobbertest - number of set pixel is not 50",
     106           4 :                                countPixel( rBmp, aCol ) == 50);
     107             : 
     108           2 :     }
     109             : 
     110           2 :     void implTestBmpClip(const BitmapDeviceSharedPtr& rDevice,
     111             :                          const BitmapDeviceSharedPtr& rBmp)
     112             :     {
     113           2 :         rDevice->clear(Color(0));
     114           2 :         const Color aCol(0xFFFFFFFF);
     115             : 
     116           2 :         const basegfx::B2IBox aSourceRect(0,0,10,10);
     117           2 :         const basegfx::B2IBox aDestLeftTop(-2,-2,2,2);
     118           2 :         const basegfx::B2IBox aDestRightTop(8,-2,12,2);
     119           2 :         const basegfx::B2IBox aDestLeftBottom(-2,8,2,12);
     120           2 :         const basegfx::B2IBox aDestRightBottom(8,8,12,12);
     121             : 
     122             :         rDevice->drawBitmap(
     123             :             rBmp,
     124             :             aSourceRect,
     125             :             aDestLeftTop,
     126           2 :             DrawMode::Paint );
     127           4 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4",
     128           2 :                                countPixel( rDevice, aCol ) == 4);
     129             : 
     130             :         rDevice->drawBitmap(
     131             :             rBmp,
     132             :             aSourceRect,
     133             :             aDestLeftBottom,
     134           2 :             DrawMode::Paint );
     135           4 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4(c)",
     136           2 :                                countPixel( rDevice, aCol ) == 4);
     137             : 
     138             :         rDevice->drawBitmap(
     139             :             rBmp,
     140             :             aSourceRect,
     141             :             aDestRightBottom,
     142           2 :             DrawMode::Paint );
     143           4 :         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
     144           2 :                                countPixel( rDevice, aCol ) == 8);
     145           2 :     }
     146             : 
     147             : public:
     148           2 :     void setUp() SAL_OVERRIDE
     149             :     {
     150           2 :         const basegfx::B2ISize aSize(10,10);
     151           2 :         sal_Int32 nStride = basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX());
     152           4 :         mpDevice1bpp = createBitmapDevice( aSize,
     153             :                                            true,
     154           2 :                                            Format::OneBitMsbPal, nStride );
     155           2 :         nStride = basebmp::getBitmapDeviceStrideForWidth(Format::ThirtyTwoBitTcMaskBGRA, aSize.getX());
     156           4 :         mpDevice32bpp = createBitmapDevice( aSize,
     157             :                                             true,
     158           2 :                                             Format::ThirtyTwoBitTcMaskBGRA, nStride );
     159             : 
     160           2 :         nStride = basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX());
     161           4 :         mpBmp1bpp = createBitmapDevice( aSize,
     162             :                                         true,
     163           2 :                                         Format::OneBitMsbPal, nStride );
     164           2 :         nStride = basebmp::getBitmapDeviceStrideForWidth(Format::ThirtyTwoBitTcMaskBGRA, aSize.getX());
     165           4 :         mpBmp32bpp = createBitmapDevice( aSize,
     166             :                                          true,
     167           2 :                                          Format::ThirtyTwoBitTcMaskBGRA, nStride );
     168             : 
     169           4 :         OUString aSvg( "m 0 0h5v10h5v-5h-10z" );
     170             : 
     171           4 :         basegfx::B2DPolyPolygon aPoly;
     172           2 :         basegfx::tools::importFromSvgD( aPoly, aSvg, false, NULL );
     173           2 :         const Color aCol(0xFFFFFFFF);
     174             :         mpBmp1bpp->fillPolyPolygon(
     175             :             aPoly,
     176             :             aCol,
     177           2 :             DrawMode::Paint );
     178             :         mpBmp32bpp->fillPolyPolygon(
     179             :             aPoly,
     180             :             aCol,
     181           4 :             DrawMode::Paint );
     182           2 :     }
     183             : 
     184           1 :     void testBmpBasics()
     185             :     {
     186           1 :         implTestBmpBasics( mpDevice1bpp, mpBmp1bpp );
     187           1 :         implTestBmpBasics( mpDevice32bpp, mpBmp32bpp );
     188           1 :     }
     189             : 
     190           1 :     void testBmpClip()
     191             :     {
     192           1 :         implTestBmpClip( mpDevice1bpp, mpBmp1bpp );
     193           1 :         implTestBmpClip( mpDevice32bpp, mpBmp32bpp );
     194           1 :     }
     195             : 
     196             :     // Change the following lines only, if you add, remove or rename
     197             :     // member functions of the current class,
     198             :     // because these macros are need by auto register mechanism.
     199             : 
     200           2 :     CPPUNIT_TEST_SUITE(BmpTest);
     201           1 :     CPPUNIT_TEST(testBmpBasics);
     202           1 :     CPPUNIT_TEST(testBmpClip);
     203           5 :     CPPUNIT_TEST_SUITE_END();
     204             : };
     205             : 
     206           1 : CPPUNIT_TEST_SUITE_REGISTRATION(BmpTest);
     207           3 : }
     208             : 
     209             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11