nss: upgrade to release 3.73
[LibreOffice.git] / oox / qa / unit / drawingml.cxx
blobe1c665e22e866cc4e1eed77489dd4e910ebb8af9
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/bootstrapfixture.hxx>
11 #include <unotest/macros_test.hxx>
13 #include <com/sun/star/awt/Gradient.hpp>
14 #include <com/sun/star/beans/XPropertySet.hpp>
15 #include <com/sun/star/container/XNamed.hpp>
16 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
17 #include <com/sun/star/drawing/FillStyle.hpp>
18 #include <com/sun/star/drawing/XShape.hpp>
19 #include <com/sun/star/frame/Desktop.hpp>
20 #include <com/sun/star/frame/XStorable.hpp>
21 #include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp>
22 #include <com/sun/star/chart2/XChartDocument.hpp>
23 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
24 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
25 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
26 #include <com/sun/star/chart2/XDataPointCustomLabelField.hpp>
27 #include <com/sun/star/style/ParagraphAdjust.hpp>
28 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
30 #include <unotools/mediadescriptor.hxx>
31 #include <unotools/tempfile.hxx>
33 using namespace ::com::sun::star;
35 namespace
37 /// Gets one child of xShape, which one is specified by nIndex.
38 uno::Reference<drawing::XShape> getChildShape(const uno::Reference<drawing::XShape>& xShape,
39 sal_Int32 nIndex)
41 uno::Reference<container::XIndexAccess> xGroup(xShape, uno::UNO_QUERY);
42 CPPUNIT_ASSERT(xGroup.is());
44 CPPUNIT_ASSERT(xGroup->getCount() > nIndex);
46 uno::Reference<drawing::XShape> xRet(xGroup->getByIndex(nIndex), uno::UNO_QUERY);
47 CPPUNIT_ASSERT(xRet.is());
49 return xRet;
53 /// oox drawingml tests.
54 class OoxDrawingmlTest : public test::BootstrapFixture, public unotest::MacrosTest
56 private:
57 uno::Reference<lang::XComponent> mxComponent;
59 public:
60 void setUp() override;
61 void tearDown() override;
62 uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
63 void load(const OUString& rURL);
64 void loadAndReload(const OUString& rURL, const OUString& rFilterName);
67 void OoxDrawingmlTest::setUp()
69 test::BootstrapFixture::setUp();
71 mxDesktop.set(frame::Desktop::create(mxComponentContext));
74 void OoxDrawingmlTest::tearDown()
76 if (mxComponent.is())
77 mxComponent->dispose();
79 test::BootstrapFixture::tearDown();
82 void OoxDrawingmlTest::load(const OUString& rURL) { mxComponent = loadFromDesktop(rURL); }
84 void OoxDrawingmlTest::loadAndReload(const OUString& rURL, const OUString& rFilterName)
86 load(rURL);
87 uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
88 utl::MediaDescriptor aMediaDescriptor;
89 aMediaDescriptor["FilterName"] <<= rFilterName;
90 utl::TempFile aTempFile;
91 aTempFile.EnableKillingFile();
92 xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
93 mxComponent->dispose();
94 validate(aTempFile.GetFileName(), test::OOXML);
95 mxComponent = loadFromDesktop(aTempFile.GetURL());
98 char const DATA_DIRECTORY[] = "/oox/qa/unit/data/";
100 CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTransparentText)
102 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "transparent-text.pptx";
103 loadAndReload(aURL, "Impress Office Open XML");
105 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
106 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
107 uno::UNO_QUERY);
108 uno::Reference<container::XEnumerationAccess> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
109 uno::Reference<container::XEnumerationAccess> xParagraph(
110 xShape->createEnumeration()->nextElement(), uno::UNO_QUERY);
111 uno::Reference<beans::XPropertySet> xPortion(xParagraph->createEnumeration()->nextElement(),
112 uno::UNO_QUERY);
114 sal_Int16 nTransparency = 0;
115 xPortion->getPropertyValue("CharTransparence") >>= nTransparency;
117 // Without the accompanying fix in place, this test would have failed with:
118 // - Expected: 75
119 // - Actual : 0
120 // i.e. the transparency of the character color was lost on import/export.
121 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(75), nTransparency);
124 CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTdf131082)
126 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf131082.pptx";
127 loadAndReload(aURL, "Impress Office Open XML");
129 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
130 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
131 uno::UNO_QUERY);
133 uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
134 uno::Reference<beans::XPropertySet> XPropSet(getChildShape(getChildShape(xShape, 0), 0),
135 uno::UNO_QUERY);
137 drawing::FillStyle eFillStyle = drawing::FillStyle_NONE;
138 XPropSet->getPropertyValue("FillStyle") >>= eFillStyle;
140 // Without the accompanying fix in place, this test would have failed with:
141 // with drawing::FillStyle_NONE - 0
142 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_SOLID, eFillStyle);
145 CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testPresetAdjustValue)
147 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "preset-adjust-value.pptx";
149 load(aURL);
151 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
152 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
153 uno::UNO_QUERY);
154 uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
155 uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
156 uno::Sequence<beans::PropertyValue> aGeoPropSeq;
157 xShapeProps->getPropertyValue("CustomShapeGeometry") >>= aGeoPropSeq;
158 comphelper::SequenceAsHashMap aGeoPropMap(aGeoPropSeq);
159 uno::Sequence<drawing::EnhancedCustomShapeAdjustmentValue> aAdjustmentSeq;
160 aGeoPropMap.getValue("AdjustmentValues") >>= aAdjustmentSeq;
161 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aAdjustmentSeq.getLength());
162 // Without the accompanying fix in place, this test would have failed with:
163 // - Expected: 11587
164 // - Actual : 10813
165 // i.e. the adjust value was set from the placeholder, not from the shape.
166 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(11587), aAdjustmentSeq[0].Value.get<sal_Int32>());
169 CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testChartDataLabelCharColor)
171 OUString aURL
172 = m_directories.getURLFromSrc(DATA_DIRECTORY) + "chart-data-label-char-color.docx";
173 load(aURL);
175 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
176 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
177 uno::UNO_QUERY);
178 uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
179 uno::Reference<chart2::XChartDocument> xModel(xShape->getPropertyValue("Model"),
180 uno::UNO_QUERY);
181 uno::Reference<chart2::XCoordinateSystemContainer> xDiagram(xModel->getFirstDiagram(),
182 uno::UNO_QUERY);
184 uno::Reference<chart2::XChartTypeContainer> xCoordinateSystem(
185 xDiagram->getCoordinateSystems()[0], uno::UNO_QUERY);
187 uno::Reference<chart2::XDataSeriesContainer> xChartType(xCoordinateSystem->getChartTypes()[0],
188 uno::UNO_QUERY);
190 uno::Reference<chart2::XDataSeries> xDataSeries = xChartType->getDataSeries()[0];
192 uno::Reference<beans::XPropertySet> xDataPoint = xDataSeries->getDataPointByIndex(0);
194 uno::Sequence<uno::Reference<chart2::XDataPointCustomLabelField>> aLabels;
195 xDataPoint->getPropertyValue("CustomLabelFields") >>= aLabels;
196 uno::Reference<beans::XPropertySet> xLabel = aLabels[0];
198 sal_Int32 nCharColor = 0;
199 xLabel->getPropertyValue("CharColor") >>= nCharColor;
200 // Without the accompanying fix in place, this test would have failed with:
201 // - Expected: 16777215
202 // - Actual : -1
203 // i.e. the data label had no explicit (white) color.
204 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0xffffff), nCharColor);
207 CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testGradientMultiStepTransparency)
209 // Load a document with a multi-step gradient.
210 OUString aURL
211 = m_directories.getURLFromSrc(DATA_DIRECTORY) + "gradient-multistep-transparency.pptx";
212 load(aURL);
214 // Check the end transparency of the gradient.
215 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
216 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
217 uno::UNO_QUERY);
218 uno::Reference<container::XNamed> xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY);
219 CPPUNIT_ASSERT_EQUAL(OUString("Rectangle 4"), xShape->getName());
220 uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
221 awt::Gradient aTransparence;
222 xShapeProps->getPropertyValue("FillTransparenceGradient") >>= aTransparence;
224 // Without the accompanying fix in place, this test would have failed with:
225 // - Expected: 16777215 (0xffffff)
226 // - Actual : 3487029 (0x353535)
227 // i.e. the end transparency was not 100%, but was 21%, leading to an unexpected visible line on
228 // the right of this shape.
229 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0xffffff), aTransparence.EndColor);
232 CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testShapeTextAlignment)
234 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "shape-text-alignment.pptx";
235 load(aURL);
237 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
238 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
239 uno::UNO_QUERY);
240 uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
241 sal_Int16 nParaAdjust = -1;
242 CPPUNIT_ASSERT(xShape->getPropertyValue("ParaAdjust") >>= nParaAdjust);
243 // Without the accompanying fix in place, this test would have failed with:
244 // - Expected: 0
245 // - Actual : 3
246 // i.e. text which is meant to be left-aligned was centered at a paragraph level.
247 CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_LEFT,
248 static_cast<style::ParagraphAdjust>(nParaAdjust));
251 CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testShapeTextAdjustLeft)
253 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "shape-text-adjust-left.pptx";
254 load(aURL);
256 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
257 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
258 uno::UNO_QUERY);
259 uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
260 drawing::TextHorizontalAdjust eAdjust;
261 // Without the accompanying fix in place, this test would have failed with:
262 // - Expected: 3 (center)
263 // - Actual : 1 (block)
264 // i.e. text was center-adjusted, not default-adjusted (~left).
265 CPPUNIT_ASSERT(xShape->getPropertyValue("TextHorizontalAdjust") >>= eAdjust);
266 CPPUNIT_ASSERT_EQUAL(drawing::TextHorizontalAdjust_BLOCK, eAdjust);
269 CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testCameraRotationRevolution)
271 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "camera-rotation-revolution.docx";
272 load(aURL);
274 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
275 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
276 uno::UNO_QUERY);
277 uno::Reference<container::XNamed> xShape0(xDrawPage->getByIndex(0), uno::UNO_QUERY);
278 uno::Reference<container::XNamed> xShape1(xDrawPage->getByIndex(1), uno::UNO_QUERY);
279 uno::Reference<beans::XPropertySet> xShapeProps0(xShape0, uno::UNO_QUERY);
280 uno::Reference<beans::XPropertySet> xShapeProps1(xShape1, uno::UNO_QUERY);
281 sal_Int32 nRotateAngle0;
282 sal_Int32 nRotateAngle1;
283 xShapeProps0->getPropertyValue("RotateAngle") >>= nRotateAngle0;
284 xShapeProps1->getPropertyValue("RotateAngle") >>= nRotateAngle1;
286 // Without the accompanying fix in place, this test would have failed with:
287 // - Expected: 8000
288 // - Actual : 0
289 // so the camera rotation would not have been factored into how the shape is displayed
290 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(8000), nRotateAngle0);
291 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(27000), nRotateAngle1);
294 CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTableShadow)
296 auto verify = [](const uno::Reference<lang::XComponent>& xComponent) {
297 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY);
298 uno::Reference<drawing::XDrawPage> xDrawPage(
299 xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
300 uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
301 bool bShadow = false;
302 CPPUNIT_ASSERT(xShape->getPropertyValue("Shadow") >>= bShadow);
304 CPPUNIT_ASSERT(bShadow);
305 sal_Int32 nColor = 0;
306 CPPUNIT_ASSERT(xShape->getPropertyValue("ShadowColor") >>= nColor);
307 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0xff0000), nColor);
309 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "table-shadow.pptx";
310 load(aURL);
311 // Without the accompanying fix in place, this test would have failed, because shadow on a table
312 // was lost on import.
313 verify(getComponent());
315 uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY);
316 utl::MediaDescriptor aMediaDescriptor;
317 aMediaDescriptor["FilterName"] <<= OUString("Impress Office Open XML");
318 utl::TempFile aTempFile;
319 aTempFile.EnableKillingFile();
320 xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
321 getComponent()->dispose();
322 validate(aTempFile.GetFileName(), test::OOXML);
323 getComponent() = loadFromDesktop(aTempFile.GetURL());
324 // Without the accompanying fix in place, this test would have failed, because shadow on a table
325 // was lost on export.
326 verify(getComponent());
329 CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testGroupShapeSmartArt)
331 // Given a file with a smartart inside a group shape:
332 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "smartart-groupshape.pptx";
334 // When loading that file:
335 load(aURL);
337 // Then make sure that the smartart is not just an empty group shape:
338 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
339 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
340 uno::UNO_QUERY);
341 uno::Reference<drawing::XShapes> xGroup(xDrawPage->getByIndex(0), uno::UNO_QUERY);
342 uno::Reference<drawing::XShapes> xSmartArt(xGroup->getByIndex(0), uno::UNO_QUERY);
343 // Without the accompanying fix in place, this test would have failed, because we lost all
344 // children of the group shape representing the smartart.
345 CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(0), xSmartArt->getCount());
348 CPPUNIT_PLUGIN_IMPLEMENT();
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */