1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <unotest/filters-test.hxx>
11 #include <test/bootstrapfixture.hxx>
13 #include <osl/file.hxx>
14 #include <osl/process.h>
16 #include <vcl/graphicfilter.hxx>
18 using namespace ::com::sun::star
;
20 /* Implementation of Filters test */
22 class VclFiltersTest
:
23 public test::FiltersTest
,
24 public test::BootstrapFixture
26 GraphicFilter mGraphicFilter
;
29 BootstrapFixture(true, false),
30 mGraphicFilter(GraphicFilter(false))
33 virtual bool load(const OUString
&,
34 const OUString
&rURL
, const OUString
&,
35 SfxFilterFlags
, SotClipboardFormatId
, unsigned int) SAL_OVERRIDE
;
37 void checkExportImport(const OUString
& aFilterShortName
);
40 * Ensure CVEs remain unbroken
45 void testExportImport();
47 CPPUNIT_TEST_SUITE(VclFiltersTest
);
48 CPPUNIT_TEST(testCVEs
);
49 CPPUNIT_TEST(testScaling
);
50 CPPUNIT_TEST(testExportImport
);
51 CPPUNIT_TEST_SUITE_END();
54 bool VclFiltersTest::load(const OUString
&,
55 const OUString
&rURL
, const OUString
&,
56 SfxFilterFlags
, SotClipboardFormatId
, unsigned int)
58 SvFileStream
aFileStream(rURL
, StreamMode::READ
);
60 return mGraphicFilter
.ImportGraphic(aGraphic
, rURL
, aFileStream
) == 0;
63 void VclFiltersTest::testScaling()
65 for (BmpScaleFlag i
= BmpScaleFlag::Default
; i
<= BmpScaleFlag::Box
; i
= (BmpScaleFlag
)((int)i
+ 1))
67 Bitmap
aBitmap( Size( 413, 409 ), 24 );
68 BitmapEx
aBitmapEx( aBitmap
);
70 fprintf( stderr
, "scale with type %d\n", int( i
) );
71 CPPUNIT_ASSERT( aBitmapEx
.Scale( 0.1937046, 0.193154, i
) );
72 Size
aAfter( aBitmapEx
.GetSizePixel() );
73 fprintf( stderr
, "size %ld, %ld\n", (long)aAfter
.Width(),
75 CPPUNIT_ASSERT( labs (aAfter
.Height() - aAfter
.Width()) <= 1 );
79 void VclFiltersTest::checkExportImport(const OUString
& aFilterShortName
)
81 Bitmap
aBitmap( Size( 100, 100 ), 24 );
82 aBitmap
.Erase(COL_WHITE
);
84 SvMemoryStream aStream
;
85 aStream
.SetVersion( SOFFICE_FILEFORMAT_CURRENT
);
87 css::uno::Sequence
< css::beans::PropertyValue
> aFilterData( 3 );
88 aFilterData
[ 0 ].Name
= "Interlaced";
89 aFilterData
[ 0 ].Value
<<= (sal_Int32
) 0;
90 aFilterData
[ 1 ].Name
= "Compression";
91 aFilterData
[ 1 ].Value
<<= (sal_Int32
) 1;
92 aFilterData
[ 2 ].Name
= "Quality";
93 aFilterData
[ 2 ].Value
<<= (sal_Int32
) 90;
95 sal_uInt16 aFilterType
= mGraphicFilter
.GetExportFormatNumberForShortName(aFilterShortName
);
96 mGraphicFilter
.ExportGraphic( aBitmap
, OUString(), aStream
, aFilterType
, &aFilterData
);
98 CPPUNIT_ASSERT(aStream
.Tell() > 0);
100 aStream
.Seek( STREAM_SEEK_TO_BEGIN
);
102 Graphic aLoadedGraphic
;
103 mGraphicFilter
.ImportGraphic( aLoadedGraphic
, OUString(), aStream
);
105 BitmapEx aLoadedBitmapEx
= aLoadedGraphic
.GetBitmapEx();
106 Size aSize
= aLoadedBitmapEx
.GetSizePixel();
108 CPPUNIT_ASSERT_EQUAL(100L, aSize
.Width());
109 CPPUNIT_ASSERT_EQUAL(100L, aSize
.Height());
112 void VclFiltersTest::testExportImport()
114 fprintf(stderr
, "Check ExportImport JPG\n");
115 checkExportImport(OUString("jpg"));
116 fprintf(stderr
, "Check ExportImport PNG\n");
117 checkExportImport(OUString("png"));
118 fprintf(stderr
, "Check ExportImport BMP\n");
119 checkExportImport(OUString("bmp"));
122 void VclFiltersTest::testCVEs()
124 #ifndef DISABLE_CVE_TESTS
126 getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/wmf/"),
130 getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/emf/"),
134 getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/sgv/"),
138 getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/png/"),
142 getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/jpg/"),
146 getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/gif/"),
150 getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/bmp/"),
154 getURLFromSrc("/vcl/qa/cppunit/graphicfilter/data/xbm/"),
159 CPPUNIT_TEST_SUITE_REGISTRATION(VclFiltersTest
);
161 CPPUNIT_PLUGIN_IMPLEMENT();
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */