bump product version to 7.2.5.1
[LibreOffice.git] / xmloff / qa / unit / draw.cxx
blob3b0cda0f03837dd0152dae53ad1fe34db444f61d
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>
12 #include <test/xmltesttools.hxx>
14 #include <com/sun/star/beans/XPropertySet.hpp>
15 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
16 #include <com/sun/star/frame/Desktop.hpp>
17 #include <com/sun/star/frame/XStorable.hpp>
18 #include <com/sun/star/packages/zip/ZipFileAccess.hpp>
20 #include <unotools/mediadescriptor.hxx>
21 #include <unotools/tempfile.hxx>
22 #include <unotools/ucbstreamhelper.hxx>
24 using namespace ::com::sun::star;
26 constexpr OUStringLiteral DATA_DIRECTORY = u"/xmloff/qa/unit/data/";
28 /// Covers xmloff/source/draw/ fixes.
29 class XmloffDrawTest : public test::BootstrapFixture,
30 public unotest::MacrosTest,
31 public XmlTestTools
33 private:
34 uno::Reference<lang::XComponent> mxComponent;
36 public:
37 void setUp() override;
38 void tearDown() override;
39 void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override;
40 uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
43 void XmloffDrawTest::setUp()
45 test::BootstrapFixture::setUp();
47 mxDesktop.set(frame::Desktop::create(mxComponentContext));
50 void XmloffDrawTest::tearDown()
52 if (mxComponent.is())
53 mxComponent->dispose();
55 test::BootstrapFixture::tearDown();
58 void XmloffDrawTest::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
60 XmlTestTools::registerODFNamespaces(pXmlXpathCtx);
63 CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testTextBoxLoss)
65 // Load a document that has a shape with a textbox in it. Save it to ODF and reload.
66 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "textbox-loss.docx";
67 getComponent() = loadFromDesktop(aURL);
68 uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY);
69 utl::TempFile aTempFile;
70 aTempFile.EnableKillingFile();
71 utl::MediaDescriptor aMediaDescriptor;
72 aMediaDescriptor["FilterName"] <<= OUString("writer8");
73 xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
74 getComponent()->dispose();
75 getComponent() = loadFromDesktop(aTempFile.GetURL());
77 // Make sure that the shape is still a textbox.
78 uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(getComponent(), uno::UNO_QUERY);
79 uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
80 uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
81 bool bTextBox = false;
82 xShape->getPropertyValue("TextBox") >>= bTextBox;
84 // Without the accompanying fix in place, this test would have failed, as the shape only had
85 // editeng text, losing the image part of the shape text.
86 CPPUNIT_ASSERT(bTextBox);
89 CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testTdf141301_Extrusion_Angle)
91 // Load a document that has a custom shape with extrusion direction as set by LO as its default.
92 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf141301_Extrusion_Skew.odg";
93 getComponent() = loadFromDesktop(aURL, "com.sun.star.comp.drawing.DrawingDocument");
95 // Prepare use of XPath
96 uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY);
97 utl::TempFile aTempFile;
98 aTempFile.EnableKillingFile();
99 utl::MediaDescriptor aMediaDescriptor;
100 aMediaDescriptor["FilterName"] <<= OUString("draw8");
101 xStorable->storeAsURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
102 uno::Reference<packages::zip::XZipFileAccess2> xNameAccess
103 = packages::zip::ZipFileAccess::createWithURL(mxComponentContext, aTempFile.GetURL());
104 uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName("content.xml"),
105 uno::UNO_QUERY);
106 std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true));
107 xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get());
109 // Without fix draw:extrusion-skew="50 -135" was not written to file although "50 -135" is not
110 // default in ODF, but only default inside LO.
111 assertXPath(pXmlDoc, "//draw:enhanced-geometry", "extrusion-skew", "50 -135");
114 CPPUNIT_PLUGIN_IMPLEMENT();
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */