diff options
author | Matúš Kukan <matus.kukan@collabora.com> | 2014-07-29 21:09:08 +0200 |
---|---|---|
committer | Matúš Kukan <matus.kukan@collabora.com> | 2014-07-29 22:58:16 +0200 |
commit | dbe2da93340cb0b693f49afc93812199a39bb118 (patch) | |
tree | 85359db854a28d38e56262268b208904a2d37eea /chart2/qa | |
parent | c8cc89ff802d86b1f3a69afe1b4835b7df7f70c7 (diff) |
Add chart import, percentage number formats, unit test.
Change-Id: Id1b73c153f4b09ab94446452e7eb096b529473f4
Diffstat (limited to 'chart2/qa')
-rw-r--r-- | chart2/qa/extras/chart2import.cxx | 68 | ||||
-rw-r--r-- | chart2/qa/extras/charttest.hxx | 9 | ||||
-rwxr-xr-x | chart2/qa/extras/data/pptx/percentage-number-formats.pptx | bin | 0 -> 58872 bytes |
3 files changed, 77 insertions, 0 deletions
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx index 785129118043..659987ae3d7c 100644 --- a/chart2/qa/extras/chart2import.cxx +++ b/chart2/qa/extras/chart2import.cxx @@ -10,6 +10,7 @@ #include "charttest.hxx" #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/chart2/CurveStyle.hpp> +#include <com/sun/star/chart2/DataPointLabel.hpp> #include <com/sun/star/chart/ErrorBarStyle.hpp> #include <com/sun/star/chart2/XChartDocument.hpp> #include <com/sun/star/chart/XChartDocument.hpp> @@ -40,6 +41,7 @@ public: * hidden columns for internal data table yet). */ void testPPTXHiddenDataSeries(); + void testPPTXPercentageNumberFormats(); void testPPTXStackedNonStackedYAxis(); void testPPTChartSeries(); void testODPChartSeries(); @@ -71,6 +73,7 @@ public: CPPUNIT_TEST(testPPTChartSeries); CPPUNIT_TEST(testPPTXChartSeries); CPPUNIT_TEST(testPPTXHiddenDataSeries); + CPPUNIT_TEST(testPPTXPercentageNumberFormats); CPPUNIT_TEST(testPPTXStackedNonStackedYAxis); CPPUNIT_TEST(testODPChartSeries); CPPUNIT_TEST(testBnc864396); @@ -367,6 +370,71 @@ void Chart2ImportTest::testPPTXHiddenDataSeries() CPPUNIT_ASSERT_EQUAL(OUString("Category 4"), aCategories[3][0]); } +void Chart2ImportTest::testPPTXPercentageNumberFormats() +{ + load("/chart2/qa/extras/data/pptx/", "percentage-number-formats.pptx"); + + // 1st chart + Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xChartDoc.is()); + + uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0)); + CPPUNIT_ASSERT(xDataSeries.is()); + uno::Reference<beans::XPropertySet> xPropertySet; + chart2::DataPointLabel aLabel; + sal_Int32 nNumberFormat; + const sal_Int32 nPercentFormatSimple = getNumberFormat(xChartDoc, "0%"); + const sal_Int32 nPercentFormatDecimal = getNumberFormat(xChartDoc, "0.00%"); + + xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("Label") >>= aLabel; + CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumber); + CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumberInPercent); + xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat; + CPPUNIT_ASSERT_EQUAL(nPercentFormatSimple, nNumberFormat); + + xPropertySet.set(xDataSeries->getDataPointByIndex(1), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("Label") >>= aLabel; + CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumber); + CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumberInPercent); + xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat; + CPPUNIT_ASSERT_EQUAL(nPercentFormatDecimal, nNumberFormat); + + xPropertySet.set(xDataSeries->getDataPointByIndex(2), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("Label") >>= aLabel; + CPPUNIT_ASSERT_EQUAL(sal_False, aLabel.ShowNumber); + CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumberInPercent); + xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat; + CPPUNIT_ASSERT_EQUAL(nPercentFormatSimple, nNumberFormat); + + xPropertySet.set(xDataSeries->getDataPointByIndex(3), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("Label") >>= aLabel; + CPPUNIT_ASSERT_EQUAL(sal_False, aLabel.ShowNumber); + CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumberInPercent); + xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat; + CPPUNIT_ASSERT_EQUAL(nPercentFormatDecimal, nNumberFormat); + + // 2nd chart + xChartDoc.set(getChartDocFromDrawImpress(1, 0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xChartDoc.is()); + + Reference<chart2::XAxis> xYAxis = getAxisFromDoc(xChartDoc, 0, 1, 0); + CPPUNIT_ASSERT(xYAxis.is()); + + Reference<beans::XPropertySet> xPS(xYAxis, uno::UNO_QUERY_THROW); + bool bLinkNumberFormatToSource = true; + bool bSuccess = xPS->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bLinkNumberFormatToSource; + CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to false.", bSuccess && !bLinkNumberFormatToSource); + + // FIXME: This should be in fact "0.00%". + // see TODO in oox/source/drawingml/chart/modelbase.cxx + const sal_Int32 nPercentFormatDecimalShort = getNumberFormat(xChartDoc, "0.0%"); + nNumberFormat = getNumberFormatFromAxis(xYAxis); + CPPUNIT_ASSERT_EQUAL(nPercentFormatDecimalShort, nNumberFormat); + sal_Int16 nType = getNumberFormatType(xChartDoc, nNumberFormat); + CPPUNIT_ASSERT_MESSAGE("Y axis should be a percent format.", (nType & util::NumberFormat::PERCENT)); +} + void Chart2ImportTest::testPPTXStackedNonStackedYAxis() { load("/chart2/qa/extras/data/pptx/", "stacked-non-stacked-mix-y-axis.pptx"); diff --git a/chart2/qa/extras/charttest.hxx b/chart2/qa/extras/charttest.hxx index 318bac2c15d4..7c53b95ecc9d 100644 --- a/chart2/qa/extras/charttest.hxx +++ b/chart2/qa/extras/charttest.hxx @@ -494,6 +494,15 @@ OUString getTitleString( const Reference<chart2::XTitled>& xTitled ) return aText; } +sal_Int32 getNumberFormat( const Reference<chart2::XChartDocument>& xChartDoc, const OUString& sFormat ) +{ + Reference<util::XNumberFormatsSupplier> xNFS(xChartDoc, uno::UNO_QUERY_THROW); + Reference<util::XNumberFormats> xNumberFormats = xNFS->getNumberFormats(); + CPPUNIT_ASSERT(xNumberFormats.is()); + + return xNumberFormats->queryKey(sFormat, css::lang::Locale(), sal_False); +} + sal_Int32 getNumberFormatFromAxis( const Reference<chart2::XAxis>& xAxis ) { Reference<beans::XPropertySet> xPS(xAxis, uno::UNO_QUERY); diff --git a/chart2/qa/extras/data/pptx/percentage-number-formats.pptx b/chart2/qa/extras/data/pptx/percentage-number-formats.pptx Binary files differnew file mode 100755 index 000000000000..280c7ef29113 --- /dev/null +++ b/chart2/qa/extras/data/pptx/percentage-number-formats.pptx |