From df8bb7b32161ede37a0a82b421046435ad586f5c Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 28 Jun 2016 17:50:40 +0200 Subject: svx: add XOutBitmap testcase This fails with commit 7d76bb251e0c88ff17282a33b801a5d17a434af5 (vcl: add graphic export-as-pdf filter, 2016-06-24) reverted. Change-Id: Idea5c282d610d949958d757677ee642d97ca1c8e Reviewed-on: https://gerrit.libreoffice.org/26747 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- svx/CppunitTest_svx_unit.mk | 11 ++++++++ svx/qa/unit/data/graphic.pdf | Bin 0 -> 7243 bytes svx/qa/unit/xoutdev.cxx | 65 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 svx/qa/unit/data/graphic.pdf create mode 100644 svx/qa/unit/xoutdev.cxx (limited to 'svx') diff --git a/svx/CppunitTest_svx_unit.mk b/svx/CppunitTest_svx_unit.mk index 0e9fea3591a4..765f3858c6cb 100644 --- a/svx/CppunitTest_svx_unit.mk +++ b/svx/CppunitTest_svx_unit.mk @@ -19,11 +19,22 @@ $(eval $(call gb_CppunitTest_set_include,svx_unit,\ $(eval $(call gb_CppunitTest_add_exception_objects,svx_unit, \ svx/qa/unit/svdraw/test_SdrTextObject \ + svx/qa/unit/xoutdev \ )) $(eval $(call gb_CppunitTest_use_libraries,svx_unit, \ sal \ svxcore \ + tl \ + unotest \ + vcl \ + utl \ )) +$(eval $(call gb_CppunitTest_use_sdk_api,svx_unit)) +$(eval $(call gb_CppunitTest_use_ure,svx_unit)) +$(eval $(call gb_CppunitTest_use_vcl,svx_unit)) +$(eval $(call gb_CppunitTest_use_rdb,svx_unit,services)) +$(eval $(call gb_CppunitTest_use_configuration,svx_unit)) + # vim: set noet sw=4 ts=4: diff --git a/svx/qa/unit/data/graphic.pdf b/svx/qa/unit/data/graphic.pdf new file mode 100644 index 000000000000..4b53d2056549 Binary files /dev/null and b/svx/qa/unit/data/graphic.pdf differ diff --git a/svx/qa/unit/xoutdev.cxx b/svx/qa/unit/xoutdev.cxx new file mode 100644 index 000000000000..468d7aef6414 --- /dev/null +++ b/svx/qa/unit/xoutdev.cxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +class XOutdevTest : public CppUnit::TestFixture +{ +public: + void testPdfGraphicExport(); + + CPPUNIT_TEST_SUITE(XOutdevTest); + CPPUNIT_TEST(testPdfGraphicExport); + CPPUNIT_TEST_SUITE_END(); +}; + +void XOutdevTest::testPdfGraphicExport() +{ + // Import the graphic. + Graphic aGraphic; + test::Directories aDirectories; + OUString aURL = aDirectories.getURLFromSrc("svx/qa/unit/data/graphic.pdf"); + SvFileStream aStream(aURL, StreamMode::READ); + CPPUNIT_ASSERT_EQUAL(static_cast(GRFILTER_OK), GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURL, aStream)); + + // Export it. + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(true); + XOutFlags eFlags = XOutFlags::DontExpandFilename | XOutFlags::DontAddExtension | XOutFlags::UseNativeIfPossible; + OUString aTempURL = aTempFile.GetURL(); + XOutBitmap::WriteGraphic(aGraphic, aTempURL, "pdf", eFlags); + + // Assert that the output looks like a PDF. + SvStream* pStream = aTempFile.GetStream(StreamMode::READ); + pStream->Seek(STREAM_SEEK_TO_END); + CPPUNIT_ASSERT(pStream->Tell() > 5); + pStream->Seek(STREAM_SEEK_TO_BEGIN); + sal_uInt8 sFirstBytes[5]; + pStream->ReadBytes(sFirstBytes, 5); + CPPUNIT_ASSERT_EQUAL(static_cast('%'), sFirstBytes[0]); + CPPUNIT_ASSERT_EQUAL(static_cast('P'), sFirstBytes[1]); + CPPUNIT_ASSERT_EQUAL(static_cast('D'), sFirstBytes[2]); + CPPUNIT_ASSERT_EQUAL(static_cast('F'), sFirstBytes[3]); + CPPUNIT_ASSERT_EQUAL(static_cast('-'), sFirstBytes[4]); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(XOutdevTest); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit