/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace ::com::sun::star; namespace { /// Gets one child of xShape, which one is specified by nIndex. uno::Reference getChildShape(const uno::Reference& xShape, sal_Int32 nIndex) { uno::Reference xGroup(xShape, uno::UNO_QUERY); CPPUNIT_ASSERT(xGroup.is()); CPPUNIT_ASSERT(xGroup->getCount() > nIndex); uno::Reference xRet(xGroup->getByIndex(nIndex), uno::UNO_QUERY); CPPUNIT_ASSERT(xRet.is()); return xRet; } } /// oox drawingml tests. class OoxDrawingmlTest : public test::BootstrapFixture, public unotest::MacrosTest { private: uno::Reference mxComponent; public: void setUp() override; void tearDown() override; uno::Reference& getComponent() { return mxComponent; } void load(const OUString& rURL); void loadAndReload(const OUString& rURL, const OUString& rFilterName); }; void OoxDrawingmlTest::setUp() { test::BootstrapFixture::setUp(); mxDesktop.set(frame::Desktop::create(mxComponentContext)); } void OoxDrawingmlTest::tearDown() { if (mxComponent.is()) mxComponent->dispose(); test::BootstrapFixture::tearDown(); } void OoxDrawingmlTest::load(const OUString& rURL) { mxComponent = loadFromDesktop(rURL); } void OoxDrawingmlTest::loadAndReload(const OUString& rURL, const OUString& rFilterName) { load(rURL); uno::Reference xStorable(mxComponent, uno::UNO_QUERY); utl::MediaDescriptor aMediaDescriptor; aMediaDescriptor["FilterName"] <<= rFilterName; utl::TempFile aTempFile; xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); mxComponent->dispose(); validate(aTempFile.GetFileName(), test::OOXML); mxComponent = loadFromDesktop(aTempFile.GetURL()); } char const DATA_DIRECTORY[] = "/oox/qa/unit/data/"; CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTransparentText) { OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "transparent-text.pptx"; loadAndReload(aURL, "Impress Office Open XML"); uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); uno::Reference xParagraph( xShape->createEnumeration()->nextElement(), uno::UNO_QUERY); uno::Reference xPortion(xParagraph->createEnumeration()->nextElement(), uno::UNO_QUERY); sal_Int16 nTransparency = 0; xPortion->getPropertyValue("CharTransparence") >>= nTransparency; // Without the accompanying fix in place, this test would have failed with: // - Expected: 75 // - Actual : 0 // i.e. the transparency of the character color was lost on import/export. CPPUNIT_ASSERT_EQUAL(static_cast(75), nTransparency); } CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTdf131082) { OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf131082.pptx"; loadAndReload(aURL, "Impress Office Open XML"); uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); uno::Reference XPropSet(getChildShape(getChildShape(xShape, 0), 0), uno::UNO_QUERY); drawing::FillStyle eFillStyle = drawing::FillStyle_NONE; XPropSet->getPropertyValue("FillStyle") >>= eFillStyle; // Without the accompanying fix in place, this test would have failed with: // with drawing::FillStyle_NONE - 0 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_SOLID, eFillStyle); } CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testPresetAdjustValue) { OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "preset-adjust-value.pptx"; load(aURL); uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); uno::Reference xShapeProps(xShape, uno::UNO_QUERY); uno::Sequence aGeoPropSeq; xShapeProps->getPropertyValue("CustomShapeGeometry") >>= aGeoPropSeq; comphelper::SequenceAsHashMap aGeoPropMap(aGeoPropSeq); uno::Sequence aAdjustmentSeq; aGeoPropMap.getValue("AdjustmentValues") >>= aAdjustmentSeq; CPPUNIT_ASSERT_EQUAL(static_cast(1), aAdjustmentSeq.getLength()); // Without the accompanying fix in place, this test would have failed with: // - Expected: 11587 // - Actual : 10813 // i.e. the adjust value was set from the placeholder, not from the shape. CPPUNIT_ASSERT_EQUAL(static_cast(11587), aAdjustmentSeq[0].Value.get()); } CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testChartDataLabelCharColor) { OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "chart-data-label-char-color.docx"; load(aURL); uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); uno::Reference xModel(xShape->getPropertyValue("Model"), uno::UNO_QUERY); uno::Reference xDiagram(xModel->getFirstDiagram(), uno::UNO_QUERY); uno::Reference xCoordinateSystem( xDiagram->getCoordinateSystems()[0], uno::UNO_QUERY); uno::Reference xChartType(xCoordinateSystem->getChartTypes()[0], uno::UNO_QUERY); uno::Reference xDataSeries = xChartType->getDataSeries()[0]; uno::Reference xDataPoint = xDataSeries->getDataPointByIndex(0); uno::Sequence> aLabels; xDataPoint->getPropertyValue("CustomLabelFields") >>= aLabels; uno::Reference xLabel = aLabels[0]; sal_Int32 nCharColor = 0; xLabel->getPropertyValue("CharColor") >>= nCharColor; // Without the accompanying fix in place, this test would have failed with: // - Expected: 16777215 // - Actual : -1 // i.e. the data label had no explicit (white) color. CPPUNIT_ASSERT_EQUAL(static_cast(0xffffff), nCharColor); } CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testGradientMultiStepTransparency) { // Load a document with a multi-step gradient. OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "gradient-multistep-transparency.pptx"; load(aURL); // Check the end transparency of the gradient. uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); uno::Reference xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("Rectangle 4"), xShape->getName()); uno::Reference xShapeProps(xShape, uno::UNO_QUERY); awt::Gradient aTransparence; xShapeProps->getPropertyValue("FillTransparenceGradient") >>= aTransparence; // Without the accompanying fix in place, this test would have failed with: // - Expected: 16777215 (0xffffff) // - Actual : 3487029 (0x353535) // i.e. the end transparency was not 100%, but was 21%, leading to an unexpected visible line on // the right of this shape. CPPUNIT_ASSERT_EQUAL(static_cast(0xffffff), aTransparence.EndColor); } CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testShapeTextAlignment) { OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "shape-text-alignment.pptx"; load(aURL); uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); sal_Int16 nParaAdjust = -1; CPPUNIT_ASSERT(xShape->getPropertyValue("ParaAdjust") >>= nParaAdjust); // Without the accompanying fix in place, this test would have failed with: // - Expected: 0 // - Actual : 3 // i.e. text which is meant to be left-aligned was centered at a paragraph level. CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_LEFT, static_cast(nParaAdjust)); } CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testShapeTextAdjustLeft) { OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "shape-text-adjust-left.pptx"; load(aURL); uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); drawing::TextHorizontalAdjust eAdjust; // Without the accompanying fix in place, this test would have failed with: // - Expected: 3 (center) // - Actual : 1 (block) // i.e. text was center-adjusted, not default-adjusted (~left). CPPUNIT_ASSERT(xShape->getPropertyValue("TextHorizontalAdjust") >>= eAdjust); CPPUNIT_ASSERT_EQUAL(drawing::TextHorizontalAdjust_BLOCK, eAdjust); } CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */