Kaydet (Commit) 2ead27dc authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

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
üst b32651fe
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "charttest.hxx" #include "charttest.hxx"
#include <com/sun/star/chart/ErrorBarStyle.hpp> #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 uno::Reference;
using beans::XPropertySet; using beans::XPropertySet;
...@@ -19,10 +21,12 @@ class Chart2ExportTest : public ChartTest ...@@ -19,10 +21,12 @@ class Chart2ExportTest : public ChartTest
public: public:
void test(); void test();
void testErrorBarXLSX(); void testErrorBarXLSX();
void testTrendline();
CPPUNIT_TEST_SUITE(Chart2ExportTest); CPPUNIT_TEST_SUITE(Chart2ExportTest);
CPPUNIT_TEST(test); CPPUNIT_TEST(test);
CPPUNIT_TEST(testErrorBarXLSX); CPPUNIT_TEST(testErrorBarXLSX);
CPPUNIT_TEST(testTrendline);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
...@@ -54,6 +58,142 @@ void testErrorBar( Reference< XPropertySet > xErrorBar ) ...@@ -54,6 +58,142 @@ void testErrorBar( Reference< XPropertySet > xErrorBar )
CPPUNIT_ASSERT_DOUBLES_EQUAL(nVal, 10.0, 1e-10); 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 // improve the test
...@@ -95,6 +235,27 @@ void Chart2ExportTest::testErrorBarXLSX() ...@@ -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_TEST_SUITE_REGISTRATION(Chart2ExportTest);
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
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