LCOV - code coverage report
Current view: top level - vcl/qa/cppunit/graphicfilter - filters-test.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 67 67 100.0 %
Date: 2015-06-13 12:38:46 Functions: 17 18 94.4 %
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             : 
      10             : #include <unotest/filters-test.hxx>
      11             : #include <test/bootstrapfixture.hxx>
      12             : 
      13             : #include <osl/file.hxx>
      14             : #include <osl/process.h>
      15             : 
      16             : #include <vcl/graphicfilter.hxx>
      17             : 
      18             : using namespace ::com::sun::star;
      19             : 
      20             : /* Implementation of Filters test */
      21             : 
      22           6 : class VclFiltersTest :
      23             :     public test::FiltersTest,
      24             :     public test::BootstrapFixture
      25             : {
      26             :     GraphicFilter mGraphicFilter;
      27             : public:
      28           3 :     VclFiltersTest() :
      29             :         BootstrapFixture(true, false),
      30           3 :         mGraphicFilter(GraphicFilter(false))
      31           3 :     {}
      32             : 
      33             :     virtual bool load(const OUString &,
      34             :         const OUString &rURL, const OUString &,
      35             :         SfxFilterFlags, SotClipboardFormatId, unsigned int) SAL_OVERRIDE;
      36             : 
      37             :     void checkExportImport(const OUString& aFilterShortName);
      38             : 
      39             :     /**
      40             :      * Ensure CVEs remain unbroken
      41             :      */
      42             :     void testCVEs();
      43             : 
      44             :     void testScaling();
      45             :     void testExportImport();
      46             : 
      47           2 :     CPPUNIT_TEST_SUITE(VclFiltersTest);
      48           1 :     CPPUNIT_TEST(testCVEs);
      49           1 :     CPPUNIT_TEST(testScaling);
      50           1 :     CPPUNIT_TEST(testExportImport);
      51           5 :     CPPUNIT_TEST_SUITE_END();
      52             : };
      53             : 
      54          69 : bool VclFiltersTest::load(const OUString &,
      55             :     const OUString &rURL, const OUString &,
      56             :     SfxFilterFlags, SotClipboardFormatId, unsigned int)
      57             : {
      58          69 :     SvFileStream aFileStream(rURL, StreamMode::READ);
      59         138 :     Graphic aGraphic;
      60         138 :     return mGraphicFilter.ImportGraphic(aGraphic, rURL, aFileStream) == 0;
      61             : }
      62             : 
      63           1 : void VclFiltersTest::testScaling()
      64             : {
      65          10 :     for (BmpScaleFlag i = BmpScaleFlag::Default; i <= BmpScaleFlag::Box; i = (BmpScaleFlag)((int)i + 1))
      66             :     {
      67           9 :         Bitmap aBitmap( Size( 413, 409 ), 24 );
      68          18 :         BitmapEx aBitmapEx( aBitmap );
      69             : 
      70           9 :         fprintf( stderr, "scale with type %d\n", int( i ) );
      71           9 :         CPPUNIT_ASSERT( aBitmapEx.Scale( 0.1937046, 0.193154, i ) );
      72           9 :         Size aAfter( aBitmapEx.GetSizePixel() );
      73           9 :         fprintf( stderr, "size %ld, %ld\n", (long)aAfter.Width(),
      74          18 :                  aAfter.Height() );
      75           9 :         CPPUNIT_ASSERT( labs (aAfter.Height() - aAfter.Width()) <= 1 );
      76           9 :     }
      77           1 : }
      78             : 
      79           3 : void VclFiltersTest::checkExportImport(const OUString& aFilterShortName)
      80             : {
      81           3 :     Bitmap aBitmap( Size( 100, 100 ), 24 );
      82           3 :     aBitmap.Erase(COL_WHITE);
      83             : 
      84           6 :     SvMemoryStream aStream;
      85           3 :     aStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
      86             : 
      87           6 :     css::uno::Sequence< css::beans::PropertyValue > aFilterData( 3 );
      88           3 :     aFilterData[ 0 ].Name = "Interlaced";
      89           3 :     aFilterData[ 0 ].Value <<= (sal_Int32) 0;
      90           3 :     aFilterData[ 1 ].Name = "Compression";
      91           3 :     aFilterData[ 1 ].Value <<= (sal_Int32) 1;
      92           3 :     aFilterData[ 2 ].Name = "Quality";
      93           3 :     aFilterData[ 2 ].Value <<= (sal_Int32) 90;
      94             : 
      95           3 :     sal_uInt16 aFilterType = mGraphicFilter.GetExportFormatNumberForShortName(aFilterShortName);
      96           3 :     mGraphicFilter.ExportGraphic( aBitmap, OUString(), aStream, aFilterType, &aFilterData );
      97             : 
      98           3 :     CPPUNIT_ASSERT(aStream.Tell() > 0);
      99             : 
     100           3 :     aStream.Seek( STREAM_SEEK_TO_BEGIN );
     101             : 
     102           6 :     Graphic aLoadedGraphic;
     103           3 :     mGraphicFilter.ImportGraphic( aLoadedGraphic, OUString(), aStream );
     104             : 
     105           6 :     BitmapEx aLoadedBitmapEx = aLoadedGraphic.GetBitmapEx();
     106           3 :     Size aSize = aLoadedBitmapEx.GetSizePixel();
     107             : 
     108           3 :     CPPUNIT_ASSERT_EQUAL(100L, aSize.Width());
     109           6 :     CPPUNIT_ASSERT_EQUAL(100L, aSize.Height());
     110           3 : }
     111             : 
     112           1 : void VclFiltersTest::testExportImport()
     113             : {
     114           1 :     fprintf(stderr, "Check ExportImport JPG\n");
     115           1 :     checkExportImport(OUString("jpg"));
     116           1 :     fprintf(stderr, "Check ExportImport PNG\n");
     117           1 :     checkExportImport(OUString("png"));
     118           1 :     fprintf(stderr, "Check ExportImport BMP\n");
     119           1 :     checkExportImport(OUString("bmp"));
     120           1 : }
     121             : 
     122           1 : void VclFiltersTest::testCVEs()
     123             : {
     124             : #ifndef DISABLE_CVE_TESTS
     125             :     testDir(OUString(),
     126             :         getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/wmf/"),
     127           1 :         OUString());
     128             : 
     129             :     testDir(OUString(),
     130             :         getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/emf/"),
     131           1 :         OUString());
     132             : 
     133             :     testDir(OUString(),
     134             :         getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/sgv/"),
     135           1 :         OUString());
     136             : 
     137             :     testDir(OUString(),
     138             :         getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/png/"),
     139           1 :         OUString());
     140             : 
     141             :     testDir(OUString(),
     142             :         getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/jpg/"),
     143           1 :         OUString());
     144             : 
     145             :     testDir(OUString(),
     146             :         getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/gif/"),
     147           1 :         OUString());
     148             : 
     149             :     testDir(OUString(),
     150             :         getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/bmp/"),
     151           1 :         OUString());
     152             : #endif
     153           1 : }
     154             : 
     155           1 : CPPUNIT_TEST_SUITE_REGISTRATION(VclFiltersTest);
     156             : 
     157           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     158             : 
     159             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11