1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <test/bootstrapfixture.hxx>
11 #include <unotest/macros_test.hxx>
13 #include <com/sun/star/awt/Point.hpp>
14 #include <com/sun/star/awt/Size.hpp>
15 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
16 #include <com/sun/star/frame/Desktop.hpp>
17 #include <com/sun/star/beans/XPropertySet.hpp>
19 #include <rtl/math.hxx>
21 using namespace ::com::sun::star
;
25 /// Gets one child of xShape, which one is specified by nIndex.
26 uno::Reference
<drawing::XShape
> getChildShape(const uno::Reference
<drawing::XShape
>& xShape
,
29 uno::Reference
<container::XIndexAccess
> xGroup(xShape
, uno::UNO_QUERY
);
30 CPPUNIT_ASSERT(xGroup
.is());
32 CPPUNIT_ASSERT(xGroup
->getCount() > nIndex
);
34 uno::Reference
<drawing::XShape
> xRet(xGroup
->getByIndex(nIndex
), uno::UNO_QUERY
);
35 CPPUNIT_ASSERT(xRet
.is());
41 char const DATA_DIRECTORY
[] = "/oox/qa/unit/data/";
44 class OoxShapeTest
: public test::BootstrapFixture
, public unotest::MacrosTest
47 uno::Reference
<lang::XComponent
> mxComponent
;
50 void setUp() override
;
51 void tearDown() override
;
52 uno::Reference
<lang::XComponent
>& getComponent() { return mxComponent
; }
53 void load(const OUString
& rURL
);
56 void OoxShapeTest::setUp()
58 test::BootstrapFixture::setUp();
60 mxDesktop
.set(frame::Desktop::create(mxComponentContext
));
63 void OoxShapeTest::tearDown()
66 mxComponent
->dispose();
68 test::BootstrapFixture::tearDown();
71 void OoxShapeTest::load(const OUString
& rFileName
)
73 OUString aURL
= m_directories
.getURLFromSrc(DATA_DIRECTORY
) + rFileName
;
74 mxComponent
= loadFromDesktop(aURL
);
77 CPPUNIT_TEST_FIXTURE(OoxShapeTest
, testGroupTransform
)
79 load(u
"tdf141463_GroupTransform.pptx");
81 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY
);
82 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
84 uno::Reference
<drawing::XShape
> xGroup(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
85 uno::Reference
<drawing::XShape
> xShape(getChildShape(xGroup
, 0), uno::UNO_QUERY
);
86 uno::Reference
<beans::XPropertySet
> xPropSet(xShape
, uno::UNO_QUERY
);
87 // Without the accompanying fix in place, this test would have failed in several properties.
90 xPropSet
->getPropertyValue("ShearAngle") >>= nAngle
;
91 // Failed with - Expected: 0
93 // i.e. the shape was sheared although shearing does not exist in oox
94 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nAngle
);
96 xPropSet
->getPropertyValue("RotateAngle") >>= nAngle
;
97 // Failed with - Expected: 26000 (is in 1/100deg)
98 // - Actual : 26481 (is in 1/100deg)
99 // 100deg in PowerPoint UI = 360deg - 100deg in LO.
100 CPPUNIT_ASSERT_EQUAL(sal_Int32(26000), nAngle
);
102 sal_Int32 nActual
= xShape
->getSize().Width
;
103 // The group has ext.cy=2880000 and chExt.cy=4320000 resulting in Y-scale=2/3.
104 // The child has ext 2880000 x 1440000. Because of rotation angle 80deg, the Y-scale has to be
105 // applied to the width, resulting in 2880000 * 2/3 = 1920000EMU = 5333Hmm
106 // ToDo: Expected value currently 1 off.
107 // Failed with - Expected: 5332
109 CPPUNIT_ASSERT_EQUAL(sal_Int32(5332), nActual
);
112 CPPUNIT_TEST_FIXTURE(OoxShapeTest
, testMultipleGroupShapes
)
114 load("multiple-group-shapes.docx");
116 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY
);
117 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
119 // Without the accompanying fix in place, this test would have failed with:
122 // i.e. the 2 group shapes from the document were imported as a single one.
123 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(2), xDrawPage
->getCount());
126 CPPUNIT_TEST_FIXTURE(OoxShapeTest
, testCustomshapePosition
)
128 load("customshape-position.docx");
130 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY
);
131 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
133 uno::Reference
<beans::XPropertySet
> xShape(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
136 xShape
->getPropertyValue("VertOrientPosition") >>= nY
;
137 // <wp:posOffset>581025</wp:posOffset> in the document.
138 sal_Int32 nExpected
= rtl::math::round(581025.0 / 360);
139 // Without the accompanying fix in place, this test would have failed with:
142 // i.e. the position of the shape was lost on import due to the rounded corners.
143 CPPUNIT_ASSERT_EQUAL(nExpected
, nY
);
146 CPPUNIT_PLUGIN_IMPLEMENT();
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */