diff options
author | Tomaž Vajngerl <quikee@gmail.com> | 2013-11-26 08:28:29 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2013-11-26 08:30:42 +0100 |
commit | 2ead27dc7026fc4789323f8849f43c5cafcec2fe (patch) | |
tree | 23df9833dde44052a6ea3b636cfed93a96b91fcd /chart2 | |
parent | b32651febdaad5939250fb04f721d88952f54732 (diff) |
Test trendline properties using an emport -> ixport cycle
Added a test which checks the preservation of properties for
trendlines / regression curves in an export -> import cycle
using different file formats - ODS, XLS and XLSX.
Change-Id: I59fe6c045f7f503ee074e6a2741fa017756b3018
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/qa/extras/chart2export.cxx | 161 | ||||
-rw-r--r-- | chart2/qa/extras/data/ods/trendline.ods | bin | 0 -> 17563 bytes |
2 files changed, 161 insertions, 0 deletions
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index 3a6cd81df77b..f46ab1a55453 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -10,6 +10,8 @@ #include "charttest.hxx" #include <com/sun/star/chart/ErrorBarStyle.hpp> +#include <com/sun/star/chart2/XRegressionCurveContainer.hpp> +#include <com/sun/star/lang/XServiceName.hpp> using uno::Reference; using beans::XPropertySet; @@ -19,10 +21,12 @@ class Chart2ExportTest : public ChartTest public: void test(); void testErrorBarXLSX(); + void testTrendline(); CPPUNIT_TEST_SUITE(Chart2ExportTest); CPPUNIT_TEST(test); CPPUNIT_TEST(testErrorBarXLSX); + CPPUNIT_TEST(testTrendline); CPPUNIT_TEST_SUITE_END(); private: @@ -54,6 +58,142 @@ void testErrorBar( Reference< XPropertySet > xErrorBar ) CPPUNIT_ASSERT_DOUBLES_EQUAL(nVal, 10.0, 1e-10); } +void checkCommonTrendline( + Reference<chart2::XRegressionCurve> xCurve, + double aExpectedExtrapolateForward, double aExpectedExtrapolateBackward, + sal_Bool aExpectedForceIntercept, double aExpectedInterceptValue, + sal_Bool aExpectedShowEquation, sal_Bool aExpectedR2) +{ + Reference<XPropertySet> xProperties( xCurve , uno::UNO_QUERY ); + CPPUNIT_ASSERT(xProperties.is()); + + double aExtrapolateForward = 0.0; + CPPUNIT_ASSERT(xProperties->getPropertyValue("ExtrapolateForward") >>= aExtrapolateForward); + CPPUNIT_ASSERT_EQUAL(aExpectedExtrapolateForward, aExtrapolateForward); + + double aExtrapolateBackward = 0.0; + CPPUNIT_ASSERT(xProperties->getPropertyValue("ExtrapolateBackward") >>= aExtrapolateBackward); + CPPUNIT_ASSERT_EQUAL(aExpectedExtrapolateBackward, aExtrapolateBackward); + + sal_Bool aForceIntercept = false; + CPPUNIT_ASSERT(xProperties->getPropertyValue("ForceIntercept") >>= aForceIntercept); + CPPUNIT_ASSERT_EQUAL(aExpectedForceIntercept, aForceIntercept); + + if (aForceIntercept) + { + double aInterceptValue = 0.0; + CPPUNIT_ASSERT(xProperties->getPropertyValue("InterceptValue") >>= aInterceptValue); + CPPUNIT_ASSERT_EQUAL(aExpectedInterceptValue, aInterceptValue); + } + + Reference< XPropertySet > xEquationProperties( xCurve->getEquationProperties() ); + CPPUNIT_ASSERT(xEquationProperties.is()); + + sal_Bool aShowEquation = false; + CPPUNIT_ASSERT(xEquationProperties->getPropertyValue("ShowEquation") >>= aShowEquation); + CPPUNIT_ASSERT_EQUAL(aExpectedShowEquation, aShowEquation); + + sal_Bool aShowCorrelationCoefficient = false; + CPPUNIT_ASSERT(xEquationProperties->getPropertyValue("ShowCorrelationCoefficient") >>= aShowCorrelationCoefficient); + CPPUNIT_ASSERT_EQUAL(aExpectedR2, aShowCorrelationCoefficient); +} + +void checkNameAndType(Reference<XPropertySet> xProperties, OUString aExpectedName, OUString aExpectedServiceName) +{ + OUString aService; + Reference< lang::XServiceName > xServiceName( xProperties, UNO_QUERY ); + CPPUNIT_ASSERT(xServiceName.is()); + + OUString aServiceName = xServiceName->getServiceName(); + CPPUNIT_ASSERT_EQUAL(aExpectedServiceName, aServiceName); + + OUString aCurveName; + CPPUNIT_ASSERT(xProperties->getPropertyValue("CurveName") >>= aCurveName); + CPPUNIT_ASSERT_EQUAL(aExpectedName, aCurveName); +} + +void checkLinearTrendline( + Reference<chart2::XRegressionCurve> xCurve, OUString aExpectedName, + double aExpectedExtrapolateForward, double aExpectedExtrapolateBackward, + sal_Bool aExpectedForceIntercept, double aExpectedInterceptValue, + sal_Bool aExpectedShowEquation, sal_Bool aExpectedR2) +{ + Reference<XPropertySet> xProperties( xCurve , uno::UNO_QUERY ); + CPPUNIT_ASSERT(xProperties.is()); + + checkNameAndType(xProperties, aExpectedName, "com.sun.star.chart2.LinearRegressionCurve"); + + checkCommonTrendline( + xCurve, + aExpectedExtrapolateForward, aExpectedExtrapolateBackward, + aExpectedForceIntercept, aExpectedInterceptValue, + aExpectedShowEquation, aExpectedR2); +} + +void checkPolynomialTrendline( + Reference<chart2::XRegressionCurve> xCurve, OUString aExpectedName, + sal_Int32 aExpectedDegree, + double aExpectedExtrapolateForward, double aExpectedExtrapolateBackward, + sal_Bool aExpectedForceIntercept, double aExpectedInterceptValue, + sal_Bool aExpectedShowEquation, sal_Bool aExpectedR2) +{ + Reference<XPropertySet> xProperties( xCurve , uno::UNO_QUERY ); + CPPUNIT_ASSERT(xProperties.is()); + + checkNameAndType(xProperties, aExpectedName, "com.sun.star.chart2.PolynomialRegressionCurve"); + + sal_Int32 aDegree = 2; + CPPUNIT_ASSERT(xProperties->getPropertyValue("PolynomialDegree") >>= aDegree); + CPPUNIT_ASSERT_EQUAL(aExpectedDegree, aDegree); + + checkCommonTrendline( + xCurve, + aExpectedExtrapolateForward, aExpectedExtrapolateBackward, + aExpectedForceIntercept, aExpectedInterceptValue, + aExpectedShowEquation, aExpectedR2); +} + +void checkMovingAverageTrendline( + Reference<chart2::XRegressionCurve> xCurve, OUString aExpectedName, sal_Int32 aExpectedPeriod) +{ + Reference<XPropertySet> xProperties( xCurve , uno::UNO_QUERY ); + CPPUNIT_ASSERT(xProperties.is()); + + checkNameAndType(xProperties, aExpectedName, "com.sun.star.chart2.MovingAverageRegressionCurve"); + + sal_Int32 aPeriod = 2; + CPPUNIT_ASSERT(xProperties->getPropertyValue("MovingAveragePeriod") >>= aPeriod); + CPPUNIT_ASSERT_EQUAL(aExpectedPeriod, aPeriod); +} + +void checkTrendlinesInChart(uno::Reference< chart2::XChartDocument > xChartDoc) +{ + CPPUNIT_ASSERT(xChartDoc.is()); + + Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 ); + CPPUNIT_ASSERT( xDataSeries.is() ); + + Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer( xDataSeries, UNO_QUERY ); + CPPUNIT_ASSERT( xRegressionCurveContainer.is() ); + + Sequence< Reference< chart2::XRegressionCurve > > xRegressionCurveSequence = xRegressionCurveContainer->getRegressionCurves(); + CPPUNIT_ASSERT_EQUAL(3, xRegressionCurveSequence.getLength()); + + Reference<chart2::XRegressionCurve> xCurve; + + xCurve = xRegressionCurveSequence[0]; + CPPUNIT_ASSERT(xCurve.is()); + checkPolynomialTrendline(xCurve, "col2_poly", 3, 0.1, -0.1, true, -1.0, true, true); + + xCurve = xRegressionCurveSequence[1]; + CPPUNIT_ASSERT(xCurve.is()); + checkLinearTrendline(xCurve, "col2_linear", -0.5, -0.5, false, 0.0, true, false); + + xCurve = xRegressionCurveSequence[2]; + CPPUNIT_ASSERT(xCurve.is()); + checkMovingAverageTrendline(xCurve, "col2_moving_avg", 3); +} + } // improve the test @@ -95,6 +235,27 @@ void Chart2ExportTest::testErrorBarXLSX() } } +// This method tests the preservation of properties for trendlines / regression curves +// in an export -> import cycle using different file formats - ODS, XLS and XLSX. +void Chart2ExportTest::testTrendline() +{ + load("/chart2/qa/extras/data/ods/", "trendline.ods"); + checkTrendlinesInChart(getChartDocFromSheet( 0, mxComponent)); + reload("calc8"); + checkTrendlinesInChart(getChartDocFromSheet( 0, mxComponent)); + + load("/chart2/qa/extras/data/ods/", "trendline.ods"); + checkTrendlinesInChart(getChartDocFromSheet( 0, mxComponent)); + reload("Calc Office Open XML"); + checkTrendlinesInChart(getChartDocFromSheet( 0, mxComponent)); + + load("/chart2/qa/extras/data/ods/", "trendline.ods"); + checkTrendlinesInChart(getChartDocFromSheet( 0, mxComponent)); + reload("MS Excel 97"); + checkTrendlinesInChart(getChartDocFromSheet( 0, mxComponent)); + +} + CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/chart2/qa/extras/data/ods/trendline.ods b/chart2/qa/extras/data/ods/trendline.ods Binary files differnew file mode 100644 index 000000000000..707d51020318 --- /dev/null +++ b/chart2/qa/extras/data/ods/trendline.ods |