diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-06-20 11:45:57 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-06-20 12:03:06 -0400 |
commit | aac149e4ad06e207e6c1b14f11867dbfbd343ab2 (patch) | |
tree | 17f0d572f986c9fb78fa869349db9b0dd727be56 /chart2 | |
parent | 553f88e3d65fd25f645c22589de575924c3879fc (diff) |
fdo#71767: Write test for this.
Not a direct test for the reported bug, but to ensure that the reworked
properties survive import and export.
Change-Id: I6c5a4c98eca5180251f04a24346290dedc44447a
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/qa/extras/chart2export.cxx | 66 | ||||
-rw-r--r-- | chart2/qa/extras/charttest.hxx | 39 | ||||
-rw-r--r-- | chart2/qa/extras/data/ods/axis-numformats-linked.ods | bin | 0 -> 26944 bytes |
3 files changed, 105 insertions, 0 deletions
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index 51eb6c305c55..80aab3069e06 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -62,6 +62,7 @@ public: void testFdo78290LineChartMarkerX(); void testFdo78290ScatterChartMarkerX(); void testFdo78290CombinationChartMarkerX(); + void testAxisNumberFormatODS(); CPPUNIT_TEST_SUITE(Chart2ExportTest); CPPUNIT_TEST(test); @@ -95,6 +96,7 @@ public: CPPUNIT_TEST(testFdo78290LineChartMarkerX); CPPUNIT_TEST(testFdo78290ScatterChartMarkerX); CPPUNIT_TEST(testFdo78290CombinationChartMarkerX); + CPPUNIT_TEST(testAxisNumberFormatODS); CPPUNIT_TEST_SUITE_END(); protected: @@ -672,6 +674,70 @@ void Chart2ExportTest::testFdo78290CombinationChartMarkerX() assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:marker[1]/c:size[1]","val","7"); } +void Chart2ExportTest::testAxisNumberFormatODS() +{ + struct + { + void check( const Reference<chart2::XChartDocument>& xChartDoc ) + { + Reference<util::XNumberFormatsSupplier> xNFS(xChartDoc, UNO_QUERY_THROW); + Reference<util::XNumberFormats> xNumberFormats = xNFS->getNumberFormats(); + CPPUNIT_ASSERT(xNumberFormats.is()); + + Reference<chart2::XAxis> xAxisX = getAxisFromDoc(xChartDoc, 0, 0, 0); + Reference<chart2::XTitled> xTitle(xAxisX, UNO_QUERY_THROW); + OUString aTitleText = getTitleString(xTitle); + CPPUNIT_ASSERT_EQUAL(OUString("Linked To Source"), aTitleText); + + Reference<beans::XPropertySet> xPS(xAxisX, UNO_QUERY_THROW); + + sal_Int32 nNumFmt = -1; + xPS->getPropertyValue("NumberFormat") >>= nNumFmt; + CPPUNIT_ASSERT_MESSAGE("Failed to get a number format value from X axis.", nNumFmt != -1); + Reference<beans::XPropertySet> xNumPS = xNumberFormats->getByKey(nNumFmt); + CPPUNIT_ASSERT(xNumPS.is()); + sal_Int16 nType = util::NumberFormat::UNDEFINED; + xNumPS->getPropertyValue("Type") >>= nType; + CPPUNIT_ASSERT_MESSAGE("X axis should be percentage format.", (nType & util::NumberFormat::PERCENT)); + + bool bNumFmtLinked = false; + xPS->getPropertyValue("LinkNumberFormatToSource") >>= bNumFmtLinked; + CPPUNIT_ASSERT_MESSAGE("X axis should have its number format linked to source.", bNumFmtLinked); + + Reference<chart2::XAxis> xAxisY = getAxisFromDoc(xChartDoc, 0, 1, 0); + xTitle.set(xAxisY, UNO_QUERY_THROW); + aTitleText = getTitleString(xTitle); + CPPUNIT_ASSERT_EQUAL(OUString("Not Linked"), aTitleText); + + xPS.set(xAxisY, UNO_QUERY_THROW); + + nNumFmt = -1; + xPS->getPropertyValue("NumberFormat") >>= nNumFmt; + CPPUNIT_ASSERT_MESSAGE("Failed to get a number format value from Y axis.", nNumFmt != -1); + xNumPS = xNumberFormats->getByKey(nNumFmt); + CPPUNIT_ASSERT(xNumPS.is()); + nType = util::NumberFormat::UNDEFINED; + xNumPS->getPropertyValue("Type") >>= nType; + CPPUNIT_ASSERT_MESSAGE("Y axis should be a normal number format.", (nType & util::NumberFormat::NUMBER)); + + bNumFmtLinked = true; + xPS->getPropertyValue("LinkNumberFormatToSource") >>= bNumFmtLinked; + CPPUNIT_ASSERT_MESSAGE("Y axis should not have its number format linked to source.", !bNumFmtLinked); + } + + } aTest; + + load("/chart2/qa/extras/data/ods/", "axis-numformats-linked.ods"); + + Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent); + aTest.check(xChartDoc); + + // Reload the document and make sure everything remains intact. + reload("calc8"); + xChartDoc = getChartDocFromSheet(0, mxComponent); + aTest.check(xChartDoc); +} + void Chart2ExportTest::testBarChartRotation() { load ("/chart2/qa/extras/data/docx/", "barChartRotation.docx"); diff --git a/chart2/qa/extras/charttest.hxx b/chart2/qa/extras/charttest.hxx index 5d0d15e0b2e9..e0969f4e037f 100644 --- a/chart2/qa/extras/charttest.hxx +++ b/chart2/qa/extras/charttest.hxx @@ -38,11 +38,17 @@ #include <com/sun/star/chart2/XChartTypeContainer.hpp> #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> #include <com/sun/star/chart2/XDataSeriesContainer.hpp> +#include <com/sun/star/chart2/XFormattedString.hpp> +#include <com/sun/star/chart2/XTitle.hpp> +#include <com/sun/star/chart2/XTitled.hpp> #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp> #include <com/sun/star/chart2/data/XDataSource.hpp> #include <com/sun/star/chart/XChartDataArray.hpp> #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> #include <com/sun/star/chart/XChartDocument.hpp> +#include <com/sun/star/util/XNumberFormatsSupplier.hpp> +#include <com/sun/star/util/NumberFormat.hpp> + #include <iostream> #include <libxml/xmlwriter.h> @@ -211,6 +217,27 @@ Reference< chart2::XChartType > getChartTypeFromDoc( Reference< chart2::XChartDo return xChartTypeSequence[nChartType]; } +Reference<chart2::XAxis> getAxisFromDoc( + const Reference<chart2::XChartDocument>& xChartDoc, sal_Int32 nCooSys, sal_Int32 nAxisDim, sal_Int32 nAxisIndex ) +{ + Reference<chart2::XDiagram> xDiagram = xChartDoc->getFirstDiagram(); + CPPUNIT_ASSERT(xDiagram.is()); + + Reference<chart2::XCoordinateSystemContainer> xCooSysContainer(xDiagram, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xCooSysContainer.is()); + + Sequence<Reference<chart2::XCoordinateSystem> > xCooSysSequence = xCooSysContainer->getCoordinateSystems(); + CPPUNIT_ASSERT(xCooSysSequence.getLength() > nCooSys); + + Reference<chart2::XCoordinateSystem> xCoord = xCooSysSequence[nCooSys]; + CPPUNIT_ASSERT(xCoord.is()); + + Reference<chart2::XAxis> xAxis = xCoord->getAxisByDimension(nAxisDim, nAxisIndex); + CPPUNIT_ASSERT(xAxis.is()); + + return xAxis; +} + Reference< chart2::XDataSeries > getDataSeriesFromDoc( uno::Reference< chart2::XChartDocument > xChartDoc, sal_Int32 nDataSeries, sal_Int32 nChartType = 0, sal_Int32 nCooSys = 0 ) { @@ -406,6 +433,18 @@ uno::Sequence < OUString > ChartTest::getImpressChartColumnDescriptions( const c return seriesList; } +OUString getTitleString( const Reference<chart2::XTitled>& xTitled, sal_Int32 nIndex = 0 ) +{ + uno::Reference<chart2::XTitle> xTitle = xTitled->getTitleObject(); + CPPUNIT_ASSERT(xTitle.is()); + uno::Sequence<uno::Reference<chart2::XFormattedString> > aFSSeq = xTitle->getText(); + CPPUNIT_ASSERT(aFSSeq.getLength() > nIndex); + uno::Reference<chart2::XFormattedString> xFS = aFSSeq[nIndex]; + CPPUNIT_ASSERT(xFS.is()); + + return xFS->getString(); +} + #endif // INCLUDED_CHART2_QA_EXTRAS_CHARTTEST_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/qa/extras/data/ods/axis-numformats-linked.ods b/chart2/qa/extras/data/ods/axis-numformats-linked.ods Binary files differnew file mode 100644 index 000000000000..ddaa9c9014b2 --- /dev/null +++ b/chart2/qa/extras/data/ods/axis-numformats-linked.ods |