summaryrefslogtreecommitdiff
path: root/chart2/qa/extras/chart2import.cxx
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-03-05 11:11:44 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-03-05 11:14:59 +0100
commit7cd6f8f7ad868d2c69bd528d21aa0d8190299270 (patch)
tree34c6721c55bf604f5034abfca80c996b630baa62 /chart2/qa/extras/chart2import.cxx
parentb6d79264399cbb11f0c030ce18e486914a5515df (diff)
start for an initial chart2 import test
Change-Id: Iedd531186fccd73704eb3137195a22d3ca005293
Diffstat (limited to 'chart2/qa/extras/chart2import.cxx')
-rw-r--r--chart2/qa/extras/chart2import.cxx172
1 files changed, 172 insertions, 0 deletions
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
new file mode 100644
index 000000000000..1a6db5be6cd5
--- /dev/null
+++ b/chart2/qa/extras/chart2import.cxx
@@ -0,0 +1,172 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/bootstrapfixture.hxx>
+#include <unotest/macros_test.hxx>
+
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
+#include <com/sun/star/sheet/XSpreadsheet.hpp>
+#include <com/sun/star/container/XIndexAccess.hpp>
+#include <com/sun/star/table/XTableChartsSupplier.hpp>
+#include <com/sun/star/table/XTableCharts.hpp>
+#include <com/sun/star/table/XTableChart.hpp>
+#include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+#include <com/sun/star/chart2/XChartDocument.hpp>
+#include <com/sun/star/chart2/XDiagram.hpp>
+#include <com/sun/star/chart2/XDataSeries.hpp>
+#include <com/sun/star/chart2/XChartTypeContainer.hpp>
+#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
+#include <com/sun/star/chart2/XDataSeriesContainer.hpp>
+
+#include <comphelper/processfactory.hxx>
+
+using namespace com::sun::star;
+using namespace com::sun::star::uno;
+
+class Chart2ImportTest : public test::BootstrapFixture, public unotest::MacrosTest
+{
+public:
+ void Fdo60083();
+
+ virtual void setUp();
+ virtual void tearDown();
+
+ CPPUNIT_TEST_SUITE(Chart2ImportTest);
+ CPPUNIT_TEST(Fdo60083);
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+ void load( const char* pDir, const char* pName );
+
+ Reference< chart2::XChartDocument > getChartDocFromSheet( sal_Int32 nSheet, uno::Reference< lang::XComponent > xComponent );
+ Reference< chart2::XDataSeries > getDataSeriesFromDoc( Reference< chart2::XChartDocument > xChartDoc,
+ sal_Int32 nDataSeries, sal_Int32 nChartType = 0, sal_Int32 nCooSys = 0 );
+
+ Reference< lang::XComponent > mxComponent;
+};
+
+// error bar import
+// split method up into smaller chunks for more detailed tests
+void Chart2ImportTest::Fdo60083()
+{
+ load("/chart2/qa/extras/data/ods/", "error_bar_simple.ods");
+ uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0, mxComponent );
+ CPPUNIT_ASSERT(xChartDoc.is());
+
+ Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
+ CPPUNIT_ASSERT( xDataSeries.is() );
+
+ Reference< beans::XPropertySet > xPropSet( xDataSeries, UNO_QUERY_THROW );
+ CPPUNIT_ASSERT( xPropSet.is() );
+
+ // test that y error bars are there
+ Reference< beans::XPropertySet > xErrorBarYProps;
+ xPropSet->getPropertyValue("ErrorBarY") >>= xErrorBarYProps;
+ CPPUNIT_ASSERT(xErrorBarYProps.is());
+
+ // test that x error bars are not imported
+ Reference< beans::XPropertySet > xErrorBarXProps;
+ xPropSet->getPropertyValue("ErrorBarX") >>= xErrorBarXProps;
+ CPPUNIT_ASSERT(!xErrorBarXProps.is());
+}
+
+Reference< chart2::XChartDocument > Chart2ImportTest::getChartDocFromSheet( sal_Int32 nSheet, uno::Reference< lang::XComponent > xComponent )
+{
+ // let us assume that we only have one chart per sheet
+
+ uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(xDoc.is());
+
+ uno::Reference< container::XIndexAccess > xIA(xDoc->getSheets(), UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(xIA.is());
+
+ uno::Reference< table::XTableChartsSupplier > xChartSupplier( xIA->getByIndex(nSheet), UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(xChartSupplier.is());
+
+ uno::Reference< table::XTableCharts > xCharts = xChartSupplier->getCharts();
+ CPPUNIT_ASSERT(xCharts.is());
+
+ uno::Reference< container::XIndexAccess > xIACharts(xCharts, UNO_QUERY_THROW);
+ uno::Reference< table::XTableChart > xChart( xIACharts->getByIndex(0), UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(xChart.is());
+
+ uno::Reference< document::XEmbeddedObjectSupplier > xEmbObjectSupplier(xChart, UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(xEmbObjectSupplier.is());
+
+ uno::Reference< lang::XComponent > xChartComp( xEmbObjectSupplier->getEmbeddedObject(), UNO_QUERY_THROW );
+ CPPUNIT_ASSERT(xChartComp.is());
+
+ uno::Reference< chart2::XChartDocument > xChartDoc ( xChartComp, UNO_QUERY_THROW );
+
+ CPPUNIT_ASSERT(xChartDoc.is());
+ return xChartDoc;
+}
+
+Reference< chart2::XDataSeries > Chart2ImportTest::getDataSeriesFromDoc( uno::Reference< chart2::XChartDocument > xChartDoc,
+ sal_Int32 nDataSeries, sal_Int32 nChartType, sal_Int32 nCooSys )
+{
+ CPPUNIT_ASSERT( xChartDoc.is() );
+
+ 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::XChartTypeContainer > xChartTypeContainer( xCooSysSequence[nCooSys], UNO_QUERY_THROW );
+ CPPUNIT_ASSERT( xChartTypeContainer.is() );
+
+ Sequence< Reference< chart2::XChartType > > xChartTypeSequence( xChartTypeContainer->getChartTypes() );
+ CPPUNIT_ASSERT( xChartTypeSequence.getLength() > nChartType );
+
+ Reference< chart2::XDataSeriesContainer > xDataSequenceContainer( xChartTypeSequence[nChartType], UNO_QUERY_THROW );
+ CPPUNIT_ASSERT ( xDataSequenceContainer.is() );
+
+ Sequence< Reference< chart2::XDataSeries > > xSeriesSequence( xDataSequenceContainer->getDataSeries() );
+ CPPUNIT_ASSERT( xSeriesSequence.getLength() > nDataSeries );
+
+ Reference< chart2::XDataSeries > xSeries = xSeriesSequence[nDataSeries];
+
+ return xSeries;
+}
+
+void Chart2ImportTest::load( const char* pDir, const char* pName )
+{
+ mxComponent = loadFromDesktop(getURLFromSrc(pDir) + OUString::createFromAscii(pName), "com.sun.star.sheet.SpreadsheetDocument");
+ CPPUNIT_ASSERT(mxComponent.is());
+}
+
+void Chart2ImportTest::setUp()
+{
+ test::BootstrapFixture::setUp();
+
+ mxDesktop.set( com::sun::star::frame::Desktop::create( comphelper::getComponentContext(getMultiServiceFactory()) ) );
+}
+
+void Chart2ImportTest::tearDown()
+{
+ if(mxComponent.is())
+ mxComponent->dispose();
+
+ test::BootstrapFixture::tearDown();
+
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */