Kaydet (Commit) bd591a94 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

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 56ca1b76)

Conflicts:
	chart2/qa/extras/chart2export.cxx

Change-Id: I49e0417e1ecbc70f40aab8531237ae98ae58bdd3
üst 41cfc01a
......@@ -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()
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment