diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-06-11 11:45:14 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-06-12 11:32:17 -0400 |
commit | bd591a9480a769199e19e8c737e8645de5306ef8 (patch) | |
tree | 61bc4ab753334ef2fea45823a8c08df07b14d2a9 /chart2 | |
parent | 41cfc01a5676d237438a543c467821359dd5550a (diff) |
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
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/qa/extras/chart2export.cxx | 53 | ||||
-rw-r--r-- | chart2/qa/extras/charttest.hxx | 61 | ||||
-rw-r--r-- | chart2/qa/extras/data/odg/scatter-plot-labels.odg | bin | 12861 -> 0 bytes | |||
-rw-r--r-- | chart2/qa/extras/data/odt/scatter-plot-labels.odt | bin | 0 -> 13454 bytes |
4 files changed, 84 insertions, 30 deletions
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<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY); + load("/chart2/qa/extras/data/odt/", "scatter-plot-labels.odt"); + Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY); CPPUNIT_ASSERT(xChartDoc.is()); Reference<chart2::XChartType> 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<uno::Sequence<uno::Any> > aLabels = getDataSeriesLabelsFromChartType(xCT); + CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels.size()); + CPPUNIT_ASSERT_EQUAL(OUString("a"), aLabels[0][0].get<OUString>()); + CPPUNIT_ASSERT_EQUAL(OUString("b"), aLabels[1][0].get<OUString>()); + CPPUNIT_ASSERT_EQUAL(OUString("c"), aLabels[2][0].get<OUString>()); - Reference<chart2::XDataSeriesContainer> xDSCont(xCT, uno::UNO_QUERY); - CPPUNIT_ASSERT(xDSCont.is()); - Sequence<uno::Reference<chart2::XDataSeries> > 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<chart2::data::XDataSource> xDSrc(aDataSeriesSeq[i], uno::UNO_QUERY); - CPPUNIT_ASSERT(xDSrc.is()); - uno::Sequence<Reference<chart2::data::XLabeledDataSequence> > aDataSeqs = xDSrc->getDataSequences(); - for (sal_Int32 j = 0; j < aDataSeqs.getLength(); ++j) - { - Reference<chart2::data::XDataSequence> xValues = aDataSeqs[j]->getValues(); - CPPUNIT_ASSERT(xValues.is()); - Reference<beans::XPropertySet> 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<OUString>()); + CPPUNIT_ASSERT_EQUAL(OUString("b"), aLabels[1][0].get<OUString>()); + CPPUNIT_ASSERT_EQUAL(OUString("c"), aLabels[2][0].get<OUString>()); +#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<chart::XChartDocument> getChartDocFromDrawImpress( sal_Int32 nPage, sal_Int32 nShape ); + uno::Reference<chart::XChartDocument> 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<uno::Sequence<uno::Any> > getDataSeriesLabelsFromChartType( const Reference<chart2::XChartType>& xCT ) +{ + OUString aLabelRole = xCT->getRoleOfSequenceForSeriesLabel(); + + Reference<chart2::XDataSeriesContainer> xDSCont(xCT, uno::UNO_QUERY); + CPPUNIT_ASSERT(xDSCont.is()); + Sequence<uno::Reference<chart2::XDataSeries> > aDataSeriesSeq = xDSCont->getDataSeries(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aDataSeriesSeq.getLength()); + + std::vector<uno::Sequence<uno::Any> > aRet; + for (sal_Int32 i = 0; i < aDataSeriesSeq.getLength(); ++i) + { + uno::Reference<chart2::data::XDataSource> xDSrc(aDataSeriesSeq[i], uno::UNO_QUERY); + CPPUNIT_ASSERT(xDSrc.is()); + uno::Sequence<Reference<chart2::data::XLabeledDataSequence> > aDataSeqs = xDSrc->getDataSequences(); + for (sal_Int32 j = 0; j < aDataSeqs.getLength(); ++j) + { + Reference<chart2::data::XDataSequence> xValues = aDataSeqs[j]->getValues(); + CPPUNIT_ASSERT(xValues.is()); + Reference<beans::XPropertySet> xPropSet(xValues, uno::UNO_QUERY); + if (!xPropSet.is()) + continue; + + OUString aRoleName; + xPropSet->getPropertyValue("Role") >>= aRoleName; + if (aRoleName == aLabelRole) + { + Reference<chart2::data::XLabeledDataSequence> xLabel = aDataSeqs[j]; + CPPUNIT_ASSERT(xLabel.is()); + Reference<chart2::data::XDataSequence> xDS2 = xLabel->getLabel(); + CPPUNIT_ASSERT(xDS2.is()); + uno::Sequence<uno::Any> 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<chart::XChartDocument> ChartTest::getChartDocFromDrawImpress( return xChartDoc; } +uno::Reference<chart::XChartDocument> ChartTest::getChartDocFromWriter( sal_Int32 nShape ) +{ + Reference<drawing::XDrawPageSupplier> xPageSupp(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xPageSupp.is()); + + Reference<drawing::XDrawPage> xPage = xPageSupp->getDrawPage(); + CPPUNIT_ASSERT(xPage.is()); + + Reference<beans::XPropertySet> xShapeProps(xPage->getByIndex(nShape), uno::UNO_QUERY); + CPPUNIT_ASSERT(xShapeProps.is()); + + Reference<frame::XModel> xDocModel; + xShapeProps->getPropertyValue("Model") >>= xDocModel; + CPPUNIT_ASSERT(xDocModel.is()); + + uno::Reference<chart::XChartDocument> 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 Binary files differdeleted file mode 100644 index af0dfee11384..000000000000 --- a/chart2/qa/extras/data/odg/scatter-plot-labels.odg +++ /dev/null diff --git a/chart2/qa/extras/data/odt/scatter-plot-labels.odt b/chart2/qa/extras/data/odt/scatter-plot-labels.odt Binary files differnew file mode 100644 index 000000000000..ab8f24324256 --- /dev/null +++ b/chart2/qa/extras/data/odt/scatter-plot-labels.odt |