Bump version to 6.4-15
[LibreOffice.git] / svx / qa / unit / xoutdev.cxx
blob308c484a7ba17635ffeefd564340560855a84aa6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <config_features.h>
12 #include <cppunit/TestAssert.h>
13 #include <cppunit/TestFixture.h>
14 #include <unotest/bootstrapfixturebase.hxx>
16 #include <sal/types.h>
17 #include <sfx2/app.hxx>
18 #include <tools/stream.hxx>
19 #include <unotest/directories.hxx>
20 #include <unotools/tempfile.hxx>
21 #include <vcl/graph.hxx>
22 #include <vcl/graphicfilter.hxx>
23 #include <svx/xoutbmp.hxx>
25 class XOutdevTest : public CppUnit::TestFixture
27 public:
28 virtual void setUp() override
30 CppUnit::TestFixture::setUp();
31 SfxApplication::GetOrCreate();
35 CPPUNIT_TEST_FIXTURE(XOutdevTest, testPdfGraphicExport)
37 #if HAVE_FEATURE_PDFIUM
38 // Import the graphic.
39 Graphic aGraphic;
40 test::Directories aDirectories;
41 OUString aURL = aDirectories.getURLFromSrc("svx/qa/unit/data/graphic.pdf");
42 SvFileStream aStream(aURL, StreamMode::READ);
43 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURL, aStream));
45 // Export it.
46 utl::TempFile aTempFile;
47 aTempFile.EnableKillingFile();
48 XOutFlags const eFlags = XOutFlags::DontExpandFilename | XOutFlags::DontAddExtension | XOutFlags::UseNativeIfPossible;
49 OUString aTempURL = aTempFile.GetURL();
50 XOutBitmap::WriteGraphic(aGraphic, aTempURL, "pdf", eFlags);
52 // Assert that the output looks like a PDF.
53 SvStream* pStream = aTempFile.GetStream(StreamMode::READ);
54 CPPUNIT_ASSERT(pStream->TellEnd() > 5);
55 sal_uInt8 sFirstBytes[5];
56 pStream->ReadBytes(sFirstBytes, 5);
57 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('%'), sFirstBytes[0]);
58 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('P'), sFirstBytes[1]);
59 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('D'), sFirstBytes[2]);
60 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('F'), sFirstBytes[3]);
61 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('-'), sFirstBytes[4]);
62 #endif
65 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */