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

Generated by: LCOV version 1.10