From 5c9cd49df8e806d1f0bfd62f62ba057d54186ee8 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Tue, 6 Mar 2018 11:33:16 +0100 Subject: tdf#116163 import test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie4fd1142e1111e4968941a639a265d169aaa6413 Reviewed-on: https://gerrit.libreoffice.org/50814 Tested-by: Jenkins Reviewed-by: Szymon Kłos Reviewed-on: https://gerrit.libreoffice.org/50831 Reviewed-by: Michael Meeks --- chart2/qa/extras/chart2import.cxx | 97 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) (limited to 'chart2') diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx index a49e80e1b867..8a67b4e4349b 100644 --- a/chart2/qa/extras/chart2import.cxx +++ b/chart2/qa/extras/chart2import.cxx @@ -23,6 +23,9 @@ #include #include #include +#include +#include +#include #include @@ -98,6 +101,7 @@ public: void testTdf109858(); // Pie chart label placement settings(XLSX) void testTdf111173(); + void testTdf116163(); void testInternalDataProvider(); @@ -157,6 +161,7 @@ public: CPPUNIT_TEST(testTdf90510); CPPUNIT_TEST(testTdf109858); CPPUNIT_TEST(testTdf111173); + CPPUNIT_TEST(testTdf116163); CPPUNIT_TEST(testInternalDataProvider); @@ -166,6 +171,31 @@ private: }; +uno::Reference getShapeByName(const uno::Reference& rShapes, + const OUString& rName, + std::function&)> pCondition = nullptr) +{ + uno::Reference XIndexAccess(rShapes, uno::UNO_QUERY); + for (sal_Int32 i = 0; i < XIndexAccess->getCount(); ++i) + { + uno::Reference xShapes(XIndexAccess->getByIndex(i), uno::UNO_QUERY); + if (xShapes.is()) + { + uno::Reference xRet = getShapeByName(xShapes, rName, pCondition); + if (xRet.is()) + return xRet; + } + uno::Reference xNamedShape(XIndexAccess->getByIndex(i), uno::UNO_QUERY); + if (xNamedShape->getName() == rName) + { + uno::Reference xShape(xNamedShape, uno::UNO_QUERY); + if (pCondition == nullptr || pCondition(xShape)) + return xShape; + } + } + return uno::Reference(); +} + // error bar import // split method up into smaller chunks for more detailed tests void Chart2ImportTest::Fdo60083() @@ -1317,6 +1347,73 @@ void Chart2ImportTest::testTdf111173() CPPUNIT_ASSERT_MESSAGE( "failed to load chart", xChart1Doc.is() ); } +void Chart2ImportTest::testTdf116163() +{ + load("/chart2/qa/extras/data/pptx/", "tdf116163.pptx"); + + Reference xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xChartDoc.is()); + + Reference xHAxis = getAxisFromDoc(xChartDoc, 0, 0, 0); + CPPUNIT_ASSERT(xHAxis.is()); + + chart2::ScaleData aScaleData = xHAxis->getScaleData(); + CPPUNIT_ASSERT(aScaleData.Categories.is()); + + Reference xLabeledDataSequence = aScaleData.Categories; + CPPUNIT_ASSERT(xLabeledDataSequence.is()); + + Reference xDataSequence = xLabeledDataSequence->getValues(); + CPPUNIT_ASSERT(xDataSequence.is()); + + Reference xTextualDataSequence(xDataSequence, uno::UNO_QUERY); + CPPUNIT_ASSERT(xTextualDataSequence.is()); + + std::vector aCategories; + Sequence aTextData(xTextualDataSequence->getTextualData()); + ::std::copy(aTextData.begin(), aTextData.end(), + ::std::back_inserter(aCategories)); + + CPPUNIT_ASSERT_EQUAL(OUString("Aaaa"), aCategories[0]); + CPPUNIT_ASSERT_EQUAL(OUString("Bbbbbbb"), aCategories[1]); + CPPUNIT_ASSERT_EQUAL(OUString("Ccc"), aCategories[2]); + CPPUNIT_ASSERT_EQUAL(OUString("Ddddddddddddd"), aCategories[3]); + + // Check visible text + + uno::Reference xDrawPageSupplier(xChartDoc, uno::UNO_QUERY); + uno::Reference xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference xShapes(xDrawPage->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xShapes.is()); + + const OUString sXAxisName = "CID/D=0:CS=0:Axis=0,0"; + uno::Reference xXAxis = getShapeByName(xShapes, sXAxisName, + // Axis occurs twice in chart xshape representation so need to get the one related to labels + [](const uno::Reference& rXShape) -> bool + { + uno::Reference xAxisShapes(rXShape, uno::UNO_QUERY); + CPPUNIT_ASSERT(xAxisShapes.is()); + uno::Reference xChildShape(xAxisShapes->getByIndex(0), uno::UNO_QUERY); + uno::Reference< drawing::XShapeDescriptor > xShapeDescriptor(xChildShape, uno::UNO_QUERY_THROW); + return (xShapeDescriptor->getShapeType() == "com.sun.star.drawing.TextShape"); + }); + CPPUNIT_ASSERT(xXAxis.is()); + + uno::Reference xIndexAccess(xXAxis, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xIndexAccess.is()); + + // Check text + uno::Reference xLabel0(xIndexAccess->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Aaaa"), xLabel0->getString()); + uno::Reference xLabel1(xIndexAccess->getByIndex(1), uno::UNO_QUERY); + // If there is space for 3 chars only then don't show "..." + CPPUNIT_ASSERT_EQUAL(OUString("Bbb"), xLabel1->getString()); + uno::Reference xLabel2(xIndexAccess->getByIndex(2), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Ccc"), xLabel2->getString()); + uno::Reference xLabel3(xIndexAccess->getByIndex(3), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Dddd..."), xLabel3->getString()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest); CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit