LCOV - code coverage report
Current view: top level - basebmp/test - basictest.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 178 178 100.0 %
Date: 2014-11-03 Functions: 13 14 92.9 %
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             : // autogenerated file with codegen.pl
      21             : 
      22             : #include <cppunit/TestAssert.h>
      23             : #include <cppunit/TestFixture.h>
      24             : #include <cppunit/extensions/HelperMacros.h>
      25             : #include <cppunit/plugin/TestPlugIn.h>
      26             : 
      27             : #include <basegfx/vector/b2isize.hxx>
      28             : #include <basegfx/point/b2ipoint.hxx>
      29             : 
      30             : #include <basebmp/color.hxx>
      31             : #include <basebmp/scanlineformats.hxx>
      32             : #include <basebmp/bitmapdevice.hxx>
      33             : #include "tools.hxx"
      34             : 
      35             : using namespace ::basebmp;
      36             : 
      37             : namespace
      38             : {
      39          24 : class BasicTest : public CppUnit::TestFixture
      40             : {
      41             : public:
      42           2 :     void colorTest()
      43             :     {
      44           2 :         Color aTestColor;
      45             : 
      46           2 :         aTestColor = Color(0xDEADBEEF);
      47           4 :         CPPUNIT_ASSERT_MESSAGE("unary constructor",
      48           2 :                                aTestColor.toInt32() == 0xDEADBEEF );
      49             : 
      50           2 :         aTestColor = Color( 0x10, 0x20, 0xFF );
      51           4 :         CPPUNIT_ASSERT_MESSAGE("ternary constructor",
      52           2 :                                aTestColor.toInt32() == 0x001020FF );
      53             : 
      54           2 :         aTestColor.setRed( 0x0F );
      55           4 :         CPPUNIT_ASSERT_MESSAGE("setRed()",
      56           2 :                                aTestColor.toInt32() == 0x00F20FF );
      57             : 
      58           2 :         aTestColor.setGreen( 0x0F );
      59           4 :         CPPUNIT_ASSERT_MESSAGE("setGreen()",
      60           2 :                                aTestColor.toInt32() == 0x00F0FFF );
      61             : 
      62           2 :         aTestColor.setBlue( 0x10 );
      63           4 :         CPPUNIT_ASSERT_MESSAGE("setBlue()",
      64           2 :                                aTestColor.toInt32() == 0x00F0F10 );
      65             : 
      66           2 :         aTestColor.setGrey( 0x13 );
      67           4 :         CPPUNIT_ASSERT_MESSAGE("setGrey()",
      68           2 :                                aTestColor.toInt32() == 0x00131313 );
      69             : 
      70           2 :         aTestColor = Color( 0x10, 0x20, 0xFF );
      71           4 :         CPPUNIT_ASSERT_MESSAGE("getRed()",
      72           2 :                                aTestColor.getRed() == 0x10 );
      73           4 :         CPPUNIT_ASSERT_MESSAGE("getGreen()",
      74           2 :                                aTestColor.getGreen() == 0x20 );
      75           4 :         CPPUNIT_ASSERT_MESSAGE("getBlue()",
      76           2 :                                aTestColor.getBlue() == 0xFF );
      77             : 
      78           2 :     }
      79             : 
      80           2 :     void testConstruction()
      81             :     {
      82           2 :         const basegfx::B2ISize aSize(101,101);
      83           4 :         basegfx::B2ISize       aSize2(aSize);
      84             :         BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
      85             :                                                            true,
      86           4 :                                                            FORMAT_ONE_BIT_MSB_PAL ));
      87           4 :         CPPUNIT_ASSERT_MESSAGE("right size",
      88           2 :                                pDevice->getSize() == aSize2 );
      89           4 :         CPPUNIT_ASSERT_MESSAGE("Top down format",
      90           2 :                                pDevice->isTopDown() == true );
      91           4 :         CPPUNIT_ASSERT_MESSAGE("Scanline format",
      92           2 :                                pDevice->getScanlineFormat() == FORMAT_ONE_BIT_MSB_PAL );
      93           4 :         CPPUNIT_ASSERT_MESSAGE("Scanline len",
      94           2 :                                pDevice->getScanlineStride() == (aSize2.getY() + 7)/8 );
      95           4 :         CPPUNIT_ASSERT_MESSAGE("Palette existence",
      96           2 :                                pDevice->getPalette() );
      97           4 :         CPPUNIT_ASSERT_MESSAGE("Palette entry 0 is black",
      98           2 :                                (*pDevice->getPalette())[0] == Color(0) );
      99           4 :         CPPUNIT_ASSERT_MESSAGE("Palette entry 1 is white",
     100           4 :                                (*pDevice->getPalette())[1] == Color(0xFFFFFFFF) );
     101           2 :     }
     102             : 
     103           2 :     void testClone()
     104             :     {
     105           2 :         const basegfx::B2ISize aSize(101,101);
     106           4 :         basegfx::B2ISize       aSize2(3,3);
     107             :         BitmapDeviceSharedPtr  pDevice( createBitmapDevice( aSize,
     108             :                                                             true,
     109           4 :                                                             FORMAT_ONE_BIT_MSB_PAL ));
     110             : 
     111             :         BitmapDeviceSharedPtr  pClone( cloneBitmapDevice(
     112             :                                            aSize2,
     113           4 :                                            pDevice ));
     114           4 :         CPPUNIT_ASSERT_MESSAGE("right size",
     115           4 :                                pClone->getSize() == aSize2 );
     116           2 :     }
     117             : 
     118           2 :     void testPixelFuncs()
     119             :     {
     120             :         // 1bpp
     121           2 :         const basegfx::B2ISize aSize(64,64);
     122             :         BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
     123             :                                                            true,
     124           4 :                                                            FORMAT_ONE_BIT_MSB_PAL ));
     125             : 
     126           4 :         const basegfx::B2IPoint aPt(3,3);
     127           4 :         CPPUNIT_ASSERT_MESSAGE("getPixelData for virgin device",
     128           2 :                                pDevice->getPixelData(aPt) == 0);
     129             : 
     130           2 :         const Color aCol(0xFFFFFFFF);
     131           2 :         pDevice->setPixel( aPt, aCol, DrawMode_PAINT );
     132           4 :         CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #1",
     133           2 :                                pDevice->getPixel(aPt) == aCol);
     134           4 :         CPPUNIT_ASSERT_MESSAGE("getPixelData for white pixel",
     135           2 :                                pDevice->getPixelData(aPt) == 1);
     136             : 
     137           4 :         const basegfx::B2IPoint aPt2(0,0);
     138           2 :         const Color aCol2(0xFFFFFFFF);
     139           2 :         pDevice->setPixel( aPt2, aCol2, DrawMode_PAINT );
     140           4 :         CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #2",
     141           2 :                                pDevice->getPixel(aPt2) == aCol2);
     142             : 
     143           4 :         const basegfx::B2IPoint aPt3(aSize.getX()-1,aSize.getY()-1);
     144           2 :         const Color aCol3(0x00000000);
     145           2 :         pDevice->setPixel( aPt3, aCol3, DrawMode_PAINT );
     146           4 :         CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3",
     147           2 :                                pDevice->getPixel(aPt3) == aCol3);
     148             : 
     149           2 :         pDevice->setPixel( aPt3, aCol2, DrawMode_PAINT );
     150           4 :         CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3.5",
     151           2 :                                pDevice->getPixel(aPt3) == aCol2);
     152             : 
     153           4 :         const basegfx::B2IPoint aPt4(-100000,-100000);
     154           2 :         pDevice->setPixel( aPt4, aCol3, DrawMode_PAINT );
     155           4 :         const basegfx::B2IPoint aPt5(100000,100000);
     156           2 :         pDevice->setPixel( aPt5, aCol3, DrawMode_PAINT );
     157             : 
     158           2 :         sal_Int32 nPixel(countPixel(pDevice, aCol2));
     159           4 :         const basegfx::B2IPoint aPt6(aSize.getX(),aSize.getY());
     160           2 :         pDevice->setPixel( aPt6, aCol2, DrawMode_PAINT );
     161           4 :         CPPUNIT_ASSERT_MESSAGE("setPixel clipping",
     162           2 :                                countPixel(pDevice, aCol2) == nPixel);
     163             : 
     164           4 :         CPPUNIT_ASSERT_MESSAGE("raw pixel value #1",
     165           2 :                                pDevice->getBuffer()[0] == 0x80);
     166             : 
     167             :         // 1bit LSB
     168             :         {
     169           4 :             pDevice = createBitmapDevice( aSize,
     170             :                                           true,
     171           2 :                                           FORMAT_ONE_BIT_LSB_PAL );
     172             : 
     173           2 :             pDevice->setPixel( aPt2, aCol, DrawMode_PAINT );
     174           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
     175           2 :                                    pDevice->getPixel(aPt2) == aCol);
     176             : 
     177           2 :             const basegfx::B2IPoint aPt222(1,1);
     178           2 :             pDevice->setPixel( aPt222, aCol, DrawMode_PAINT );
     179           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
     180           2 :                                    pDevice->getPixel(aPt222) == aCol);
     181             : 
     182           2 :             pDevice->setPixel( aPt3, aCol, DrawMode_PAINT );
     183           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
     184           2 :                                    pDevice->getPixel(aPt3) == aCol);
     185             : 
     186           4 :             CPPUNIT_ASSERT_MESSAGE("raw pixel value #2",
     187           2 :                                    pDevice->getBuffer()[0] == 0x01);
     188           4 :             CPPUNIT_ASSERT_MESSAGE("raw pixel value #3",
     189           4 :                                    pDevice->getBuffer()[8] == 0x02);
     190             :         }
     191             : 
     192             :         // 8bit alpha
     193             :         {
     194           4 :             pDevice = createBitmapDevice( aSize,
     195             :                                           true,
     196           2 :                                           FORMAT_EIGHT_BIT_GREY );
     197             : 
     198           2 :             const Color aCol4(0x010101);
     199           2 :             pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
     200           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
     201           2 :                                    pDevice->getPixel(aPt) == aCol4);
     202             : 
     203           2 :             const Color aCol5(0x0F0F0F);
     204           2 :             pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
     205           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
     206           2 :                                    pDevice->getPixel(aPt2) == aCol5);
     207             : 
     208           2 :             const Color aCol6(0xFFFFFF);
     209           2 :             pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
     210           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
     211           2 :                                    pDevice->getPixel(aPt3) == aCol6);
     212             :         }
     213             : 
     214             :         // 16bpp
     215             :         {
     216           4 :             pDevice = createBitmapDevice( aSize,
     217             :                                           true,
     218           2 :                                           FORMAT_SIXTEEN_BIT_LSB_TC_MASK );
     219           2 :             const Color aCol7(0);
     220           2 :             pDevice->clear( aCol7 );
     221             : 
     222           2 :             const Color aCol4(0x00101010);
     223           2 :             pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
     224           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #7",
     225           2 :                                    pDevice->getPixel(aPt) == aCol4);
     226             : 
     227           2 :             const Color aCol5(0x00F0F0F0);
     228           2 :             pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
     229           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #8",
     230           2 :                                    pDevice->getPixel(aPt2) != aCol7);
     231             : 
     232           2 :             const Color aCol6(0x00FFFFFF);
     233           2 :             pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
     234           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #9",
     235           2 :                                    pDevice->getPixel(aPt3) == aCol6);
     236             :         }
     237             : 
     238             :         // 24bpp
     239             :         {
     240           4 :             pDevice = createBitmapDevice( aSize,
     241             :                                           true,
     242           2 :                                           FORMAT_TWENTYFOUR_BIT_TC_MASK );
     243             : 
     244           2 :             const Color aCol4(0x01010101);
     245           2 :             pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
     246           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #10",
     247           2 :                                    pDevice->getPixel(aPt) == aCol4);
     248             : 
     249           2 :             const Color aCol5(0x0F3F2F1F);
     250           2 :             pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
     251           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #11",
     252           2 :                                    pDevice->getPixel(aPt2) == aCol5);
     253             : 
     254           2 :             const Color aCol6(0xFFFFFFFF);
     255           2 :             pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
     256           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #12",
     257           2 :                                    pDevice->getPixel(aPt3) == aCol6);
     258             : 
     259           4 :             CPPUNIT_ASSERT_MESSAGE("raw pixel value #4",
     260             :                                    pDevice->getBuffer()[2] == 0x3F
     261             :                                    && pDevice->getBuffer()[1] == 0x2F
     262           2 :                                    && pDevice->getBuffer()[0] == 0x1F);
     263             :         }
     264             : 
     265             :         // 32bpp
     266             :         {
     267           4 :             pDevice = createBitmapDevice( aSize,
     268             :                                           true,
     269           2 :                                           FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA );
     270             : 
     271           2 :             const Color aCol4(0x01010101);
     272           2 :             pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
     273           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #13",
     274           2 :                                    pDevice->getPixel(aPt) == aCol4);
     275             : 
     276           2 :             const Color aCol5(0x0F0F0F0F);
     277           2 :             pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
     278           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #14",
     279           2 :                                    pDevice->getPixel(aPt2) == aCol5);
     280             : 
     281           2 :             const Color aCol6(0xFFFFFFFF);
     282           2 :             pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
     283           4 :             CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #15",
     284           2 :                                    pDevice->getPixel(aPt3) == aCol6);
     285           2 :         }
     286           2 :     }
     287             : 
     288             :     // Change the following lines only, if you add, remove or rename
     289             :     // member functions of the current class,
     290             :     // because these macros are need by auto register mechanism.
     291             : 
     292           4 :     CPPUNIT_TEST_SUITE(BasicTest);
     293           2 :     CPPUNIT_TEST(colorTest);
     294           2 :     CPPUNIT_TEST(testConstruction);
     295           2 :     CPPUNIT_TEST(testClone);
     296           2 :     CPPUNIT_TEST(testPixelFuncs);
     297           4 :     CPPUNIT_TEST_SUITE_END();
     298             : };
     299             : 
     300           2 : CPPUNIT_TEST_SUITE_REGISTRATION(BasicTest);
     301             : }
     302             : 
     303           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     304             : 
     305             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10