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

Generated by: LCOV version 1.10