Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / qa / unit / xoutdev.cxx
blob800c709770de0774ea7317a479d000e025eddd14
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 <test/unoapi_test.hxx>
12 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
13 #include <com/sun/star/beans/XPropertySet.hpp>
15 #include <sal/types.h>
16 #include <tools/stream.hxx>
17 #include <unotools/tempfile.hxx>
18 #include <vcl/graph.hxx>
19 #include <vcl/graphicfilter.hxx>
20 #include <svx/xoutbmp.hxx>
21 #include <vcl/filter/PDFiumLibrary.hxx>
22 #include <docmodel/uno/UnoComplexColor.hxx>
24 using namespace com::sun::star;
26 class XOutdevTest : public UnoApiTest
28 public:
29 XOutdevTest()
30 : UnoApiTest("svx/qa/unit/data/")
35 CPPUNIT_TEST_FIXTURE(XOutdevTest, testPdfGraphicExport)
37 auto pPdfium = vcl::pdf::PDFiumLibrary::get();
38 if (!pPdfium)
40 return;
43 // Import the graphic.
44 Graphic aGraphic;
45 OUString aURL = createFileURL(u"graphic.pdf");
46 SvFileStream aStream(aURL, StreamMode::READ);
47 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE,
48 GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURL, aStream));
50 // Export it.
51 XOutFlags const eFlags = XOutFlags::DontExpandFilename | XOutFlags::DontAddExtension
52 | XOutFlags::UseNativeIfPossible;
53 OUString aTempURL = maTempFile.GetURL();
54 XOutBitmap::WriteGraphic(aGraphic, aTempURL, "pdf", eFlags);
56 // Assert that the output looks like a PDF.
57 SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
58 CPPUNIT_ASSERT(pStream->TellEnd() > 5);
59 sal_uInt8 sFirstBytes[5];
60 pStream->ReadBytes(sFirstBytes, 5);
61 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('%'), sFirstBytes[0]);
62 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('P'), sFirstBytes[1]);
63 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('D'), sFirstBytes[2]);
64 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('F'), sFirstBytes[3]);
65 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('-'), sFirstBytes[4]);
68 CPPUNIT_TEST_FIXTURE(XOutdevTest, testTdf60684)
70 Graphic aGraphic;
71 OUString aURL = createFileURL(u"tdf60684.jpg");
72 SvFileStream aStream(aURL, StreamMode::READ);
73 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE,
74 GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURL, aStream));
76 // Export it.
77 XOutFlags const eFlags = XOutFlags::DontExpandFilename | XOutFlags::DontAddExtension
78 | XOutFlags::UseNativeIfPossible;
79 OUString aTempURL = maTempFile.GetURL();
80 XOutBitmap::WriteGraphic(aGraphic, aTempURL, "png", eFlags);
82 SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
83 CPPUNIT_ASSERT(pStream->TellEnd() > 4);
84 sal_uInt8 sFirstBytes[4];
85 pStream->ReadBytes(sFirstBytes, 4);
87 //Checks if the file's header matches a PNG's expected header
88 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('P'), sFirstBytes[1]);
89 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('N'), sFirstBytes[2]);
90 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('G'), sFirstBytes[3]);
93 CPPUNIT_TEST_FIXTURE(XOutdevTest, testFillColorThemeUnoApi)
95 // Given an empty Impress document with a (title) shape:
96 mxComponent = loadFromDesktop("private:factory/simpress",
97 "com.sun.star.presentation.PresentationDocument");
99 // When setting the theme index of the shape's fill color:
100 uno::Reference<drawing::XDrawPagesSupplier> xPagesSupplier(mxComponent, uno::UNO_QUERY);
101 uno::Reference<drawing::XDrawPage> xPage(xPagesSupplier->getDrawPages()->getByIndex(0),
102 uno::UNO_QUERY);
103 uno::Reference<beans::XPropertySet> xShape(xPage->getByIndex(0), uno::UNO_QUERY);
104 // Set theme color
106 model::ComplexColor aComplexColor;
107 aComplexColor.setSchemeColor(model::ThemeColorType::Accent1);
108 aComplexColor.addTransformation({ model::TransformationType::LumMod, 2000 });
109 aComplexColor.addTransformation({ model::TransformationType::LumOff, 8000 });
110 xShape->setPropertyValue("FillComplexColor",
111 uno::Any(model::color::createXComplexColor(aComplexColor)));
114 // Then make sure the value we read back is the expected one:
116 uno::Reference<util::XComplexColor> xComplexColor;
117 CPPUNIT_ASSERT(xShape->getPropertyValue("FillComplexColor") >>= xComplexColor);
118 CPPUNIT_ASSERT(xComplexColor.is());
119 auto aComplexColor = model::color::getFromXComplexColor(xComplexColor);
120 CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent1, aComplexColor.getSchemeType());
121 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod,
122 aComplexColor.getTransformations()[0].meType);
123 CPPUNIT_ASSERT_EQUAL(sal_Int16(2000), aComplexColor.getTransformations()[0].mnValue);
124 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff,
125 aComplexColor.getTransformations()[1].meType);
126 CPPUNIT_ASSERT_EQUAL(sal_Int16(8000), aComplexColor.getTransformations()[1].mnValue);
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */