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 <cppunit/TestAssert.h>
11 #include <cppunit/TestFixture.h>
12 #include <cppunit/extensions/HelperMacros.h>
13 #include <unotest/bootstrapfixturebase.hxx>
15 #include <sal/types.h>
16 #include <sfx2/app.hxx>
17 #include <tools/stream.hxx>
18 #include <unotest/directories.hxx>
19 #include <unotools/tempfile.hxx>
20 #include <vcl/graph.hxx>
21 #include <vcl/graphicfilter.hxx>
22 #include <svx/xoutbmp.hxx>
23 #include <vcl/filter/PDFiumLibrary.hxx>
25 class XOutdevTest
: public CppUnit::TestFixture
28 virtual void setUp() override
30 CppUnit::TestFixture::setUp();
31 SfxApplication::GetOrCreate();
35 CPPUNIT_TEST_FIXTURE(XOutdevTest
, testPdfGraphicExport
)
37 auto pPdfium
= vcl::pdf::PDFiumLibrary::get();
43 // Import the graphic.
45 test::Directories aDirectories
;
46 OUString aURL
= aDirectories
.getURLFromSrc(u
"svx/qa/unit/data/graphic.pdf");
47 SvFileStream
aStream(aURL
, StreamMode::READ
);
48 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE
,
49 GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic
, aURL
, aStream
));
52 utl::TempFile aTempFile
;
53 aTempFile
.EnableKillingFile();
54 XOutFlags
const eFlags
= XOutFlags::DontExpandFilename
| XOutFlags::DontAddExtension
55 | XOutFlags::UseNativeIfPossible
;
56 OUString aTempURL
= aTempFile
.GetURL();
57 XOutBitmap::WriteGraphic(aGraphic
, aTempURL
, "pdf", eFlags
);
59 // Assert that the output looks like a PDF.
60 SvStream
* pStream
= aTempFile
.GetStream(StreamMode::READ
);
61 CPPUNIT_ASSERT(pStream
->TellEnd() > 5);
62 sal_uInt8 sFirstBytes
[5];
63 pStream
->ReadBytes(sFirstBytes
, 5);
64 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('%'), sFirstBytes
[0]);
65 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('P'), sFirstBytes
[1]);
66 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('D'), sFirstBytes
[2]);
67 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('F'), sFirstBytes
[3]);
68 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('-'), sFirstBytes
[4]);
71 CPPUNIT_TEST_FIXTURE(XOutdevTest
, testTdf60684
)
74 test::Directories aDirectories
;
75 OUString aURL
= aDirectories
.getURLFromSrc(u
"svx/qa/unit/data/tdf60684.jpg");
76 SvFileStream
aStream(aURL
, StreamMode::READ
);
77 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE
,
78 GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic
, aURL
, aStream
));
81 utl::TempFile aTempFile
;
82 aTempFile
.EnableKillingFile();
83 XOutFlags
const eFlags
= XOutFlags::DontExpandFilename
| XOutFlags::DontAddExtension
84 | XOutFlags::UseNativeIfPossible
;
85 OUString aTempURL
= aTempFile
.GetURL();
86 XOutBitmap::WriteGraphic(aGraphic
, aTempURL
, "png", eFlags
);
88 SvStream
* pStream
= aTempFile
.GetStream(StreamMode::READ
);
89 CPPUNIT_ASSERT(pStream
->TellEnd() > 4);
90 sal_uInt8 sFirstBytes
[4];
91 pStream
->ReadBytes(sFirstBytes
, 4);
93 //Checks if the file's header matches a PNG's expected header
94 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('P'), sFirstBytes
[1]);
95 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('N'), sFirstBytes
[2]);
96 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('G'), sFirstBytes
[3]);
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */