From bd591a9480a769199e19e8c737e8645de5306ef8 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Wed, 11 Jun 2014 11:45:14 -0400 Subject: fdo#77506: (finally) write a unit test for this. I've switched from using a Draw document to Writer document due to some instability with Draw instance in our cppunit run. The bug is reproducible either way. The test is disabled for now, since the bug has yet to be fixed. (cherry picked from commit 56ca1b76963c44318a4f5577e15cfa5e7e1cd2a2) Conflicts: chart2/qa/extras/chart2export.cxx Change-Id: I49e0417e1ecbc70f40aab8531237ae98ae58bdd3 --- chart2/qa/extras/chart2export.cxx | 53 ++++++++----------- chart2/qa/extras/charttest.hxx | 61 ++++++++++++++++++++++ chart2/qa/extras/data/odg/scatter-plot-labels.odg | Bin 12861 -> 0 bytes chart2/qa/extras/data/odt/scatter-plot-labels.odt | Bin 0 -> 13454 bytes 4 files changed, 84 insertions(+), 30 deletions(-) delete mode 100644 chart2/qa/extras/data/odg/scatter-plot-labels.odg create mode 100644 chart2/qa/extras/data/odt/scatter-plot-labels.odt diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index 8ad51b66e25d..2d4713ed963e 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -83,7 +83,7 @@ public: CPPUNIT_TEST(testShapeFollowedByChart); CPPUNIT_TEST(testPieChartDataLabels); CPPUNIT_TEST(testSeriesIdxOrder); -// CPPUNIT_TEST(testScatterPlotLabels); TODO : This test crashes for some unknown reason. + CPPUNIT_TEST(testScatterPlotLabels); CPPUNIT_TEST(testErrorBarDataRangeODS); CPPUNIT_TEST(testChartCrash); CPPUNIT_TEST(testPieChartRotation); @@ -716,43 +716,36 @@ void Chart2ExportTest::testSeriesIdxOrder() void Chart2ExportTest::testScatterPlotLabels() { - load("/chart2/qa/extras/data/odg/", "scatter-plot-labels.odg"); - Reference xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY); + load("/chart2/qa/extras/data/odt/", "scatter-plot-labels.odt"); + Reference xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY); CPPUNIT_ASSERT(xChartDoc.is()); Reference xCT = getChartTypeFromDoc(xChartDoc, 0, 0); CPPUNIT_ASSERT(xCT.is()); - OUString aLabelRole = xCT->getRoleOfSequenceForSeriesLabel(); + // Make sure the original chart has 'a', 'b', 'c' as its data labels. + std::vector > aLabels = getDataSeriesLabelsFromChartType(xCT); + CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels.size()); + CPPUNIT_ASSERT_EQUAL(OUString("a"), aLabels[0][0].get()); + CPPUNIT_ASSERT_EQUAL(OUString("b"), aLabels[1][0].get()); + CPPUNIT_ASSERT_EQUAL(OUString("c"), aLabels[2][0].get()); - Reference xDSCont(xCT, uno::UNO_QUERY); - CPPUNIT_ASSERT(xDSCont.is()); - Sequence > aDataSeriesSeq = xDSCont->getDataSeries(); - CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aDataSeriesSeq.getLength()); + // Reload the doc and check again. The labels should not change. + reload("writer8"); - for (sal_Int32 i = 0; i < aDataSeriesSeq.getLength(); ++i) - { - uno::Reference xDSrc(aDataSeriesSeq[i], uno::UNO_QUERY); - CPPUNIT_ASSERT(xDSrc.is()); - uno::Sequence > aDataSeqs = xDSrc->getDataSequences(); - for (sal_Int32 j = 0; j < aDataSeqs.getLength(); ++j) - { - Reference xValues = aDataSeqs[j]->getValues(); - CPPUNIT_ASSERT(xValues.is()); - Reference xPropSet(xValues, uno::UNO_QUERY); - if (!xPropSet.is()) - continue; - - OUString aRoleName; - xPropSet->getPropertyValue("Role") >>= aRoleName; - if (aRoleName == aLabelRole) - { - // TODO : Check the data series labels. - } - } - } + xChartDoc.set(getChartDocFromWriter(0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xChartDoc.is()); + + xCT = getChartTypeFromDoc(xChartDoc, 0, 0); + CPPUNIT_ASSERT(xCT.is()); - CPPUNIT_ASSERT(false); +#if 0 + aLabels = getDataSeriesLabelsFromChartType(xCT); + CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels.size()); + CPPUNIT_ASSERT_EQUAL(OUString("a"), aLabels[0][0].get()); + CPPUNIT_ASSERT_EQUAL(OUString("b"), aLabels[1][0].get()); + CPPUNIT_ASSERT_EQUAL(OUString("c"), aLabels[2][0].get()); +#endif } void Chart2ExportTest::testErrorBarDataRangeODS() diff --git a/chart2/qa/extras/charttest.hxx b/chart2/qa/extras/charttest.hxx index 0b90f76a87e9..72af75afbeed 100644 --- a/chart2/qa/extras/charttest.hxx +++ b/chart2/qa/extras/charttest.hxx @@ -64,6 +64,8 @@ public: uno::Reference getChartDocFromDrawImpress( sal_Int32 nPage, sal_Int32 nShape ); + uno::Reference getChartDocFromWriter( sal_Int32 nShape ); + virtual void setUp() SAL_OVERRIDE; virtual void tearDown() SAL_OVERRIDE; @@ -289,6 +291,46 @@ uno::Sequence < OUString > getWriterChartColumnDescriptions( Reference< lang::XC return seriesList; } +std::vector > getDataSeriesLabelsFromChartType( const Reference& xCT ) +{ + OUString aLabelRole = xCT->getRoleOfSequenceForSeriesLabel(); + + Reference xDSCont(xCT, uno::UNO_QUERY); + CPPUNIT_ASSERT(xDSCont.is()); + Sequence > aDataSeriesSeq = xDSCont->getDataSeries(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aDataSeriesSeq.getLength()); + + std::vector > aRet; + for (sal_Int32 i = 0; i < aDataSeriesSeq.getLength(); ++i) + { + uno::Reference xDSrc(aDataSeriesSeq[i], uno::UNO_QUERY); + CPPUNIT_ASSERT(xDSrc.is()); + uno::Sequence > aDataSeqs = xDSrc->getDataSequences(); + for (sal_Int32 j = 0; j < aDataSeqs.getLength(); ++j) + { + Reference xValues = aDataSeqs[j]->getValues(); + CPPUNIT_ASSERT(xValues.is()); + Reference xPropSet(xValues, uno::UNO_QUERY); + if (!xPropSet.is()) + continue; + + OUString aRoleName; + xPropSet->getPropertyValue("Role") >>= aRoleName; + if (aRoleName == aLabelRole) + { + Reference xLabel = aDataSeqs[j]; + CPPUNIT_ASSERT(xLabel.is()); + Reference xDS2 = xLabel->getLabel(); + CPPUNIT_ASSERT(xDS2.is()); + uno::Sequence aData = xDS2->getData(); + aRet.push_back(aData); + } + } + } + + return aRet; +} + uno::Reference< chart::XChartDocument > ChartTest::getChartDocFromImpress( const char* pDir, const char* pName ) { mxComponent = loadFromDesktop(getURLFromSrc(pDir) + OUString::createFromAscii(pName), "com.sun.star.comp.Draw.PresentationDocument"); @@ -334,6 +376,25 @@ uno::Reference ChartTest::getChartDocFromDrawImpress( return xChartDoc; } +uno::Reference ChartTest::getChartDocFromWriter( sal_Int32 nShape ) +{ + Reference xPageSupp(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xPageSupp.is()); + + Reference xPage = xPageSupp->getDrawPage(); + CPPUNIT_ASSERT(xPage.is()); + + Reference xShapeProps(xPage->getByIndex(nShape), uno::UNO_QUERY); + CPPUNIT_ASSERT(xShapeProps.is()); + + Reference xDocModel; + xShapeProps->getPropertyValue("Model") >>= xDocModel; + CPPUNIT_ASSERT(xDocModel.is()); + + uno::Reference xChartDoc(xDocModel, uno::UNO_QUERY); + return xChartDoc; +} + uno::Sequence < OUString > ChartTest::getImpressChartColumnDescriptions( const char* pDir, const char* pName ) { uno::Reference< chart::XChartDocument > xChartDoc = getChartDocFromImpress( pDir, pName ); diff --git a/chart2/qa/extras/data/odg/scatter-plot-labels.odg b/chart2/qa/extras/data/odg/scatter-plot-labels.odg deleted file mode 100644 index af0dfee11384..000000000000 Binary files a/chart2/qa/extras/data/odg/scatter-plot-labels.odg and /dev/null differ diff --git a/chart2/qa/extras/data/odt/scatter-plot-labels.odt b/chart2/qa/extras/data/odt/scatter-plot-labels.odt new file mode 100644 index 000000000000..ab8f24324256 Binary files /dev/null and b/chart2/qa/extras/data/odt/scatter-plot-labels.odt differ -- cgit v1.2.3