nss: upgrade to release 3.73
[LibreOffice.git] / oox / qa / unit / vml.cxx
blobd75372da39ae9da863565c2466b1e813f9ae8e72
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/beans/XPropertySet.hpp>
14 #include <com/sun/star/drawing/LineStyle.hpp>
15 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
16 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
17 #include <com/sun/star/frame/Desktop.hpp>
18 #include <com/sun/star/lang/XServiceInfo.hpp>
19 #include <com/sun/star/text/WritingMode2.hpp>
21 using namespace ::com::sun::star;
23 char const DATA_DIRECTORY[] = "/oox/qa/unit/data/";
25 /// oox vml tests.
26 class OoxVmlTest : public test::BootstrapFixture, public unotest::MacrosTest
28 private:
29 uno::Reference<lang::XComponent> mxComponent;
31 public:
32 void setUp() override;
33 void tearDown() override;
34 uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
35 void load(const OUString& rURL);
38 void OoxVmlTest::setUp()
40 test::BootstrapFixture::setUp();
42 mxDesktop.set(frame::Desktop::create(mxComponentContext));
45 void OoxVmlTest::tearDown()
47 if (mxComponent.is())
48 mxComponent->dispose();
50 test::BootstrapFixture::tearDown();
53 void OoxVmlTest::load(const OUString& rFileName)
55 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + rFileName;
56 mxComponent = loadFromDesktop(aURL);
59 CPPUNIT_TEST_FIXTURE(OoxVmlTest, tdf137314_vml_rotation_unit_fd)
61 // Load a document with a 30deg rotated arc on a drawing canvas. Rotation is given
62 // as 1966080fd. Error was, that the vml angle unit "fd" was not converted to Degree100.
63 load(u"tdf137314_vml_rotation_unit_fd.docx");
64 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
65 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
66 uno::UNO_QUERY);
67 uno::Reference<container::XIndexAccess> xGroup(xDrawPage->getByIndex(0), uno::UNO_QUERY);
68 uno::Reference<drawing::XShape> xShape(xGroup->getByIndex(1), uno::UNO_QUERY);
69 uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
70 drawing::PolyPolygonBezierCoords aPolyPolygonBezierCoords;
71 xShapeProps->getPropertyValue("PolyPolygonBezier") >>= aPolyPolygonBezierCoords;
72 drawing::PointSequence aPolygon = aPolyPolygonBezierCoords.Coordinates[1];
73 // Without fix in place, the vector was -1441|1490.
74 // [1] and [2] are Bezier-curve control points.
75 sal_Int32 nDiffX = aPolygon[3].X - aPolygon[0].X;
76 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(1490), nDiffX, 1);
77 sal_Int32 nDiffY = aPolygon[3].Y - aPolygon[0].Y;
78 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(1441), nDiffY, 1);
81 CPPUNIT_TEST_FIXTURE(OoxVmlTest, testSpt202ShapeType)
83 // Load a document with a groupshape, 2nd child is a <v:shape>, its type has o:spt set to 202
84 // (TextBox).
85 load("group-spt202.docx");
86 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
87 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
88 uno::UNO_QUERY);
89 uno::Reference<container::XIndexAccess> xGroup(xDrawPage->getByIndex(0), uno::UNO_QUERY);
90 uno::Reference<drawing::XShape> xShape(xGroup->getByIndex(1), uno::UNO_QUERY);
92 // Without the accompanying fix in place, this test would have failed with:
93 // - Expected: com.sun.star.drawing.TextShape
94 // - Actual : com.sun.star.drawing.CustomShape
95 // and then the size of the group shape was incorrect, e.g. its right edge was outside the page
96 // boundaries.
97 CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.TextShape"), xShape->getShapeType());
100 CPPUNIT_TEST_FIXTURE(OoxVmlTest, testShapeNonAutosizeWithText)
102 // Load a document which has a group shape, containing a single child.
103 // 17.78 cm is the full group shape width, 19431/64008 is the child shape's relative width inside
104 // that, so 5.3975 cm should be the shape width.
105 load("shape-non-autosize-with-text.docx");
106 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
107 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
108 uno::UNO_QUERY);
109 uno::Reference<container::XIndexAccess> xGroup(xDrawPage->getByIndex(0), uno::UNO_QUERY);
110 uno::Reference<drawing::XShape> xShape(xGroup->getByIndex(0), uno::UNO_QUERY);
111 // Without the accompanying fix in place, this test would have failed with:
112 // - Actual : 1115
113 // - Expected: 5398
114 // because the width was determined using its text size, not using the explicit size.
115 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5398), xShape->getSize().Width);
118 CPPUNIT_TEST_FIXTURE(OoxVmlTest, testGraphicStroke)
120 load("graphic-stroke.pptx");
121 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
122 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
123 uno::UNO_QUERY);
125 uno::Reference<beans::XPropertySet> xShape;
126 for (sal_Int32 i = 0; i < xDrawPage->getCount(); ++i)
128 uno::Reference<lang::XServiceInfo> xInfo(xDrawPage->getByIndex(i), uno::UNO_QUERY);
129 if (!xInfo->supportsService("com.sun.star.drawing.GraphicObjectShape"))
131 continue;
134 xShape.set(xInfo, uno::UNO_QUERY);
135 break;
137 CPPUNIT_ASSERT(xShape.is());
139 drawing::LineStyle eLineStyle{};
140 xShape->getPropertyValue("LineStyle") >>= eLineStyle;
141 // Without the accompanying fix in place, this test would have failed with:
142 // - Expected: 1
143 // - Actual : 0
144 // i.e. line style was NONE, not SOLID.
145 CPPUNIT_ASSERT_EQUAL(drawing::LineStyle_SOLID, eLineStyle);
148 CPPUNIT_PLUGIN_IMPLEMENT();
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */