/* -*- 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 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 ); void reload( const OUString& rFilterName ); 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::reload(const OUString& rFilterName) { uno::Reference xStorable(mxComponent, uno::UNO_QUERY); uno::Sequence aArgs(1); aArgs[0].Name = "FilterName"; aArgs[0].Value <<= rFilterName; utl::TempFile aTempFile; aTempFile.EnableKillingFile(); xStorable->storeToURL(aTempFile.GetURL(), aArgs); uno::Reference xComponent(xStorable, uno::UNO_QUERY); xComponent->dispose(); mxComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.sheet.SpreadsheetDocument"); std::cout << aTempFile.GetURL(); 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 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: */