summaryrefslogtreecommitdiff
path: root/svx/qa
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-06-28 17:50:40 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-06-29 07:04:24 +0000
commitdf8bb7b32161ede37a0a82b421046435ad586f5c (patch)
tree9e83875fee0a9ed50d4ac7280f4fdc4eee73aaaf /svx/qa
parent1ce7176ba1b39f02ab45056023f8e7622f48cc74 (diff)
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 <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'svx/qa')
-rw-r--r--svx/qa/unit/data/graphic.pdfbin0 -> 7243 bytes
-rw-r--r--svx/qa/unit/xoutdev.cxx65
2 files changed, 65 insertions, 0 deletions
diff --git a/svx/qa/unit/data/graphic.pdf b/svx/qa/unit/data/graphic.pdf
new file mode 100644
index 000000000000..4b53d2056549
--- /dev/null
+++ b/svx/qa/unit/data/graphic.pdf
Binary files 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 <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <sal/types.h>
+#include <tools/stream.hxx>
+#include <unotest/directories.hxx>
+#include <unotools/tempfile.hxx>
+#include <vcl/graph.hxx>
+#include <vcl/graphicfilter.hxx>
+#include <svx/xoutbmp.hxx>
+
+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<sal_uInt16>(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<sal_uInt8>('%'), sFirstBytes[0]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('P'), sFirstBytes[1]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('D'), sFirstBytes[2]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('F'), sFirstBytes[3]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('-'), sFirstBytes[4]);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(XOutdevTest);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */