[Libreoffice-commits] core.git: chart2/qa

Tomaž Vajngerl quikee at gmail.com
Mon Nov 25 23:31:17 PST 2013


 chart2/qa/extras/chart2export.cxx       |  161 ++++++++++++++++++++++++++++++++
 chart2/qa/extras/data/ods/trendline.ods |binary
 2 files changed, 161 insertions(+)

New commits:
commit 2ead27dc7026fc4789323f8849f43c5cafcec2fe
Author: Tomaž Vajngerl <quikee at gmail.com>
Date:   Tue Nov 26 08:28:29 2013 +0100

    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

diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 3a6cd81..f46ab1a 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
new file mode 100644
index 0000000..707d510
Binary files /dev/null and b/chart2/qa/extras/data/ods/trendline.ods differ


More information about the Libreoffice-commits mailing list