LCOV - code coverage report
Current view: top level - chart2/qa/extras - charttest.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 263 275 95.6 %
Date: 2015-06-13 12:38:46 Functions: 25 26 96.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #ifndef INCLUDED_CHART2_QA_EXTRAS_CHARTTEST_HXX
      11             : #define INCLUDED_CHART2_QA_EXTRAS_CHARTTEST_HXX
      12             : 
      13             : #include <test/bootstrapfixture.hxx>
      14             : #include <unotest/macros_test.hxx>
      15             : #include <comphelper/processfactory.hxx>
      16             : #include <comphelper/propertysequence.hxx>
      17             : 
      18             : #include <com/sun/star/lang/XComponent.hpp>
      19             : #include <com/sun/star/frame/Desktop.hpp>
      20             : 
      21             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      22             : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      23             : #include <com/sun/star/container/XIndexAccess.hpp>
      24             : #include <com/sun/star/table/XTableChartsSupplier.hpp>
      25             : #include <com/sun/star/table/XTableCharts.hpp>
      26             : #include <com/sun/star/table/XTableChart.hpp>
      27             : #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
      28             : #include <com/sun/star/beans/XPropertySet.hpp>
      29             : #include <com/sun/star/frame/XStorable.hpp>
      30             : #include <com/sun/star/beans/PropertyValue.hpp>
      31             : 
      32             : #include <unotools/tempfile.hxx>
      33             : 
      34             : #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
      35             : #include <com/sun/star/chart2/XChartDocument.hpp>
      36             : #include <com/sun/star/chart2/XDiagram.hpp>
      37             : #include <com/sun/star/chart2/XDataSeries.hpp>
      38             : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
      39             : #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
      40             : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
      41             : #include <com/sun/star/chart2/XFormattedString.hpp>
      42             : #include <com/sun/star/chart2/XTitle.hpp>
      43             : #include <com/sun/star/chart2/XTitled.hpp>
      44             : #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
      45             : #include <com/sun/star/chart2/data/XDataSource.hpp>
      46             : #include <com/sun/star/chart/XChartDataArray.hpp>
      47             : #include <com/sun/star/chart/XComplexDescriptionAccess.hpp>
      48             : #include <com/sun/star/chart/DataLabelPlacement.hpp>
      49             : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
      50             : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      51             : #include <com/sun/star/drawing/FillStyle.hpp>
      52             : #include <com/sun/star/chart/XChartDocument.hpp>
      53             : #include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
      54             : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      55             : #include <com/sun/star/util/NumberFormat.hpp>
      56             : 
      57             : #include <unonames.hxx>
      58             : 
      59             : #include <iostream>
      60             : 
      61             : #include <libxml/xmlwriter.h>
      62             : #include <libxml/xpath.h>
      63             : 
      64             : #include <boost/shared_ptr.hpp>
      65             : #include <boost/make_shared.hpp>
      66             : 
      67             : using namespace css;
      68             : using namespace css::uno;
      69             : 
      70         106 : class ChartTest : public test::BootstrapFixture, public unotest::MacrosTest
      71             : {
      72             : public:
      73         106 :     ChartTest():mbSkipValidation(false) {}
      74             :     void load( const OUString& rDir, const OUString& rFileName );
      75             :     boost::shared_ptr<utl::TempFile> reload( const OUString& rFileName );
      76             :     uno::Sequence < OUString > getImpressChartColumnDescriptions( const char* pDir, const char* pName );
      77             :     OUString getFileExtension( const OUString& rFileName );
      78             : 
      79             :     uno::Reference< chart::XChartDocument > getChartDocFromImpress( const char* pDir, const char* pName );
      80             : 
      81             :     uno::Reference<chart::XChartDocument> getChartDocFromDrawImpress( sal_Int32 nPage, sal_Int32 nShape );
      82             : 
      83             :     uno::Reference<chart::XChartDocument> getChartDocFromWriter( sal_Int32 nShape );
      84             : 
      85             :     virtual void setUp() SAL_OVERRIDE;
      86             :     virtual void tearDown() SAL_OVERRIDE;
      87             : 
      88             : protected:
      89             :     Reference< lang::XComponent > mxComponent;
      90             :     OUString maServiceName;
      91             :     bool mbSkipValidation; // if you set this flag for a new test I'm going to haunt you!
      92             : };
      93             : 
      94         102 : OUString ChartTest::getFileExtension( const OUString& aFileName )
      95             : {
      96         102 :     sal_Int32 nDotLocation = aFileName.lastIndexOf('.');
      97         102 :     CPPUNIT_ASSERT(nDotLocation != -1);
      98         102 :     return aFileName.copy(nDotLocation+1); // Skip the dot.
      99             : }
     100             : 
     101         102 : void ChartTest::load( const OUString& aDir, const OUString& aName )
     102             : {
     103         102 :     OUString extension = getFileExtension(aName);
     104         102 :     if (extension == "ods" || extension == "xlsx" || extension == "fods")
     105             :     {
     106          62 :         maServiceName = "com.sun.star.sheet.SpreadsheetDocument";
     107             :     }
     108          40 :     else if (extension == "docx")
     109             :     {
     110          31 :         maServiceName = "com.sun.star.text.TextDocument";
     111             :     }
     112           9 :     else if (extension == "odg")
     113             :     {
     114           0 :         maServiceName = "com.sun.star.drawing.DrawingDocument";
     115             :     }
     116             : 
     117         102 :     mxComponent = loadFromDesktop(getURLFromSrc(aDir) + aName, maServiceName);
     118         102 :     CPPUNIT_ASSERT(mxComponent.is());
     119         102 : }
     120             : 
     121          57 : boost::shared_ptr<utl::TempFile> ChartTest::reload(const OUString& rFilterName)
     122             : {
     123          57 :     uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
     124             :     auto aArgs(::comphelper::InitPropertySequence({
     125             :         { "FilterName", makeAny(rFilterName) }
     126         114 :     }));
     127          57 :     boost::shared_ptr<utl::TempFile> pTempFile = boost::make_shared<utl::TempFile>();
     128          57 :     pTempFile->EnableKillingFile();
     129          57 :     xStorable->storeToURL(pTempFile->GetURL(), aArgs);
     130          57 :     mxComponent->dispose();
     131          57 :     mxComponent = loadFromDesktop(pTempFile->GetURL(), maServiceName);
     132          57 :     std::cout << pTempFile->GetURL();
     133          57 :     if(rFilterName == "Calc Office Open XML")
     134             :     {
     135          23 :         validate(pTempFile->GetFileName(), test::OOXML);
     136             :     }
     137          34 :     else if(rFilterName == "Office Open XML Text")
     138             :     {
     139             :         // validate(pTempFile->GetFileName(), test::OOXML);
     140             :     }
     141           6 :     else if(rFilterName == "calc8")
     142             :     {
     143           4 :         if(!mbSkipValidation)
     144           3 :             validate(pTempFile->GetFileName(), test::ODF);
     145             :     }
     146             : 
     147          57 :     CPPUNIT_ASSERT(mxComponent.is());
     148         114 :     return pTempFile;
     149             : }
     150             : 
     151         106 : void ChartTest::setUp()
     152             : {
     153         106 :     test::BootstrapFixture::setUp();
     154             : 
     155         106 :     mxDesktop.set( css::frame::Desktop::create( comphelper::getComponentContext(getMultiServiceFactory()) ) );
     156         106 : }
     157             : 
     158         106 : void ChartTest::tearDown()
     159             : {
     160         106 :     if(mxComponent.is())
     161         105 :         mxComponent->dispose();
     162             : 
     163         106 :     test::BootstrapFixture::tearDown();
     164             : 
     165         106 : }
     166             : 
     167          66 : Reference< lang::XComponent > getChartCompFromSheet( sal_Int32 nSheet, uno::Reference< lang::XComponent > xComponent )
     168             : {
     169             :     // let us assume that we only have one chart per sheet
     170             : 
     171          66 :     uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW);
     172          66 :     CPPUNIT_ASSERT(xDoc.is());
     173             : 
     174         132 :     uno::Reference< container::XIndexAccess > xIA(xDoc->getSheets(), UNO_QUERY_THROW);
     175          66 :     CPPUNIT_ASSERT(xIA.is());
     176             : 
     177         132 :     uno::Reference< table::XTableChartsSupplier > xChartSupplier( xIA->getByIndex(nSheet), UNO_QUERY_THROW);
     178          66 :     CPPUNIT_ASSERT(xChartSupplier.is());
     179             : 
     180         132 :     uno::Reference< table::XTableCharts > xCharts = xChartSupplier->getCharts();
     181          66 :     CPPUNIT_ASSERT(xCharts.is());
     182             : 
     183         132 :     uno::Reference< container::XIndexAccess > xIACharts(xCharts, UNO_QUERY_THROW);
     184         132 :     uno::Reference< table::XTableChart > xChart( xIACharts->getByIndex(0), UNO_QUERY_THROW);
     185          66 :     CPPUNIT_ASSERT(xChart.is());
     186             : 
     187         132 :     uno::Reference< document::XEmbeddedObjectSupplier > xEmbObjectSupplier(xChart, UNO_QUERY_THROW);
     188          66 :     CPPUNIT_ASSERT(xEmbObjectSupplier.is());
     189             : 
     190          66 :     uno::Reference< lang::XComponent > xChartComp( xEmbObjectSupplier->getEmbeddedObject(), UNO_QUERY_THROW );
     191          66 :     CPPUNIT_ASSERT(xChartComp.is());
     192             : 
     193         132 :     return xChartComp;
     194             : 
     195             : }
     196             : 
     197          61 : Reference< chart2::XChartDocument > getChartDocFromSheet( sal_Int32 nSheet, uno::Reference< lang::XComponent > xComponent )
     198             : {
     199          61 :     uno::Reference< chart2::XChartDocument > xChartDoc ( getChartCompFromSheet(nSheet, xComponent), UNO_QUERY_THROW );
     200          61 :     CPPUNIT_ASSERT(xChartDoc.is());
     201          61 :     return xChartDoc;
     202             : }
     203             : 
     204          56 : Reference< chart2::XChartType > getChartTypeFromDoc( Reference< chart2::XChartDocument > xChartDoc,
     205             :                                                                 sal_Int32 nChartType, sal_Int32 nCooSys = 0 )
     206             : {
     207          56 :     CPPUNIT_ASSERT( xChartDoc.is() );
     208             : 
     209          56 :     Reference <chart2::XDiagram > xDiagram = xChartDoc->getFirstDiagram();
     210          56 :     CPPUNIT_ASSERT( xDiagram.is() );
     211             : 
     212         112 :     Reference< chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, UNO_QUERY_THROW );
     213          56 :     CPPUNIT_ASSERT( xCooSysContainer.is() );
     214             : 
     215         112 :     Sequence< Reference< chart2::XCoordinateSystem > > xCooSysSequence( xCooSysContainer->getCoordinateSystems());
     216          56 :     CPPUNIT_ASSERT( xCooSysSequence.getLength() > nCooSys );
     217             : 
     218         112 :     Reference< chart2::XChartTypeContainer > xChartTypeContainer( xCooSysSequence[nCooSys], UNO_QUERY_THROW );
     219          56 :     CPPUNIT_ASSERT( xChartTypeContainer.is() );
     220             : 
     221         112 :     Sequence< Reference< chart2::XChartType > > xChartTypeSequence( xChartTypeContainer->getChartTypes() );
     222          56 :     CPPUNIT_ASSERT( xChartTypeSequence.getLength() > nChartType );
     223             : 
     224         112 :     return xChartTypeSequence[nChartType];
     225             : }
     226             : 
     227          15 : Reference<chart2::XAxis> getAxisFromDoc(
     228             :     const Reference<chart2::XChartDocument>& xChartDoc, sal_Int32 nCooSys, sal_Int32 nAxisDim, sal_Int32 nAxisIndex )
     229             : {
     230          15 :     Reference<chart2::XDiagram> xDiagram = xChartDoc->getFirstDiagram();
     231          15 :     CPPUNIT_ASSERT(xDiagram.is());
     232             : 
     233          30 :     Reference<chart2::XCoordinateSystemContainer> xCooSysContainer(xDiagram, UNO_QUERY_THROW);
     234          15 :     CPPUNIT_ASSERT(xCooSysContainer.is());
     235             : 
     236          30 :     Sequence<Reference<chart2::XCoordinateSystem> > xCooSysSequence = xCooSysContainer->getCoordinateSystems();
     237          15 :     CPPUNIT_ASSERT(xCooSysSequence.getLength() > nCooSys);
     238             : 
     239          30 :     Reference<chart2::XCoordinateSystem> xCoord = xCooSysSequence[nCooSys];
     240          15 :     CPPUNIT_ASSERT(xCoord.is());
     241             : 
     242          15 :     Reference<chart2::XAxis> xAxis = xCoord->getAxisByDimension(nAxisDim, nAxisIndex);
     243          15 :     CPPUNIT_ASSERT(xAxis.is());
     244             : 
     245          30 :     return xAxis;
     246             : }
     247             : 
     248          29 : Reference< chart2::XDataSeries > getDataSeriesFromDoc( uno::Reference< chart2::XChartDocument > xChartDoc,
     249             :                                                                 sal_Int32 nDataSeries, sal_Int32 nChartType = 0, sal_Int32 nCooSys = 0 )
     250             : {
     251          29 :     Reference< chart2::XChartType > xChartType = getChartTypeFromDoc( xChartDoc, nChartType, nCooSys );
     252          58 :     Reference< chart2::XDataSeriesContainer > xDataSeriesContainer( xChartType, UNO_QUERY_THROW );
     253          29 :     CPPUNIT_ASSERT ( xDataSeriesContainer.is() );
     254             : 
     255          58 :     Sequence< Reference< chart2::XDataSeries > > xSeriesSequence( xDataSeriesContainer->getDataSeries() );
     256          29 :     CPPUNIT_ASSERT( xSeriesSequence.getLength() > nDataSeries );
     257             : 
     258          29 :     Reference< chart2::XDataSeries > xSeries = xSeriesSequence[nDataSeries];
     259             : 
     260          58 :     return xSeries;
     261             : }
     262             : 
     263           2 : Reference< chart2::data::XDataSequence > getLabelDataSequenceFromDoc(
     264             :         Reference< chart2::XChartDocument > xChartDoc,
     265             :         sal_Int32 nDataSeries = 0, sal_Int32 nChartType = 0, sal_Int32 nCooSys = 0 )
     266             : {
     267             :     Reference< chart2::XDataSeries > xDataSeries =
     268           2 :         getDataSeriesFromDoc( xChartDoc, nDataSeries, nChartType, nCooSys );
     269           2 :     CPPUNIT_ASSERT(xDataSeries.is());
     270           4 :     Reference< chart2::data::XDataSource > xDataSource( xDataSeries, uno::UNO_QUERY_THROW );
     271             :     Sequence< Reference< chart2::data::XLabeledDataSequence > > xDataSequences =
     272           4 :         xDataSource->getDataSequences();
     273           4 :     for(sal_Int32 i = 0; i < xDataSequences.getLength(); ++i)
     274             :     {
     275           4 :         Reference< chart2::data::XDataSequence> xLabelSeq = xDataSequences[i]->getLabel();
     276           4 :         if(!xLabelSeq.is())
     277           2 :             continue;
     278             : 
     279           2 :         return xLabelSeq;
     280           0 :     }
     281             : 
     282           0 :     CPPUNIT_FAIL("no Label sequence found");
     283           2 :     return Reference< chart2::data::XDataSequence > ();
     284             : }
     285             : 
     286           1 : Reference< chart2::data::XDataSequence > getDataSequenceFromDocByRole(
     287             :         Reference< chart2::XChartDocument > xChartDoc, const OUString& rRole,
     288             :         sal_Int32 nDataSeries = 0, sal_Int32 nChartType = 0, sal_Int32 nCooSys = 0 )
     289             : {
     290             :     Reference< chart2::XDataSeries > xDataSeries =
     291           1 :         getDataSeriesFromDoc( xChartDoc, nDataSeries, nChartType, nCooSys );
     292           1 :     CPPUNIT_ASSERT(xDataSeries.is());
     293           2 :     Reference< chart2::data::XDataSource > xDataSource( xDataSeries, uno::UNO_QUERY_THROW );
     294             :     Sequence< Reference< chart2::data::XLabeledDataSequence > > xDataSequences =
     295           2 :         xDataSource->getDataSequences();
     296           2 :     for(sal_Int32 i = 0; i < xDataSequences.getLength(); ++i)
     297             :     {
     298           2 :         Reference< chart2::data::XDataSequence> xLabelSeq = xDataSequences[i]->getValues();
     299           3 :         uno::Reference< beans::XPropertySet > xProps(xLabelSeq, uno::UNO_QUERY);
     300           2 :         if(!xProps.is())
     301           0 :             continue;
     302             : 
     303           3 :         OUString aRoleName = xProps->getPropertyValue("Role").get<OUString>();
     304             : 
     305           2 :         if(aRoleName == rRole)
     306           1 :             return xLabelSeq;
     307           1 :     }
     308             : 
     309           0 :     CPPUNIT_FAIL("no Label sequence found");
     310           1 :     return Reference< chart2::data::XDataSequence > ();
     311             : }
     312             : 
     313           2 : uno::Sequence < OUString > getWriterChartColumnDescriptions( Reference< lang::XComponent > mxComponent )
     314             : {
     315           2 :     uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
     316           4 :     uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
     317           4 :     uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
     318           2 :     CPPUNIT_ASSERT( xShape.is() );
     319           4 :     uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
     320           4 :     uno::Reference< chart2::XChartDocument > xChartDoc;
     321           2 :     xChartDoc.set( xPropertySet->getPropertyValue( "Model" ), uno::UNO_QUERY );
     322           2 :     CPPUNIT_ASSERT( xChartDoc.is() );
     323           2 :     CPPUNIT_ASSERT( xChartDoc->getDataProvider().is() );
     324           4 :     uno::Reference<beans::XPropertySet> xProp(xChartDoc->getDataProvider(), uno::UNO_QUERY );
     325           4 :     uno::Reference< chart2::XAnyDescriptionAccess > xAnyDescriptionAccess ( xChartDoc->getDataProvider(), uno::UNO_QUERY_THROW );
     326           2 :     CPPUNIT_ASSERT( xAnyDescriptionAccess.is() );
     327           2 :     uno::Sequence< OUString > seriesList = xAnyDescriptionAccess->getColumnDescriptions();
     328           4 :     return seriesList;
     329             : }
     330             : 
     331           1 : std::vector<std::vector<double> > getDataSeriesYValuesFromChartType( const Reference<chart2::XChartType>& xCT )
     332             : {
     333           1 :     Reference<chart2::XDataSeriesContainer> xDSCont(xCT, uno::UNO_QUERY);
     334           1 :     CPPUNIT_ASSERT(xDSCont.is());
     335           2 :     Sequence<uno::Reference<chart2::XDataSeries> > aDataSeriesSeq = xDSCont->getDataSeries();
     336             : 
     337             :     double fNan;
     338           1 :     rtl::math::setNan(&fNan);
     339             : 
     340           1 :     std::vector<std::vector<double> > aRet;
     341           4 :     for (sal_Int32 i = 0; i < aDataSeriesSeq.getLength(); ++i)
     342             :     {
     343           3 :         uno::Reference<chart2::data::XDataSource> xDSrc(aDataSeriesSeq[i], uno::UNO_QUERY);
     344           3 :         CPPUNIT_ASSERT(xDSrc.is());
     345           6 :         uno::Sequence<Reference<chart2::data::XLabeledDataSequence> > aDataSeqs = xDSrc->getDataSequences();
     346           9 :         for (sal_Int32 j = 0; j < aDataSeqs.getLength(); ++j)
     347             :         {
     348           6 :             Reference<chart2::data::XDataSequence> xValues = aDataSeqs[j]->getValues();
     349           6 :             CPPUNIT_ASSERT(xValues.is());
     350          12 :             Reference<beans::XPropertySet> xPropSet(xValues, uno::UNO_QUERY);
     351           6 :             if (!xPropSet.is())
     352           0 :                 continue;
     353             : 
     354          12 :             OUString aRoleName;
     355           6 :             xPropSet->getPropertyValue("Role") >>= aRoleName;
     356           6 :             if (aRoleName == "values-y")
     357             :             {
     358           3 :                 uno::Sequence<uno::Any> aData = xValues->getData();
     359           6 :                 std::vector<double> aValues;
     360           3 :                 aValues.reserve(aData.getLength());
     361          15 :                 for (sal_Int32 nVal = 0; nVal < aData.getLength(); ++nVal)
     362             :                 {
     363             :                     double fVal;
     364          12 :                     if (aData[nVal] >>= fVal)
     365          12 :                         aValues.push_back(fVal);
     366             :                     else
     367           0 :                         aValues.push_back(fNan);
     368             :                 }
     369           6 :                 aRet.push_back(aValues);
     370             :             }
     371           6 :         }
     372           3 :     }
     373             : 
     374           2 :     return aRet;
     375             : }
     376             : 
     377           6 : std::vector<uno::Sequence<uno::Any> > getDataSeriesLabelsFromChartType( const Reference<chart2::XChartType>& xCT )
     378             : {
     379           6 :     OUString aLabelRole = xCT->getRoleOfSequenceForSeriesLabel();
     380             : 
     381          12 :     Reference<chart2::XDataSeriesContainer> xDSCont(xCT, uno::UNO_QUERY);
     382           6 :     CPPUNIT_ASSERT(xDSCont.is());
     383          12 :     Sequence<uno::Reference<chart2::XDataSeries> > aDataSeriesSeq = xDSCont->getDataSeries();
     384             : 
     385           6 :     std::vector<uno::Sequence<uno::Any> > aRet;
     386          24 :     for (sal_Int32 i = 0; i < aDataSeriesSeq.getLength(); ++i)
     387             :     {
     388          18 :         uno::Reference<chart2::data::XDataSource> xDSrc(aDataSeriesSeq[i], uno::UNO_QUERY);
     389          18 :         CPPUNIT_ASSERT(xDSrc.is());
     390          36 :         uno::Sequence<Reference<chart2::data::XLabeledDataSequence> > aDataSeqs = xDSrc->getDataSequences();
     391          43 :         for (sal_Int32 j = 0; j < aDataSeqs.getLength(); ++j)
     392             :         {
     393          25 :             Reference<chart2::data::XDataSequence> xValues = aDataSeqs[j]->getValues();
     394          25 :             CPPUNIT_ASSERT(xValues.is());
     395          50 :             Reference<beans::XPropertySet> xPropSet(xValues, uno::UNO_QUERY);
     396          25 :             if (!xPropSet.is())
     397           0 :                 continue;
     398             : 
     399          50 :             OUString aRoleName;
     400          25 :             xPropSet->getPropertyValue("Role") >>= aRoleName;
     401          25 :             if (aRoleName == aLabelRole)
     402             :             {
     403          16 :                 Reference<chart2::data::XLabeledDataSequence> xLabel = aDataSeqs[j];
     404          16 :                 CPPUNIT_ASSERT(xLabel.is());
     405          32 :                 Reference<chart2::data::XDataSequence> xDS2 = xLabel->getLabel();
     406          16 :                 CPPUNIT_ASSERT(xDS2.is());
     407          32 :                 uno::Sequence<uno::Any> aData = xDS2->getData();
     408          32 :                 aRet.push_back(aData);
     409             :             }
     410          25 :         }
     411          18 :     }
     412             : 
     413          12 :     return aRet;
     414             : }
     415             : 
     416           3 : uno::Reference< chart::XChartDocument > ChartTest::getChartDocFromImpress( const char* pDir, const char* pName )
     417             : {
     418           3 :     mxComponent = loadFromDesktop(getURLFromSrc(pDir) + OUString::createFromAscii(pName), "com.sun.star.comp.Draw.PresentationDocument");
     419           3 :     uno::Reference< drawing::XDrawPagesSupplier > xDoc(mxComponent, uno::UNO_QUERY_THROW );
     420             :     uno::Reference< drawing::XDrawPage > xPage(
     421           6 :         xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW );
     422           3 :     CPPUNIT_ASSERT(xPage.is());
     423             :     uno::Reference< beans::XPropertySet > xShapeProps(
     424           6 :         xPage->getByIndex(0), uno::UNO_QUERY );
     425           3 :     CPPUNIT_ASSERT(xShapeProps.is());
     426           6 :     uno::Reference< frame::XModel > xDocModel;
     427           3 :     xShapeProps->getPropertyValue("Model") >>= xDocModel;
     428           3 :     CPPUNIT_ASSERT(xDocModel.is());
     429           3 :     uno::Reference< chart::XChartDocument > xChartDoc( xDocModel, uno::UNO_QUERY_THROW );
     430             : 
     431           6 :     return xChartDoc;
     432             : }
     433             : 
     434           8 : uno::Reference<chart::XChartDocument> ChartTest::getChartDocFromDrawImpress(
     435             :     sal_Int32 nPage, sal_Int32 nShape )
     436             : {
     437           8 :     uno::Reference<chart::XChartDocument> xEmpty;
     438             : 
     439          16 :     uno::Reference<drawing::XDrawPagesSupplier> xPages(mxComponent, uno::UNO_QUERY);
     440           8 :     if (!xPages.is())
     441           0 :         return xEmpty;
     442             : 
     443             :     uno::Reference<drawing::XDrawPage> xPage(
     444          16 :         xPages->getDrawPages()->getByIndex(nPage), uno::UNO_QUERY_THROW);
     445           8 :     if (!xPage.is())
     446           0 :         return xEmpty;
     447             : 
     448          16 :     uno::Reference<beans::XPropertySet> xShapeProps(xPage->getByIndex(nShape), uno::UNO_QUERY);
     449           8 :     if (!xShapeProps.is())
     450           0 :         return xEmpty;
     451             : 
     452          16 :     uno::Reference<frame::XModel> xDocModel;
     453           8 :     xShapeProps->getPropertyValue("Model") >>= xDocModel;
     454           8 :     if (!xDocModel.is())
     455           0 :         return xEmpty;
     456             : 
     457          16 :     uno::Reference<chart::XChartDocument> xChartDoc(xDocModel, uno::UNO_QUERY);
     458          16 :     return xChartDoc;
     459             : }
     460             : 
     461          16 : uno::Reference<chart::XChartDocument> ChartTest::getChartDocFromWriter( sal_Int32 nShape )
     462             : {
     463             :     // DO NOT use XDrawPageSupplier since SwVirtFlyDrawObj are not created
     464             :     // during import, only in layout!
     465          16 :     Reference<text::XTextEmbeddedObjectsSupplier> xEOS(mxComponent, uno::UNO_QUERY);
     466          16 :     CPPUNIT_ASSERT(xEOS.is());
     467          32 :     Reference<container::XIndexAccess> xEmbeddeds(xEOS->getEmbeddedObjects(), uno::UNO_QUERY);
     468          16 :     CPPUNIT_ASSERT(xEmbeddeds.is());
     469             : 
     470          32 :     Reference<beans::XPropertySet> xShapeProps(xEmbeddeds->getByIndex(nShape), uno::UNO_QUERY);
     471          16 :     CPPUNIT_ASSERT(xShapeProps.is());
     472             : 
     473          32 :     Reference<frame::XModel> xDocModel;
     474          16 :     xShapeProps->getPropertyValue("Model") >>= xDocModel;
     475          16 :     CPPUNIT_ASSERT(xDocModel.is());
     476             : 
     477          16 :     uno::Reference<chart::XChartDocument> xChartDoc(xDocModel, uno::UNO_QUERY);
     478          32 :     return xChartDoc;
     479             : }
     480             : 
     481           2 : uno::Sequence < OUString > ChartTest::getImpressChartColumnDescriptions( const char* pDir, const char* pName )
     482             : {
     483           2 :     uno::Reference< chart::XChartDocument > xChartDoc = getChartDocFromImpress( pDir, pName );
     484           4 :     uno::Reference< chart::XChartDataArray > xChartData ( xChartDoc->getData(), uno::UNO_QUERY_THROW);
     485           2 :     CPPUNIT_ASSERT(xChartData.is());
     486           2 :     uno::Sequence < OUString > seriesList = xChartData->getColumnDescriptions();
     487           4 :     return seriesList;
     488             : }
     489             : 
     490           8 : OUString getTitleString( const Reference<chart2::XTitled>& xTitled )
     491             : {
     492           8 :     uno::Reference<chart2::XTitle> xTitle = xTitled->getTitleObject();
     493           8 :     CPPUNIT_ASSERT(xTitle.is());
     494          16 :     uno::Sequence<uno::Reference<chart2::XFormattedString> > aFSSeq = xTitle->getText();
     495           8 :     OUString aText;
     496          22 :     for (sal_Int32 i = 0; i < aFSSeq.getLength(); ++i)
     497          14 :         aText += aFSSeq[i]->getString();
     498             : 
     499          16 :     return aText;
     500             : }
     501             : 
     502           4 : sal_Int32 getNumberFormat( const Reference<chart2::XChartDocument>& xChartDoc, const OUString& sFormat )
     503             : {
     504           4 :     Reference<util::XNumberFormatsSupplier> xNFS(xChartDoc, uno::UNO_QUERY_THROW);
     505           8 :     Reference<util::XNumberFormats> xNumberFormats = xNFS->getNumberFormats();
     506           4 :     CPPUNIT_ASSERT(xNumberFormats.is());
     507             : 
     508           8 :     return xNumberFormats->queryKey(sFormat, css::lang::Locale(), sal_False);
     509             : }
     510             : 
     511           8 : sal_Int32 getNumberFormatFromAxis( const Reference<chart2::XAxis>& xAxis )
     512             : {
     513           8 :     Reference<beans::XPropertySet> xPS(xAxis, uno::UNO_QUERY);
     514           8 :     CPPUNIT_ASSERT(xPS.is());
     515           8 :     sal_Int32 nNumberFormat = -1;
     516           8 :     bool bSuccess = xPS->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormat;
     517           8 :     CPPUNIT_ASSERT(bSuccess);
     518             : 
     519           8 :     return nNumberFormat;
     520             : }
     521             : 
     522           8 : sal_Int16 getNumberFormatType( const Reference<chart2::XChartDocument>& xChartDoc, sal_Int32 nNumberFormat )
     523             : {
     524           8 :     Reference<util::XNumberFormatsSupplier> xNFS(xChartDoc, uno::UNO_QUERY_THROW);
     525          16 :     Reference<util::XNumberFormats> xNumberFormats = xNFS->getNumberFormats();
     526           8 :     CPPUNIT_ASSERT(xNumberFormats.is());
     527             : 
     528          16 :     Reference<beans::XPropertySet> xNumPS = xNumberFormats->getByKey(nNumberFormat);
     529           8 :     CPPUNIT_ASSERT(xNumPS.is());
     530             : 
     531           8 :     sal_Int16 nType = util::NumberFormat::UNDEFINED;
     532           8 :     xNumPS->getPropertyValue("Type") >>= nType;
     533             : 
     534          16 :     return nType;
     535             : }
     536             : 
     537             : #endif // INCLUDED_CHART2_QA_EXTRAS_CHARTTEST_HXX
     538             : 
     539             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11