diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2013-04-23 07:11:57 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2013-04-24 12:17:48 +0200 |
commit | a172ed9837d1c52eebd9336e5262f459920e525b (patch) | |
tree | a9ce15244ffbe1ac6783f3e5a9e695e811e0b9dc /chart2 | |
parent | 4b520d2ee8732d24d882ac965078f54e5ae5d418 (diff) |
extract common chart test parts into own header
Change-Id: Id41b9c3cd241de9bc5fa1da885bc9a206bca093d
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/qa/extras/chart2import.cxx | 131 | ||||
-rw-r--r-- | chart2/qa/extras/charttest.hxx | 139 |
2 files changed, 141 insertions, 129 deletions
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx index b498c695ff96..decd18ed2b1a 100644 --- a/chart2/qa/extras/chart2import.cxx +++ b/chart2/qa/extras/chart2import.cxx @@ -7,45 +7,18 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <test/bootstrapfixture.hxx> -#include <unotest/macros_test.hxx> +#include "charttest.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 <com/sun/star/chart2/CurveStyle.hpp> #include <com/sun/star/chart/ErrorBarStyle.hpp> -#include <com/sun/star/chart/XChartDocument.hpp> - -#include <comphelper/processfactory.hxx> - -using namespace com::sun::star; -using namespace com::sun::star::uno; -class Chart2ImportTest : public test::BootstrapFixture, public unotest::MacrosTest +class Chart2ImportTest : public ChartTest { public: void Fdo60083(); void testSteppedLines(); void testErrorBarRange(); - virtual void setUp(); - virtual void tearDown(); - CPPUNIT_TEST_SUITE(Chart2ImportTest); CPPUNIT_TEST(Fdo60083); CPPUNIT_TEST(testSteppedLines); @@ -53,15 +26,7 @@ public: 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< chart2::XChartType > getChartTypeFromDoc( Reference< chart2::XChartDocument > xChartDoc, - sal_Int32 nChartType, sal_Int32 nCooSys = 0 ); - Reference< lang::XComponent > mxComponent; }; // error bar import @@ -186,98 +151,6 @@ void Chart2ImportTest::testSteppedLines() } } -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::XChartType > Chart2ImportTest::getChartTypeFromDoc( Reference< chart2::XChartDocument > xChartDoc, - 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 ); - - return xChartTypeSequence[nChartType]; -} - -Reference< chart2::XDataSeries > Chart2ImportTest::getDataSeriesFromDoc( uno::Reference< chart2::XChartDocument > xChartDoc, - sal_Int32 nDataSeries, sal_Int32 nChartType, sal_Int32 nCooSys ) -{ - Reference< chart2::XChartType > xChartType = getChartTypeFromDoc( xChartDoc, nChartType, nCooSys ); - Reference< chart2::XDataSeriesContainer > xDataSequenceContainer( xChartType, 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(); diff --git a/chart2/qa/extras/charttest.hxx b/chart2/qa/extras/charttest.hxx new file mode 100644 index 000000000000..e4968f1fde01 --- /dev/null +++ b/chart2/qa/extras/charttest.hxx @@ -0,0 +1,139 @@ +/* -*- 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 <comphelper/processfactory.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> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +class ChartTest : public test::BootstrapFixture, public unotest::MacrosTest +{ +public: + void load( const char* pDir, const char* pName ); + + virtual void setUp(); + virtual void tearDown(); +protected: + Reference< lang::XComponent > mxComponent; +}; + +void ChartTest::load( const char* pDir, const char* pName ) +{ + mxComponent = loadFromDesktop(getURLFromSrc(pDir) + OUString::createFromAscii(pName), "com.sun.star.sheet.SpreadsheetDocument"); + CPPUNIT_ASSERT(mxComponent.is()); +} + +void ChartTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set( com::sun::star::frame::Desktop::create( comphelper::getComponentContext(getMultiServiceFactory()) ) ); +} + +void ChartTest::tearDown() +{ + if(mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); + +} + +Reference< chart2::XChartDocument > 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::XChartType > getChartTypeFromDoc( Reference< chart2::XChartDocument > xChartDoc, + sal_Int32 nChartType, sal_Int32 nCooSys = 0 ) +{ + 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 ); + + return xChartTypeSequence[nChartType]; +} + +Reference< chart2::XDataSeries > getDataSeriesFromDoc( uno::Reference< chart2::XChartDocument > xChartDoc, + sal_Int32 nDataSeries, sal_Int32 nChartType = 0, sal_Int32 nCooSys = 0 ) +{ + Reference< chart2::XChartType > xChartType = getChartTypeFromDoc( xChartDoc, nChartType, nCooSys ); + Reference< chart2::XDataSeriesContainer > xDataSequenceContainer( xChartType, 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; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |