diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2018-03-06 11:33:16 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2018-03-22 10:30:14 +0100 |
commit | 6a9a239a1ce799275b8b6eab49ec06b51894f5eb (patch) | |
tree | 8300a5cc641878d23998d0bdaf29c9b4360d4424 /chart2 | |
parent | 7b80e54640e20657402656614228998e0544a842 (diff) |
tdf#116163 import test
Change-Id: Ie4fd1142e1111e4968941a639a265d169aaa6413
Reviewed-on: https://gerrit.libreoffice.org/50814
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/50926
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/qa/extras/chart2import.cxx | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx index 9ea527b1bf76..6452c3c26d80 100644 --- a/chart2/qa/extras/chart2import.cxx +++ b/chart2/qa/extras/chart2import.cxx @@ -23,6 +23,9 @@ #include <com/sun/star/chart/MissingValueTreatment.hpp> #include <com/sun/star/chart2/TickmarkStyle.hpp> #include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/chart2/data/XTextualDataSequence.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <iterator> #include <com/sun/star/util/Color.hpp> @@ -96,6 +99,7 @@ public: void testTdf90510(); // Pie chart label placement settings(XLS) void testTdf109858(); // Pie chart label placement settings(XLSX) + void testTdf116163(); void testInternalDataProvider(); CPPUNIT_TEST_SUITE(Chart2ImportTest); @@ -152,6 +156,7 @@ public: CPPUNIT_TEST(testAxisTitleRotationXLSX); CPPUNIT_TEST(testTdf90510); CPPUNIT_TEST(testTdf109858); + CPPUNIT_TEST(testTdf116163); CPPUNIT_TEST(testInternalDataProvider); @@ -161,6 +166,31 @@ private: }; +uno::Reference<drawing::XShape> getShapeByName(const uno::Reference<drawing::XShapes>& rShapes, + const OUString& rName, + std::function<bool(const uno::Reference<drawing::XShape>&)> pCondition = nullptr) +{ + uno::Reference<container::XIndexAccess> XIndexAccess(rShapes, uno::UNO_QUERY); + for (sal_Int32 i = 0; i < XIndexAccess->getCount(); ++i) + { + uno::Reference<drawing::XShapes> xShapes(XIndexAccess->getByIndex(i), uno::UNO_QUERY); + if (xShapes.is()) + { + uno::Reference<drawing::XShape> xRet = getShapeByName(xShapes, rName, pCondition); + if (xRet.is()) + return xRet; + } + uno::Reference<container::XNamed> xNamedShape(XIndexAccess->getByIndex(i), uno::UNO_QUERY); + if (xNamedShape->getName() == rName) + { + uno::Reference<drawing::XShape> xShape(xNamedShape, uno::UNO_QUERY); + if (pCondition == nullptr || pCondition(xShape)) + return xShape; + } + } + return uno::Reference<drawing::XShape>(); +} + // error bar import // split method up into smaller chunks for more detailed tests void Chart2ImportTest::Fdo60083() @@ -1277,6 +1307,73 @@ void Chart2ImportTest::testTdf109858() CPPUNIT_ASSERT_EQUAL_MESSAGE( "Data labels should be placed outside", chart::DataLabelPlacement::OUTSIDE, nLabelPlacement ); } +void Chart2ImportTest::testTdf116163() +{ + load("/chart2/qa/extras/data/pptx/", "tdf116163.pptx"); + + Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xChartDoc.is()); + + Reference<chart2::XAxis> xHAxis = getAxisFromDoc(xChartDoc, 0, 0, 0); + CPPUNIT_ASSERT(xHAxis.is()); + + chart2::ScaleData aScaleData = xHAxis->getScaleData(); + CPPUNIT_ASSERT(aScaleData.Categories.is()); + + Reference<chart2::data::XLabeledDataSequence> xLabeledDataSequence = aScaleData.Categories; + CPPUNIT_ASSERT(xLabeledDataSequence.is()); + + Reference<chart2::data::XDataSequence> xDataSequence = xLabeledDataSequence->getValues(); + CPPUNIT_ASSERT(xDataSequence.is()); + + Reference<chart2::data::XTextualDataSequence> xTextualDataSequence(xDataSequence, uno::UNO_QUERY); + CPPUNIT_ASSERT(xTextualDataSequence.is()); + + std::vector<OUString> aCategories; + Sequence<OUString> 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<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xShapes.is()); + + const OUString sXAxisName = "CID/D=0:CS=0:Axis=0,0"; + uno::Reference<drawing::XShape> xXAxis = getShapeByName(xShapes, sXAxisName, + // Axis occurs twice in chart xshape representation so need to get the one related to labels + [](const uno::Reference<drawing::XShape>& rXShape) -> bool + { + uno::Reference<drawing::XShapes> xAxisShapes(rXShape, uno::UNO_QUERY); + CPPUNIT_ASSERT(xAxisShapes.is()); + uno::Reference<drawing::XShape> 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<container::XIndexAccess> xIndexAccess(xXAxis, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xIndexAccess.is()); + + // Check text + uno::Reference<text::XTextRange> xLabel0(xIndexAccess->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Aaaa"), xLabel0->getString()); + uno::Reference<text::XTextRange> 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<text::XTextRange> xLabel2(xIndexAccess->getByIndex(2), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Ccc"), xLabel2->getString()); + uno::Reference<text::XTextRange> xLabel3(xIndexAccess->getByIndex(3), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Dddd..."), xLabel3->getString()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest); CPPUNIT_PLUGIN_IMPLEMENT(); |